# Tree corresponding to expression in Symbolics

**URL:** <https://discourse.julialang.org/t/tree-corresponding-to-expression-in-symbolics/86034>\
**Category:** Modelling & Simulations\
**Tags:** symbolics\
**Created:** [August 19, 2022, 6:13pm UTC](https://discourse.julialang.org/t/tree-corresponding-to-expression-in-symbolics/86034 "2022-08-19T18:13:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Post date:** [August 19, 2022, 6:13pm UTC](https://discourse.julialang.org/t/tree-corresponding-to-expression-in-symbolics/86034/1 "2022-08-19T18:13:47Z")

</div>

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

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

```

How can i access the elements of the tree?

* * *

Also I saw that it can be displayed with:

```julia
showtree(tree_expr)

```

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

---

<div class="post-metadata">

**Author:** ![Audrius-St](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/audrius-st/32/24175_2.png) [@Audrius-St](https://discourse.julialang.org/u/Audrius-St)\
**Post date:** [August 28, 2022, 8:36am UTC](https://discourse.julialang.org/t/tree-corresponding-to-expression-in-symbolics/86034/2 "2022-08-28T08:36:07Z")

</div>

> How can i access the elements of the tree?

```julia
# 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

```julia
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

---

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Post date:** [August 28, 2022, 9:25am UTC](https://discourse.julialang.org/t/tree-corresponding-to-expression-in-symbolics/86034/3 "2022-08-28T09:25:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Audrius-St](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/audrius-st/32/24175_2.png) [@Audrius-St](https://discourse.julialang.org/u/Audrius-St)\
**Post date:** [August 28, 2022, 6:59pm UTC](https://discourse.julialang.org/t/tree-corresponding-to-expression-in-symbolics/86034/4 "2022-08-28T18:59:57Z")

</div>

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.

> **[GitHub - JuliaSymbolics/Metatheory.jl: General purpose algebraic...](https://github.com/JuliaSymbolics/Metatheory.jl)**
>
> General purpose algebraic metaprogramming and symbolic computation library for the Julia programming language: E-Graphs & equality saturation, term rewriting and more. - GitHub - JuliaSymbolics...
