2 PA3: Truth tables and equivalence 3 4 5 For PA3 you will be provided with...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2 PA3: Truth tables and equivalence 3 4 5 For PA3 you will be provided with a function call f2(f,p,q) 6 which will cal f(p,q), and with a main to test your code. 7 You will implement two functions: eval_tt_f2(f) and 8 equivalent (tt1, tt2). 9 10 The function eval_tt_f2(f) will, given a two argument Boolean 11 function f ( one of the functions you created in PA2.py), return 12 the truth table for f. Use your make_tt_ins(n) function from 13 PA2.py to create an arrayList with n inputs, then use callf2 14 to append the truth value for f to each row of that arrayList. 15 For example, eval_tt_f2(iff) will return: 16 17 [[False, False, True], [False, True, False], [True, False, False], [True, True, True]] 18 19 The function equivalent(tt1,tt2) will return True if tt1 and tt2 20 are equivalent and False otherwise. For example, 21 equivalent (eval_tt_f2(PA2.implies), eval_tt_f2(PA2.nqIMPnp)) 22 will return True. 23 24 You will need to add your code from PA2 by selecting PA2.py as the current file above. 25 26 28 import sys 29 import PA2 30 31 # provided 32 def callf2(f, p, q): 33 return f(p,q) 34 35 # implement this 36 def eval_tt_f2(f): 37 38 tt = PA1.make_tt_ins(2) #pass 2 as argument since we our functions take two inputs [False, True] for n in range(numpy. array(tt).shape [0]): tt[n].append(callf2(f, tt[n][0], tt[n][1])) return tt 39 40 41 42 # implement this 43 def equivalent(tt1, tt2): 44 45 46 47 # implement this 48 def is tautology(tt): 49 return False 50 51 # use program input section to input choice return (tt1==tt2) 51 # use program input section to input choice 52 # ex. entering 'iff' will run code after the label # one arg 53 # and entering 'iff implies' will run code after the labe #one arg and # two args 54 if _name__ "__main__": 55 print("program", sys.argv[0]) 56 args = 57 argc = 58 f1 59 60 61 #one arg 62 if(f1 63 if(f1 64 if(f1 65 if(f1 66 if(f1 67 if(f1 68 if(f1 69 if(f1 70 print(tt1) 71 27374元 75 = input().split() len(args) args [0] print (f1) tt1 = == == == "implies"): tt1 "iff"): tt1 "npIMPnq"): tt1 "nqIMPnp"): tt1 "nand"): tt1 = eval_tt_f2(PA2. nand) "nor"): tt1 eval_tt_f2(PA2.nor) # two args if(argc>1): f2 = nnint/f21 = "npANDnq"): tt1 "npORnq"): tt1 args [1] = eval_tt_f2(PA2.iff) = eval_tt_f2(PA2.implies) eval_tt_f2(PA2.npIMPnq) eval_tt_f2 (PA2. nqIMPnp) = = eval_tt_f2(PA2. npANDnq) eval_tt_f2(PA2. npORnq) # two args if(argc>1): f2 print(f2) tt2 if(f2 if(f2 if(f2 "npIMPnq"): tt2 if(f2 "nqIMPnp"): tt2 if(f2 "nand"): tt2 eval_tt_f2(PA2. nand) if(f2 "nor"): tt2 = eval_tt_f2(PA2.nor) if(f2 "npANDnq"): tt2 if(f2 "npORnq"): tt2 print(tt2) args [1] = else: print () == "implies"): tt2 = eval_tt_f2(PA2. implies) "iff"): tt2 = eval_tt_f2(PA2. iff) eval_tt_f2(PA2. npIMPnq) eval_tt_f2(PA2.nqIMPnp) if equivalent(tt1, tt2): print("equivalent!") = = = = = print("NOT equivalent!") eval_tt_f2(PA2. npANDnq) eval_tt_f2(PA2.npORnq) 5.9 Populating Truth Tables with Boolean Functions IMPORTANT: You will need to use the drop down above the code, below, to select "PA2.py" and paste your PA2 code in that file in order for your PA3 code to work. For this assignment you will be provided with a function callf 2 (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 (ttl,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 (ttl,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. 2 PA3: Truth tables and equivalence 3 4 5 For PA3 you will be provided with a function call f2(f,p,q) 6 which will cal f(p,q), and with a main to test your code. 7 You will implement two functions: eval_tt_f2(f) and 8 equivalent (tt1, tt2). 9 10 The function eval_tt_f2(f) will, given a two argument Boolean 11 function f ( one of the functions you created in PA2.py), return 12 the truth table for f. Use your make_tt_ins(n) function from 13 PA2.py to create an arrayList with n inputs, then use callf2 14 to append the truth value for f to each row of that arrayList. 15 For example, eval_tt_f2(iff) will return: 16 17 [[False, False, True], [False, True, False], [True, False, False], [True, True, True]] 18 19 The function equivalent(tt1,tt2) will return True if tt1 and tt2 20 are equivalent and False otherwise. For example, 21 equivalent (eval_tt_f2(PA2.implies), eval_tt_f2(PA2.nqIMPnp)) 22 will return True. 23 24 You will need to add your code from PA2 by selecting PA2.py as the current file above. 25 26 28 import sys 29 import PA2 30 31 # provided 32 def callf2(f, p, q): 33 return f(p,q) 34 35 # implement this 36 def eval_tt_f2(f): 37 38 tt = PA1.make_tt_ins(2) #pass 2 as argument since we our functions take two inputs [False, True] for n in range(numpy. array(tt).shape [0]): tt[n].append(callf2(f, tt[n][0], tt[n][1])) return tt 39 40 41 42 # implement this 43 def equivalent(tt1, tt2): 44 45 46 47 # implement this 48 def is tautology(tt): 49 return False 50 51 # use program input section to input choice return (tt1==tt2) 51 # use program input section to input choice 52 # ex. entering 'iff' will run code after the label # one arg 53 # and entering 'iff implies' will run code after the labe #one arg and # two args 54 if _name__ "__main__": 55 print("program", sys.argv[0]) 56 args = 57 argc = 58 f1 59 60 61 #one arg 62 if(f1 63 if(f1 64 if(f1 65 if(f1 66 if(f1 67 if(f1 68 if(f1 69 if(f1 70 print(tt1) 71 27374元 75 = input().split() len(args) args [0] print (f1) tt1 = == == == "implies"): tt1 "iff"): tt1 "npIMPnq"): tt1 "nqIMPnp"): tt1 "nand"): tt1 = eval_tt_f2(PA2. nand) "nor"): tt1 eval_tt_f2(PA2.nor) # two args if(argc>1): f2 = nnint/f21 = "npANDnq"): tt1 "npORnq"): tt1 args [1] = eval_tt_f2(PA2.iff) = eval_tt_f2(PA2.implies) eval_tt_f2(PA2.npIMPnq) eval_tt_f2 (PA2. nqIMPnp) = = eval_tt_f2(PA2. npANDnq) eval_tt_f2(PA2. npORnq) # two args if(argc>1): f2 print(f2) tt2 if(f2 if(f2 if(f2 "npIMPnq"): tt2 if(f2 "nqIMPnp"): tt2 if(f2 "nand"): tt2 eval_tt_f2(PA2. nand) if(f2 "nor"): tt2 = eval_tt_f2(PA2.nor) if(f2 "npANDnq"): tt2 if(f2 "npORnq"): tt2 print(tt2) args [1] = else: print () == "implies"): tt2 = eval_tt_f2(PA2. implies) "iff"): tt2 = eval_tt_f2(PA2. iff) eval_tt_f2(PA2. npIMPnq) eval_tt_f2(PA2.nqIMPnp) if equivalent(tt1, tt2): print("equivalent!") = = = = = print("NOT equivalent!") eval_tt_f2(PA2. npANDnq) eval_tt_f2(PA2.npORnq) 5.9 Populating Truth Tables with Boolean Functions IMPORTANT: You will need to use the drop down above the code, below, to select "PA2.py" and paste your PA2 code in that file in order for your PA3 code to work. For this assignment you will be provided with a function callf 2 (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 (ttl,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 (ttl,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.
Expert Answer:
Answer rating: 100% (QA)
he algorithm for the PA3py program Define the callf2f p q function that takes a twoargument Boolean function f and two Boolean inputs p and q This function simply calls fp q and returns the result Imp... View the full answer
Related Book For
Applied Regression Analysis and Other Multivariable Methods
ISBN: 978-1285051086
5th edition
Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg
Posted Date:
Students also viewed these programming questions
-
A consumer organization wants to know whether there is a difference in the price of a particular toy at three different types of stores. The price of the toy was checked in a sample of five discount...
-
in c++ language please follow instructions. i want the output to be exactly form the Sample Output in the image down below. thank you, i will definitely give a thumb up when you did what I have ask...
-
Write a generic table-driven predictive parser in Prolog. The parser will be instantiated with the LL(1) grammar for arithmetic expressions with operators-(minus) and*(times). Given an expression as...
-
You have a project to build a new fence. The fence is four sided as shown below. Each side is to take one day to build and is budgeted for $1,000 per side. The sides are planned to be completed one...
-
One of the accounting development patterns that was introduced in Chapter 2 was the macroeconomic development model. Under this framework accounting practices are designed to enhance national...
-
LeGaroutte Industries makes industrial pipe manufacturing equipment. Use direct-labor hours as the burden vehicle, and compute the total cost per unit for each model given in the table. Total...
-
What is are the key elements of the BCG matrix?
-
The data file TVLife provides information on life expectancy and number of televisions per thousand people in a sample of 22 countries, as reported by the 2006 World Almanac and Book of Facts. Enter...
-
Question 20 (Part Level Submission) Saylor Enterprises had a capital balance of $168,000 at the beginning of the period. At the end of the accounting period, the capital balance was $198,000. (a)...
-
To generate needed foreign exchange, the Cuban government entered into a joint venture with Domingo Cigars of Spain. The joint venture manufactures Domingo Cigars in Cuba using Cuban tobacco and...
-
is miles correct in thinking that an ipo will dramatically increase in value?
-
Thornton Concrete Company pours concrete slabs for single - family dwellings. Lancing Construction Company, which operates outside Thornton s normal sales territory, asks Thornton to pour 4 6 slabs...
-
Examine three economic scenarios and determine how the Federal Reserve might address each one. You will then compare these monetary policy actions to fiscal policy. Use the template pictures below to...
-
2.13 Find the natural frequency of the pulley system shown in Fig. 2.56 by neglecting the friction and the masses of the pulleys. K 0000 elle m k Figure 2.56 0000 4k elle 4k
-
Procedure a one 1. Select a hard surface that will not be damaged by dropping each ball from a meter (h = 1 m) height. For better result, you can set and tape the wooden meter stick flat on the...
-
I. II. Find the mode shapes and nodes corresponding to the natural frequencies found Graph the mode shapes and nodes and interpret the graphs. www 2m k L 2 X * L 2 Fo sincot Slender bar of mass m
-
Meenach Corporation uses a job-order costing system with asingle plantwide predetermined overhead rate based on directlabor-hours. The company based its predetermined overhead rate forthe current y 2...
-
The packaging division of a company having considered several alternative package designs for the company's new product has finally brought down their choices to two designs of which only one has to...
-
For the data involving regression of DI (Y) on IQ (X) in Problem 4 in Chapter 5, assume that the sample of 17 observations (with the outlier removed) consists of males only. Now suppose that another...
-
Repeat Problem 20, this time including three interactions: SEX and AGE, SEX and HEIGHT, and SEX and WEIGHT.
-
a.-c. Repeat Problem 15 using BLOODTOL as the response and BRAINTOL as the predictor.
-
Nutrition Products, Inc., uses a traditional product costing system to assign over- head costs uniformly to all products. To meet Food and Drug Administration require- ments and to assure its...
-
The New York Times reported that Neil Simon planned to open his play London Suite off Broadway. Why? For financial reasons. Producer Emanuel Azenberg predicted the following costs before the play...
-
Agribiz Food Products, Inc. produces a wide variety of food and related products. The companys tomato canning operation relies partly on tomatoes grown on Agribizs own farms and partly on tomatoes...
Study smarter with the SolutionInn App