Predicate logic

http://en.wikipedia.org/wiki/Gottlob_Frege
http://en.wikipedia.org/wiki/First-order_logic
http://www.cs.odu.edu/~toida/nerzic/content/logic/pred_logic/intr_to_pred_logic.html
Predicate
logic
While propositional logic deals with simple declarative propositions, first-order logic additionally
covers predicates and quantification.
www.tudorgirba.com
Boolean algebra
Propositional logic
0, 1
True, False
boolean variables: a∈{0, 1}
atomic formulas: p∈{True,False}
boolean operators: ¬ ∧ ∨
logical connectives: ¬ ∧ ∨
boolean functions:
propositional formulas (propositions):
0, 1
True and False
boolean variables
atomic formulas
if a is a boolean function, then ¬a is a
boolean function
if a is a propositional formula, then ¬a
is a propositional formula
if a and b are boolean functions, then
a∧b, a∨b, a b, a b are boolean
if a and b are propositional formulas,
then a∧b, a∨b, a b, a b are
functions
truth value of a boolean function (truth
tables)
Boolean algebra and propositional logic are different ways of interpreting the same thing. Usage:
computer processors (circuits, switches).
Atomic formulas are also called atoms.
Propositions are called “Aussagen” in German
propositional formulas
truth value of a propositional formula (truth
tables)
What is propositional logic good for?
There are three persons: Stirlitz, Mueller, and Eismann. It is known that exactly
one of them is Russian, while the other two are Germans.
Moreover, every Russian must be a spy.
When Stirlitz meets Mueller in a corridor, he makes the following joke: “you
know, Mueller, you are as German as I am Russian”. It is known that Stirlitz
always says the truth when he is joking.
Establish that Eismann is not a Russian spy.
lem
py prob
ssian s
The Ru
Consider the problem. How can we formalize it?
There are three persons: Stirlitz, Mueller, and Eismann. It is known that exactly
one of them is Russian, while the other two are Germans.
Introduce propositions (atomic formulas, boolean variables) X Y ,
where X ∈ {R, G, S} (denoting Russian, German, Spy)
Y ∈ {S,M,E} (denoting Stirlitz, Mu ̈ller, Eismann)
Moreover, every Russian must be a spy.
When Stirlitz meets Mueller in a corridor, he makes the following joke: “you
know, Mueller, you are as German as I am Russian”. It is known that Stirlitz
always says the truth when he is joking.
Establish that Eismann is not a Russian spy.
For example,
SE : Eismann is a Spy
RS : Stirlitz is Russian
X ∈ {R, G, S} (denoting Russian, German, Spy)
Y ∈ {S,M,E} (denoting Stirlitz, Müller, Eismann)
SE : Eismann is a Spy
RS : Stirlitz is Russian
There are three persons: Stirlitz, Mueller, and Eismann. It is known that exactly
one of them is Russian, while the other two are Germans.
(RS ∧ GM ∧ GE) ∨ (GS ∧ RM ∧ GE) ∨ (GS ∧ GM ∧ RE).
(RS
¬GS) ∧ (RM
¬GM) ∧ (RE
¬GE).
If this set of formulas is satisfiable in some situation I, then
1. All conditions of the puzzle are satisfied by I.
2. I also satisfies the property that Eismann is a Russian spy.
Moreover, every Russian must be a spy.
(RS
SS) ∧ (RM
SM) ∧ (RE
SE).
When Stirlitz meets Mueller in a corridor, he makes the following joke: “you
know, Mueller, you are as German as I am Russian”. It is known that Stirlitz
always says the truth when he is joking.
RS
If we demonstrate that the problem is unsatisfiable (it is a contradiction), then we prove that
Eismann cannot be a Russian spy.
GM.
Establish that Eismann is not a Russian spy.
RE ∧ SE.
Why formalisms?
Formalisms can describe computation and information.
computation
information
computer
information
Propositional logic not enough to reason about concepts like of “greater than 5”.
2 is greater than 5
False
6 is greater than 5
True
x is greater than 5
?
predicate
The value of “x is greater than 5” depends on the value of variable x.
This construct speaks about many simple propositions. Thus, it is not a propositional formula. We
need predicate logic.
Usage: software systems in financial services, automotive industry, medicine.
“ x is greater than 5” is a predicate, denoted it by F.
F(2) = 2 is greater than 5
False
F(6) = 6 is greater than 5
True
F(x) = x is greater than 5
A predicate describes a property of objects represented by variables from an universe (domain,
Bereichsangabe).
Any predicate can be transformed into a proposition by replacing variables with actual values.
predicate
universe
quantifier for all natural numbers x,
x is greater than 5
False
quantifier for some natural numbers x,
x is greater than 5
True
Universal quantifier ∀ :
Existential quantifiers ∃ :
∀x: U(x): F(x)
∃x: U(x): F(x)
∀x:x∈N:x>5
∃x:x∈N:x>5
for all natural numbers x,
x is greater than 5
for some natural numbers x,
x is greater than 5
Universal quantifier: ∀ ∀x: U(x): F(x)
“for every object x in the universe U, F(x) holds”, “for all (any) object x in the universe U, F(x)
holds”
Example: ∀x:x∈N:x>5
Note: ∀x: False: F(x) is True
Existential quantifier: ∃ ∃x: U(x): F(x)
“for some object x in the universe U, F(x) holds”, “there exist an object x in the universe U such
that F(x) holds”
Example: ∃ x:x∈N:x>5
Note: ∃x: False: F(x) is False
Gottlob Frege
1848—1925
no appeal to intuition
Distributivity of ∀ ∧
∀x: U(x): (P(x) ∧ Q(x))
(∀x: U(x): P(x)) ∧ (∀ x: U(x): Q(x))
Distributivity of ∃ ∨
∃x: U(x): (P(x) ∨ Q(x))
(∃x: U(x): P(x)) ∨ (∃ x: U(x): Q(x))
Non-distributivity of ∀ ∨
(∀x: U(x): P(x)) ∨ (∀x: U(x): Q(x))
∀x: U(x): (P(x) ∨ Q(x))
Non-distributivity of ∃ ∧
∃x: U(x): (P(x) ∧ Q(x))
(∃x: U(x): P(x)) ∧ (∃x: U(x): Q(x))
A couple of examples.
∀ i: 0≤i<N: ai=0
∃ i: 0≤i<N: ai ≠ 0
all elements ai of array a (of length N) are
zero
at least one element of array a (of length N) is
not zero
∀ i: 1≤i<N: ai-1 ≤ ai
∃ i: 1≤i<N: ai-1 > ai
elements of array a are monotonically
increasing
elements of array a are not monotonically
increasing
∀ i,j: 0≤i<j<N: ai ≤ aj
∃ i,j: 0≤i<j<N: ai > aj
elements of array a are monotonically
increasing
elements of array a are not monotonically
increasing
∀ i,j: 0≤i,j<N: ai = aj
∃ i,j: 0≤i<j<N: ai ≠ aj
all elements of array a are equal
not all elements of array a are equal
∀ i: 0<i<N: ai ≤ a0
∃ i: 0<i<N: ai > a0
a0 is the greatest element of array a
a0 is not the greatest element of array a
s
le
Examp
∀ i: 0≤i<N: ai=0
∃ i: 0≤i<N: ai ≠ 0
all elements ai of array a (of length N) are
zero
at least one element of array a (of length N) is
not zero
∀ i: 1≤i<N: ai-1 ≤ ai
∃ i: 1≤i<N: ai-1 > ai
elements of array a are monotonically
increasing
elements of array a are not monotonically
increasing
∀ i,j: 0≤i<j<N: ai ≤ aj
∃ i,j: 0≤i<j<N: ai > aj
elements of array a are monotonically
increasing
elements of array a are not monotonically
increasing
∀ i,j: 0≤i,j<N: ai = aj
∃ i,j: 0≤i<j<N: ai ≠ aj
all elements of array a are equal
not all elements of array a are equal
∀ i: 0<i<N: ai ≤ a0
∃ i: 0<i<N: ai > a0
a0 is the greatest element of array a
a0 is not the greatest element of array a
s
le
Examp
De Morgan’s Axiom ¬∃ :
¬(∃ x: U(x): F(x))
∀ x: U(x): ¬ F(x)
De Morgan’s Axiom ¬∀ :
¬(∀ x: U(x): F(x))
∃ x: U(x): ¬ F(x)
What is the negation of the statement
“Always, when he drives then he is sober.”
D(t): He drives at moment t.
S(t): He is sober at moment t.
∀t : D(t)->S(t)
¬(∀t :: D(t)->S(t))
¬(∀t :: ¬D(t)∨S(t))
∃t :: ¬(¬D(t)∨S(t))
∃t :: D(t)∧¬S(t))
le
Examp
Examples:
- Rewrite (∃ i: 0≤i<N: ai≠0) into an equivalent WFF with ∀
- Rewrite (∀ i: 1≤i<N: ai-1<ai ) into an equivalent WFF with ∃
- Rewrite (∃ i,j: 0≤i<j<N: ai≠aj) into an equivalent WFF with ∀
Formalisms can describe computation.
We have talked about the computation part. Letʼs talk about the information part.
computation
information
computer
information
We say that x is a variable in Universe when it represents objects of the Universe U.
Well formed formulas (WFF)
True, False are WFFs.
Propositional variables are WFFs.
Predicates with variables are WFFs.
If A and B are WFFs, then
¬A, A∧B, A∨B, A B, A B are also WFFs.
If x is a variable in universe U and A is a WFF, then
∀x:U(x):A(x) and ∃x:U(x):A(x) are also WFFs.
Bounded variables
An appearance of variable is bound in a WFF if
a specific value is assigned to it, or it is quantified.
∃i,j: 0<i,j<N: P(i,j) ∨ Q(i,j)
Free variables
If a variable is not bound in a WFF then
it is free.
∃i: 0<i<N: ( (∃j: 0<j<N: P(i,j) ∨ Q(i,j)) )
In the first proposition, it does not matter logically whether we use x or some other letter.
However, it could be confusing to use the same letter again elsewhere in some compound
proposition. That is, free variables become bound, and then in a sense retire from being available
as stand-in values for other values in the creation of formulae.
An appearance (Auftreten) of variable is bound (gebunden) in a WFF if
- a specific value is assigned to it or
- it is quantified.
If a variable is not bound in a WFF then it is free (frei).
The extent of the effect of a quantifier is called the scope (Einflussbereich) of the quantifier:
Swapping ∀ and ∃
∀x: U1(x): (∀y: U2(y): Q(x,y))
∀y: U2(y): (∀x: U1(x): Q(x,y))
∃x: U1(x): (∃y: U2(y): Q(x,y))
∃y: U2(y): (∃x: U1(x): Q(x,y))
However
∃x: U1(x): (∀y: U2(y): Q(x,y))
∀y: U2(y): (∃x: U1(x): Q(x,y))
∃x: U1(x): (∀y: U2(y): Q(x,y))
∀y: U2(y): (∃x: U1(x): Q(x,y))
∀y: U2(y): (∃x: U1(x): Q(x,y))
∃x: U1(y): (∀y: U2(y): Q(x,y))
Every boy loves some girl does not imply that
some girl is loved by every boy.
U1 - the universe of boys.
U2 - the universe of girls.
Q(x,y) - boy x loves girl y.
∀y: U2(y): (∃x: U1(x): Q(x,y))
∃x: U1(y): (∀y: U2(y): Q(x,y))
le
Examp
If P does not contain x as a free variable
∀x: U(x): (Q(x) ∨ P)
(∀x: U(x): Q(x)) ∨ P
∀x: U(x): (Q(x) ∧ P)
(∀x: U(x): Q(x)) ∧ P
∃x: U(x): (Q(x) ∨ P)
(∃x: U(x): Q(x)) ∨ P
∃x: U(x): (Q(x) ∧ P)
(∃x: U(x): Q(x)) ∧ P
Given: an array a[0..N-1] of length N≥3
Find: i, j, k such that:
i is the index of the greatest element of a;
j is the index of the 2nd greatest element of a;
k is the index of the 3rd greatest element of a.
∃ i,j,k: (0≤i,j,k<N)∧(i≠j)∧(i≠k)∧(j≠k):
( (ai≥aj≥ak) ∧
(∀m: (0≤m<N)∧(m≠i)∧(m≠j)∧(m≠k): ak≥am) )
le
Examp
ambiguous
All elements of an array a of length N are either zero or one
(1)
∀i: 0≤i<N: ( ai=0 ∨ ai=1 )
(2)
(∀i: 0≤i<N: ai=0) ∨ (∀i: 0≤i<N: ai=1)
le
Examp
ambiguous
The elements of arrays a and b are the same (both arrays of length N).
(1)
∀i: 0≤i<N: (ai=bi)
(2)
∀i: 1≤i<N: ((ai=ai-1) ∧ (bi=bi-1))
(3)
(∀i: 1≤i<N: (ai=ai-1)) ∧ (∀i: 0≤i<N: (ai=bi))
(4)
∀i: 0≤i<N: (∃ j: 0≤j<N: (ai=bi) )
le
Examp
They drank two cups of tea because they were warm.
They drank two cups of tea because they were cold.
le
Examp
Go to the shop and buy bread.
If they have eggs, buy 10.
...
Do you have eggs?
Yes.
Then give me 10 pieces of bread.
le
Examp
Quantifiers for Math Reasoning.
Min x: U(x): T(x)
gives the “smallest value of terms T(x)
for all objects x from the universe U“
Min x: False: T(x) is +∞.
( m = (Min i: 0≤i<N: a[i]) )
((∃ i: 0≤i<N: m=a[i]) ∧ (∀ i: 0≤i<N: m≤a[i]))
Quantifiers for Math Reasoning.
Max x: U(x): T(x)
gives the “greatest value of terms T(x)
for all objects x from the universe U“
Max x: False: T(x) is -∞.
Max x: U(x): T(x) = - (Min x: U(x): - T(x))
Min x: U(x): T(x) = - (Max x: U(x): - T(x))
Quantifiers for Math Reasoning.
Anz x: U(x): F(x)
gives the “number of all those objects x
from the universe U for which F(x) holds“
Anz x: False: F(x) is 0.
((Anz x: U(x): F(x)) = 0)
∀x: U(x):¬F(x)
((Anz x: U(x): F(x)) ≥ 0)
∃x: U(x): F(x)
Quantifiers for Math Reasoning.
Given arrays a and b.
Both arrays are of length N.
The elements of both arrays are natural numbers.
(Anz i: 0≤i<N: ai=0) = 0
all elements ai of a are different than 0
(Anz i: 0≤i<N: ai=x) > 0
at least one element ai has the value x (x∈N)
(Anz i: 0≤i<N: ai<x) = (Anz i: 0≤i<N: ai>x)
x is the median value of a
∀x:: ( (Anz i: 0≤i<N: ai=x) = (Anz i: 0≤i<N: bi=x) )
a is a permutation of b
le
Examp
Formalisms can describe computation.
computation
information
computer
Tudor Gîrba
www.tudorgirba.com
creativecommons.org/licenses/by/3.0/
information