4

I have written an HTML code using JavaScript to differentiate a single variable function. My code is here. I have used Mathjax to print the output. But the output produced is not simplified. For example, the derivative of sin(x)/cos(x) is produced as

((((cos(x))*(cos(x)))-((sin(x))*(-(sin(x)))))/((cos(x))^2))

which can be simplified to

(sin(x)^2+cos(x)^2)/cos(x)^2

I have constructed expression tree with the application of Dijkstra's shunting yard algorithm. And then constructed the expression tree of derivative recursively. But I have problem with the simplification.

Can anyone please help with the simplification of the output produced? My knowledge is not beyond elementary data structures.

Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
  • Please be more specific in the question. At least examples what you are getting and what is desirable output. The question should work even if the link is dead. – IvanH Nov 17 '13 at 16:08
  • 1
    I have added an example now. Thanks for the comment. – Sumit Kumar Jha Nov 17 '13 at 16:12
  • @SumitKumarJha - What IvanH was asking for is code sample. Do you have a specific coding/algorithmic problem - either with correctness or performance of your code? – Chandranshu Nov 17 '13 at 16:52
  • @Chandranshu- I wanted to know, if there exists an algorithm for simplification of algebraic expression.(Like simplification of radicals etc.) – Sumit Kumar Jha Nov 17 '13 at 16:54
  • 1
    I think you want at least three things: removal of unneeded parentheses, collection of a^n * a ==> a^(n+1), and collection of sign terms. – ellisbben Nov 19 '13 at 18:13
  • 3
    SICP discusses symbolic differentiation and how to achieve a few simplifications by adding rules to the differentiation: http://mitpress.mit.edu/sicp/full-text/sicp/book/node39.html – ellisbben Nov 19 '13 at 18:17
  • You could always look into an existing library? https://github.com/jiggzson/nerdamer – ArchHaskeller Sep 29 '15 at 22:51

1 Answers1

1

Well i can think only of implementation of algebraic rules.

  • extremlly hard to code
  • even harder to debug

1.create a list of simplification equations

  • like:

    cos^2(x)+sin^2(x)=1
    ...
    
  • this is easy

  • but be careful not to add cyclic equations here (so it would loop without end)
  • or rules that not simplify the output

2.create list of substitution methods

3.go through equation

  • test all the simplification rules
  • if it is applyable then apply it (hard to code)
  • if none found then try substitutions (extremlly hard to code it right)
  • if still none found then stop

4.do the point 3 for all representations of equation

  • equation can be writen in more ways
  • multiplicative
  • exponentiol
  • fractional,etc ...
  • you need to test all the variations
Spektre
  • 49,595
  • 11
  • 110
  • 380