Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: This is what UpValues are for

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19422] Re: [mg19357] This is what UpValues are for
  • From: "Wolf, Hartmut" <hwolf at debis.com>
  • Date: Mon, 23 Aug 1999 13:57:27 -0400
  • Organization: debis Systemhaus
  • References: <199908210309.XAA12608@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Hallo Ted,

we all thank you very much for your elucidations on UpValues, I'd just
like to add two little comments:

this is from your posting:
> 
> We could also use the next line to associate the identity with both (Sinh)
> and (Cosh), but not (Plus).  This is clear from the result of evaluating
> (??Sinh ), (??Cosh ), (??Plus ).  In this case the identity is stored in
> DownValues[Sinh] and DownValues[Cosh].  When this method is used both (Sinh)
> and (Cosh) will run slower.
> 
> In[11]:=
> Cosh[z_]+Sinh[z_]^:=Exp[z];
> ??Sinh
> (* Sinh information does include the identity above. *)
> 
> In[12]:=
> ??Cosh
> (* Cosh information does include the identity above. *)
>
> In[13]:=
> ??Plus
> (* Plus information doesn't include the identity above. *)
>

You said "...both (Sinh) and (Cosh) will run slower"

This could be misconstrued. As far as I understand Mathematica -- I
confess I did not prove this by testing, so I'm feeling a little bit
uncomfortable -- the execution of Sinh and Cosh, whenever you call them,
will _not_ be less efficient than before. However, when evaluating any
expression that contains Sinh or Cosh at level 1, when within the
evaluation sequence for _that_ expression it comes at looking for
UpValues >>some will be found for Sinh or Cosh and then have to be
checked whether they apply<< That's the >>extra effort<< , but that's
the minimal prize you have to pay as long as you want to install that
relation as a general rule -- and Mathematica will pay you back.

> --------------------
> Now suppose you wanted the kernel to automatically use the identity
>   Sin[z]^2 + Cos[z]^2 -->1
> 
> Notice both (Sin[z]^2) and (Cos[z]^2) have the Head Power.
> 
> You could give ...
> ...

> BUT Mathematica will not let you associate the definition above with (Sin)
> or (Cos) ...
> ...

I think we should mention Roman E. Maeders "Programming in Mathematica",
Chapter 6 "Building Rule Sets" where he told how to effectively deal
with those cases. So if you do:

In[1]:= << "ProgrammingInMathematica\\TrigSimplification.m"

In[2]:= Sin[x]^2 + Cos[x]^2 // TrigLinear
Out[2]= 1

You get what you want, without any performance penalties elsewhere.

With kind regards, 
your hartmutw

------------------------------------
> 
> For Mathematica tips, tricks see
> http://www.dot.net.au/~elisha/ersek/Tricks.html



  • Prev by Date: Re: Magnitude of Vector
  • Next by Date: Re: Standard Evaluation with UpValues
  • Previous by thread: This is what UpValues are for
  • Next by thread: RE: This is what UpValues are for