Skip to content

Commit 42adfd9

Browse files
authored
Merge pull request #346 from JuliaSymbolics/myb/opt
Optimized ordering computation
2 parents 3f2654c + 306dbb4 commit 42adfd9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/ordering.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
arglength(a) = length(arguments(a))
1212
function <(a, b)
13-
if !istree(a) && !istree(b)
13+
if a isa Term && (b isa Symbolic && !(b isa Term))
14+
return false
15+
elseif b isa Term && (a isa Symbolic && !(a isa Term))
16+
return true
17+
elseif !istree(a) && !istree(b)
1418
T = typeof(a)
1519
S = typeof(b)
1620
return T===S ? (T <: Number ? isless(a, b) : hash(a) < hash(b)) : nameof(T) < nameof(S)

test/order.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ SymbolicUtils.show_simplified[] = false
55

66
@syms a b c
77

8-
function istotal(x,y)
8+
function istotal(x, y)
99
#either
1010
if x <ₑ y
1111
return !(y <ₑ x)
1212
elseif y <ₑ x
1313
return !(x <ₑ y) # already tested
1414
else
1515
# neither, equal
16-
return true
16+
return isequal(x, y)
1717
end
1818
end
1919

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

8584
@testset "transitivity" begin

0 commit comments

Comments
 (0)