Skip to content

Commit

Permalink
gh-36881: Fix cardinality of special linear group
Browse files Browse the repository at this point in the history
    
- Fixed infinite recursion of the cardinality and order functions
- Improved pycodestyle
- Add more doctests to cover all cases

This patch fixes #36876 and fixes #35490. In this PR, I have implemented
a method to fix the
answer given by cardinality function for finite special linear groups
(before it was going into infinite recursion). This also fixes the
answer given by is_finite()
function for finite special linear groups.
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- #12345: short description why this is a dependency
- #34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
None
    
URL: #36881
Reported by: Ruchit Jagodara
Reviewer(s): Dima Pasechnik, Martin Rubey, Ruchit Jagodara
  • Loading branch information
Release Manager committed Feb 11, 2024
2 parents bbe70e7 + baa3b50 commit 6ad8584
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/sage/categories/finite_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ def cardinality(self):
sage: G.cardinality()
384
"""
try:
o = self.order
except AttributeError:
return self._cardinality_from_iterator()
else:
return o()
if hasattr(self, 'order'):
return self.order()
return self._cardinality_from_iterator()

def some_elements(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/groups/libgap_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class ParentLibGAP(SageObject):

def minimal_normal_subgroups(self):
"""
Return the nontrivial minimal normal subgroups ``self``.
Return the nontrivial minimal normal subgroups of ``self``.
EXAMPLES::
Expand Down
48 changes: 48 additions & 0 deletions src/sage/groups/matrix_gps/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
from sage.groups.matrix_gps.named_group import (
normalize_args_vectorspace, NamedMatrixGroup_generic)
from sage.misc.latex import latex
from sage.misc.misc_c import prod
from sage.rings.infinity import Infinity


###############################################################################
Expand Down Expand Up @@ -307,3 +309,49 @@ def _check_matrix(self, x, *args):
else:
if x.determinant() == 0:
raise TypeError('matrix must non-zero determinant')

def order(self):
"""
Return the order of ``self``.
EXAMPLES::
sage: G = SL(3, GF(5))
sage: G.order()
372000
TESTS:
Check if :trac:`36876` is fixed::
sage: SL(1, QQ).order()
1
sage: SL(2, ZZ).cardinality()
+Infinity
Check if :trac:`35490` is fixed::
sage: q = 7
sage: FqT.<T> = GF(q)[]
sage: N = T^2+1
sage: FqTN = QuotientRing(FqT, N*FqT)
sage: S = SL(2, FqTN)
sage: S.is_finite()
True
sage: S.order()
117600
"""
n = self.degree()

if self.base_ring().is_finite():
q = self.base_ring().order()
ord = prod(q**n - q**i for i in range(n))
if self._special:
return ord / (q-1)
return ord

if self._special and n == 1:
return 1
return Infinity

cardinality = order

0 comments on commit 6ad8584

Please sign in to comment.