为什么 sympy.init_printing 改变集合表示法?

Why does sympy.init_printing change set notation?

当我调用 sympy.init_printing() 时,设置符号从 {a, b, c} 更改为 set([a, b, c])。为什么会这样?

In [1]: import sympy

In [2]: (x, y, z) = sympy.symbols("x y z")

In [3]: x+y**z
Out[3]: x + y**z

In [4]: (x+y**z).free_symbols
Out[4]: {z, y, x}

In [5]: sympy.init_printing()

In [6]: x+y**z
Out[6]: 
     z
x + y 

In [7]: (x+y**z).free_symbols
Out[7]: set([x, y, z])

In [8]: {1, 2, 3}
Out[8]: set([1, 2, 3])

(它还会更改项目的顺序,如图所示)

这是一个 Python 2 对 3 的问题。在 Python 2 中,集合像 set([...]) 一样打印,因为 {...} 集合文字直到 Python 2.7 才被添加。 SymPy 打印机是在 Python 3.

之前制造的

在 SymPy 版本 1.0 之后,SymPy 不再支持 Python 2.6,所以这已在 SymPy master 中修复,始终使用 {...}(即使在 Python 2 中)在 https://github.com/sympy/sympy/pull/11116 for the string printer, but apparently I missed that the pretty printer does this as well. I've put a fix in at https://github.com/sympy/sympy/pull/12087

因此,简而言之,在这些更改之后(即在 SymPy 的开发版本和所有未来版本中),SymPy 打印将使用 {...} 符号打印集。