Download Article on Propositional Calculus and Boolean Logic: Syntax, Semantics, and Applications - and more Study notes Computer Science in PDF only on Docsity!
Artificial Intelligence
Propositional Calculus
First-order Predicate Logic
P´eter Moln´ar
Objectives
in.brief
- Definition of Propositional Calculus: Syntax and Semantics
- Proof of logical equivalence using truth tables and identities
- Application of our new knowledge in exercises
in.depth
- Definition of Propositional Calculus: Syntax and Semantics
- Proof of logical equivalence using truth tables and identities
- Application of our new knowledge in exercises
<in:action>
- Definition of Propositional Calculus: Syntax and Semantics
- Proof of logical equivalence using truth tables and identities
- Application of our new knowledge in exercises.
George Boole lived from 1815 to 1864 Boole approached logic in a new way reducing it to a sim- ple algebra, incorporating logic into mathematics. He also worked on differential equations, the calculus of finite dif- ferences and general methods in probability.
- http://www-history.mcs.st-andrews.ac.uk/ history/Mathematicians/Boole.html
- http://en.wikipedia.org/wiki/George_Boole
1 Gates And Boolean Logic
1.1 Gates
- Device Level: implementation of logical gates with transistors; bipolar and MOS (Metal Oxide Semiconductor).
- TTL (Transistor Transistor Logic): fast, high-load, power hungry. 5 Volts.
- MOS (PMOS, NMOS, CMOS): slower, but take less space, use less power
- Time required to switch from one state to the other is typically a few nanoseconds (10−^9 s). Most CPUs are built in CMOS, only 3.3 Volts.
2 Propositional Calculus
2.1 Propositional Calculus Symbols
- propositional symbols: P , Q, R, S, ...
- truth symbols: true, f alse
- connectives: ∧, ∨, ¬, → (or ⇒), ≡ (or ⇔)
2.2 Propositional Calculus Sentences
- Every propositional symbol and truth symbol is a sentence. For example: true, P , Q, and R are sentences.
- The negation of a sentence is a sentence. For example: ¬P , ¬f alse
- The conjunction of two sentences is a sentence. For example: P ∧ Q
- The disjunction of two sentences is a sentence. For example: P ∨ Q
- The implication of two sentences is a sentence. For example: P → Q
- The equivalence of two sentences is a sentence. For example: P ≡ Q
2.3 Terminology
- Legal sentences are also called well-formed formulas.
- In an expression P ∧ Q, P and Q are called the conjuncts.
- In an expression P ∨ Q, P and Q are called the disjuncts.
- In an implication P → Q, P is the premise or antecedent, and Q is the conclusion of consequent.
2.4 Parenthesis
- Parenthesis ( ) are used to group symbols into sub expressions and to define the order of evaluation and meaning.
2.5 Propositional Calculus Semantics
- The interpretation of a set of propositions is the assignment of a truth value, either T or F , to each propositional symbol.
- The symbol true is always assigned T , and f alse is assigned F.
- The interpretation of the truth value of sentences is determined by:
- negation: ¬P is F if the assignment of P is T , and T if the assignment of P is F.
- conjunction: P ∧ Q is T if both conjuncts have the value T , oth- erwise it is F.
- disjunction: P ∨ Q is F if both conjuncts have the value F , oth- erwise it is T.
- implication: P → Q is F only if the premise is T and the impli- cation is F , otherwise it is T.
- equivalence: ≡ is T only if both expressions have the same truth assignment for all possible interpretations; otherwise it is F.
2.6 Converse and Contrapositive
- For the proposition P → Q, the proposition Q → P is called its con- verse, and the proposition ¬Q → ¬P is called its contrapositive.
- For example for the proposition ”If it rains, then I get wet”,
- Converse: If I get wet, then it rains.
- Contrapositive: If I don’t get wet, then it does not rain.
- The converse of a proposition is not necessarily logically equivalent to it, that is they may or may not take the same truth value at the same time.
- Also ”If she smiles, she is happy” is equivalent to ”It is necessary for her to smile that she is happy”. For ”If she smiles, she is happy” means ”If she smiles, she is always happy”. That is, she never fails to be happy when she smiles. ”Being happy” is inevitable consequence/necessity of ”smile”. Thus if ”being happy” is missing, then ”smile” can not be there either. ”Being happy” is necessary ”for her to smile” or equiva- lently ”It is necessary for her to smile that she is happy”.
2.8 Reasoning
- Reasoning is done on propositions using inference rules. For exam- ple, if the two propositions ”if it snows, then the school is closed”, and ”it snows” are true, then we can conclude that ”the school is closed” is true. In everyday life, that is how we reason.
- To check the correctness of reasoning, we must check whether or not rules of inference have been followed to draw the conclusion from the premises. However, for reasoning in English or in general for reasoning in a natural language, that is not necessarily straightforward and it often encounters some difficulties: 1. Connectives are not necessarily easily identified as we can get a flavor of that from the previous topic on variations of if-then state- ments. 2. If the argument becomes complicated involving many statements in a number of different forms twisted and tangled up, it can easily get out of hand unless it is simplified in some way.
- One solution for that is to use symbols (and mechanize it). Each sen- tence is represented by symbols representing building block sentences, and connectives. For example, if P represents ”it snows” and Q rep- resents ”the school is closed”, then the previous argument can be ex- pressed as
[ [ P -> Q ] ^ P ] -> Q ,
or
P -> Q
P
Q
- To convert English statements into a symbolic form, we restate the given statements using the building block sentences, those for which symbols are given, and the connectives of propositional logic (not, and, or, if-then, if-and-only-if), and then substitute the symbols for the building blocks and the connectives.
- For example, let P be the proposition ”It is snowing”, Q be the propo- sition ”I will go the beach”, and R be the proposition ”I have time”. Then first ”I will go to the beach if it is not snowing” is restated as ”If it is not snowing, I will go to the beach”. Then symbols P and Q are substituted for the respective sentences to obtain ¬P → Q. Similarly, ”It is not snowing and I have time only if I will go to the beach” is restated as ”If it is not snowing and I have time, then I will go to the beach”, and it is translated as (¬P ∧ R) → Q.
3 Exercises
3.1 Exercise 1
- The exclusive or operator, ⊗, may be defined by the following truth table: P Q P ⊗ Q T T F T F T F T T F F F
- Create an equivalent propositonal calculus expression using only ∧, ∨, and ¬. Prove their equivalence using a truth table.
3.2 Solution
P Q P ∨ Q P ∧ Q ¬(P ∧ Q) (P ∨ Q) ∧ ¬(P ∧ Q) P ⊗ Q
T T T T F F F
T F T F T T T
F T T F T T T
F F F F T T F
3.3 Exercise 2
- The logical operator ↔ is read if and only if. P ↔ Q is defined as being equivalent to (P → Q) ∧ (Q → P ).
- Based on this definition, show that P ↔ Q is equivalent to (P ∨ Q) → (P ∧ Q) by a series of substitutions using the identities.
4 Predicate Calculus
- In Propositional Calculus, each atomic symbol P, Q denotes a proposi- tion of some complexity that is either true or false. There is no access to the components of the proposition. For example, instead letting a single symbol denote the entire sentence “it rained on Tuesday”, we
can create a predicate weather that describes the relationship between a date and the weather condition: weather(tuesday,rain).
- Through inference rules we can manipulate predicate calculus expres- sions, accessing their intgernal components and inferring new sentences.
- Predicate calculus also allows expressions to contain variables, which allow for the general assertions about classes of entities. E.g. we could state for all values of X, where X is a day of the week, the statement weather(X, rain) is true; i.e., it rains every day of the week.
4.1 Symbols in Predicate Calculus
- Alphabet:
- Letters of the English alphabet, upper and lower case.
- Digits 0..
- Underscore ’ ’ to improve readability.
- Symbols start with a letter, followed by any of the characters listed above.
- Examples for symbols
- George fire3 tom and jerry bill ABC friends of
4.2 Symbols and Terms
- Truth symbols true and false (reserved symbols)
- Constant symbols are symbol expressions beginning with a lower case letter
- Variable symbols beginning with upper case character
- Function symbols, beginning with a lower case character. Functions have an attached arity indicating the number of elements of the do- main mapped onto each element of the range.
- A predicate calculus term is either a constant, a variable or a function. Functions use parenthesis to enclose their comma separated arguments.
4.6 Variable Quantifiers
- Variable Quantifiers: ∀ (universal), ∃ (existential)
- More rules to combine sentences:
- If X is a variable and s a sentence, then ∀Xs is a sentence.
- If X is a variable and s a sentence, then ∃Xs is a sentence.
- Examples: ∃X friends(X, paul). ∀Xlikes(X, ice cream). mother(eve, able). mother(eve, cain). f ather(adam, able). f ather(adam, cain). ∀X∀Y f ather(X, Y ) ∨ mother(X, Y ) → parent(X, Y ). ∀X∀Y ∀Zparent(X, Y ) ∧ parent(X, Z) → sibling(Y, Z).
4.7 Representation of English sentences in First-order
Logic
- “If it doesn’t rain on Monday. Tom will go to the mountains.”
- “Emma is a Doberman pinscher and a good dog.”
- “All basketball players are tall.”
- “Some people like anchovies.”
- “If wishes were horses, beggars would ride”
- “Nobody likes taxes.”
5 Inference in Propositional and Predicate
Logic
5.1 Inference Rules
- Modus Ponens: from an implication and the premise of the implica- tion, you can infer the conclusion.
α ⇒ β, α β
- And-Elimination: from a conjunction, you can infer any of the con- juncts. α 1 ∧ α 2 ∧... ∧ αn αi
- And-Introduction: from a sequence of sentences, you can infer their conjunctions. α 1 , α 2 ,... , αn α 1 ∧ α 2 ∧... ∧ αn
- Or-Introduction: from a sentence, you can infer its disjunction with anything. αi α 1 ∨ α 2 ∨... ∨ αn
- Double-Negation Elimination: ¬¬α α
- Unit Resolution: α ∨ β, ¬β α
- Resolution: α ∨ β, ¬β ∨ γ α ∨ γ
or equivalently
¬α ⇒ β, β ⇒ γ ¬α ⇒ γ
- The bf order of quantifiers is crucial: bf Statement When True? When False? ∀X∀Y p(X, Y ), ∀Y ∀Xp(X, Y )
p(X, Y ) is true for ev- ery pair of X, Y.
There is a pair X, Y for which p(X, Y ) is false. ∀X∃Y p(X, Y ) For every X there is a Y for which p(X, Y ) is true.
There is an X such that p(X, Y ) is false for every Y. ∃X∀Y p(X, Y ) There is an X for which p(X, Y ) is true for every Y.
For every X there is a Y for which p(X, Y ) is false. ∃X∃Y p(X, Y ), ∃Y ∃Xp(X, Y )
There is a pair X, Y for which p(X, Y ) is true.
p(X, Y ) is false for ev- ery pair X, Y.
- Negation of quantifiers is applied in sequence (from outside in ...).
6 Using First-Order Logic
- Domain: a section of the world about which we wish to express some knowledge; use of axioms, and definitions to capture basic facts of the domain.
- Example:
∀ M, C mother(M, C) ⇔ f emale(M ) ∧ parent(M, C)
∀ W, H husband(H, W ) ⇔ male(H) ∧ spouse(H, W ) ∀ X male(X) ⇔ ¬f emale(X) ∀ P, C parent(P, C) ⇔ child(C, P ) ∀ G, C grandparent(G, C) ⇔ ∃P parent(G, P ) ∧ parent(P, C) ∀ X, Y sibling(X, Y ) ⇔ X 6 = Y ∧ ∃P parent(P, X) ∧ parent(P, Y )
6.1 Prolog Examples∗
- Syntax: similar to first-order logic (predicate calculus).
α ⇒ β −→ beta :- alpha. α ∧ β −→ alpha, beta. α ∨ β −→ alpha; beta | alpha. beta.
6.2 Inference Rules Involving Quantifiers
Notation
Subst ({X/sam, Y /pam} , likes(X, Y )) = likes(sam, pam)
- Universal Elimination: For any sentence α, variable ν, and ground term^1 g: ∀ ν α Subst({ν, g}, α) For example, from ∀ x likes(X, iceCream), we can use substitution {X/ben} and infer likes(ben, iceCream).
- Existential Elimination: For any sentence α, variable ν, and con- stant symbol k that does not appear elsewhere in the knowledge base:
∃ ν α Subst({ν/k}, α)
For example: from ∃ X kill(X, victim), we can infer kill(murderer, victim), as long as murderer does not appear elsewhere.
- Existential Introduction: For any sentence α, variable ν that does not occur in α, and ground term g that does occur in α: α ∃ ν Subst({g/ν}, α)
For example: from likes(jerry, iceCream) we can infer ∃ x likes(x, iceCream). (^1) ground term does not include variables
6.5 Generalized Modus Ponens
- Combine And-Introduction, Universal Elimination, and Modus Ponens: missile(m1) owns(nono, m1) ∀ X missile(X) ∧ owns(nono, X) ⇒ sells(west, nono, X) infer in one step sells(west, nono, m1)
- Find some X in the knowledge base such that X is a missile and Nono owns X, and then infer that West sells the missile to Nono.
- Even if we knew ∀ Y owns(Y, m1) (more general assertion), we can find the substitutions {X/m 1 } and {Y /nono}.
6.6 Generalized Modus Ponens (cont’d)
- Generalized Modus Ponens: For atomic sentences pi, p′ i and q, where there is a substitution θ such that Subst(θ, p′ i) = Subst((θ, pi), for all i: p′ 1 , p′ 2 ,... p′ n, (p 1 ∧ p 2 ∧... ∧ pn ⇒ q) Subst(θ, q) p′ 1 is missile(m1), p′ 2 is owns(Y, m1), θ is {X/m 1 , Y /nono}, p 1 is missile(X), p 2 is owns(nono, X), q is sells(west, nono, X), and Subst(θ, q) is sells(west, nono, m1).
6.7 Generalized Modus Ponens – Canonical Form
- Attempt to build an inference mechanism with one inference rule → Generalized Modus Ponens; a sentence is either an atomic sentence or an implication with a conjunction of atomic sentences on the left (premise) and a single atomic sentence on the right. (Horn sentences, Horn Normal Form
- One can convert sentences into Horn sentences when they are entered into the KB, using Existential Elimination and And-Elimination: e.g. ∃ X owns(nono, X) ∧ missile(X) is converted into two atomic Horn sentences (owns(nono, m1) and missile(m1)).
- The universal quantifier is dropped since the existential quantifier is eliminated.
6.8 Generalized Modus Ponens – Unification
- The unification routine Unify takes two atomic sentences p and q and returns a substitution that would make p and q look the same. If there is no such substitution, then Unify returns f ail.
Unify(p, q) = θ where Subst(θ, p) = Subst(θ, q)
θ is called the unifier of the two sentences.
6.9 Unification Example
- Assertion: knows(john, X) ⇒ hates(john, X) Use Modus Ponens to find out who he hates.
- Knowledge base:
knows(john, jane) knows(Y, leon) knows(Y, mother(Y )) knows(X, elisabeth)
X and Y are implicitly universally quantified.
Unify(knows(john, X), knows(john, jane)) = {X/jane} Unify(knows(john, X), knows(Y, leon)) = {X/leon, Y /john} Unify(knows(john, X), knows(Y, mother(Y ))) = {Y /john, X/mother(john)} Unify(knows(john, X), knows(X, elisabeth)) = f ail
- The last unification fails because X cannot take the value john and elisabeth at the same time. A way to solve this problem is to stan- dardize apart the two sentences being unified: rename variables to avoid the conflict.