Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Logic and Truth Tables with Mathematica?

  • To: mathgroup at
  • Subject: [mg29833] Re: Logic and Truth Tables with Mathematica?
  • From: Tom Burton <tburton at>
  • Date: Fri, 13 Jul 2001 04:19:15 -0400 (EDT)
  • References: <9iji4d$ris$>
  • Sender: owner-wri-mathgroup at


On Thu, 12 Jul 2001 07:03:41 +0000 (UTC), in comp.soft-sys.math.mathematica you wrote:

>Can Mathematica, given a relation such as P->Q generate the truth table?
>Is there a book available that talks about Mathematica and logic?

Here is an answer to your first question. Given a list of logical variables v, the following ugly function prepares a table of all combinations of possible values:

p[v_List] := Outer[{##}&, Sequence@@Outer[#1->#2&, v, {True, False}]]

Perhaps someone can construct a less ugly form of this function. My brain seems to be stuck in Outer space. Anyway, with

In[61]:= v = {a,b};

we have

In[62]:= p[v]
{{{a -> True, b -> True}, {a -> True, b -> False}},  
  {{a -> False, b -> True}, {a -> False, b -> False}}}

Now suppose we have hypothesis h in logical variables v. Then the function tt will generate the truth table of h.

In[63]:= tt[h_, v_List] := h /. p[v]

In your example,

In[64]:= h = Implies[a, b];


In[65]:= tt[h,v] 
Out[65]= {{True, False}, {True, True}}

Other examples:

In[66]:= tt[And[a,b], v]
{{True, False}, {False, False}}

In[67]:= tt[Or[a,b], v]
Out[67]= {{True, True}, {True, False}}

In[68]:= tt[Not[a], v]
Out[68]= {{False, False}, {True, True}}

In[69]:= tt[Implies[Or[a,b], Not[And[a,c]]], {a,b,c}]
{{{False, True},  
   {False, True}}, 
  {{True, True}, 
   {True, True}}}

By the way, in Traditional form the logical operators are pretty (i.e., traditional) and Implies displays as a double right arrow, not the single-right arrow in your message. 


  • Prev by Date: Re: Naming pieces of patterns
  • Next by Date: Re: Changing Pure Function in Module
  • Previous by thread: Re: Logic and Truth Tables with Mathematica?
  • Next by thread: Head wanted