
On Mon, 31 May 2021 at 13:10, Neil Girdhar <mistersheik@gmail.com> wrote:
Have you considered using the JAX library's trick of decorating functions to provide automatic symbols?
For example, your problem could be done in current Python with an appropriately-coded library:
@symbolic def f(x, a, b, c): return a * x ** 2 + b * x + c
sentinel = Sentinel()
solve(f(sentinel, 1, 0, -1 / 2), solve_for=sentinel)
The idea is that f(sentinel) would produce the expression graph by propagating tracer objects throughout the tree. Then, solve would identify the appropriate tracer to be solved.
JAX uses this trick to accomplish three tasks: JIT compilation of mathematical expressions, automatic calculation of gradients and related functions, and automatic generation of vectorized versions of functions.
To be fair, JAX's design is brilliant. I don't fault the SymPy people for not coming up with it, but the problem that you're trying to solved could be done with a better-designed SymPy. You don't need new syntax.
Hi Neil, Thanks for the suggestion but I'm not sure exactly what you mean. It's not clear to me what problem you think this would solve for sympy. If the problem is to do with needing to declare symbols then this solution seems awkward because it only works if the variables are function parameters so that a decorator can be used on the function. The current situation is this: a, b, c, x = symbols('a:c, x') eq = a*x**2 + b*x + c Your suggestion seems to require defining an otherwise unnecessary function like this: @symbolic def equation(a, b, c, x): return a*x**2 + b*x + c eq = equation() That doesn't seem like an improvement to me (maybe I've misunderstood...). Oscar