@@ -64,8 +64,25 @@ struct Field end
6464struct UniqueFactorizationDomain end
6565const UFD = UniqueFactorizationDomain
6666
67+ """
68+ promote_to_field(::Type{T})
69+
70+ Promote the type `T` to a field. For instance, `promote_to_field(T)` returns
71+ `Rational{T}` if `T` is an integer and `promote_to_field(T)` returns `RationalPoly{T}`
72+ if `T` is a polynomial.
73+ """
74+ function promote_to_field end
75+
76+ function promote_to_field (:: Type{T} ) where {T<: Integer }
77+ return Rational{T}
78+ end
79+ function promote_to_field (:: Type{T} ) where {T<: _APL }
80+ return RationalPoly{T,T}
81+ end
82+ promote_to_field (:: Type{T} ) where {T} = T
83+
6784algebraic_structure (:: Type{<:Integer} ) = UFD ()
68- algebraic_structure (:: Type{<:AbstractPolynomialLike } ) = UFD ()
85+ algebraic_structure (:: Type{<:_APL } ) = UFD ()
6986# `Rational`, `AbstractFloat`, JuMP expressions, etc... are fields
7087algebraic_structure (:: Type ) = Field ()
7188_field_absorb (:: UFD , :: UFD ) = UFD ()
@@ -430,7 +447,7 @@ function MA.promote_operation(
430447 :: Type{P} ,
431448 :: Type{Q} ,
432449) where {T,S,P<: _APL{T} ,Q<: _APL{S} }
433- U = MA. promote_operation (/ , T, S )
450+ U = MA. promote_operation (/ , promote_to_field (T), promote_to_field (S) )
434451 # `promote_type(P, Q)` is needed for TypedPolynomials in case they use different variables
435452 return polynomial_type (promote_type (P, Q), MA. promote_operation (- , U, U))
436453end
0 commit comments