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...
-
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...
-
SQL allows a foreign-key dependency to refer to the same relation, as in the following example: create table manager (employee-name char (20), manager-name char(20), primary key employee-name,...
-
Describe the accounting treatment for a forward exchange contract where there is no hedging relationship.
-
Levine Company uses the perpetual inventory system and allows customers to use two credit cards in charging purchases. With the Suntrust Bank Card, Levine receives an immediate credit to its account...
-
1. In the given reaction, XYZ3 2. 3. 4. 5. X+Y+3Z If one mole of each of X and Y with 0.05 mol of Z gives compound XYZ3. (Given: Atomic masses of X, Y and Z are 10, 20 and 30 amu, respectively.) The...
-
On December 15 XYZ enters into $50 million NP swap with ABSwaps. Payments will be on 15th of March, June, September, December for one year. XYZ will pay 7.5% fixed to ABSwaps, and ABSwaps will pay...
-
Describe three paths for implementing the strategy of Hedge Fund A. After a significant amount of internal discussion, Wallace concludes that the pension fund should invest in either Hedge Fund B or...
-
Nowackis most appropriate response to Knights question about the quantitative investment process is to: A. backtest the new strategy. B. define the market opportunity. C. identify the factors to...
-
Which investment approach is the most likely basis for Sardars buy recommendation for AZ Industrial? A. Relative value B. High-quality value C. Deep-value investing Jack Dewey is managing partner of...
-
Based on Exhibit 1, which stock pair should Knight recommend as the best candidate for statistical arbitrage? A. Stock 1 and Stock 2 B. Stock 3 and Stock 4 C. Stock 5 and Stock 6 Aleksy Nowacki is a...
-
Nowackis calculated price/book ratios (P/Bs) and price/earnings ratios (P/Es), in his backtesting of the new strategy, are a problem because of: A. data mining. B. look-ahead bias. C. survivorship...
-
Does American culture help or hinder acceptance of foreign products? How?
-
The overall reaction and equilibrium constant value for a hydrogenoxygen fuel cell at 298 K is 2H 2 (g) + O 2 (g) 2H 2 O(l) K = 1.28 10 83 a. Calculate E cell and G 8 at 298 K for the fuel cell...
-
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.
-
Show that the Fourier transform of a conjugate antisymmetric sequence is imaginary.
-
Solve Exercise 1.22 using the concept of the transfer function. Exercise 1.22 Compute the inverse Fourier transform of \[X\left(\mathrm{e}^{\mathrm{j} \omega} ight)=\frac{1}{1-\mathrm{e}^{-\mathrm{j}...
-
We define the even and odd parts of a complex sequence \(x(n)\) as \[\mathcal{E}\{x(n)\}=\frac{x(n)+x^{*}(-n)}{2} \quad \text { and } \quad \mathcal{O}\{x(n)\}=\frac{x(n)-x^{*}(-n)}{2}\]...
Study smarter with the SolutionInn App