Skip to content

<ₑ not fully reliable #483

@bowenszhu

Description

@bowenszhu

<ₑ 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.

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