Question: For this assignment you will be provided with a function callf2(f,p,q) whose input is a function and its two arguments, and returns the value of

For this assignment you will be provided with a function callf2(f,p,q) whose input is a function and its two arguments, and returns the value of the function applied to the arguments. You are also given a "main" to test your code.

Your task is to implement three functions: eval_tt_f2(f) and equivalent(tt1,tt2) and is_tautology(tt).

The function eval_tt_f2(f) will, given a two argument Boolean function f as input (one of the functions you created in PA2.py), return the truth table for f. Use the function make_tt_ins(n) function you implemented in PA2.py to create a list with the inputs for the truth table, and then use callf2 to append the truth value for f to each row. For example, evalttf2(iff) should return:

[[False, False, True], [False, True, False], [True, False, False], [True, True, True]]

The function equivalent(tt1,tt2) should return True if tt1 and tt2 are logically equivalent and False otherwise. For example, equivalent(eval_tt_f2(PA2.implies), eval_tt_f2(PA2.nqIMPnp)) should return True.

The function is_tautology(tt) should return True if the tt parameter has a True value as the output for all possible tt inputs, otherwise it should return false.

''' PA1: Boolean functions and truth-table inputs -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

For PA1 you will implememnt a number of Boolean functions, such as implies, nand, etc.

a) Boolean functions You are provided with a set of undefined functions.You will create the bodies for these 2 parameter functions, such that they return the appropriate Boolean value (True or False). The formal parameters are always p and q (in that order)

Notice the difference between npIMPnq and nqIMPnp: In npIMPnq you return not p implies not q (not first param implies not second param), for example npIMPnq(True,False) returns True.

In nqIMPnp you return not q implies not p (not second param implies not first param), for example nqIMPnp(True,False) returns False.

b) Truth-table inputs The function make_tt_ins(n) will create a truth table for all combinations of n Boolean variables. A truth table is an arrayList of 2**n arrayLists of n Booleans. For example make_tt_ins(2) returns [[False, False], [False, True], [True, False], [True, True]]

Notice the recursive nature of make_tt_ins(n): It consists of a truth-table(n-1), each row prefixed with False followed by the same truth-table(n-1), each row prefixed with True, with a base case for n==1: [[False], [True]]

Two functions are provided: run(f) and main, so that you can test your code.

python3 PA1.py tests your Boolean function python3 PA1.p=y tt tests your function make_tt_ins() '''

PA2.py import sys

# p implies q def implies(p, q): return False

# not p implies not q def npIMPnq(p,q): return False

# not q implies not p def nqIMPnp(p,q): return False

# p if and only if q: (p implies q) and (q implies p) def iff(p, q): return False

# not ( p and q ) def nand(p, q): return False

# not p and not q def npANDnq(p,q): return False

# not ( p or q) def nor(p, q): return False

# not p or not q def npORnq(p,q): return False

def make_tt_ins(n): return [[]]

#provided def run(f): print(" True,True : ", f(True,True)) print(" True,False : ", f(True,False)) print(" False,True : ", f(False,True)) print(" False,False: ", f(False,False)) print() #provided if __name__ == "__main__": print("program", sys.argv[0]) f1 = sys.argv[1] print(f1); if(f1 == "implies"): run(implies); if(f1 == "iff"): run(iff) if(f1 == "npIMPnq"): run(npIMPnq) if(f1 == "nqIMPnp"): run(nqIMPnp) if(f1 == "nand"): run(nand) if(f1 == "nor"): run(nor) if(f1 == "npANDnq"): run(npANDnq) if(f1 == "npORnq"): run(npORnq) if(f1 == "tt"): print(make_tt_ins(int(sys.argv[2]))) PA3.py

''' PA3: Truth tables and equivalence -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

For PA3 you will be provided with a function callf2(f,p,q) which will cal f(p,q), and with a main to test your code. You will implement two functions: eval_tt_f2(f) and equivalent(tt1,tt2).

The function eval_tt_f2(f) will, given a two argument Boolean function f ( one of the functions you created in PA2.py), return the truth table for f. Use your make_tt_ins(n) function from PA2.py to create an arrayList with n inputs, then use callf2 to append the truth value for f to each row of that arrayList. For example, eval_tt_f2(iff) will return:

[[False, False, True], [False, True, False], [True, False, False], [True, True, True]]

The function equivalent(tt1,tt2) will return True if tt1 and tt2 are equivalent and False otherwise. For example, equivalent(eval_tt_f2(PA2.implies), eval_tt_f2(PA2.nqIMPnp)) will return True.

You will need to add your code from PA2 by selecting PA2.py as the current file above.

'''

import sys import PA2

# provided def callf2(f, p, q): return f(p,q)

# implement this def eval_tt_f2(f): return []

# implement this def equivalent(tt1,tt2): return False

# implement this def is_tautology(tt): return False # use program input section to input choice # ex. entering 'iff' will run code after the label # one arg # and entering 'iff implies' will run code after the labe # one arg and # two args if __name__ == "__main__": print("program", sys.argv[0]) args = input().split() argc = len(args) f1 = args[0] print(f1) tt1 = [] # one arg if(f1 == "implies"): tt1 = eval_tt_f2(PA2.implies) if(f1 == "iff"): tt1 = eval_tt_f2(PA2.iff) if(f1 == "npIMPnq"): tt1 = eval_tt_f2(PA2.npIMPnq) if(f1 == "nqIMPnp"): tt1 = eval_tt_f2(PA2.nqIMPnp) if(f1 == "nand"): tt1 = eval_tt_f2(PA2.nand) if(f1 == "nor"): tt1 = eval_tt_f2(PA2.nor) if(f1 == "npANDnq"): tt1 = eval_tt_f2(PA2.npANDnq) if(f1 == "npORnq"): tt1 = eval_tt_f2(PA2.npORnq) print(tt1)

# two args if(argc>1): f2 = args[1] print(f2) tt2 = [] if(f2 == "implies"): tt2 = eval_tt_f2(PA2.implies) if(f2 == "iff"): tt2 = eval_tt_f2(PA2.iff) if(f2 == "npIMPnq"): tt2 = eval_tt_f2(PA2.npIMPnq) if(f2 == "nqIMPnp"): tt2 = eval_tt_f2(PA2.nqIMPnp) if(f2 == "nand"): tt2 = eval_tt_f2(PA2.nand) if(f2 == "nor"): tt2 = eval_tt_f2(PA2.nor) if(f2 == "npANDnq"): tt2 = eval_tt_f2(PA2.npANDnq) if(f2 == "npORnq"): tt2 = eval_tt_f2(PA2.npORnq) print(tt2) if equivalent(tt1,tt2): print("equivalent!") else: print("NOT equivalent!") print()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!