Lectures onType Theory
ch:dimension-types: ch:dimension-types
appendix sectionsolutions

ch:dimension-types: ch:dimension-types

Exercise 6.1.

Use additive exponent arithmetic inside the multiplicative notation: (Lδ1)2(δT1)2=L2δ2δ2T2=L2T2. The exponent of δ is 2+2=0, so the dimension variable cancels. The remaining base exponents are L:2 and T:2.

Similarly, MLT2L1T=ML11T2+1=MT1. Here L cancels. The surviving base exponents are M:1 and T:1.

Exercise 6.2.

Give x type Num[δ]. Two variable leaves and D-Mul give x:Num[δ]x:Num[δ]x:Num[δ]x:Num[δ]x:Num[δ]xx:Num[δ2]DMul. Lambda introduction yields λx.xx:Num[δ]Num[δ2]. Since δ is absent from the empty context, generalization gives square:δ.Num[δ]Num[δ2].

For the second term, run the algorithm rather than guessing its argument types. The two lambda clauses begin with fresh ordinary variables x:α and y:β. The multiplication clause introduces fresh dimension variables δ1,δ2 and generates αNum[δ1],βNum[δ2]. For the division, its left operand has dimension δ1δ2, while the second occurrence of y is already forced to Num[δ2]. Renaming the two principal dimension parameters to δ,ϵ, the algorithm returns xy:Num[δϵ],(xy)/y:Num[(δϵ)ϵ1]=DNum[δ]. Thus the two lambdas have type Num[δ]Num[ϵ]Num[δ], and both dimension variables are generalized: δϵ.Num[δ]Num[ϵ]Num[δ]. Only the dimension annotation was normalized. The source term still contains the multiplication and division by y, so at run time division by zero can still produce aritherr.

exercise 6.3.

The lambda clause first gives x a fresh ordinary type variable α. The two variable calls return α. The multiplication clause chooses fresh dimension variables δ1,δ2 and generates αNum[δ1],αNum[δ2]. Eliminating α leaves δ1=Dδ2. Its principal dimension solution names their common value by a fresh parameter η; equivalently the combined substitution sends α to Num[η] and both δi to η. Thus the bound expression has monotype and generalized scheme λx.xx:Num[η]Num[η2],s:η.Num[η]Num[η2]. At the first application s(3@m), instantiate η by a fresh dimension variable θ1 and choose the application result variable β1. Unifying Num[θ1]Num[θ12]Num[L]β1 generates the dimension equation θ1=DL and the type equation β1Num[θ12]. The resulting principal substitution sends θ1 to L and β1 to Num[L2], so the inner let binds a:Num[L2].

The second occurrence of s is instantiated independently, with fresh θ2,β2. Unifying Num[θ2]Num[θ22]Num[T]β2 generates θ2=DT and β2Num[θ22]. Its principal substitution sends θ2 to T and β2 to Num[T2]. Therefore the whole term has type Num[T2]. The four variables θ1,β1,θ2,β2 are pairwise distinct, while the scheme for s is generalized once.

Exercise 6.4.

Both literals have dimension L. Their canonical coefficients in meters are 12sinch=121275000=3811250,1sft=3811250. Therefore elaboration produces elabU(D12in+1ft)=381/1250L+381/1250L. Here D12in+1ft is the syntax-directed derivation of 12@inch+1@ft. Both core operands have annotation L, so the C-Add root reduces 381/1250L+381/1250L762/1250L=381/625L. Hence the canonical result is 381/625 meters, or 0.6096 meters.

exercise 6.5.

The coherent change of coordinates extends multiplicatively, hence χ(MLT2)=χ(M)χ(L)χ(T)2=100010012=100000. The coefficient 3 therefore becomes 300000 in gram–centimeter–second coordinates. Directly, 3kgms2=3(1000g)(100cm)s2=300000gcms2, which agrees with the invariance theorem.

exercise 6.6.

Orient the first equation at the flexible ordinary variable and eliminate it: αNum[δ]. Applying this substitution to the second equation leaves the numeric equation Num[δ]Num[L], hence the dimension store is δ=DL. Its deterministic Smith solve returns δL. Composition therefore gives ρ={αNum[L], δL}. Replay yields α[ρ]=Num[L]=Num[δ][ρ],α[ρ]=Num[L]=Num[L][ρ]. Now let R solve both input equations. Ordinary-type constructor injectivity gives R(α)=Num[R(δ)] from the first equation and R(α)=Num[L] from the second. Numeric constructor injectivity and normalized dimension equality give R(δ)=L, hence R(α)=Num[L]. Take T=R. On the problem-variable set {α,δ}, the required factorization is R{α,δ}=(ρ;T){α,δ}, which is the required factorization.

exercise 6.7.

Apply three recorded column operations: M0=[4  6],M1=[4  2],C2C2C1,M2=[2  2],C1C1C2,M3=[2  0],C2C2C1. The corresponding column matrices give V=[1101][1011][1101]=[2312]. Direct multiplication checks [4  6]V=[2  0]. The determinant of V is 1, so this is a unimodular change of coordinates. Put z=(δ,ϵ)T and z=Vz. The Smith equation has pivot 2 and right side L2, hence z1=L; write the free coordinate as z2=η. Therefore δL2η3,ϵL1η2. Substitution checks the answer: (L2η3)4(L1η2)6=distribute powersL8η12L6η12=collect exponentsL2. Every solution is obtained by choosing η, because the second column of V spans the integer kernel. Replacing the right side by L makes the transformed pivot equation (z1)2=L. At generator L, 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 p,q, a(p+q)+b=(ap+b)+(aq+b)=a(p+q)+2b. Thus b=2b, so b=0; conversely b=0 makes the equation immediate. Celsius-to-Kelvin conversion has a=1 and b=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: (p+b)(q+b)=pq. 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.

Search the book

Type to search the local edition.