@@ -205,7 +205,7 @@ function wrap_array_vars(sys::AbstractSystem, exprs; dvs = unknowns(sys))
205
205
isscalar = ! (exprs isa AbstractArray)
206
206
array_vars = Dict {Any, AbstractArray{Int}} ()
207
207
for (j, x) in enumerate (dvs)
208
- if istree (x) && operation (x) == getindex
208
+ if iscall (x) && operation (x) == getindex
209
209
arg = arguments (x)[1 ]
210
210
inds = get! (() -> Int[], array_vars, arg)
211
211
push! (inds, j)
@@ -352,7 +352,7 @@ function SymbolicIndexingInterface.is_variable(sys::AbstractSystem, sym)
352
352
end
353
353
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
354
354
return is_variable (ic, sym) ||
355
- istree (sym) && operation (sym) === getindex &&
355
+ iscall (sym) && operation (sym) === getindex &&
356
356
is_variable (ic, first (arguments (sym)))
357
357
end
358
358
return any (isequal (sym), variable_symbols (sys)) ||
@@ -378,7 +378,7 @@ function SymbolicIndexingInterface.variable_index(sys::AbstractSystem, sym)
378
378
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
379
379
return if (idx = variable_index (ic, sym)) != = nothing
380
380
idx
381
- elseif istree (sym) && operation (sym) === getindex &&
381
+ elseif iscall (sym) && operation (sym) === getindex &&
382
382
(idx = variable_index (ic, first (arguments (sym)))) != = nothing
383
383
idx[arguments (sym)[(begin + 1 ): end ]. .. ]
384
384
else
@@ -416,7 +416,7 @@ function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym)
416
416
sym = unwrap (sym)
417
417
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
418
418
return is_parameter (ic, sym) ||
419
- istree (sym) && operation (sym) === getindex &&
419
+ iscall (sym) && operation (sym) === getindex &&
420
420
is_parameter (ic, first (arguments (sym)))
421
421
end
422
422
if unwrap (sym) isa Int
@@ -441,7 +441,7 @@ function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym)
441
441
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
442
442
return if (idx = parameter_index (ic, sym)) != = nothing
443
443
idx
444
- elseif istree (sym) && operation (sym) === getindex &&
444
+ elseif iscall (sym) && operation (sym) === getindex &&
445
445
(idx = parameter_index (ic, first (arguments (sym)))) != = nothing
446
446
ParameterIndex (idx. portion, (idx. idx... , arguments (sym)[(begin + 1 ): end ]. .. ))
447
447
else
@@ -745,22 +745,22 @@ function _apply_to_variables(f::F, ex) where {F}
745
745
if isvariable (ex)
746
746
return f (ex)
747
747
end
748
- istree (ex) || return ex
749
- similarterm (ex , _apply_to_variables (f, operation (ex)),
748
+ iscall (ex) || return ex
749
+ maketerm ( typeof (ex) , _apply_to_variables (f, operation (ex)),
750
750
map (Base. Fix1 (_apply_to_variables, f), arguments (ex)),
751
- metadata = metadata (ex))
751
+ symtype (ex), metadata (ex))
752
752
end
753
753
754
754
abstract type SymScope end
755
755
756
756
struct LocalScope <: SymScope end
757
757
function LocalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
758
758
apply_to_variables (sym) do sym
759
- if istree (sym) && operation (sym) === getindex
759
+ if iscall (sym) && operation (sym) === getindex
760
760
args = arguments (sym)
761
761
a1 = setmetadata (args[1 ], SymScope, LocalScope ())
762
- similarterm ( sym, operation (sym), [a1, args[2 : end ]. .. ];
763
- metadata = metadata (sym))
762
+ maketerm ( typeof ( sym) , operation (sym), [a1, args[2 : end ]. .. ],
763
+ symtype (sym), metadata (sym))
764
764
else
765
765
setmetadata (sym, SymScope, LocalScope ())
766
766
end
@@ -772,12 +772,12 @@ struct ParentScope <: SymScope
772
772
end
773
773
function ParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
774
774
apply_to_variables (sym) do sym
775
- if istree (sym) && operation (sym) === getindex
775
+ if iscall (sym) && operation (sym) === getindex
776
776
args = arguments (sym)
777
777
a1 = setmetadata (args[1 ], SymScope,
778
778
ParentScope (getmetadata (value (args[1 ]), SymScope, LocalScope ())))
779
- similarterm ( sym, operation (sym), [a1, args[2 : end ]. .. ];
780
- metadata = metadata (sym))
779
+ maketerm ( typeof ( sym) , operation (sym), [a1, args[2 : end ]. .. ],
780
+ symtype (sym), metadata (sym))
781
781
else
782
782
setmetadata (sym, SymScope,
783
783
ParentScope (getmetadata (value (sym), SymScope, LocalScope ())))
@@ -791,12 +791,12 @@ struct DelayParentScope <: SymScope
791
791
end
792
792
function DelayParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} , N)
793
793
apply_to_variables (sym) do sym
794
- if istree (sym) && operation (sym) == getindex
794
+ if iscall (sym) && operation (sym) == getindex
795
795
args = arguments (sym)
796
796
a1 = setmetadata (args[1 ], SymScope,
797
797
DelayParentScope (getmetadata (value (args[1 ]), SymScope, LocalScope ()), N))
798
- similarterm ( sym, operation (sym), [a1, args[2 : end ]. .. ];
799
- metadata = metadata (sym))
798
+ maketerm ( typeof ( sym) , operation (sym), [a1, args[2 : end ]. .. ],
799
+ symtype (sym), metadata (sym))
800
800
else
801
801
setmetadata (sym, SymScope,
802
802
DelayParentScope (getmetadata (value (sym), SymScope, LocalScope ()), N))
@@ -808,11 +808,11 @@ DelayParentScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}}) = DelayParentSco
808
808
struct GlobalScope <: SymScope end
809
809
function GlobalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
810
810
apply_to_variables (sym) do sym
811
- if istree (sym) && operation (sym) == getindex
811
+ if iscall (sym) && operation (sym) == getindex
812
812
args = arguments (sym)
813
813
a1 = setmetadata (args[1 ], SymScope, GlobalScope ())
814
- similarterm ( sym, operation (sym), [a1, args[2 : end ]. .. ];
815
- metadata = metadata (sym))
814
+ maketerm ( typeof ( sym) , operation (sym), [a1, args[2 : end ]. .. ],
815
+ symtype (sym), metadata (sym))
816
816
else
817
817
setmetadata (sym, SymScope, GlobalScope ())
818
818
end
@@ -827,16 +827,16 @@ function renamespace(sys, x)
827
827
x = unwrap (x)
828
828
if x isa Symbolic
829
829
T = typeof (x)
830
- if istree (x) && operation (x) isa Operator
831
- return similarterm (x , operation (x),
832
- Any[renamespace (sys, only (arguments (x)))];
833
- metadata = metadata (x)):: T
830
+ if iscall (x) && operation (x) isa Operator
831
+ return maketerm ( typeof (x) , operation (x),
832
+ Any[renamespace (sys, only (arguments (x)))],
833
+ symtype (x), metadata (x)):: T
834
834
end
835
- if istree (x) && operation (x) === getindex
835
+ if iscall (x) && operation (x) === getindex
836
836
args = arguments (x)
837
- return similarterm (
838
- x , operation (x), vcat (renamespace (sys, args[1 ]), args[2 : end ]);
839
- metadata = metadata (x)):: T
837
+ return maketerm (
838
+ typeof (x) , operation (x), vcat (renamespace (sys, args[1 ]), args[2 : end ]),
839
+ symtype (x), metadata (x)):: T
840
840
end
841
841
let scope = getmetadata (x, SymScope, LocalScope ())
842
842
if scope isa LocalScope
@@ -904,7 +904,7 @@ function namespace_expr(
904
904
O = unwrap (O)
905
905
if any (isequal (O), ivs)
906
906
return O
907
- elseif istree (O)
907
+ elseif iscall (O)
908
908
T = typeof (O)
909
909
renamed = let sys = sys, n = n, T = T
910
910
map (a -> namespace_expr (a, sys, n; ivs):: Any , arguments (O))
@@ -913,13 +913,14 @@ function namespace_expr(
913
913
# Use renamespace so the scope is correct, and make sure to use the
914
914
# metadata from the rescoped variable
915
915
rescoped = renamespace (n, O)
916
- similarterm (O, operation (rescoped), renamed,
917
- metadata = metadata (rescoped))
916
+ maketerm (typeof (rescoped), operation (rescoped), renamed,
917
+ symtype (rescoped),
918
+ metadata (rescoped))
918
919
elseif Symbolics. isarraysymbolic (O)
919
920
# promote_symtype doesn't work for array symbolics
920
- similarterm (O , operation (O), renamed, symtype (O), metadata = metadata (O))
921
+ maketerm ( typeof (O) , operation (O), renamed, symtype (O), metadata (O))
921
922
else
922
- similarterm (O , operation (O), renamed, metadata = metadata (O))
923
+ maketerm ( typeof (O) , operation (O), renamed, symtype (O), metadata (O))
923
924
end
924
925
elseif isvariable (O)
925
926
renamespace (n, O)
@@ -1097,7 +1098,7 @@ function time_varying_as_func(x, sys::AbstractTimeDependentSystem)
1097
1098
# than pass in a value in place of x(t).
1098
1099
#
1099
1100
# This is done by just making `x` the argument of the function.
1100
- if istree (x) &&
1101
+ if iscall (x) &&
1101
1102
issym (operation (x)) &&
1102
1103
! (length (arguments (x)) == 1 && isequal (arguments (x)[1 ], get_iv (sys)))
1103
1104
return operation (x)
@@ -1125,7 +1126,7 @@ function push_vars!(stmt, name, typ, vars)
1125
1126
isempty (vars) && return
1126
1127
vars_expr = Expr (:macrocall , typ, nothing )
1127
1128
for s in vars
1128
- if istree (s)
1129
+ if iscall (s)
1129
1130
f = nameof (operation (s))
1130
1131
args = arguments (s)
1131
1132
ex = :($ f ($ (args... )))
@@ -1142,7 +1143,7 @@ function round_trip_expr(t, var2name)
1142
1143
name = get (var2name, t, nothing )
1143
1144
name != = nothing && return name
1144
1145
issym (t) && return nameof (t)
1145
- istree (t) || return t
1146
+ iscall (t) || return t
1146
1147
f = round_trip_expr (operation (t), var2name)
1147
1148
args = map (Base. Fix2 (round_trip_expr, var2name), arguments (t))
1148
1149
return :($ f ($ (args... )))
@@ -2564,8 +2565,10 @@ is_diff_equation(eq2) # false
2564
2565
"""
2565
2566
function is_diff_equation (eq)
2566
2567
(eq isa Equation) || (return false )
2567
- isdefined (eq, :lhs ) && occursin (is_derivative, wrap (eq. lhs)) && (return true )
2568
- isdefined (eq, :rhs ) && occursin (is_derivative, wrap (eq. rhs)) && (return true )
2568
+ isdefined (eq, :lhs ) && hasnode (is_derivative, wrap (eq. lhs)) &&
2569
+ (return true )
2570
+ isdefined (eq, :rhs ) && hasnode (is_derivative, wrap (eq. rhs)) &&
2571
+ (return true )
2569
2572
return false
2570
2573
end
2571
2574
0 commit comments