Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kronecker product & new (superpos) #3

Open
mgraffam opened this issue Jun 18, 2020 · 0 comments
Open

Kronecker product & new (superpos) #3

mgraffam opened this issue Jun 18, 2020 · 0 comments

Comments

@mgraffam
Copy link

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))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant