Skip to content

Null-byte-00/qc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QC: Quantum Computing Simulator library for C

QC
QC is a minimalistic C library for simulating quantum circuits and algorithms

Basics

defining qubits

defining a zero qubit:

Q q = zero_qubit();

defining a one qubit:

Q q = one_qubit();

defining a qubit with different probabilities

Q q = new_qubit(1,1);

the first parameter of new_qubit function is probability of qubit being zero and the second is the probability of it being one
note: new_qubit function normalizes the values so in this example both probabilities will be 1/sqrt(2) or 0.7071

defining qubit groups

defining a group of two qubits

Q q0, q1;
Q2 q_group = {q0, q1};

defining group of three qubits

Q q0,q1,q2;
Q3 q_group = {q0, q1, q2};

Gates

Pauli-X gate:
pauli_x() or X()
Pauli-Y gate:
pauli_y() or Y()
Pauli-Z gate:
pauli_z() or Z()
Hadamard gate:
hadamard() or H()
Phase gate:
phase() or P()
T gate:
t_gate() or T()
Controlled NOT Gate:
cnot()
Controlled Z Gate:
cz()
Controlled S Gate:
cs()
Toffoli (CCNOT) Gate:
ccnot()

Measuring

getting probability of qubit being zero:

float zero_prob = zero_chance(q);

getting probability of qubit being one:

float one_prob = one_chance(q);

measuring the value based on probabilities

int result = measure(q); // always 1 or 0

Example

Bell state:

#include<stdio.h>
#include "qc.h"

int main() {
    Q q0 = one_qubit();
    Q q1 = zero_qubit();
    q0 = H(q0);
    Q2 q_group = cnot(q0, q1);
    q0 = q_group.first;
    q1 = q_group.second;

    printf("Q0:\n");
    printf("Zero Probability: %lf \n",  zero_chance(q0)); // 0.5
    printf("One Probability: %lf \n",  one_chance(q0)); // 0.5
    printf("Measured: %d\n", measure(q0));
    printf("Q1:\n");
    printf("Zero Probability: %lf \n", zero_chance(q1)); // 0.5
    printf("One Probability: %lf \n", one_chance(q1)); // 0.5
    printf("Measured: %d\n", measure(q1));
}

Donation

If you found this useful and would like to support, you can send donations to this XMR address: 43EfpCz23b5WPgzaw6UVnF9KsbvueFUumTuk3yMJ8acQbPPFoxgHfq6LE2qD8gNfR3j6Fzc4oGvXRCHvvfmdsYEvPtUXK2v