Yes, I could probably find use for this sort of thing from time to
time in my work on the assumptions.

Aaron Meurer

On Fri, Dec 20, 2013 at 10:07 PM, Chris Smith <[email protected]> wrote:
> Does anyone who works with (teaching?) boolean algebra think the following
> is a utility to include in boolalg?
>
>>>> def truth_table(eq):
> ...   free = list(ordered(eq.free_symbols))
> ...   rows = [free + [str(eq)]]
> ...   for i in cartes(*[[true,false]]*len(free)):
> ...    rows.append(list(i))
> ...    rows[-1].append(eq.subs(zip(free, i)))
> ...    rows[-1] = ["1" if i else "0" for i in rows[-1]]
> ...   return TableForm(rows, wipe_zeros=False)
> ...
>>>> truth_table(a&b|c)
> a b c Or(And(a, b), c)
> 1 1 1 1
> 1 1 0 1
> 1 0 1 1
> 1 0 0 0
> 0 1 1 1
> 0 1 0 0
> 0 0 1 1
> 0 0 0 0
>>>> truth_table(~(~(a&b)|~(b&c)))
> a b c And(a, b, c)
> 1 1 1 1
> 1 1 0 0
> 1 0 1 0
> 1 0 0 0
> 0 1 1 0
> 0 1 0 0
> 0 0 1 0
> 0 0 0 0
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to