@@ -35,15 +35,19 @@ struct Field end
3535struct UniqueFactorizationDomain end
3636const UFD = UniqueFactorizationDomain
3737
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 ()
4246
4347# _div(a, b) assumes that b divides a
4448_div (:: Field , a, b) = a / b
4549_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)
4751_div (m1:: AbstractMonomialLike , m2:: AbstractMonomialLike ) = mapexponents (- , m1, m2)
4852function _div (t:: AbstractTerm , m:: AbstractMonomial )
4953 term (coefficient (t), _div (monomial (t), m))
@@ -77,7 +81,7 @@ Base.div(f::APL, g::Union{APL, AbstractVector{<:APL}}; kwargs...) = divrem(f, g;
7781Base. rem (f:: APL , g:: Union{APL, AbstractVector{<:APL}} ; kwargs... ) = divrem (f, g; kwargs... )[2 ]
7882
7983function 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)
8185end
8286
8387function _pseudo_divrem (:: Field , f:: APL , g:: APL , algo)
@@ -102,7 +106,7 @@ function _pseudo_divrem(::UFD, f::APL, g::APL, algo)
102106end
103107
104108function 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)
106110end
107111
108112function _pseudo_rem (:: Field , f:: APL , g:: APL , algo)
@@ -137,7 +141,7 @@ function MA.promote_operation(
137141 :: Type{P} ,
138142 :: Type{Q} ,
139143) 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)
141145end
142146function _promote_operation (
143147 :: Field ,
0 commit comments