Quantum Circuits

QBit

import spire.math._

import axle.quantumcircuit._
import axle.syntax.kolmogorov._
import axle.algebra.RegionEq

val sqrtHalf = Complex(Real(1) / sqrt(Real(2)), Real(0))

val qEven = QBit[Real](sqrtHalf, sqrtHalf)

val distribution = qEven.cpt
distribution.P(RegionEq(CBit0))
// res0: Real = Inexact(
//   f = spire.math.Real$$Lambda$10869/0x00000008027fe1b8@3767f5c1
// )

distribution.P(RegionEq(CBit1))
// res1: Real = Inexact(
//   f = spire.math.Real$$Lambda$10869/0x00000008027fe1b8@282da99e
// )

Dirac Vector Notation

import axle.quantumcircuit._
import axle.algebra.Binary
|("00").>().unindex
// res3: Vector[Binary] = Vector(
//   axle.algebra.B1$@38430e08,
//   axle.algebra.B0$@650fccb5,
//   axle.algebra.B0$@650fccb5,
//   axle.algebra.B0$@650fccb5
// )

Vector[Binary](1, 0) ⊗ Vector[Binary](1, 0)
// res4: Vector[Binary] = Vector(
//   axle.algebra.B1$@38430e08,
//   axle.algebra.B0$@650fccb5,
//   axle.algebra.B0$@650fccb5,
//   axle.algebra.B0$@650fccb5
// )

CNOT

import axle.quantumcircuit._
import axle.quantumcircuit.QBit._
import spire.algebra.Field
import spire.math.Real

implicit val fieldReal: Field[Real] = new spire.math.RealAlgebra()
val QBit0 = constant0[Real]
val QBit1 = constant1[Real]
QBit2.cnot(QBit2(QBit0.unindexQBit0.unindex)).unindex
// res6: Vector[spire.math.Complex[Real]] = Vector(
//   Complex(real = Exact(n = 1), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0))
// )

QBit2.cnot(QBit2(QBit0.unindexQBit1.unindex)).unindex
// res7: Vector[spire.math.Complex[Real]] = Vector(
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 1), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0))
// )

QBit2.cnot(QBit2(QBit1.unindexQBit0.unindex)).unindex
// res8: Vector[spire.math.Complex[Real]] = Vector(
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 1), imag = Exact(n = 0))
// )

QBit2.cnot(QBit2(QBit1.unindexQBit1.unindex)).unindex
// res9: Vector[spire.math.Complex[Real]] = Vector(
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 1), imag = Exact(n = 0)),
//   Complex(real = Exact(n = 0), imag = Exact(n = 0))
// )

Future Work

Later