1. Propositional Logic Solutions Exercises A. 1. What order of precedence does DERIVE use for the five predefined logical operators? Solution Author and simplify various DERIVE expressions to observe how DERIVE drops certain parentheses and how DERIVE evaluates these expressions. The following expressions are useful in determining operator precedence. TRUTH_TABLE(p, q, NOT(p) AND q, NOT(p AND q)) TRUTH_TABLE(p, q, r, (p AND q) OR r, p AND (q OR r), (p OR q) AND r, p OR (q AND r)) TRUTH_TABLE(p, q, r, (p AND q) XOR r, p AND (q XOR r), (p XOR q) AND r, p XOR (q AND r)) TRUTH_TABLE(p, q, r, (p XOR q) OR r, p XOR (q OR r), (p OR q) XOR r, p OR (q XOR r)) TRUTH_TABLE(p, q, r, (p IMP q) OR r, p IMP (q OR r), (p OR q) IMP r, p OR (q IMP r)) The logical operator NOT has the highest precedence. Next in order of precedence is the operator AND. Then come OR and XOR at the same level with right to left evaluation when they occur in the same expression without parentheses. The operator IMP has the lowest precedence of the five predefined logical operators. 2. Define the biconditional function IFF of two variables. For example, IFF(true, false) should simplify to false. Check your definition of IFF with a truth table. Solution Enter the following DERIVE expressions and simplify the second expression. IFF(p, q) := (p IMP q) AND (q IMP p) TRUTH_TABLE(p, q, IFF(p, q)) 1 3. Use DERIVE truth tables to determine whether each of the following is a contradiction, a tautology, or neither. Explain. ~p p p ~p (p q) (q p) (p ~p) (p ~p) Solution Observe the values in the truth tables generated by the following DERIVE expression. TRUTH_TABLE(p, NOT(p) AND p, p IMP NOT(p), p AND NOT(p) IMP p OR NOT(p)) The first propositional form in the DERIVE expression is a contradiction because it is false in all cases. The second form is neither a contradiction nor a tautology because it has a true case and a false case. The third form is a tautology because it is true in all cases The propositional form involving both p and q can be investigated by simplifying the following DERIVE expression. TRUTH_TABLE(p, q, IFF(p IMP q, q IMP p)) This propositional form is neither a contradiction nor a tautology because it has both true and false values. 4. Verify that the operator < on the set {-2, -1, 0, 1, 2} is not commutative. Explain. Hint: Simplify the expression: VECTOR( VECTOR( IFF (x < y , y < x), x, -2, 2), y, -2, 2) Solution Since false cases are observed when the DERIVE expression: VECTOR(VECTOR(IFF(x<y, y<x),x, -2, 2), y, -2, 2) is simplified, the operator < is not commutative. 2 Exercises B. So that we can use common names for the functions that we define in DERIVE, we will override one default choice for input of function names. To allow case-sensitive names, use the DERIVE command: Declare Algebra State Input and choose Sensitive Case. expression. Another way to change to this state is to author the following CaseMode := Sensitive 1. In many applications of logic, such as in digital circuit design, the integers 0 and 1 correspond to the logic values false and true, respectively. With this correspondence in mind, we will develop a system of logic using these integers rather than logic values. Use simple arithmetic operations to define numerical DERIVE functions not and and that behave as their names indicate: not(p) := 1 – p and(p, q) := pq For example, some values of these functions should be: not(0) = 1 and(1, 1) = 1 and(0, 1) = 0. Verify that both functions yield correct results in all cases. Solution Author the following DERIVE expressions and simplify the VECTOR and APPEND expressions to show that the functions not and and correctly implement the corresponding logical operators: CaseMode := Sensitive not(p) := 1 - p VECTOR([p, not(p)], p, 0, 1) and(p, q) := p*q A := VECTOR(VECTOR([p, q, and (p, q)], q, 0, 1), p, 0, 1) 3 APPEND(A SUB 1, A SUB 2) 2. Suppose that you are given only the definitions of the logic operators negation and conjunction with truth tables. Define the logic operators disjunction, conditional, and biconditional in terms of the two given operators (without using truth tables). Solution The following logical equivalences express the logic operators disjunction, conditional and biconditional in terms of only negation and conjunction. p q (p q) p q (p q) p q (p q) (q p) 3. Define numerical DERIVE functions or, imp, and iff. Some values of these functions should be: or(0, 0) = 0 or(1, 1) = 1 imp(1, 0) = 0 iff(1, 0) = 0. Hint: Use the definitions developed for the two preceding questions. Verify that your functions yield correct results in all cases. Solution Author the following DERIVE expressions and simplify the last expression to show that correct results are obtained for each of the three functions. or(p, q) := not(and(not(p), not(q))) imp(p, q) := not(and(p, not(q))) iff(p, q) := and(not(and(p, not(q))), not(and(q, not(p)))) A := VECTOR(VECTOR([p, q, or(p, q), imp(p, q), iff(p, q)], q, 0, 1), p, 0, 1) APPEND(A SUB 1, A SUB 2) 4