1
$\begingroup$

Consider the following

ClearAll[eqv, not, neqv, p, q, r]
ReplaceAll[eqv[neqv[p, q], r], neqv[p_, q_] :> not[eqv[p, q]]]

eqv[not[eqv[p, q]], r]

According to the documentation, I should expect ReplaceList to return (at least) this result in a list, but, instead, I am surprised to get an empty list:

ClearAll[eqv, not, neqv, p, q, r]
ReplaceList[eqv[neqv[p, q], r], neqv[p_, q_] :> not[eqv[p, q]]]

{}

Again, according to the documentation, ReplaceList thinks there is no transformation possible, but ReplaceAll found one. I didn't see any indication that ReplaceList could be expected to return the empty list under any other circumstances.

This is important because in some deeper and more complicated programs, I need to scan all alternative replacements, but I now fear I can't trust ReplaceList.

Mathematica 11.3.0.0 Ubuntu 18.04

$\endgroup$
3
$\begingroup$

This is within the documented design of these functions.

ReplaceList[expr,rules] attempts to transform the entire expression expr by applying a rule or list of rules in all possible ways, and returns a list of the results obtained.

ReplaceAll[expr,rules] applies a rule or list of rules in an attempt to transform each subpart of an expression expr.

Perhaps a simpler example clarifies things:

In[3]:= ReplaceList[{1, 2, 3, 4}, x_Integer :> x^2]

Out[3]= {}

In[4]:= ReplaceAll[{1, 2, 3, 4}, x_Integer :> x^2]

Out[4]= {1, 4, 9, 16}
$\endgroup$
  • 1
    $\begingroup$ Sure enough, ReplaceList[neqvRule] /@ eqv[neqv[p, q], r], mapping instead of applying, reveals what I expected eqv[{not[eqv[neqv[p], neqv[q]]], not[eqv[p, q]]}, {}]. $\endgroup$ – Reb.Cabin Oct 13 '18 at 20:36

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.