Symbolic Arrays have issues with Complex Numbers

I can’t work with complex numbers multiplying Symbolic Arrays.

Here an example:

using Symbolics, SpecialFunctions
N = 3
@variables r[1:N, 1:N], ϕ[1:N, 1:N]

H = hankelh1.(0, r)
P = cos.(ϕ) 
Q = im.*cos.(ϕ)# also does not work for 'im*sin.(ϕ)', or 'cis.(ϕ)'

PH = P.*H
QH = Q.*H

y = Symbolics.scalarize(PH[1])
substitute.(y, (Dict(r[1,1] => 2.0),))  # works

y = Symbolics.scalarize(QH[1])
substitute.(y, (Dict(r[1,1] => 2.0),))  # Fails
ERROR: type ComplexTerm has no field metadata
Stacktrace:
  [1] getproperty
    @ ./Base.jl:42 [inlined]
  [2] metadata(s::Symbolics.ComplexTerm{Real})
    @ SymbolicUtils ~/.julia/packages/SymbolicUtils/vnuIf/src/types.jl:12
  [3] substitute(expr::Symbolics.ComplexTerm{Real}, dict::Dict{SymbolicUtils.Term{Real, Nothing}, Float64}; fold::Bool)
    @ SymbolicUtils ~/.julia/packages/SymbolicUtils/vnuIf/src/substitute.jl:34
  [4] substitute
    @ ~/.julia/packages/SymbolicUtils/vnuIf/src/substitute.jl:17 [inlined]
  [5] #16#17
    @ ~/.julia/packages/Symbolics/sDAUx/src/num.jl:85 [inlined]
  [6] (::Symbolics.var"#16#19"{Symbolics.var"#16#17#20"{Dict{SymbolicUtils.Term{Real, Nothing}, Float64}}})(expr::Symbolics.ComplexTerm{Real})
    @ Symbolics ~/.julia/packages/Symbolics/sDAUx/src/num.jl:85
  [7] substitute(expr::Complex{Num}, s::Dict{Num, Float64}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Symbolics ~/.julia/packages/Symbolics/sDAUx/src/Symbolics.jl:149
  [8] substitute
    @ ~/.julia/packages/Symbolics/sDAUx/src/Symbolics.jl:149 [inlined]
  [9] _broadcast_getindex_evalf
    @ ./broadcast.jl:670 [inlined]
 [10] _broadcast_getindex
    @ ./broadcast.jl:643 [inlined]
 [11] #29
    @ ./broadcast.jl:1075 [inlined]
 [12] ntuple
    @ ./ntuple.jl:48 [inlined]
 [13] copy
    @ ./broadcast.jl:1075 [inlined]
 [14] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(substitute), Tuple{Complex{Num}, Tuple{Dict{Num, Float64}}}})
    @ Base.Broadcast ./broadcast.jl:860
 [15] top-level scope
    @ REPL[12]:2

I accept suggestions: Do I need to put some keyword inside substitute ? Do I need to declare my variables as Complex? Is this a bug?

Sounds like this should be an issue.

1 Like