Skip to content

Commit

Permalink
Merge pull request #346 from JuliaSymbolics/myb/opt
Browse files Browse the repository at this point in the history
Optimized ordering computation
  • Loading branch information
YingboMa authored Sep 2, 2021
2 parents 3f2654c + 306dbb4 commit 42adfd9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/ordering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

arglength(a) = length(arguments(a))
function <(a, b)
if !istree(a) && !istree(b)
if a isa Term && (b isa Symbolic && !(b isa Term))
return false
elseif b isa Term && (a isa Symbolic && !(a isa Term))
return true
elseif !istree(a) && !istree(b)
T = typeof(a)
S = typeof(b)
return T===S ? (T <: Number ? isless(a, b) : hash(a) < hash(b)) : nameof(T) < nameof(S)
Expand Down
7 changes: 3 additions & 4 deletions test/order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ SymbolicUtils.show_simplified[] = false

@syms a b c

function istotal(x,y)
function istotal(x, y)
#either
if x <ₑ y
return !(y <ₑ x)
elseif y <ₑ x
return !(x <ₑ y) # already tested
else
# neither, equal
return true
return isequal(x, y)
end
end

Expand Down Expand Up @@ -78,8 +78,7 @@ end
@testset "small terms" begin
# this failing was a cause of a nasty stackoverflow #82
@syms a
@test Term(^, [a, -1]) <ₑ (a + 2)
@test !((a + 2) <Term(^, [a, -1]))
istotal(Term(^, [a, -1]), (a + 2))
end

@testset "transitivity" begin
Expand Down

0 comments on commit 42adfd9

Please sign in to comment.