Hi everyone,
I want to represent an equation like a binary tree,
e,g., I have this equation x**2+x+1
and in Julia I want to represent it as a tree with nodes
e.g. + sign is a Node in that tree or x is Node or 1 is another Node.
Please comment on how I can do this in Julia?
:(x^2 + x + 1) returns an Expr object which is exactly a syntax tree for that expression. (Julia syntax for exponentiation is x^2, not x**2 as in Python or Fortran.)
To plot any tree or any other graph type you should install a few packages.
In this particular case, this is the code that defines and plots the binary tree associated to the expression x^2+x+1:
I suggest you take a look at the manual page on expressions. You can define a recursive function depth(ex::Expr) which uses the attributes ex.head and ex.args