Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Can someone help me with this please, it is in German language that is why I am translating it and putting it down. Write a

Can someone help me with this please, it is in German language that is why I am translating it and putting it down.
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
Schreiben Sie eine Funktion function createTable(f, n), welche zu einer Boole'schen Formel f mit n Eingaben eine Tabelle liefert, welche zu jeder Eingabe die Ausgabe der Formel enthlt. Im Programmcode nimmt die Funktion f als Parameter ein Array von Boole'schen Werten der Lngen entgegen. So wird beispielsweise die Boole'sche Formel a V ((-6) Ac) als TScript-Funktion function f(x) return x[e] or ((not x[1]) and x[2]); ) ausgedrckt Die Wahrheitstabelle soll als geschachteltos n-dimensionales Array zurckgegeben werden. Jedes einzelne Array hat zwei Indizes, wobei Index ofur false und Index 1 fr true steht. Der entsprechende Wert der Formel wird im innersten Array gespeichert. Im obigen Beispiel wird das folgende dreidimensionale Array mit insgesamt 8 Werten als Rockgabe erwartet (Zollenumbrche und Kommentare nur zur Verdeutlichung der Logik): [ [ [false, # false or ((not false) and false) false truel # false or ((not false) and true) (false, # false or ((not true) and false) = false false) # false or ((not true) and true) = false 1. [ or (not false) and false) = true true). # true or ((not false) and true) - true [true, true or ((not true) and false) = true truel #true or ((not true) and true) 1 = true (true, # true true Fr beliebige Werte a,b,c e {0, 1) soll es die Eigenschaft haben, dass der Aufruf der Formel For beliebige Werte a, b, c = {0,1} soll es die Eigenschaft haben, dass der Aufruf der Formel +(a == 1, b = 1, c == 1)) dasselbe Ergebnis liefert wie createTable(, 3) [a][b][c] Hinweise: Die letzte Eigenschaft knnen Sie nutzen, um die Korrektheit Ihrer Lsung zu berprfen Ihre Lsung soll fr beliebiges n > O funktionieren, nicht nur fr n = 3 Variablen. . Zum Aufbau der geschachtelten Arrays bietet sich mglicherweise ein rekursiver Ansatz an. Beachten Sie, dass die Eingabe der Funktion f ein Array von Boole'schen Werten ist, nicht ein Array mit Werten und 1. Entsprechend soll Ihre Funktion die Werte true und false im zurckgegebenen Array enthalten, so wie es im Beispiel der Fall ist. 1 function createTable(t, n)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions