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
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.
> (* Sinh information does include the identity above. *)
> (* Cosh information does include the identity above. *)
> (* 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:= << "ProgrammingInMathematica\\TrigSimplification.m"
In:= Sin[x]^2 + Cos[x]^2 // TrigLinear
You get what you want, without any performance penalties elsewhere.
With kind regards,
> For Mathematica tips, tricks see
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