Toffoli from AND

A four-T temporary AND is combined with a delayed CZ correction. The target output carries z XOR (x AND y), while the two control wires are retained.

Block graph

BLOG source

BLOG 1.0

module main {
  in x_in: data = 6
  out x_out: data = 48
  in y_in: data = 50
  out y_out: data = 19
  in z_in: data = 46
  out z_xor_xy: data = 33

  0: T [0, 0, 0]
  1: XZX [0, 0, 1]
  2: ZZX [1, 0, 1]
  3: XZX [2, 0, 1]
  4: XZX [2, 0, 2]
  5: XZX [3, 0, 1]
  6: Port [4, 0, 0] <In_x>
  7: XZX [4, 0, 1]
  8: ZZX [1, 0, 2]
  9: ZZX [1, 1, 2]
  10: XY [0, 0, 2]
  11: XZX [2, 1, 2]
  12: ZZX [1, 1, 1]
  13: ZZX [1, 2, 1]
  14: XZX [2, 2, 1]
  15: XZX [2, 1, 1]
  16: T [2, 1, 0]
  17: XZX [3, 2, 1]
  18: XZX [4, 2, 1]
  19: Port [4, 2, 2] <Out_y>
  20: XZX [2, 1, 3]
  21: XZZ [2, 2, 2]
  22: XZX [0, 1, 2]
  23: T [0, 1, 1]
  24: XY [0, 1, 3]
  25: XZX [2, 2, 3]
  26: ZZX [1, 1, 3]
  27: ZZX [1, 2, 3]
  28: XZX [0, 2, 3]
  29: T [0, 2, 2]
  30: XY [0, 2, 4]
  31: ZXX [2, 1, 4]
  32: ZXZ [4, 1, 3]
  33: Port [4, 1, 4] <Out_z_xor_xy>
  34: Y [2, 1, 5]
  35: XZX [2, 2, 4]
  36: ZZX [1, 1, 4]
  37: ZZX [1, 2, 4]
  38: XZX [3, 0, 4]
  39: ZZX [2, 0, 4]
  40: XZX [0, 1, 4]
  41: XZ [0, 1, 5]
  42: XZ [1, 0, 5]
  43: ZXX [1, 0, 4]
  44: XZX [1, 0, 3]
  45: XZX [2, 0, 3]
  46: Port [4, 1, 2] <In_z>
  47: XXZ [3, 1, 3]
  48: Port [4, 0, 2] <Out_x>
  49: XZZ [3, 0, 3]
  50: Port [4, 2, 0] <In_y>
  0 -> +Z
  1 -> +X
  1 -> +Z
  2 -> +X
  2 -> +Y
  3 -> +Z
  3 -> +X
  4 -> -X
  5 -> +X
  7 -> -Z
  7 -> +Z
  8 -> +Y
  9 -> +X
  9 -> -X
  11 -> +Z
  12 -> +Y
  12 -> +X
  13 -> +X
  14 -> +X
  14 -> +Z
  15 -> +Z
  15 -> -Z
  17 -> +X
  18 -> +Z
  18 -> -Z
  20 -> -X
  20 -H> +Z
  21 -> +Z
  22 -> -Z
  22 -> +Z
  25 -> -X
  25 -> +Z
  27 -> -Y
  27 -> -X
  28 -> -Z
  28 -> +Z
  31 -> +Z
  31 -> -Y
  32 -> +Z
  32 -> -Z
  35 -> -X
  36 -> -X
  36 -> -Y
  37 -> -Y
  38 -> -Z
  39 -> +X
  40 -> +Z
  43 -H> +Z
  43 -H> -Z
  44 -> +X
  45 -> -Z
  47 -> +X
  49 -> +Y

  MZxZyZxyZa = measure 1 -> +X
  resolve 10 if !MZxZyZxyZa
  MZxZxyZb = measure 22 -> +X
  resolve 24 if MZxZxyZb
  MZyZxyZc = measure 28 -> +X
  resolve 30 if MZyZxyZc
  mxy = measure 34
  resolve 41 if mxy
  resolve 42 if mxy

}

See BLOG Format for the syntax or return to all examples.