SymbolicUtils.jl icon indicating copy to clipboard operation
SymbolicUtils.jl copied to clipboard

`<ₑ` not fully reliable

Open bowenszhu opened this issue 1 year ago • 3 comments

<ₑ is normally used for sorting arguments.

sort!(v; lt=isless, ...) requires that only one of lt(x,y) and lt(y,x) can return true.

Here is an example where both return true.

using SymbolicUtils
using SymbolicUtils: <ₑ
@syms x
a = 28(x^14)
b = 44(x^7)
a <ₑ b # true
b <ₑ a # true

We got strange results sometimes.

using SymbolicUtils
using SymbolicUtils: <ₑ, unsorted_arguments
@syms x
n = 4
expr = sum((n + 1 - i) * x^i for i in 1:n)
args = unsorted_arguments(expr)
julia> sort(args, lt = <ₑ)
4-element Vector{Any}:
 x^4
 2(x^3)
 4x
 3(x^2)

julia> sort(reverse(args), lt = <ₑ)
4-element Vector{Any}:
 x^4
 3(x^2)
 4x
 2(x^3)

Note that the two above are different.

bowenszhu avatar Nov 03 '22 02:11 bowenszhu