Atelier des rouesLab FR
Objects/Documentation

temoin_xii.py

Reproducible material from the experimental kit.

Download ↓
"""Curated XII routines and a separate small exact oracle. Python 3.10+."""
import json
from math import isqrt


def mcx(controls,target,anc):
    controls=list(controls);neg=[i for i,v in controls if not v];c=[i for i,v in controls];m=len(c)
    gates=[(0,1<<i) for i in neg]
    def gate(xs,t):return (sum(1<<i for i in xs),1<<t)
    if m<=2:gates.append(gate(c,target))
    else:
        assert len(anc)>=m-2
        chain=[gate(c[:2],anc[0])]+[gate([anc[j-1],c[j+1]],anc[j]) for j in range(1,m-2)]
        gates+=chain+[gate([anc[m-3],c[-1]],target)]+chain[::-1]
    gates.extend((0,1<<i) for i in neg[::-1]);return gates

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.