I am working on developing an online homework system.
One thing I would like to have is something which compares a student's answer (like $2\sin(x)\cos(x)$) with the intended answer (maybe $\sin(2x)$).
I would like to be able to numerically test equality between two expressions which are compositions of the following functions:
- Variables a,b,c,d,..
- Rational functions
- Trig functions and inverses
- Expontential function
- Log
for example, I would need to be able to compare the equality of $\sin(a^2b)\log(x)$ with some other expression with a similar form.
I understand that this is impossible from a purely syntactic point of view: there is a theorem to this effect. So I would like a numerical algorithm which "approximately works". I do not mind if the algorithm occasionally returns a mistaken "true" but it should never return a mistaken "false".
At first, we thought we could just test a couple hundred points in the interval $[-10,10]$ at random, and see if the answers agree at these points to within some specified relative error tolerance (with a default of something like $\epsilon = 10^{-6}$).
This method fails for a function like $\sqrt{x^2-100}$ which does not contain $[-10,10]$ in its domain.
Finding the domain algorithmically (or even any interval in the domain) seems difficult.
We have had more luck (testing against a bank of examples) by evaluating at complex numbers in the unit disk. This too runs into problems for functions with branch cuts (which, for the expressions I am considering, all really stem from $\log$). For example, our system has trouble with $\log(a^2b)$ vs $2\log(a)+\log(b)$.
We are thinking about working with the actual riemann surface, so that we can resolve these domain issues.
I imagine that a lot of people need to test equality between expressions of this form, but I have not found any preexisting open source algorithms which do this reliably.
Does anyone have any pointers to existing open source algorithms, or literature about how to approach this problem?