67
Introduction to Logic Herbrand Logic Michael Genesereth Computer Science Department Stanford University

Introduction to Logic Herbrand Logicintrologic.stanford.edu/lectures/lecture_11.pdf · Introduction to Logic Herbrand Logic Michael Genesereth Computer Science Department Stanford

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

  • Introduction to LogicHerbrand Logic

    Michael GeneserethComputer Science Department

    Stanford University

  • something or other

    Motivation

  • Syntax

  • Wordsa, b, g, p

    Termsg(a,a)

    Sentences∀x.(p(x) ⇒ p(g(x,x)))

    Components of Syntax

  • Words are strings of letters, digits, and occurrences of the underscore character.

    Variables begin with characters from the end of the alphabet (from u through z).

    u, v, w, x, y, z

    Constants begin with digits or letters from the beginning of the alphabet (from a through t).

    a, b, c, 123, comp225, barack_obama

    Words

  • Object constants represent objects.

    joe, stanford, usa, 2345

    Function constants represent functions.

    father, mother, age, plus, times

    Relation constants represent relations.

    knows, loves

    Constants

  • The arity of a function constant or a relation constant is the number of arguments it takes.

    Unary function or relation constant - 1 argument

    Binary function or relation constant - 2 arguments

    Ternary function or relation constant - 3 arguments

    n-ary function or relation constant - n arguments

    Arity

  • A signature consist of a set of object constants, a set of function constants, and a set of relation constants together with a specification of arity for the function constants and relation constants.

    Object Constants: a, b

    Unary Function Constant: fBinary Function Constant: g

    Unary Relation Constant: pBinary Relation Constant: q

    Signatures

  • A term is either a variable, an object constant, ora functional term (defined shortly).

    Terms represent objects.

    Terms are analogous to noun phrases in natural language.

    Terms

  • A functional term is an expression formed from an n-ary function constant and n terms enclosed in parentheses and separated by commas.

    f(a)f(x)

    g(a, y)

    Functional terms are terms and so can be nested.

    g(f(a), g(y,a))

    Functional Terms

  • Three types of sentences in Herbrand Logic:

    Relational sentences - analogous to the simple sentences in natural language

    Logical sentences - analogous to the logical sentences in natural language

    Quantified sentences - sentences that express the significance of variables

    Sentences

  • A relational sentence is an expression formed from an n-ary relation constant and n terms enclosed in parentheses and separated by commas.

    q(a, f(a))

    Relational sentences are not terms and cannot be nested in terms or relational sentences.

    No! q(a,q(a,y)) No!

    Relational Sentences

  • Logical sentences in Herbrand Logic are analogous to those in Propositional Logic.

    (¬q(a,b))(p(a) ∧ p(b))(p(a) ∨ p(b))(q(x,y) ⇒ q(y,x))(q(x,y) ⇔ q(y,x))

    Logical 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)))

    Quantified Sentences

  • Parentheses can be removed when precedence allows us to reconstruct sentences correctly.

    Precedence relations same as in Propositional Logic with quantifiers being of higher precedence than logical operators.

    ∀x.p(x) ⇒ q(x,x) → (∀x.p(x)) ⇒ q(x,x)∃x.p(x) ∧ q(x,x) → (∃x.p(x)) ∧ q(x,x)

    Parentheses

  • Semantics

  • The Herbrand base for a Herbrand language is the set of all ground relational sentences that can be formed from the vocabulary of the language.

    Herbrand Base

  • Object Constants: a, bUnary Relation Constant: pBinary Relation Constant: q

    Herbrand Base:

    {p(a), p(b), q(a,a), q(a,b), q(b,a), q(b,b)}

    Herbrand Base Without Functions

  • Object Constants: aUnary Function Constant: fUnary Relation Constant: p

    Herbrand Base:

    {p(a), p(f(a)), p(f(f(a))), …}

    Herbrand Base With Functions

  • A truth assignment is an association between ground atomic sentences and the truth values true or false. As with Propositional Logic, we use 1 as a synonym for true and 0 as a synonym for false.

    p(a)i = 1 p(b)i = 0 q(a,a)i = 1 q(a,b)i = 0 q(b,a)i = 1 q(b,b)i = 0

    Truth Assignments

  • All other notions are defined the same as in Relational Logic.

    The main difference is that now we have truth assignments that are infinitely large and there are infinitely many of them. This means that it is no longer possible in general to determine properties and relationships like logical entailment in finite time.

    Everything Else

  • Example - Peano Arithmetic

  • In Peano Arithmetic, we are concerned with all of the natural numbers, not just a finite subset, and functions do not wrap around as in Modular Arithmetic.

    0+0=01+0=1 2+0=2 3+0=30+1=11+1=2 2+1=3 3+1=50+2=21+2=3 2+2=4 3+2=60+3=31+3=4 2+3=5 3+3=7

    … … … …

    Peano Arithmetic

  • Object Constants: 0, 1, 2, …

    Ground Terms: 0, 1, 2, …

    Possible Representations

  • Object Constants: 0, 1, 2, …

    Ground Terms: 0, 1, 2, …

    Object Constant: 0Unary Function Constant: s

    Ground Terms: 0, s(0), s(s(0)), …

    Possible Representations

  • Object Constant: 0

    Unary Function Constant: s

    Binary Relation Constant: same - the first and second arguments are identical

    Ternary Relation Constant: plus - the third argument is the sum of the first two times - third argument is the product of the first two

    Signature

  • Enumerating ground relational data impossible

    same(0,0) plus(0,0,0) times(0,0,0)¬same(0,s(0)) ¬plus(0,0,s(0)) ¬times(0,0,s(0))¬same(0,s(s(0))) ¬plus(0,0,s(s(0))) ¬times(0,0,s(s(0)))

    … … …

    Solution - write logical and quantified sentences

    Axiomatization

  • Definition:∀x.same(x,x)

    ∀x.(¬same(0,s(x)) ∧ ¬same(s(x),0))

    ∀x.∀y.(¬same(x,y) ⇒ ¬same(s(x), s(y)))

    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(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,s(0)) same(0,0) ¬same(0,s(s(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,s(0)) same(0,0) ¬same(0,s(s(0))) same(s(0),s(0)) … same(s(s(0)),s(s(0))) ¬same(s(0),s(s(0)))

    … ¬same(s(0),s(s(s(0)))) …

    Same

  • Identity:∀y.plus(0,y,y)

    Successor:

    ∀x.∀y.∀z.(plus(x,y,z)⇒ plus(s(x),y,s(z)))

    Functionality:

    ∀x.∀y. ∀z.∀w.(plus(x,y,z) ∧ plus(x,y,w) ⇒ same(z,w)

    Addition

  • Identity:∀y.times(0,y,0)

    Successor:

    ∀x.∀y.∀z.(times(x,y,z) ∧ plus(y,z,w) ⇒ times(s(x),y,w))

    Functionality:

    ∀x.∀y.∀z.∀w.(times(x,y,z) ∧ times(x,y,w) ⇒ same(z,w)

    Multiplication

  • A polynomial equation is an algebraic expression composed using only addition and multiplication and exponentiation with fixed exponents.

    3x2 + 2y = 2z3

    A natural Diophantine equation is a polynomial in which the values of variables are restricted to natural numbers.

    x = 2y = 2z = 2

    Diophantine Equations

  • Diophantine equation:

    3x2 = 1

    Diophantine equation in Peano Arithmetic:

    ∀x.∀y.∀z. (times(x,x,y) ∧ times(s(s(s(0))),y,z) ⇒ same(z,s(0)))

    Diophantine equation with “syntactic sugar”:

    ∀x.∀y.∀z.(x*x=y ∧ 3*y=z ⇒ z=1) ∀x.∀y.∀z.(3*x*x=1)

    Diophantine Equations in Peano

  • Example - Linked Lists

  • Flat Lists:[a, b, c, d]

    Nested Lists:[a, [a, b], b, [c, d], d]

    Linked List:

    a b

    a b c d

    d

    Linked Lists

  • Example

    Representation as Term

    cons(a,cons(b,cons(c,cons(d,nil))))

    a b c d

    Representation

  • Object Constants: a, b, c, d, nil

    Binary Function Constant: cons

    Binary Relation Constants: member, among

    Ternary Relation Constant: append

    Signature

  • Example: 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)))

    Membership

  • Example: append(cons(a,cons(b,nil)), cons(c,cons(d,nil)), cons(a,cons(b,cons(c,cons(d,nil)))))

    Definition :∀x.∀y.append(nil,y,y)∀x.∀y.∀z.∀w.(append(x,y,w) ⇒ append(cons(x,y),z,cons(x,w)))

    Concatenation

  • Example:among(c,cons(a, cons(cons(b,cons(c,nil)), cons(d,nil))))

    Definition:

    ∀x.among(x,x) ∀x.∀y.∀z.(among(x,y) ∨ among(x,z) ⇒ among(x,cons(y,z)))

    Containment

  • Example - Pseudo English

  • Good Sentences: Mary likes Pat. Mary likes Pat and Quincy. Pat and Quincy like Mary.

    Bad Sentences: Mary Pat likes. Likes and Mary Pat Quincy.

    Pseudo English

  • ::= ::= ::= "and" ::= ::= ”mary" | ”pat" | ”puincy" ::= "like" | "likes"

    Backus Naur Form

  • np(x) ∧ vp(y) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w)

    verb(x) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z)

    noun(mary)noun(pat)noun(quincy)

    verb(like)verb(likes)

    Logical Grammar

  • np(x) ∧ vp(y) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w)

    verb(x) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z)

    noun(mary)noun(pat)noun(quincy)

    verb(like)verb(likes)

    Logical Grammar

  • np(x) ∧ vp(y) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w)

    verb(x) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z)

    noun(mary)noun(pat)noun(quincy)

    verb(like)verb(likes)

    Logical Grammar

  • np(x) ∧ vp(y) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w)

    verb(x) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z)

    noun(mary)noun(pat)noun(quincy)

    verb(like)verb(likes)

    Logical Grammar

  • np(x) ∧ vp(y) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w)

    verb(x) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z)

    noun(mary)noun(pat)noun(quincy)

    verb(like)verb(likes)

    Logical Grammar

  • Sentences: √ Mary likes Pat. √ Mary likes Pat and Quincy. √ Pat and Quincy like Mary.

    Not Sentences: × Mary Pat likes. × Likes and Mary Pat Quincy.

    Examples

  • Sentences: Mary likes Pat. Mary likes Pat and Quincy. Pat and Quincy like Mary.

    Allowed but not sentences in natural English: Mary likes Pat. Pat and Quincy likes Mary.

    How can we enforce subject-verb number agreement?

    Glitch

  • np(x,w) ∧ vp(y,w) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x,0)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w,1)

    verb(x,w) ∧ np(y,v) ∧ append(x,y,z) ⇒ vp(z,w)

    noun(mary)noun(pat)noun(quincy)

    verb(like,1)verb(likes,0)

    Augmented Logic Grammar

  • np(x,w) ∧ vp(y,w) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x,0)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w,1)

    verb(x,w) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z,w)

    noun(mary)noun(pat)noun(quincy)

    verb(like,1)verb(likes,0)

    Augmented Logic Grammar

  • np(x,w) ∧ vp(y,w) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x,0)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w,1)

    verb(x,w) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z,w)

    noun(mary)noun(pat)noun(quincy)

    verb(like,1)verb(likes,0)

    Augmented Logic Grammar

  • np(x,w) ∧ vp(y,w) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x,0)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w,1)

    verb(x,w) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z,w)

    noun(mary)noun(pat)noun(quincy)

    verb(like,1)verb(likes,0)

    Augmented Logic Grammar

  • np(x,w) ∧ vp(y,w) ∧ append(x,y,z) ⇒ sentence(z)

    noun(x) ⇒ np(x,0)noun(x) ∧ noun(y) ∧ append(x,and,z) ∧ append(z,y,w) ⇒ np(w,1)

    verb(x,w) ∧ np(y) ∧ append(x,y,z) ⇒ vp(z,w)

    noun(mary)noun(pat)noun(quincy)

    verb(like,1)verb(likes,0)

    Augmented Logic Grammar

  • Example - Metalevel Logic

  • Basic idea: represent expressions in Propositional Logic as terms in Herbrand Logic, write Herbrand sentences to define basic concepts of Propositional Logic, prove metatheorems.

    NB: We can extend to Herbrand Logic as well. The formalization is messier, and some nasty problems need to be handled (notably paradoxes).

    Metalevel Logic

  • Object Constants (propositions) p, q, r

    Syntactic Metavocabulary

  • Object Constants (propositions) p, q, r

    Function constants not(p) if(p,q) and(p,q) iff(p,q) or(p,q)

    Syntactic Metavocabulary

  • Object Constants (propositions) p, q, r

    Function constants not(x) if(x,y) and(x,y) iff(x,y) or(x,y)

    Relation Constants proposition(x) implication(x) negation(x) biconditional(x) conjunction(x) sentence(x) disjunction(x)

    Syntactic Metavocabulary

  • 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)equivalence(iff(x,y)) ⇔ sentence(x) ∧ sentence(y)

    sentence(x) ⇔ proposition(x) ∨ negation(x) ∨ conjunction(x) ∨ disjunction(x) ∨ implication(x) ∨ biconditional(x)

    Syntactic Metadefinitions

  • And Introduction:

    ∀x.(sentence(x) ∧ sentence(y) ⇒ ai(x,y,and(x,y)))

    And Elimination:

    ∀x.(sentence(x) ∧ sentence(y) ⇒ ae(and(x,y),x))∀x.(sentence(x) ∧ sentence(y) ⇒ ae(and(x,y),y))

    Rules of Inference

  • Validity of Axiom Scemata:

    valid(or(x,not(x)) ⇔ sentence(x)

    Soundness:

    proves(x,y) ⇔ entails(x,y)

    Deduction Theorem:

    proves(and(x,y),z) ⇔ proves(x,implies(y,z))

    Metatheorems

  • In similar fashion, we can axiomatize Herbrand Logic in Herbrand Logic. But with some care to avoid paradoxes (sentences that are both true and false) and self-contradictory terms.

    Paradox:This sentence is false.

    Self-contradictory terms:This set of all sets that do not contain themselves

    Herbrand Logic in Herbrand Logic