Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: Is it doable in Mathematica? How?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39767] Re: Is it doable in Mathematica? How?
  • From: dan_kefford at hotmail.com (Dan Kefford)
  • Date: Thu, 6 Mar 2003 02:36:42 -0500 (EST)
  • References: <b3v7ef$k96$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear all...

I am by no means a Mathematica expert, and it's been quite a while
since I last used it on a regular basis. That said, I couldn't resist
this little puzzle.

Anyway, I thought maybe the original poster was looking for a
generalized solution-- to be able to print a truth table for _any
arbitrary logical expression_.

So, here goes:

ListOfVariables[expr_] := 
  Union[Cases[expr, _Symbol?(! NumericQ[#] &), Infinity]]

BooleanTuples[variableList_] := 
  Map[Thread[variableList -> #] &, 
    Distribute[Table[{True, False}, {Length[variableList]}], List]]

TruthTable[expr_] :=
  Module[ 
    {variableList, transformationRules},
    variableList = ListOfVariables[expr] ;
    transformationRules = BooleanTuples[variableList] ;
    Print[
      GridBox[
          {Append[variableList, expr // TraditionalForm]}~Join~
            (Append[variableList, expr] /. transformationRules)
          , RowLines -> {True, False}, ColumnLines -> True
          ] // DisplayForm
      ];
    ]

I haven't tested this extensively, but it appears to work quite well. 

I know the ListOfVariables function has some vulnerabilities, from
some Googling that I did for this, but in most situations it should
do. Ultimately, too, the truth table should display intermediate
results; I'll have to figure out how to do that.

Anyway... my $0.02 to this interesting problem.

dan kefford

"Konrad Den Ende" <chamsterkonrad at bigfoot.com> wrote in message news:<b3v7ef$k96$1 at smc.vnet.net>...
> I'd like to create a truth table for, say, A, B and C, as
> well as two different expression, say, A&&B&&C and
> (A||B) -> C. How do i go about that?
> 
> I have tried Table, but since True/False are not allowed
> there i got stuck. The help in Mathematica was of little
> help in this case. Any hints or suggestions?
> 
> --
> 
> Vänligen
> Konrad
> ---------------------------------------------------
> phone #1:  (+46/0) 708 - 70 73 92
> phone #2: (+46/0) 704 - 79 96 95
> url: http://konrads.webbsida.com
> e-mail: chamsterkonrad at bigfoot.com
> -----------------------------------
> 
> Sleep - thing used by ineffective people
>             as a substitute for coffee
> 
> Ambition - a poor excuse for not having
>                  enough sence to be lazy
> ---------------------------------------------------


  • Prev by Date: How do i open a notebook from mathlink (python)
  • Next by Date: RE: Re: Is Sort stable?
  • Previous by thread: Re: Is it doable in Mathematica? How?
  • Next by thread: How to evaluate a NIntegrate expression properly