# SymPy undefined behavior

**URL:** <https://discourse.julialang.org/t/sympy-undefined-behavior/89432>\
**Category:** General Usage\
**Tags:** behavior, sympy\
**Created:** [October 28, 2022, 8:28am UTC](https://discourse.julialang.org/t/sympy-undefined-behavior/89432 "2022-10-28T08:28:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mendeli](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mendeli](https://discourse.julialang.org/u/mendeli)\
**Post date:** [October 28, 2022, 8:28am UTC](https://discourse.julialang.org/t/sympy-undefined-behavior/89432/1 "2022-10-28T08:28:44Z")

</div>

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

```julia
using SymPy
@syms x y
f = x + y^2
f(1,2)

```

can result in both 3 and 5.

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [October 28, 2022, 11:29am UTC](https://discourse.julialang.org/t/sympy-undefined-behavior/89432/2 "2022-10-28T11:29:40Z")

</div>

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)`.

---

<div class="post-metadata">

**Author:** ![samuelelipani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samuelelipani/32/43940_2.png) [@samuelelipani](https://discourse.julialang.org/u/samuelelipani)\
**Post date:** [October 28, 2022, 12:15pm UTC](https://discourse.julialang.org/t/sympy-undefined-behavior/89432/3 "2022-10-28T12:15:30Z")

</div>

Shouldn’t `free_symbols` always return the same order of x and y?

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [October 28, 2022, 12:59pm UTC](https://discourse.julialang.org/t/sympy-undefined-behavior/89432/4 "2022-10-28T12:59:06Z")

</div>

Yes, though it relies on string sorting which might give unexpected order.
