I am extreamly interested in math and programming and planning to start symbolic math project from scratch.
Is this good project idea?
Where to start?
How should one approach this project?
Any good resources?
Thanks in advance.
I am extreamly interested in math and programming and planning to start symbolic math project from scratch.
Is this good project idea?
Where to start?
How should one approach this project?
Any good resources?
Thanks in advance.
This pySym Blog might also interest you for getting ideas and starters, and learning what others are doing with python & symbolic math.
More in the way of resources: SympyCore:
The aim of the SympyCore project is to seek out new high Performance solutions to represent and manipulate symbolic expressions in the Python programming language, and to try out new symbolic models to achive fundamentally consistent and sufficiently general symbolic model that would be easy to extend to a Computer Algebra System (CAS).
It's a good project to practice programming skills. But if you want to create a real library that other people will want to use this is a project you do not want to start allone and from scratch ...
Where to start: Have a look at the solutions that are already out there and think about what it is that you want to do different. How will your project differ from others?
Resource: SymPy is a Python library for symbolic mathematics
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.
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.
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.)