CS 173 Lecture 2: Propositional Logic José Meseguer University of Illinois at Urbana-Champaign 1 Propositional Formulas A proposition is a statement that is either true, T or false, F. A proposition usually combines simpler propositions by means of connectives such as AND (^), OR (_), exclusive-or, XOR ( ), NOT ( ), and IMPLIES (ñ). Aristotle (384 322 BC) invented Formal Logic thanks to his insight that the truth value of any proposition only depends on the truth value of its most basic ones and on the form in which they are combined by various connectives, i.e., on its logical form, which is obtained by replacing the basic propositions by propositional variables. For example, the logical form of: is: (pigs fly AND smoke) IMPLIES (fire OR smoke) pp ^ Sq ñ pf _ Sq A proposition so abstracted is called a propositional formula, denoted ϕ, φ, ψ, ϕ 1..., ϕ n,..., which can be precisely defined as follows: Propositional variables, P, Q, X, Y, X 1,..., X n,... are (the most basic) propositional formulas. If ϕ, ϕ 1 are propositional formulas, then: ϕ, ϕ ^ ϕ 1, ϕ _ ϕ 1, ϕ ϕ 1, and ϕ ñ ϕ 1 are propositional formulas. Nothing else is a propositional formula. Using digital electronics we can implement ϕpx 1,..., X n q as a circuit viewing the X 1,..., X n as its input wires and producing then the output ϕpx 1,..., X n q in its output wire. The shape of the circuit ϕpx 1,..., X n q is exactly the logical form of ϕpx 1,..., X n q pictured as a tree, with each connective, ^, _,, and ñ implemented as a gate (or as a small circuit using other gates). This is the way microprocessors having millions of gates are built in hardware to implement a general-purpose computer as, e.g., an Intel chip. 2 Truth Tables and Evaluation of Propositional Formulas Given a propositional formula ϕpx 1,..., X n q and truth values b 1,..., b n, i.e., b i P tt, Fu for i 1,..., n, for its variables X 1,..., X n, then ϕpx 1,..., X n q will evaluate to exactly one truth value. This is Aristotle s insight about logical form.
2 J. Meseguer The truth value of ϕpx 1,..., X n q for any b 1,..., b n can be determined as follows: Variables. For variables X 1,..., X n and truth values b 1,..., b n, then X i evaluates to b i for i 1,..., n, Connectives are evaluated according to the following truth tables (similar to addition and multiplication tables for numbers): AND : X 1 X 2 X 1 ^ X 2 T F F F T F OR : X 1 X 2 X 1 _ X 2 T F T XOR : X 1 X 2 X 1 X 2 T T F T F T NOT : X X T F F T IMPLIES : X 1 X 2 X 1 ñ X 2 T F F F F T Complex Propositions. Evaluate as follows. If for truth values b 1,..., b n for the variables X 1,..., X n, ϕpx 1,..., X n q evaluates to b and ϕ 1 px 1,..., X n q evaluates to b 1, then: ϕ evaluates to b ϕ ^ ϕ 1 evaluates to b ^ b 1 ϕ _ ϕ 1 evaluates to b _ b 1 ϕ ϕ 1 evaluates to b b 1 ϕ ñ ϕ 1 evaluates to b ñ b 1
Propositional Logic 3 according to the above truth tables, where not all variables X 1,..., X n need to appear in both ϕ and ϕ 1. Truth Tables for Complex Propositions. We can build a truth table for any complex proposition by applying above s idea to incrementally build truth tables for its subexpressions. For example, we can define a new connective for if and only if IFF (ô), where, by definition, X 1 ô X 2 is the complex proposition X 1 ô X 2 def px 1 ñ X 2 q ^ px 2 ñ X 1 q as follows: X 1 X 2 X 1 ñ X 2 X 2 ñ X 1 X 1 ô X 2 T T T F F T F F F F T Note that the truth table for X 1 ô X 2 is exactly the identity predicate on truth values, that is, b ô b 1 T if b b 1, and b ô b 1 F if b b 1. Therefore, if for truth values b 1,..., b n, ϕpx 1,..., X n q evaluates to b and ϕpx 1,..., X n q evaluates to b 1, then ϕ ô ϕ 1 evaluates to b b 1. Viewed as an electronic circuit, X 1 ô X 2 is a circuit that can be used to check whether the circuits for ϕ and ϕ 1 produce the same output value for all inputs. This will happen exactly when ϕ ô ϕ 1 produces the value T for all inputs. We then say that ϕ and ϕ 1 are equivalent as formulas, and therefore as circuits, so that we can replace one by the other as equivalent components in a hardware design. This is further explained in what follows. 3 Tautologies, Falsities, and Equivalences Tautologies and Falsities. A formula ϕ is called a tautology if it is true for all inputs, that is, if for all truth values b 1,..., b n, ϕpx 1,..., X n q evaluates to T. Equivalently, ϕpx 1,..., X n q is a tautology if its truth table is true for all inputs. Tautologies are exactly the formulas that are logically true in all circumstances. A formula ϕ is called a falsity if it is false for all inputs, that is, if for all truth values b 1,..., b n, ϕpx 1,..., X n q evaluates to F. Equivalently, ϕpx 1,..., X n q is a falsity if its truth table is false for all inputs. Falsities are exactly the formulas that are logically false in all circumstances. Note the important facts that: ϕ is a tautology iff ϕ is a falsity, and ϕ is a falsity iff ϕ is a tautology. Equivalences. An equivalence is a tautology of the form ϕ ô ψ. But recall that the truth table of ô is the identity function. Therefore, ϕ ô ψ is a tautology if and only if for truth values b 1,..., b n of their input variables 1 X 1,..., X n ϕpx 1,..., X n q and ϕ 1 px 1,..., X n q evaluate to the same truth value b P tt, Fu. If ϕ ô ψ is a tautology then we write: ϕ ψ and call it an equivalence. 1 Some of those variables may not appear in either ϕ or ψ. The X 1,..., X n are the variables appearing in either ϕ or ψ (or both).
4 J. Meseguer If we view ϕ and ψ as digital circuits, then ϕ ψ exactly means that we can replace the circuit ϕ by the circuit ψ, or viceversa (perhaps inside any bigger circuit) without changing the behavior of the circuit. Also, if we view ô as a circuit, we can use it to check that ϕ and ψ are equivalent circuits by connecting the output wires of ϕ, and ψ into the inputs of ô and then checking that the output of the combined circuit ϕ ô ψ is T for all inputs. Tautologies and Falsities as Equivalences. We have three related notions: tautology, falsity, and equivalence as a special kind of tautology. Can we reduce these three notions to just one? Yes! Just to the notion of equivalence, as follows: ϕ is a tautology if and only if ϕ T ϕ is a falsity if and only if ϕ F The Algebra of Equivalences. Recall that the meaning of ô is just equality. Therefore, we should think of an equivalence ϕ ô ψ an algebraic law ϕ ψ that holds for Propositional Algebra (also called Boolean Algebra after its inventor George Boole in the 19 th Century), the same way the arithmetic laws hold for ordinary algebra. In fact, if we think of _ as `, ^ as, T as 1, and F as 0, we see that many laws (though not all) are the same. For example distributivity: X py ` Xq px Y q ` px Zq versus X ^ py _ Xq px ^ Y q _ px ^ Zq. Boolean Algebra Laws. The following are very useful equivalences in Boolean Algebra, which can be proved by checking that they are tautologies building their truth table (do it for a couple of them to convince yourself): 1. Commutativity of _ and ^: X _ Y Y _ X and X ^ Y Y ^ X. 2. Associativity of _ and ^: px _ Y q _ Z X _ py _ Zq and X ^ py ^ Zq X ^ py ^ Zq. 3. Identity Laws for _ and ^: X _ F X and X ^ T X. 4. Collapse Laws for _ and ^: X _ T T and X ^ F F. 5. Idempotency Laws for _ and ^: X _ X X and X ^ X X. 6. Distributivity of ^ over _: X ^ py _ Zq px ^ Y q _ px ^ Zq. 7. Distributivity of _ over ^: X _ py ^ Zq px _ Y q ^ px _ Zq. 8. Absorption Laws for _ and ^: X _ px ^ Y q X and X ^ px _ Y q X. 9. Double Negation: X X. 10. Principle of Contradiction: X ^ X F. 11. Law of Excluded Middle: X _ X T.
Propositional Logic 5 12. De Morgan s Laws for _ and ^: px _ Y q p Xq ^ p Y q and px ^ Y q p Xq _ p Y q. Expressing All Connectives in Terms of _ and ^. We can express all other connectives in terms of _ and ^ by means of the following very useful equivalences, which can be checked by building the associated truth tables: X Y px _ Y q ^ px ^ Y q X ñ Y p Xq _ Y X ô Y pp Xq _ Y q ^ p py q _ Xq. Proving Equivalences vs. Building Truth Tables. How can we convince ourselves that a formula ϕ ô ψ is in fact an equivalence ϕ ψ? We have two ways: (1) We can settle the matter by checking that ϕ and ψ have the same truth table. But this is tedious for humans, although easy to write a program to check it, so that we can automatically decide whether any equivalence holds or not. 2 (2) Alternatively, an often easier way is to use the above equivalences (1) (12) as algebraic laws as we do in ordinary algebra by replacing equals for equals. In this way, it is often much easier to obtain new equivalences. In fact, the above laws (1) (12) are enough to prove all equivalences algebraically. Of course, as in ordinary algebra, we can also use equivalences that we have already proved as lemmas when proving other equivalences. Here is a simple example on deriving the so-called Law of Contrapositive, X ñ Y p Y q ñ p Xq, which we will use in writing proofs by contrapositive: X ñ Y p Xq _ Y p Xq _ p Y q p Y q _ p Xq p Y q ñ p Xq. where we have used Double Negation for the second step, and Commutativity of _ for the third, together with the equivalence X ñ Y p Xq _ Y (twice) as a lemma. 2 A naive program will be very inefficient, because the problem of checking equivalence is a so-called NP-Complete problem that has an exponential blowup on the size of the formula. This means that for formulas with many propositional variables the program will easily get bogged down and take forever. Even though NP-completeness is an intrinsic difficulty of the problem, much more efficient programs called SATsolvers that can often efficiently handle formulas with thousands of variables are now routinely used for this purpose in many applications (e.g., hardware design).