Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Re: Re: symbol replace


Hi,
have you ever tried the package <<Utilities'Notation? It is a standard
built-in package and I think It's perfect for your first problem, just do:
<< Utilities`Notation`

Notation Palette will appear, then select Symbolize[] from the palette
(AND ONLY FROM THE PALETTE,do not type it) and:
Symbolize[Eo];

every expression containing Eo from now on will be treated correctly (even
replace rules),for more informations about Symbolize[] ??Symbolize or
search mathematica help browser.
Hope it helps,
Delfino Matteo

> Hi,
>
> Answer to the first question.
> You should temporary replace \!\(E\_0\) (Subscript[E,0]) with "E0" or
> other unused symbol, then perform substitution and finally replace "E0"
>  back:
>
> In[1]=  E*Subscript[E,0]/.
>          Subscript[E,0]->"E0"/.
>          E->Subscript[E,0]/.
>          "E0"->Subscript[E, 0]
> Out[1]= Subscript[E, 0]^2
>
> The following is general solution for this problem.
> Function "SubscriptProtectReplaceAll" is the same as
> Build-In function "ReplaceAll", but it preserves parts of
> Subscripted symbols from replacing:
>
> In[2]=  SubscriptProtectReplaceAll[exprn_, rules_] :=
>          Module[{ProtectRules},
>            ProtectRules =
>              Cases[
>                exprn,
>                Subscript[A_,b_]:>(Subscript[A,b]->Unique[tmp]),
>                {0, Infinity},
>                Heads->True
>              ];
>            exprn/.ProtectRules/.rules/.(Reverse/@ProtectRules)
>          ]
>
> In[3]=  SubscriptProtectReplaceAll[
>          E*Subscript[E,0],
>          E->Subscript[E,0]
>        ]
> Out[3]= Subscript[E,0]^2;
>
> More sophisticated example:
>
> In[4]=  \!\(SubscriptProtectReplaceAll[A+A\_2+A\_A+A\_\(A\_3\)+A\_4[x],
>            A->A\_1]\)
> Out[4]= \!\(A\_1+A\_2+A\_A+A\_\(A\_3\)+A\_4[x]\)
>
> The following code permanently substitutes "ReplaceAll" with
> "SubscriptProtectReplaceAll":
>
> In[5]=  Unprotect[ReplaceAll];
>        SubscriptProtect[ReplaceAll]=True;
>        (exprn_ /. rules_)/;SubscriptProtect[ReplaceAll]:=
>          Block[{SubscriptProtect},
>            SubscriptProtect[ReplaceAll]=False;
>            SubscriptProtectReplaceAll[exprn, rules]
>          ];
>        Protect[ReplaceAll];
>
> Now you can use ordinary substitution symbol "/.":
>
> In[6]=  \!\(A+A\_2+A\_A+A\_\(A\_3\)+A\_4[x]/.A->A\_1\)
> Out[6]= \!\(A\_1+A\_2+A\_A+A\_\(A\_3\)+A\_4[x]\)
>
> Resetting
>
> In[7]=  SubscriptProtect[ReplaceAll]=False;
>
> Will return you to ordinary substitution rules.
>
>
>
> Sincerely,
> Maxim A. Dubinnyi
>
>
>
> symbio wrote:
>
>>I am facing 2 problems with Mathematica:
>> 1st problem)
>>With replace all command,  when I use it with subscripts I get an
>>unintended  effect, this is what I do:
>>E * (Eo) /. E -> (Eo)
>>I intend to replace only E with Eo, but Mathematica instead replaces
>>all E's  with (Eo) and I get this instead:
>>(Eo) * (Eo)o
>>Please note the 'o' in Eo is supposed to be a subscript here and reads
>>Enot.  Can anyone please help?
>>here is the Mathematica code:
>>
>>In[1]:=
>>\!\(E\ *\ E\_0\ /. \ E -> \ E\_0\)
>>Out[1]=
>>\!\(\[ExponentialE]\_0\ \((\[ExponentialE]\_0)\)\_0\)
>>
>>2nd problem)
>>I like to use descriptive names for my variables with Underscore to
>>separate  the names, it's really easier to read, but of course
>>underscore is a special  character in Mathematica unfortunately, so is
>>there an alternative??   For  example, I like to use variable
>>Dynamic_Energy_of_Stars_With_Sand = 123;  Is  there something else
>>equally as obvious as Underscore that maybe used for  purpose of
>>separting words in a variables names??
>>
>>Thanks a lot for your help
>>
>>




  • Prev by Date: Re: Re: normal distribution random number generation
  • Next by Date: Re: Re: normal distribution random number generation
  • Previous by thread: Re: symbol replace
  • Next by thread: Re: symbol replace