Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
WIP - Change design
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jan 22, 2023
1 parent 960506b commit 19255e8
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 110 deletions.
5 changes: 5 additions & 0 deletions src/sage/rings/polynomial/commutative_polynomial.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from sage.structure.element cimport CommutativeAlgebraElement


cdef class CommutativePolynomial(CommutativeAlgebraElement):
pass
10 changes: 10 additions & 0 deletions src/sage/rings/polynomial/commutative_polynomial.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cdef class CommutativePolynomial(CommutativeAlgebraElement):
r"""
Abstract base class for commutative polynomials in any number of variables
It is a common base for :class:`~sage.rings.polynomial.polynomial_element.Polynomial`,
:class:`~sage.rings.polynomial.multi_polynomial.MPolynomial`, and
:class:`~sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial`.
"""

pass
6 changes: 4 additions & 2 deletions src/sage/rings/polynomial/infinite_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@
from sage.structure.richcmp import richcmp
from sage.misc.cachefunc import cached_method
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
from sage.structure.element import RingElement, MPolynomial, InfinitePolynomial as InfinitePolynomial_base
from sage.structure.element import RingElement
from .commutative_polynomial import CommutativePolynomial
from .multi_polynomial import MPolynomial
import copy


class InfinitePolynomial(InfinitePolynomial_base, metaclass=InheritComparisonClasscallMetaclass):
class InfinitePolynomial(CommutativePolynomial, metaclass=InheritComparisonClasscallMetaclass):
"""
Create an element of a Polynomial Ring with a Countably Infinite Number of Variables.
Expand Down
8 changes: 6 additions & 2 deletions src/sage/rings/polynomial/multi_polynomial.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from sage.structure.element cimport MPolynomial as MPolynomial_base
from .commutative_polynomial cimport CommutativePolynomial

cdef class MPolynomial(MPolynomial_base):

cdef class MPolynomial(CommutativePolynomial):
cdef long _hash_c(self) except -1
cpdef _mod_(self, right)
cpdef dict _mpoly_dict_recursive(self, tuple vars=*, base_ring=*)


cdef class MPolynomial_libsingular(MPolynomial):
pass
25 changes: 24 additions & 1 deletion src/sage/rings/polynomial/multi_polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ from sage.rings.real_mpfr import RealField_class,RealField
from sage.rings.polynomial.polydict cimport ETuple
from sage.rings.polynomial.polynomial_element cimport Polynomial

cdef class MPolynomial(MPolynomial_base):
cdef class MPolynomial(CommutativePolynomial):

####################
# Some standard conversions
Expand Down Expand Up @@ -2623,3 +2623,26 @@ cdef remove_from_tuple(e, int ind):
return w[0]
else:
return tuple(w)


cdef class MPolynomial_libsingular(MPolynomial):
r"""
Abstract base class for :class:`~sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular`
This class is defined for the purpose of :func:`isinstance` tests. It should not be
instantiated.
EXAMPLES::
sage: R1.<x> = QQ[]
sage: isinstance(x, sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular)
False
sage: R2.<y,z> = QQ[]
sage: isinstance(y, sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular)
True
By design, there is a unique direct subclass::
sage: len(sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular.__subclasses__()) <= 1
True
"""
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pxd
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from sage.libs.singular.decl cimport poly, ring

from sage.rings.polynomial.multi_polynomial cimport MPolynomial
from sage.rings.polynomial.multi_polynomial cimport MPolynomial_libsingular as MPolynomial_libsingular_base
from sage.rings.polynomial.multi_polynomial_ring_base cimport MPolynomialRing_base

cdef class MPolynomialRing_libsingular

cdef class MPolynomial_libsingular(MPolynomial):
cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
cdef poly *_poly
cdef ring *_parent_ring
cpdef _add_(self, other)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ def unpickle_MPolynomialRing_libsingular(base_ring, names, term_order):
return _multi_variate(base_ring, tuple(names), None, term_order, None)


cdef class MPolynomial_libsingular(MPolynomial):
cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
"""
A multivariate polynomial implemented using libSINGULAR.
"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/polynomial_element.pxd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from sage.structure.element import Element
from sage.structure.element cimport Element, CommutativeAlgebraElement, ModuleElement
from sage.structure.element cimport Polynomial as Polynomial_base
from sage.structure.parent cimport Parent
from sage.rings.integer cimport Integer
from .commutative_polynomial cimport CommutativePolynomial
from .polynomial_compiled cimport CompiledPolynomialFunction


cdef class Polynomial(Polynomial_base):
cdef class Polynomial(CommutativePolynomial):
cdef Polynomial _new_generic(self, list coeffs)
cdef char _is_gen
cdef CompiledPolynomialFunction _compiled
Expand Down
9 changes: 0 additions & 9 deletions src/sage/structure/element.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,6 @@ cdef class CommutativeAlgebraElement(CommutativeRingElement):
cdef class Expression(CommutativeRingElement):
pass

cdef class CommutativePolynomial(CommutativeAlgebraElement):
pass

cdef class Polynomial(CommutativePolynomial):
pass

cdef class MPolynomial(CommutativePolynomial):
pass

cdef class InfinityElement(RingElement):
pass

Expand Down
91 changes: 0 additions & 91 deletions src/sage/structure/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ abstract base classes.
EuclideanDomainElement
FieldElement
CommutativeAlgebraElement
CommutativePolynomial
Polynomial
MPolynomial
InfinitePolynomial
Expression
AlgebraElement
Matrix
Expand Down Expand Up @@ -4310,93 +4306,6 @@ cdef class CommutativeAlgebraElement(CommutativeRingElement):

##############################################

cdef class CommutativePolynomial(CommutativeAlgebraElement):
r"""
Abstract base class for commutative polynomials in any number of variables
It is a common base for :class:`Polynomial`, :class:`MPolynomial`, and
:class:`InfinitePolynomial`.
"""

pass

##############################################

cdef class Polynomial(CommutativePolynomial):
r"""
Abstract base class for :class:`~sage.rings.polynomial.polynomial_element.Polynomial`
This class is defined for the purpose of :func:`isinstance` tests. It should not be
instantiated.
EXAMPLES::
sage: R1.<x> = QQ[]
sage: isinstance(x, sage.structure.element.Polynomial)
True
sage: R2.<y,z> = QQ[]
sage: isinstance(y, sage.structure.element.Polynomial)
False
By design, there is a unique direct subclass::
sage: len(sage.structure.element.Polynomial.__subclasses__()) <= 1
True
"""

pass

##############################################

cdef class MPolynomial(CommutativePolynomial):
r"""
Abstract base class for :class:`~sage.rings.polynomial.multi_polynomial.MPolynomial`
This class is defined for the purpose of :func:`isinstance` tests. It should not be
instantiated.
EXAMPLES::
sage: R1.<x> = QQ[]
sage: isinstance(x, sage.structure.element.MPolynomial)
False
sage: R2.<y,z> = QQ[]
sage: isinstance(y, sage.structure.element.MPolynomial)
True
By design, there is a unique direct subclass::
sage: len(sage.structure.element.MPolynomial.__subclasses__()) <= 1
True
"""

pass

##############################################

cdef class InfinitePolynomial(CommutativePolynomial):
r"""
Abstract base class for :class:`~sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial`
This class is defined for the purpose of :func:`isinstance` tests. It should not be
instantiated.
EXAMPLES::
sage: X.<x> = InfinitePolynomialRing(QQ)
sage: isinstance(x[0], sage.structure.element.InfinitePolynomial)
True
By design, there is a unique direct subclass::
sage: len(sage.structure.element.InfinitePolynomial.__subclasses__()) <= 1
True
"""

pass

##############################################

def is_InfinityElement(x):
"""
Return ``True`` if x is of type InfinityElement.
Expand Down

0 comments on commit 19255e8

Please sign in to comment.