Dear Florent, Wolfgang, and Hans,

Thank you for the solutions.

All solutions are working well.

I add more rows for the last solution to show the truth table of a logical 
function.
I may modify it for 2-variable function.

Thanks again.

Best regards,

Dalyoung


\starttext
\startluacode
  function document.logicFa(p,q,r)
    local p,q,r
      if ((p or r) and (not q)) then
        return "1"
      else
        return "0"
      end
  end

  function document.logicFb(p,q)
    local p,q
      if ((not p) or q) then
        return "1"
      else
        return "0"
      end
  end

  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()
--    context.stoptabulate()
  end
\stopluacode

\startluacode
  a = { "x", "y","z", "\\overbar{y}(x+z)" }
  document.MakeHead (a)
--       "|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(2cm)|”,

  for i,p in ipairs({true,false}) do
    for j,q in ipairs({true,false}) do
      for k,r in ipairs({true,false}) do
        context.NC()
        if p then val=1 else val=0 end
        context(val)
        context.NC()
        if q then val=1 else val=0 end
        context(val)
        context.NC()
        if r then val=1 else val=0 end
        context(val)          
        context.NC()
        con=document.logicFa(p,q,r)
        context(con)
        context.NC()
        context.AR() 
      end
    end
  end
  context.HL()
  context.stoptabulate()
\stopluacode
\stoptext

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to