Skip to content

Instantly share code, notes, and snippets.

@joshuisken
Created April 22, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuisken/869c383c684ed75c6fde to your computer and use it in GitHub Desktop.
Save joshuisken/869c383c684ed75c6fde to your computer and use it in GitHub Desktop.
''' sympy.Dummy bug report '''
from __future__ import print_function
from sympy import Dummy, Symbol
import sympy
print("\nUsing sympy version:", sympy.__version__)
print("Example: (p + q) * (p + q) using various choices of p and q")
p = Symbol('p')
print("\np == p gives", p == p, ", OK")
f = (p + p) * (p + p)
print("f: ", f)
print("f: ", f.evalf(subs = {p: 2}), ", OK with p := 2\n")
q0 = Symbol('q')
q1 = Symbol('q')
print("q0 == q1 gives", q0 == q1, ", OK so Symbols are globally defined")
f0 = (q0 + q1) * (q0 + q1)
print("f0:", f0)
print("f0:", f0.evalf(subs = {q0: 2, q1: 1}), ", OK: using 'arbitrarily last' assignment from q0 := 2 and q1 := 1, chosen q1 := 1\n")
q4 = Dummy()
q5 = Dummy()
print("q4 == q5 gives", q4 == q5, ", OK, despite giving no name: unequal")
f4 = (q4 + q5) * (q4 + q5)
print("f4:", f4, ", OK the're different")
print("f4:", f4.evalf(subs = {q4: 2, q5: 1}), ", expect 9 here... with q4 := 2 and q5 := 1 ==> OK\n")
q2 = Dummy('q')
q3 = Dummy('q')
print("q2 == q3 gives", q2 == q3, ", OK, despite given the same name: unequal")
f2 = (q2 + q3) * (q2 + q3)
print("f2:", f2, "does not look like different q2/q3, but they are different, otherwise it would by symplified...")
print("f2:", f2.evalf(subs = {q2: 2, q3: 1}), ", expect 9 here... with q2 := 2 and q3 := 1 ==> BUG")
print("I guess the name '_p', should be made unique?")
print("In any case: value assignment FAILS\n")
@joshuisken
Copy link
Author

For sympy 0.7.[56] this code produces a wrong answer when evaluating function f2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment