Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Evaluation of boolean functions in Mathematica 8

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127538] Re: Evaluation of boolean functions in Mathematica 8
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Thu, 2 Aug 2012 04:53:02 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20120801085530.4222B6802@smc.vnet.net>

There are a number of ways.

Clear[g, p, q, r]

First, note the form of your g

g = BooleanConvert[And[p, q, r], "BFF"]

BooleanFunction[<3>][p,q,r]

You need to use or substitute for the existing arguments not add
additional arguments

Method 1: Replace (Drop and Add)

g[[0]][True, True, True]

True

g[[0]] @@@ Tuples[{True, False}, 3]

{True, False, False, False, False, False, False, False}

Method 2: Replace (Substitute)

g /. {p -> True, q -> True, r -> True}

True

(g /. Thread[{p, q, r} -> #]) & /@
 Tuples[{True, False}, 3]

{True, False, False, False, False, False, False, False}

Method 3: Set the existing arguments

p = True; q = True; r = True;

g

True

Or locally rather than globally

Clear[p, q, r]

With[{p = True, q = True, r = True}, Evaluate[g]]

True


Bob Hanlon


On Wed, Aug 1, 2012 at 4:55 AM,  <lalwani.akhil at 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.
>



  • Prev by Date: Re: How do I create a circular lamina?
  • Next by Date: Using Workbench to debug Compile[] ??
  • Previous by thread: Evaluation of boolean functions in Mathematica 8
  • Next by thread: Re: Evaluation of boolean functions in Mathematica 8