Skip to content

BoundsError when using expand_derivatives on a particular expression in y, but not the same expression in x #1126

@krsteffen

Description

@krsteffen

MWE (Julia Version 1.10.2, Symbolics v5.28.0, SymbolicUtils v1.5.1):

using Symbolics

expr_gen = (var, fun) -> Differential(var)(Differential(var)(((-Differential(var)(Differential(var)(fun))) / g(var))))

@syms y f(y) g(y) h(y)

expr = expr_gen(y, f(y))
expand_derivatives(expr)
expr = expr_gen(y, g(y))
expand_derivatives(expr) # Error
expr = expr_gen(y, h(y))
expand_derivatives(expr) # Error

The error message:

> show(err)
1-element ExceptionStack:
BoundsError: attempt to access 1-element Vector{Any} at index [2]
Stacktrace:
 [1] getindex(A::Vector{Any}, i1::Int64)
   @ Base ./essentials.jl:13
 [2] expand_derivatives(O::SymbolicUtils.BasicSymbolic{Number}, simplify::Bool; occurrences::SymbolicUtils.BasicSymbolic{Real}) (repeats 2 times)
   @ Symbolics ~/.julia/packages/Symbolics/Eas9m/src/diff.jl:245
 [3] expand_derivatives(O::SymbolicUtils.BasicSymbolic{Number}, simplify::Bool; occurrences::Nothing)
   @ Symbolics ~/.julia/packages/Symbolics/Eas9m/src/diff.jl:245
 [4] expand_derivatives
   @ ~/.julia/packages/Symbolics/Eas9m/src/diff.jl:171 [inlined]
 [5] expand_derivatives(O::SymbolicUtils.BasicSymbolic{Number})
   @ Symbolics ~/.julia/packages/Symbolics/Eas9m/src/diff.jl:171
 [6] top-level scope
   @ REPL[9]:1

For some reason all of the following run successfully. The only difference is replacing y with x.

using Symbolics

expr_gen = (var, fun) -> Differential(var)(Differential(var)(((-Differential(var)(Differential(var)(fun))) / g(var))))

@syms x f(x) g(x) h(x)

expr = expr_gen(x, f(x))
expand_derivatives(expr)
expr = expr_gen(x, g(x))
expand_derivatives(expr)
expr = expr_gen(x, h(x))
expand_derivatives(expr)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions