\startluacode
function document.MakeHead(p,a)
if not a then
local t = p
p = string.rep("|mcw(1cm)",#p-1) .. "|mcw(1.5cm)|"
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.truthTable(a)
document.MakeHead (a)
for i,s in ipairs({true,false}) do
for j,t in ipairs({true,false}) do
for k,u in ipairs({true,false}) do
if s then val=1 else val=0 end
context.NC()
context(val)
context.NC()
if t then val=1 else val=0 end
context(val)
context.NC()
if #a == 3 then
break
end
if u then val=1 else val=0 end
context(val)
context.NC()
con=document.logicFa(s,t,u)
context(con)
context.NC()
context.AR()
end
if #a == 3 then
con=document.logicF2(s,t)
context(con)
context.NC()
context.AR()
end
end
end
context.HL()
context.stoptabulate()
end
\stopluacode
\startplacetable[location=here,reference=tbl:Fxyz]
\startluacode
function document.logicFa(p,q,r)
if ((not p or not q) and r) or (p and (q or not r)) then
return "1"
else
return "0"
end
end
a = { "p", "q", "r","f(p,q,r)"}
document.truthTable(a)
\stopluacode
\stopplacetable