qwerty
1
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:
showtree(tree_expr)
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
begin
@variables x
expr = sin(cos(x))
expr_tree = Symbolics.unwrap(sin(cos(x)))
# https://symbolicutils.juliasymbolics.org/#expression_interface
@show expr_args = arguments(tree_expr)
@show expr_argsā = arguments(expr_args[1])
end
returns
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]
showtree(tree_expr)
requires an answer from one of the developers,
I was also not able to locate this function
2 Likes
qwerty
3
Thanks.
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