Atelier des rouesLab FR
Objects/Documentation

reversible.py

The basis-state simulator checks the output bit of the coprimality test and restores its working registers to zero.

Download ↓
"""Reversible modular predicate, classical basis-state simulation (NOT physical gate circuit)."""
from math import gcd,prod
from random import Random
from motifs import primes

def predicate(n,x,L,flag=0):
 ps=primes(n);m=len(ps);assert 0<=x<1<<L
 c=0;updates=0;inc=0
 def residue(p):
  nonlocal updates
  r=0
  for i in range(L-1,-1,-1):r=(2*r+((x>>i)&1))%p;updates+=1
  return r
 def clean(p,r):
  nonlocal updates
  inv=pow(2,-1,p)

Read in context

Comments

Comments from both language editions appear here.

The discussion is open for reading. I’ll enable submissions once spam protection is configured.