pymbolic
pymbolic copied to clipboard
Stop auto-flattening
FP arithmetic isn't associative, after all.
I think the auto-flattening is just fine. See
>> import pymbolic.primitives as p
>>> a = p.Variable("a")
>>> b = p.Variable("b")
>>> c = p.Variable("c")
>>> (a * b) * c
Product((Variable('a'), Variable('b'), Variable('c'))) # flattening was legal and hence was done
>>> a * (b * c)
Product((Variable('a'), Product((Variable('b'), Variable('c'))))) # flattening wouldn't be legal and was avoided.
12569d59cb548c15094d11b2a1cc1bd36ebe4895 removed the flattening in IdentityMapper
.
As for flatten-upon-creation, we should document that the intended eval order is from left to right, so that the flattening behavior on operator overload is fine, as @kaushikcfd states.