I'm working with a notebook that defines NonCommutativeMultiply
on a defined set of symbols, called operators
. Semantically, this is a list of objects that have a noncommutative multiplication (operators on a Hilbert space). It also contains a function CNumberQ
that returns true when its argument does not contain any operator.
CNumberQ[expr_] := And @@ (FreeQ[expr, #] & /@ operators);
NonCommutativeMultiply
has, as one of its definitions,
x_ ** y_ := x y /; CNumberQ[x] || CNumberQ[y]
Even though the replacement rule is constrained, the following pattern
x_ ** y_
evaluates to
x_ y_
Why does Mathematica apply a constrained replacement rule to a pattern that is unconstrained? I know I can work around this by using HoldPattern
, but I could not figure out why this replacement happens by looking at the documentation for rules and patterns.
Pattern
andBlank
are not in the list ofoperators
, i.e.,CNumberQ[y_]
evaluates toTrue
? $\endgroup$operators
. $\endgroup$