Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6440

Re: Replace in an elegant way

From Ulrich Arndt <ulrich.arndt@data2knowledge.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Replace in an elegant way
Date 2011-11-14 12:06 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j9r07n$bb8$1@smc.vnet.net> (permalink)
References <201111130943.EAA29993@smc.vnet.net> <AE38C434-8D19-4785-A21C-B8E7F5B7D8FE@data2knowledge.de>

Show all headers | View raw


Seeing the problem of theta'[m] and giving on more thought on problems 
of "dummy" replacements this might be more generic


Clear[replacebyhash, replacebyexp]
replacebyhash[exp_, replaceList_List] := Module[{rules},
   rules = Map[Rule[#, ToString[Hash[#, "SHA256"]]] &, replaceList];
   exp /. rules
   ];

replacebyexp[exp_, replaceList_List] := Module[{rules},
   rules = Map[Rule[ToString[Hash[#, "SHA256"]], #] &, replaceList];
   exp /. rules
   ];

ignoreList = {theta[m], theta'[m]}

replacebyexp[
 replacebyhash[expression, ignoreList] /. m -> gg, ignoreList]

Ulrich

Am 13.11.2011 um 11:50 schrieb Ulrich Arndt:

> not sure if we consider this as elegant but at least it is clear what 
is done...
>
> expression = ((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));
>
> expression /. theta[m] -> dummy /. m -> gg /. dummy -> theta[m]
>
>
> Ulrich
>
> Am 13.11.2011 um 10:43 schrieb Mirko:
>
>> 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).
>>
>
> --
> Ulrich Arndt
> Mobile: +49 172 287 6630
> ulrich.arndt@data2knowledge.de
> www.data2knowledge.de
>
> data2knowledge GmbH
> Fahrenheitstr. 1
> D-28359 Bremen
>
> Gesch=E4ftsf=FChrung: Ulrich Arndt
> Sitz der Gesellschaft: Bremen, Amtsgericht Bremen, HRB 26480 HB
>
>

--
Ulrich Arndt
Mobile: +49 172 287 6630
ulrich.arndt@data2knowledge.de
www.data2knowledge.de

data2knowledge GmbH
Fahrenheitstr. 1
D-28359 Bremen

Gesch=E4ftsf=FChrung: Ulrich Arndt
Sitz der Gesellschaft: Bremen, Amtsgericht Bremen, HRB 26480 HB


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Replace in an elegant way Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2011-11-14 12:06 +0000

csiph-web