I am trying to write a replacement rule that will substitute values for d_1 and d_2 only the places they are outside the Phi equation:
I was able to write a function that replaced Phi[d_1] and Phi[d_2] with Phi[d1] and Phi[d2], thereby creating two new variables and then apply my transformation rules only to the original d_1 and d_2. But this does not generalize for when the function Phi contains a linear combination of d_1 and d_2, or some other value that I don't want to substitute for. Can you help me figure how to do this?
In mathematica code:
E^(-2 r T) k^2 (1 + E^(
2 Subscript[d, 1] (Subscript[d, 1] - Subscript[d, 2])) +
2 E^(1/2 (\!\(
\*SubsuperscriptBox[\(d\), \(1\), \(2\)] -
\*SubsuperscriptBox[\(d\), \(2\), \(2\)]\))) (-1 + \[CapitalPhi][
Subscript[d, 1]]) -
1] (Subscript[d, 1] - Subscript[d, 2])) \[CapitalPhi][
2 Subscript[d, 1] - Subscript[d, 2]] - \[CapitalPhi][Subscript[d,
2]])
Or, for easier copy/paste (brackets corrected):
E^(-2 r T) k^2 (1 + E^(2 Subscript[d, 1] (Subscript[d, 1] - Subscript[d, 2])) + 2 E^(1/2 (\!\(\*SubsuperscriptBox[\(d\), \(1\), \(2\)] -\*SubsuperscriptBox[\(d\), \(2\), \(2\)]\))) (-1 + \[CapitalPhi][Subscript[d, 1]]) - E^(2 Subscript[d, 1] (Subscript[d, 1] - Subscript[d, 2])) \[CapitalPhi][2 Subscript[d, 1] - Subscript[d, 2]] - \[CapitalPhi][Subscript[d,2]])
yourexpression /. {a : Φ[___] :> a, Subscript[d, a : 1 | 2] :> ToExpression["d" <> IntegerString[a]]}
? The first replacement prevents other replacements of expressions with headΦ
. $\endgroup$