Being relatively new to Julia, I wrote something like the code below and stumbled on undefined behavior. Since the code below does not use the correct expr.subs()
syntax, shouldn’t it issue an error message or warning?
This
using SymPy
@syms x y
f = x + y^2
f(1,2)
can result in both 3 and 5.
It isn’t undefined, though it is arbitrarily defined: when specified in this way, the ordering follows that returned by free_symbols
which sorts the string value of each symbol. It could be better documented, though I’d suggest being explicit, as in f(x=>1, y=>2)
.
Shouldn’t free_symbols
always return the same order of x and y?
Yes, though it relies on string sorting which might give unexpected order.