Cosine similarity adds vector lengths. Squared norms are exact, while the square-root lengths are named instead of decimalized.

highlighted = computed this step

Cosine is the named boundary

Cosine divides a dot product by the two vector lengths. The squared norms are exact, but each length introduces a square root.

cos(u,v)=uvuv,u=uu\cos(u,v)=\frac{u\cdot v}{\|u\|\|v\|},\quad \|u\|=\sqrt{u\cdot u}
Cosine named boundaryThe square-root lengths are named, not decimalized.Cosine named boundaryThe square-root lengths are named, not decimalized.exact dot productstie-break: lexicographically smallest word among max dot productsvectors:cat=(3,1); kitten=(2,1); car=(1,3)pairdotcosine named boundarycat·kitten77/(√10·√5)cat·car66/(√10·√10)kitten·car55/(√5·√10)nearest to cat by dot=kitten (dot=7)√ is named; no decimal cosine is pinned

Exact squared norms

The squared norms are cat dot cat = 10, kitten dot kitten = 5, and car dot car = 10. Therefore cosine(cat, kitten) is named as 7 over sqrt(10) times sqrt(5).

7105\frac{7}{\sqrt{10}\sqrt{5}}
Cosine named boundaryThe square-root lengths are named, not decimalized.Cosine named boundaryThe square-root lengths are named, not decimalized.exact dot productstie-break: lexicographically smallest word among max dot productsvectors:cat=(3,1); kitten=(2,1); car=(1,3)pairdotcosine named boundarycat·kitten77/(√10·√5)cat·car66/(√10·√10)kitten·car55/(√5·√10)nearest to cat by dot=kitten (dot=7)√ is named; no decimal cosine is pinned

Summary

The dot products stay exact integers. The square-root length is the named non-exact step here, so the diagram renders 7/(sqrt(10)*sqrt(5)) as a symbol and never as a decimal.

named   boundary; no decimal cosine\text{named }\sqrt{\ } \text{ boundary; no decimal cosine}
Cosine named boundaryThe square-root lengths are named, not decimalized.Cosine named boundaryThe square-root lengths are named, not decimalized.exact dot productstie-break: lexicographically smallest word among max dot productsvectors:cat=(3,1); kitten=(2,1); car=(1,3)pairdotcosine named boundarycat·kitten77/(√10·√5)cat·car66/(√10·√10)kitten·car55/(√5·√10)nearest to cat by dot=kitten (dot=7)√ is named; no decimal cosine is pinned