Documentation

Kraus.Qubit

Qubits #

def transl₂ :
Fin 2 × Fin 2Fin 4

To use Fin 4 × Fin 4 matrices to manipulate 2 qubits.

Equations
Instances For
    def transl₃ :
    Fin 2 × Fin 2 × Fin 2Fin 8

    To use Fin 8 × Fin 8 matrices to manipulate 3 qubits.

    Equations
    Instances For
      def transl₃'' :
      (Fin 2 × Fin 2) × Fin 2Fin 8

      An "associative variant" for using Fin 8 × Fin 8 matrices to manipulate 3 qubits.

      Equations
      Instances For
        noncomputable def transl3 {a b : } :
        (Fin bFin a)Fin (a ^ b)
        Equations
        Instances For
          def transl {a b : } :
          (Fin bFin a)Fin (a ^ b)
          Equations
          Instances For
            def transl₃' :
            Fin 2 × Fin 2 × Fin 2Fin 8
            Equations
            Instances For
              def translate₂ :
              Matrix (Fin 4) (Fin 4) Matrix (Fin 2 × Fin 2) (Fin 2 × Fin 2)
              Equations
              Instances For
                def translate₃ :
                Matrix (Fin 8) (Fin 8) Matrix (Fin 2 × Fin 2 × Fin 2) (Fin 2 × Fin 2 × Fin 2)
                Equations
                Instances For
                  def translate₃' :
                  Matrix (Fin 8) (Fin 8) Matrix ((Fin 2 × Fin 2) × Fin 2) ((Fin 2 × Fin 2) × Fin 2)
                  Equations
                  Instances For
                    def toffoli₀ :
                    Matrix (Fin 8) (Fin 8)
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      def cnot₀ :
                      Matrix (Fin 4) (Fin 4)
                      Equations
                      • cnot₀ = !![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 0]
                      Instances For
                        def toffoli :
                        Matrix (Fin 2 × Fin 2 × Fin 2) (Fin 2 × Fin 2 × Fin 2)
                        Equations
                        Instances For
                          def toffoli' :
                          Matrix ((Fin 2 × Fin 2) × Fin 2) ((Fin 2 × Fin 2) × Fin 2)
                          Equations
                          Instances For
                            def cnot :
                            Matrix (Fin 2 × Fin 2) (Fin 2 × Fin 2)
                            Equations
                            Instances For
                              theorem toffoli_unchange {a b c : Fin 2} (h : ¬(a = 1 b = 1)) :
                              toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e c)) = Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e c))
                              theorem toffoli_change (c : Fin 2) :
                              toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e c)) = Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e (1 - c)))
                              theorem kroneckerMap_injective {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {w : Matrix α β } (hw : w 0) {x y : Matrix (α × γ) (β × δ) } (h₂ : Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) w x = Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) w y) :
                              x = y
                              theorem kroneckerMap_injective₀ {α : Type u_1} {β : Type u_2} {w : Matrix α β } (hw : w 0) {x y : Matrix α β } (h₂ : Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) w x = Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) w y) :
                              x = y
                              theorem e_ne_zero {z : Fin 2} :
                              e z 0
                              theorem toffoli_characterize (a b c : Fin 2) :
                              toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e c)) = if a = 1 b = 1 then Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e (1 - c))) else Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e c))
                              theorem negation_using_toffoli (a : Fin 2) :
                              toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e 1)) = Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e (1 - a)))

                              If we inspect the third qubit on input (a,1,1) we find 1-a.

                              theorem partialTraceLeft_tensor_rankOne_basis {R : Type u_1} [RCLike R] {k : Type u_2} [Fintype k] [DecidableEq k] (i : k) (M : Matrix (k × k) (Fin 1 × Fin 1) R) :
                              partialTraceLeft (pureState' (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e i) M)) = pureState' M
                              theorem partialTraceLeft_tensor_rankOne_basis' {R : Type u_1} [RCLike R] {k : Type u_2} [Fintype k] [DecidableEq k] (i : k) (M : Matrix k (Fin 1) R) :
                              partialTraceLeft (pureState' (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e i) M)) = pureState' M
                              theorem negation_using_toffoli'' (a : Fin 2) :
                              have t := toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e 1)); partialTraceLeft (pureState' t) = pureState' (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e (1 - a)))
                              theorem negation_using_toffoli' (a : Fin 2) :
                              partialTraceLeft (partialTraceLeft (pureState' (toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e 1))))) = pureState' (e (1 - a))

                              May 21, 2026. Best result so far on computing negation using Toffoli gate.

                              noncomputable def bit_from_pureState (M : Matrix (Fin 2) (Fin 2) ) :
                              Matrix (Fin 1) (Fin 1)
                              Equations
                              Instances For
                                theorem bit_from_pureState_eq (i : Fin 2) :
                                bit_from_pureState (pureState' (e i)) = !![i]
                                theorem negation_using_toffoli''' (a : Fin 2) :
                                bit_from_pureState (partialTraceLeft (partialTraceLeft (pureState' (toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e 1) (e 1)))))) 0 0 = 1 - a
                                theorem scratch_off_tensor_general {R : Type u_1} [RCLike R] {i : Fin 2} (M : Matrix (Fin 2 × Fin 2) (Fin 1 × Fin 1) R) :
                                partialTraceLeft (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e i) M * (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e i) M).conjTranspose) = M * M.conjTranspose
                                theorem scratch_off_tensor {R : Type u_1} [RCLike R] {i j k : Fin 2} :
                                have v := Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e i) (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e j) (e k)); have B := v * v.conjTranspose; have Bl := partialTraceLeft B; Bl = Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e j) (e k) * (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) (e j) (e k)).conjTranspose

                                correct acc. to https://chatgpt.com/c/6a0ba46b-6c94-83e8-8262-52b4a2dc0954 This can be used to compute negation using the Toffoli gate.

                                theorem toffoli_characterize.TFAE (a b c : Fin 2) :
                                [a = 1 b = 1, toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e c)) = Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e (1 - c))), toffoli * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e c)) Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e a) (Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e b) (e c))].TFAE

                                The usual characterization of the behavior of the Toffoli gate: the target bit (third bit) will be inverted if and only if the first and second bits are both 1 from https://en.wikipedia.org/wiki/Toffoli_gate

                                Prove that toffolo is a unitary circuit.

                                noncomputable def toffoli_probability (startState : Matrix (Fin 2 × Fin 2 × Fin 2) (Fin 1 × Fin 1 × Fin 1) ) :
                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  noncomputable def toffoli_probability'' (startState : Fin 2 × Fin 2 × Fin 2) :

                                  May 11, 2026. Using *ᵥ to simplify matrix structure.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    noncomputable def toffoli_probability' (startState : Matrix (Fin 2 × Fin 2 × Fin 2) (Fin 1 × Fin 1 × Fin 1) ) :
                                    Equations
                                    Instances For
                                      def ket₀ :
                                      Matrix (Fin 2) (Fin 1)
                                      Equations
                                      Instances For
                                        noncomputable def proj₀ :
                                        Matrix (Fin 2) (Fin 2)
                                        Equations
                                        Instances For
                                          noncomputable def first_qubit_proj₀ :
                                          Matrix (Fin 2 × Fin 2 × Fin 2) (Fin 2 × Fin 2 × Fin 2)
                                          Equations
                                          Instances For
                                            noncomputable def gate_probability (startState : Matrix (Fin 2 × Fin 2 × Fin 2) (Fin 1 × Fin 1 × Fin 1) ) :
                                            Equations
                                            Instances For
                                              theorem cnot_basis (i j : Fin 2) :
                                              cnot * Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e i) (e j) = if i = 0 then Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e i) (e j) else Matrix.kroneckerMap (fun (x1 x2 : ) => x1 * x2) (e i) (e (1 - j))
                                              Equations
                                              Instances For
                                                theorem isOne :
                                                1 = !![1, 0; 0, 1]
                                                def f {a b : } :
                                                Fin a × Fin b Fin a × Fin bFin a × Fin b × Fin 2
                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For
                                                  def split {a b : } :
                                                  Fin a × Fin b × Fin 2Fin a × Fin b Fin a × Fin b
                                                  Equations
                                                  Instances For
                                                    def split' {a b : } :
                                                    Fin 2 × Fin a × Fin bFin a × Fin b Fin a × Fin b
                                                    Equations
                                                    Instances For
                                                      noncomputable def quantumCircuit (A : Matrix (Fin 2 × Fin 2) (Fin 2 × Fin 2) ) (σ : Equiv.Perm (Fin 2 × Fin 2 × Fin 2)) :
                                                      Matrix (Fin 2 × Fin 2 × Fin 2) (Fin 2 × Fin 2 × Fin 2)

                                                      Given a circuit A that only touches 2 qubits, and a permutation P of 3 qubits, get a unitary as Pᵀ Q P where Q = A ⊕ I.

                                                      Equations
                                                      Instances For
                                                        def Matrix.fromBlocks_id {a b : } (A : Matrix (Fin a × Fin b) (Fin a × Fin b) ) :
                                                        Matrix (Fin a × Fin b Fin a × Fin b) (Fin a × Fin b Fin a × Fin b)
                                                        Equations
                                                        Instances For
                                                          def Matrix.fromBlocks_split' {a b : } (A : Matrix (Fin a × Fin b) (Fin a × Fin b) ) :
                                                          Matrix (Fin 2 × Fin a × Fin b) (Fin 2 × Fin a × Fin b)
                                                          Equations
                                                          Instances For
                                                            def Matrix.prod_sum {a b : } :
                                                            Matrix (Fin 2 × Fin a × Fin b) (Fin a × Fin b Fin a × Fin b)
                                                            Equations
                                                            Instances For
                                                              def Matrix.sum_prod {a b : } :
                                                              Matrix (Fin a × Fin b Fin a × Fin b) (Fin 2 × Fin a × Fin b)
                                                              Equations
                                                              Instances For
                                                                theorem fromBlocks_unitary (A : (unitary (Matrix (Fin 2 × Fin 2) (Fin 2 × Fin 2) ))) :
                                                                Matrix.fromBlocks (↑A) 0 0 1 unitary (Matrix (Fin 2 × Fin 2 Fin 2 × Fin 2) (Fin 2 × Fin 2 Fin 2 × Fin 2) )
                                                                def quantumCircuitUnitary'' (A : (unitary (Matrix (Fin 2 × Fin 2) (Fin 2 × Fin 2) ))) :
                                                                (unitary (Matrix (Fin 2 × Fin 2 Fin 2 × Fin 2) (Fin 2 × Fin 2 Fin 2 × Fin 2) ))
                                                                Equations
                                                                Instances For