Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Expronicon.jl, add Const(::Any) #617

Draft
wants to merge 150 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
39d8791
Add Expronicon v0.8
bowenszhu Jun 13, 2024
dd7a7b2
Add MLStyle for pattern matching
bowenszhu Jun 18, 2024
e15c015
Remove Unityper
bowenszhu Jun 18, 2024
ffaefd8
Add `CONST` enum member value
bowenszhu Jun 18, 2024
4eec0ef
Migrate `BasicSymbolic` to Expronicon ADTs
bowenszhu Jun 18, 2024
989907b
Replace `Unityper.@compactified` with `MLStyle.@match`
bowenszhu Jun 18, 2024
608e23a
Adapt functions to new struct definition
bowenszhu Jun 18, 2024
93e3942
Use `@kwdef` instead of `Base.@kwdef`
bowenszhu Jun 19, 2024
6e5f170
Remove the default value for `Sym.name`
bowenszhu Jun 19, 2024
a7fd87a
Update `Sym` constructor
bowenszhu Jun 19, 2024
d3dcdde
Update `Term` constructor
bowenszhu Jun 19, 2024
ad6dff7
Update `_promote_symtype`
bowenszhu Jun 19, 2024
94f7ef1
Update `Add` constructor
bowenszhu Jun 19, 2024
f97813a
Update `Mul` constructor
bowenszhu Jun 19, 2024
42da470
Remove default value for `Add.dict`
bowenszhu Jun 19, 2024
44af526
Create `arguments` for `Div` and `Pow` at construction step
bowenszhu Jun 19, 2024
4bd021c
Remove default arguments for `Term` struct fields
bowenszhu Jun 19, 2024
552e7f9
Add tests for fundamental types and functions
bowenszhu Jun 19, 2024
12d9c71
Test Expronicon generated constructors
bowenszhu Jun 19, 2024
26cee9f
Add tests for `Sym`
bowenszhu Jun 20, 2024
d2d21b9
Test Expronicon generated constructors for `Div`
bowenszhu Jun 20, 2024
559c732
Test Expronicon `Pow`
bowenszhu Jun 21, 2024
3d808ab
Test Expronicon `Const`
bowenszhu Jun 21, 2024
10bae2a
Add Expronicon type check tests
bowenszhu Jun 21, 2024
f52bbfe
Test Expronicon `Add` & `Mul`
bowenszhu Jun 21, 2024
6906ced
Test `BasicSymbolic` `@kwdef` keyword-based constructor
bowenszhu Jun 21, 2024
74a8f84
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Jun 26, 2024
a771dab
Add `_iszero(x::BasicSymbolic)`
bowenszhu Jun 28, 2024
2e68253
Add a `Const` custom constructor
bowenszhu Jun 28, 2024
1d50a8d
Test custom constructors for `Sym`, `Term` & `Const`
bowenszhu Jun 28, 2024
e645ba6
Correct MLStyle `@match` in `exprtype`
bowenszhu Jun 28, 2024
5c8dd14
Correct MLStyle `@match` in `operation`
bowenszhu Jun 28, 2024
1772173
Correct MLStyle `@match` in `sorted_arguments`
bowenszhu Jun 28, 2024
9e4049a
Fix MLStyle `@match` in `arguments`
bowenszhu Jun 28, 2024
dda1206
Rewrite `is...` functions
bowenszhu Jun 28, 2024
385ad06
Adapt `nameof` to new struct structure
bowenszhu Jun 28, 2024
b2e3a0d
Modify `Div` custom constructors
bowenszhu Jun 28, 2024
911789a
Adapt `numerators` & `denominators` to new struct structure
bowenszhu Jun 28, 2024
776942b
Rewrite `Pow` custom constructors
bowenszhu Jun 28, 2024
fdd345e
Rewrite `toterm`
bowenszhu Jun 28, 2024
21161cc
Rewrite `makeadd`, `makemul`, `makepow`
bowenszhu Jun 28, 2024
7e04640
Rewrite `term`
bowenszhu Jun 28, 2024
1803d3e
Modify `unflatten`
bowenszhu Jun 28, 2024
209a64d
Modify `basicsymbolic`
bowenszhu Jun 28, 2024
bb42582
Modify `setargs`
bowenszhu Jun 28, 2024
4e459bb
Modify `(f::Symbolic{<:FnType})(args...)`
bowenszhu Jun 28, 2024
5a60f5a
Modify `@syms`
bowenszhu Jun 28, 2024
3d487a0
Modify `+`, `-`, `*`, `/`, `\`, `^`
bowenszhu Jun 28, 2024
0b0b2ba
Modify `show`
bowenszhu Jun 28, 2024
3cea20f
Fix calling `term`
bowenszhu Jun 28, 2024
07ffb87
Fix `isone` & `iszero` for `BasicSymbolic`
bowenszhu Jul 1, 2024
014c097
Add `convert` methods for `BasicSymbolic`
bowenszhu Jul 1, 2024
c556359
Fix field access in `+`
bowenszhu Jul 1, 2024
6217809
Fix `isexpr` for `Const`
bowenszhu Jul 1, 2024
4646d12
Fix `Base.show` for `Const`
bowenszhu Jul 1, 2024
98ec692
Fix `issafecanon` for `Const` and add docstring
bowenszhu Jul 1, 2024
ed3fcc3
Modify `+` for `Const`
bowenszhu Jul 1, 2024
f6ea72a
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Jul 17, 2024
962606e
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Jul 31, 2024
f519322
Remove unreachable error case in type matching
bowenszhu Aug 4, 2024
e77e470
Fix function argument type
bowenszhu Aug 4, 2024
8840e23
Update argument name in `makepattern` `Expr`
bowenszhu Aug 4, 2024
145c303
Replace deprecated `Term` constructor
bowenszhu Aug 4, 2024
1c23710
Remove unnecessary tests for `Term` constructor
bowenszhu Aug 4, 2024
4547bde
Remove unnecessary tests for `Pow` constructor
bowenszhu Aug 4, 2024
99549b8
Remove unnecessary tests for `Div` constructor
bowenszhu Aug 4, 2024
df99cff
Change `==` to `isequal` for testing
bowenszhu Aug 5, 2024
f6f557b
Adapt `@syms` tests to new type structure
bowenszhu Aug 5, 2024
87bee71
Revert field type of `Div` and `Pow` from `BasicSymbolic` to `Any`
bowenszhu Aug 6, 2024
0db3e9f
Fix `Pow` function call in `^`
bowenszhu Aug 6, 2024
3f34dc0
Replace `Unityper.rt_constructor` with `BasicSymbolic` constructor
bowenszhu Aug 6, 2024
4cb4323
Fix `Pow` construction in `^`
bowenszhu Aug 6, 2024
4beca44
Fix typo in `Pow` constructor definition
bowenszhu Aug 6, 2024
a026af7
Fix `Pow` construction
bowenszhu Aug 7, 2024
26c7150
Fix `isexpr` for composite symbolic expressions
bowenszhu Aug 7, 2024
98d5c38
Revert `Add` & `Mul` `coeff` type from `BasicSymbolic` to `Any`
bowenszhu Aug 7, 2024
3e73790
Unroll `Const` in addition operation
bowenszhu Aug 7, 2024
b6f6456
Fix `term` keyword argument function call
bowenszhu Aug 7, 2024
59bc77a
Fix `Add` construction in tests
bowenszhu Aug 8, 2024
2031008
Fix `Term` construction in tests
bowenszhu Aug 8, 2024
903f95c
Fix `Term` construction in `ifelse`
bowenszhu Aug 8, 2024
289ad31
Fix `Div` constructor
bowenszhu Aug 8, 2024
f732718
Fix `Div` constructor
bowenszhu Aug 8, 2024
1e9c990
Fix `ConstructionBase.setproperties_object` for changing fields
bowenszhu Aug 8, 2024
1cb71a9
Adapt `getproperty` for new class structure
bowenszhu Aug 11, 2024
34b0796
Fix `Pow` constructor
bowenszhu Aug 11, 2024
9f6b426
Fix test case due keyword argument name change
bowenszhu Aug 11, 2024
c3743f6
Adapt `getproperty` to new class structure
bowenszhu Aug 11, 2024
0b1eaae
Fix `Mul` printing
bowenszhu Aug 11, 2024
f2234c1
Fix `get` `coeff` to new class structure
bowenszhu Aug 11, 2024
fb77a93
Fix printing negative term in `Add`
bowenszhu Aug 11, 2024
4792348
Adapt `maybe_intcoeff` to new class structure
bowenszhu Aug 11, 2024
9133330
Remove unnecessary imports in test
bowenszhu Aug 11, 2024
7ab12c3
Fix `Term` construction in tests
bowenszhu Aug 11, 2024
cf4a6c7
Fix `term` function call due to keyword argument name change
bowenszhu Aug 11, 2024
3af7c31
Fix `PolyForm` construction for `Const`
bowenszhu Aug 11, 2024
79d19bd
Fix `Sym` constructor call in `polyize`
bowenszhu Aug 11, 2024
481c8c7
Fix getting `exp` field in `*`
bowenszhu Aug 13, 2024
54e16af
Fix `inspect` printing for `Const`
bowenszhu Aug 13, 2024
2bd9fc0
Fix getting `coeff` `dict` fields
bowenszhu Aug 13, 2024
8120646
Fix `Div` construction when `isone(den)`
bowenszhu Aug 13, 2024
d5a4b3c
Fix `quick_*` functions in polyform
bowenszhu Aug 13, 2024
0136808
Fix `Sym` construction in subtyping test
bowenszhu Aug 13, 2024
97def56
Fix getting fields in div tests
bowenszhu Aug 13, 2024
5b5abc2
Fix `Term` construction in ordering test
bowenszhu Aug 13, 2024
25ba87e
Fix ordering for `Const`
bowenszhu Aug 15, 2024
c87e593
Fix `Term` construction in an ordering test
bowenszhu Aug 15, 2024
6849cf0
Fix polyform tests
bowenszhu Aug 16, 2024
5d13fa7
Fix `Term` construction in `ACRule`
bowenszhu Aug 16, 2024
0d9e0ac
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Aug 23, 2024
7d2fcfd
Fix `matcher` for `Const`
bowenszhu Aug 23, 2024
7697b81
Set `Term` arguments `eltype` to `Symbolic` to avoid wrapping `PolyForm`
bowenszhu Aug 24, 2024
ed167b1
Fix `Term` construction in `expand` test
bowenszhu Aug 24, 2024
538e896
Fix `*` for `Const`
bowenszhu Aug 25, 2024
b1b855b
Fix calling `term`
bowenszhu Aug 25, 2024
4ac8d4f
Fix "Equality matching" tests due to `Term` `argument` `eltype` change
bowenszhu Aug 25, 2024
d1140d9
Fix `Term` construction in "Numeric" testset
bowenszhu Aug 27, 2024
5c088dc
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Aug 28, 2024
a024aa1
Fix `is_literal_number` for `Const`
bowenszhu Aug 28, 2024
76d7b8e
Fix `*` for `Const`
bowenszhu Aug 28, 2024
d32622a
Fix `_Div` constructor call in `*`
bowenszhu Aug 28, 2024
0e9c845
Fix `literal_matcher` for `Const`
bowenszhu Aug 29, 2024
678507c
Fix `Term` construction in "boolean" tests
bowenszhu Aug 29, 2024
7ddad9c
Fix `!` for `Const`
bowenszhu Aug 29, 2024
ca4be53
Unwrap `Const` in `substitute`
bowenszhu Aug 29, 2024
8072eea
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Aug 30, 2024
768f1ce
Fix `toexpr` for `Const`
bowenszhu Aug 30, 2024
497a717
Fix `Term` construction in "Code" tests
bowenszhu Aug 30, 2024
835aab4
Revert keyword argument `T` back to `type` in `term` to avoid breaking
bowenszhu Aug 30, 2024
ad7a861
Fix `Expr` generation for `Const`
bowenszhu Sep 11, 2024
0f072b4
Fix `Sym` construction in CSE
bowenszhu Sep 11, 2024
d924da7
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Sep 13, 2024
36d28cc
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Sep 16, 2024
8870978
Fix `Sym` getting name
bowenszhu Sep 16, 2024
8d18d9d
Fix `length` for `BasicSymbolic`
bowenszhu Sep 16, 2024
85efc31
Fix `-(a)` for `Const`
bowenszhu Sep 16, 2024
c3b0585
Fix `show_mul` for `Const`
bowenszhu Sep 16, 2024
1660338
Fix `Term` construction in `gen_expr`
bowenszhu Sep 16, 2024
203afab
Define `get_name` function
bowenszhu Sep 18, 2024
206d21c
Define `get_coeff` function
bowenszhu Sep 18, 2024
53ca3b8
Define `get_dict` function
bowenszhu Sep 18, 2024
38e5f6a
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Sep 18, 2024
546b000
Fix `_occursin` for `Const`
bowenszhu Sep 19, 2024
e011b04
Define `get_num`
bowenszhu Sep 27, 2024
f044cec
Define `get_den`
bowenszhu Sep 27, 2024
8e73313
Define `get_base`
bowenszhu Sep 27, 2024
f7a77d6
Define `get_exp`
bowenszhu Sep 27, 2024
b0c5de1
Define `get_val`
bowenszhu Sep 27, 2024
0aa94dd
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
bowenszhu Sep 27, 2024
73805e2
Fix `eltype` in doctest
bowenszhu Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
Expronicon = "6b7a57c9-7cc1-4fdf-b7f5-e857abae3636"
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
Expand All @@ -25,7 +27,6 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Unityper = "a7c27f48-0311-42f6-a7f8-2c11e75eb415"

[weakdeps]
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
Expand All @@ -45,8 +46,10 @@ ConstructionBase = "1.5.7"
DataStructures = "0.18"
DocStringExtensions = "0.8, 0.9"
DynamicPolynomials = "0.5, 0.6"
Expronicon = "~0.8"
IfElse = "0.1"
LabelledArrays = "1.5"
MLStyle = "0.4"
MultivariatePolynomials = "0.5"
NaNMath = "0.3, 1"
ReverseDiff = "1"
Expand All @@ -56,7 +59,6 @@ StaticArrays = "0.12, 1.0"
SymbolicIndexingInterface = "0.3"
TermInterface = "2.0"
TimerOutputs = "0.5"
Unityper = "0.1.2"
julia = "1.3"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/manual/rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ If you want to match a variable number of subexpressions at once, you will need
@rule(+(~~xs) => ~~xs)(x + y + z)

# output
3-element view(::Vector{Any}, 1:3) with eltype Any:
3-element view(::Vector{SymbolicUtils.BasicSymbolic}, 1:3) with eltype SymbolicUtils.BasicSymbolic:
z
y
x
Expand Down
5 changes: 4 additions & 1 deletion src/SymbolicUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ using DocStringExtensions

export @syms, term, showraw, hasmetadata, getmetadata, setmetadata

using Unityper
using TermInterface
using DataStructures
using Setfield
Expand All @@ -23,6 +22,10 @@ import ArrayInterface

Base.@deprecate istree iscall
export istree, operation, arguments, sorted_arguments, similarterm, iscall

using Base: RefValue
using Expronicon.ADT: @adt
using MLStyle: @match
# Sym, Term,
# Add, Mul and Pow
include("types.jl")
Expand Down
10 changes: 6 additions & 4 deletions src/code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export toexpr, Assignment, (←), Let, Func, DestructuredArgs, LiteralExpr,

import ..SymbolicUtils
import ..SymbolicUtils.Rewriters
import SymbolicUtils: @matchable, BasicSymbolic, Sym, Term, iscall, operation, arguments, issym,
symtype, sorted_arguments, metadata, isterm, term, maketerm
import SymbolicUtils: @matchable, BasicSymbolic, _Sym, Term, iscall, operation, arguments, issym,
isconst, symtype, sorted_arguments, metadata, isterm, term, maketerm, get_val
import SymbolicIndexingInterface: symbolic_type, NotSymbolic

##== state management ==##
Expand Down Expand Up @@ -182,6 +182,8 @@ function toexpr(O, st)
if issym(O)
O = substitute_name(O, st)
return issym(O) ? nameof(O) : toexpr(O, st)
elseif isconst(O)
return toexpr(get_val(O), st)
end
O = substitute_name(O, st)

Expand Down Expand Up @@ -681,7 +683,7 @@ end

### Common subexprssion evaluation

@inline newsym(::Type{T}) where T = Sym{T}(gensym("cse"))
@inline newsym(::Type{T}) where T = _Sym(T, gensym("cse"))

function _cse!(mem, expr)
iscall(expr) || return expr
Expand Down Expand Up @@ -745,7 +747,7 @@ function cse_block!(assignments, counter, names, name, state, x)
if haskey(names, x)
return names[x]
else
sym = Sym{symtype(x)}(Symbol(name, counter[]))
sym = _Sym(symtype(x), Symbol(name, counter[]))
names[x] = sym
push!(assignments, sym ← x)
counter[] += 1
Expand Down
15 changes: 8 additions & 7 deletions src/inspect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ function AbstractTrees.nodevalue(x::Symbolic)
end

function AbstractTrees.nodevalue(x::BasicSymbolic)
str = if !iscall(x)
str = if issym(x)
string(exprtype(x), "(", x, ")")
elseif isconst(x)
string(get_val(x))
elseif isadd(x)
string(exprtype(x),
(scalar=x.coeff, coeffs=Tuple(k=>v for (k,v) in x.dict)))
string(exprtype(x),
(scalar = get_coeff(x), coeffs = Tuple(k => v for (k, v) in get_dict(x))))
elseif ismul(x)
string(exprtype(x),
(scalar=x.coeff, powers=Tuple(k=>v for (k,v) in x.dict)))
(scalar = get_coeff(x), powers = Tuple(k => v for (k, v) in get_dict(x))))
elseif isdiv(x) || ispow(x)
string(exprtype(x))
else
string(exprtype(x),"{", operation(x), "}")
string(exprtype(x), "{", operation(x), "}")
end

if inspect_metadata[] && !isnothing(metadata(x))
str *= string(" metadata=", Tuple(k=>v for (k, v) in metadata(x)))
str *= string(" metadata=", Tuple(k => v for (k, v) in metadata(x)))
end
Text(str)
end
Expand Down
18 changes: 16 additions & 2 deletions src/matchers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@
# 3. Callback: takes arguments Dictionary × Number of elements matched
#
function matcher(val::Any)
iscall(val) && return term_matcher(val)
if isconst(val)
slot = get_val(val)
return matcher(slot)
elseif iscall(val)
return term_matcher(val)
end
function literal_matcher(next, data, bindings)
islist(data) && isequal(car(data), val) ? next(bindings, 1) : nothing
if islist(data)
cd = car(data)
if isconst(cd)
cd = get_val(cd)
end
if isequal(cd, val)
return next(bindings, 1)
end
end
nothing
end
end

Expand Down
16 changes: 11 additions & 5 deletions src/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,30 @@ for (f, Domain) in [(==) => Number, (!=) => Number,
xor => Bool]
@eval begin
promote_symtype(::$(typeof(f)), ::Type{<:$Domain}, ::Type{<:$Domain}) = Bool
(::$(typeof(f)))(a::Symbolic{<:$Domain}, b::$Domain) = term($f, a, b, type=Bool)
(::$(typeof(f)))(a::Symbolic{<:$Domain}, b::Symbolic{<:$Domain}) = term($f, a, b, type=Bool)
(::$(typeof(f)))(a::$Domain, b::Symbolic{<:$Domain}) = term($f, a, b, type=Bool)
(::$(typeof(f)))(a::Symbolic{<:$Domain}, b::$Domain) = term($f, a, b; type = Bool)
(::$(typeof(f)))(a::Symbolic{<:$Domain}, b::Symbolic{<:$Domain}) = term($f, a, b; type = Bool)
(::$(typeof(f)))(a::$Domain, b::Symbolic{<:$Domain}) = term($f, a, b; type = Bool)
end
end

for f in [!, ~]
@eval begin
promote_symtype(::$(typeof(f)), ::Type{<:Bool}) = Bool
(::$(typeof(f)))(s::Symbolic{Bool}) = Term{Bool}(!, [s])
function (::$(typeof(f)))(s::Symbolic{Bool})
if isconst(s)
s = get_val(s)
return !s
end
_Term(Bool, !, [s])
end
end
end


# An ifelse node, ifelse is a built-in unfortunately
# So this uses IfElse.jl's ifelse that we imported
function ifelse(_if::Symbolic{Bool}, _then, _else)
Term{Union{symtype(_then), symtype(_else)}}(ifelse, Any[_if, _then, _else])
_Term(Union{symtype(_then), symtype(_else)}, ifelse, Any[_if, _then, _else])
end
promote_symtype(::typeof(ifelse), _, ::Type{T}, ::Type{S}) where {T,S} = Union{T, S}

Expand Down
15 changes: 13 additions & 2 deletions src/ordering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function get_degrees(expr)
elseif iscall(expr)
op = operation(expr)
args = sorted_arguments(expr)
if op == (^) && args[2] isa Number
if op == (^) && (args[2] isa Number || (isconst(args[2]) && get_val(args[2]) isa Number))
return map(get_degrees(args[1])) do (base, pow)
(base => pow * args[2])
end
Expand Down Expand Up @@ -79,12 +79,23 @@ function <ₑ(a::Tuple, b::Tuple)
end

function <ₑ(a::BasicSymbolic, b::BasicSymbolic)
aisconst = isconst(a)
if aisconst
a = get_val(a)
end
bisconst = isconst(b)
if bisconst
b = get_val(b)
end
if aisconst || bisconst
return a <ₑ b
end
da, db = get_degrees(a), get_degrees(b)
fw = monomial_lt(da, db)
bw = monomial_lt(db, da)
if fw === bw && !isequal(a, b)
if _arglen(a) == _arglen(b)
return (operation(a), arguments(a)...,) <ₑ (operation(b), arguments(b)...,)
return (operation(a), arguments(a)...) <ₑ (operation(b), arguments(b)...)
else
return _arglen(a) < _arglen(b)
end
Expand Down
Loading
Loading