Tag Info

New answers tagged

8

GCD[a] returns unevaluated because the definitions of GCD only apply when all arguments are numeric. The presence of even one non-numeric argument yields an unevaluated result: ClearAll[a] GCD[1, 2, 3, a] (* GCD[1, 2, 3, a] *) This is true even when the sole argument is non-numeric: GCD[a] (* GCD[a] *) The attribute OneIdentity has no bearing on this ...


6

Leaving aside the wisdom of modifying System functions this is an interesting question. I would not have been surprised to see this behavior had the input list been packed as I have already learned about low-level optimizations on packed arrays. See: Block attributes of Equal However that does not appear to be the issue here since (typed in) {1, 2, 3} ...


7

OneIdentity is a poorly, and I think incorrectly, documented attribute. It is not an attribute that would have the effect that f[x]=x, as can be seen in your GCD example. According to the documentation, it is an attribute that can be assigned to a symbol f to indicate that f[x], f[f[x]], etc. are all equivalent to x for the purpose of pattern matching. ...


11

I think the documentation needs to be more clear on this; the order of definitions is important: Remove[plus] Attributes[plus] = {Orderless}; plus[x__Integer, y__Real] := x + y plus[2.5, 3] 5.5 So the Orderless attribute must be active at the time the definition is created. Noteworthy is that definitions made before setting the attribute can ...



Top 50 recent answers are included