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)
│  ├─ :+
│  ├─ Expr(:call)
│  │  ├─ :*
│  │  ├─ 3
│  │  └─ :x
│  └─ Expr(:call)
│     ├─ :*
│     ├─ 2
│     └─ :y
└─ Expr(:call)
   ├─ :f
   └─ Expr(:call)
      ├─ :+
      ├─ :z
      └─ :π
             
            
              
              
              1 Like