Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<ₑ not fully reliable #483

Closed
bowenszhu opened this issue Nov 3, 2022 · 5 comments
Closed

<ₑ not fully reliable #483

bowenszhu opened this issue Nov 3, 2022 · 5 comments

Comments

@bowenszhu
Copy link
Member

<ₑ 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
Copy link
Member Author

bowenszhu commented Nov 19, 2022

describes a bug caused by this issue.

And it is also important to take

into account. Sometimes symbolic software are used in math classes for educational purpose. Printing results in an appropriate order is important to avoid making bad first impression.

@bowenszhu
Copy link
Member Author

bowenszhu commented Nov 23, 2022

@bowenszhu
Copy link
Member Author

@karlwessel
Copy link
Contributor

Note that the example in the first comment got fixed at some point, at least for me with SymbolicsUtils 3.6.0 it gives:

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

@bowenszhu
Copy link
Member Author

OK. Thank you! @karlwessel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants