Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/QuestBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ using Symbolics:
Equation,
Differential,
arguments,
substitute,
term,
expand,
operation,
Expand Down
20 changes: 19 additions & 1 deletion src/Symbolics/Symbolics_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,26 @@ Perform substitutions in `rules` on `x`.
`Symbolics.substitute_in_deriv`.
"""
Subtype = Union{Num,Equation,BasicSymbolic}

# SymbolicUtils 4 / Symbolics 7: substitute() does not recurse into call arguments
# (e.g. it leaves x(t) unchanged when substituting t => T). Walk the expression and
# rewrite matching nodes ourselves.
function _deep_substitute(e::BasicSymbolic, unwrap_rules::Dict)
# SU 4's default filter blocks recursion into the arguments of callable-symbolic
# terms (e.g. `x(t)`). Override with an always-true filter so substitutions like
# `t => T` reach inside `x(t)`. Compound keys still match before recursion, and
# SU does not re-walk the replacement, so self-referential rules don't loop.
return SymbolicUtils.substitute(e, unwrap_rules; filterer = _ -> true)
end
_deep_substitute(x::Num, ur::Dict) = wrap(_deep_substitute(unwrap(x), ur))
function _deep_substitute(eq::Equation, ur::Dict)
return Equation(_deep_substitute(unwrap(eq.lhs), ur), _deep_substitute(unwrap(eq.rhs), ur))
end
_deep_substitute(x, ::Dict) = x

function substitute_all(x::Subtype, rules::Dict; include_derivatives=true)
result = substitute(x, rules)
unwrap_rules = Dict(unwrap(k) => unwrap(v) for (k, v) in rules)
result = _deep_substitute(x, unwrap_rules)
if include_derivatives
result = Symbolics.substitute_in_deriv(result, rules)
end
Expand Down
5 changes: 3 additions & 2 deletions src/Symbolics/fourier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ is_trig(f::Num) = is_trig(unwrap(f))
is_trig(f) = false
function is_trig(f::BasicSymbolic)
f = ispow(f) ? arguments(f)[1] : f
isterm(f) && operation(f) ∈ [cos, sin] && return true
return false
isterm(f) || return false
op = operation(f)
return op === cos || op === sin
end

"""
Expand Down
6 changes: 5 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ end
is_identity(A::Matrix{Num}) = (@eqsym A == Matrix{Num}(LinearAlgebra.I, size(A)...))
hasnan(x::Matrix{Num}) = any(my_isnan, unwrap.(x))
my_isnan(x) = isnan(x)
my_isnan(x::BasicSymbolic) = false
function my_isnan(x::BasicSymbolic)
SymbolicUtils.isconst(x) || return false
v = Symbolics.value(x)
return v isa Number && isnan(v)
end
Loading