# Thread: program that finds antiderivative

1. ## program that finds antiderivative

Has any one here ever written a program that finds the derivative or anti derivative?
Because I'm trying to write a program that finds the derivative or antiderivative but I don't know where to start. I dont know how I would allow the user to enter in their f(x) and then take that and find the derivative or antiderivative? Any tips or tricks would be appreciated thanks

2. I believe, might be wrong, that in order to do that you have to do it the way you would do it with a pen and paper.
You have to parse an expression, make a tree with all the variables, then apply some rules on them. Lets say you have one variable, x. And only +, * and ^
Example:
f(x) = 2*x + x^2
Node0 (Root)
var1 = Node1
var2 = Node2
operator = +

Node1
var1 = 2
var2 = x
operator = *

Node1
var1 = x
var2 = 2
operator = ^

Then you evaluate first Node1 and Node2. You will get x from Node1 and 2*x from Node2. Then you apply the + operator from Node0 and get 2 + 2*x, which is the result.
Now, every node will be a struct, which is up to you how to implement. But you can use the above as the basic idea.
If you have (,) note that things get more complicated, so I suggest starting simple.
If the above isn't clear I can elaborate a bit more.

Note that if you had numbers, not variables, like df(4)/dx then maybe there are some arithmetic algorithms that come close (really close) to the real result. Those are used generally to calculate a result. Computers don't do this as humans.

3. Derivative yes, anti-derivative no.

4. Just to clarify that the antiderivative would be solved in almost an identical way. The only difference is that if you have, for example, f(x) = x^2 you will create two functions:
1) derivative(f) = 2*x
2) antiDerivative(f) = (3/2) * x^3

So if you find how to do one, you can easily do the other

5. if you need to evaluate an integral, then it's easy. if you need to provide a symbolic answer, then you're in for a world of pain.

edit: to answer your other question, yes there is software out there that does that:

http://www.maplesoft.com/

http://www.wolfram.com/

6. Originally Posted by C_ntua
Just to clarify that the antiderivative would be solved in almost an identical way. The only difference is that if you have, for example, f(x) = x^2 you will create two functions:
1) derivative(f) = 2*x
2) antiDerivative(f) = (3/2) * x^3

So if you find how to do one, you can easily do the other
try f = e^(-x^2)

7. Graphmatica too

8. The approximations of either are easily handled by a computer. However, as someone else suggested, finding the symbolic answer is not easy (it's nearly impossible for most humans to program that).

Computers are akin to finding the approximations of either derivatives(using Newton's method comes to mind) or anti-derivatives.

Coming up with a symbolic answer is a lot tougher. Think if you had to program the logic to come up with a symbolic answer for an integral that involved trig-integration. That would be a rather daunting task!

Generating a symbolic answer for derivatives is just as difficult if you consider implicit-differentiation and any other type of derivative that doesn't involve simple polynomials (i.e., one's that don't intuitively conform to x^2dx = 2x^x-1).

However, if you're looking only to use your program on simple polynomials, I think you could do that with little effort.

9. About your question on how to allow the user to enter the polynomial, that's easy and there's a number of ways to do it.

In school I once had to program that did different operations on polynomials and user input was as easy as letting the user enter terms in this fashion:
Code:
```[Q]-quit [E]-enter term
e
Enter order: 2
Enter coefficient: 3
q```
would mean the user entered 3x^2. You can store those terms in a container (list,vector,etc), and overload the "<" operator( checking orders first, then coefficients if necessary, and if orders are equal, add the coefficients), call sort on the container, and whola! you have the standard form for your polynomial.

Implementing the derivative/anit-derivative, then running it on the container is a snap!

10. newton's method is a root-finding algorithm that requires the derivative as part of the equation...

can it be used to solve for derivatives? seems like there's an 'incompleteness' problem there.

11. Originally Posted by dudeomanodude
The approximations of either are easily handled by a computer. However, as someone else suggested, finding the symbolic answer is not easy (it's nearly impossible for most humans to program that).
And yet my TI-89 does it.

12. Originally Posted by Thantos
And yet my TI-89 does it.
So that means TI found a couple of the humans that can. And much like the dog that sings showtunes, it's not that the TI does it well (because it doesn't), it's that it does it at all.

13. The TI does it sure, but often what it spits out is not the answer you would expect nor does it look like what you would get by finding the answer with pen and paper.

Nearly impossible for humans
well, i'm sure they've got some mathematical geniuses at TI who came up with what they have, and at best, what they've come up with is certainly not perfect.

I want a human to write a program that comes up with the symbolic answer to find the derivative/anti-derivative of anything, perfectly... my bet is that will never happen.

about newton's method, perhaps i was thinking about a way to find the anti-derivative... not sure, but I do remember writing a program that found the approximations and it wasn't terribly difficult (can't remember if it was derivatives or anti now)

14. Originally Posted by dudeomanodude
The TI does it sure, but often what it spits out is not the answer you would expect nor does it look like what you would get by finding the answer with pen and paper.

well, i'm sure they've got some mathematical geniuses at TI who came up with what they have, and at best, what they've come up with is certainly not perfect.

I want a human to write a program that comes up with the symbolic answer to find the derivative/anti-derivative of anything, perfectly... my bet is that will never happen.

about newton's method, perhaps i was thinking about a way to find the anti-derivative... not sure, but I do remember writing a program that found the approximations and it wasn't terribly difficult (can't remember if it was derivatives or anti now)
I'm pretty sure it CAN be done for things that actually have defined integrations (anti-derivative), as there are fairly good rules for these things. However, in many cases, the integral calculation is not defined.

However, integral calculus is a complicated part of math, and it does contain A LOT of rules that are not particularly easy to describe to a computer. Here's one example:
http://en.wikipedia.org/wiki/Trigonometric_substitution

--
Mats

15. Originally Posted by m37h0d
try f = e^(-x^2)
Well, yeah that is kind of hard. The result is 1/2*pi*erf(x) according to this tool

Antiderivatives are hard to solve, because not all can be solved. There are a lot of methologies also, which really makes it difficult. You will require a lot of math, which personally I don't know. But it is possible.
Alternatively, you create a program that connects to a site like the above, gets the result and prints it :P

Popular pages Recent additions