As a query, have you looked into lisp at all? I've seen (through HN) examples of stuff like derivatives expressed quite elegantly using Lisp.
Using C for maths programming sounds fun and all, but I'm sure there's got to be a better way of doing things.