# Symbolics istree returning false when there is a tree

**URL:** <https://discourse.julialang.org/t/symbolics-istree-returning-false-when-there-is-a-tree/82993>\
**Category:** New to Julia\
**Tags:** modelingtoolkit, symbolic-utils\
**Created:** [June 19, 2022, 2:00am UTC](https://discourse.julialang.org/t/symbolics-istree-returning-false-when-there-is-a-tree/82993 "2022-06-19T02:00:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![infiniteFun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/infinitefun/32/36979_2.png) [@infiniteFun](https://discourse.julialang.org/u/infiniteFun)\
**Post date:** [June 19, 2022, 2:00am UTC](https://discourse.julialang.org/t/symbolics-istree-returning-false-when-there-is-a-tree/82993/1 "2022-06-19T02:00:54Z")

</div>

Hello,

I have the following scenario that I’m unable to understand in Symbolics. It would be great if somebody could help me with that:

```julia
using ModelingToolkit

@variables t x(t)
D = Differential(t)

eqs = [D(x) ~ x]

eqs[1].lhs # Output: Differential(t)(x(t))

D(x) # Output: Differential(t)(x(t))

istree(eqs[1].lhs) # true

istree(D(x)) # false

```

Why is the first call to istree true and the second false? It would be great if someone helped me understand this.

EDIT: When I call typeof on the eqs[1].lhs I get a “Term” and when I call typeof on D(x) I get Num if that helps. And that is consistent with the return value from istree.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 19, 2022, 9:52am UTC](https://discourse.julialang.org/t/symbolics-istree-returning-false-when-there-is-a-tree/82993/2 "2022-06-19T09:52:28Z")

</div>

@shashi is there a reason this isn’t istree? It does look like a bug to me.

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [June 19, 2022, 9:10pm UTC](https://discourse.julialang.org/t/symbolics-istree-returning-false-when-there-is-a-tree/82993/3 "2022-06-19T21:10:54Z")

</div>

The issue is [TermInterface.jl/TermInterface.jl at 91f77ff2babaaad22a6a2a0c6adbb6a2b7ccb149 · JuliaSymbolics/TermInterface.jl · GitHub](https://github.com/JuliaSymbolics/TermInterface.jl/blob/91f77ff2babaaad22a6a2a0c6adbb6a2b7ccb149/src/TermInterface.jl#L3-L9) combined with

```julia
istree(x::Num) = istree(ModelingToolkit.unwrap(x))

```

or equivalent not being defined anywhere.

If you call

```julia
istree(ModelingToolkit.unwrap(D(x)))

```

it works.

Seems like this is a missing dispatch in Symbolics.

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [June 19, 2022, 9:23pm UTC](https://discourse.julialang.org/t/symbolics-istree-returning-false-when-there-is-a-tree/82993/4 "2022-06-19T21:23:01Z")

</div>

I opened [add istree for Nums by isaacsas · Pull Request #625 · JuliaSymbolics/Symbolics.jl · GitHub](https://github.com/JuliaSymbolics/Symbolics.jl/pull/625) to fix this (if it is considered a bug).

---

<div class="post-metadata">

**Author:** ![infiniteFun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/infinitefun/32/36979_2.png) [@infiniteFun](https://discourse.julialang.org/u/infiniteFun)\
**Post date:** [June 20, 2022, 1:29am UTC](https://discourse.julialang.org/t/symbolics-istree-returning-false-when-there-is-a-tree/82993/5 "2022-06-20T01:29:00Z")

</div>

Yes!

```julia
istree(ModelingToolkit.unwrap(D(x)))

```

does output true. Thank you!
