From cac388f0e6c9ac572e3a14ed9382136286e38970 Mon Sep 17 00:00:00 2001 From: Martin Elsman Date: Thu, 16 Jan 2025 11:21:43 +0100 Subject: [PATCH] cleanup: oo is now ++, dim is now height, def of T --- src/circuit.sig | 13 ++-- src/circuit.sml | 42 ++++++++--- src/comp.sml | 36 ++++++---- src/diagram-latex.sml | 124 +++++++++++++++++++++++++++++++++ src/diagram.mlb | 4 ++ src/diagram.sml | 2 +- src/quantum.mlb | 2 +- src/quantum_ex1.sml | 5 +- src/semantics.sml | 30 ++++---- src/test/test_circuit.mlb | 2 +- src/test/test_circuit.sml | 4 +- src/test/test_diagram.sml | 12 ++-- src/test/test_semantics.out.ok | 14 ++-- src/test/test_semantics.sml | 17 ++--- 14 files changed, 232 insertions(+), 75 deletions(-) create mode 100644 src/diagram-latex.sml create mode 100644 src/diagram.mlb diff --git a/src/circuit.sig b/src/circuit.sig index 98ffce6..46271c7 100644 --- a/src/circuit.sig +++ b/src/circuit.sig @@ -1,15 +1,16 @@ signature CIRCUIT = sig - datatype t = I | X | Y | Z | H | SW + datatype t = I | X | Y | Z | H | T | SW | C of t | Tensor of t * t | Seq of t * t - val oo : t * t -> t - val ** : t * t -> t + val ++ : t * t -> t + val ** : t * t -> t - val pp : t -> string - val draw : t -> string - val dim : t -> int + val pp : t -> string + val draw : t -> string + val draw_latex : t -> string + val height : t -> int end diff --git a/src/circuit.sml b/src/circuit.sml index 71bfb3c..af65f7b 100644 --- a/src/circuit.sml +++ b/src/circuit.sml @@ -2,12 +2,12 @@ structure Circuit : CIRCUIT = struct infix |> fun a |> f = f a - datatype t = I | X | Y | Z | H | SW + datatype t = I | X | Y | Z | H | T | SW | Tensor of t * t | Seq of t * t | C of t - val oo = op Seq + val ++ = op Seq val ** = op Tensor fun pp t = @@ -15,9 +15,9 @@ structure Circuit : CIRCUIT = struct fun pp p t = case t of Tensor(t1,t2) => maybePar (p > 4) (pp 4 t1 ^ " ** " ^ pp 4 t2) - | Seq(t1,t2) => maybePar (p > 3) (pp 3 t1 ^ " oo " ^ pp 3 t2) + | Seq(t1,t2) => maybePar (p > 3) (pp 3 t1 ^ " ++ " ^ pp 3 t2) | C t => "C" ^ pp 8 t - | I => "I" | X => "X" | Y => "Y" | Z => "Z" | H => "H" | SW => "SW" + | I => "I" | X => "X" | Y => "Y" | Z => "Z" | H => "H" | T => "T" | SW => "SW" in pp 0 t end @@ -32,6 +32,7 @@ structure Circuit : CIRCUIT = struct | Y => Diagram.box "Y" | Z => Diagram.box "Z" | H => Diagram.box "H" + | T => Diagram.box "T" | C X => Diagram.cntrl "X" | C Y => Diagram.cntrl "Y" | C Z => Diagram.cntrl "Z" @@ -41,17 +42,40 @@ structure Circuit : CIRCUIT = struct in dr t |> Diagram.toString end - fun dim t = + structure DiagramL = DiagramLatex + + fun draw_latex t = + let fun dr t = + case t of + SW => DiagramL.swap + | Tensor(a,b) => DiagramL.par(dr a, dr b) + | Seq(a,b) => DiagramL.seq(dr a, dr b) + | I => DiagramL.line + | X => DiagramL.box "X" + | Y => DiagramL.box "Y" + | Z => DiagramL.box "Z" + | H => DiagramL.box "H" + | T => DiagramL.box "T" + | C X => DiagramL.cntrl "X" + | C Y => DiagramL.cntrl "Y" + | C Z => DiagramL.cntrl "Z" + | C H => DiagramL.cntrl "H" + | C _ => raise Fail ("Circuit.draw_latex: Controlled circuit " ^ + pp t ^ " cannot be drawn") + in dr t |> DiagramL.toString + end + + fun height t = case t of - Tensor(a,b) => dim a + dim b + Tensor(a,b) => height a + height b | Seq(a,b) => - let val d = dim a - in if d <> dim b + let val d = height a + in if d <> height b then raise Fail "Sequence error: mismatching dimensions" else d end | SW => 2 - | C t => 1 + dim t + | C t => 1 + height t | _ => 1 end diff --git a/src/comp.sml b/src/comp.sml index 233263c..bac23f9 100644 --- a/src/comp.sml +++ b/src/comp.sml @@ -35,29 +35,30 @@ structure Comp :> COMP = struct | Y => ret (APP("Y",[])) | Z => ret (APP("Z",[])) | H => ret (APP("H",[])) + | T => ret (APP("T",[])) | SW => ret (APP("SW",[])) | Seq(t1,t2) => comp t1 >>= (fn e1 => comp t2 >>= (fn e2 => - let val n = Int.toString (pow2 (dim t)) + let val n = Int.toString (pow2 (height t)) val ty = "[" ^ n ^ "][" ^ n ^ "]C.complex" in ret (TYPED(APP("matmul", [e2,e1]),ty)) end)) | Tensor(t1,t2) => comp t1 >>= (fn e1 => comp t2 >>= (fn e2 => - let val n = Int.toString (pow2 (dim t)) + let val n = Int.toString (pow2 (height t)) val ty = "[" ^ n ^ "][" ^ n ^ "]C.complex" in ret (TYPED(APP("tensor", [e1,e2]),ty)) end)) | C t' => comp t' >>= (fn e => - let val n = Int.toString (pow2 (dim t)) + let val n = Int.toString (pow2 (height t)) val ty = "[" ^ n ^ "][" ^ n ^ "]C.complex" in ret (TYPED(APP("control",[e]),ty)) end) end - fun vecTyFromDim d = + fun vecTyFromHeight d = "[" ^ Int.toString(pow2 d) ^ "]C.complex" local @@ -73,7 +74,7 @@ structure Comp :> COMP = struct end fun FunC A (f:F.exp -> F.exp F.M) : F.var option F.M = if allI A then ret NONE - else let val ty = vecTyFromDim (Circuit.dim A) + else let val ty = vecTyFromHeight (Circuit.height A) in Fun f ty ty >>= (ret o SOME) end fun splitF d v = @@ -81,7 +82,7 @@ structure Comp :> COMP = struct Int.toString (pow2 d) ^ "]C.complex" in APP("split",[TYPED(v,ty)]) end - fun concatF d a b = TYPED(APP("concat",[a,b]),vecTyFromDim d) + fun concatF d a b = TYPED(APP("concat",[a,b]),vecTyFromHeight d) fun unvecF (e,ty) = APP("unvec", [TYPED(e,ty)]) fun vecF e = APP("vec",[e]) fun mapF f e = APP("map", [VAR f,e]) @@ -95,25 +96,26 @@ structure Comp :> COMP = struct Circuit.I => ret v | Circuit.Seq(t1,t2) => icomp t1 v >>= (icomp t2) | Circuit.C t' => - Let (splitF (Circuit.dim t') v) >>= (fn p => + Let (splitF (Circuit.height t') v) >>= (fn p => icomp t' (SEL(1,VAR p)) >>= (fn v1 => - ret (concatF (Circuit.dim t) (SEL(0,VAR p)) v1))) + ret (concatF (Circuit.height t) (SEL(0,VAR p)) v1))) | Circuit.Tensor(A,B) => FunC A (icomp A) >>= (fn Af => FunC B (icomp B) >>= (fn Bf => - let val dA = pow2(Circuit.dim A) - val dB = pow2(Circuit.dim B) + let val dA = pow2(Circuit.height A) + val dB = pow2(Circuit.height B) val ty = "[" ^ Int.toString dA ^ "*" ^ Int.toString dB ^ "]C.complex" in Let (unvecF(v,ty)) >>= (fn V => Let (mapF' Bf (transposeF (VAR V))) >>= (fn W => Let (mapF' Af (transposeF (VAR W))) >>= (fn Y => - ret (TYPED(vecF (VAR Y),vecTyFromDim (Circuit.dim t)))))) + ret (TYPED(vecF (VAR Y),vecTyFromHeight (Circuit.height t)))))) end)) - | Circuit.H => ret (matvecmulF (APP("H",[])) v) | Circuit.X => ret (matvecmulF (APP("X",[])) v) | Circuit.Y => ret (matvecmulF (APP("Y",[])) v) | Circuit.Z => ret (matvecmulF (APP("Z",[])) v) + | Circuit.H => ret (matvecmulF (APP("H",[])) v) + | Circuit.T => ret (matvecmulF (APP("T",[])) v) | Circuit.SW => ret (matvecmulF (APP("SW",[])) v) end @@ -126,20 +128,24 @@ structure Comp :> COMP = struct val cni = APP("C.mk_im", [CONST "(-1)"]) val rsqrt2 = APP("C.mk_re", [CONST "(1.0 / f64.sqrt(2.0))"]) val rnsqrt2 = APP("C.mk_re", [CONST "((-1.0) / f64.sqrt(2.0))"]) + val tmp = APP("C.exp", [APP("C.mk_im",[CONST "(f64.pi/4)"])]) + val rsqrt2eipi4 = APP("C.*", [rsqrt2,tmp]) fun ty n = "[" ^ Int.toString n ^ "][" ^ Int.toString n ^ "]C.complex" fun binds nil = ret () | binds ((s,n,e)::rest) = FunNamed s (fn _ => ret e) "()" (ty n) >>= (fn _ => binds rest) in binds [("I", 2, ARR[ARR[c1,c0], ARR[c0,c1]]), - ("H", 2, ARR[ARR[rsqrt2,rsqrt2], - ARR[rsqrt2,rnsqrt2]]), ("X", 2, ARR[ARR[c0,c1], ARR[c1,c0]]), ("Y", 2, ARR[ARR[c0,cni], ARR[ci,c0]]), ("Z", 2, ARR[ARR[c1,c0], ARR[c0,cn1]]), + ("H", 2, ARR[ARR[rsqrt2,rsqrt2], + ARR[rsqrt2,rnsqrt2]]), + ("T", 2, ARR[ARR[rsqrt2,c0], + ARR[c0,rsqrt2eipi4]]), ("SW", 4, ARR[ARR[c1,c0,c0,c0], ARR[c0,c0,c1,c0], ARR[c0,c1,c0,c0], @@ -156,7 +162,7 @@ structure Comp :> COMP = struct fun circuitToFutFunBind (f:string) (t:Circuit.t) : string = let open F infix >>= - val ty = vecTyFromDim (Circuit.dim t) + val ty = vecTyFromHeight (Circuit.height t) in runBinds (FunNamed f (icomp t) ty ty >>= (fn _ => ret())) end diff --git a/src/diagram-latex.sml b/src/diagram-latex.sml new file mode 100644 index 0000000..4944a8e --- /dev/null +++ b/src/diagram-latex.sml @@ -0,0 +1,124 @@ +structure DiagramLatex :> DIAGRAM = struct + + datatype t = Box of string + | Line + | Cntrl of string + | Swap + | Par of t * t + | Seq of t * t + + fun depth t : int = + case t of + Line => 1 + | Box _ => 1 + | Cntrl _ => 1 + | Swap => 1 + | Par (t1,t2) => Int.max(depth t1, depth t2) + | Seq(t1,t2) => depth t1 + depth t2 + + fun height t : int = + case t of + Line => 1 + | Box _ => 1 + | Cntrl _ => 2 + | Swap => 2 + | Par (t1,t2) => height t1 + height t2 + | Seq(t1,t2) => Int.max(height t1, height t2) + + val dy = 10 + val dx = 10 + + fun i2s x = if x < 0 then "-" ^ i2s (~x) + else Int.toString x + + fun put (x,y) c = + "\\put(" ^ i2s x ^ "," ^ i2s y ^ "){" ^ c ^ "}" + + fun circ () = "\\circle*{" ^ i2s (dy div 10) ^ "}" + + fun line (x,y) l = + "\\line(" ^ i2s x ^ "," ^ i2s y ^ "){" ^ i2s l ^ "}" + + fun framebox (sx,sy) s = + "\\framebox(" ^ i2s sx ^ "," ^ i2s sy ^ "){" ^ s ^ "}" + + fun put_line (x,y) a = + put (x,y + dy div 2) (line (1,0) dx) :: a + + fun put_swap (x,y) a = + let val (x1,y1) = (x + dx div 2, y + dy div 2) + val (x2,y2) = (x1,y1-dy) + in put_line (x,y) + (put_line (x,y-dy) + (put (x1,y2) (line (0,1) dy) :: + put (x1,y1) (circ()) :: + put (x2,y2) (circ()) :: a)) + end + + fun put_cntrl (x,y) a = + let val (x1,y1) = (x + dx div 2, y + dy div 2) + val dy' = dy - 3 * dy div 10 + in put_line (x,y) + (put (x1,y1) (line (0,~1) dy') :: + put (x1,y1) (circ()) :: a) + end + + fun put_box s (x,y) a = + let val dx' = dx div 5 + val x' = x + dx' + val dy' = dy div 5 + val y' = y + dy' + val sx = dx - 2 * dx' + val sy = dy - 2 * dy' + in put (x',y') (framebox(sx,sy) s) :: + put (x,y + dy div 2) (line(1,0) dx') :: + put (x+dx,y + dy div 2) (line(~1,0) dx') :: a + end + + fun lines n = + if n > 1 then Par(Line,lines(n-1)) + else Line + + fun padl t = + Seq(lines (height t), t) + + fun padr t = + Seq(t,lines (height t)) + + fun toStr x y t a = + case t of + Box s => put_box s (x,y) a + | Line => put_line (x,y) a + | Swap => put_swap (x,y) a + | Cntrl s => put_box s (x,y - dy) (put_cntrl (x,y) a) + | Seq (t1,t2) => toStr (x + dx*(depth t1)) y t2 (toStr x y t1 a) + | Par (t1,t2) => + let val d1 = depth t1 + val d2 = depth t2 + in if d1 > d2 + 1 then + toStr x y (Par(t1,padl (padr t2))) a + else if d1 > d2 then + toStr x y (Par(t1,padl t2)) a + else if d2 > d1 + 1 then + toStr x y (Par(padl (padr t1),t2)) a + else if d2 > d1 then + toStr x y (Par(padl t1,t2)) a + else + toStr x (y - dy*(height t1)) t2 (toStr x y t1 a) + end + + fun toString t = + let val (h,d) = (height t, depth t) + in String.concatWith "\n" + ("\\begin{picture}(" ^ i2s (dx*d) ^ "," ^ i2s (dy*h) ^ ")(0,0)" :: + toStr 0 ((h-1)*dy) t ["\\end{picture}"]) + end + + val box = Box + val line = Line + val cntrl = Cntrl + val swap = Swap + val seq = Seq + val par = Par + +end diff --git a/src/diagram.mlb b/src/diagram.mlb new file mode 100644 index 0000000..026fd72 --- /dev/null +++ b/src/diagram.mlb @@ -0,0 +1,4 @@ +local $(SML_LIB)/basis/basis.mlb +in diagram.sml + diagram-latex.sml +end \ No newline at end of file diff --git a/src/diagram.sml b/src/diagram.sml index b752683..027f82e 100644 --- a/src/diagram.sml +++ b/src/diagram.sml @@ -11,7 +11,7 @@ sig val toString : t -> string end -structure Diagram : DIAGRAM = +structure Diagram :> DIAGRAM = struct type t = string list (* lines; invariant: lines have equal size *) diff --git a/src/quantum.mlb b/src/quantum.mlb index 8425050..7be3f36 100644 --- a/src/quantum.mlb +++ b/src/quantum.mlb @@ -1,7 +1,7 @@ local $(SML_LIB)/basis/basis.mlb ../lib/github.com/diku-dk/sml-matrix/matrix.mlb ../lib/github.com/diku-dk/sml-complex/complex.mlb -in diagram.sml +in diagram.mlb circuit.sig circuit.sml semantics.sig diff --git a/src/quantum_ex1.sml b/src/quantum_ex1.sml index 1147310..f32de64 100644 --- a/src/quantum_ex1.sml +++ b/src/quantum_ex1.sml @@ -1,11 +1,12 @@ open Circuit Semantics -infix 3 oo +infix 3 ++ infix 4 ** fun run c k = (print ("Circuit for c = " ^ pp c ^ ":\n"); print (draw c ^ "\n"); + print (draw_latex c ^ "\n"); print ("Semantics of c:\n" ^ pp_mat(sem c) ^ "\n"); print ("Result distribution when evaluating c on " ^ pp_ket k ^ " :\n"); let val v0 = init k @@ -15,4 +16,4 @@ fun run c k = ; print ("V2: " ^ pp_state (interp c v0) ^ "\n") end) -val () = run ((I ** H oo C X oo Z ** Z oo C X oo I ** H) ** I oo I ** SW oo C X ** Y) (ket[1,0,1]) +val () = run ((I ** H ++ C X ++ Z ** Z ++ C X ++ I ** H) ** I ++ I ** SW ++ C X ** Y) (ket[1,0,1]) diff --git a/src/semantics.sml b/src/semantics.sml index 43ee171..325f338 100644 --- a/src/semantics.sml +++ b/src/semantics.sml @@ -61,22 +61,22 @@ structure Semantics :> SEMANTICS = struct fun sem (t:Circuit.t) : mat = let open Circuit val c0 = C.fromInt 0 - val c1 = C.fromInt 1 - val cn1 = C.~ c1 val ci = C.fromIm 1.0 - val cni = C.~ ci + val rsqrt2 = C.fromRe (1.0 / Math.sqrt 2.0) + val rsqrt2eipi4 = C.*(rsqrt2,C.exp(C.fromIm(Math.pi/4.0))) in case t of I => fromIntM [[1,0], [0,1]] | X => fromIntM [[0,1], [1,0]] - | Y => M.fromListList [[c0,cni], + | Y => M.fromListList [[c0,C.~ ci], [ci,c0]] - | Z => fromIntM [[1,0],[0,~1]] - | H => let val rsqrt2 = C.fromRe (1.0 / Math.sqrt 2.0) - in M.fromListList [[rsqrt2,rsqrt2], - [rsqrt2,C.~ rsqrt2]] - end + | Z => fromIntM [[1,0], + [0,~1]] + | H => M.fromListList [[rsqrt2,rsqrt2], + [rsqrt2,C.~ rsqrt2]] + | T => M.fromListList [[rsqrt2,c0], + [c0,rsqrt2eipi4]] | SW => fromIntM [[1,0,0,0], [0,0,1,0], [0,1,0,0], @@ -142,8 +142,7 @@ structure Semantics :> SEMANTICS = struct type vec = state fun flatten (a:mat) : vec = - let val rows = M.nRows a - val cols = M.nCols a + let val (rows,cols) = M.dimensions a in Vector.tabulate(rows * cols, fn i => M.sub(a,i div cols,i mod cols)) end @@ -174,11 +173,9 @@ structure Semantics :> SEMANTICS = struct case t of Circuit.Seq(t1,t2) => interp t2 (interp t1 v) | Circuit.Tensor(A,B) => - let val Af = interp A - val Bf = interp B - val V = unvec (pow2(Circuit.dim A),pow2(Circuit.dim B)) v - val W = mapRows Bf (M.transpose V) - val Y = mapRows Af (M.transpose W) + let val V = unvec (pow2(Circuit.height A),pow2(Circuit.height B)) v + val W = mapRows (interp B) (M.transpose V) + val Y = mapRows (interp A) (M.transpose W) in vec Y end | Circuit.C A => @@ -187,5 +184,4 @@ structure Semantics :> SEMANTICS = struct end | Circuit.I => v | _ => eval t v - end diff --git a/src/test/test_circuit.mlb b/src/test/test_circuit.mlb index a99a456..969cb32 100644 --- a/src/test/test_circuit.mlb +++ b/src/test/test_circuit.mlb @@ -1,5 +1,5 @@ local $(SML_LIB)/basis/basis.mlb - ../diagram.sml + ../diagram.mlb ../circuit.sig ../circuit.sml in diff --git a/src/test/test_circuit.sml b/src/test/test_circuit.sml index 8673e6b..3fc345e 100644 --- a/src/test/test_circuit.sml +++ b/src/test/test_circuit.sml @@ -2,8 +2,8 @@ val () = print "Testing: Circuit\n" open Circuit infix 4 ** -infix 3 oo +infix 3 ++ -val c = X ** H oo I ** Y oo SW oo Y ** H +val c = X ** H ++ I ** Y ++ SW ++ Y ** H val () = print (draw c ^ "\n") diff --git a/src/test/test_diagram.sml b/src/test/test_diagram.sml index 5eb083b..f9a2262 100644 --- a/src/test/test_diagram.sml +++ b/src/test/test_diagram.sml @@ -4,12 +4,12 @@ open Diagram val H = box "H" val I = box "I" val X = box "X" -infix 7 ** -infix 3 oo +infix 3 ++ +infix 4 ** val op ** = par -val op oo = seq -val d = ((H oo I oo H) ** (H oo X oo I)) oo swap oo cntrl "H" -val d' = H**H oo I**X oo H**I oo swap oo cntrl "H" +val op ++ = seq +val d = ((H ++ I ++ H) ** (H ++ X ++ I)) ++ swap ++ cntrl "H" +val d' = H**H ++ I**X ++ H**I ++ swap ++ cntrl "H" val () = print(if toString d = toString d' then "Eq OK\n" else "Eq Err\n") -val d2 = d ** (I oo H) +val d2 = d ** (I ++ H) val () = print (toString d2 ^ "\n") diff --git a/src/test/test_semantics.out.ok b/src/test/test_semantics.out.ok index e0a3aba..6662ae4 100644 --- a/src/test/test_semantics.out.ok +++ b/src/test/test_semantics.out.ok @@ -1,6 +1,6 @@ Testing: Semantics *** Example: Double Beam-Splitter -Diagram of g = H oo H: +Diagram of g = H ++ H: .---. .---. --| H |-| H |-- '---' '---' @@ -15,7 +15,7 @@ State Distribution: Testing interpretation against semantics: OK *** *** Example: Two Qubits (NOT on second qubit) -Diagram of g = (H oo H) ** X: +Diagram of g = (H ++ H) ** X: .---. .---. --| H |-| H |-- '---' '---' @@ -38,7 +38,7 @@ State Distribution: Testing interpretation against semantics: OK *** *** Example: Two Qubits Swapped -Diagram of g = (H oo H) ** X oo SW: +Diagram of g = (H ++ H) ** X ++ SW: .---. .---. --| H |-| H |-. .-- '---' '---' \ / @@ -61,7 +61,7 @@ State Distribution: Testing interpretation against semantics: OK *** *** Example: Swap -Diagram of g = I ** SW oo SW ** I: +Diagram of g = I ** SW ++ SW ** I: --------. .-- \ / @@ -96,7 +96,7 @@ State Distribution: Testing interpretation against semantics: OK *** *** Example: SwapSwap -Diagram of g = SW oo X ** X oo SW: +Diagram of g = SW ++ X ** X ++ SW: .---. --. .-| X |-. .-- \ / '---' \ / @@ -119,7 +119,7 @@ State Distribution: Testing interpretation against semantics: OK *** *** Example: Swap with Y -Diagram of g = SW oo Y ** X oo SW: +Diagram of g = SW ++ Y ** X ++ SW: .---. --. .-| Y |-. .-- \ / '---' \ / @@ -143,7 +143,7 @@ Testing interpretation against semantics: OK *** The following two systems are identical *** Example: System 1 -Diagram of g = I ** H oo CX oo Z ** Z oo CX oo I ** H: +Diagram of g = I ** H ++ CX ++ Z ** Z ++ CX ++ I ** H: .---. ----------*---| Z |---*---------- | '---' | diff --git a/src/test/test_semantics.sml b/src/test/test_semantics.sml index 1e20f8f..23e3813 100644 --- a/src/test/test_semantics.sml +++ b/src/test/test_semantics.sml @@ -1,7 +1,8 @@ val () = print "Testing: Semantics\n" open Circuit Semantics -infix 4 ** infix 3 oo +infix 3 ++ +infix 4 ** fun err s = raise Fail ("TestSemantics: " ^ s) @@ -60,18 +61,18 @@ fun run t (g:t) (k:ket) : unit = in () end -val () = run "Double Beam-Splitter" (H oo H) (ket[0]) +val () = run "Double Beam-Splitter" (H ++ H) (ket[0]) -val () = run "Two Qubits (NOT on second qubit)" ((H oo H) ** X) (ket[0,1]) +val () = run "Two Qubits (NOT on second qubit)" ((H ++ H) ** X) (ket[0,1]) -val () = run "Two Qubits Swapped" ((H oo H) ** X oo SW) (ket[0,1]) +val () = run "Two Qubits Swapped" ((H ++ H) ** X ++ SW) (ket[0,1]) -val () = run "Swap" (I ** SW oo SW ** I) (ket[0,1,1]) +val () = run "Swap" (I ** SW ++ SW ** I) (ket[0,1,1]) -val () = run "SwapSwap" (SW oo X ** X oo SW) (ket[1,0]) +val () = run "SwapSwap" (SW ++ X ** X ++ SW) (ket[1,0]) -val () = run "Swap with Y" (SW oo Y ** X oo SW) (ket[1,0]) +val () = run "Swap with Y" (SW ++ Y ** X ++ SW) (ket[1,0]) val () = print "The following two systems are identical\n" -val () = run "System 1" ((I ** H) oo C X oo (Z ** Z) oo C X oo (I ** H)) (ket[1,0]) +val () = run "System 1" ((I ** H) ++ C X ++ (Z ** Z) ++ C X ++ (I ** H)) (ket[1,0]) val () = run "System 2" (I ** X) (ket[1,0])