commit state before changing what noether considers primitive roots
This commit is contained in:
parent
a168a728ce
commit
33bcffdc69
11 changed files with 441 additions and 36 deletions
76
py/mquiet.py
Normal file
76
py/mquiet.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# Modulo Test
|
||||
from prbraid.math import *
|
||||
from prbraid.color 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 = orbit(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
|
||||
Loading…
Add table
Add a link
Reference in a new issue