Get your hands dirty before we prove anything
This lab uses N=16 and D=4 so you can see every single coefficient clearly. Try editing the query and your selected corpus vector. Toggle between the natural and reversed packing. The JointJS contribution graph will actually trace every single term that reaches your selected coefficient!
Worked example
Picking a good diagnostic input
Using all-ones vectors is actually a terrible first test, because a lot of incorrect pairings will still accidentally add up to 4! Try using q=[1,2,4,8] and v=[3,5,7,11] instead. Having distinct contributions makes it really obvious if a coordinate gets swapped. Designing good tests is a real part of mathematical reasoning: your examples should be able to tell the difference between your intended invariant and a plausible bug.
Check your understanding
When natural order fails but reversed order succeeds for a bunch of values you edited, what has the lab actually established?
Lab summary
- Natural order forces us along the anti-diagonals.
- Reversed blocks perfectly align matching logical coordinates.
- Our target coefficient perfectly equals the direct dot product.
- JointJS lets us expose and see the contributing terms, rather than hiding the math.
Repository layer · second pass
What should an experiment establish before we attempt a proof?
The laboratory lets you edit coordinates, switch between natural and reversed packing, and inspect which product nodes feed a chosen coefficient. Experiments reveal the invariant and catch index mistakes; they do not prove correctness for every value or dimension.
Use adversarial values rather than symmetric friendly ones. Distinct primes, negative signs, zeros, and one-hot vectors make it possible to identify which logical product reached a coefficient. If every value is one, many incorrect pairings produce the same total.
Reasoning chain
- 1
Predict the target before running.
- 2
Choose distinguishable coordinate values.
- 3
Trace one matching and one nonmatching product.
- 4
Switch layout while holding values constant.
- 5
Record what evidence supports the invariant.
- 6
State what remains for symbolic proof.
Worked trace
One-hot probes identify routing
- Set q coordinate 2 to one and all others zero.
- Set v coordinate 2 to seven and all others distinct.
- Reversed packing places their product at the target.
- Natural packing places it at destination 4 instead.
Result. The probe tests routing independently of accumulation complexity.
Executable lens · Python
Make the hidden state visible
def one_hot(size, index, value=1):
out = [0] * size
out[index] = value
return out
q, v = one_hot(4,2), one_hot(4,2,7)
assert sum(a*b for a,b in zip(q,v)) == 7Retype this example, predict each intermediate value, and then change one input that touches a boundary.
Misconception clinic
Tempting mistakes
- Calling many passing random tests a proof.
- Using values that allow wrong terms to cancel invisibly.
Retrieval and transfer
Close the book first
- Design a probe for every coordinate of D=5.
- Find a natural-order case that accidentally passes.
- Write a property-based test over several D values.