Comments (7)
Pymbolic flattens those, assuming that multiplication is associative. (Product
can have multiple children.) Do you have a use case in which that's not correct behavior?
from pymbolic.
Pymbolic flattens those,
The AST is correct (i.e. unflattened) but I think the StringifyMapper
is to be blamed here.:
>>> a * (b * c)
Product((Variable('a'), Product((Variable('b'), Variable('c')))))
Do you have a use case in which that's not correct behavior?
No, no concrete use case.
from pymbolic.
No, no concrete use case.
Well given floating point arithmetic is not associative we can always buggy behavior associated with this in a generated code ;).
from pymbolic.
Well given floating point arithmetic is not associative we can always buggy behavior associated with this in a generated code ;).
Grr, you're right. We should probably turn off auto-flattening. #69
For the StringifyMapper
, I can think of use cases where I'd want the parentheses and where I wouldn't. (Math vs CS, really.) Would an option be OK?
from pymbolic.
I can think of use cases where I'd want the parentheses and where I wouldn't. (Math vs CS, really.) Would an option be OK?
I think its unsafe to stringify to incorrect schedules and should be avoided.
Would an option be OK?
Yep, but the default should prefer correctness.
from pymbolic.
OK, I can live with that.
from pymbolic.
I think it is not just StringifyMapper that is wrong, even the parser implements left-to-right associativity incorrectly:
>>> parse("a*b*c")
Product((Variable('a'), Product((Variable('b'), Variable('c')))))
>>> from pymbolic.mapper.evaluator import evaluate
>>> a_np = np.float64(1/3)
>>> b_np = np.finfo("float64").max
>>> c_np = np.float64(2)
>>> a_np * b_np * c_np
1.1984620899082103e+308
>>> evaluate(parse("a*b*c"), {"a": a_np, "b": b_np, "c": c_np})
/home/line/.local/lib/python3.10/site-packages/pytools/__init__.py:1103: RuntimeWarning: overflow encountered in double_scalars
return reduce(mul, iterable, 1)
inf
from pymbolic.
Related Issues (20)
- Cached mappers can't handle lists HOT 8
- Minimum python version for running tests is unexpectedly 3.10 HOT 2
- Test missing assertions HOT 3
- Pymbolic to SymEngine conversion error when using FloorDiv. HOT 6
- ParseError when parsing assignment expression HOT 4
- pymbolic interoperabiity with python ast described in the pymbolic documentation raises an exception under python 3.8.2 HOT 2
- Symengine version mismatch in CI HOT 9
- TypeError for foreign unhashable types HOT 4
- Mapper for deriving subexpressions as a list HOT 1
- [parser] Cannot parse boolean literals HOT 2
- Use a better parser HOT 3
- Applicability for Image Domain Delayed Operation Problem HOT 3
- Method for removing the `__getinitargs__` and `init_arg_names` boilerplate. HOT 1
- Symengine conversion fails due to potentially spurious isinstance check HOT 2
- [Parser] Incorrect if-else precedence
- Stop auto-flattening HOT 3
- Equality comparison of DAGs can have exponential complexity
- EvaluationMapper can't handle math functions HOT 1
- Memoizing results of traversals HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymbolic.