21

我对数学和编程非常感兴趣,并计划从头开始符号数学项目。

  1. 这是一个好的项目想法吗?

  2. 从哪儿开始?

  3. 应该如何处理这个项目?

  4. 有什么好的资源吗?

提前致谢。

4

7 回答 7

19
  1. 这是一个练习编程技能的好项目。但是,如果您想创建一个其他人想要使用的真实库,这是一个您不想从头开始的项目......

  2. 从哪里开始:看看已经存在的解决方案,想想你想做的不同之处是什么。您的项目与其他项目有何不同?

  3. 资源:SymPy 是用于符号数学的 Python 库

于 2009-02-03T11:41:40.240 回答
10

1.Is this good project idea?

Yes; I would expect it to provide an endless source of interesting work which will, quite quickly, test and extend your programming powers.

2.Where to start?

I second the other suggestions that you should look at existing work. SAGE is very impressive and if you had asked for my advice I would suggest that you firstly write a basic system for doing arithmetic with numbers and symbols; then have a look at SAGE and write a module to extend the system, in other words become a contributor to something larger rather than trying to do it all on your own. Look also at Mathematica and Maple, Macsyma and Axiom. The latter 2 are free (I think) but they are all well documented on-line and a great source of ideas and challenges.

3.How should one approach this project?

As one would approach eating an elephant. One bite at a time. More seriously, I think there are some core issues, such as representation of expressions, and some basic functionality (arithmetic on polynomials) which you could cut your teeth on.

4.Any good resources?

Lots and lots. google for 'computer algebra', 'term rewriting'. Have a look at what's available on Amazon. And, if you have access, check out the ACM digital library

Good luck.

于 2009-02-03T12:02:38.700 回答
7

Symbolic math is a fun project. Whether or not anyone uses it doesn't appear to matter in your question, so dive in.

I've written two of these over the years. The coolest was one for SQL where clauses -- it did some trivial symbolic manipulations on the SQL to fold in some additional AND conditions. Not a complete "solver" or "optimizer" or anything, just a few symbolic manipulations of any SQL where clause possible. The less cool one was for a debugger; it did complex math to work out (symbolically) stack offsets for variables.

You start by defining classes for elements of a mathematical expression -- operands, operators, functions, etc.

You have to decide what manipulations these objects have to participate in. Getting a concrete value for an expression is an easy and obvious one. Start with the case where all variables have a binding.

Then handle the case where some variables remain unbound, and you can only evaluate parts of the expression.

Then handle rearranging an expression into a canonical form. I.e., you've done a partial evaluation and have Add( Variable(x), Add( Variable(x), Lit(3) ) ). You need to write rules to transform this into Add( Multiply( Lit(2), Variable(x) ), Lit(3) ).

One very cool exercise is optimizing the parenthesis so that the printed output has the fewest parenthesis necessary to capture the meaning.

There are many, many other "expression transformation" rules that we all learn in school for doing algebraic manipulations. Lots of them.

In particular, rearranging an equation to isolate a variable can be really hard in some cases.

Doing the derivative transformation is easy, but symbolic integration is really, really hard with a ton of special cases.

The basics are fun. Depending on how far you want to go, it gets progressively harder.

于 2009-02-03T11:57:43.423 回答
4

@Resources:你可以看看pythonica - 这是尝试在 Python 中实现 Mathematica 类型的程序(源代码可供下载)。

于 2009-02-03T11:36:33.123 回答
3

这个pySym 博客也可能会让您感兴趣,因为您可以获取想法和入门,并了解其他人使用 python 和符号数学所做的事情。

于 2009-02-03T11:38:38.173 回答
1

更多资源方式:SympyCore

SympyCore 项目的目的是寻找新的高性能解决方案来表示和操作 Python 编程语言中的符号表达式,并尝试新的符号模型以实现基本一致且足够通用的符号模型,该模型很容易扩展到计算机代数系统(CAS)。

于 2009-02-03T11:39:13.100 回答
1

I think this is a great project for a programmer of any skill level. It is quite easy to do implement a symbolic calculator that is just powerful enough to be useful. If you continue to work on breadth, there are so many fun features to add that you can occupy yourself with it for a long time. If you choose to go for depth, you will find that things soon get very hard. You can challenge yourself indefinitely, if that's what you like.

There are many great resources. I recommend the book "Modern Computer Algebra" by zur Gathen and Gerhard, although it is really more concerned with arithmetic in special forms (polynomials, integers, matrices) than general symbolic manipulation. When you're starting out, you may actually be better helped by looking at some Lisp or Scheme tutorial, because symbolic math is conceptually very straightforward to do in Lisp, and to build a symbolic engine in Python you'll more or less have to implement a mini-Lisp as a foundation.

As others have pointed out, you could look at SymPy and sympycore for inspiration or concrete algorithms. The source code for either project is a bit complex (but certainly not too hard to learn from).

(If I may plug a bit, I wrote a tiny symbolic engine a while back (as a weekend project -- it's very tiny and I haven't worked on it since). It implements a generic symbolic engine in about 200 lines of code, and then there are 300 lines of code implementing symbolic arithmetic and symbolic boolean algebra, with some very rudimentary simplification. Perhaps easier to dig into than SymPy. But everything in there is things that you could easily discover for yourself, and may have more fun doing so.)

于 2009-02-03T22:04:22.277 回答