COP 3223H meeting -*- Outline -*- * Friday Problems with Boolean Expressions and Predicates ** implication function ------------------------------------------ FOR YOU TO DO 1. Write a function, implies(b1, b2), that takes two bool arguments, b1 and b2, and returns True just when b1 implies b2. That is, it returns true just when either not b1 or b2 is True. ------------------------------------------ ** printing truth tables for arbitrary functions In Python, you can pass functions as arguments! ------------------------------------------ FOR YOU TO DO 2. Write a procedure, print_truth_table(p), that takes a 2-argument Boolean predicate, p, as an argument, and prints a truth table for p that displays the value of p(b1, b2) for all pairs of Booleans b1 and b2. For example, print_truth_table(implies) would print on stdout: arg1\arg2 | True | False True | True | False False | True | True For another example, suppose we have: def notOrDM(b1, b2): return not (b1 or b2) == not b1 and not b2 Then print_truth_table(notOrDM) would print on stdout: arg1\arg2 | True | False True | True | True False | True | True ------------------------------------------ It may be helpful to have a procedure that prints a bool in 6 spaces. def printB6(b): """Print b on stdout in 6 spaces, left aligned, with no trailing newline.""" if b: print("True ", end='') else: print("False ", end='') How to solve problems like this? Imagine that the function parameter is something specific, solve for that, then generalize. ** tautologies ------------------------------------------ FOR YOU TO DO 3. Write a function, is_tautology(p), that takes a 2-argument Boolean predicate, p, as an argument and returns True just when p is a tautology. That is is_tautology(p) returns True just when p(True,True), p(True, False), p(False, True), and p(False, False) are all True. ------------------------------------------