Skip to content

Commit 2014516

Browse files
committed
avoid using Field in free quadratic modules
1 parent 665a3fa commit 2014516

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

src/sage/modules/free_quadratic_module.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@
6868
import weakref
6969

7070
from sage.categories.commutative_rings import CommutativeRings
71+
from sage.categories.fields import Fields
7172
from sage.categories.principal_ideal_domains import PrincipalIdealDomains
7273
from sage.categories.integral_domains import IntegralDomains
7374
from sage.modules import free_module
74-
from sage.rings.ring import Field
7575
import sage.matrix.matrix_space
7676
import sage.misc.latex as latex
7777

@@ -168,7 +168,7 @@ def FreeQuadraticModule(base_ring, rank, inner_product_matrix,
168168
# elif not sparse and isinstance(base_ring,sage.rings.complex_double.ComplexDoubleField_class):
169169
# M = ComplexDoubleQuadraticSpace_class(rank, inner_product_matrix=inner_product_matrix, sparse=False)
170170

171-
elif base_ring.is_field():
171+
if base_ring in Fields():
172172
M = FreeQuadraticModule_ambient_field(
173173
base_ring, rank, sparse=sparse, inner_product_matrix=inner_product_matrix)
174174

@@ -213,7 +213,7 @@ def QuadraticSpace(K, dimension, inner_product_matrix, sparse=False):
213213
...
214214
TypeError: argument K (= Integer Ring) must be a field
215215
"""
216-
if not K.is_field():
216+
if K not in Fields():
217217
raise TypeError(f"argument K (= {K}) must be a field")
218218
if sparse not in (True, False):
219219
raise TypeError("Argument sparse (= %s) must be a boolean." % sparse)
@@ -307,7 +307,8 @@ class FreeQuadraticModule_generic(free_module.FreeModule_generic):
307307
sage: M1 == M2
308308
False
309309
"""
310-
def __init__(self, base_ring, rank, degree, inner_product_matrix, sparse=False):
310+
def __init__(self, base_ring, rank, degree,
311+
inner_product_matrix, sparse=False) -> None:
311312
"""
312313
Create the free module of given rank over the given ``base_ring``.
313314
@@ -589,7 +590,8 @@ class FreeQuadraticModule_generic_pid(free_module.FreeModule_generic_pid,
589590
"""
590591
Class of all free modules over a PID.
591592
"""
592-
def __init__(self, base_ring, rank, degree, inner_product_matrix, sparse=False):
593+
def __init__(self, base_ring, rank, degree,
594+
inner_product_matrix, sparse=False) -> None:
593595
"""
594596
Create a free module over a PID.
595597
@@ -696,7 +698,8 @@ class FreeQuadraticModule_generic_field(free_module.FreeModule_generic_field,
696698
"""
697699
Base class for all free modules over fields.
698700
"""
699-
def __init__(self, base_field, dimension, degree, inner_product_matrix, sparse=False):
701+
def __init__(self, base_field, dimension, degree,
702+
inner_product_matrix, sparse=False) -> None:
700703
"""
701704
Create a vector space over a field.
702705
@@ -718,10 +721,11 @@ def __init__(self, base_field, dimension, degree, inner_product_matrix, sparse=F
718721
[0 0 0 0 0 1 0]
719722
[0 0 0 0 0 0 1]
720723
"""
721-
if not isinstance(base_field, Field):
722-
raise TypeError("the base_field (=%s) must be a field" % base_field)
724+
if base_field not in Fields():
725+
raise TypeError(f"the base_field (={base_field}) must be a field")
723726
free_module.FreeModule_generic_field.__init__(
724-
self, base_field=base_field, dimension=dimension, degree=degree, sparse=sparse)
727+
self, base_field=base_field, dimension=dimension,
728+
degree=degree, sparse=sparse)
725729
self._inner_product_matrix = inner_product_matrix
726730

727731
def span(self, gens, check=True, already_echelonized=False):
@@ -820,7 +824,8 @@ class FreeQuadraticModule_ambient(free_module.FreeModule_ambient,
820824
"""
821825
Ambient free module over a commutative ring.
822826
"""
823-
def __init__(self, base_ring, rank, inner_product_matrix, sparse=False):
827+
def __init__(self, base_ring, rank,
828+
inner_product_matrix, sparse=False) -> None:
824829
"""
825830
The free module of given rank over the given ``base_ring``.
826831
@@ -838,7 +843,7 @@ def __init__(self, base_ring, rank, inner_product_matrix, sparse=False):
838843
free_module.FreeModule_ambient.__init__(self, base_ring=base_ring, rank=rank, sparse=sparse)
839844
self._inner_product_matrix = inner_product_matrix
840845

841-
def _repr_(self):
846+
def _repr_(self) -> str:
842847
"""
843848
The printing representation of ``self``.
844849
@@ -872,7 +877,7 @@ def _repr_(self):
872877
return "Ambient free quadratic module of rank %s over %s\n" % (self.rank(), self.base_ring()) + \
873878
"Inner product matrix:\n%s" % self.inner_product_matrix()
874879

875-
def _latex_(self):
880+
def _latex_(self) -> str:
876881
r"""
877882
Return a latex representation of this ambient free quadratic module.
878883
@@ -944,7 +949,8 @@ class FreeQuadraticModule_ambient_domain(free_module.FreeModule_ambient_domain,
944949
"""
945950
Ambient free quadratic module over an integral domain.
946951
"""
947-
def __init__(self, base_ring, rank, inner_product_matrix, sparse=False):
952+
def __init__(self, base_ring, rank,
953+
inner_product_matrix, sparse=False) -> None:
948954
"""
949955
EXAMPLES::
950956
@@ -955,7 +961,7 @@ def __init__(self, base_ring, rank, inner_product_matrix, sparse=False):
955961
free_module.FreeModule_ambient.__init__(self, base_ring=base_ring, rank=rank, sparse=sparse)
956962
self._inner_product_matrix = inner_product_matrix
957963

958-
def _repr_(self):
964+
def _repr_(self) -> str:
959965
"""
960966
The printing representation of ``self``.
961967
@@ -1035,7 +1041,8 @@ class FreeQuadraticModule_ambient_pid(free_module.FreeModule_ambient_pid,
10351041
"""
10361042
Ambient free quadratic module over a principal ideal domain.
10371043
"""
1038-
def __init__(self, base_ring, rank, inner_product_matrix, sparse=False):
1044+
def __init__(self, base_ring, rank,
1045+
inner_product_matrix, sparse=False) -> None:
10391046
"""
10401047
Create the ambient free module of given rank over the given
10411048
principal ideal domain.
@@ -1064,7 +1071,7 @@ def __init__(self, base_ring, rank, inner_product_matrix, sparse=False):
10641071
free_module.FreeModule_ambient_pid.__init__(self, base_ring=base_ring, rank=rank, sparse=sparse)
10651072
self._inner_product_matrix = inner_product_matrix
10661073

1067-
def _repr_(self):
1074+
def _repr_(self) -> str:
10681075
"""
10691076
The printing representation of ``self``.
10701077
@@ -1120,7 +1127,8 @@ class FreeQuadraticModule_ambient_field(free_module.FreeModule_ambient_field,
11201127
FreeQuadraticModule_generic_field,
11211128
FreeQuadraticModule_ambient_pid):
11221129

1123-
def __init__(self, base_field, dimension, inner_product_matrix, sparse=False):
1130+
def __init__(self, base_field, dimension,
1131+
inner_product_matrix, sparse=False) -> None:
11241132
"""
11251133
Create the ambient vector space of given dimension over the given field.
11261134
@@ -1158,7 +1166,7 @@ def __init__(self, base_field, dimension, inner_product_matrix, sparse=False):
11581166
self, base_field=base_field, dimension=dimension, sparse=sparse)
11591167
self._inner_product_matrix = inner_product_matrix
11601168

1161-
def _repr_(self):
1169+
def _repr_(self) -> str:
11621170
"""
11631171
The printing representation of ``self``.
11641172
@@ -1239,7 +1247,7 @@ class FreeQuadraticModule_submodule_with_basis_pid(free_module.FreeModule_submod
12391247
"""
12401248
def __init__(self, ambient, basis, inner_product_matrix,
12411249
check=True, echelonize=False, echelonized_basis=None,
1242-
already_echelonized=False):
1250+
already_echelonized=False) -> None:
12431251
"""
12441252
Create a free module with basis over a PID.
12451253
@@ -1282,7 +1290,7 @@ def __init__(self, ambient, basis, inner_product_matrix,
12821290
echelonize=echelonize, echelonized_basis=echelonized_basis, already_echelonized=already_echelonized)
12831291
self._inner_product_matrix = inner_product_matrix
12841292

1285-
def _repr_(self):
1293+
def _repr_(self) -> str:
12861294
"""
12871295
The printing representation of ``self``.
12881296
@@ -1326,7 +1334,7 @@ def _repr_(self):
13261334
"Inner product matrix:\n%r" % self.inner_product_matrix()
13271335
return s
13281336

1329-
def _latex_(self):
1337+
def _latex_(self) -> str:
13301338
r"""
13311339
Return latex representation of this free module.
13321340
@@ -1410,7 +1418,9 @@ class FreeQuadraticModule_submodule_pid(free_module.FreeModule_submodule_pid,
14101418
sage: loads(v.dumps()) == v
14111419
True
14121420
"""
1413-
def __init__(self, ambient, gens, inner_product_matrix, check=True, already_echelonized=False):
1421+
def __init__(self, ambient, gens,
1422+
inner_product_matrix, check=True,
1423+
already_echelonized=False) -> None:
14141424
"""
14151425
Create an embedded free module over a PID.
14161426
@@ -1428,7 +1438,7 @@ def __init__(self, ambient, gens, inner_product_matrix, check=True, already_eche
14281438
self, ambient=ambient, gens=gens, check=check, already_echelonized=already_echelonized)
14291439
self._inner_product_matrix = inner_product_matrix
14301440

1431-
def _repr_(self):
1441+
def _repr_(self) -> str:
14321442
"""
14331443
The printing representation of ``self``.
14341444
@@ -1507,7 +1517,8 @@ class FreeQuadraticModule_submodule_with_basis_field(free_module.FreeModule_subm
15071517
True
15081518
"""
15091519
def __init__(self, ambient, basis, inner_product_matrix,
1510-
check=True, echelonize=False, echelonized_basis=None, already_echelonized=False):
1520+
check=True, echelonize=False, echelonized_basis=None,
1521+
already_echelonized=False) -> None:
15111522
"""
15121523
Create a vector space with given basis.
15131524
@@ -1536,7 +1547,7 @@ def __init__(self, ambient, basis, inner_product_matrix,
15361547
echelonize=echelonize, echelonized_basis=echelonized_basis, already_echelonized=already_echelonized)
15371548
self._inner_product_matrix = inner_product_matrix
15381549

1539-
def _repr_(self):
1550+
def _repr_(self) -> str:
15401551
"""
15411552
The printing representation of ``self``.
15421553
@@ -1627,7 +1638,8 @@ class FreeQuadraticModule_submodule_field(free_module.FreeModule_submodule_field
16271638
sage: vector(QQ, W.coordinates(v)) * W.basis_matrix()
16281639
(1, 5, 9)
16291640
"""
1630-
def __init__(self, ambient, gens, inner_product_matrix, check=True, already_echelonized=False):
1641+
def __init__(self, ambient, gens, inner_product_matrix, check=True,
1642+
already_echelonized=False) -> None:
16311643
"""
16321644
Create an embedded vector subspace with echelonized basis.
16331645
@@ -1645,7 +1657,7 @@ def __init__(self, ambient, gens, inner_product_matrix, check=True, already_eche
16451657
self, ambient=ambient, gens=gens, check=check, already_echelonized=already_echelonized)
16461658
self._inner_product_matrix = inner_product_matrix
16471659

1648-
def _repr_(self):
1660+
def _repr_(self) -> str:
16491661
"""
16501662
The default printing representation of ``self``.
16511663

0 commit comments

Comments
 (0)