Project is now named Celeste
This commit is contained in:
parent
87917f9526
commit
269092fb53
45 changed files with 1507 additions and 12 deletions
37
celeste/math/groups.py
Normal file
37
celeste/math/groups.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
'''
|
||||
This library exists to isolate all math functions
|
||||
related to groups and their representations.
|
||||
'''
|
||||
|
||||
from math import gcd
|
||||
|
||||
'''
|
||||
Returns the multiplicative cyclic subgroup
|
||||
generated by an element g modulo m.
|
||||
Returns the cyclic subgroup as a list[int],
|
||||
the order of that subgroup, and a boolean
|
||||
indicating whether g is infinitely repeating
|
||||
with period == ord<g> (or otherwise if it
|
||||
terminates with g**ord<g> == 0).
|
||||
'''
|
||||
def cyclic_subgrp(g: int,
|
||||
m: int,
|
||||
ignore_zero: bool = True) -> tuple[list[int], int, bool]:
|
||||
G = []
|
||||
order = 0
|
||||
periodic = True
|
||||
a = 1 # start at identity
|
||||
for _ in range(m):
|
||||
a = (a * g) % m
|
||||
if a == 0:
|
||||
if not ignore_zero:
|
||||
G.append(a)
|
||||
order += 1
|
||||
periodic = False
|
||||
break
|
||||
# check if we've reached something periodic
|
||||
elif a in G[:1]:
|
||||
break
|
||||
G.append(a)
|
||||
order += 1
|
||||
return G, order, periodic
|
||||
Loading…
Add table
Add a link
Reference in a new issue