1
$\begingroup$

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.

  • 0
    A better place to ask: http://mathematica.stackexchange.com/2017-01-31
  • 0
    Look for CAS (computer algebra systems). Their basic trick is to treat irrational numbers as variables as long as possible, before trying to apply further knowledge. If you enter $e+\pi$ it will not ne able to simplify further, because nothing is known about that value.2017-01-31
  • 1
    Relevant: http://mathoverflow.net/q/118972/17064 — for algebraic quantities the problem is simpler. But don't imagine that Maple or Mathematica are always able to decide the equality of real quantities (they are able to prove that *certain* quantities are equal, but in general they will simply treat unknown reals as indeterminates as Manfred Weis pointed out).2017-01-31
  • 0
    How do *you* give exact answers to complex problems, ThePedestrian? And what's to stop Alpha from doing it the same way?2017-01-31
  • 0
    What does "exact" mean?2017-01-31
  • 0
    @YuriyS $\pi$ is an *exact* number but $3.14159$ is a decimal approximation to that number. One distinction between computer algebra and numerical analysis is that computer algebra systems can work with the former and decide, for example, that `30*pi-10*pi-20*pi=0` - exactly. A numerical system will typically return something involving `10^(-15)` for that computation, due to round off error.2017-01-31

1 Answers 1

1

First off, I guess you need a specialized data structure to represent symbolic objects. Here's an example lifted straight from SymPy's documentation:

from sympy import *
x, y, z = symbols('x y z')
expr = x**2 + x*y
srepr(expr)

# Out: 
# "Add(Pow(Symbol('x'), Integer(2)), Mul(Symbol('x'), Symbol('y')))"

So, I guess that Add, Pow, Symbol, Integer, and Mul are classes defined by SymPy with methods indicating how to perform basic algebraic operations. All those classes have a diff method, for example, that indicates how they should be differentiated with respect to a symbol. The diff method for Pow encodes the power rule; the diff method for Mul encodes the product rule.

The whole expression can be visualized with a tree - again, from the SymPy documentation:

enter image description here

To differentiate the expression with respect to a symbol, we traverse the tree applying the appropriate diff method as we go along to build up a new expression tree for the derivative.

Note that Mathematica does something very similar:

expr = x^2 + x^y;
FullForm[expr]
TreeForm[expr]

(* Out: 
   Plus[Power[x,2],Power[x,y]]
*)

enter image description here