MathGroup Archive 2001

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

Search the Archive

Re: Custom Function's Rules Ignored in Simplify/FullSimplify?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27838] Re: Custom Function's Rules Ignored in Simplify/FullSimplify?
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Mon, 19 Mar 2001 17:51:19 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

The definition f[x_ /; x > 1] := 99 results in Mathematica storing the
follwoing rule:

HoldPattern[f[x_ /; x > 1]] :> 99

as a DownValue of f. What this means is that only when Mathematica sees a
pattern which matches the left hand side the rule will be used. This is
quite different from the mechanism used by Simplify. In particular, rules
given by specifiying patterns are not "deductive" as can be seen in the
following example:

f[x_ /; x > 1] := 99

y /: (y > 1) = True

In[3]:=
f[y]

Out[3]=
99

In[4]:=
f[y+1]

Out[4]=
f[1+y]

The only way to make Simplify (or FullSimplify) use automatically rules like
the one you gave for f, is to either modify Simplify or define your own
version, for example as below:

mySimplify[expr_, x_, cond_] /; Not[FreeQ[expr, f[x]] || FreeQ[cond, x]] :=
  If[Simplify[x > 1, cond], Simplify[expr /. f[x] -> 99, cond],
    Simplify[expr, cond]]

This will now do the sort of thing you had in mind, at leastin simple cases,
e.g.:


In[6]:=
mySimplify[f[x]+Sqrt[a^2],x,{x>1,a>0}]

Out[6]=
99+a

or evn in more complex ones:

In[7]:=
mySimplify[Sqrt[(f[y]+3+x)^2],y,{y>2,x>0}]

Out[7]=
102+x


-- 
Andrzej Kozlowski
Toyama International University
JAPAN

http://platon.c.u-tokyo.ac.jp/andrzej/


on 3/19/01 7:29 AM, Steve W. Brewer at ste-ve at kate-ch.com wrote:

> I'm having a problem with Mathematica 4.0.
> 
> 
> Say I define a function:
> 
> f[x_ /; x > 1] := 99
> 
> 
> Then I try a Simplify or FullSimplify using assumptions:
> 
> FullSimplify[f[x], x > 1]
> 
> 
> Obviously, the correct result should be:
> 
> 99
> 
> 
> But the best I can get Mathematica to do is:
> 
> f[x]
> 
> 
> How can I get Mathematica to incorporate my function's rules into Simplify
> and FullSimplify?
> 
> 
> Thanks,
> Steve W. Brewer
> (Remove the two dashes from my email address to send email.)
> 
> 
> 
> 



  • Prev by Date: Re: page numbers of cells with celltag
  • Next by Date: Re: ExtendGraphics LabelContour Error Message
  • Previous by thread: Custom Function's Rules Ignored in Simplify/FullSimplify?
  • Next by thread: Re: Custom Function's Rules Ignored in Simplify/FullSimplify?