# Path: libcirc/compile/compilecirc.py
# def standardGate(line, listMode=False, lineMode=False):
#     if line == "main":
#         if listMode or lineMode:
#             raise ValueError("Can't bring 'main' into list form.")
#         return "main"
# 
#     if not lineMode:
#         toRemove = ["_", "M"]
#         for r in toRemove:
#             line = line.replace(r, "")
# 
#     elems = []
#     for letter in line:
#         if not letter.islower(): elems.append(letter)
#         else: elems = elems[:-1] + [elems[-1] + letter]
# 
#     if lineMode: return elems
#     if listMode: return sorted(elems)
#     return "".join(sorted(elems))


from libcirc.compile.compilecirc import standardGate
import numpy as np
        # printProjector((phases, xs, zs))
        # test = input()
        # print("")

    # printProjector((phases, xs, zs))
    # raise ValueError("hi")
    return phases, xs, zs


# turn list of generators to complete list of elements
# relies on fact that generators commute!
def expandGenerators(proj):
    (phases, xs, zs) = proj
    newPhases, newXs, newZs = [], [], []
    k = len(phases)
    if (k == 0):
        return ([], [], [])

    n = len(xs[0])

    def ph(xs1, zs1, xs2, zs2):
        out = 0
        for i in range(n):
            tup = (xs1[i], zs1[i], xs2[i], zs2[i])
            if tup == (0, 1, 1, 0): out += 2  # Z*X
            if tup == (0, 1, 1, 1): out += 2  # Z*XZ
            if tup == (1, 1, 1, 0): out += 2  # XZ*X
            if tup == (1, 1, 1, 1): out += 2  # XZ*XZ
        return out


# Path: libcirc/compile/compilecirc.py
# def standardGate(line, listMode=False, lineMode=False):
#     if line == "main":
#         if listMode or lineMode:
#             raise ValueError("Can't bring 'main' into list form.")
#         return "main"
# 
#     if not lineMode:
#         toRemove = ["_", "M"]
#         for r in toRemove:
#             line = line.replace(r, "")
# 
#     elems = []
#     for letter in line:
#         if not letter.islower(): elems.append(letter)
#         else: elems = elems[:-1] + [elems[-1] + letter]
# 
#     if lineMode: return elems
#     if listMode: return sorted(elems)
#     return "".join(sorted(elems))


# Path: libcirc/compile/gadgetize.py
from libcirc.compile.compilecirc import standardGate
import numpy as np

        # printProjector((phases, xs, zs))
        # test = input()
        # print("")

    # printProjector((phases, xs, zs))
    # raise ValueError("hi")
    return phases, xs, zs


# turn list of generators to complete list of elements
# relies on fact that generators commute!
def expandGenerators(proj):
    (phases, xs, zs) = proj
    newPhases, newXs, newZs = [], [], []
    k = len(phases)
    if (k == 0):
        return ([], [], [])

    n = len(xs[0])

    def ph(xs1, zs1, xs2, zs2):
        out = 0
        for i in range(n):
            tup = (xs1[i], zs1[i], xs2[i], zs2[i])
            if tup == (0, 1, 1, 0): out += 2  # Z*X
            if tup == (0, 1, 1, 1): out += 2  # Z*XZ
            if tup == (1, 1, 1, 0): out += 2  # XZ*X
            if tup == (1, 1, 1, 1): out += 2  # XZ*XZ
        return out


    for i in range(1, 2**k):  # omit identity