3 ms·
For comparison, here is symbolic derivatives in C. I wrote this in 1990 for school project: https://github.com/jhallen/joes-sandbox/tree/master/x/xquiz https:
by jhallenworld 8y ago
For comparison, here is symbolic derivatives in C. I wrote this in 1990 for school project:
https://github.com/jhallen/joes-sandbox/tree/master/x/xquiz https://github.com/jhallen/joes-sandbox/tree/master/x/xquiz
I need to make slides and a better write up for it, but the program is a math quiz with equation editing and graphing capabilities for X. It includes a simplifier which will take derivatives if they are in the form: D(x^2)/D(x)
The simplifier also combines terms, reduces fractions, etc. I was shooting for something like Macsyma.
The derivative taking function is
here:
https://github.com/jhallen/joes-sandbox/blob/master/x/xquiz/simplify.c#L208 https://github.com/jhallen/joes-sandbox/blob/master/x/xquiz/...
Equations are parsed into LISP-like lists, defined in box.h. There are list nodes, numbers and symbols. They are allocated in aligned pages. To distinguish between them, you look at the page header. Some of the classic LISP implementation used this same technique- I was interested in it at the time, but wouldn't use it today.
As you type equations in, they are typeset in standard math notation on the screen. You can edit the tree by selecting any part of the equation with the mouse. Once something is selected, you can type in a replacement, or click simplify, distribute, or factor. I had fun correlating mouse coordinates with tree locations.
- taeric 8y agoNicely done! I'm curious if you used the SICP or similar literature as inspiration, or if this was just a natural way that you thought to do it.
- jhallenworld 8y agoI don't remember SICP, but I read lots of similar books. Actually the advisor wanted me to do this in Prolog, with the idea that we would try to prove equivalency between the entered answer and known answer. The problem is that I saw no way to do all of the mundane tasks in Prolog. LISP would have been a far better choice (perhaps with a unification library), but even LISP at the time did not have great support for X. I already knew C, and had to get the project done...
- taeric 8y agoIt occurred to me later, that the first volume of Art of Computer Programming has a derivative calculator algorithm. Even implements part in its assembly language. Regardless of any of that, really cool project. Being for a class underscores the deadline you did that in. Thanks for sharing!