@@ -18,6 +18,8 @@ elem_type(::Type{MPolyRing{T}}) where T <: RingElement = MPoly{T}
1818
1919base_ring (R:: MPolyRing{T} ) where T <: RingElement = R. base_ring:: parent_type (T)
2020
21+ is_trivial (R:: MPolyRing ) = R. istrivial
22+
2123@doc raw """
2224 symbols(a::MPolyRing)
2325
@@ -36,20 +38,23 @@ number_of_variables(a::MPolyRing) = a.num_vars
3638number_of_generators (a:: MPolyRing ) = a. num_vars
3739
3840function gen (a:: MPolyRing{T} , i:: Int , :: Val{:lex} ) where {T <: RingElement }
41+ is_trivial (a) && return zero (a)
3942 n = nvars (a)
4043 @boundscheck 1 <= i <= n || throw (ArgumentError (" variable index out of range" ))
4144 return a ([one (base_ring (a))], reshape (UInt[UInt (j == n - i + 1 )
4245 for j = 1 : n], n, 1 ))
4346end
4447
4548function gen (a:: MPolyRing{T} , i:: Int , :: Val{:deglex} ) where {T <: RingElement }
49+ is_trivial (a) && return zero (a)
4650 n = nvars (a)
4751 @boundscheck 1 <= i <= n || throw (ArgumentError (" variable index out of range" ))
4852 return a ([one (base_ring (a))], reshape (UInt[(UInt (j == n - i + 1 )
4953 for j in 1 : n). .. , UInt (1 )], n + 1 , 1 ))
5054end
5155
5256function gen (a:: MPolyRing{T} , i:: Int , :: Val{:degrevlex} ) where {T <: RingElement }
57+ is_trivial (a) && return zero (a)
5358 n = nvars (a)
5459 @boundscheck 1 <= i <= n || throw (ArgumentError (" variable index out of range" ))
5560 return a ([one (base_ring (a))], reshape (UInt[(UInt (j == i)
@@ -838,7 +843,7 @@ Return the number of terms of the polynomial.
838843"""
839844length (x:: MPoly ) = x. length
840845
841- isone (x:: MPoly ) = x . length == 1 && monomial_iszero (x. exps, 1 , size (x. exps, 1 )) && is_one (x. coeffs[1 ])
846+ isone (x:: MPoly ) = is_trivial ( parent (x)) || (x . length == 1 && monomial_iszero (x. exps, 1 , size (x. exps, 1 )) && is_one (x. coeffs[1 ]) )
842847
843848is_constant (x:: MPoly ) = x. length == 0 || (x. length == 1 && monomial_iszero (x. exps, 1 , size (x. exps, 1 )))
844849
@@ -3896,6 +3901,7 @@ function zero!(a::MPoly{T}) where {T <: RingElement}
38963901end
38973902
38983903function one! (a:: MPoly{T} ) where {T <: RingElement }
3904+ is_trivial (parent (a)) && return zero! (a)
38993905 a. length = 1
39003906 fit! (a, 1 )
39013907 a. coeffs[1 ] = one (base_ring (a))
0 commit comments