Propositions are logical formulas consisting of proposition symbols and connecting operators. They are recursively defined by the following rules:
negation | conjunction | disjunction | implication | equivalence |
! 0=1 | 0& 0=0 | 0| 0=0 | 0--> 0=1 | 0<-> 0=1 |
! 1=0
| 0& 1=0 | 0| 1=1 | 0--> 1=1 | 0<-> 1=0 |
1& 0=0 | 1| 0=1 | 1--> 0=0 | 1<-> 0=0 | |
1& 1=1 | 1| 1=1 | 1--> 1=1 | 1<-> 1=1 |
The input contains several test cases, each on a separate line. Every test case denotes a proposition and may contain arbitrary amounts of spaces in between. The input file terminates immediately after the newline symbol following the last test case.
For each test case generate a truth table for the denoted proposition. Start the truth table by repeating the input line. Evaluate the proposition (and its subformulas) for all assignments to its variables, and output one line for each assignment. The line must have the same length as the corresponding input line and must consist only of spaces and the characters 0 and 1. Output an empty line after each test case.
Let s1,...,sn be the proposition symbols in the denoted proposition sorted in alphabetic order. Then, all assignments of 0 to s1 must precede the assignments of 1 to s1. Within each of these blocks of assignments, all assignments of 0 to s2 must precede the assignments of 1 to s2, and so on.
((b --> a) <-> ((! a) --> (! b))) ((y & a) - ->(c |c))
((b --> a) <-> ((! a) --> (! b))) 0 1 0 1 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 0 1 ((y & a) - ->(c |c)) 0 0 0 1 0 00 1 0 0 1 0 00 0 0 0 1 1 11 1 0 0 1 1 11 0 0 1 1 0 00 1 1 1 0 0 00 0 0 1 1 1 11 1 1 1 1 1 11