In src/variable.jl:331
SymbolicIndexingInterface.symbolic_type(::Type{Symbolics.Num}) = ScalarSymbolic()
the symbolic_type of a Symbolics.Num is inferred to be a ScalarSymbolic.
However, when working with complex-valued symbols, they are currently inferred to be a NotSymbolic. This causes some issues in substitution of matrices of symbols, where they are inserted as SymbolicUtils.Const instead of SymbolicUtils.array_literal. This in return prevents get_variables to find the symbols in the matrix.
Solution
Would it be possible to add also the following line to the file?
SymbolicIndexingInterface.symbolic_type(::Type{Complex{Symbolics.Num}}) = ScalarSymbolic()
Demonstrator
import Symbolics
import SymbolicUtils
# Uncomment next line to see new behaviour.
# SymbolicUtils.SymbolicIndexingInterface.symbolic_type(::Type{Complex{Symbolics.Num}}) = SymbolicUtils.ScalarSymbolic()
θ, λ = Symbolics.@variables θ::Real λ::Real
real_f = Symbolics.variable(:real_f; T=Symbolics.FnType{Tuple{Vararg{Number}}, Number, Nothing})(θ)
complex_f = Symbolics.variable(:complex_f; T=Symbolics.FnType{Tuple{Vararg{Number}}, Number, Nothing})(λ)
real_mat = Matrix([exp( θ) 0.0; 0.0 0.0])
complex_mat = Matrix([exp(1im*λ) 0.0; 0.0 0.0])
expr = real_f * complex_f
real_subs = Symbolics.substitute(expr, Dict(real_f => real_mat)) # substitutes a SymbolicUtils.array_literal
complex_subs = Symbolics.substitute(expr, Dict(complex_f => complex_mat)) # substitutes a SymbolicUtils.Const
real_vars = Symbolics.get_variables(real_subs)
complex_vars = Symbolics.get_variables(complex_subs) # does not find λ
The added line would make also the matrix in complex_subs to be a array_literal (same as in real_subs), and get_variables would then be able to find λ.
Tested with
SymbolicUtils v4.45.0
Symbolics v7.36.0
In src/variable.jl:331
the
symbolic_typeof aSymbolics.Numis inferred to be aScalarSymbolic.However, when working with complex-valued symbols, they are currently inferred to be a
NotSymbolic. This causes some issues in substitution of matrices of symbols, where they are inserted asSymbolicUtils.Constinstead ofSymbolicUtils.array_literal. This in return preventsget_variablesto find the symbols in the matrix.Solution
Would it be possible to add also the following line to the file?
Demonstrator
The added line would make also the matrix in
complex_substo be a array_literal (same as inreal_subs), andget_variableswould then be able to findλ.Tested with
SymbolicUtils v4.45.0
Symbolics v7.36.0