|
1 | 1 | ## Create linear independent basis |
| 2 | + |
| 3 | +# Helper to check if x is a constant (Number or SymbolicUtils Const type) |
| 4 | +_is_constant(x::Number) = true |
| 5 | +function _is_constant(x) |
| 6 | + # In SymbolicUtils v4+, constants are wrapped in Const type |
| 7 | + # Check using isconst if available |
| 8 | + SymbolicUtils.isconst(x) |
| 9 | +end |
| 10 | + |
2 | 11 | count_operation(x::Number, op::Function, nested::Bool = true) = 0 |
3 | 12 | function count_operation(x::SymbolicUtils.BasicSymbolic, op::Function, nested::Bool = true) |
4 | | - issym(x) && return 0 |
| 13 | + # Check if x is a symbol or not a call (e.g., Const in SymbolicUtils v4) |
| 14 | + (issym(x) || !iscall(x)) && return 0 |
5 | 15 | if operation(x) == op |
6 | 16 | if is_unary(op) |
7 | 17 | # Handles sin, cos and stuff |
@@ -76,7 +86,8 @@ function remove_constant_factor(x) |
76 | 86 | # Create a new array |
77 | 87 | ops = Array{Any}(undef, n_ops) |
78 | 88 | @views split_term!(ops, x, [*]) |
79 | | - filter!(x -> !isa(x, Number), ops) |
| 89 | + # Filter out constants (both Number and SymbolicUtils Const types) |
| 90 | + filter!(x -> !_is_constant(x), ops) |
80 | 91 | return Num(prod(ops)) |
81 | 92 | end |
82 | 93 |
|
@@ -106,15 +117,18 @@ function create_linear_independent_eqs(ops::AbstractVector, simplify_eqs::Bool = |
106 | 117 | return simplify_eqs ? simplify.(Num.(u_o)) : Num.(u_o) |
107 | 118 | end |
108 | 119 |
|
109 | | -function is_dependent(x::SymbolicUtils.Symbolic, y::SymbolicUtils.Symbolic) |
110 | | - occursin(y, x) |
| 120 | +function is_dependent(x::SymbolicUtils.BasicSymbolic, y::SymbolicUtils.BasicSymbolic) |
| 121 | + # In SymbolicUtils v4, occursin was removed. Use get_variables instead. |
| 122 | + # Check if y appears in the variables of x |
| 123 | + vars = Symbolics.get_variables(x) |
| 124 | + y in vars |
111 | 125 | end |
112 | 126 |
|
113 | | -function is_dependent(x::Any, y::SymbolicUtils.Symbolic) |
| 127 | +function is_dependent(x::Any, y::SymbolicUtils.BasicSymbolic) |
114 | 128 | false |
115 | 129 | end |
116 | 130 |
|
117 | | -function is_dependent(x::SymbolicUtils.Symbolic, y::Any) |
| 131 | +function is_dependent(x::SymbolicUtils.BasicSymbolic, y::Any) |
118 | 132 | false |
119 | 133 | end |
120 | 134 |
|
|
0 commit comments