Here are definitions of the two auxiliary functions addCarry
and mulDigit
used in Homework 6 Problem 9. These in turn call other auxiliary functions, that are also supplied.
addCarry(θ, carry) =def dissect θ {
λ "". carry;
λ υ ⁀ β if isDigit(υ). dissect addAux2(υ, carry) {
λ υ ⁀ ν if isDigit(υ). υ ⁀ addCarry(β, ν)
}
}
addAux2(υ, carry) =def dissect υ {
λ "0". carry ⁀ "0";
λ "1" if carry = "0". "10";
λ "1" if carry = "1". "20";
λ "1" if carry = "2". "01";
λ "2" if carry = "0". "20";
λ "2" if carry = "1". "01";
λ "2" if carry = "2". "11"
}
addAux3(ν, υ, carry) =def dissect ν {
λ "0". addAux2(υ, carry);
λ "1" if υ = "0" and carry = "0". "10";
λ "1" if υ = "0" and carry = "1". "20";
λ "1" if υ = "0" and carry = "2". "01";
λ "1" if υ = "1" and carry = "0". "20";
λ "1" if υ = "1" and carry = "1". "01";
λ "1" if υ = "1" and carry = "2". "11";
λ "1" if υ = "2" and carry = "0". "01";
λ "1" if υ = "2" and carry = "1". "11";
λ "1" if υ = "2" and carry = "2". "21";
λ "2" if υ = "0" and carry = "0". "20";
λ "2" if υ = "0" and carry = "1". "01";
λ "2" if υ = "0" and carry = "2". "11";
λ "2" if υ = "1" and carry = "0". "01";
λ "2" if υ = "1" and carry = "1". "11";
λ "2" if υ = "1" and carry = "2". "21";
λ "2" if υ = "2" and carry = "0". "11";
λ "2" if υ = "2" and carry = "1". "21";
λ "2" if υ = "2" and carry = "2". "02"
}
mulDigit(γ, ψ, η, carry) =def dissect mulAux2(γ, ψ) {
λ υ ⁀ ν if isDigit(υ). dissect addAux3(υ, η, carry) {
λ β if ν = "0". β;
λ β ⁀ "0" if ν = "1". β ⁀ "1";
λ β ⁀ "1" if ν = "1". β ⁀ "2";
λ β ⁀ "0" if ν = "2". β ⁀ "2"
}
}
mulAux2(γ, ψ) =def dissect γ {
λ "0". "00";
λ "1". ψ ⁀ "0";
λ "2" if ψ = "0". "00";
λ "2" if ψ = "1". "20";
λ "2" if ψ = "2". "11"
}