Re: Is it doable in Mathematica? How?
- To: mathgroup at smc.vnet.net
- Subject: [mg39734] Re: [mg39704] Is it doable in Mathematica? How?
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Mon, 3 Mar 2003 23:51:30 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On Monday, March 3, 2003, at 04:25 AM, Konrad Den Ende wrote: > 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? > > generatetruthtable[numvars_Integer, expr_] := TableForm[Table[Block[{tvalues = IntegerDigits[i, 2, numvars] /. {1 ->True, 0 ->False}}, Append[tvalues, expr @@ tvalues]], {i, 0, 2\^numvars - 1}], TableHeadings -> {None, Append[Table["v" <> ToString[i], { i, numvars}], ToString[Part[expr, 1]]]}] Try generatetruthtable[3, #1 && #2 && #3 &] to get A&&B&&C. Regards, Sseziwa