Esempio n. 1
0
def not_gate(in_=None):
    conf = mawatam.Configuration(mawatam.CollatzTileset)
    if in_ is not None:
        conf.add_glue((0, 0)).west(f"ter.{in_[0]}")
    conf.add_glue((-1, 1)).south("bin.1")
    conf.add_glue((0, -1)).west("ter.0")
    return conf
Esempio n. 2
0
def fanout(even=True):
    conf = mawatam.Configuration(mawatam.CollatzTileset)
    conf.add_glue((0, -1)).west(f"ter.{int(even)}")
    conf.add_glue((-1, 1)).south("bin.1")
    conf.add_glue((-2, 1)).south("bin.0")
    conf.add_glue((-2, -1))
    return conf
Esempio n. 3
0
def wires_fan_out_nand(with_input=None):
    conf = mawatam.Configuration(mawatam.DamienTileset)

    # input
    if with_input is not None:
        conf.add_tile(C(1, -1)).west(f"bin.{with_input}")

    # Horz wire up
    hwire_up_length = 4
    for i in range(hwire_up_length):
        conf.add_tile(C(0, 0) + WEST * i).south("bin.1")

    conf.add_tile(C(0, 0) + WEST * (hwire_up_length - 1) + SOUTH * 2)

    # Vertical wire
    vert_length = 5
    for i in range(vert_length + 2):
        conf.add_tile(C(0, 0) + WEST + SOUTH * (i + 2)).west("bin.1")

    curr = C(0, 0) + WEST + SOUTH * (vert_length + 1)

    conf.add_tile(curr + SOUTH * 2 + WEST * 2)

    # Horz wire down
    hwire_down_length = 2
    for i in range(hwire_down_length):
        conf.add_tile(curr + WEST * (i + 2)).south("bin.1")

    return conf
Esempio n. 4
0
def prime_circuit(with_input=None):
    conf = mawatam.Configuration(mawatam.DamienTileset)

    if with_input is not None:
        conf.add_glue((0, 0)).west(f"bin.{with_input[0]}")
        conf.add_glue((0, -2)).west(f"bin.{with_input[1]}")
        conf.add_glue((0, -6)).west(f"bin.{with_input[2]}")

    conf.add_sub_conf(crossover().translate(EAST))

    conf.add_glue((-6, 1)).south("bin.1")
    conf.add_glue((-7, 1)).south("bin.0")
    conf.add_glue((-7, -1)).south("bin.1")

    conf.add_glue((-8, 1)).south("bin.1")
    conf.add_glue((-7, -1)).west("bin.1")

    conf.add_glue((-7, -3)).west("bin.1")

    conf.add_glue((-6, -3)).south("bin.1")
    conf.add_glue((-5, -5)).west("bin.1")

    for x in range(1, 6):
        conf.add_glue((-1 * x, -5)).south("bin.1")

    conf.add_glue((-5, -7)).west("bin.1")
    conf.add_glue((-5, -8)).west("bin.1")
    conf.add_glue((-5, -9)).west("bin.1")
    conf.add_glue((-7, -8)).south("bin.1")

    for y in range(4, 9):
        conf.add_glue((-7, y * -1)).west("bin.1")

    return conf
Esempio n. 5
0
def crossover(with_input=None):
    conf = mawatam.Configuration(mawatam.DamienTileset)

    if with_input is not None:
        conf.add_glue((-1, 0)).west(f"bin.{with_input[0]}")
        conf.add_glue((-1, -2)).west(f"bin.{with_input[1]}")

    for i in range(2, 7):
        conf.add_glue((-1 * i, 1)).south("bin.1")

    # conf.add_glue((-1, -1)).south("bin.1")
    conf.add_glue((-2, -1)).south("bin.1").west("bin.1")

    # conf.add_glue((-2, -3)).south("bin.1")
    conf.add_glue((-3, -3)).south("bin.1")
    conf.add_glue((-4, -3)).south("bin.1").west("bin.1")

    conf.add_glue((-4, -1)).south("bin.0")
    conf.add_glue((-5, -1)).south("bin.1").west("bin.1")

    conf.add_glue((-1, -3)).west("bin.1")
    conf.add_glue((-1, -4)).west("bin.1")
    conf.add_glue((-6, -3))

    conf.add_glue((-7, -1)).south("bin.0")
    conf.add_glue((-6, -3)).south("bin.0")
    return conf
Esempio n. 6
0
def Four_tileset():
    conf = mawatam.Configuration(mawatam.DamienTileset)
    conf.add_tile((0, 0), "A")
    conf.add_tile((2, 0), "B")
    conf.add_tile((0, -2), "C")
    conf.add_tile((2, -2), "D")
    return conf
Esempio n. 7
0
def or_gate(with_input=None):
    conf = mawatam.Configuration(mawatam.DamienTileset)
    self_nand_size = 3
    conf.add_sub_conf(self_nand_gate(self_nand_size))
    bottom_left = conf.bottom_left()
    conf.add_tile(bottom_left + SOUTH + EAST).west("bin.1")
    conf.add_tile(bottom_left + WEST).south("bin.1")
    conf.add_tile(bottom_left + WEST * 2).south("bin.1")

    south_translate = 6
    second_self_nand = self_nand_gate().translate(SOUTH * south_translate)
    conf.add_sub_conf(second_self_nand)
    conf.add_tile(second_self_nand.bottom_left() + SOUTH + EAST).west("bin.1")

    for i in range(5):
        if i < 4:
            conf.add_tile(bottom_left + WEST + SOUTH * (i + 2)).west("bin.1")
        else:
            conf.add_tile(bottom_left + WEST + SOUTH *
                          (i + 2)).south("bin.1").west("bin.1")

    # inputs
    if with_input is not None:
        conf.add_tile(CENTER).west(f"bin.{with_input[0]}")
        conf.add_tile(SOUTH * south_translate).west(f"bin.{with_input[1]}")

    return conf
Esempio n. 8
0
def x_y_on_top_gate(with_input=None,
                    right_word="",
                    middle_top="",
                    prefix_top=""):
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    total_top_word = prefix_top + " " + middle_top + " "

    curr_in = 1
    for i in range(len(total_top_word)):
        c = total_top_word[::-1][i]
        if c == " ":
            if with_input is None:
                continue

            c = with_input[curr_in]
            curr_in -= 1
            # conf.add_glue((-1 * i, 0)).north(f"bin.{c}")

        conf.add_glue((-1 * i, 0)).south(f"bin.{c}")

    for i in range(len(right_word)):
        conf.add_glue(C(0, -1 * i) + SOUTH + EAST).west(f"ter.{right_word[i]}")

    return conf
Esempio n. 9
0
def circuit_from_spec(spec_file, with_input=None):
    conf = mawatam.Configuration(mawatam.CollatzTileset)
    with open(spec_file, "r") as f:
        spec_content = f.read()

    spec_split = spec_split.split("\n")

    nodes_index = {}
    nodes = []

    for i, line in enumerate(spec_split):
        space_split = line.split(" ")
        node_name = space_split[0]
        nodes_index[node_name] = i
        if len(space_split) == 1:
            # input node
            nodes.append((True, node_name))
        else:
            # computation node
            # <name> <gate> <node x> <node y>
            nodes.append((False, node_name, space_split[1], space_split[2],
                          space_split[3]))

    conf.add_tile((0, 0))
    return conf
Esempio n. 10
0
def fanout_two_even_pos(with_input=None):
    conf = mawatam.Configuration(mawatam.CollatzTileset)
    if with_input is not None:
        conf.add_glue((0, 0)).west(f"ter.{with_input[0]}")
    conf.add_glue((-1, -1)).north("bin.1")
    conf.add_glue((-2, -1)).north("bin.1").west("ter.1")
    conf.add_glue(C(-2, -1) + NORTH * 2 + WEST).south("bin.1")
    return conf
Esempio n. 11
0
def base6_anti_diagonal(in_):
    conf = mawatam.Configuration(mawatam.CollatzTileset)
    pos = C(0, 0)

    for i, c in enumerate(in_):
        conf.add_tile(pos, str(c))
        pos += NORTH + EAST
    return conf
Esempio n. 12
0
def Collatz_tileset():
    conf = mawatam.Configuration(mawatam.CollatzTileset)
    conf.add_tile((0, 0), "0")
    conf.add_tile((2, 0), "1")
    conf.add_tile((4, 0), "2")
    conf.add_tile((0, -2), "3")
    conf.add_tile((2, -2), "4")
    conf.add_tile((4, -2), "5")
    return conf
Esempio n. 13
0
def diago_135(in_word):
    conf = mawatam.Configuration(mawatam.DamienTileset)
    curr_pos = CENTER

    for c in in_word:
        conf.add_tile(curr_pos, c)
        curr_pos += EAST
        curr_pos += SOUTH

    return conf
Esempio n. 14
0
def build_powers_of_2(size=10):
    size = int(size)
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    conf.add_tile(C(1, -1)).north("bin.1")
    for x in range(size):
        conf.add_tile(C(0, x)).east("ter.0")
        conf.add_tile(C(x + 2, -1)).north("bin.0")

    return conf
Esempio n. 15
0
def horizontal_wire(with_input=None, size="4"):
    size = int(size)
    conf = mawatam.Configuration(mawatam.DamienTileset)

    for i in range(size):
        conf.add_glue((-1 * i, 1)).south("bin.1")

    if with_input is not None:
        conf.add_glue((1, 0)).west(f"bin.{with_input}")

    return conf
Esempio n. 16
0
def Collatz_forward(binary_input, number_odd_steps="5"):
    conf = mawatam.Configuration(mawatam.xCollatzTileset)
    number_odd_steps = len(binary_input)
    curr_x = 0
    for c in binary_input:
        conf.add_glue((curr_x, 0)).south(f"bin.{c}")
        curr_x += 1

    for i in range(int(number_odd_steps)):
        conf.add_glue((curr_x, -1 * (i + 1))).west("x.S")

    return conf
Esempio n. 17
0
def self_nand_gate(size=3):
    conf = mawatam.Configuration(mawatam.DamienTileset)
    curr_pos = CENTER

    for i in range(size):
        conf.add_glue(CENTER + NORTH + WEST * (i + 1)).south("bin.1")
        if i < size - 2:
            curr_pos += WEST

    conf.add_tile(curr_pos + SOUTH + EAST).west("bin.1")
    conf.add_tile(curr_pos + SOUTH * 2 + EAST).west("bin.1")
    conf.add_tile(curr_pos + SOUTH + WEST).south("bin.1").west("bin.1")

    return conf
Esempio n. 18
0
def two_bridges_type_2(with_input=None, variant1=0, variant2=0):

    if len(with_input) != 3:
        print("Need three input for the two bridges configuration",
              file=sys.stderr)
        exit(-1)

    conf = mawatam.Configuration(mawatam.CollatzTileset)
    conf.add_sub_conf(bridge_type_2(with_input[:2], variant1))
    bottom_left = conf.bottom_left()
    conf.add_sub_conf(
        bridge_type_2((with_input[2], None),
                      variant2).translate(bottom_left + NORTH * 3 + WEST * 1))
    conf.add_glue(bottom_left).north("bin.0")
    return conf
Esempio n. 19
0
def bridge_type_1(with_input=None, variant=0):
    # This bridge takes one input from north and one input from east
    # and carries them along on bottom left most tile

    # the encoding is: on north: `top0 top1 top2 x 0` with top one of the words below (first component)
    #                   on east: `0 y east0 east1 east2` from top to bottom with east one the words below (second component)

    # Found by computer search, ((top, east))
    bridge_variant = [
        ("000", "120"),
        ("001", "010"),
    ]
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    # TOP
    conf.add_tile((0, 0)).south("bin.0")

    for i in range(3):
        conf.add_tile((-1 * (i + 2), 0)).south(
            f"bin.{bridge_variant[variant%len(bridge_variant)][0][-(i+1)]}")

    # EAST
    conf.add_tile((1, -1)).west("ter.0")

    for i in range(3):
        conf.add_tile((1, -(i + 3))).west(
            f"ter.{bridge_variant[variant%len(bridge_variant)][1][i]}", )

    # Output wiring
    bottom_left = conf.bottom_left()
    conf.add_tile(bottom_left + SOUTH + WEST).north("bin.0")
    conf.add_tile(bottom_left + SOUTH + WEST * 2).north("bin.0")
    conf.add_tile(bottom_left + NORTH + WEST)
    conf.add_tile(bottom_left + SOUTH + EAST * 1).west("ter.0")

    # input
    if with_input is not None:
        conf.add_tile(
            (-1,
             0)).south(f"bin.{with_input[0]}").north(f"bin.{with_input[0]}")
        conf.add_tile(C(
            1, -2)).east(f"ter.{with_input[1]}").west(f"ter.{with_input[1]}")

    return conf
Esempio n. 20
0
def frontier(in_):
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    curr_pos = C(0, 0)

    for c in in_:

        if c in ["0", "1"]:
            curr_pos += WEST
            conf.add_glue(curr_pos).north(f"bin.{c}")
        elif c in ["a", "b", "c"]:
            to_p = ord(c) - ord("a")
            conf.add_glue(curr_pos).west(f"ter.{to_p}")
            curr_pos += SOUTH
        else:
            print(f"Invalid frontier character `{c}`", file=sys.stderr)
            exit(-1)

    return conf
Esempio n. 21
0
def top_binary_and_instr(top_bin, instr):

    conf = mawatam.Configuration(mawatam.CollatzTileset)
    curr_pos = C(0, 0)

    for c in top_bin[::-1]:
        conf.add_glue(curr_pos).south(f"bin.{c}")
        curr_pos += WEST

    curr_pos = C(1, -1)
    for c in instr:
        if c == "-":
            curr_pos += WEST
            conf.add_glue(curr_pos)
            continue
        conf.add_glue(curr_pos).west(f"ter.{c}")
        curr_pos += SOUTH

    return conf
Esempio n. 22
0
def bridge_type_2_inverter(with_input=None, variant=0, minimal=False):
    bridge_variant = [
        ("000", "021"),
    ]
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    # TOP
    conf.add_glue((0, 0)).south("bin.0")

    for i in range(3):
        conf.add_glue((-1 * (i + 2), 0)).south("bin.0")

    # EAST
    conf.add_glue((1, -1)).west("ter.0")

    for i in range(3):
        conf.add_glue((1, -(i + 3))).west(
            f"ter.{bridge_variant[variant%len(bridge_variant)][1][i]}", )

    # Output wiring
    bottom_left = conf.bottom_left()
    if not minimal:
        conf.add_glue(bottom_left + SOUTH + WEST).north("bin.0")
        conf.add_glue(bottom_left + SOUTH + WEST * 2).north("bin.0")
        conf.add_glue(bottom_left + SOUTH + EAST * 4).west("ter.0")

    conf.add_glue(bottom_left + NORTH + WEST)
    conf.add_glue(bottom_left + SOUTH + EAST * 2)

    # input
    if with_input is not None:
        if with_input[0] is not None:
            conf.add_glue((
                -1,
                0)).south(f"bin.{with_input[0]}").north(f"bin.{with_input[0]}")
        if with_input[1] is not None:
            conf.add_glue(C(
                1,
                -2)).east(f"ter.{with_input[1]}").west(f"ter.{with_input[1]}")

    return conf
Esempio n. 23
0
def x_y_on_east_gate(with_input, top, east, middle_east):

    conf = mawatam.Configuration(mawatam.CollatzTileset)

    total_east_word = " " + middle_east + " " + east

    curr_in = 0
    for i in range(len(total_east_word)):
        c = total_east_word[i]
        if c == " ":
            if with_input is None:
                continue

            c = with_input[curr_in]
            curr_in += 1

        conf.add_glue((0, -1 * i)).west(f"ter.{c}")

    for i in range(len(top)):
        conf.add_glue(C(-1 * i, 0) + NORTH + WEST).south(f"bin.{top[::-1][i]}")

    return conf
Esempio n. 24
0
import sys
import mawatam
import random
from mawatam import C, CENTER, NORTH, EAST, SOUTH, WEST

conf = mawatam.Configuration(mawatam.DamienTileset)

i = -20
while i < 0:
    conf.add_tile((i, 0)).south(f"bin.{random.randint(0,1)}")
    i += 1

# i = -20
# while i < -1:
#     conf.add_tile((0, i + 1)).west(f"bin.{random.randint(0,1)}")
#     i += 1

conf.add_tile((0, -1)).west("bin.0")
conf.add_tile((0, -2)).west("bin.1")
conf.add_tile((0, -3)).west("bin.0")
conf.add_tile((0, -4)).west("bin.1")
conf.add_tile((0, -5)).west("bin.0")
conf.add_tile((0, -6)).west("bin.1")
conf.add_tile((0, -7)).west("bin.0")
conf.add_tile((0, -8)).west("bin.1")

print(conf)
Esempio n. 25
0
def prime_circuit_better(in_=None):
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    if in_ is not None:
        conf.add_glue((1, 0)).west(f"ter.{in_[0]}")
        conf.add_glue((1, -3)).west(f"ter.{in_[1]}")
        conf.add_glue((1, -11)).west(f"ter.{in_[2]}")

    conf.add_glue((0, -1)).north(f"bin.1")
    conf.add_sub_conf(fanout(even=False))  # even true because we want not

    conf.add_sub_conf(bridge_type_2(minimal=True).translate(SOUTH))

    # not x and y
    conf.add_sub_conf(
        input_x_y_on_east_canonical_gate("AND").translate((-6, -4)))

    # not x to and
    conf.add_glue((-3, -1)).north("bin.1")
    conf.add_glue((-4, -1)).north("bin.1")
    conf.add_glue((-5, -1)).north("bin.1")

    for i in range(1, 5):
        conf.add_glue((-5, -1 * i)).west("ter.0")

    conf.add_glue((-6, 1)).south("bin.1")

    # y to and
    conf.add_glue((-5, -7)).north("bin.1")
    conf.add_glue((-6, -7)).north("bin.1")

    # x and z
    conf.add_sub_conf(
        input_x_y_on_east_canonical_gate("AND").translate((-6, -10)))

    # x to and
    conf.add_glue((0, -7)).west("ter.0")
    conf.add_glue((0, -8)).west("ter.0")
    conf.add_glue((0, -9)).west("ter.0")
    conf.add_glue((-2, -8))

    for i in range(2, 6):
        conf.add_glue((-1 * i, -10)).north("bin.1")

    conf.add_sub_conf(not_gate().translate((-4, -11)))
    conf.add_sub_conf(not_gate().translate((-5, -9)))
    # z to and
    for i in range(0, 5):
        conf.add_glue((-1 * i, -12)).north("bin.1")
    conf.add_glue((-1, -10))
    conf.add_glue((-6, -13)).north("bin.1")
    conf.add_glue((-5, -10)).south("bin.0")
    conf.add_glue((-6, -8)).south("bin.0")
    conf.add_glue((-9, -6))
    conf.add_sub_conf(
        input_x_y_on_east_canonical_gate("OR").translate((-10, -11)))
    conf.add_glue((-9, -14)).north("bin.1")
    conf.add_glue((-10, -14)).north("bin.1")
    conf.add_glue((-9, -12))

    conf.add_glue((-9, -8)).north("bin.1")

    conf.add_glue((-10, -6)).south("bin.1")
    for i in range(8, 12):
        conf.add_glue((-9, -1 * i)).west("ter.0")
    return conf
Esempio n. 26
0
def bridge_type_2(with_input=None, variant=0, minimal=False):
    # This bridge takes one input from north and one input from east
    # and carries them along: north is to be read on same column than input north
    # and east is to be read on the bottom left most tile

    # if minimal=False a short 2 base wire will be added for west output

    # the encoding is: on north: `top0 top1 top2 x 0` with top one of the words below (first component)
    #                   on east: `0 y east0 east1 east2` from top to bottom with east one the words below (second component)

    # Found by computer search, ((top, east))
    bridge_variant = [
        ("000", "012"),
        ("000", "100"),
        ("000", "111"),
        ("000", "122"),
        ("000", "210"),
        ("000", "221"),
        ("001", "001"),
        ("001", "012"),
        ("001", "100"),
        ("001", "111"),
        ("010", "001"),
        ("111", "122"),
        ("111", "210"),
        ("111", "221"),
    ]
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    # TOP
    conf.add_glue((0, 0)).south("bin.0")

    for i in range(3):
        conf.add_glue((-1 * (i + 2), 0)).south("bin.0")

    # EAST
    conf.add_glue((1, -1)).west("ter.0")

    for i in range(3):
        conf.add_glue((1, -(i + 3))).west(
            f"ter.{bridge_variant[variant%len(bridge_variant)][1][i]}", )

    # Output wiring
    bottom_left = conf.bottom_left()
    if not minimal:
        conf.add_glue(bottom_left + SOUTH + WEST).north("bin.0")
        conf.add_glue(bottom_left + SOUTH + WEST * 2).north("bin.0")
        conf.add_glue(bottom_left + SOUTH + EAST * 4).west("ter.0")

    conf.add_glue(bottom_left + NORTH + WEST)
    conf.add_glue(bottom_left + SOUTH + EAST * 2)

    # input
    if with_input is not None:
        if with_input[0] is not None:
            conf.add_glue((
                -1,
                0)).south(f"bin.{with_input[0]}").north(f"bin.{with_input[0]}")
        if with_input[1] is not None:
            conf.add_glue(C(
                1,
                -2)).east(f"ter.{with_input[1]}").west(f"ter.{with_input[1]}")

    return conf
Esempio n. 27
0
def circuit_prime_3_bits(with_input=None):
    # (not x and y) or (x and z)
    conf = mawatam.Configuration(mawatam.CollatzTileset)

    if with_input is not None:
        # x
        conf.add_tile(C(0, 0) + EAST).west(f"ter.{with_input[0]}")
        # top horizontal wire for x
        conf.add_tile(C(0, 0) + SOUTH).north("bin.1")
        conf.add_tile(C(0, 0) + WEST + SOUTH).north("bin.1")
        conf.add_tile(C(0, 0) + WEST * 2 + SOUTH).north("bin.1")

        # y
        conf.add_tile(C(0, 0) + SOUTH * 3 + EAST).west(f"ter.{with_input[1]}")

        # horz wire for y
        now = C(0, 0) + SOUTH * 3
        conf.add_glue(now + SOUTH).north("bin.1")
        conf.add_glue(now + WEST + SOUTH).north("bin.1")

        # z
        conf.add_tile(C(0, 0) + SOUTH * 9 + EAST).west(f"ter.{with_input[2]}")

        # horz wire for z
        now = C(0, 0) + SOUTH * 9
        conf.add_glue(now + SOUTH).north("bin.1")
        conf.add_glue(now + WEST + SOUTH).north("bin.1")

    # turn south for x
    conf.add_tile(C(0, 0) + WEST * 3 + NORTH).south("bin.1")
    conf.add_tile(C(0, 0) + WEST * 4 + NORTH).south("bin.0")
    conf.add_glue(C(0, 0) + WEST * 5 + SOUTH).north("bin.1")
    conf.add_glue(C(0, 0) + WEST * 2 + SOUTH).west("ter.0")

    # growth blocker
    conf.add_tile(C(0, 0) + WEST * 4 + SOUTH)

    # bridge x y
    now = C(0, 0) + WEST * 3 + SOUTH
    conf.add_sub_conf(bridge_type_2(minimal=True).translate(C(-2, -1)))

    # bridge x z
    now = C(0, 0) + WEST * 2 + SOUTH * 7
    conf.add_glue(now).west("ter.0")
    conf.add_sub_conf(bridge_type_2(minimal=True).translate(now))

    # brige y z
    now = C(0, 0) + WEST * 7 + SOUTH * 13
    conf.add_tile(now).north("bin.1")
    conf.add_tile(now + WEST).north("bin.1")
    now += WEST * 2 + NORTH * 3
    conf.add_sub_conf(bridge_type_2(minimal=True).translate(now))

    # turn for y
    now = now = C(0, 0) + WEST * 7 + SOUTH * 7
    conf.add_glue(now).north("bin.1")
    conf.add_glue(now + WEST).north("bin.1")
    conf.add_glue(now + WEST * 2).north("bin.1")
    conf.add_glue(now + WEST * 3 + NORTH * 2).south("bin.1")
    # conf.add_glue(now + WEST * 4 + NORTH * 2).south("bin.0")
    # conf.add_glue(now + WEST * 5).north("bin.1")

    # y goes south to bridge
    for i in range(4):
        conf.add_glue(now + WEST * 2 + SOUTH * i).west("ter.0")

    now = C(0, 0) + SOUTH * 15 + WEST
    # bring x to gate
    for i in range(4):
        conf.add_glue(now + NORTH * 2 + WEST + SOUTH * i).west("ter.0")
        conf.add_glue(now + NORTH * 2 + WEST * 3 + SOUTH * 4 +
                      WEST * i).north("bin.1")
    conf.add_tile(now + NORTH * 2 + WEST * 3 + SOUTH * 4 + NORTH * 2)
    conf.add_glue(now + NORTH * 2 + WEST * 3 + SOUTH * 4 + NORTH * 2 +
                  WEST * 4).south("bin.1")

    conf.add_sub_conf(
        input_x_y_on_top_canonical_gate("AND").translate(now + WEST * 7 +
                                                         SOUTH))
    conf.add_glue(now + WEST * 7 + SOUTH + WEST).west("ter.0")

    # bridge (x,z)
    conf.add_glue(C(-16, -13) + EAST + SOUTH * 3).north("bin.1")
    conf.add_glue(C(-16, -13) + EAST * 2 + SOUTH * 3).north("bin.1")
    conf.add_sub_conf(bridge_type_2(minimal=True).translate((-16, -13)))

    # bridge (x, AND x y)
    conf.add_glue((-16, -19)).west("ter.0")
    conf.add_sub_conf(bridge_type_2(minimal=True).translate((-16, -19)))

    # x coming to bridges (x,z) (x, AND x y)
    for i in range(6, 17):
        conf.add_glue((-1 * i, -1)).north("bin.1")
    conf.add_glue((-17, 1)).south("bin.1")

    for i in range(1, 14):
        conf.add_glue((-16, -1 * i)).west("ter.0")

    # (AND x y) coming to x bridge we need a not to correct parity
    conf.add_glue((-12, -16)).south("bin.1")
    for i in range(18, 22):
        conf.add_glue((-11, -1 * i)).west("ter.0")

    for i in range(13, 16):
        conf.add_glue((-1 * i, -22)).north("bin.1")

    conf.add_tile((-13, -20))

    # bridge z, (AND x y)
    conf.add_glue((-21, -25)).north("bin.1")
    conf.add_glue((-22, -25)).north("bin.1")
    conf.add_sub_conf(bridge_type_2(minimal=True).translate((-23, -22)))

    # z coming to brige z, (AND x y)
    for i in range(21, 24):
        conf.add_glue((-1 * i, -19)).north("bin.1")

    conf.add_glue((-24, -17)).south("bin.1")

    for i in range(19, 23):
        conf.add_glue((-23, -1 * i)).west("ter.0")

    # (AND x z)
    conf.add_sub_conf(
        input_x_y_on_top_canonical_gate("AND").translate((-22, -28)))

    # bringing x to (AND x z)
    conf.add_glue((-23, -28)).west("ter.0")
    for i in range(25, 29):
        conf.add_glue((-16, -1 * i)).west("ter.0")

    for i in range(18, 22):
        conf.add_glue((-1 * i, -29)).north("bin.1")
    conf.add_tile((-18, -27))

    # OR
    conf.add_glue((-22, -27)).south("bin.0")
    conf.add_glue((-26, -28)).south("bin.0")
    conf.add_sub_conf(
        input_x_y_on_top_canonical_gate("OR").translate((-26, -29)))

    # bring AND(x,y) to OR gate
    conf.add_glue((-28, -26)).south("bin.0")
    conf.add_glue((-27, -28)).west("ter.0")
    conf.add_glue((-27, -29)).west("ter.0")

    # light bulb
    for i in range(30, 36):
        conf.add_glue((-1 * i, -33)).south("bin.0")
    for i in range(35, 40):
        conf.add_glue((-29, -1 * i)).west("ter.0")

    return conf