MathGroup Archive 2003

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

Search the Archive

Re: Is it doable in Mathematica? How?

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_] :=
    {variableList, transformationRules},
    variableList = ListOfVariables[expr] ;
    transformationRules = BooleanTuples[variableList] ;
          {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> wrote in message news:<b3v7ef$k96$1 at>...
> 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:
> e-mail: chamsterkonrad at
> -----------------------------------
> 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