-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEquality.qs
More file actions
27 lines (24 loc) · 1.35 KB
/
Equality.qs
File metadata and controls
27 lines (24 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace ExpressionsExamples {
open Microsoft.Quantum.Intrinsic;
/// # Summary
/// The collection of examples of equality expressions.
operation EqualityExamples() : Unit {
Message("============================== Q# expressions: equality ==============================");
// Equality and inequality operators check whether their operands are equal.
// They are defined for types Int, BigInt, Double, String, Bool, Result, Pauli, and Qubit.
Message($"intEquality = {42 == 10 * 4}"); // false
Message($"bigIntEquality = {13L == 0b1101L}"); // true
Message($"doubleInequality = {1. / 0. != 2. / 0.}"); // false - both are Infinity
Message($"stringInequality = {"hi" != "HI"}"); // true
Message($"boolEquality = {true == false}"); // false
Message($"resultInequality = {Zero != One}"); // true
Message($"pauliEquality = {PauliX == PauliZ}"); // false
// Qubit variables equality compares the qubits they point to, rather than their states.
// Allocate two qubits in the |0⟩ state.
use (a, b) = (Qubit(), Qubit());
Message($"sameStatesAreEqual = {a == b}"); // false
// Copy variable b to variable c.
let c = b;
Message($"sameQubitsAreEqual = {b == c}"); // true
}
}