Skip to content

Commit 85fbdb2

Browse files
committed
when variable is indexed, sort by variable name and then by index
1 parent dccce50 commit 85fbdb2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/ordering.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# find symbols and their corresponding degrees
2020
function get_degrees(expr)
2121
if issym(expr)
22-
(nameof(expr) => 1,)
22+
((Symbol(expr),) => 1,)
2323
elseif istree(expr)
2424
op = operation(expr)
2525
args = arguments(expr)
@@ -34,8 +34,11 @@ function get_degrees(expr)
3434
ds = map(get_degrees, args)
3535
_, idx = findmax(x->sum(last.(x), init=0), ds)
3636
return ds[idx]
37+
elseif operation(expr) == (getindex)
38+
args = arguments(expr)
39+
return ((Symbol.(args)...,) => 1,)
3740
else
38-
return (Symbol("zzzzzzz", hash(expr)) => 1,)
41+
return ((Symbol("zzzzzzz", hash(expr)),) => 1,)
3942
end
4043
else
4144
return ()

test/basics.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,15 @@ end
189189
end
190190

191191
@testset "polynomial printing" begin
192-
@syms a b c
192+
@syms a b c x[1:3]
193193
@test repr(b+a) == "a + b"
194194
@test repr(b-a) == "-a + b"
195195
@test repr(2a+1+3a^2) == "1 + 2a + 3(a^2)"
196196
@test repr(2a+1+3a^2+2b+3b^2+4a*b) == "1 + 2a + 2b + 3(a^2) + 4a*b + 3(b^2)"
197+
198+
@syms a b[1:3] c d[1:3]
199+
@test repr(a + b[3] + b[1] + d[2] + c) == "a + b[1] + b[3] + c + d[2]"
200+
@test repr(expand((c + b[3] - d[1])^3)) == "b[3]^3 + 3(b[3]^2)*c - 3(b[3]^2)*d[1] + 3b[3]*(c^2) - 6b[3]*c*d[1] + 3b[3]*(d[1]^2) + c^3 - 3(c^2)*d[1] + 3c*(d[1]^2) - (d[1]^3)"
197201
end
198202

199203
@testset "inspect" begin

0 commit comments

Comments
 (0)