[Date Index]
[Thread Index]
[Author Index]
Re: Logic and Truth Tables with Mathematica?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg29833] Re: Logic and Truth Tables with Mathematica?
*From*: Tom Burton <tburton at cts.com>
*Date*: Fri, 13 Jul 2001 04:19:15 -0400 (EDT)
*References*: <9iji4d$ris$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Hello,
On Thu, 12 Jul 2001 07:03:41 +0000 (UTC), in comp.soft-sys.math.mathematica you wrote:
>Hi,
>Can Mathematica, given a relation such as P->Q generate the truth table?
>Is there a book available that talks about Mathematica and logic?
>Thanks,
>Heath
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:
In[60]:=
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]
Out[62]=
{{{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];
so
In[65]:= tt[h,v]
Out[65]= {{True, False}, {True, True}}
Other examples:
In[66]:= tt[And[a,b], v]
Out[66]=
{{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}]
Out[69]=
{{{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.
Tom
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**
| |