MathGroup Archive 2009

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

Search the Archive

Re: Replace in operators

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102913] Re: [mg102869] Replace in operators
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Wed, 2 Sep 2009 04:02:06 -0400 (EDT)
  • References: <200909010750.DAA18607@smc.vnet.net>

Hi,

Replacement does not happen because the internal form of the derivative does
not
contain f[x] anywhere:

In[1] = D[f[x], x] // FullForm

Out[1] = Derivative[1][f][x]

One option would be indeed to use something lime f->g. Not knowing your
context,
one other thing I can suggest is: take your operator and wrap it in
Unevaluated. This way
you get, for instance:

In[2] = Unevaluated[f[x] + D[f[x], x]] /. f[x] -> g[x]

Out[2] = g[x]+(g^\[Prime])[x]

The role of Unevaluated here was to prevent the rewriting of D[f[x], x] into
Derivative[1][f][x], which
otherwise takes place internally before the rule substitution happens.

In general, it is worth realizing that there aren't special "rules for
operators" etc - there are only Mathematica expressions and evaluation
process, which follow the same rules regardless of what these expressions
mean to us. Replacements  are based entirely on the syntactic form of
expression, and if they did not happen as planned, then the pattern of your
rule does not match the form that the expression takes ***by the time
replacement is about to happen***.

Hope this helps.

Regards,
Leonid


On Tue, Sep 1, 2009 at 11:50 AM, did <didier.oslo at hotmail.com> wrote:

> I can't figure out how to force Mathematica to replace
> f[x] by g[x] in expressions involving operators.
> For example:
>
> f[x] + D[f[x],x] /. f[x] -> g[x]
>
> f is not replaced in the derivative. I found
> somewhere in the manual that the replacement
> does not work on operators, but then it does
> not indicate how to do it.
>
> In my real problem, f[x]->g[x] is a (long)
> list of complicated transformations resulting
> from the resolution of many equations.
> Thus, changing f[x]->g[x] by f->g is not
> an option.
>
> f[x] + D[f[x],x] is actually a complicated
> expression involving many operators.
>
> There are no ways I can do the
> substitution by hand, bit by bit.
>
> Any suggestions ?
> Thanks
>
> PS: it may help to precise the context.
> I'm trying to solve a system of PDEs by
> a small parameter expansion. Solving the
> system at order N, I want to re-inject the
> results into the equations at order N+1.
>
>


  • Prev by Date: Re: Faster alternative to AppendTo?
  • Next by Date: Re: Question about SDTS format
  • Previous by thread: Re: Replace in operators
  • Next by thread: Re: Re: Replace in operators