Exercise 6.1.
Use additive exponent arithmetic inside the multiplicative notation: (𝐿𝛿−1)2(𝛿𝑇−1)2=𝐿2𝛿−2𝛿2𝑇−2=𝐿2𝑇−2. The exponent of 𝛿 is −2 +2 =0, so the dimension variable cancels. The remaining base exponents are 𝐿 :2 and 𝑇 : −2.
Similarly, 𝑀𝐿𝑇−2⋅𝐿−1𝑇=𝑀𝐿1−1𝑇−2+1=𝑀𝑇−1. Here 𝐿 cancels. The surviving base exponents are 𝑀 :1 and 𝑇 : −1.
Exercise 6.2.
Give 𝑥 type 𝖭𝗎𝗆[𝛿]. Two variable leaves and D-Mul give 𝑥:𝖭𝗎𝗆[𝛿]⊢𝑥:𝖭𝗎𝗆[𝛿]𝑥:𝖭𝗎𝗆[𝛿]⊢𝑥:𝖭𝗎𝗆[𝛿]𝑥:𝖭𝗎𝗆[𝛿]⊢𝑥∗𝑥:𝖭𝗎𝗆[𝛿2]D−Mul. Lambda introduction yields ⊢𝜆𝑥.𝑥∗𝑥:𝖭𝗎𝗆[𝛿]→𝖭𝗎𝗆[𝛿2]. Since 𝛿 is absent from the empty context, generalization gives 𝗌𝗊𝗎𝖺𝗋𝖾:∀𝛿.𝖭𝗎𝗆[𝛿]→𝖭𝗎𝗆[𝛿2].
For the second term, run the algorithm rather than guessing its argument types. The two lambda clauses begin with fresh ordinary variables 𝑥 :𝛼 and 𝑦 :𝛽. The multiplication clause introduces fresh dimension variables 𝛿1,𝛿2 and generates 𝛼≐𝖭𝗎𝗆[𝛿1],𝛽≐𝖭𝗎𝗆[𝛿2]. For the division, its left operand has dimension 𝛿1𝛿2, while the second occurrence of 𝑦 is already forced to 𝖭𝗎𝗆[𝛿2]. Renaming the two principal dimension parameters to 𝛿,𝜖, the algorithm returns 𝑥∗𝑦:𝖭𝗎𝗆[𝛿𝜖],(𝑥∗𝑦)/𝑦:𝖭𝗎𝗆[(𝛿𝜖)𝜖−1]=𝐷𝖭𝗎𝗆[𝛿]. Thus the two lambdas have type 𝖭𝗎𝗆[𝛿]→𝖭𝗎𝗆[𝜖]→𝖭𝗎𝗆[𝛿], and both dimension variables are generalized: ∀𝛿∀𝜖.𝖭𝗎𝗆[𝛿]→𝖭𝗎𝗆[𝜖]→𝖭𝗎𝗆[𝛿]. Only the dimension annotation was normalized. The source term still contains the multiplication and division by 𝑦, so at run time division by zero can still produce 𝖺𝗋𝗂𝗍𝗁𝖾𝗋𝗋.
exercise 6.3.
The lambda clause first gives 𝑥 a fresh ordinary type variable 𝛼. The two variable calls return 𝛼. The multiplication clause chooses fresh dimension variables 𝛿1,𝛿2 and generates 𝛼≐𝖭𝗎𝗆[𝛿1],𝛼≐𝖭𝗎𝗆[𝛿2]. Eliminating 𝛼 leaves 𝛿1 =𝐷𝛿2. Its principal dimension solution names their common value by a fresh parameter 𝜂; equivalently the combined substitution sends 𝛼 to 𝖭𝗎𝗆[𝜂] and both 𝛿𝑖 to 𝜂. Thus the bound expression has monotype and generalized scheme 𝜆𝑥.𝑥∗𝑥:𝖭𝗎𝗆[𝜂]→𝖭𝗎𝗆[𝜂2],𝑠:∀𝜂.𝖭𝗎𝗆[𝜂]→𝖭𝗎𝗆[𝜂2]. At the first application 𝑠 (3@𝗆), instantiate 𝜂 by a fresh dimension variable 𝜃1 and choose the application result variable 𝛽1. Unifying 𝖭𝗎𝗆[𝜃1]→𝖭𝗎𝗆[𝜃21]≐𝖭𝗎𝗆[𝐿]→𝛽1 generates the dimension equation 𝜃1 =𝐷𝐿 and the type equation 𝛽1 ≐𝖭𝗎𝗆[𝜃21]. The resulting principal substitution sends 𝜃1 to 𝐿 and 𝛽1 to 𝖭𝗎𝗆[𝐿2], so the inner let binds 𝑎 :𝖭𝗎𝗆[𝐿2].
The second occurrence of 𝑠 is instantiated independently, with fresh 𝜃2,𝛽2. Unifying 𝖭𝗎𝗆[𝜃2]→𝖭𝗎𝗆[𝜃22]≐𝖭𝗎𝗆[𝑇]→𝛽2 generates 𝜃2 =𝐷𝑇 and 𝛽2 ≐𝖭𝗎𝗆[𝜃22]. Its principal substitution sends 𝜃2 to 𝑇 and 𝛽2 to 𝖭𝗎𝗆[𝑇2]. Therefore the whole term has type 𝖭𝗎𝗆[𝑇2]. The four variables 𝜃1,𝛽1,𝜃2,𝛽2 are pairwise distinct, while the scheme for 𝑠 is generalized once.
Exercise 6.4.
Both literals have dimension 𝐿. Their canonical coefficients in meters are 12𝑠𝗂𝗇𝖼𝗁=12⋅1275000=3811250,1𝑠𝖿𝗍=3811250. Therefore elaboration produces elabU(𝐷12𝗂𝗇+1𝖿𝗍)=――――――381/1250𝐿+――――――381/1250𝐿. Here 𝐷12𝗂𝗇+1𝖿𝗍 is the syntax-directed derivation of 12@𝗂𝗇𝖼𝗁 +1@𝖿𝗍. Both core operands have annotation 𝐿, so the C-Add root reduces ――――――381/1250𝐿+――――――381/1250𝐿⟶――――――762/1250𝐿=―――――381/625𝐿. Hence the canonical result is 381/625 meters, or 0.6096 meters.
exercise 6.5.
The coherent change of coordinates extends multiplicatively, hence 𝜒(𝑀𝐿𝑇−2)=𝜒(𝑀)𝜒(𝐿)𝜒(𝑇)−2=1000⋅100⋅1−2=100000. The coefficient 3 therefore becomes 300000 in gram–centimeter–second coordinates. Directly, 3𝗄𝗀𝗆𝗌−2=3(1000𝗀)(100𝖼𝗆)𝗌−2=300000𝗀𝖼𝗆𝗌−2, which agrees with the invariance theorem.
exercise 6.6.
Orient the first equation at the flexible ordinary variable and eliminate it: 𝛼↦𝖭𝗎𝗆[𝛿]. Applying this substitution to the second equation leaves the numeric equation 𝖭𝗎𝗆[𝛿] ≐𝖭𝗎𝗆[𝐿], hence the dimension store is 𝛿 =𝐷𝐿. Its deterministic Smith solve returns 𝛿 ↦𝐿. Composition therefore gives 𝜌={𝛼↦𝖭𝗎𝗆[𝐿], 𝛿↦𝐿}. Replay yields 𝛼[𝜌]=𝖭𝗎𝗆[𝐿]=𝖭𝗎𝗆[𝛿][𝜌],𝛼[𝜌]=𝖭𝗎𝗆[𝐿]=𝖭𝗎𝗆[𝐿][𝜌]. Now let 𝑅 solve both input equations. Ordinary-type constructor injectivity gives 𝑅(𝛼) =𝖭𝗎𝗆[𝑅(𝛿)] from the first equation and 𝑅(𝛼) =𝖭𝗎𝗆[𝐿] from the second. Numeric constructor injectivity and normalized dimension equality give 𝑅(𝛿) =𝐿, hence 𝑅(𝛼) =𝖭𝗎𝗆[𝐿]. Take 𝑇 =𝑅. On the problem-variable set {𝛼,𝛿}, the required factorization is 𝑅↾{𝛼,𝛿}=(𝜌;𝑇)↾{𝛼,𝛿}, which is the required factorization.
exercise 6.7.
Apply three recorded column operations: 𝑀0=[4 6],𝑀1=[4 2],𝐶2←𝐶2−𝐶1,𝑀2=[2 2],𝐶1←𝐶1−𝐶2,𝑀3=[2 0],𝐶2←𝐶2−𝐶1. The corresponding column matrices give 𝑉=[1−101][10−11][1−101]=[2−3−12]. Direct multiplication checks [4 6]𝑉=[2 0]. The determinant of 𝑉 is 1, so this is a unimodular change of coordinates. Put 𝑧 =(𝛿,𝜖)𝖳 and 𝑧 =𝑉𝑧′. The Smith equation has pivot 2 and right side 𝐿2, hence 𝑧′1 =𝐿; write the free coordinate as 𝑧′2 =𝜂. Therefore 𝛿↦𝐿2𝜂−3,𝜖↦𝐿−1𝜂2. Substitution checks the answer: (𝐿2𝜂−3)4(𝐿−1𝜂2)6distribute powers=𝐿8𝜂−12𝐿−6𝜂12collect exponents=𝐿2. Every solution is obtained by choosing 𝜂, because the second column of 𝑉 spans the integer kernel. Replacing the right side by 𝐿 makes the transformed pivot equation (𝑧′1)2 =𝐿. At generator 𝐿, the pivot 2 does not divide the right-hand exponent 1, so no dimension substitution exists.
exercise 6.8.
If source addition is to elaborate homomorphically, then for all 𝑝,𝑞, 𝑎(𝑝+𝑞)+𝑏=(𝑎𝑝+𝑏)+(𝑎𝑞+𝑏)=𝑎(𝑝+𝑞)+2𝑏. Thus 𝑏 =2𝑏, so 𝑏 =0; conversely 𝑏 =0 makes the equation immediate. Celsius-to-Kelvin conversion has 𝑎 =1 and 𝑏 =27315/100, so it does not preserve addition and cannot be a unit scale in definition 6.3. In a calculus extended with subtraction, differences would cancel the offset: (𝑝 +𝑏) −(𝑞 +𝑏) =𝑝 −𝑞. Such an extension must distinguish affine temperature points, on which subtraction produces a difference, from vector- like temperature differences, on which addition and scaling remain valid.
Practical route.
The dimension inferencer of exercise 6.9 is built in appendix F; its Smith-divisibility mutation and frozen run are recorded in appendix E.