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

Commit

Permalink
Rename to Module_free_ambient and fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu committed Jun 9, 2022
1 parent c4e89b9 commit 9f12e32
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 44 deletions.
63 changes: 23 additions & 40 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def is_FreeModule(M):
return isinstance(M, FreeModule_generic)


class FreeModule_base(Module):
class Module_free_ambient(Module):
"""
Base class for modules with elements represented by elements of a free
module.
Expand Down Expand Up @@ -810,10 +810,6 @@ class FreeModule_base(Module):
]
sage: N.degree()
2
sage: N.rank()
Traceback (most recent call last):
...
TypeError: no rank is defined for this module
"""
def __init__(self, base_ring, degree, sparse=False, category=None):
"""
Expand Down Expand Up @@ -898,22 +894,6 @@ def degree(self):
"""
return self.__degree

def rank(self):
"""
Raise an exception as no rank is defined for this module.
EXAMPLES::
sage: S.<x,y,z> = PolynomialRing(QQ)
sage: M = S**2
sage: N = M.submodule([vector([x - y, z]), vector([y * z, x * z])])
sage: N.rank()
Traceback (most recent call last):
...
TypeError: no rank is defined for this module
"""
raise TypeError('no rank is defined for this module')

def is_sparse(self):
"""
Return ``True`` if the underlying representation of this module uses
Expand Down Expand Up @@ -1083,7 +1063,7 @@ def zero(self):


@richcmp_method
class FreeModule_generic(FreeModule_base):
class FreeModule_generic(Module_free_ambient):
"""
Base class for all free modules.
Expand Down Expand Up @@ -1642,8 +1622,6 @@ def _eq(self, other):
sage: L._eq(IntegralLattice("U"))
True
"""
if self.rank() is None or other.rank() is None:
return False
if self.rank() != other.rank():
return False
if self.base_ring() != other.base_ring():
Expand Down Expand Up @@ -3129,8 +3107,8 @@ def span(self, gens, base_ring=None, check=True, already_echelonized=False):
if isinstance(gens, FreeModule_generic):
gens = gens.gens()
if base_ring is None or base_ring is self.base_ring():
from .submodule import Submodule_ambient_domain
return Submodule_ambient_domain(self.ambient_module(), gens,
from .submodule import Submodule_free_ambient
return Submodule_free_ambient(self.ambient_module(), gens,
check=check)
else:
try:
Expand Down Expand Up @@ -3166,7 +3144,7 @@ def submodule(self, gens, check=True):
[x - y z]
[ y*z x*z]
"""
if isinstance(gens, FreeModule_base):
if isinstance(gens, Module_free_ambient):
gens = gens.gens()
V = self.span(gens, check=check)
if check:
Expand Down Expand Up @@ -5086,7 +5064,7 @@ def __hash__(self):

def _coerce_map_from_(self, M):
"""
Return a coercion map from `M` to ``self``, or None.
Return a coercion map from `M` to ``self``, or ``None``.
TESTS:
Expand All @@ -5096,19 +5074,24 @@ def _coerce_map_from_(self, M):
sage: M = QQ^3 / [[1,2,3]]
sage: V = QQ^2
sage: V.coerce_map_from(M)
"""
if isinstance(M, FreeModule_base):
from sage.modules.quotient_module import FreeModule_ambient_field_quotient
if isinstance(M, FreeModule_ambient_field_quotient):
# No forgetful map.
return None
elif (self.base_ring().has_coerce_map_from(M.base_ring())
and self.degree() == M.degree()):
from sage.modules.submodule import Submodule_free_ambient
from sage.modules.quotient_module import FreeModule_ambient_field_quotient

if isinstance(M, FreeModule_ambient_field_quotient):
# No forgetful map.
return None
if isinstance(M, FreeModule_ambient):
if (self.base_ring().has_coerce_map_from(M.base_ring()) and
self.rank() == M.rank()):
# We could return M.hom(self.basis(), self), but the
# complexity of this is quadratic in space and time,
# since it constructs a matrix.
return True
elif isinstance(M, Submodule_free_ambient):
if (self.base_ring().has_coerce_map_from(M.base_ring()) and
self.rank() == M.degree()):
return True
return super(FreeModule_ambient, self)._coerce_map_from_(M)

def _dense_module(self):
Expand Down Expand Up @@ -5906,15 +5889,15 @@ def quotient_module(self, sub, check=True):
[x - y z]
[ y*z x*z]
"""
if isinstance(sub, FreeModule_base) and self.base_ring() != sub.base_ring():
if isinstance(sub, Module_free_ambient) and self.base_ring() != sub.base_ring():
raise ValueError("base rings must be the same")
if check and (not isinstance(sub, FreeModule_base) or not sub.is_submodule(self)):
if check and (not isinstance(sub, Module_free_ambient) or not sub.is_submodule(self)):
try:
sub = self.submodule(sub)
except (TypeError, ArithmeticError):
raise ArithmeticError("sub must be a subspace of self")
from . quotient_module import FreeModule_ambient_domain_quotient
return FreeModule_ambient_domain_quotient(self, sub)
from .quotient_module import QuotientModule_free_ambient
return QuotientModule_free_ambient(self, sub)

quotient = quotient_module

Expand Down
4 changes: 2 additions & 2 deletions src/sage/modules/quotient_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from sage.structure.richcmp import rich_to_bool, richcmp

from .free_module import (FreeModule_base,
from .free_module import (Module_free_ambient,
FreeModule_ambient,
FreeModule_ambient_field)

Expand All @@ -31,7 +31,7 @@
#
###############################################################################

class FreeModule_ambient_domain_quotient(FreeModule_base):
class QuotientModule_free_ambient(Module_free_ambient):
"""
Quotients of ambient free modules over a domain by a submodule.
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modules/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@

from sage.misc.cachefunc import cached_method
from sage.modules.free_module import (basis_seq,
FreeModule_base,
Module_free_ambient,
FreeModule_ambient_domain)

class Submodule_ambient_domain(FreeModule_base):
class Submodule_free_ambient(Module_free_ambient):
"""
Base class of submodules of ambient free modules over an integral domain.
Expand Down

0 comments on commit 9f12e32

Please sign in to comment.