@@ -64,8 +64,25 @@ struct Field end
64
64
struct UniqueFactorizationDomain end
65
65
const UFD = UniqueFactorizationDomain
66
66
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
+
67
84
algebraic_structure (:: Type{<:Integer} ) = UFD ()
68
- algebraic_structure (:: Type{<:AbstractPolynomialLike } ) = UFD ()
85
+ algebraic_structure (:: Type{<:_APL } ) = UFD ()
69
86
# `Rational`, `AbstractFloat`, JuMP expressions, etc... are fields
70
87
algebraic_structure (:: Type ) = Field ()
71
88
_field_absorb (:: UFD , :: UFD ) = UFD ()
@@ -430,7 +447,7 @@ function MA.promote_operation(
430
447
:: Type{P} ,
431
448
:: Type{Q} ,
432
449
) 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) )
434
451
# `promote_type(P, Q)` is needed for TypedPolynomials in case they use different variables
435
452
return polynomial_type (promote_type (P, Q), MA. promote_operation (- , U, U))
436
453
end
0 commit comments