This workaround does what I'd like to have happen:
{-(1/2) E^(-e t)
(2 - 2 NormCDF[((-2 e + s^2) t - 2 Log[A])/(2 s Sqrt[t])])} //. {2 -
2 NormCDF[x___] -> 2 NormCDF[-x]}
I expected this to work, but it doesn't:
{-(1/2) E^(-e t)
(2 - 2 NormCDF[((-2 e + s^2) t - 2 Log[A] + 2 Log[K])/(2 s Sqrt[t])])} //. {n_ -
n_ NormCDF[x___] -> n NormCDF[-x]}
Appreciate any hints or tips.
Answer
As always with a replacement issue, look at the FullForm of your expressions. Here is your expression:
expr = (2-2 NormCDF[((-2 e+s^2) t-2 Log[A]+2 Log[K])/(2 s Sqrt[t])]);
expr //FullForm
Plus[2,Times[-2,NormCDF[Times[Rational[1,2],Power[s,-1],Power[t,Rational[-1,2]],Plus[Times[Plus[Times[-2,e],Power[s,2]],t],Times[-2,Log[A]],Times[2,Log[K]]]]]]]
And here is your rule:
rule = n_-n_ NormCDF[x___];
rule //FullForm
Plus[Pattern[n,Blank[]],Times[-1,NormCDF[Pattern[x,BlankNullSequence[]]],Pattern[n,Blank[]]]]
Notice how the product in your expression is of the form:
Times[-2, _NormCDF]
and your replacement rule uses:
Times[-1, _NormCDF, n_]
Since they don't match, no replacement occurs. An alternative that will work is:
expr /. n_ + m_ NormCDF[x_] /; n+m==0 :> n NormCDF[-x]
2 NormCDF[-(((-2 e + s^2) t - 2 Log[A] + 2 Log[K])/(2 s Sqrt[t]))]
Comments
Post a Comment