Julia expression to AbstractTree-like structure in Symbolics

I was looking at the different possibilities for Expr to tree-like structure in Julia and thought of the Symbolics ecosystem as the natural modern place for it

I found an old post and GitHub - dfdx/Espresso.jl: Expression transformation package but was wondering if there is something in Symbolics

Expr is a tree structure. But @shashi might have some other tools.

True, it is a tree structure but I didn’t see the AbstractTree interface implemented anywhere.

Edit: no clue how I missed it, it is already built in AbstractTrees

julia> AbstractTrees.print_tree(:(3x + 2 * y - f(z + Ο€)))
β”œβ”€ :-
β”œβ”€ Expr(:call)
β”‚  β”œβ”€ :+
β”‚  β”œβ”€ Expr(:call)
β”‚  β”‚  β”œβ”€ :*
β”‚  β”‚  β”œβ”€ 3
β”‚  β”‚  └─ :x
β”‚  └─ Expr(:call)
β”‚     β”œβ”€ :*
β”‚     β”œβ”€ 2
β”‚     └─ :y
└─ Expr(:call)
   β”œβ”€ :f
   └─ Expr(:call)
      β”œβ”€ :+
      β”œβ”€ :z
      └─ :Ο€
1 Like