简体   繁体   English

SymPy和Sage有什么区别?

[英]What is the difference between SymPy and Sage?

SymPySage aka SageMath有什么区别?

(Full disclosure: I am the lead developer of SymPy) (完全披露:我是SymPy的首席开发人员)

The first thing you should understand is that SymPy and Sage are not quite the same thing. 你应该首先理解的是,SymPy和Sage并不完全相同。 SymPy is a pure Python library, that does computer algebra. SymPy是一个纯粹的Python库,可以完成计算机代数。 Sage is a collection of open source mathematical software. Sage是一个开源数学软件的集合。 Sage tries to gather together all the major open source mathematics software, and glue it together into a useful system. Sage试图将所有主要的开源数学软件聚集在一起,并将它们粘合在一起形成一个有用的系统。 In fact, Sage includes SymPy as one of its systems. 事实上, Sage将SymPy作为其系统之一。

Here is a short list of (biased) facts for each (I won't call them pros or cons, just facts): 以下是每个(有偏见的)事实的简短列表(我不会称之为利弊,只是事实):

SymPy SymPy

  • SymPy is completely standalone. SymPy是完全独立的。 It has no dependencies other than Python. 除了Python之外,它没有依赖关系。
  • Despite being standalone, it is full featured as a computer algebra system . 尽管是独立的,但它是一个全功能的计算机代数系统 If you want to do numerics, you are encouraged to use other libraries in the scientific Python ecosystem . 如果你想做数字,我们鼓励你在科学的Python生态系统中使用其他库。
  • SymPy is BSD licensed. SymPy获得BSD许可。 For many people, this doesn't matter, but if you want to include SymPy in something else, it's nice to know that you can pretty much do whatever you want with the code. 对于很多人来说,这没关系,但是如果你想将SymPy包含在其他东西中,很高兴知道你可以用代码做任何你想做的事情。
  • SymPy does not try to change Python. SymPy不会尝试更改Python。 SymPy takes the philosophy that Python is doing things well, so it should do things the Python way. SymPy采用Python做得很好的理念,所以它应该以Python的方式做事。 For example, the operator for exponentiation is ** as it is in Python, not ^ as it is in many other systems. 例如,对于幂运算符是** ,因为它是在Python,而不是^因为它在许多其他系统。
  • SymPy can be used as a library. SymPy可以用作库。 Since SymPy is just a Python module, you can just import it and use it in any place that uses Python. 由于SymPy只是一个Python模块,您只需导入它并在任何使用Python的地方使用它。 There are a lot of really cool apps and libraries out there that use SymPy in the background to do symbolics (in many cases, in places where you might not even realize that symbolics are being used). 有很多非常酷的应用程序和库在后台使用SymPy来做符号(在很多情况下,在你可能甚至没有意识到使用符号的地方)。

Sage 智者

  • Sage includes everything (including SymPy) from the open source world that you might want to do mathematics. Sage包含了你可能想要做数学的开源世界的所有东西(包括SymPy)。 This includes many libraries that are useful for numerics, like octave. 这包括许多对数字有用的库,如八度音程。
  • Sage is GPL. Sage是GPL。 If you like the whole FSF software freedom shpel, then more power to you. 如果你喜欢整个FSF软件的自由大肆宣传,那么你的权力就更大了。 You can't reuse the source code in your own application without licensing your application under the GPL as well. 如果没有在GPL下许可您的应用程序,您也不能在自己的应用程序中重用源代码。
  • Sage is hard to use as a library. Sage很难用作图书馆。 On the other hand, it has a very nice notebook interface. 另一方面,它有一个非常好的笔记本界面。 If you want to do the same with SymPy, the recommended way is to use the IPython notebook and run from sympy import init_session; init_session() 如果你想对SymPy做同样的事情,推荐的方法是使用IPython笔记本并from sympy import init_session; init_session()运行from sympy import init_session; init_session() from sympy import init_session; init_session() at the top (replace init_session with init_printing if you just want printing and not to import everything). from sympy import init_session; init_session() (如果您只想打印而不是导入所有内容, init_printing替换为init_session )。
  • Sage includes a bit of a DSL on top of Python. Sage在Python之上包含了一些DSL。 For example, you can type 1/2 without wrapping the integer literals, and it will return a rational. 例如,您可以在不包装整数文字的情况下键入1/2 ,它将返回一个有理数。 x^2 gives x squared, not Xor(x, 2) . x^2给出x平方,而不是Xor(x, 2) I'm not sure if it automatically defines variables for you by default. 我不确定它是否默认为您自动定义变量。 This means that things that you do in an interactive Sage session might not translate directly to a Python script. 这意味着您在交互式Sage会话中执行的操作可能无法直接转换为Python脚本。 On the other hand, this can be useful for interactive use (btw, SymPy also has isympy -I that does some similar things). 另一方面,这对于交互式使用非常有用(顺便说isympy -I ,SymPy也有isympy -I做了类似的事情)。

Maybe that's not what you were looking for. 也许这不是你想要的。 You probably wanted some actual mathematical features. 你可能想要一些实际的数学特征。 But as I said, Sage includes SymPy, so by definition, every feature of SymPy will be a feature of Sage. 但正如我所说,Sage包含SymPy,因此根据定义,SymPy的每个功能都将成为Sage的一个功能。 In practice, this is not necessarily the case because Sage doesn't always use SymPy by default (I'm not sure what the current status of this is actually), so you may have to call to SymPy manually if you want to use it from within Sage. 在实践中,情况不一定是这样,因为Sage默认情况下并不总是使用SymPy(我不确定它的实际状态是什么),因此如果你想使用它,你可能需要手动调用SymPy来自Sage内部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM