2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 1) can you reproduce your problem with a minimal example? Also, what is exactly the desired outcome? 2) you have a dangling } in both examples of your code; 3) Is the first term -(1/2) E^(-e t) multiplied by the second (2 - 2...)? $\endgroup$ – MarcoB Nov 20 '19 at 23:48
6
$\begingroup$

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]))]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.