sympy/sympy

GitHub: sympy/sympy

SymPy 是一个用纯 Python 实现的开源计算机代数系统,旨在为科学计算生态系统提供强大的符号数学处理能力。

Stars: 14717 | Forks: 5348

# SymPy [![pypi version](https://img.shields.io/pypi/v/sympy.svg)](https://pypi.python.org/pypi/sympy) [![加入聊天室 https://gitter.im/sympy/sympy](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sympy/sympy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Zenodo 徽章](https://zenodo.org/badge/18918/sympy/sympy.svg)](https://zenodo.org/badge/latestdoi/18918/sympy/sympy) [![下载量](https://pepy.tech/badge/sympy/month)](https://pepy.tech/project/sympy) [![GitHub Issues](https://img.shields.io/badge/issue_tracking-github-blue.svg)](https://github.com/sympy/sympy/issues) [![Git 教程](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project) [![由 NumFocus 提供支持](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org) [![自上次发布以来的提交数](https://img.shields.io/github/commits-since/sympy/sympy/latest.svg?longCache=true&style=flat-square&logo=git&logoColor=fff)](https://github.com/sympy/sympy/releases) [![SymPy 横幅](https://static.pigsec.cn/wp-content/uploads/repos/cas/ee/ee6cbf8ac0f8dd3055df4d32180891a87efeea45c49fb7e7c5bc42289f7c6d65.svg)](https://sympy.org/) 请查看 [AUTHORS](https://github.com/sympy/sympy/blob/master/AUTHORS) 文件获取作者列表。 还有许多人在 SymPy 邮件列表中提供了帮助,报告了 bug, 协助组织了 SymPy 参与 Google Summer of Code、Google Highly Open Participation Contest 和 Google Code-In, 撰写并发表了关于 SymPy 的博客…… 许可证:New BSD License(详情请参阅 [LICENSE](https://github.com/sympy/sympy/blob/master/LICENSE) 文件)涵盖 sympy 仓库中的所有文件,除非另有说明。 我们的邮件列表位于 。 ## 下载 推荐的安装方法是通过 Anaconda, 你也可以从以下地址获取最新版本的 SymPy 要获取 git 版本,请执行 ``` $ git clone https://github.com/sympy/sympy.git ``` 有关其他选项(tarballs, debs 等),请参阅 。 ## 文档与使用 有关安装和构建文档的详细说明,请参阅 [SymPy 文档风格指南](https://docs.sympy.org/dev/documentation-style-guide.html)。 所有内容均位于: 你可以通过以下命令在本地 SymPy 副本中生成上述网站的所有内容: ``` $ cd doc $ make html ``` 然后文档将位于 \_build/html。如果你不想阅读那些,这里有一个简短的使用说明: 在此目录下,启动 Python 并执行: ``` >>> from sympy import Symbol, cos >>> x = Symbol('x') >>> e = 1/cos(x) >>> print(e.series(x, 0, 10)) 1 + x**2/2 + 5*x**4/24 + 61*x**6/720 + 277*x**8/8064 + O(x**10) ``` SymPy 还附带了一个控制台,它是经典 Python 控制台(或可用时的 IPython)的简单包装器,它会加载 SymPy 命名空间并为你执行一些常用命令。 要启动它,请执行: ``` $ bin/isympy ``` 在此目录下(如果未安装 SymPy),或者直接执行: ``` $ isympy ``` 如果已安装 SymPy。 ## 安装 要使用 PyPI 安装 SymPy,请运行以下命令: ``` $ pip install sympy ``` 要使用 Anaconda 安装 SymPy,请运行以下命令: ``` $ conda install -c anaconda sympy ``` 要从 GitHub 源码安装 SymPy,首先使用 `git` 克隆 SymPy: ``` $ git clone https://github.com/sympy/sympy.git ``` 然后,在你克隆的 `sympy` 仓库中,只需运行: ``` $ pip install . ``` 请参阅 获取更多信息。 ## 测试 要执行所有测试,请运行: ``` $./setup.py test ``` 在当前目录中。 要进行更细粒度的测试或 doctest 运行,请使用 `bin/test` 或分别使用 `bin/doctest`。master 分支由 GitHub Actions 自动测试。 要测试 pull requests,请使用 [sympy-bot](https://github.com/sympy/sympy-bot)。 ## 重新生成实验性 LaTeX 解析器/词法分析器 解析器和词法分析器是使用 `sympy/parsing/latex/_antlr` 中的 [ANTLR4](http://antlr4.org) 工具链生成的,并已提交到仓库中。 目前,大多数用户不需要重新生成这些文件,但如果你计划开发此功能,你将需要 `antlr4` 命令行工具(并且必须确保它在你的 `PATH` 中)。 获取它的一种方法是: ``` $ conda install -c conda-forge antlr=4.11.1 ``` 或者,按照 ANTLR 网站上的说明下载 `antlr-4.11.1-complete.jar`。然后按照说明导出 `CLASSPATH`,并且不要将 `antlr4` 创建为别名,而是创建一个包含以下内容的可执行文件: ``` #!/bin/bash java -jar /usr/local/lib/antlr-4.11.1-complete.jar "$@" ``` 在对 `sympy/parsing/latex/LaTeX.g4` 进行修改后,请运行: ``` $ ./setup.py antlr ``` ## 清理 要清理所有内容(从而获得与仓库中相同的目录树): ``` $ git clean -Xdf ``` 这将清除所有被 `.gitignore` 忽略的文件,以及: ``` $ git clean -df ``` 清除所有未跟踪的文件。你可以使用以下命令撤销 git 中最近的更改: ``` $ git reset --hard ``` 警告:上述命令都会清除你可能已经做出的更改,并且你将永远丢失它们。在执行任何这些操作之前,请务必使用 `git status`、`git diff`、`git clean -Xn` 和 `git clean -n` 进行检查。 ## Bug 我们的 issue 跟踪器位于 。请报告你发现的任何 bug。或者,更好的是,在 GitHub 上 fork 该仓库并创建一个 pull request。我们欢迎所有的更改,无论大小,如果你是 git 新手,我们将帮助你创建 pull request(只需在我们的邮件列表或 Gitter 频道上询问即可)。如果你还有任何其他疑问,你可以在 Stack Overflow 上使用 [sympy](https://stackoverflow.com/questions/tagged/sympy) 标签找到答案。 ## 简史 SymPy 由 Ondřej Čertík 于 2005 年创建,他在那年夏天编写了一些代码,然后在 2006 年夏天又编写了更多代码。2007 年 2 月,Fabian Pedregosa 加入了该项目并帮助修复了许多问题,贡献了文档,并使其重新焕发生机。5 名学生(Mateusz Paprocki、Brian Jorgensen、Jason Gedge、Robert Schwarz 和 Chris Wu)作为 Google Summer of Code 的一部分,在 2007 年夏天极大地改进了 SymPy。Pearu Peterson 在 2007 年夏天加入了开发,他从头重写了核心,使 SymPy 的速度提升了 10 到 100 倍,从而使其更具竞争力。Jurjen N.E. Bos 贡献了 pretty-printing 和其他补丁。Fredrik Johansson 编写了 mpmath 并贡献了大量补丁。 自 2007 年以来,SymPy 每年都参加 Google Summer of Code。你可以查看 了解完整详情。每年 SymPy 都取得了长足的进步。SymPy 的大部分开发工作都来自 Google Summer of Code 的学生。 2011 年,Ondřej Čertík 卸任首席开发者,同样是从 Google Summer of Code 学生开始的 Aaron Meurer 接替了他的位置。Ondřej Čertík 仍然在社区中很活跃,但由于工作和家庭太忙,无法扮演主要开发角色。 从那时起,有更多的人加入了开发,也有一些人离开了。你可以在 [AUTHORS](https://github.com/sympy/sympy/blob/master/AUTHORS) 中查看完整列表。 git 的历史可以追溯到 2007 年,当时开发工作从 svn 转移到了 hg。 要查看在此之前的历史记录,请访问 。 你可以使用 git 查看最主要的开发者。命令: ``` $ git shortlog -ns ``` 将显示每个开发者,并按对项目的提交次数进行排序。命令: ``` $ git shortlog -ns --since="1 year" ``` 将显示过去一年中最主要的开发者。 ## 引用 要在出版物中引用 SymPy,请使用 LaTeX 用户的 BibTeX 条目是 ``` @article{10.7717/peerj-cs.103, title = {SymPy: symbolic computing in Python}, author = {Meurer, Aaron and Smith, Christopher P. and Paprocki, Mateusz and \v{C}ert\'{i}k, Ond\v{r}ej and Kirpichev, Sergey B. and Rocklin, Matthew and Kumar, Amit and Ivanov, Sergiu and Moore, Jason K. and Singh, Sartaj and Rathnayake, Thilina and Vig, Sean and Granger, Brian E. and Muller, Richard P. and Bonazzi, Francesco and Gupta, Harsh and Vats, Shivam and Johansson, Fredrik and Pedregosa, Fabian and Curry, Matthew J. and Terrel, Andy R. and Rou\v{c}ka, \v{S}t\v{e}p\'{a}n and Saboo, Ashutosh and Fernando, Isuru and Kulal, Sumith and Cimrman, Robert and Scopatz, Anthony}, year = 2017, month = Jan, keywords = {Python, Computer algebra system, Symbolics}, abstract = { SymPy is an open-source computer algebra system written in pure Python. It is built with a focus on extensibility and ease of use, through both interactive and programmatic applications. These characteristics have led SymPy to become a popular symbolic library for the scientific Python ecosystem. This paper presents the architecture of SymPy, a description of its features, and a discussion of select submodules. The supplementary material provides additional examples and further outlines details of the architecture and features of SymPy. }, volume = 3, pages = {e103}, journal = {PeerJ Computer Science}, issn = {2376-5992}, url = {https://doi.org/10.7717/peerj-cs.103}, doi = {10.7717/peerj-cs.103} } ``` SymPy 采用 BSD 许可,因此你可以自由地以任何喜欢的方式使用它,无论是学术、商业、创建分支或衍生作品,只要你重新分发它时复制了 BSD 声明即可(详见 LICENSE 文件)。也就是说,尽管 SymPy 的许可证并未要求,但如果方便的话,当你在工作中使用 SymPy 时请引用它,同时也请考虑将你所有的更改贡献回来,以便我们能够合并它们,最终我们所有人都会从中受益。
标签:Python, 数学库, 无后门, 科学计算, 符号计算, 计算机代数系统, 逆向工具