MathGroup Archive 2001

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

Search the Archive

Re: Unconventional Max[] behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28094] Re: [mg28048] Unconventional Max[] behavior
  • From: Adam Strzebonski <adams at wolfram.com>
  • Date: Fri, 30 Mar 2001 04:12:49 -0500 (EST)
  • References: <B6E8F603.BC12%andrzej@platon.c.u-tokyo.ac.jp>
  • Sender: owner-wri-mathgroup at wolfram.com

Simplification rules for Max similar to the ones you propose 
already are in Simplify, and work in "most" cases.

In[1]:= Simplify[Max[a+3,a^2+a+3,a],a>0]
 
                 2
Out[1]= 3 + a + a

There is a bug which prevents simplification of Max[e1, e2], 
whenever e1-e2 is not a number, but Expand[e1-e2] is a number.
This is the case with 2a+1 and 2a+2 (which Simplify transforms
to 2(a+1) before using the Max rules).
 
The bug will be fixed in the next release. A (somewhat hackish)
workaround would be to have Max expand its
arguments.                                                 

In[1]:= Unprotect[Max];
 
In[2]:= Max[args__]:=With[{e=Expand[{args}]}, Max@@e /; e=!={args}]
 
In[3]:= Simplify[Max[2a+1,2a+2,2a+3]]
 
Out[3]= 3 + 2 a
 
In[4]:= Max[2a + 1, 2a + 2] // Simplify
 
Out[4]= 2 (1 + a)  

> > A related question to my "discovery": Is there a standard way of
> > defining a "simplification" rather than an "evaluation" rule?  For
> > example, if I have some function `foo' and I do _not_ want to include
> > the definition
> >
> > foo[a_] + foo[b_] ^:= foo[a+b]
> >
> > can I still have the rewrite rule
> >
> > foo[a_] + foo[b_] -> foo[a+b]
> >
> > applied automatically whenever I invoke Simplify[]?

You can do it using TransformationFunctions option.

In[1]:= tf[e_] := e /. foo[a_] + foo[b_] -> foo[a+b]
 
In[2]:= SetOptions[Simplify, TransformationFunctions->{Automatic, tf}];
 
In[3]:= Simplify[foo[a]+foo[b]+foo[c]]
 
Out[3]= foo[a + b + c]           

Best Regards,

Adam Strzebonski
Wolfram Research                                               
                                                      
Andrzej Kozlowski wrote:
> 
> The first question: the behaviour you observed has little if anything to do
> with the inner workings of Max and is determined by the "inner workings" of
> Simplify. Or rather, it looks to me like a small omission in the inner
> workings of Simplify. I suspect, however, that is is not really important
> because, as you had originally assumed, Max and Min are really intended to
> deal with numeric quantities. Note that it is quite easy to modify Simplify
> in sucha way that it will work with Max and symbolic expressions, e.g.:
> 
> In[1]:=
> Unprotect[Simplify];
> Simplify[Max[a___,x_,b___,y_,c___],assum_:{}]/;Simplify[x>y,assum]:=Simplify
> [Max[a,x,b,c],assum];
> Simplify[Max[a___,x_,b___,y_,c___],assum_:{}]/;Simplify[x<y,assum]:=Simplify
> [Max[a,b,y,c],assum];
> Protect[Simplify];
> {Simplify};
> 
> With this modification we can apply Simplify to Max even with symbolic
> expressions, e.g.:
> 
> In[10]:=
> Simplify[Max[2a+1,2a+2,2a+3]]
> 
> Out[10]=
> 3 + 2 a
> 
> In[11]:=
> Simplify[Max[a+3,a^2+a+3,a],a>0]
> 
> Out[11]=
>          2
> 3 + a + a
> 
> The problem with this approach is that it makes Simplify work much more
> slowly with expressions containing Max with symbolic parameters, which may
> be undesirable in some situations. So it may be  be prefarable to define a
> new function (e.g. mySimplify or myMax) which would behave in the above way.
> 
> The answer to the second question is similar, that is, you have ot modify
> Simplify in the above manner or define your own version.
> 
> --
> Andrzej Kozlowski
> Toyama International University
> JAPAN
> 
> http://platon.c.u-tokyo.ac.jp/andrzej/
> 
> 
> on 3/29/01 9:24 AM, Ralph Benzinger at mma-l at endlos.net wrote:
> 
> > Hello:
> >
> > For many years I've been under the impression that Max[] can deal with
> > numerical quantities only:
> >
> > In[1]:=
> > Max[a + 1, a + 2]
> > Out[1]=
> > Max[1 + a, 2 + a]
> >
> > I was quite surprised when some days ago I discovered by accident that
> > Max[] actually does simplify symbolic arguments when specifically told
> > to do so:
> >
> > In[2]:=
> > Max[a + 1, a + 2] // Simplify
> > Out[2]=
> > 2 + a
> >
> > But I was even more surprised when I tried to get a feel for the
> > capabilities of the function:
> >
> > In[3]:=
> > Max[2a + 1, 2a + 2] // Simplify
> > Out[3]=
> > Max[1 + 2 a, 2 + 2 a]
> >
> > Just WHY can Mathematica simplify [2] but not [3]?  Does anybody
> > happen to know some details about the inner workings of the Max[]
> > function?
> >
> > A related question to my "discovery": Is there a standard way of
> > defining a "simplification" rather than an "evaluation" rule?  For
> > example, if I have some function `foo' and I do _not_ want to include
> > the definition
> >
> > foo[a_] + foo[b_] ^:= foo[a+b]
> >
> > can I still have the rewrite rule
> >
> > foo[a_] + foo[b_] -> foo[a+b]
> >
> > applied automatically whenever I invoke Simplify[]?
> >
> > Regards,
> > Ralph


  • Prev by Date: mathlink compile problem
  • Next by Date: Re: Strange behavior of NSum on 4.0
  • Previous by thread: Re: Unconventional Max[] behavior
  • Next by thread: Defining a flat, orderless, one-identical function?