Re: Simplifying a Boolean Expression

• To: mathgroup at smc.vnet.net
• Subject: [mg68886] Re: [mg68790] Simplifying a Boolean Expression
• From: Daniel Lichtblau <danl at wolfram.com>
• Date: Tue, 22 Aug 2006 05:20:22 -0400 (EDT)
• References: <200608180712.DAA02183@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hebhardt, Jon wrote:
> Can Mathametica be used to simplify the following type of logic typically
> found in programming applications, and if so, how do I go about setting it
> up?
>
>
>
> EXAMPLE
>
> Variables A and T can have the values "none", "dense", "sparse"
>
> The variable X will be assigned a value of either "onepass" or "twopass"
> based on the following logic:
>
>
>
> IF
>
> [(A="none") AND (T="none")] OR [(A="dense") OR (A="sparse") AND (T="none")]
> OR [(A="dense") AND (T="dense")] THEN X = "onepass"
>
> ELSE IF
>
> [{A="sparse") AND (T="sparse")] OR [(A="sparse") AND (T="dense")] THEN X =
> "twopass"
>
>
>
> I want to be able to express this type of problem in Mathematica and have it
> return the simplest logic for assigning a value to X.
>
>
>
> Regards,
>
> Jon
>
>
>
> Work:  401-752-3821
>
> Cell:    508-873-9780
>

Here is an approach that might help. Use integers 1-3 for "none",
"dense", and "sparse", and likewise for the number of passes (where
"threepass" is a dummy for the case where neither condition holds). Then
use Reduce to solve a system of equations and bounded inequalities,
removing from consideration the threepass case. It can be done as below.

{none,dense,sparse} = {1,2,3};

{onepass,twopass,threepass} = {1,2,3};

cond1 = (aa==none && tt==none) ||
((aa==dense || aa==sparse) && tt==none);

cond2 = (aa==sparse && tt==sparse) ||
(aa==sparse && tt==dense);

In[51]:= Reduce[{Implies[cond1,xx==onepass] &&
Implies[!cond1 && cond2, xx==twopass] &&
Implies[!cond1 && !cond2, xx==threepass],
Element[{aa,tt,xx},Integers],
1<=aa<=3, 1<=tt<=3, 1<=xx<=2}, xx]

Out[51]= (aa == 1 && tt == 1 && xx == 1) ||
(aa == 2 && tt == 1 && xx == 1) ||
(aa == 3 && tt == 1 && xx == 1) ||
(aa == 3 && tt == 2 && xx == 2) ||
(aa == 3 && tt == 3 && xx == 2)

I'm not sure if this is quite what you seek but it might be a start.

Daniel Lichtblau
Wolfram Research

```

• Prev by Date: Re: "Freezing" evaluation Output?
• Next by Date: RE: Re: Need good reference for writing Stylesheets
• Previous by thread: Simplifying a Boolean Expression
• Next by thread: Re: Simplifying a Boolean Expression