Tree corresponding to expression in Symbolics

In a video on YB I saw that you can get the tree corresponding to the expression with unwrap.

tree_expr = unwrap(sin(cos(x)))

How can i access the elements of the tree?

Also I saw that it can be displayed with:


But the showtree function is not defined. Where do I find it?
Thank you

1 Like

How can i access the elements of the tree?

# test_symbolics_tree.jl

using Symbolics

    @variables x

    expr = sin(cos(x))

    expr_tree = Symbolics.unwrap(sin(cos(x)))

    @show expr_args = arguments(tree_expr)

    @show expr_args₁ = arguments(expr_args[1])



expr_args = arguments(tree_expr) = SymbolicUtils.Term{Real, Nothing}[cos(x)]
expr_args₁ = arguments(expr_args[1]) = SymbolicUtils.Sym{Real, Base.ImmutableDict{DataType, Any}}[x]


requires an answer from one of the developers,
I was also not able to locate this function


Is there a way to get the entire tree corresponding to the expression in a format compatible with AbstractTrees.jl?

I don’t know the answer to your general question.

Suggest that you provide a more detailed explanation and example with a diagram of what you would like to do.

However, a tree is a subset of a graph and

Julia Symbolics.jl uses a graph data structure termed an E-graph, Also suggest that you have a look at the documentation.

1 Like