@@ -35,15 +35,19 @@ struct Field end
35
35
struct UniqueFactorizationDomain end
36
36
const UFD = UniqueFactorizationDomain
37
37
38
- algebraic_structure (:: Type{<:Union{Rational, AbstractFloat}} , :: Type{<:Union{Rational, AbstractFloat}} ) = Field ()
39
- algebraic_structure (:: Type{<:Union{Rational, AbstractFloat}} , :: Type ) = Field ()
40
- algebraic_structure (:: Type , :: Type{<:Union{Rational, AbstractFloat}} ) = Field ()
41
- algebraic_structure (:: Type , :: Type ) = UFD ()
38
+ algebraic_structure (:: Type{<:Integer} ) = UFD ()
39
+ algebraic_structure (:: Type{<:AbstractPolynomialLike} ) = UFD ()
40
+ # `Rational`, `AbstractFloat`, JuMP expressions, etc... are fields
41
+ algebraic_structure (:: Type ) = Field ()
42
+ _field_absorb (:: UFD , :: UFD ) = UFD ()
43
+ _field_absorb (:: UFD , :: Field ) = Field ()
44
+ _field_absorb (:: Field , :: UFD ) = Field ()
45
+ _field_absorb (:: Field , :: Field ) = Field ()
42
46
43
47
# _div(a, b) assumes that b divides a
44
48
_div (:: Field , a, b) = a / b
45
49
_div (:: UFD , a, b) = div (a, b)
46
- _div (a, b) = _div (algebraic_structure (typeof (a), typeof (b)), a, b)
50
+ _div (a, b) = _div (algebraic_structure (promote_type ( typeof (a), typeof (b) )), a, b)
47
51
_div (m1:: AbstractMonomialLike , m2:: AbstractMonomialLike ) = mapexponents (- , m1, m2)
48
52
function _div (t:: AbstractTerm , m:: AbstractMonomial )
49
53
term (coefficient (t), _div (monomial (t), m))
@@ -77,7 +81,7 @@ Base.div(f::APL, g::Union{APL, AbstractVector{<:APL}}; kwargs...) = divrem(f, g;
77
81
Base. rem (f:: APL , g:: Union{APL, AbstractVector{<:APL}} ; kwargs... ) = divrem (f, g; kwargs... )[2 ]
78
82
79
83
function pseudo_divrem (f:: APL{S} , g:: APL{T} , algo) where {S,T}
80
- return _pseudo_divrem (algebraic_structure (S, T), f, g, algo)
84
+ return _pseudo_divrem (algebraic_structure (MA . promote_operation ( - , S, T) ), f, g, algo)
81
85
end
82
86
83
87
function _pseudo_divrem (:: Field , f:: APL , g:: APL , algo)
@@ -102,7 +106,7 @@ function _pseudo_divrem(::UFD, f::APL, g::APL, algo)
102
106
end
103
107
104
108
function pseudo_rem (f:: APL{S} , g:: APL{T} , algo) where {S,T}
105
- return _pseudo_rem (algebraic_structure (S, T), f, g, algo)
109
+ return _pseudo_rem (algebraic_structure (MA . promote_operation ( - , S, T) ), f, g, algo)
106
110
end
107
111
108
112
function _pseudo_rem (:: Field , f:: APL , g:: APL , algo)
@@ -137,7 +141,7 @@ function MA.promote_operation(
137
141
:: Type{P} ,
138
142
:: Type{Q} ,
139
143
) where {T,S,P<: APL{T} ,Q<: APL{S} }
140
- return _promote_operation (algebraic_structure (T , S), pseudo_rem, P, Q)
144
+ return _promote_operation (algebraic_structure (MA . promote_operation ( - , S, T) ), pseudo_rem, P, Q)
141
145
end
142
146
function _promote_operation (
143
147
:: Field ,
0 commit comments