You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To replicate this error, it is necessary to add some debug statements to the expand_derivatives function. In the below MWE, that function is modified from version 6.12.0 only by adding debug printing. It's about line 78 of the MWE, after the comment "#DEBUG PRINTING".
I was trying to debug #1262 and one of the intermediate variables fails to print. It has type "SymbolicUtils.BasicSymbolic{Real}". There might be two things going on
This variable "occurrences" is in some corrupt state that doesn't stand a chance of being displayed
It should be display()-able but there is a bug somewhere in the display code, perhaps in show_call or show_term
Here is the error output first; it includes a full dump() of the offending variable. I can't read it but hopefully someone can!
using Symbolics
@eval Symbolics begin
function expand_derivatives(O::Symbolics.Symbolic, simplify = false; occurrences = nothing)
if iscall(O) && isa(operation(O), Differential)
arg = only(arguments(O))
arg = expand_derivatives(arg, false)
if occurrences == nothing
occurrences = occursin_info(operation(O).x, arg)
end
_isfalse(occurrences) && return 0
occurrences isa Bool && return 1 # means it's a `true`
D = operation(O)
if !iscall(arg)
return D(arg) # Cannot expand
elseif (op = operation(arg); issym(op))
inner_args = arguments(arg)
if any(isequal(D.x), inner_args)
return D(arg) # base case if any argument is directly equal to the i.v.
else
return sum(inner_args, init = 0) do a
return expand_derivatives(Differential(a)(arg)) *
expand_derivatives(D(a))
end
end
elseif op === (IfElse.ifelse)
args = arguments(arg)
O = op(args[1], D(args[2]), D(args[3]))
return expand_derivatives(O, simplify; occurrences)
elseif isa(op, Differential)
# The recursive expand_derivatives was not able to remove
# a nested Differential. We can attempt to differentiate the
# inner expression wrt to the outer iv. And leave the
# unexpandable Differential outside.
if isequal(op.x, D.x)
return D(arg)
else
inner = expand_derivatives(D(arguments(arg)[1]), false)
# if the inner expression is not expandable either, return
if iscall(inner) && operation(inner) isa Differential
return D(arg)
else
return expand_derivatives(op(inner), simplify)
end
end
elseif isa(op, Integral)
if isa(op.domain.domain, AbstractInterval)
domain = op.domain.domain
a, b = DomainSets.endpoints(domain)
c = 0
inner_function = expand_derivatives(arguments(arg)[1])
if iscall(value(a))
t1 = SymbolicUtils.substitute(
inner_function, Dict(op.domain.variables => value(a)))
t2 = D(a)
c -= t1 * t2
end
if iscall(value(b))
t1 = SymbolicUtils.substitute(
inner_function, Dict(op.domain.variables => value(b)))
t2 = D(b)
c += t1 * t2
end
inner = expand_derivatives(D(arguments(arg)[1]))
c += op(inner)
return value(c)
end
end
inner_args = arguments(arg)
l = length(inner_args)
exprs = []
c = 0
#DEBUG PRINTING
@info "before loop" O "line 79"
println(typeof(occurrences))
dump(occurrences)
display(occurrences)
for i in 1:l
t2 = expand_derivatives(D(inner_args[i]),false, occurrences=arguments(occurrences)[i])
x = if _iszero(t2)
t2
elseif _isone(t2)
d = derivative_idx(arg, i)
d isa NoDeriv ? D(arg) : d
else
t1 = derivative_idx(arg, i)
t1 = t1 isa NoDeriv ? D(arg) : t1
t1 * t2
end
if _iszero(x)
continue
elseif x isa Symbolic
push!(exprs, x)
else
c += x
end
end
if isempty(exprs)
return c
elseif length(exprs) == 1
term = (simplify ? SymbolicUtils.simplify(exprs[1]) : exprs[1])
return _iszero(c) ? term : c + term
else
x = +((!_iszero(c) ? vcat(c, exprs) : exprs)...)
return simplify ? SymbolicUtils.simplify(x) : x
end
elseif iscall(O) && isa(operation(O), Integral)
return operation(O)(expand_derivatives(arguments(O)[1]))
elseif !hasderiv(O)
return O
else
args = map(a -> expand_derivatives(a, false), arguments(O))
O1 = operation(O)(args...)
return simplify ? SymbolicUtils.simplify(O1) : O1
end
end
end
function main()
@variables t b(t)
D = Differential(t)
expr = b - D(b) * D(b) * D(D(b))
expr2 = D(expr)
#display(expr)
#display(expand_derivatives(expr))
#display(expr2)
expand_derivatives(expr2)
end
main()
The text was updated successfully, but these errors were encountered:
To replicate this error, it is necessary to add some debug statements to the expand_derivatives function. In the below MWE, that function is modified from version 6.12.0 only by adding debug printing. It's about line 78 of the MWE, after the comment "#DEBUG PRINTING".
I was trying to debug #1262 and one of the intermediate variables fails to print. It has type "SymbolicUtils.BasicSymbolic{Real}". There might be two things going on
Here is the error output first; it includes a full dump() of the offending variable. I can't read it but hopefully someone can!
MWE:
The text was updated successfully, but these errors were encountered: