1
$\begingroup$

I will give two cases, where the rule replacement works in the first one and does not work in the second one, but they are essentially the same!

Consider the following definition, whose details are not important:

vall = -Sqrt[Δ^2 + μ^2 + 2*μ*Sqrt[px^2 + py^2] + px^2 + py^2]

Now, we check the following:

vall /. {ϕ -> 0, py -> pyy, px -> 0, μ -> 0}

As expected, I can obtain the desired replacement:

minus square root of pyy^2 + Delta^2: substitution achieved

Now, consider the following expression, which contains the above expression as a subexpression:

Exists[
 {py, pyy}, 
 123 == (vall /. {ϕ -> 0, py -> pyy, px -> 0, μ -> 0}) == 0  ]

The result is surprising:

no substitution was achieved

As can be seen in the picture, no replacement py -> pyy is made!

Why does this happen?

$\endgroup$
3
  • 1
    $\begingroup$ You should condense your problem to a much smaller, minimal working example that reproduces the behavior you see. $\endgroup$ – MarcoB Mar 29 at 3:19
  • 1
    $\begingroup$ @MarcoB I simplified the code. $\endgroup$ – eigenvalue Mar 29 at 7:12
  • $\begingroup$ After printing vars like Exists[{py, pyy}, Print[{py, pyy}]; 123 == (vall /. {[Phi] -> 0, py -> pyy, px -> 0, [Mu] -> 0}) == 0] your will note that Exists renamed vars. So, substitution simply do not mach pattern. $\endgroup$ – user18792 Mar 29 at 8:01
1
$\begingroup$

I suspect that this has to do with the HoldAll attribute of Exists (see Attributes[Exists]). However, if you force evaluation of its second argument, i.e. the expression you are trying to modify, you obtain the desired result:

Exists[
  {py, pyy}, 
  Evaluate[ 123 == (vall /. {ϕ -> 0, py -> pyy, px -> 0, μ -> 0}) == 0 ]
]

(* Out: Exists[{pyy}, 123 == -Sqrt[pyy^2 + Δ^2] == 0] *)
$\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.