Propositional Calculus Proposition is a statement that is either or. Example 1 Propositions: It rains. Sun is shining and my coat is wet. If Ann plays with me, I give her a candy. x > 10 x = 1 and y < 10 Propositional variables are propositions, that is, they can only be assigned either the truth value or the truth value. Propositional constants and are denoted by symbols 1 (or T, standing for ) and 0 (or F, standing for ). Propositions can be denoted by propositional variables, e.g., A: Sun is shining. B: My coat is wet. C: x > 10 Assigning A = 1 (A is ) means that the proposition "Sun is shining" is (the case is that the sun is shining), assigning A = 0 (A is ) means that the proposition "Sun is shining" is (the case is that the sun is not shining). Assigning C = 1 means the case that x is greater than 10, assigning C = 0 means the case that x is not greater than ten, that is, x is less than or equal to 10. We can now state the proposition "Sun is shining and my coat is wet" in a more compact form: "A and B" (in fact, even in a more compact form: A B, using the logical "and" connective ). An atomic proposition is a proposition consisting of only a single propositional variable or a single propositional constant. Nonatomic propositions are called compound propositions, and they contain at least one logical connective. In a truth table we can list the truth values of a proposition under all possible assignments. Example 2 Truth table for the proposition A B: A B A B 0 0 0 0 1 0 1 0 0 1
With logical connectives propositions can be combined to form new propositions (cf., A B, where propositions A and B are combined with the connective ). Logical connectives ~ (negation), (conjunction), (disjunction), fi (conditional), «(biconditional) can be defined by means of truth tables. Notice, that the negation connective operates one proposition, all the other connectives operate with two propositions. Negation ~P can be pronounced "not P" P ~P 0 1 1 0 Conjunction P Q can be pronounced "P and Q" P Q P Q 0 0 0 0 1 0 1 0 0 Disjunction P Q can be pronounced "P or Q" P Q P Q 0 0 0 0 1 1 1 0 1 Conditional P Q can be pronounced "If P, then Q" P Q P Q 0 0 1 0 1 1 1 0 0 Biconditional P Q can be pronounced "P if and only if Q" P Q P Q 0 0 1 0 1 0 1 0 0 Example 3 Calculate (i.e., evaluate the truth values of the following logical expressions): ~1 solution: 0 1 0 solution: 0 2
0 1 solution: 1 1 1 solution: 1 1 0 solution: 0 Logical arguments, like "Sun is shining and my coat is wet.", can be written with propositional calculus notation with the help of the above pronounciation rules (and common sense). Example 4 Let's analyse the statement "If Ann plays with me, I give her a candy." as a logical argument. We can find two atomic propositions A: Ann plays with me. B: I give her (Ann) a candy. These two propositions can be combined with the "if.. then" connective ( ): A B. To check if this straightforward conversion is correct, we can find the truth table for the original argument and compare it to the truth table of proposition A B: Ann plays with me. (Ann doesn't play with me) (Ann doesn't play with me) (Ann plays with me) (Ann plays with me) I give her a candy. (I don't give her a candy) (I give her a candy) (I don't give her a candy) (I give her a candy) If Ann plays with me, I give her a candy. ( meaning that there is no conflict between the described situation and this argument) (to be strict, there is no conflict, because the argument doesn't say anything about the situation when Ann doesn't play) ( meaning that there is conflict between the described situation and this argument) Compare this to the truth table of A B and see that they are identical. Convert the following logical arguments to propositional calculus notation: 1. I give Ann a candy if and only if Ann plays with me. 2. I don't go to London or I go to London and send Bill a postcard. 3. I'll give you a candy or a doll. 4. I'll give you a candy but not my doll. In programming languages logical expressions may look different, because of the use of other notation than ours. However, the same logic works. For example, the expression True And False in Visual Basic evaluates False and the expression =AND(TRUE; FALSE) in Excel's spreadsheet evaluates FALSE. 3
The following table shows corresponding expressions. We suppose that A and B are valid logical expressions (logical or propotional variables, constants, or compound expressions) in the shown context: Propositional calculus notation Visual Basic notation Excel spreadsheet function notation ~A Not A =NOT(A) A B A And B =AND(A;B) A B A Or B =OR(A;B) A B A Imp B A B A Eqv B In many programming languages there is also an "exclusive or" operator (Xor), which is like Or, but "True Xor True" evaluates False. Parentheses are used to show the order of calculation. Example 5 3 * (2 + 5) = 3 * 7 = 21 1 (1 0) = 1 0 = 1 Example 6 Find the truth table for proposition A (A B). A B A B A (A B) 0 0 0 0 = 0 0 0 = 0 0 1 0 1 = 0 0 0 = 0 1 0 1 0 = 0 1 0 = 1 1 = 1 1 1 = 1 Normally, this is done more simply just by showing the results of each stage: A B A B A (A B) 0 0 0 0 0 1 0 0 1 0 0 1 1 Example 7 Find the truth table for proposition A (B C). A B C B C A (B C) 0 0 0 0 0 = 0 0 0 = 0 0 0 1 0 1 = 0 0 0 = 0 0 1 0 1 0 = 0 0 0 = 0 0 1 = 1 0 1 = 1 1 0 0 0 0 = 0 1 0 = 1 1 0 1 0 1 = 0 1 0 = 1 1 1 0 1 0 = 0 1 0 = 1 1 1 = 1 1 1 = 1 4
Find the truth tables for the following propositions: 5. ~A (A B) 6. A ~(A B) 7. A (A ~A) 8. A (B C) 9. ~(A (B C)) 10. ~A (B C) 11. A (B C) 12. (~A B) ((B A) B) 13. (A B) B 14. Write the above propositions with the Visual Basic notation. 15. Write the above propositions with no conditional or biconditional connectives with the Excel spreadsheet function notation. What is the order of calculation, if parentheses are missing? Precedence order of connectives: ~, ( and ), fi, «Example 8 There is precedence order between arithmetic operators + and *, namely * takes precedence over +. That is, 1 + 2 * 3 = 1 + (2 * 3) rather than (1 + 2) * 3. In the same way we use the precedence order of logical connectives: A B C is to be understood as (A B) C, not as A (B C), because takes precedence over. Notice, that there is no precedence order between and. Therefore, for example, expression A B C cannot be understood at all. It is not a proposition! However, in some programming languages there is a fixed order for the "and" and "or" operators, but make sure what it is, or, preferably, use parentheses to avoid errors. We can make use of the following rules, too: P Q R is understood as (P Q) R. P Q R is understood as (P Q) R. ~~P is understood as ~(~P). Example 9 (A C) B C is understood as ((A C) B) C. Show the order of calculation explicitly by inserting all the needed parentheses: 16. A B C 17. ~A B C 18. ~A B A B C 19. A B B 20. B A B 5
Remove all the parentheses that are not necessarily needed (the order of calculation should not be changed!): 21. (A (B C)) 22. (~A (B (A B))) C 23. (~A (B (A B))) C 24. ~(A (B (A B))) C 25. ~(A (B (A B))) C 26. (~A (A B)) (A (A B)) 27. (~A (A B)) (A ~(A B)) Equivalent propositions are such that evaluate the same truth values in all cases, whatever the truth values of the propotional variables are. Equivalence is denoted by the symbol. Example 10 Let's prove that ~A (A B) A (A B). A B ~A A B ~A (A B) A (A B) 0 0 1 0 1 1 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0 Proposition that is in all cases, is called a tautology. Proposition that is in all cases, is called a contradiction. Example 11 (~A (A B)) (A (A B)) is a tautology. A set of equivalences should be learned by heart, in order to be able to manipulate logical expressions. Useful laws for manipulating expressions: Law P ~P 1 P ~P 0 P 0 P P 1 P P 1 1 P 0 0 P P P P P P ~(~P) P P Q Q P P Q Q P P Q Q P (P Q) R P (Q R) (P Q) R P (Q R) (P Q) R P (Q R) Name Tautology law Contradiction law Identity laws Domination laws Idempotent laws Double-negation law Commutative laws Associative laws 6
P (Q R) (P Q) (P R) P (Q R) (P Q) (P R) P (P Q) P P (P Q) P ~(P Q) ~P ~Q ~(P Q) ~P ~Q P Q ~P Q P Q (P Q) (Q P) Distributive laws Absorption laws De Morgan's laws removing conditionals and biconditionals Example 12 Let's simplify the expression ~A (A B) using the above equivalences (laws): ~A (A B) (~A A) B Associative law 1 B Tautology law B 1 Commutative law 1 Domination law It appears that ~A (A B) is a tautology. Let's take another: ~A (A B) (~A A) (~A B) Distributive law 1 (~A B) Tautology law (~A B) 1 Commutative law ~A B Identity law Example 13 A B C ~(A B) C Don't do the following: A B C A ~B C Example 14 A B C ~A (B C) Don't do the following: A B C ~A B C removing conditional Why is this incorrect? removing conditional Why is this incorrect? First, remove all conditionals and biconditionals, then simplify (so that equivalence holds at each stage): 28. ~B A B 29. A ~B B 30. (A ~B B) ((A ~B B) (A C ~B)) 31. ~(~A ~B C) 32. ~(A ~B) A 33. A ~B C 34. A ~B C ~A 35. A B ~A B C 36. A B C ~A ~B 7
Simplifying conditional expressions in programming languages is analogous with simplifying propositions. However, sometimes the simplification can be carried out even further, because the following equivalences hold: Not (a < b) a >= b Not (a > b) a <= b Not (a <= b) a > b Not (a >= b) a < b Not (a = b) a <> b Not (a <> b) a = b In many programming languages comparison operators take precedence over logical operators, e.g., Not (a < b) can be written as Not a < b, (x < 10) and (y = 1) can be written as x < 10 and y = 1. Example 15 x > 18 Or Not (x <= 18 Or y = 'John') x > 18 Or (x > 18 And y <> 'John') De Morgan's law x > 18 Absorption law Simplify: 37. Not (x <= 5 Or Not (x > 5 Or y < 3)) 38. Not (x < 5 And y = 1) Or x < 5 39. Not (x = 1 Or y = 2 Or z = 3) Or (x <> 1 And z <>3) 40. i < 1 Or Not (i < 1 Or y = 1) And i >= 1 And y <> 1 41. i >= 1 Or Not (i < 1 And x = 2) Or x <> 2 Or (i >= 1 And z = 3) How to construct a logical expression that behaves in a desired way? For example, you wish to construct an expression with three propositional variables A, B, and C, which behaves as shown in the following truth table: A B C? 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 1 1 0 0 0 The problem can also be formulated as follows: Find an expression for a truth function f, such that f(0,1,0) = f(1,0,1) = 1 (0 otherwise). One way to do this is by first writing expressions generating one desired -value, and then combining these expressions with the disjunction connective: f(a,b,c) = (~A B ~C) (A ~B C). This technique leads to an expression which is in the disjunctive normal form. 8
Another way to do this is by first writing expressions generating one desired value, and then combining these expressions with the conjuction connective: f(a,b,c) = (A B C) (A B ~C) (A ~B ~C) (~A B C) (~A ~B C) (~A ~B ~C). This technique leads to an expression which is in the conjunctive normal form. True or : 42. For any proposition, it is always possible to construct an equivalent proposition which does not contain conditional or biconditional connectives. 43. For any proposition, it is always possible to construct an equivalent proposition which contains only negation and conjunction connectives. 44. For any proposition, it is always possible to construct an equivalent proposition which contains only negation and disjunction connectives. Find an expression for a truth function f, such that 45. f(1,0) = 1 (0 otherwise) 46. f(1,0) = f(0,1) = 1 (0 otherwise) 47. f(0,0) = f(1,1) = f(1,0) = 1 (0 otherwise) 48. f(0,0,1) = f(1,1,0) = f(0,1,1) = 1 (0 otherwise) 49. f(1,1,1) = f(1,1,0) = f(1,0,0) = 0 (1 otherwise) 50. f(0,1,0,1,1,0,1) = f(1,1,0,1,1,1,0) = 1 (0 otherwise) 51. f(0,1,0,1,1,0,1) = f(1,1,0,1,1,1,0) = 0 (1 otherwise) Logical operations can be performed with microchips. Truth values are implemented as electrical currency levels (no currency:, currency: ). In microchip design the following symbols (or correspondents) are used: a b a b a b a b a ~ a AND OR NOT Construct microchip layouts for the following truth functions: 52. f(a,b) = (A B) ~B 53. f(a,b,c) = ((~A B) (~A ~B)) C 54. f(a,b,c) = (A B) ~((A B) C) 55. f(a,b,c,d) = (~A B) (~B C) ~(A B D) 56. f(0,0,1) = f(1,1,0) = f(0,1,1) = 1 (0 otherwise) 9