File tree Expand file tree Collapse file tree 2 files changed +49
-4
lines changed Expand file tree Collapse file tree 2 files changed +49
-4
lines changed Original file line number Diff line number Diff line change 3
3
Base. @pure Base. isless (v1:: AbstractVariable , v2:: AbstractVariable ) = name (v1) > name (v2)
4
4
Base. isless (m1:: AbstractTermLike , m2:: AbstractTermLike ) = isless (promote (m1, m2)... )
5
5
6
+ # Implement this to make coefficients be compared with terms.
7
+ function isless_coefficient (a:: Real , b:: Real )
8
+ return a < b
9
+ end
10
+ function isless_coefficient (a:: Number , b:: Number )
11
+ return abs (a) < abs (b)
12
+ end
13
+ # By default, coefficients are not comparable so `a` is not strictly
14
+ # less than `b`, they are considered sort of equal.
15
+ isless_coefficient (a, b) = false
16
+
6
17
function Base. isless (t1:: AbstractTerm , t2:: AbstractTerm )
7
18
if monomial (t1) < monomial (t2)
8
- true
19
+ return true
9
20
elseif monomial (t1) == monomial (t2)
10
- abs (coefficient (t1)) < abs ( coefficient (t2))
21
+ return isless_coefficient (coefficient (t1), coefficient (t2))
11
22
else
12
- false
23
+ return false
13
24
end
14
25
end
15
26
Original file line number Diff line number Diff line change
1
+ struct CoefNotComparable
2
+ end
3
+ Base. iszero (:: CoefNotComparable ) = false
4
+
1
5
@testset " Term" begin
2
6
Mod. @polyvar x
3
7
@test convert (Any, 1 x) == 1 x
49
53
@test_throws InexactError push! ([1 ], 2 x)
50
54
@test_throws ErrorException push! ([x^ 2 ], 2 x)
51
55
52
-
53
56
@testset " Effective variables" begin
54
57
T = variable_union_type (x)
55
58
@test x isa T
61
64
@test T[y] == @inferred effective_variables (x^ 0 * y)
62
65
@test T[y] == @inferred effective_variables (y * x^ 0 )
63
66
end
67
+
68
+ @testset " Compare terms" begin
69
+ t1 = 1 * x
70
+ t2 = 2 * x
71
+ @test t1 < t2
72
+ @test t1 <= t2
73
+ @test ! (t1 > t2)
74
+ @test ! (t1 >= t2)
75
+
76
+ t1 = (1 + 1im ) * x
77
+ t2 = (2 + 2im ) * x
78
+ @test t1 < t2
79
+ @test t1 <= t2
80
+ @test ! (t1 > t2)
81
+ @test ! (t1 >= t2)
82
+
83
+ a = CoefNotComparable ()
84
+ b = CoefNotComparable ()
85
+ t1 = a * x
86
+ t2 = b * y
87
+ @test t1 > t2
88
+ @test t1 >= t2
89
+ @test ! (t1 < t2)
90
+ @test ! (t1 <= t2)
91
+ t1 = a * x
92
+ t2 = b * x
93
+ @test ! (t1 > t2)
94
+ @test t1 >= t2
95
+ @test ! (t1 < t2)
96
+ @test t1 <= t2
97
+ end
64
98
end
You can’t perform that action at this time.
0 commit comments