Symbolics istree returning false when there is a tree

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:

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.

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

The issue is TermInterface.jl/TermInterface.jl at 91f77ff2babaaad22a6a2a0c6adbb6a2b7ccb149 · JuliaSymbolics/TermInterface.jl · GitHub combined with

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

or equivalent not being defined anywhere.

If you call

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

it works.

Seems like this is a missing dispatch in Symbolics.

1 Like

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

1 Like

Yes!

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

does output true. Thank you!