inducer / pymbolic

A simple package to do symbolic math (focus on code gen and DSLs)
http://mathema.tician.de/software/pymbolic
Other
106 stars 25 forks source link

Stop auto-flattening #69

Open inducer opened 2 years ago

inducer commented 2 years ago

FP arithmetic isn't associative, after all.

kaushikcfd commented 2 years ago

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.
inducer commented 1 year ago

12569d59cb548c15094d11b2a1cc1bd36ebe4895 removed the flattening in IdentityMapper.

inducer commented 1 year ago

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.