Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2001

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

Search the Archive

Re: simplify with If's (with web interface)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28922] Re: [mg28873] simplify with If's (with web interface)
  • From: jmt <jmt at agat.net>
  • Date: Fri, 18 May 2001 01:13:29 -0400 (EDT)
  • References: <200105160728.DAA15542@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

A suggestion :

1) Define a new function "if" :
Clear@if;
if[test_,if[test_,true_,false_]:=if[test,true,false]

2) Set up compatibility with the built-in If :
if[test:(True|False),true_,false_]:=If[test,true,false]

If a has no value, simplification is correct :

Clear@a;
if[a,if[a,x,y],y] gives if[a,x,y]

And if a is either True or False, it returns either x or z.


Maybe Unprotect-ing If and adding new definitions to If should work, but I 
did not test this.



On Wednesday 16 May 2001 09:28, Daniel Reeves wrote:
> I'm looking for a way to simplify nested conditionals, like
>
> If[a, If[a, x, y], z]
>
> should simplify to
>
> If[a,x,z]
>
> I wrote some really awful code to do this:
>
> simplifyAll[x_] := FullSimplify[Evaluate //@ x]
>
> simpIf[x_, y_, z_] := Module[{sx = FullSimplify[x]},
>   If[sx, Evaluate[FullSimplify[y, sx]],
>          Evaluate[FullSimplify[z, Not[sx]]]]]
>
> simplifyWithIfsSub[x_] :=
>   FixedPoint[simplifyAll, FixedPoint[simplifyAll, x] /. If->simpIf]
>
> simplifyWithIfs[x_] := FixedPoint[simplifyWithIfsSub, x]
>
> I'm thinking someone has probably already done this so I don't want to
> spend too much time working on the approach above.
>
> PS, I have a web interface to my simplifier (which accepts input in either
> mathematica or lisp syntax):
> http://ai.eecs.umich.edu/people/dreeves/simplify.html
>
> Thanks,
> Daniel
>
> --    --    --    --    --    --    --    --    --    --    --    --
> Daniel Reeves               http://ai.eecs.umich.edu/people/dreeves/


  • Prev by Date: Re: ListPlot vs ListPlot3D
  • Next by Date: Re: Has anybody gotten MathLink Modules to compile using Linux Mandrake 8.0
  • Previous by thread: simplify with If's (with web interface)
  • Next by thread: AW: Creating graph with only a few data points