Lecture 11
Lecture 11
Functional Logic
Michael Genesereth
Computer Science Department
Stanford University
Motivation
Finite Worlds
n rows x n columns in Friends, Goldrush, Minefinder
Finite Graphs
University Students
Population of a state or country
Countable Worlds
Integers - 1, 2, 3, 4, ...
Strings - "adbyug78377bh", ...
Sequences - [], [a], [b], [a,a], [a,b], [b,a], [b,b], [a,a,a], ...
Sets - {}, {a}, {b}, {a,b}, {{a},{b}}, {{a},{a,b}}, ...
Possibilities
Today
Syntax
Semantics
Properties and Relationships
Examples
Next Time
Fitch Proofs with Induction
After Thanksgiving
Equality
Review
Syntax
Words
knows, loves
Arity
The arity of a function constant or a relation constant is the
number of arguments it takes.
Object Constants: a, b
Unary Function Constant: f
Binary Function Constant: g
Unary Relation Constant: p
Binary Relation Constant: q
Terms
f(a)
f(x)
g(a, y)
g(f(a), g(y,a))
q(a, f(a))
(¬q(a,f(a)))
(p(a) ∧ p(f(a)))
(p(a) ∨ p(f(a)))
(q(x,f(a)) ⇒ q(f(a),x))
(q(x,f(a)) ⇔ q(f(a),x))
Quantified Sentences
Universal sentences assert facts about all objects.
(∀x.(p(x) ⇒ q(x, f(x))))
Existential sentence assert the existence of objects with
given properties.
(∃x.(p(x) ∧ q(x,f(x))))
Quantified sentences can be nested within other
sentences.
(∀x.p(x)) ∨ (∃x.q(x,f(x)))
(∀x.(∃y.q(f(x),y)))
Parentheses
Parentheses can be removed when precedence allows us to
reconstruct sentences correctly.
Herbrand Universe:
{a, b}
Herbrand Base:
Herbrand Universe:
p(a)i = 1 q(a,a)i = 1
p(b)i = 0 q(a,b)i = 0
p(f(a))i = 1 q(a,f(a))i = 0
p(f(b))i = 0 q(a,f(b))i = 1
p(f(f(a)))i = 0 q(b,f(a))i = 0
p(f(f(b)))i = 0 q(b,f(b))i = 1
... ...
Everything Else
All other notions are defined the same as in Relational
Logic.
Successor:
0→1→2→3→4→…
Object Constant: 0
Unary Function Constant: s
Ground Terms: 0, s(0), s(s(0)), …
Examples:
same(0,0)
same(s(0),s(0))
same(s(s(0)),s(s(0)))
…
Same
Definition:
∀x.same(x,x)
∀x.(¬same(0,s(x)) ∧ ¬same(s(x),0))
∀x.∀y.(¬same(x,y) ⇒ ¬same(s(x), s(y)))
Examples:
same(0,0) ¬same(0,s(0)) ¬same(s(0),0)
same(s(0),s(0)) ¬same(0,s(s(0))) ¬same(s(s(0)),0)
same(s(s(0)),s(s(0))) … …
…
Same
Definition:
∀x.same(x,x)
∀x.(¬same(0,s(x)) ∧ ¬same(s(x),0))
∀x.∀y.(¬same(x,y) ⇒ ¬same(s(x), s(y)))
Examples:
same(0,0) ¬same(0,s(0)) ¬same(s(0),0)
same(s(0),s(0)) ¬same(0,s(s(0))) ¬same(s(s(0)),0)
same(s(s(0)),s(s(0))) … …
… ¬same(s(0),s(s(0))) ¬same(s(s(0)),s(0))
¬same(s(0),s(s(s(0)))) ¬same(s(s(s(0))),s(0))
… …
Successor
Positives:
∀y.succ(x,s(x))
Functionality:
∀x.∀y.(succ(x,y) ⇒ less(x,y))
Transitivity:
Irreflexivity:
∀x.¬less(x,x)
Example - Trees
Trees
a a
b a a b
a
a
a
b a
a b
Tree Vocabulary
Object constants: a, b
Binary function constants: cons
a a
b a b a
cons(cons(b,a),a) cons(a,cons(b,a))
Tree Vocabulary
Object constants: a, b
Unary function constants: cons
a a
b a b a
cons(cons(b, a), a) cons(a, cons(b, a))
Examples:
a a
b a a b
Non-Examples:
a a a
b a a b a
a b
Definition
Congruence of atomic trees
congruent(a, a)
congruent(a, b)
congruent(b, a)
congruent(b, b)
Nested Lists:
[a, [a, b], b, [c, d], d]
Linked List:
a b d
a b c d
Representation
Example:
a b c d
cons(a,cons(b,cons(c,cons(d,nil))))
Signature
Object Constants: a, b, c, d, nil
member(b, cons(a,cons(b,cons(c,nil))))
Definition:
∀x.∀y.member(x,cons(x,y)))
∀x.∀y.∀z.(member(x,z) ⇒ member(x,cons(y,z)))
Definition :
∀y.append(nil,y,y)
∀x.∀y.∀z.∀w.(append(y,z,w)
⇒ append(cons(x,y),z,cons(x,w)))
proposition(p)
proposition(q)
proposition(r)
negation(not(x)) ⇔ sentence(x)
conjunction(and(x,y)) ⇔ sentence(x) ∧ sentence(y)
disjunction(or(x,y)) ⇔ sentence(x) ∧ sentence(y)
implication(if(x,y)) ⇔ sentence(x) ∧ sentence(y)
biconditional(iff(x,y)) ⇔ sentence(x) ∧ sentence(y)
sentence(x) ⇔
proposition(x) ∨ negation(x) ∨ conjunction(x) ∨
disjunction(x) ∨ implication(x) ∨ biconditional(x)
Propositional Logic in Functional Logic
proposition(p)
proposition(q)
proposition(r)
negation(not(x)) ⇔ sentence(x)
conjunction(and(x,y)) ⇔ sentence(x) ∧ sentence(y)
disjunction(or(x,y)) ⇔ sentence(x) ∧ sentence(y)
implication(if(x,y)) ⇔ sentence(x) ∧ sentence(y)
biconditional(iff(x,y)) ⇔ sentence(x) ∧ sentence(y)
sentence(x) ⇔
proposition(x) ∨ negation(x) ∨ conjunction(x) ∨
disjunction(x) ∨ implication(x) ∨ biconditional(x)
Basic Idea
(1) Represent Propositional Logic sentences as terms
in Functional Logic.
p∧¬q represented as and(p,not(q))
(2) Write Functional Logic sentences to define the
syntax and semantics of Propositional Logic.
conjunction(and(p,not(q)))
(3) Create Functional Logic proofs of Propositional
Logic metatheorems (e.g. soundness, completeness,
deduction theorem, and so forth).
∀x.∀y.(entails(x,y) ⇒ proves(x,y))
Syntactic Metavocabulary
Object Constants (representing propositions):
p, q, r
Syntactic Metavocabulary
Object Constants (representing propositions):
p, q, r
Function constants (representing logical operators):
not(x) if(x,y)
and(x,y) iff(x,y) These are terms!!
or(x,y)
Syntactic Metavocabulary
Object Constants (representing propositions):
p, q, r
Function constants (representing logical operators):
not(x) if(x,y)
and(x,y) iff(x,y) These are terms!!
or(x,y)
Unary Relation Constants (properties of sentences):
proposition(x) implication(x)
negation(x) biconditional(x)
conjunction(x) sentence(x)
disjunction(x)
Syntactic Metadefinitions
proposition(p)
proposition(q)
proposition(r)
negation(not(x)) ⇔ sentence(x)
conjunction(and(x,y)) ⇔ sentence(x) ∧ sentence(y)
disjunction(or(x,y)) ⇔ sentence(x) ∧ sentence(y)
implication(if(x,y)) ⇔ sentence(x) ∧ sentence(y)
biconditional(iff(x,y)) ⇔ sentence(x) ∧ sentence(y)
sentence(x) ⇔
proposition(x) ∨ negation(x) ∨ conjunction(x) ∨
disjunction(x) ∨ implication(x) ∨ biconditional(x)
Semantic Metavocabulary
Unary Relation Constants (properties of sentences):
valid(x) - validity
contingent(x) - contingency
unsatisfiable(x) - unsatisfiability
valid(or(x,not(x)) ⇔ sentence(x)
Deduction Theorem:
entails(and(x,y),z) ⇔ entails(x,if(y,z))
Rules of Inference
And Introduction:
And Elimination:
Soundness:
∀x.∀y.(proves(x,y) ⇒ entails(x,y))
Completeness:
∀x.∀y.(entails(x,y) ⇒ proves(x,y))
Functional Logic in Functional Logic
Can we define Functional Logic in Functional Logic?
∀x.∀y.(true(relsent(p,x,y)) ⇔ p(x,y))
Beliefs
Can we use this "metalevel" approach to relate the truth
of sentences described in a metalanguage to sentences
describing those sentences?
∀x.(believes(john,x) ⇔ true(x))
Disinformation
Can we use this "metalevel" approach to relate the truth
of sentences described in a metalanguage to sentences
describing those sentences?
∀x.(says(john,x) ⇒ true(x))
Puzzle
You are taken prisoner by a drug cartel and told: If you
tell a lie, we will hang you. If you tell the truth, we will
shoot you. What do you say?