Esempio n. 1
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. 2
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. 3
0
 def add_glue(self, position):
     if not isinstance(position, C):
         position = C(position)
     self.last_tile_pos = position
     if position not in self.tiles:
         self.tiles[position] = [None, None, None, None]
     return self
Esempio n. 4
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. 5
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. 6
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. 7
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. 8
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. 9
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. 10
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. 11
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. 12
0
 def bottom_left(self):
     return C(
         min([pos.t()[0] for pos in self.tiles]),
         min([pos.t()[1] for pos in self.tiles]),
     )
Esempio n. 13
0
 def translate_aux(self, t_x, t_y):
     new_config = Configuration(self.tileset)
     for position in self.tiles:
         translated_position = C(position[0] + t_x, position[1] + t_y)
         new_config.tiles[translated_position] = self.tiles[position][:]
     return new_config
Esempio n. 14
0
 def delete_tile(self, position):
     if not isinstance(position, C):
         position = C(position)
     if position in self.tiles:
         del self.tiles[position]
     return self
Esempio n. 15
0
 def add_tile(self, position, glues=[None, None, None, None]):
     if not isinstance(position, C):
         position = C(position)
     self.tiles[position] = glues[:]
     self.last_tile_pos = position
     return self
Esempio n. 16
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. 17
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