|
353 | 353 |
|
354 | 354 | operation(x::Term) = getfield(x, :f) |
355 | 355 |
|
| 356 | +unsorted_arguments(x) = arguments(x) |
356 | 357 | arguments(x::Term) = getfield(x, :arguments) |
357 | 358 |
|
358 | 359 | function Base.isequal(t1::Term, t2::Term) |
@@ -632,6 +633,11 @@ istree(a::Add) = true |
632 | 633 |
|
633 | 634 | operation(a::Add) = + |
634 | 635 |
|
| 636 | +function unsorted_arguments(a::Add) |
| 637 | + args = [v*k for (k,v) in a.dict] |
| 638 | + iszero(a.coeff) ? args : vcat(a.coeff, args) |
| 639 | +end |
| 640 | + |
635 | 641 | function arguments(a::Add) |
636 | 642 | a.sorted_args_cache[] !== nothing && return a.sorted_args_cache[] |
637 | 643 | args = sort!([v*k for (k,v) in a.dict], lt=<ₑ) |
@@ -777,6 +783,11 @@ operation(a::Mul) = * |
777 | 783 |
|
778 | 784 | unstable_pow(a, b) = a isa Integer && b isa Integer ? (a//1) ^ b : a ^ b |
779 | 785 |
|
| 786 | +function unsorted_arguments(a::Mul) |
| 787 | + args = [unstable_pow(k, v) for (k,v) in a.dict] |
| 788 | + isone(a.coeff) ? args : vcat(a.coeff, args) |
| 789 | +end |
| 790 | + |
780 | 791 | function arguments(a::Mul) |
781 | 792 | a.sorted_args_cache[] !== nothing && return a.sorted_args_cache[] |
782 | 793 | args = sort!([unstable_pow(k, v) for (k,v) in a.dict], lt=<ₑ) |
|
0 commit comments