Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: User-friendly functions for seeing what's in a symbolic expression. #645

Open
orebas opened this issue Sep 1, 2024 · 3 comments

Comments

@orebas
Copy link

orebas commented Sep 1, 2024

These capabilities maybe exist but I couldn't find anything documented for either Symbolics or SymbolicUtils. Example
-Given a symbolic expression, how do I break it up into terms?
-Given a symbolic expression how do I query if it is a derivative (and if so, what order and of what?)
-Given a symbolic expression, how do I tell if it's a function, or the independent variable "t"?

I think some of this functionality is related to istree, or maybe iscall, but I'm not sure.

@jpfairbanks
Copy link
Contributor

I think that concepts like derivative and independent variable should be Symbolics.jl level concepts since in SymbolicUtils the terms are more general than the kind of calculus functions that MTK and Symbolics are designed for.

I don't think there is a notion of independent or dependent variable at the BasicSymbolics level.

@orebas
Copy link
Author

orebas commented Sep 18, 2024

Thanks. I guess I'm not clear on where the break between Symbolics and SymbolicUtils is. Should I create an issue in Symbolics?
(I had guessed that the first item, at least, was in SymbolicUtils, based on SymbolicUtils docs )

@orebas
Copy link
Author

orebas commented Sep 19, 2024

For some transparency, I'm trying to debug an issue in Symbolics and I am unable to print diagnostics. The below is triggered by inserting a "println(occurrences)" into the expand_derivatives function of Symbolics. The type of occurrences is SymbolicUtils.BasicSymbolic{Real}, and I have no idea how to query anything about it (since it refuses to even display.)

ERROR: LoadError: MethodError: no method matching nameof(::Bool)
The function `nameof` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  nameof(::JuliaInterpreter.Frame)
   @ JuliaInterpreter ~/.julia/packages/JuliaInterpreter/cxlKp/src/utils.jl:17
  nameof(::Core.IntrinsicFunction)
   @ Base reflection.jl:2273
  nameof(::Num)
   @ Symbolics ~/.julia/dev/Symbolics/src/num.jl:87
  ...

Stacktrace:
  [1] show_call(io::Base.TTY, f::Bool, args::Vector{Any})
    @ SymbolicUtils ~/.julia/dev/SymbolicUtils/src/types.jl:849
  [2] show_term(io::Base.TTY, t::SymbolicUtils.BasicSymbolic{Real})
    @ SymbolicUtils ~/.julia/dev/SymbolicUtils/src/types.jl:894
  [3] show
    @ ~/.julia/dev/SymbolicUtils/src/types.jl:907 [inlined]
  [4] print(io::Base.TTY, x::SymbolicUtils.BasicSymbolic{Real})
    @ Base ./strings/io.jl:35
  [5] print(::Base.TTY, ::SymbolicUtils.BasicSymbolic{Real}, ::String)
    @ Base ./strings/io.jl:46
  [6] println(io::Base.TTY, xs::SymbolicUtils.BasicSymbolic{Real})
    @ Base ./strings/io.jl:75
  [7] println(xs::SymbolicUtils.BasicSymbolic{Real})
    @ Base ./coreio.jl:4
  [8] expand_derivatives(O::SymbolicUtils.BasicSymbolic{Real}, simplify::Bool; occurrences::Nothing)
    @ Symbolics ~/.julia/dev/Symbolics/src/diff.jl:268
  [9] expand_derivatives(n::Num, simplify::Bool; occurrences::Nothing)
    @ Symbolics ~/.julia/dev/Symbolics/src/diff.jl:324
 [10] expand_derivatives
    @ ~/.julia/dev/Symbolics/src/diff.jl:322 [inlined]
 [11] expand_derivatives(n::Num)
    @ Symbolics ~/.julia/dev/Symbolics/src/diff.jl:323
 [12] main()
    @ Main ~/MWE-ex/mwe.jl:12
 [13] top-level scope
    @ ~/MWE-ex/mwe.jl:15
 [14] include(fname::String)
    @ Main ./sysimg.jl:38
 [15] top-level scope
    @ REPL[1]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants