Professional Documents
Culture Documents
Parts of a Grammar:
• NonTerminal Turns into a string of the stated type
• Terminal Actual characters in the resulting string
• “is a”
• | “or”
Formula:
Context Free Grammar of Syntax
eg "x, $y, y=x+1 evaluates to true/false
Formula
Term: eg x+1 evaluates to an object Universe
Quantifier
• Formula Relation | Connector | Quantifier
• Relation Loves(Term,Term) | R(Term,Term) | P(Term) | … "Variable, Formula
(Term > Term) | (Term ≥ Term) | (Term = Term) | ...
• Connector (Formula Formula ) | (Formula Formula ) | b Quantifier
(Formula iff Formula ) | (Formula Formula ) | …
Formula $ Variable, Formula
• Quantifier "Variable, Formula | $Variable, Formula
g Connector
• Term Variable | Constant | Function
• Variable x | y | z | b | g | x1 | x2 | x3 | … (Formula Formula )
• Constant c | d | c1 | c2 | c3 | …
0 | 1 | 2 | ...
Relation Relation
• Function f (Term,Term) | g(Term,Term) | f1(Term,Term) | …
Loves(Term,Term) (Term > Term)
(Term + Term) , (Term Term)
VariableVariable Variable Variable
" b ,$ g ,(Loves( b , g ) ( x > y ) )
• Formula Relation | Connector | Quantifier
• Relation Loves(Term,Term) | R(Term,Term) | P(Term) | … Quantifier
(Term > Term) | (Term ≥ Term) | (Term = Term) | ...
• Connector (Formula Formula ) | (Formula Formula ) |
(Formula iff Formula ) | (Formula Formula ) | …
Formula
"Variable, Formula
• Quantifier "Variable, Formula | $Variable, Formula
•
(Term + Term) , (Term Term)
g Connector
"b, $ g, (Loves(b,g) (x>y))
This is a formula. (Formula Formula )
Lets prove it by parsing it with the
Relation Relation
context free grammar.
Loves(Term,Term) (Term > Term)
VariableVariable Variable Variable
• Formula Relation | Connector | Quantifier
• Relation Loves(Term,Term) | R(Term,Term) | P(Term) | … Quantifier
(Term > Term) | (Term ≥ Term) | (Term = Term) | ...
• Connector (Formula Formula ) | (Formula Formula ) |
(Formula iff Formula ) | (Formula Formula ) | …
Formula
"Variable, Formula
• Quantifier "Variable, Formula | $Variable, Formula
•
(Term + Term) , (Term Term)
g Connector
"b, $ g, (Loves(b,g) (x>y))
This is a formula. (Formula Formula )
Lets prove it by parsing it with the
Relation Relation
context free grammar.
Loves(Term,Term) (Term > Term)
VariableVariable Variable Variable
It is Meta Syntax
We use α to talk about
an arbitrary Predicate logic formula.
We use α(x,y) to indicated that it has two
free variables x and y.
Closure of the Syntax
A set S is said to be closed
under an operation f iff Complex Numbers
"x,yS, f(x,y) S
+ Reals
Integers Y Y N N
Rationals Y Y Y N
Reals Y Y Y Y/N x+y
Complex Y Y Y Y xy
x/y (y0) Rationals
x (x0)
x Integers
x,y 23
Closure of the Syntax
A set S is said to be closed
under an operation f iff Integers
"x,yS, f(x,y) S ½
Suppose you want to make the integers.
• Start by adding zero
• Close it under successor
ie if x is in the set, then add x+1
-1,-2,-3,…
• Close it under addition
ie if x&y are in the set add x+y
…
This does not add non-integers 6
Neither does it add negative integers. 5
• Close it under subtraction
• Close it under division 4
oops not allowed. 3
2
1
0 24
Closure of the Syntax
A set S is said to be closed
under an operation f iff Wedding Party
"x,yS, f(x,y) S
Suppose you want to make wedding list
• Start by adding the bride and groom.
• Close it under friend function
ie if x is invited,
then you must invite
every friend(x)
• It may be a big wedding.
25
Closure of the Syntax
A set S is said to be closed Well Formed Terms
under an operation f iff (type object):
"x,yS, f(x,y) S
Suppose you want to make ((0+s(0)) s(s(0)))
the set of well formed terms (0+s(0))
…
• Start by adding
variables and constants 0 s(s(s(s(0))))
• Close it under functions s(s(s(0)))
f, g, f1, f2, f3, … s s(s(0))
+, -, , /… s(0)
ie if t1 and t2 are terms, 0
then so is f(t1,t2) and (t1+t2) (f(x,y) + g(x,y))
/c
• You might want ((x+y)z) (f(x,y) + g(x,y))
positive integers. f(x,y) g(x,y) (x+y)
c, d, c1, c2, c3, ...
x, y, z, x1, x2, x3, …
26
Closure of the Syntax
A set S is said to be closed Well Formed
under an operation f iff Formulas
"x,yS, f(x,y) S (Type true/false)
Suppose you want to make
the set of well formed formulas
• Take each predicates/relations:
P, A, B, P1, P2, P3, =, >, <, …
Apply it to each well formed term.
ie if t1 and t2 are terms,
then P(t1,t2) and (t1<t2)
are formulas.
Well Formed Terms
…
s(s(s(s(s(0)))))
s(s(s(s(0))))
s(s(s(0)))
s(s(0))
((0+s(0))s(s(0))) = s(s(0)))
s(0)
0 (f(x,y)+g(x,y)) < z
(f(x,y) + g(x,y))
/c
((x+y)z) (f(x,y) + g(x,y))
f(x,y) g(x,y) (x+y)
P1(x3,z)
c, d, c1, c2, c3, ...
x, y, z, x1, x2, x3, …
P(x) 27
Closure of the Syntax
A set S is said to be closed Well Formed
under an operation f iff Formulas
"x,yS, f(x,y) S (Type true/false)
Suppose you want to make
the set of well formed formulas $z "x ((P(x) P1(x3,z))
• Take each predicates/relations:
"x (P(x) P1(x3,z))
P, A, B, P1, P2, P3, =, >, <, …
Apply it to each well formed term. P(x) iff P1(x3,z)
• Close it under connectors ((P(x) P1(x3,z))
, , , , iff, ,
(f(x,y)+g(x,y))<z)
ie if P1 and P2 are formulas,
then so is (P1P2) (P(x) P1(x3,z))
• Close it under quantifiers
((0+s(0))s(s(0))) = s(s(0)))
" and $
ie if P(x,y) is a formula, (f(x,y)+g(x,y)) < z
then so is "x P(x,y) & $x P(x,y) P1(x3,z)
P(x) 28
Parsing of the Syntax
Is it Well Formed?:
Given a string of characters
Determine if it is a well formed
Predicate logic formula.
$z "x ((P(x) P1(x3,z))
Recall the Contest Free Grammar
"x (P(x) P1(x3,z))
• S $zS | "xS | (TT) | P1(T,T) | P(T) | …
• T f(T,T) | (T+T) | x | x3 | z
Unambiguous:
This parsing (way of constructing)
must be unique. (P(x) P1(x3,z))
So that meaning is well defined.
P1(x3,z)
Parsing (Compiling): (See EECS2001)
P(x)
Given a sting, build its parse tree.
x3 x z 29
Lets do an easier example.
Parsing of the Syntax
Input: A string of brackets.
Output: Each “(”, “{”, or “[” must be paired
with a matching “)”, “}”, or “[”.
Contest Free Grammar:
• S [S] | (S) | {S} | SS | emptystring
[()(( )
Stack
[(
Parsing of the Syntax
Input: A string of brackets.
Output: Each “(”, “{”, or “[” must be paired
with a matching “)”, “}”, or “[”.
Loop Invariant: Prefix has been read.
• Matched brackets are matched and removed.
• Unmatched brackets are on the stack.
No! True.
Who said anything But it does say that every value
about division? has a multiplicative inverse,
which can be used for divisions.
Formula
Quantifier
"Variable, Formula
b Quantifier
$ Variable, Formula
g Connector
(Formula Formula )
Relation Relation
Loves(Term,Term) (Term > Term)
We will
define and
algorithm
for doing
this.
Semantics (Meaning?)
I dare you! We will also study
It is undecidable informal and formal
given a Predicate formula finite length proofs that
to know whether it is true. formulas are valid
i.e. there is no algorithm! (ie true in every universe)
This will add more meaning.
M: The Model/Universe/Interpretation
Bound Free
Local variable Input Parameter
No specific value Value provide by user
[ "i $y R( y,i) x, ]
A(x,y)
F(obj x, obj y)
A(x,y)
loop i {objects} checking true for all
loop y {objects} checking true for some
R(x,y,i)
"i α(i) is true iff α(i) is true for every value i.
$y α(y) is true iff α(y) is true for some value y.
Free and Bound Variables
• Free Variables x, y, z, x1, x2, x3, …
Free
Input Parameter
Value provide by user
α ≡ “[ "i $y R( y,i) x, ]
A(x,y)
• The truth of a formula depends on ”these free values.
• Let α denote the Predicate formula.
Note ‘α’ is not in the syntax. It is in a “meta” language.
• We use α(x,y) to indicate that x and y are its free variables.
• We use α(5,6) to denote α with 5 and 6 replacing x and y.
α(5,6) ≡ ["i $y R(5,y,i)] A(5, 6)
α(f(a)+b, ab) ≡ ["i $y R(f(a)+b,y,i)] A(f(a)+b, ab)
• Another standard notation is
• A formula with no free variables is called a sentence/closed.
Free Variables and Models
• Free Variables x, y, z, x1, x2, x3, …
Free
Input Parameter
Value provide by user
α= “[ "i $y R( y,i) x, ]
A(x,y)
”
Free Variables and Models
• Free Variables x, y, z, x1, x2, x3, …
Free
Input Parameter
Value provide by user
α = “[ "i $y R( y,i) x, ]
that
• We use α(x,y) to indicate A(x,y)
x and y are its free variables.
” 6 replacing x and y.
• We use α(5, 6) to denote α with 5 and
= ["i $y R(5,y,i)] A(5, 6)
• Another standard notation is
Free Variables and Models
• Free Variables x, y, z, x1, x2, x3, …
Free
Input Parameter
Value provide by user
α = “[ "i $y R( y,i) x, ]
that
• We use α(x,y) to indicate A(x,y)
x and y are its free variables.
” f(a)+b and ab replacing x and y.
• We use α(f(a)+b, ab) to denote α with
= ["i $y R(f(a)+b,y,i)] A(f(a)+b, ab)
• Another standard notation is
Free Variables and Models
• Free Variables x, y, z, x1, x2, x3, …
Free
Input Parameter
Value provide by user
" [ [ "i $y R( y,i) x, ]
A(x,y)
• A formula is said to be Valid ]
if it is true for every setting of the free values.
You can imagine a big forall over the values of the free variables.
Free Variables and Models
Back up a minute! The model M:
The model defines many things. decided three ways:
• The universe of objects • It might be understood that we are
– Integers, or reals, or … working over the integers and that
• How functions are 45=20 and ½=??
interpreted • Input: Set by user
– 4+5, “Hi”+“there” - Truth of ½=0.5 depends on M.
Who decides this? • Free: "M
- Formula needs to be true
for “every” model.
Free Variables and Models
Definitely true!
There is a value 5
and its bigger than 4
Don’t confuse this with
$x ( x=5 x4 )
Free Variables and Models
xx=5 $x
x xx4 x=5 $y y4
Free Bound
The two x are Equivalent and more
separate variables. clear formula.
Free Variables and Models
4
x $y y4
"M [ " [ x=5 ]
]
True only Always
when x is true.
given the
value 5. True only when
M defines and 4
appropriately.
Formula Truth
(An Infinite Recursive Algorithm)
Semantic = Meaning Values
• Assign true/false to each formula
– "b $g Love(b,g) ≡ true
As I said,
this is not valid because
there are models in which
is it not true.
Indeed
No.
Proofs must be
finite in length.
Formula Truth
(An Infinite Recursive Algorithm)
P(x) (P(x) R(f(x),z))
A ( A B)
If y$ is really fixed,
it should work for every x.
y y
T T
T T
x x
T T
T T
Skolem Functions y$(x)
$y, "x, α(x, y) "x, $y, α(x, y)
α(x, y$)
If y$ is really fixed,
it should work for every x.
y y
T T
T T
x x
T T
T T
Skolem Functions y$(x)
$y, "x, α(x, y) "x, $y, α(x, y)
α(x, y$) α(x, y$(x))
What about here?
T T
T T
x x
T T
T T
Skolem Functions y$(x)
$y, "x, α(x, y) "x, $y, α(x, y)
≡ ≡
$ [ " α(x, y$) ] $ [" α(x, y$ (x))
Implied
single fixed value fixed function
These Skolem same value/function
must work for every x.
y y
T T
T T
x x
T T
T T
Skolem Functions y$(x)
$y, "x, α(x, y) "x, $y, α(x, y)
≡ ≡
"M $ [ " α(x, y$) ] $
"M [" α(x, y$ (x))
Implied
single fixed value fixed function
T T
T T
x x
T T
T T
Skolem Functions y$(x)
Predicate logic syntax has
• Terms that represent objects/elements
• Formulas/formula that evaluate to true/false.
Objects/Elements UM: Might be U={3,Bob,banana,…}
Terms (type object):
• Bound Variables: "x $y, z, x1, x2, x3, …
• Free Variables x, y, z, x1, x2, x3, …
• Constants M: c, d, c1, c2, c3, 0, 1, 2, ... Closed:
• Functions M: f, g, f1, f2, f3, +, -, , /…
f(t1,t2), t1+t2, …
• Skolem Functions y$, x$, z$, y$:α, y$:β, … y$(x) , …
Yes the rules of going from one line to the next with x´
is different than that with x.
Deduction Reminding Variables x´
Formal Proof:
Goal is to prove α(x)β(x) In the indented block,
______ α(x´) assumption
______ … x´ is a fixed but
______ β(x´) arbitrary value.
α(x)β(x) conclusion In the conclusion,
x is free variable.
ie. implied "x
Deduction Reminding Variables x´
Formal Proof:
Goal is to prove α(x)β(x)
______ α(x´) assumption
______ …
______ β(x´)
α(x)β(x) conclusion
We write
M[a]⊧
to mean that formula
is true in model M
and assignment a.
Sound and Complete
True vs Tautology vs Valid:
A Tautology is a formula that evaluates to true
under setting of the variables.
Eg: (PQ) P.
Namely if P and Q are true then P is true.
Same except
generally, (i-2i-1)⇒i
involves a single (or few) steps
while Γ⊢ could be a long proof.
Sound and Complete
Quantifier Closure:
• Sound Requires:
Rule “If i-2 and i-1 are lines in your proof, then you can add line i”
requires “If i-2 and i-1 are valid, then so is i”
ie (i-2i-1)⇒i requires (i-2i-1)i
Careful! homework