T3: Predicate logic (exercises)

Exercises Artificial Intelligence: Predicate logic
1. Formulate these sentences, which are written in plain English (a natural language),
in the language of predicate logic.
Use the predicate Loves2
E.g. Loves(A,B) means “A loves B”
a.
b.
c.
d.
e.
f.
g.
“There is someone who loves everyone”
“There is someone who loves at least one person”.
“There is someone who loves someone else”
“Everybody loves each other”.
“There is someone who is loved by everyone”.
“There is someone whom everybody loves”.
“Everyone has someone who loves him (or her)”.
Use the predicates or functions (you will have to decide which is which) city,
spanish, telephoneNumber, firstDigits, with the obvious meaning for each of the
predicates or functions to formalize the sentence
h. “The first two digits of the telephone number of two people who live in the
same Spanish city coincide.”
1. Consider the WFFs
∀x ∃y Loves(x,y) (I)
∃y ∀x Loves(x,y) (II)
(a) Are they equivalent? Show whether they are by translating them into English.
(b) Does (I) entail (II) [(I) ╞═ (II)] ?
(c) Does (II) entail (I) [(II) ╞═ (I)] ?
2. Given the set of wffs S = { A( x, y ), A( f ( z ), a), A( f (a), z )} and the substitution
σ = { x := f ( z ); y := a; z := a} :
a) Is σ a unifier of the wffs?
b) Is it the most general unifier for this set of wffs?
c) If the answer to b) is no, construct the most general unifier for S.
All answers must be reasoned
3. Find, if it exists, the mgu of each pair of atomic sentences.
a. Lower(y,integer(exponent(y,x))),
Lower(8,integer(exponent(x,f(x))))
b. Greater(y,f(x,y,g(h(a),y))), Greater (8,f(a,z,g(w,8)))
Notation: constants: a, 8; variables: x,y,w,z; functions: f,g,h
4.
[Adapted from Nilsson]
Consider the ontology for lists.
The function cons(x,y) constructs a list by inserting the element x at the beginning
of the list y.
In particular, the list (a b c) is constructed using the formula
•
cons(a,cons(b,cons(c,NIL)))
•
where NIL represents the empty list.
The predicate Last(y,x) evaluates to True if the last element of the list y is
element x.
a) Using only these elements in the ontology, translate to wffs in predicate logic
the following axioms
i) The empty list has no last element.
ii) The last element of a list with a single element is precisely that element.
iii) The last element of a list y is also the last element of any list constructed by
inserting an element at the beginning of y.
b) Use inference to find the last element of the list (a b c).
5. Consider the following ontology for lists:
Objects: Nil, A,B,C... (átomos)
Predicates: Find2, Atom1, Listp1
Functions: cons2, append2, first1, rest1
•
•
•
Superindices indicate the number of arguments the superscripted function or
predicate takes.
Predicate “Find(x,s)” takes value True if element “x” is included in list “s” and
False otherwise.
The remaining functions and predicates have the same meaning as their
counterparts in Lisp.
Formalize the following axioms for a theory of lists in first order logic. Equality can be
used.
a) [Example] A list is either the empty list or the result of consing an element with
another list.
(∀s) [Listp(s) ⇔ [[s = Nil] ∨ (∃x,s’) [Listp(s’)∧[s=cons(x,s’)]]]
b) The empty list contains no elements.
c) The empty list does not contain any non-empty sublists.
d) Two lists are equal iff the elements all elements in the first list are equal to the
elements in the second list and these elements are in the same order in the list.
e) Define the predicate Find, which evaluates to True when an element is in a list.
6. Consider the following ontology for data trees
Objects: A,B,C... (Atoms)
Predicates or relations: isRoot1, isInternal1, isLeaf1, isChild2, isParent2,
isSibling2, isAntecessor2, isSuccessor2
Funciones: Parent1, Child1
Superscript indicated the number of arguments of the corresponding function or predicate.
Example:
o The predicate “isParent(A,B)” takes the value True if node “A” is the
parent node of node “B”.
o If A is not a root node, Parent(A) represents the object for which the
wff “isParent(Parent(A),A)” always evaluates to True, etc.
4.1 Write wffs for the following (incomplete) list of axioms for a theory of data trees in
first order logic. It is possible to use the equality predicate)
a) [Example] isParent y isChild are inverse relations: If a node is the parent node of
another node, the latter is a child node of the former
(∀x,y) [isParent(x,y) ⇔ isChild(y,x)]
b)
c)
d)
e)
A root node has no parent node.
A parent node, if it exists, is unique
Two sibling nodes are two different nodes that share the same parent.
A node is an antecessor node of another node if the former is the parent, or the
grandparent, or the great-grandparent or the great-great-grandparent,... of the latter.
4.2 Express the following fact in first order logic
“isSibling is a symmetric relation: If a node is a sibling to another node, the latter is
a sibling of the former.”
Is this an axiom or a theorem? If it is a theorem, demonstrate it starting from the
listed axioms, specifying at each step which inference rules have been used.
4.3 Consider the following wff
(∀x,y) [isParent(Parent(x),y) ⇒ [(x=y) ∨ isSibling(y,x)]
Is this an axiom or a theorem? If it is a theorem, demonstrate it starting from the
listed axioms, specifying at each step which inference rules have been used.
4.4 Solve the following riddle using formal logic methods from the axioms and
theorems listed.
A node says: “I have no sibling nodes, but the father of the node of which I am
speaking is the child node of my parent node”. Which node is being spoken of?
7. Consider the following equivalences between predicates:
≤ ≡ LE ; > ≡ G; = ≡ E .
You are requested to:
a. Express the following statements in predicate logic, indicating the sets of clauses
that can be inferred from them
1. If x ≤ y and y ≤ z then not x > z
2. x ≤ y if and only if y > x or x = y
3. For every x there exists a y such that x ≤ y
4. x ≤ x for all x
b. Is there a most general unifier for the clauses that result form iii) and iv)?
8. Consider the elements of an ontology for affine geometry:
•
•
•
Points: P, Q, …
Geometrical objects : r, s (straight lines) y π 1 , π 2 (planes).
Predicate: BelongsTo2
o BelongsTo2 is the only relation defined. It takes two arguments
arg1: Point
arg2: Geometric object.
Solve the following problem using inference:
“The straight line r is the intersection between planes π 1 and π 2 . The straight line s
is contained in π 2 and P is in both s and π 1 . Show that r and s have an intersection
point using only elements of the ontology. Which is the intersection point?”
9. Using Green’s trick and the formal methods of predicate logic, solve the enigma:
“Laura’s grandmother drives a red sports car. The only person that Laura knows
who drives a red car is Antonia. Who is Laura’s grandmother?”
The following functions and predicates are available:
functions: grandmother1
Predicates: SportsCar1, Car1, Red1 , Knows2 , Drives2
You may need to include implicit knowledge in your knowledge base to solve the
enigma.
Only complete, correct and detailed answers using formal reasoning are valid.
10. [Adapted from Nilsson] (1,5 points) Consider the digital circuit:
S1
S2
S3
XOR1
S4
NOT1
If the gate G (where G stands for either XOR1 or NOT1) is functioning correctly, the
predicate OK(G)evaluates to True. If the gate is malfunctioning (the output of the
gate is zero independent of the inputs), the predicate OK(G) evaluates to False.
If the signal Si is 1 then On(Si) evaluates to True. the signal Si is 0, On(Si)
evaluates to False.
a) Write the wffs describe the functioning of this particular circuit using only the
predicates On and OK. Each wff involves at most one gate. Do not use the
equality predicate.
b) Use inference (no semiformal reasoning or truth values can be used) to derive:
i. Assuming that all gates are functioning properly, the output of the
circuit when the signals S1,S2 are equal.
ii. Assuming that all gates are functioning properly, the output of the
circuit when the signals S1,S2 are different.
iii. Derive the consequences of knowing that the signals S1,S2 are
different and that the signal S4 is 1.
11. The figure below depicts a half adder, which is a logic circuit that performs an
addition operation on two binary digits. The circuit has two input and two output
carry lines. The signals in the input carry lines are combined using logic gates that
generate the output signals.
Objects: Circuit (C1), logic gates (X1, A1) and carry lines
Functions:
• Function Type1:
Receives the identifier of a logic gate.
Returns the type of logic gate.
Example: For the circuit depicted in the figure the following predicate evaluates to T
Type(A1) = AND
•
•
•
•
Function Input2:
Receives the identifier of an input line and the identifier of a logic gate/circuit.
Returns the input line.
Function Output2:
Receives the identifier of an output line and the identifier of a logic gate/circuit.
Returns the output line.
Function SignalValue2
Receives the identifier of a carry line.
Returns the value of the signal carried by the line.
Predicate Connected2:
Receives the identifiers of two carry lines.
Returns T if the two lines are connected and F otherwise.
Example: For the circuit depicted in the figure the following predicates evaluate to T
Connected(Input(1,C1), Input(1,A1)) Connected(Output(1,A1),Output(2,C1))
a) (1.5 points) Using the elements listed, and the equality predicate with the usual
properties (reflexive, commutative, transitive), express the wffs that correspond to
the following knowledge base:
Example:
The output of an OR logic gate is 1 if and only if at least one of its two inputs has value
1.
∀g Type(g)=OR ⇒ SignalValue (Output(1,g))=1 ⇔
(SignalValue(Input(1,g))=1 ∨ SignalValue(Input(2,g))=1)
1)
2)
3)
4)
5)
The value of a signal is either 0 or 1.
Connected carry lines have the same signal value.
Connected2 is a commutative predicate.
The output of an AND logic gate is 1 if and only if its inputs have value 1.
The output of an XOR logic gate is 1 if and only if its two inputs have different
values.
Augment this knowledge base with the following wffs:
b) (0.25 puntos) Define the types of logic gates used in the half adder depicted in the
figure.
c) (0.25 puntos) Define the instances of the predicates that represent the connections
between inputs and outputs of the different elements in the half adder.
Example: For the circuit depicted in the figure the following predicates evaluate to T
Connected(Input(1,C1), Input(1,A1)) Connected(Output(1,A1),Output(2,C1))
d) (1 point) Knowing that
1) SignalValue(Input(1,C1)) = 1
2) SignalValue(Input(2,C1)) = 1
Deduce using modus ponens and equivalence rules (DO NOT use resolution) vale
of the output of the half adder SignalValue(Output(1,C1)) and
SignalValue(Output(2,C1)).
[adapted from http://aima.eecs.berkeley.edu/slides-ppt/]
12. Find the resolvent of the following clauses
K1 = P (y, m(y),f(y)) ∨ P (w, m(y), r(z))
K2 = ¬P (f(x), m(r(x)), y) ∨ Q (x,y)
13. Consider an ontology for lists with the following functions and predicates:
Object constants:
• NIL: empty list
• A,B,C,… : other atoms
Variables:
• lst [Domain: lists]
• x,y,z [Domain: lists + atoms]
• n
[Domain: positive integers]
Functions
• cons(x,lst):
Standard LISP cons function
Predicates
• First(lst,x):
• Second(lst,x):
The first element of list lst is x.
The second element of list lst is x.
• Nth(n,lst,x):
The nth element of list lst is x.
Assume that, if needed, arithmetic expressions can be directly evaluated.
a) Express concisely and with precision in natural language what the following
axioms mean:
(i)
(ii)
b)
∀ lst,x First(cons(x,lst),x)
∀ lst,x,y Second(cons(y,lst),x) ⇔ First(lst,x)
Write a wff that expresses the following sentence in natural language:
“The nth element of a list when n is 1 is the first element of that list”.
c) Write an axiom that defines Nth(n,lst,x) recursively. Note that axiom (7.2) is
the base case of the recursion.
d) Using the previous axioms, answer extraction and Green’s trick, determine
which is the second element of the list (A B C). Only inference is allowed (no
semiformal reasoning or truth values can be used). Please name the inference
rule applied at each step.
14. [Adapted from:
Lógica de Predicados. Labra J.E., Fernández D. EUITIO]
Given the following ontology for natural numbers:
• Function s1: s(x) [≡ successor of x]
• Constants:
0
3
• Relations Sum , Product3:
means z is equal to x+y
Sum(x,y,z)
Product(x,y,z)
means z is equal to x*y
• Axioms:
-
∀ x Sum(x,0,x)
∀ x,y,z Sum(x,y,z) ⇒ Sum(x,s(y),s(z))
[≡ x+(y+1)=(x+y)+1]
Product(x,0,0)
∀ x,y,z,v [Product(x,y,v)∧Sum(x,v,z)] ⇒ Product(x,s(y),z)
[≡ x*(y+1)=(x*y)+x]
a. (1 point) Demonstrate the theorem: (∃x)Product(x,x,s(0))
b. (0.5 points) What is the value of x that verifies the relation
Product(x,x,s(0))?
15. Consider the relation “Knows” applicable to individuals in a group of people.
Assume that within this group the following properties hold:
A: Symmetric: If a person knows another person in the group, then the second
person also knows the first one.
B: Transitive: If a person knows another person and this person knows a third
one, then the first person also knows the third one.
Consider the statement
C: If a person in the group knows some other person, then if another person
knows the second person, then he or she also knows the first one.
Is C a logical consequence of A^ B?
Formalize the problem expressing A, B y C as fbf’s y demonstrate your answer.
16. [Adapted from “The new Turing Omnibus”, A. K. Dewdney]
A peasant traveling with a wolf, a sheep and a cauliflower needs to cross a river
with a boat. The boat can take only the peasant and one of the three companions.
The wolf and the sheep cannot stay alone, nor can the sheep and the cauliflower.
How can the peasant cross the river without having any accidents?
Find the solution to this puzzle using predicate logic
L = left bank of the river
R = right-bank of the river
Function:
c(x):
If x == L then c(x) := R
If x == R then c(x) := L
Predicate:
P(p,w,g,c) evaluates to True if the configuration is possible
False otherwise
p: location of the man (either L or R)
w: location of the wolf (either L or R)
g: location of the sheep (either L or R)
c: location of the cauliflower (either L or R)
E(x,y) evaluates to True if the locations x and y are the same
False otherwise
x,y: locations (either L or R)
Kowledge base:
(i) ∀x E(x,x)
(ii) ∀x ¬ E(x,c(x))
(iii) ∀x,y,z P(x,y,x,z) ⇒ P(c(x),y,c(x),z)
Explanation: “If the peasant and the sheep are on the same side of the river,
it is possible for the peasant to transport the sheep to the other side of the
river”
(iv) ∀x,y,z P(x,x,y,z) ∧ ¬E(y,z) ⇒ P(c(x),c(x),y,z)
Explanation: <Explanation 4>
(v) <Axiom 5>
Explanation: <Explanation 5>
(vi) <Axiom 6>
Explanation: “If the wolf and the cauliflower are on the same side of the
river, and the sheep is on the other side of the river, the peasant can cross the
river by himself”
(vii) P(L,L,L,L)
Explanation: Initially the peasant, the wolf, the sheep and the cauliflower are
on the left-hand side of the river.
To simplify the derivations, assume that
c(L) and R
c(R) and L
are interchangeable.
a) Complete the missing axioms and explanations
<Explanation 4>
<Axiom 5>
<Explanation 5>
<Axiom 6>
b) Demonstrate whether it is possible to transport the wolf, the sheep and the
cauliflower to the other side of the river.
(1) Determine the goal.
(2) Use resolution refutation to show that the goal is a logical consequence
of the knowledge base.
(3) If there is a solution to the problem, what is the sequence of steps that
lead to the solution?