77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
# Modulo Test
|
|
from noether.lib.groups import *
|
|
from noether.cli.ansi import *
|
|
from noether.cli._old import *
|
|
|
|
import sys
|
|
|
|
PROMPT = '[n]: '
|
|
|
|
'''
|
|
Pairwise orbit cumulative summation (cum orb)
|
|
'''
|
|
def orb_cum(cum, orb):
|
|
for i in range(len(cum)):
|
|
cum[i] += orb[i]
|
|
|
|
def main():
|
|
while True:
|
|
n = None
|
|
strlen_n = None
|
|
try:
|
|
uprint(PROMPT, color=Color.BLUE, end='')
|
|
n = input()
|
|
strlen_n = len(n)
|
|
n = int(n)
|
|
except ValueError:
|
|
continue
|
|
|
|
# calculate phi of n
|
|
phi = totient(n)
|
|
# determine if n is prime
|
|
prime = n - 1 == phi
|
|
if prime:
|
|
uprint('', moveup=1, end='', flush=False)
|
|
column = len(PROMPT) + strlen_n + 1
|
|
sys.stdout.write(f'\033[{column}C')
|
|
uprint('[PRIME]', color=Color.Magenta, style=Color.Bold, flush=True)
|
|
# primitive root values
|
|
proot_v = []
|
|
# primitive root count
|
|
proot_c = 0
|
|
# cumulative sum of primitive root orbits
|
|
prorb_cum = []
|
|
|
|
# find all invertible elements (skipped for now)
|
|
for a in range(n):
|
|
orb, ord, periodic = cyclic_subgrp(a, n)
|
|
# check if `a` is a primitive root
|
|
proot = (ord + 1 == n)
|
|
proot_c += proot
|
|
|
|
if proot:
|
|
proot_v.append(a)
|
|
if not prorb_cum:
|
|
prorb_cum = orb
|
|
else:
|
|
orb_cum(prorb_cum, orb)
|
|
print(a)
|
|
uprint('Cum Orb: ', end='', color=Color.Cyan)
|
|
uprint(f'{prorb_cum}', flush=True)
|
|
prorb_cum_mod = [x % n for x in prorb_cum]
|
|
uprint(f' {prorb_cum_mod}', flush=True)
|
|
|
|
uprint('Roots: ', end='', color=Color.Cyan)
|
|
uprint(proot_v, flush=True)
|
|
root_delta = [proot_v[i+1] - proot_v[i] for i in range(proot_c - 1)]
|
|
uprint('Delta: ', end='', color=Color.Cyan)
|
|
uprint(root_delta, flush=True)
|
|
|
|
uprint('Roots/Phi: ', end='', color=Color.Cyan)
|
|
uprint(f'{proot_c}/{phi}\n', flush=True)
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except (KeyboardInterrupt, EOFError):
|
|
pass
|