I've always wondered how sites like Wolfram Alpha or tools like TI-89 calculators can give exact answers to complex problems. I.e. irrational numbers or exact solutions to calculus problems.
For example, take a simple problem of: $2\pi/4$. Wolfram Alpha gives an exact answer of $\pi/2$.
Having studied numerical analysis before, I know scientific tools like Matlab or Octave use approximations which is not what I'm looking for.
I'm interested in knowing what kind of techniques TI calculators or Wolfram Alpha use to give an exact answer. Granted my example was simple but you could ask Wolfram to solve a PDE and it will sometimes give an exact answer.
First off, I guess you need a specialized data structure to represent symbolic objects. Here's an example lifted straight from SymPy's documentation:
So, I guess that
Add,Pow,Symbol,Integer, andMulare classes defined by SymPy with methods indicating how to perform basic algebraic operations. All those classes have adiffmethod, for example, that indicates how they should be differentiated with respect to a symbol. Thediffmethod forPowencodes the power rule; thediffmethod forMulencodes the product rule.The whole expression can be visualized with a tree - again, from the SymPy documentation:
To differentiate the expression with respect to a symbol, we traverse the tree applying the appropriate
diffmethod as we go along to build up a new expression tree for the derivative.Note that Mathematica does something very similar: