The big picture. Humans can use logical reasoning to draw conclusions and prove things. Is it possible to teach computer
Computation Club: Predicate calculus The big picture Humans can use logical reasoning to draw conclusions and prove things. Is it possible to teach computers to do this automatically? Yes it is! We just need a language for writing logical statements and rules for manipulating them.
The main pieces ● ● ● ● ● ●
●
●
Predicate calculus is a simple formal language for making statements about the world. Clausal form is a restricted subset of predicate calculus. Any predicate calculus statement can be converted to clausal form via a series of mechanical transformations. Two matching clausal form statements can be combined to make a new statement by using the resolution rule. Even if two statements don’t exactly match, they can sometimes be made to match by using the unification algorithm. We can prove a statement ( theorem ) by assuming some initial statements ( axioms ), then assuming the negation of the theorem, then using resolution to get to a contradiction . For example, we can use this technique to solve the “a man, a wolf, a goat and a cabbage crossing the river” puzzle, by expressing the rules as axioms and using them to prove the theorem that everyone can reach the other side. All of this can be done automatically by a computer.
Predicate calculus (a.k.a. “firstorder logic”) Syntax Terms : constants, variables, functions on terms Formulas : predicates on terms (“atomic formula”), ∧ (“and”), ∨ (“or”), → (“implies”), ~ (“not”), ∀ (“for all”), ∃ (“there exists”)
Semantics ● ● ●
●
●
●
The logical connectives (∧, ∨, →, ~) have a builtin meaning (standard truth tables) The quantifiers (∀, ∃) have a builtin meaning too The other symbols don’t mean anything by themselves ○ e.g. we can’t say whether the formula “∀x(∀y(P(x, f(y))))” is true or false, because it depends what “P” and “f” mean We need an interpretation to give meaning to the predicates and functions ○ interpretation = a “universe” of values + an interpretation function ○ the interpretation function maps predicates onto relations (i.e. booleanvalued functions) on U, functions onto functions in U > U ○ think of the interpretation function as “the method definitions” for the predicate and function names: each predicate is implemented as a method that returns booleans, each function is implemented as a method that returns values satisfiable means “this formula is true under some interpretation” ○ e.g. “∀x(∃y(P(x, y)))” is true when P means “less than” and the universe is integers valid means “this formula is true under all interpretations” ○ e.g. “∀x(P(x) ∨ ~P(x))” is true regardless of what P means
See https://en.wikipedia.org/wiki/Firstorder_logic for more details.
Implies “X → Y” means “X implies Y”, or “if X then Y”: X
Y
X → Y
0
0
1
0
1
1
1
0
0
1
1
1
e.g. assuming the statement “it’s night time → it’s dark” is true, then: ● if it’s night time then it must be dark; ● if it’s not dark then it must not be night time; ● if it’s not night time then we don’t know whether it’s dark; ● if it’s dark then we don’t know whether it’s night time. See https://en.wikipedia.org/wiki/Material_conditional for more details.
Clausal form (a.k.a. “conjunctive normal form”) A formula in clausal form contains only ∨ and ~ and atomic formulas, e.g. “A(x) ∨ ~B(x) ∨ C(y)”. We can convert any predicate calculus formula into clausal form by applying some mechanical transformations: ● eliminate → ● move ~ down to atomic formulas ● eliminate ∃ ( Skolemization ) ● move ∀ left ● move ∨ down to atomic formulas ● eliminate ∧ by breaking into separate clauses ● remove all ∀ (they are implied) After these transformations, our entire “knowledge base” is represented as one big conjunctive normal form (CNF) expression. (We know that the first clause is true and the second clause is true and the third clause is true and …) See https://en.wikipedia.org/wiki/Conjunctive_normal_form for more details.
Transformations De Morgan’s laws for ∧ and ∨: ● ~(X ∧ Y) ≡ (~X ∨ ~Y) ● ~(X ∨ Y) ≡ (~X ∧ ~Y) for ∀ and ∃: ● ∀x(P(x)) ≡ ~∃x(~P(x)) ● ∃x(P(x)) ≡ ~∀x(~P(x)) See https://en.wikipedia.org/wiki/De_Morgan%27s_laws for more details
Implies X → Y ≡ ~(X ∧ ~Y) ≡ ~X ∨ Y
(from the truth table) (by de Morgan’s laws)
Skolemization Skolemization lets us remove existential quantifiers by replacing existentiallyquantified variables with functions. For example: ● in English: “every integer has another integer that’s greater than it” ● in predicate calculus: ∀x(∃y(LT(x, y))) ○ interpretation: x and y are integers, “LT” means “less than” ● but this means that there’s some way to find a larger number than any x, e.g. x + 1 ● so we can write ∀x(LT(x, f(x))) instead, where f is a function that finds a larger number than x somehow, e.g. f(x) = x + 1 ● this Skolemized formula is satisfiable if and only if the original is See https://en.wikipedia.org/wiki/Skolem_normal_form for more details.
Resolution Say we have two clauses that we know are true: X ∨ A ∨ B ∨ C and ~X ∨ D ∨ E ∨ F We don’t know what value X has, but atomic formulas have boolean values, so we know it must be either false or true . So there are two possibilities: ● if X is false, then A ∨ B ∨ C must be true (for the first clause to be true) ● if X is true, then D ∨ E ∨ F must be true (for the second clause to be true) So either A ∨ B ∨ C is true, or D ∨ E ∨ F is true. In other words, we’ve created a third clause: A ∨ B ∨ C ∨ D ∨ E ∨ F This is resolution , and it always works when we have two clauses “X ∨ …” and “~X ∨ …”. To put clauses in a suitable form for resolution, we sometimes have to use unification , i.e. find assignments for variables so that two clauses match in the right way. For example, if we want to use unification on the clauses “P(x) ∨ Q(x)” and “~P(42) ∨ R(y)” we can unify the free variable x with the constant 42 to make the first clause “P(42) ∨ Q(42)”, then apply resolution to get “Q(42) ∨ R(y)”. See https://en.wikipedia.org/wiki/Resolution_(logic) for more details.
Proof ● ● ●
●
Start with some formulas we know are true ( axioms ) Add the negation of the formula we want to prove ( theorem ) Use resolution to get to two contradictory clauses ○ e.g. prove that Socrates is mortal ○ axioms: ■ all humans are mortal ● predicate calculus: ∀x(HUMAN(x) → MORTAL(x)) ● clausal form: ~HUMAN(x) ∨ MORTAL(x) ■ Socrates is a human ● predicate calculus: HUMAN(“Socrates”) ● (that’s already clausal) ○ theorem: ■ Socrates is mortal ● predicate calculus: MORTAL(“Socrates”) ● (that’s already clausal) ○ negation of theorem: ■ Socrates is not mortal ● clausal form: ~MORTAL(“Socrates”) ○ proof: ■ resolve ~MORTAL(“Socrates”) with ~HUMAN(x) ∨ MORTAL(x) ● unify x = “Socrates” to make clauses match ○ ~MORTAL(“Socrates”) ○ ~HUMAN(“Socrates”) ∨ MORTAL(“Socrates”) ● result: ~HUMAN(“Socrates”) ■ we have both HUMAN(“Socrates”) and ~HUMAN(“Socrates”), a contradiction Because negating the theorem produces a contradiction, the theorem must be true
This process is easy to automate. Brute force strategy: try resolving all possible pairs of formulas until you manage to generate a new one, then repeat until you reach a contradiction or can’t generate any more. (Smarter strategies exist.)