Skip to main content

Subsection 4.3.3 Functions or Predicates?

Let’s now look at one particular kind of representational decision that we often have to make. By now, you may have noticed that we have two different mechanisms for indicating relationships between objects:

  • Predicates, such as MotherOf(Gruffy, Smokey). We’ve used this to say that Gruffy is the mother of Smokey.

  • Functions, such as weight(Smokey) and age(Smokey). Using these functions, we can say things like weight(Smokey) = 567 or age(Smokey) = 70.

You may be wondering what the difference is between a function and a predicate. In particular, couldn’t we equally well have:

  • used a motherof function. Then we could write, motherof(Smokey) = Gruffy.

  • used Weight and Age predicates. Then we could have that Weight(Smokey, 567) and Age(Smokey, 70) would be true.

Yes, in all these cases we could have used either technique.

In general, the one big difference is that a function must return exactly one value. So we can use a motherof function:

  • motherof(Smokey) = Gruffy, because Smokey has exactly one mother.

But we cannot write:

  • childof(Gruffy) = ___, because, while we have that Smokey is Gruffy’s child, we assume there are probably more. Which one should be the value of this expression?

So, to represent claims about Gruffy’s children, we must use a predicate. Then we can write:

  • ChildOf(Smokey, Gruffy)

  • ChildOf(Piper, Gruffy) (in case Gruffy had a second child, Piper)

In computational logic systems, the decision of when to use functions and when to use predicates is usually made on the basis of various practical considerations. When we’re writing out our claims, we’ll use whichever makes it easier to see what is going on.

Exercises Exercises

1.

1. Suppose that we are a wholesaler (we sell to other companies) and we want to talk about the customers we have for our various products. Which one or more of the following describe(s) our options:

  1. We could use a predicate Buys(company, product). We’ll read such a predicate as saying that company buys product from us. We would assert specific claims like, Buys(YesCorp, Ladders) or Buys(PaintersAreUs, Ladders) or Buys(PaintersAreUs, Tarps).

  2. We could use a function whoareourcustomers(product). So we could write, for example, whoareourcustomers(Ladders) and expect to get back the name of the customer for ladders.

  3. We could use a function whatdotheybuy(customer). So we could write, for example, whatdotheybuy(PaintersAreUs) and expect to get back the product that PaintersAreUs buys.

  1. Just I.

  2. Just II.

  3. Just III.

  4. All of them work.

Answer.
Correct answer is A.
Solution.
Explanation: We must use a predicate. We can’t use a function because there isn’t a unique value. A given product, such as ladders, can have multiple customers. And a given customer can buy multiple products.