# ReplaceRepeated with special characters: Alternatives

Following the advice here, I tried to replace part of an expression guided by the FullForm details:

-B + b - ((-A +
a) \[\[DoubleStruckCapitalE]][(-A + a) (-B +
b) | \[ScriptCapitalF]])/\[DoubleStruckCapitalE][(-A +
a)^2 | \[ScriptCapitalF]] & // FullForm


Function[Plus[Times[-1, B], b, Times[-1, Times[Plus[Times[-1, A], a], [DoubleStruckCapitalE][ Alternatives[ Times[Plus[Times[-1, A], a], Plus[Times[-1, B], b]], [ScriptCapitalF]]], Power[ [DoubleStruckCapitalE][ Alternatives[ Power[Plus[Times[-1, A], a], 2], [ScriptCapitalF]]], -1]]]]]

However, the replacement rule still does not take effect

{-B + b - ((-A +
a) \[DoubleStruckCapitalE][(-A + a) (-B +
b) | \[ScriptCapitalF]])/\[DoubleStruckCapitalE][(-A +
a)^2 | \[ScriptCapitalF]] &} //. {\[DoubleStruckCapitalE][
Alternatives[
Power[Plus[Times[-1, a_], b_], 2], \[ScriptCapitalF]]] ->
Power[Plus[Times[-1, a], b], 2]}


I'm obviously struggling how to do things in MMA. Appreciate any hints or tips.

I am guessing that you meant to use Conditioned instead of Alternatives:

expr = -B + b - ((-A + a) ℰ[(-A + a) (-B + b) | ℱ])/ℰ[(-A + a)^2 | ℱ] &


InputForm @ %


-B + b - ((-A + a)ℰ[(-A + a)(-B + b) | ℱ])/ℰ[(-A + a)^2 | ℱ] &

expr2 = expr /. Alternatives -> Conditioned


InputForm @ %


-B + b - ((-A + a)ℰ[Conditioned[(-A + a)(-B + b), ℱ]])/ℰ[Conditioned[(-A + a)^2, ℱ]] &

expr2 /. ℰ[Conditioned[Power[Plus[Times[-1, a_], b_], 2], ℱ]] :>
Power[Plus[Times[-1, a], b], 2]


InputForm @ %


-B + b - ((-A + a)ℰ[Conditioned[(-A + a)(-B + b), ℱ]])/(-A + a)^2 &

Note: I replaced \[DoubleStruckCapitalE] with ℰ.

• Hmm, does this work using the \[Conditioned] symbol? Checking... yes it does. Thanks! Can update your answer to reflect the original question notation, then I'll be able to accept. Commented Dec 12, 2019 at 22:15