Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

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

Search the Archive

Re: Replacement question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35150] Re: [mg35114] Replacement question
  • From: Omega Consulting <omega_consulting at yahoo.com>
  • Date: Wed, 26 Jun 2002 01:09:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Mathematica is designed to evaluate everything it gets it's hands on. It 
takes extra effort to hold the evaluation process. To get the held 
expression, you can use the DownValues of In.

In[101]:=
held = Hold[In[100]]/.DownValues[In]

Out[101]:=
Hold[h[3]/f[2.33342]]

Then you can do the replacement.

In[102]:=
ReleaseHold[held/.h[3]->h[5]]

At 02:41 AM 6/25/2002, ginak wrote:
>Suppose I have something like
>
>  In [100] := h[3]/f[2.33342]
>
>  Out[100] := 24.12711
>
>and now I want to evaluate h[5]/f[2.33342], i.e. the same as in
>In[100] but replaceing h[3] with h[5].  This won't work
>
>  In [101] := In[100] /. h[3]->h[5]
>
>  Out[101] := 24.12711
>
>because In[100] is fully evaluated to 24.12711 before the rule is
>applied.  (Generally, the expressions I'm interested in are more of a
>pain to type than h[5]/f[2.33342]).  How do I tell Mathematica to evaluate
>In[100] only enough to apply the given substition rule, apply the
>substitution rule, and only then proceed with the evaluation?
>
>In fact, I don't even know how to do a replacement like
>
>  In [102] := h[3]/f[2.33342] /. h[3]->h[5]
>
>for the same reason: the LHS is evaluated before the rule can be
>applied.  (Of course, in this case this replacment task is pointless,
>since it is so easy to type out the desired expression, but there are
>situations in which one can obtain a complicated expression by cutting
>and pasting, and wants to apply a substitution rule to the complicated
>expression before Mathematica evaluates it.)
>
>Thanks!
>
>G.

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.
http://www.wz.com/internet/Mathematica.html



  • Prev by Date: RE: ConstrainedMin with negative variables
  • Next by Date: help on backtesting
  • Previous by thread: Re: Replacement question
  • Next by thread: RE: Replacement question