Kronecker product & new (superpos)
- Dominant language
- Common Lisp
- Stars
- 6
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Below is some quick code I've put together while playing with this library. I've just started reading up on Quantum computing, so I'm not 100% clear on how the kronecker product is to be applied when working with a subset of qubits, but I've validated that it works properly for the spanning/parallel case. I.e. apply-qgate with H*H matrix works properly for the Hadamard to a two-qubit pair.
; More efficient construction of the superposition. On my test system constructing a 14-bit
; superposition takes 3.5 seconds with the original code. This code takes 3 milliseconds.
(defun superpos (bits &optional (zero 0))
(let ((outrep (make-list (expt 2 (length bits)) :initial-element zero))
(index (reduce (lambda (current previous) (+ (* current 2) previous)) bits)))
(setf (elt outrep index) (+ zero 1))
outrep))
; Kronecker / tensor product
(defun kronecker-product(A B)
(matrix-create
(lambda (i j)
(let ((p (matrix-row-count B))
(q (matrix-column-count B)))
(* (elt (elt A (floor i p)) (floor j q))
(elt (elt B (mod i p)) (mod j q)))))
(* (matrix-row-count A) (matrix-row-count B))
(* (matrix-column-count A) (matrix-column-count B))))
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.