diff options
| author | hachem <im@hachem.wtf> | 2026-09-06 18:53:29 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-06 18:53:29 +0200 |
| commit | ab08fa6065b5b08627b51203eb92ef65ed7b5ea2 (patch) | |
| tree | 09a22fbfcf95a7fd74edeb0dd3af9a6320f66b3a /tester | |
| parent | 565af48c1eff190ce836293a0eda75c0dc695c82 (diff) | |
c: quantum gate and state foundations
Diffstat (limited to 'tester')
| -rw-r--r-- | tester/main.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tester/main.c b/tester/main.c index 334291f..cba5d28 100644 --- a/tester/main.c +++ b/tester/main.c @@ -1,5 +1,6 @@ #include <stdio.h> +#include "core/quantum_components.h" #include "maths/complex.h" #include "maths/matrix.h" #include "maths/vector.h" @@ -60,5 +61,21 @@ int main(void) psi_free_matrix(&m); psi_free_matrix(&mm); + double inv_sqrt2 = 0.7071067811865475; + struct PsiMatrix h = psi_matrix(2, 2, + psi_new_complex(inv_sqrt2, 0.0), psi_new_complex(inv_sqrt2, 0.0), + psi_new_complex(inv_sqrt2, 0.0), psi_new_complex(-inv_sqrt2, 0.0)); + struct PsiQuantumGate gate = psi_new_quantum_gate_from_matrix("H", h); + + struct PsiVector s0 = psi_new_state_0(); + struct PsiVector hs0 = psi_mul_vector_matrix(s0, gate.matrix); + + printf("gate = %s (%zu qubit)\n", gate.name, gate.num_qubits); + printf("H|0> = [%g, %g]\n", hs0.data[0].real, hs0.data[1].real); + + psi_free_vector(&s0); + psi_free_vector(&hs0); + psi_free_quantum_gate(&gate); + return 0; } |
