Coding Differentiation: Need Math Program Help

  • Thread starter ranger
  • Start date
  • Tags
    Code
In summary, the conversation is about finding or coding a program in C, C++, or Java that solves differentiation without the use of a computer algebra system. The program should provide code extracts to demonstrate how the computer evaluates these problems. Differentiation is a systematic process that involves a few rules, but the challenge lies in typesetting and simplification of the results. Some possible methods for coding this program include using text parsing, counting variables, and working backward from the proper variable. Lisp is suggested as a good environment for this type of program, and there are also some Java calculators available for reference.
  • #1
ranger
Gold Member
1,687
2
Does anyone know where to find or how to code a program that solves differtiation. Just differentiation and nothing esle. No computer algebra system. It doesn't even have to be a functional program, just some code extracts so I can see how the computer evaluates these problems.

Langauge = C or C++. Java would be fine also.

--thank you
 
Physics news on Phys.org
  • #2
It's not clear what you mean. Do you mean a numerical differentiation?
 
  • #3
i mean that given a function f, find f`. Example

f = x^3 + 3x + 4
f`= 3x^2 + 3

No need to find the numerical value.
 
Last edited:
  • #4
ranger said:
Does anyone know where to find or how to code a program that solves differtiation. Just differentiation and nothing esle. No computer algebra system. It doesn't even have to be a functional program, just some code extracts so I can see how the computer evaluates these problems.

Langauge = C or C++. Java would be fine also.

--thank you
That would be easy to code as differentiation is very systematic. The problem would be typesetting and simplification. Without nice (hard to write) simplification and type setting the results would be very ugly. You would just need a few rules and use them in combination.
(u*v)'=u'*v+u*v'
(u+v)'=u'+v'
(u^v)'=v*u^(v-1)*u'+u^v*log(u)*v'
(f(g))'=f'(g)g'
exp'(x)=exp(x)
log'(x)=1/x
sin'(x)=cos(x)
cos'(x)=-sin(x)
and so on
 
  • #5
lurflurf said:
That would be easy to code as differentiation is very systematic. The problem would be typesetting and simplification. Without nice (hard to write) simplification and type setting the results would be very ugly. You would just need a few rules and use them in combination.
(u*v)'=u'*v+u*v'
(u+v)'=u'+v'
(u^v)'=v*u^(v-1)*u'+u^v*log(u)*v'
(f(g))'=f'(g)g'
exp'(x)=exp(x)
log'(x)=1/x
sin'(x)=cos(x)
cos'(x)=-sin(x)
and so on

That is how the rules would be coded? So for example the C programming language has built in fuctions for dealing with differentiation?
 
  • #6
ranger said:
That is how the rules would be coded? So for example the C programming language has built in fuctions for dealing with differentiation?
no no. You would need to have some text parsing. What exactly are your goals with this project? The text parsing could be quite tedeous.
here are some sloppy ideas
Say your functions are
sin()
cos()
exp()
log()
+(,)
-(,)
*(,)
/(,)
^()()
-()
first you would have your parser check that the function was valid
then it could count the x's, then use differentiate with respect one x at a time and add the results. It would then start at the proper x and work backward until finished
say you
what makes this hard is
-checking the input function is valid
-allowing freedon in keying imput function
-reduceing the answer so it does not look silly ie
f=x*x*x
f'=x*x+x*x+x*x
-allowing many functions
-making the results pretty
 
  • #7
Its not really a project. I'm just curious on how it would solve it.
then it could count the x's, then use differentiate with respect one x at a time and add the results
.

How would that code look like(for the differentiation section)?

It would be damn ugly to look at x*x*x*x + x*x
 
  • #8
Here are some links from my web search. Several pages have suggested lisp as a good environment for programs of this type.

used lisp
http://mitpress.mit.edu/sicp/full-text/sicp/book/node39.html
somewhere a class called CS 381K had this as homework (uses lisp)
http://www.cs.utexas.edu/users/novak/asg-symdif.html
paper about coding this in c++
http://www.usenix.org/publications/library/proceedings/coots98/full_papers/gil/gil_html/gil.html
more lisp
http://www.cs.sfu.ca/~cameron/Teaching/384/971/Lectures/deriv.html
 
  • #9
Thanks for these good readings lurflurf. I'll look into them right away. So lisp is better suited for this then?
 
  • #10
implicit differentiation? MAPLE
 
  • #11
neurocomp2003, I'm not interested in a computer albebra system. I just want to know how a computer evaluates the discussed subject i.e seeing the source code.
 
  • #12
ranger said:
neurocomp2003, I'm not interested in a computer albebra system. I just want to know how a computer evaluates the discussed subject i.e seeing the source code.
For what purpose? I can think of a few.
(1) understand differentiation better yourself
(2) to contrast how a computer program performs differentiatio with how a human does
(3) to see how actual step that are simple for a human are implemented

(1) is not likely, as you would need to follow individual steps out. Some steps would be ugly, possibly all steps without a good simplification process, if you did have good simplification it could make things more confusing.
(2) unlike integration, computers do symbolic differentiation much more like a human would. There are simple rules that can be followed in a deterministic fashion. The simplification, acceptable input check, and answer formating are where all the action it.
(3) is the area that could be most productive. It would also be very tedious. The process goes
-develop unambigues notation for input and output
-develop code for programe to deal with functions
-develope method for ensuring that imput and output are in proper form
-define rules by which valid imput is systematically reduced
-implement simplification to above step lest answer looks yucky
-implement typeset for answer lest looks yucky
All that is of some interest, but the details are very tedeous.
 
  • #13
  • #14
i thought maple has source code available..and maple is not a computer algebra system. If your looking for source code then your above post should be changed and you shouhld take a numerical methods/analysis course. It involves changing the function into its taylor approx. series.
 
  • #15
Thanks for pointing to the code Orion1. It will take sometime for me to analyze it.

neurocomp2003, thanks for telling that maple has its source available.
http://www.math.utah.edu/lab/ms/maple/src/
You're saying that maple isn't a CAS (or doesn't have CAS capabilities)? Well in that case I've been lied to all my life.
 
  • #16
what your definition of CAS? I was under the impression that MATLAB was CAS but maple deals with more analysis.
Unless your talking about symbolic programming?
 
  • #17
When I say CAS, I mean a program that does math fuctions. Like thoes fuctions from algebra, calculus, diff equations. Functions such as exapnsion, differentiation, factoring, limits, etc. No programming. A good example of a CAS is the one found on texas instruments TI-89 series a calculators.

I'm sure that maple supports this capability.
 

1. What is coding differentiation?

Coding differentiation is the process of modifying or customizing a program to meet the specific needs of different users or tasks. This can include changing the functionality, user interface, or other aspects of the program to better suit the intended use.

2. Why is coding differentiation important in a math program?

Coding differentiation is important in a math program because it allows for a more personalized and effective learning experience for students. Different students may have different learning styles or abilities, and a customized program can cater to these individual needs.

3. How can coding differentiation be incorporated into a math program?

Coding differentiation can be incorporated into a math program through various methods such as creating different levels of difficulty for problems, providing alternative ways of solving problems, or allowing for customization of the user interface.

4. What are some challenges of coding differentiation in a math program?

Some challenges of coding differentiation in a math program may include the need for a more complex code, potential bugs or errors in the customized program, and the need for constant updates and maintenance to keep up with changing user needs.

5. Are there any resources available for coding differentiation in math programs?

Yes, there are many resources available for coding differentiation in math programs. Some examples include online tutorials, forums, and software development kits specifically designed for creating customized programs. Additionally, programming languages such as Python and Java have built-in features for coding differentiation.

Similar threads

  • Programming and Computer Science
Replies
7
Views
516
  • STEM Academic Advising
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • STEM Academic Advising
Replies
11
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
Replies
0
Views
829
  • Programming and Computer Science
Replies
8
Views
817
  • Programming and Computer Science
Replies
30
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
Replies
15
Views
4K
Back
Top