-
Notifications
You must be signed in to change notification settings - Fork 1
1. 🗺️ Language Features and Syntax
Gabriele Messina edited this page Aug 19, 2024
·
2 revisions
bool a = true;
int b = 10;
string c = "Hello";
qubit d = 1q;
quint e = 10q;
bool b = false;
{
int b = 100; //this int b overrides the upper bool b.
}
b = true; //this b refers to the bool b.
int a = 10;
quint b = 10q;
print b;
bool b = true;
if(b){
//Do something.
}
if(!b){
//Do something.
}
else{
//Do something else.
}
if(b){
//Do something.
}
else if(true){
//Do something else.
}
bool b = true;
while(b){
//Do something while b == true.
b = false;
}
do{
//Do something until b == false.
b = true;
}
while(!b)
//alpha and beta values
qubit a = 0.7,0.3q;
//states we want the qubit to be able to take
qubit b = [0, 1]q;
//shorter syntax for a qubit that takes only the zero value
qubit c = 0q;
//special syntax for common superposition
qubit d = |+>;
qubit e = |->;
//quint with 2^4 qubits that represent the number 10.
quint a = 10q;
//quint representing the number 1
quint b = [0q, 0q, 1q]q;
//quint with a superposition state where the most significant bit can be 0(70%) or 1(30%)
quint c = [0.7,0.3q, 0q, 1q]q;
//quint with a superposition state where the most significant bit can be 0(50%) or 1(50%)
quint d = [[0, 1]q, 0q, 1q]q;
//quint with a superposition state that can be both 1(50%) or 3(50%)
quint e = [1, 3]q;
//quint representing the string "111010010"
qustring a = "111010010";
//quint representing the strings "111010010" and "111010011"
qustring a = "11101001*";
> Right now, qustring handles only a 2-character alphabet of '0' and '1'. This is needed for the circuit to run on the Qiskit simulator; otherwise, it will need too many qubits.
qubit a = 1q;
qubit b = 1q;
not a;
pauliz a;
hadamard a;
quint c = a + b;
//Explicit measure
qubit a = [1]q;
qubit b = [1]q;
quint x = a + b;
measure x;
//Implicit measure
qubit a = [true]q;
qubit b = [true]q;
int classical = a + b;
quint sum(quint a, quint b){
return a+b;
}
quint z = 1q;
quint y = 3q;
quint c = sum(z, y);
print c;
string[] foo = ["1","0","1","0","1","0","1","0"];
qubit[] fas = [0q, 1q, |+>];
print foo[1];
print fas;
qustring a = "00111111";
if("01" in a){
print "Element found.";
}
else{
print "Element not found.";
}
qubit b = 1q;
qubit c = 0q;
qubit[] a = [b, c, |+>];
foreach qubit q in a{
print q;
}
//or
foreach qubit q, int index in a{
print a[index];
}