Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6445
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Replace in an elegant way |
| Date | 2011-11-14 12:07 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j9r09k$bcp$1@smc.vnet.net> (permalink) |
| References | <j9o3hc$o$1@smc.vnet.net> |
On Sun, 13 Nov 2011 09:44:12 -0000, Mirko <dashiell@web.de> wrote:
> Hi all,
> I have following equation:
>
> ((1 + theta[m])^2)/(1 - m) - lambda*((theta[m] + ((lambda + m -
> lambda*m)*(1 + theta[m])*(1 + theta[m] - lambda*theta[m]))/(1 - m) +
> (m*Derivative[1][theta][m])/lambda))
>
> I want to replace all m that are not an argument of theta[m] or the
> Derivative. However, if I use
> /., it replaces all m. If I use Replace[expr,m->qq] it doesn't replace
> anything. (qq is the one I want to replace with). If I specify any
> level, it doesn't change anything, unless I use -1, but then I replace
> everything.
>
> Do you know how I solve this problem?
> Right now I use:
> //. Derivative[y_][theta][m] -> Derivative[y][theta][dd] //.
> theta[m] -> theta[dd] /. m -> qq //.
> Derivative[y_][theta][dd] -> Derivative[y][theta][m] //.
> theta[dd] -> theta[m]
>
> but this is not elegant at all (and takes slightly longer).
>
While still inelegant (since it contains replacements of items with
themselves), the following is something of an improvement over your
existing method:
expr /. {
deriv : Derivative[__][theta][m] :> deriv,
arg : theta[m] :> arg,
m -> qq
}
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Replace in an elegant way Mirko <dashiell@web.de> - 2011-11-13 09:44 +0000 Re: Replace in an elegant way "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-11-14 12:07 +0000
csiph-web