Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11195

Re: Evaluation of boolean functions in Mathematica 8

From Dana DeLouis <dana2010@me.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Evaluation of boolean functions in Mathematica 8
Date 2012-08-04 10:01 +0000
Message-ID <jviru2$2t0$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


> g[True,True,True]
> But the above statement does not evaluate g at the data-point given,...

Hi.  Just some additional ideas.  Here's what you have:

equ=And[p,q,r]

f=BooleanConvert[equ,"BFF"]
BooleanFunction[<3>][p,q,r]

Notice that the equation has p,q,r assigned to it.
Therefore, just assign a value to the variables.

f//FullForm
BooleanFunction[Rule["BDD",List[3,0,2,-1,1,3,-1,2,1,-1]]][p,q,r]

f/.{p->True,q->True,r->False}
False


Slightly better might be:

BooleanTable[f,{p,q,r}]
{True,False,False,False,False,False,False,False}


As a side note, notice that using x,y,z will not work as the function is expecting p,q,r.

BooleanTable[f,{x,y,z}]
< does not work >


Using your equation, we see that there is only 1 output with True, and the rest are False.
What generated the True condition?    All False, All True, or something in-between?
Here's a general idea you may find interesting.
I've includes "steps" so as to see intermediate steps one may want to look at leading up to the final solution.


TruthTable[equ_,steps_List:{}]:=Module[{v},
v = BooleanVariables[equ];
AppendTo[v,{steps,equ}];
v=Flatten[v];

MatrixForm[BooleanTable[v],
TableHeadings->{Automatic,v}]
]


Here's your example.  It appears the output is true when all inputs are true.
(I know... this example was easy)


TruthTable[equ]
( 	p	q	r	p&&q&&r
1	True	True	True	True
2	True	True	False False
3	True	False True False
4	True	False False False
5	False True True False
6	False True False False
7	False False True False
8	False False False False
)


This example is also easy, but suppose one didn't know the intermediate steps.
If one didn't know what the final NOT did, you could look at the inside part prior to the final NOT.


equ=Not[Or[And[x,y],z]];

// additional things one may want to look at:

steps = {And[x,y],  Or[And[x,y],z]};

TruthTable[equ,steps]
(         x	y	z	x&&y	(x&&y)||z	!((x&&y)||z)
1	True	True	True	True	True	False
2	True	True	False True True False

etc...
)


As a side note, does anyone know of a simple way to keep the input equation as And[p,q,r] ?

This gets simplified to p&&q&&r.
I've been trying to find a way (without typing it as string) to keep the original version of And[p,q,r]   in the heading row.
~Thanks.


= = = = = = = = = = 
HTH  :>)
Dana DeLouis
Mac & Math 8
= = = = = = = = = = 



On Aug 1, 4:57 am, lalwani.ak...@gmail.com wrote:
> Hello,
> 
> I want to evaluate a Boolean function by substituting True and False values for its variables, to get a True or False value at the output. Example,
> 
> g = BooleanConvert[And[p, q, r], "BFF"]
> 
> g[True,True,True]
> 
> But the above statement does not evaluate g at the data-point given, but instead returns the statement,
> 
> BooleanFunction[<3>][p,q,r][True,True,True]
> 
> Can anybody please suggest how to proceed?
> 
> Thanks a lot.


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Evaluation of boolean functions in Mathematica 8 Dana DeLouis <dana2010@me.com> - 2012-08-04 10:01 +0000

csiph-web