12
$\begingroup$

Bug introduced in 11.0, persisting through 14.1.


Background info

I enocountered this problem when exploring

Pattern match about Times default value

But this turns out to be a different issue i.e. the behavior of code sample in the link is consistent in version 8 and version 14. So I decide to post this as a separate question.

Consider this example:

Replace[x y, c_. (a : (x y)) :> aaa]

In version 8.0.4, the output is aaa, which looks reasonable for me:

enter image description here

But it's not the case in version 14.1:

enter image description here

I don't have access to version 9 to 13 at the moment so cannot do further test.

My question is:

  1. Is this a bug, or intentional incompatible change (this does happen in the past, see e.g. this and this)?

  2. If it's an intentional change, what's the underlying reason for it?

$\endgroup$
8
  • 2
    $\begingroup$ To the downvoter, I am interested in what's wrong with my question, would you please elaborate. I'm not trying to complain here, I just want to improve my question if possible. $\endgroup$
    – xzczd
    Commented Oct 2 at 14:26
  • 1
    $\begingroup$ It appears to have changed in version 11.0. I do not yet know the cause. $\endgroup$ Commented Oct 2 at 17:46
  • 1
    $\begingroup$ This returns x y in Version "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)". Note that this only seems to be a problem for multiplication: Both Replace[x + y, c_. (a : (x + y)) :> aaa] and Replace[f[x, y], c_. (a : f[x, y]) :> aaa] yield aaa, so I wonder if this is doing some multiplication simplification first or something like that. $\endgroup$
    – march
    Commented Oct 2 at 19:01
  • 1
    $\begingroup$ It's worth noting that the matching is not happening: MatchQ[x y, c_. (a : (x y))] and MatchQ[x + y, c_. (a : (x + y))] yield False and True, respectively. Using Trace doesn't help. $\endgroup$
    – march
    Commented Oct 2 at 19:03
  • 3
    $\begingroup$ This has been filed as a bug. $\endgroup$ Commented Oct 2 at 19:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.