Lesson 9 of 9 · Capstone derivation
Absolute rotations reveal relative distance.
Your win: derive the RoPE identity from first principles, audit its sign, and teach the algorithm back without notes.
Set up two absolute positions
Let the query be at position \(m\) and the key at position \(n\). For one dimension pair with frequency \(\theta\):
To keep notation light, write \(R_m\) for \(R_{m\theta}\) and \(R_n\) for \(R_{n\theta}\).
Derive the score
- Substitute the rotated query and key.
- Use \((A\mathbf x)^{\mathsf T}=\mathbf x^{\mathsf T}A^{\mathsf T}\).
- Use \(R_m^{\mathsf T}=R_{-m}\): transpose reverses the query rotation.
- Use \(R_\alpha R_\beta=R_{\alpha+\beta}\): \(-m+n=n-m\).
Numbers substituted: \(m=5\), \(n=8\), \(\theta=0.1\)
The absolute angles are \(0.5\) and \(0.8\) radians. Their difference is \(0.3\) radians. Substitute numerical sine and cosine values:
The matrix product is the rotation for \((n-m)\theta=(8-5)(0.1)=0.3\) radians.
Numbers substituted: the resulting score
Take \(\mathbf q=\mathbf k=(1,0)\). The rotated vectors are \((\cos0.5,\sin0.5)\) and \((\cos0.8,\sin0.8)\). Their dot product is:
The two absolute angles disappear from the final comparison; only their \(0.3\)-radian separation remains.
Exact values: \(m=2\), \(n=7\), \(\theta=\pi/6\)
mθ = 1.75nθ = 2.80relative angle (n−m)θ = 1.05 rad
Restore all dimension pairs
The full \(R_m\) is block diagonal. Pair \(i\) uses angle \(m\theta_i\), but the same identity holds in every block:
Final retrieval check
What relative rotation appears in \((R_m\mathbf q)^{\mathsf T}(R_n\mathbf k)\)?
Capstone exercises
- Derive \((R_2\mathbf q)^{\mathsf T}(R_7\mathbf k)=\mathbf q^{\mathsf T}R_5\mathbf k\) one line at a time.
- If \(\theta=0.2\), \(m=3\), and \(n=9\), calculate both absolute angles and the relative angle.
- Expand \(R_\theta^{\mathsf T}\) and prove directly that it equals \(R_{-\theta}\).
- Explain why rotating both vectors by the same extra offset \(c\) does not change their relative rotation.
- Find and correct the sign inconsistency in the supplied second image.
- Without notes, give the five-part teach-back listed below.
Check solutions
- \((R_2\mathbf q)^{\mathsf T}(R_7\mathbf k)=\mathbf q^{\mathsf T}R_2^{\mathsf T}R_7\mathbf k=\mathbf q^{\mathsf T}R_{-2}R_7\mathbf k=\mathbf q^{\mathsf T}R_5\mathbf k\).
- \(m\theta=0.6\), \(n\theta=1.8\), and \((n-m)\theta=1.2\) radians.
- Swap rows and columns, then use cosine evenness and sine oddness.
- \((n+c)-(m+c)=n-m\).
- The headline says \(R_{m-n}\); under the displayed convention it should say \(R_{n-m}\).
- Use the rubric below; ask the teaching agent for assessment.
Two-minute teach-back
- Why does RoPE group dimensions in pairs?
- What does position \(m\) do to pair \(i\)?
- Why does the rotation preserve vector magnitude?
- Why is the transpose a negative rotation?
- How does the dot product turn \(m\) and \(n\) into \(n-m\)?
Evidence of mastery is not recognizing the answer on this page. It is reconstructing the chain after a delay and applying it to a fresh \(m,n,\theta\) example.
Primary source: Su et al., RoFormer, Sections 3.1–3.2, especially Equations 11–16.
Ask the teaching agent to assess your teach-back. A passed teach-back should become the first learning record and determine what comes next.