Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function function createTable (f, n), which supplies a table for a Boolean formula ff with nn inputs, which contains the output of the

Write a function function createTable (f, n), which supplies a table for a Boolean formula ff with nn inputs, which contains the output of the formula for each input. In the program code, the function f accepts an array of Boolean values of length n as a parameter. For example, the Boolean formula a \ lor ((\ neg b) \ land c) a ((b) c) is used as a TScript function
function f (x)
{
return x [0] or ((not x [1]) and x [2]);
}
expressed.
The truth table should be returned as a nested n-dimensional array. Each individual array has two indices, where index 0 stands for false and index 1 for true. The corresponding value of the formula is stored in the innermost array. In the above example, the following three-dimensional array with a total of 8 values is expected as return (line breaks and comments only to clarify the logic):
[
[
[false, # false or ((not false) and false) = false
true], # false or ((not false) and true) = true
[false, # false or ((not true) and false) = false
false] # false or ((not true) and true) = false
],
[
[true, # true or ((not false) and false) = true
true], # true or ((not false) and true) = true
[true, # true or ((not true) and false) = true
true] # true or ((not true) and true) = true
]
]
For any values a, b, c \ in \ {0, 1 \} a, b, c {0,1} it should have the property that the call of the formula
f ([a == 1, b == 1, c == 1])
gives the same result as
createTable (f, 3) [a] [b] [c]
Hints:
You can use the last property to check the correctness of your solution.
Your solution should work for any n> 0n> 0, not just for n = 3n = 3 variables.
A recursive approach may be used to build the nested arrays.
Notice that the input to function f is an array of Boolean values, not an array of values 0 and 1. Accordingly, your function should contain the values true and false in the returned array, as is the case in the example.
image text in transcribed
image text in transcribed
Write a function function createTable (f, n), which returns a table for a Boolean formula f with n inputs, which for each zu jodor Input contains the output of the formular in the program code, the function t takes an array of Boolean values of the lengths 3s parameter opposite. For example, the Boolean formula becomes a V (1-b) c) as a TScript function ion function f(x) return x[@] or ((not x[1]) and x[2]); [2]); expressed. The truth tabte should be returned as a nested n-dimensional array. Each individual array has two indexes, with index O being for bei Index 0 for false and index 1 stands for true. The corresponding value of the formula is stored in the innermost attay. The above example becomes the following it wird das folgende three-dimensional array with a total of 8 values expected as return (line breaks and comments only to clarity the logic)ichung der Logik) [false, true}, [false, false] # false or ((not false) and false) = false se #false or ((not false) and true) = trueue #false or ((not true) and false) = false se # false or ((not true) and true) = false ale [true, true). (true, true) #true or ((not false) and false) = trueue #true or ((not false) and true) = truetrue #true or ((not true) and false) = truee) - true #true or ((not true) and true) = truele true For any values a, b, c (0.1) it should have the property that the call of the formula Formel For any values a, b, c (0,1) it should have the property that the call of the formula Formul f((a == 1, b == 1, C == 1)) gives the same result aslo createTable(1, 3)[0][b][clic Hintsise . You can use the last property to check the correctness of your solution. Your solution should work for any no, not just for n-3 variables. Variablen, A recursive approach may be used to build the nested arrays. Note that the input to function is an array of Boolean values, not an array of values and 1. Accordingly, your und false im zurckgegebenen Array enthalten, so wie es im Beispiel der Fall ist itsprechend soil ihre

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago