Open jakoblem opened 2 years ago
Can't you access the new symbols using .free_symbols
?
Sure, one can do sols[0].subs(sols[0].free_symbols.pop(),4)
but this is the same as sols[0].subs(Symbol('x_0', integer=True),4)
. The command sols[0].free_symbols.pop()
prints $x_0$ without indicating that $x_0$ has to be accessed by Symbol('x_0', integer=True)
.
The symbol you pass is just used to create the name for the parameter. You don't have to know the assumptions on the parameter when you use free_symbols
:
>>> T = Tuple(*sols)
>>> p = T.free_symbols
>>> T.subs(p[0],1)
(-2, -3)
Thanks, free_symbols may work for me, but I wish there was a simpler solution. I am using SymPy for (university) teaching for students without programming background. Students often wants to substitute values of the solution variables, and the current way to do this requires several steps (and may depend on the output type of the solver, e.g., diophantine, solve, linsolve, solveset)
We may need some research about the types of output that solvers. For describing the infinite set of solutions, there are many options, from using the substitution form (like first order logic) or explicitly giving the basis (like linear algebra). There are also the cases where algebraic equations cannot be transformed to the variable to term substitution form, but another simpler algebraic equation is returned instead.
See #20682 for some suggestions for improving the diophantine
API.
print(sols) is a tuple of
(3*x_0 - 5, 2*x_0 - 5)
, however line 4 leads to NameError. One has to writesols[0].subs(Symbol('x_0', integer=True),4)
as can be seen fromsrepr(sols[0])
. Not exactly an error, but I think it will confuse many users.