|
[Date Index]
[Thread Index]
[Author Index]
Re: Problem with evaluation of delayed rules
- To: mathgroup at smc.vnet.net
- Subject: [mg21758] Re: Problem with evaluation of delayed rules
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Thu, 27 Jan 2000 22:56:39 -0500 (EST)
- References: <85mkef$1og@smc.vnet.net> <86bkpr$b3o@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Eckhard,
More thoughts
Investigating the Trott-Strzebonski method for In-Place Evaluation (see
Robby Villegas:
http://library.wolfram.com/conferences/devconf99/villegas/UnevaluatedExpress
ions.nb)
Lead me to
If[x > 0, Difference[1, 2], Difference[3, 4]] /. Difference[x_, y_] :>
Block[{}, symbols[[x]] - symbols[[y]] /; True]
If[x > 0, a - b, c - d]
And tracing the evaluation of this shows that the main work is done by the
internal function RuleCondition.
If[x > 0, Difference[1, 2], Difference[3, 4]] /. Difference[x_, y_] :>
RuleCondition[symbols[[x]] - symbols[[y]], True]
If[x > 0, a - b, c - d]
So it seems that, as with Hartmut Wolf's solution, we need to wrap the right
side of the rules appropriately.
I'll get back on the evaluation steps later.
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Eckhard Hennig" <hennig at itwm.uni-kl.de> wrote in message
news:86bkpr$b3o at smc.vnet.net...
> Thanks to everyone who responded to my message regarding evaluation of
> delayed rules in held expressions. Unfortunately, none of the proposed
> solutions fully meets my requirements, either because Condition 1 (no
> specific solution for "If") was not taken into account or because it
doesn't
> work for my particular application. What I posted was just a simple
example,
> and the actual problem is indeed a bit more complicated:
>
> Let "equations" denote a list of mathematical expressions involving "If"
> statements (or other control statements with HoldXXX attribute). In
> "equations", I want to apply the following substitutions. All delayed
rules
> must be evaluated as soon as they apply because the variable "mnavar" (a
> list of symbols) is local to a Block.
>
> equations /.
> { Derivative[_][_][x_ /; x =!= $TimeVariable] -> 0,
> Derivative[k_][Voltage[a_, b_, _]][$TimeVariable]
> | Derivative[k_][Voltage[a_, b_, _]] :>
> D[mnavar[[a]] - mnavar[[b]], {$TimeVariable, k}],
> Voltage[a_, b_, _] :> mnavar[[a]] - mnavar[[b]],
> Derivative[k_][Current[__, i_]][$TimeVariable]
> | Derivative[k_][Current[__, i_]] :>
> D[BranchCurrentIdentifier[i], {$TimeVariable, k}],
> Current[__, i_] :> BranchCurrentIdentifier[i] }
>
> Several responses to my original message suggested using a "Cases"
statement
> to build up a list of evaluated replacement rules dynamically and then
apply
> this list to the expression. This solution has two disadvantages: it needs
> more memory and it does not work for more than one delayed rule at a time,
> thus requiring repeated application of the "Cases" approach for each of
the
> above rules. In my application, these drawbacks are not acceptable because
> the "equations" may be very large, so that memory efficiency and
performance
> is an important issue.
>
> Any other solutions that don't involve specific solutions for the "If"
> statement or degrade performance?
>
> Best regards,
>
> Eckhard
>
> -----------------------------------------------------------
> Dipl.-Ing. Eckhard Hennig mailto:hennig at itwm.uni-kl.de
> Institut fuer Techno- und Wirtschaftsmathematik e.V. (ITWM)
> Erwin-Schroedinger-Strasse, 67663 Kaiserslautern, Germany
> Voice: +49-(0)631-205-3126 Fax: +49-(0)631-205-4139
> http://www.itwm.uni-kl.de/as/employees/hennig.html
>
> ITWM - Makers of Analog Insydes for Mathematica
> http://www.itwm.uni-kl.de/as/products/ai
> -----------------------------------------------------------
>
>
>
>
>
Prev by Date:
Re: DSolve problems with system of ODEs. Out in pure notation?
Next by Date:
Re: Could this be improved?
Previous by thread:
Re: Re: Problem with evaluation of delayed rules
Next by thread:
Re: Verifying PrimeQ for n >10^16
|