A truth table is a display of the inputs to, and the output of a Boolean function organized as a table where each row gives one combination of input values and the corresponding value of the function.



Task

 Input a Boolean function from the user as a string then calculate and print a formatted truth table for the given function.
 (One can assume that the user input is correct).
 Print and show output for Boolean functions of two and three input variables, but any program should not be limited to that many variables in the function. 
 Either reverse-polish or infix notation expressions are allowed.


Related tasks

   Boolean values
   Ternary logic


See also

   Wolfram MathWorld entry on truth tables.
   some "truth table" examples from Google.


  [ stack ]               is args         (     --> s   )
  [ stack ]               is results      (     --> s   )
  [ stack ]               is function     (     --> s   )
 
  [ args share times
      [ sp
        2 /mod iff
          [ char t ] 
        else 
          [ char f ] 
        emit ]
    drop
    say " | " ]           is echoargs     ( n   -->     )
 
  [ args share times 
      [ 2 /mod swap ]
    drop ]                is preparestack ( n   --> b*n )
 
  [ results share times 
      [ sp 
        iff
          [ char t ] 
        else 
          [ char f ] 
        emit ] ]          is echoresults  ( b*? -->     )
 
  [ say "Please input your function, preceded" cr 
      $ "by the number of arguments and results: " input
    trim nextword quackery args put
    trim nextword quackery results put
    trim build function put
    args share bit times
      [ cr
        i^ echoargs 
        i^ preparestack
        function share do
        echoresults ] 
     cr
     args release
     results release
     function release ]   is truthtable   (     -->     )
 