Math toolkit
Bits, XOR and bit strings
x ⊕ y, x · z mod 2, sums over {0,1}ⁿ, and signs that depend on f(x)
In the app every question checks your answer and explains a wrong one.
Addition mod 2
XOR, written , is addition mod 2: add the bits and keep only whether the total is even (0) or odd (1). So , and . Three facts do most of the work in these lessons:
- and , the flipped bit;
- , so XOR-ing the same bit in twice undoes it;
- order and grouping don’t matter, so is 1 exactly when an odd number of the bits are 1.
CNOT is XOR made reversible. On the two-qubit basis state (first bit , second bit ) it keeps its control and XORs it into the target, (Lesson 6).
Check yourself
Compute .
Hint
- How many of the bits are 1?
Show the answer
Answer:
Four 1s, an even number: .
Common slips
- : That is the ordinary sum. Mod 2 keeps only whether it is odd or even, and 4 is even, so the answer is 0.
- : Count the 1s: there are four, an even number, so the XOR is 0. Pairing them up helps: twice.
Bit strings and the dot product mod 2
An -bit string is one of the elements of , and it also names a basis state of qubits, written as the ket . XOR of two strings works bit by bit: . The dot product mod 2 multiplies matching bits and adds the results mod 2:
With ordinary sums, as the diagnostic in Lesson 0 writes it, that is
The two agree, because XOR-ing bits together is adding them and keeping only whether the total is odd. Either way, is 1 exactly when and share an odd number of 1s. It appears in the Deutsch–Jozsa algorithm of Lesson 9.
Worked example
1011 · 1110
Line the strings up and multiply bit by bit: , , , .
Add mod 2: . The strings share two 1s (first and third places), an even number, so and .
Your turn
Compute .
Hint
- In how many places do both strings have a 1?
Show the answer
Answer:
Matching products: . Three shared 1s, an odd number, so .
Common slips
- : That is the ordinary dot product, the number of shared 1s. Mod 2 keeps only whether it is odd: 3 is odd, so the answer is 1.
Check yourself
Using , compute .
Hints
- Multiply the two strings place by place. How many places have a 1 in both?
- Add those products as ordinary numbers, then keep only the remainder on division by 2.
- The products are 1, 1, 0, 0, 1.
Show the answer
Answer:
, and : 3 shared 1s, an odd number.
Line the strings up: 11011 over 11101. The products are 1, 1, 0, 0, 1, so the ordinary sum is . Reduce mod 2: , so and the sign is .
Common slips
- : 3 is the ordinary sum, the number of places where both strings have a 1. The dot product keeps only whether that is odd: 3 is odd, so .
- : 11001 is the string of bit-by-bit products (the AND of and ). is a single bit: add those products and keep the remainder mod 2, which gives .
Sums over all strings, and signs
A sum has one term for each of the strings: for , the four terms . Deutsch’s algorithm turns a bit into a sign, : when and when . Signs multiply the way bits add, , and depends only on whether is even. One consequence: is when is constant and 0 when is balanced (as many 0s as 1s).
Check yourself
Let and . Compute .
Hint
- Write the four signs out, one per string.
Show the answer
Answer:
. This is neither constant nor balanced.
Common slips
- : That adds the values themselves. Each term is a sign: for and for the other three.
- : Right size, wrong sign: gives , and three of the four terms have , so the total is .
- : A total of 0 needs a balanced , two 0s and two 1s. This has one 0 and three 1s, so the signs do not cancel: .
Check yourself
Compute , where is the dot product mod 2.
Hint
- Find for each of 00, 01, 10, 11 first.
Show the answer
Answer:
The dot products are 0, 1, 1, 0, so the signs are and they cancel. For any , : half the strings give each sign. That fact is the heart of the Deutsch–Jozsa calculation.
Common slips
- : That counts the terms without their signs. and each share one 1 with 11, so and those two terms are .
- : shares two 1s with 11, so and its sign is . The four signs are .
Go further
Free resources for when you want more than this refresher covers.
- Exclusive orWikipedia · Article
XOR’s algebra and its uses in binary adders, parity bits and simple ciphers such as the one-time pad.
- Hadamard transformWikipedia · Article
The ±1 matrix behind sums of (−1)^(x·z), with its uses in quantum algorithms, signal processing and video compression.
- Fundamentals of quantum algorithms: The Deutsch–Jozsa algorithmJohn Watrous, IBM Quantum · Course
Goes on to the Bernstein–Vazirani problem, which uses the dot product mod 2 to find a hidden bit string in one query.
Lessons that use it
- Lesson 0: Orientation and diagnosticHow the lessons work, five key words, how states are written, and a quick check of the math the lessons assume
- Lesson 6: Many bits: tensor products, CNOT and reversible logicCombine qubits with ⊗, flip bits with CNOT and Toffoli, and see why every gate must be reversible
- Lesson 9: Parallelism, Deutsch and Deutsch–JozsaOne query, one global answer: phase kickback and interference