\startluacode
function document.MakeHead(p,a)
if not a then
local t = p
p = string.rep("|mcw(1cm)",#p-1) .. "|mcw(2cm)|"
a = t
end
context.starttabulate { p }
context.FL()
for i=1,#a do
context.NC() context(a[i])
end
context.NC() context.NR()
context.LL()
end
function document.MakeFooter()
context.HL()
context.stoptabulate()
end
local tf = { true, false }
function document.truthTable(a,func)
document.MakeHead(a)
for i,s in ipairs(tf) do
for j,t in ipairs(tf) do
for k,u in ipairs(tf) do
context.NC()
context(s and "1" or "0")
context.NC()
context(t and "1" or "0")
context.NC()
if #a == 3 then
break
end
context(u and "1" or "0")
context.NC()
context(func(s,t,u))
context.NC()
context.AR()
end
if #a == 3 then
context(func(s,t))
context.NC()
context.AR()
end
end
end
document.MakeFooter()
end
\stopluacode
—- We define a logic function before we call the main function.
—- by changing the function, we get the result for two variables.
\startluacode
--statistics.starttiming()
local function logicF(p,q,r)
if (not q) and (p or r) then
return "1"
else
return "0"
end
—- return (not q) and (p or r)
end
document.truthTable({ "x", "y","z","f(x,y,x)"},logicF)
\stopluacode
\stoptext