Tree-Form of math formula (as a dot string) Tree-Form of math formula (as a dot string) numpy numpy

Tree-Form of math formula (as a dot string)


To do this, we can use sympy to generate the tree and Graphviz to render it. Below is the code to generate the digraph data and render it into a pdf. Note that in order to use Graphviz you need to install the Graphviz executables as well as installing through pip. Hope that helps!

from sympy import symbols, cos, dotprintfrom graphviz import Sourcea, b, c, x= symbols('a b c x')expr = a * b * cos( c * x ) + bsrc = Source(dotprint(expr))src.render('output.gv', view=True)

enter image description here