For this assignment you will implement a number of Boolean functions, such as implies, nand, etc....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For this assignment you will implement a number of Boolean functions, such as implies, nand, etc. In this assignment you will implement several Boolean functions that will later enable you to compute their truth tables. In addition, you will implement a function that creates all combinations of Boolean values for n variables. a) Boolean functions You are provided with a set of Boolean functions to implement. 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). The code provides the specification of the Boolean functions that need to be implemented. b) Truth-table inputs The function make_tt_ins (n) will create all combination of Boolean values for n variables, which is the input that needs to be provided for a truth table with n variables. For example make_tt_ins (2) needs to return [[False, False], [False, True], [True, False], [True, True]] Note that we do not care about the order, so [[True, True], [False, False], [False, True], [True, False]] is also valid output. Since the input for a truth table has 2^n entries, the output for this function is a list with 2^n elements, each of which is a list of n Boolean values. We suggest to solve this problem recursively: use the list generated by makettins(n-1) and update it accordingly by appending True/False to each row. For the base case (n=-1) you should return [[False], [True]] Two functions are provided: run(f) and main, so that you can test your code. python3 PA2.py tests your Boolean function python3 PA2.py tt tests your function make_tt_ins ( ) 485062.3373508.xxy7 PA2: Boolean functions and truth-table inputs For PA2 you will implememnt a number of Boolean functions, such as implies, nand, etc. a) Boolean functions You are provided with a set of Boolean functions to implement. 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 nIMPnq 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 all combinations of n Boolean variables. The output is in the form of a list, each element of which is a list with n Boolean values. For example, make_tt_ins (2) should return [[False, False], [False, True], [True, False], [True, True]] Two functions are provided: run(f) and main, so that you can test your code. python3 PA2.py tests your Boolean function python3 PA2.p=y tt tests your function make_tt_ins( ) For this assignment you will implement a number of Boolean functions, such as implies, nand, etc. In this assignment you will implement several Boolean functions that will later enable you to compute their truth tables. In addition, you will implement a function that creates all combinations of Boolean values for n variables. a) Boolean functions You are provided with a set of Boolean functions to implement. 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). The code provides the specification of the Boolean functions that need to be implemented. b) Truth-table inputs The function make_tt_ins (n) will create all combination of Boolean values for n variables, which is the input that needs to be provided for a truth table with n variables. For example make_tt_ins (2) needs to return [[False, False], [False, True], [True, False], [True, True]] Note that we do not care about the order, so [[True, True], [False, False], [False, True], [True, False]] is also valid output. Since the input for a truth table has 2^n entries, the output for this function is a list with 2^n elements, each of which is a list of n Boolean values. We suggest to solve this problem recursively: use the list generated by makettins(n-1) and update it accordingly by appending True/False to each row. For the base case (n=-1) you should return [[False], [True]] Two functions are provided: run(f) and main, so that you can test your code. python3 PA2.py tests your Boolean function python3 PA2.py tt tests your function make_tt_ins ( ) 485062.3373508.xxy7 PA2: Boolean functions and truth-table inputs For PA2 you will implememnt a number of Boolean functions, such as implies, nand, etc. a) Boolean functions You are provided with a set of Boolean functions to implement. 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 nIMPnq 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 all combinations of n Boolean variables. The output is in the form of a list, each element of which is a list with n Boolean values. For example, make_tt_ins (2) should return [[False, False], [False, True], [True, False], [True, True]] Two functions are provided: run(f) and main, so that you can test your code. python3 PA2.py tests your Boolean function python3 PA2.p=y tt tests your function make_tt_ins( )
Expert Answer:
Answer rating: 100% (QA)
To implement the Boolean functions and the truth table input generator in Python you can follow the ... View the full answer
Related Book For
Modern Database Management
ISBN: 978-0133544619
12th edition
Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi
Posted Date:
Students also viewed these programming questions
-
In a Hopfield neural network configured as an associative memory, with all of its weights trained and fixed, what three possible behaviours may occur over time in configuration space as the net...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Assume that the Central bank decides to sell government bonds to the commercial banks. a.) Use the demand and supply curves for loanable funds to show the effect of this measure on the interest rate....
-
Fred-stone Consolidated, Inc., a real estate developer, owns a 50% general partnership interest in Realty Partners, Ltd (Realty). The 50% limited partnership interests are owned by various individual...
-
Determine the displacement at point C. EI is constant. Use the method of virtual work. A B_=
-
Does Fairmont have any personnel whose last name is similar?
-
Flight Caf is a company that prepares in-flight meals for airlines in its kitchen located next to the local airport. The companys planning budget for July appears below: In July, 17,800 meals were...
-
Give the steps required to use the Oracle Enterprise Manager to monitor the performance of the Oracle Database and identify any potential performance bottlenecks.
-
Billy is the owner of a sole proprietorship that offers catering service. During 2019, Billy had cash sales of $80,000 and credit sales of $150,000. Based on his past experience, about 3% of his...
-
Find 1, 12, 13, and I, in the network shown below. 12 mA 21, www 12 4 mA www (15 21,
-
You have two bonds with the following characteristics: Characteristics Bond A Bond B Coupon 5.0% 5.2% Years to Maturity Par Value Price 7 7 $1,000 $1,000 $788.00 $811.00 a. What are the bond...
-
A little old lady wants to fence in her garden. She wishes to build a stone wall on one side of the garden and chain link fencing on the other three sides of the garden. The area enclosed must be...
-
3a. As shown in the table, the short-term interest rate is flat at 5% across time. Does the binomial interest rate tree model imply an upward, downward, or flat term structure of spot rates? Explain....
-
The Beta of Portfolio is ...? Stock Weight Beta ABC 0.47 1.60 0.30 0.95 0.23 1.67 The table above shows the composition of a portfolio, with the weight of each stock and its associated beta provided.
-
x(n)=(-1/2)^nu(n-4) h(n)=4^nu(2-n).
-
Let (X. A. p) be a measure space. Show that for any A,B A, we have the equality: (AUB)+(An B) = (A) + (B).
-
What do you purchase when you acquire a packaged data model?
-
List MaterialName, Material, and Width for raw materials that are not cherry or oak and whose width is greater than 10 inches. Show how you constructed this query using a Venn diagram.
-
Describe the key steps to improve data quality in an organization.
-
Which of Yellows statements regarding the factors affecting the selection of a trading strategy is correct? A. Statement 1 B. Statement 2 C. Statement 3 Robert Harding is a portfolio manager at...
-
Given the parameters for the benchmark given by Harding, Yellow should recommend a benchmark that is based on the: A. arrival price. B. time-weighted average price. C. volume-weighted average price....
-
To fill the remaining portion of the ABC order, Yellow is using: A. an arrival price trading strategy. B. a TWAP participation strategy. C. a VWAP participation strategy. Robert Harding is a...
Study smarter with the SolutionInn App