Symbolic differentiator written in C++.
It reads a math expression from stdin, parses it with recursive descent, builds an expression tree, differentiates the tree, simplifies the result and generates a PDF report with intermediate steps. It also dumps expression trees, which is useful for debugging.
- parse expressions with recursive descent.
- build expression trees.
- dump expression trees to PNG through Graphviz.
- differentiate expressions symbolically.
- simplify obvious cases like constants, zero terms and one multipliers.
- generate a LaTeX/PDF report with differentiation and simplification steps.
- replace long subexpressions in the PDF report with short names.
Example tree dumps for expression: sin(x)^2+cos(x)^2
A saved PDF report is available at examples/example_report.pdf.
Requirements:
- C++14 compiler
- Graphviz (
dot) for tree pictures pdflatexfor PDF reports
Use make to build the project:
makeThis builds the main executable.
To run the project, pass an expression through stdin:
./main
sin(x)^2+cos(x)^2The program prints debug dumps to stdout, writes tree pictures to /tmp, and
writes a PDF report to data/. The exact report filename is generated
automatically and looks like data/diff_fileXXXXXX.pdf. Generated reports are
ignored by git.
Examples of accepted expressions:
x^2+2*x+1
sin(x)^2+cos(x)^2
ln(x)+sqrt(x)
(x+1)/(x-1)
The parser uses one-letter variable names. The main variable for differentiation
is x.
Supported operations are defined in operators.h. The interesting files are:
read_tree.cpp- recursive descent parsertree.cpp- expression tree utilities and Graphviz dumpsdifferentiator.cpp- differentiation and simplification logicoperators.h- rules for operatorsto_latex.cpp- LaTeX report generationdata/latex_*.txt- report templates and phrases

