Analysis I, Appendix B.1: The decimal representation of natural numbers

Am implementation of the decimal representation of Mathlib's natural numbers : Type.

This is separate from the way decimal numerals are already represenated in Mathlib via the OfNat.{u} (α : Type u) : Type uOfNat typeclass.

namespace AppendixB/- The ten digits, together with the base 10 -/ example : 0 = Nat.zero := rflexample : 1 = (0:Nat).succ := rflexample : 2 = (1:Nat).succ := rflexample : 3 = (2:Nat).succ := rflexample : 4 = (3:Nat).succ := rflexample : 5 = (4:Nat).succ := rflexample : 6 = (5:Nat).succ := rflexample : 7 = (6:Nat).succ := rflexample : 8 = (7:Nat).succ := rflexample : 9 = (8:Nat).succ := rflexample : 10 = (9:Nat).succ := rfl

Definition B.1.1

def Digit := Fin 10
instance Digit.instZero : Zero Digit := 0, 0 < 10 All goals completed! 🐙instance Digit.instOne : One Digit := 1, 1 < 10 All goals completed! 🐙instance Digit.instTwo : OfNat Digit 2 := 2, 2 < 10 All goals completed! 🐙instance Digit.instThree : OfNat Digit 3 := 3, 3 < 10 All goals completed! 🐙instance Digit.instFour : OfNat Digit 4 := 4, 4 < 10 All goals completed! 🐙instance Digit.instFive : OfNat Digit 5 := 5, 5 < 10 All goals completed! 🐙instance Digit.instSix : OfNat Digit 6 := 6, 6 < 10 All goals completed! 🐙instance Digit.instSeven : OfNat Digit 7 := 7, 7 < 10 All goals completed! 🐙instance Digit.instEight : OfNat Digit 8 := 8, 8 < 10 All goals completed! 🐙instance Digit.instNine : OfNat Digit 9 := 9, 9 < 10 All goals completed! 🐙instance Digit.instFintype : Fintype Digit := Fin.fintype 10instance Digit.instDecidableEq : DecidableEq Digit := instDecidableEqFin 10instance Digit.instInhabited : Inhabited Digit := 0 @[coe] abbrev Digit.toNat (d:Digit) : := d.valinstance Digit.instCoeNat : Coe Digit Nat where coe := toNattheorem Digit.lt (d:Digit) : (d:) < 10 := d.isLtabbrev Digit.mk {n:} (h: n < 10) : Digit := n, h@[simp] theorem Digit.toNat_mk {n:} (h: n < 10) : (Digit.mk h:) = n := rfl@[simp] theorem Digit.inj (d d':Digit) : d = d' (d:) = d' := d:Digitd':Digitd = d' d = d' All goals completed! 🐙theorem Digit.mk_eq_iff (d:Digit) {n:} (h: n < 10) : d = mk h (d:) = n := d:Digitn:h:n < 10d = mk h d = n All goals completed! 🐙
0 : Digit
1 : Digit
2 : Digit
3 : Digit
4 : Digit
5 : Digit
6 : Digit
7 : Digit
8 : Digit
9 : Digit
theorem Digit.eq (n: Digit) : n = 0 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 := n:Digitn = 0 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 (fun i => i) 0, = 0 (fun i => i) 0, = 1 (fun i => i) 0, = 2 (fun i => i) 0, = 3 (fun i => i) 0, = 4 (fun i => i) 0, = 5 (fun i => i) 0, = 6 (fun i => i) 0, = 7 (fun i => i) 0, = 8 (fun i => i) 0, = 9(fun i => i) 1, = 0 (fun i => i) 1, = 1 (fun i => i) 1, = 2 (fun i => i) 1, = 3 (fun i => i) 1, = 4 (fun i => i) 1, = 5 (fun i => i) 1, = 6 (fun i => i) 1, = 7 (fun i => i) 1, = 8 (fun i => i) 1, = 9(fun i => i) 2, = 0 (fun i => i) 2, = 1 (fun i => i) 2, = 2 (fun i => i) 2, = 3 (fun i => i) 2, = 4 (fun i => i) 2, = 5 (fun i => i) 2, = 6 (fun i => i) 2, = 7 (fun i => i) 2, = 8 (fun i => i) 2, = 9(fun i => i) 3, = 0 (fun i => i) 3, = 1 (fun i => i) 3, = 2 (fun i => i) 3, = 3 (fun i => i) 3, = 4 (fun i => i) 3, = 5 (fun i => i) 3, = 6 (fun i => i) 3, = 7 (fun i => i) 3, = 8 (fun i => i) 3, = 9(fun i => i) 4, = 0 (fun i => i) 4, = 1 (fun i => i) 4, = 2 (fun i => i) 4, = 3 (fun i => i) 4, = 4 (fun i => i) 4, = 5 (fun i => i) 4, = 6 (fun i => i) 4, = 7 (fun i => i) 4, = 8 (fun i => i) 4, = 9(fun i => i) 5, = 0 (fun i => i) 5, = 1 (fun i => i) 5, = 2 (fun i => i) 5, = 3 (fun i => i) 5, = 4 (fun i => i) 5, = 5 (fun i => i) 5, = 6 (fun i => i) 5, = 7 (fun i => i) 5, = 8 (fun i => i) 5, = 9(fun i => i) 6, = 0 (fun i => i) 6, = 1 (fun i => i) 6, = 2 (fun i => i) 6, = 3 (fun i => i) 6, = 4 (fun i => i) 6, = 5 (fun i => i) 6, = 6 (fun i => i) 6, = 7 (fun i => i) 6, = 8 (fun i => i) 6, = 9(fun i => i) 7, = 0 (fun i => i) 7, = 1 (fun i => i) 7, = 2 (fun i => i) 7, = 3 (fun i => i) 7, = 4 (fun i => i) 7, = 5 (fun i => i) 7, = 6 (fun i => i) 7, = 7 (fun i => i) 7, = 8 (fun i => i) 7, = 9(fun i => i) 8, = 0 (fun i => i) 8, = 1 (fun i => i) 8, = 2 (fun i => i) 8, = 3 (fun i => i) 8, = 4 (fun i => i) 8, = 5 (fun i => i) 8, = 6 (fun i => i) 8, = 7 (fun i => i) 8, = 8 (fun i => i) 8, = 9(fun i => i) 9, = 0 (fun i => i) 9, = 1 (fun i => i) 9, = 2 (fun i => i) 9, = 3 (fun i => i) 9, = 4 (fun i => i) 9, = 5 (fun i => i) 9, = 6 (fun i => i) 9, = 7 (fun i => i) 9, = 8 (fun i => i) 9, = 9 (fun i => i) 0, = 0 (fun i => i) 0, = 1 (fun i => i) 0, = 2 (fun i => i) 0, = 3 (fun i => i) 0, = 4 (fun i => i) 0, = 5 (fun i => i) 0, = 6 (fun i => i) 0, = 7 (fun i => i) 0, = 8 (fun i => i) 0, = 9(fun i => i) 1, = 0 (fun i => i) 1, = 1 (fun i => i) 1, = 2 (fun i => i) 1, = 3 (fun i => i) 1, = 4 (fun i => i) 1, = 5 (fun i => i) 1, = 6 (fun i => i) 1, = 7 (fun i => i) 1, = 8 (fun i => i) 1, = 9(fun i => i) 2, = 0 (fun i => i) 2, = 1 (fun i => i) 2, = 2 (fun i => i) 2, = 3 (fun i => i) 2, = 4 (fun i => i) 2, = 5 (fun i => i) 2, = 6 (fun i => i) 2, = 7 (fun i => i) 2, = 8 (fun i => i) 2, = 9(fun i => i) 3, = 0 (fun i => i) 3, = 1 (fun i => i) 3, = 2 (fun i => i) 3, = 3 (fun i => i) 3, = 4 (fun i => i) 3, = 5 (fun i => i) 3, = 6 (fun i => i) 3, = 7 (fun i => i) 3, = 8 (fun i => i) 3, = 9(fun i => i) 4, = 0 (fun i => i) 4, = 1 (fun i => i) 4, = 2 (fun i => i) 4, = 3 (fun i => i) 4, = 4 (fun i => i) 4, = 5 (fun i => i) 4, = 6 (fun i => i) 4, = 7 (fun i => i) 4, = 8 (fun i => i) 4, = 9(fun i => i) 5, = 0 (fun i => i) 5, = 1 (fun i => i) 5, = 2 (fun i => i) 5, = 3 (fun i => i) 5, = 4 (fun i => i) 5, = 5 (fun i => i) 5, = 6 (fun i => i) 5, = 7 (fun i => i) 5, = 8 (fun i => i) 5, = 9(fun i => i) 6, = 0 (fun i => i) 6, = 1 (fun i => i) 6, = 2 (fun i => i) 6, = 3 (fun i => i) 6, = 4 (fun i => i) 6, = 5 (fun i => i) 6, = 6 (fun i => i) 6, = 7 (fun i => i) 6, = 8 (fun i => i) 6, = 9(fun i => i) 7, = 0 (fun i => i) 7, = 1 (fun i => i) 7, = 2 (fun i => i) 7, = 3 (fun i => i) 7, = 4 (fun i => i) 7, = 5 (fun i => i) 7, = 6 (fun i => i) 7, = 7 (fun i => i) 7, = 8 (fun i => i) 7, = 9(fun i => i) 8, = 0 (fun i => i) 8, = 1 (fun i => i) 8, = 2 (fun i => i) 8, = 3 (fun i => i) 8, = 4 (fun i => i) 8, = 5 (fun i => i) 8, = 6 (fun i => i) 8, = 7 (fun i => i) 8, = 8 (fun i => i) 8, = 9(fun i => i) 9, = 0 (fun i => i) 9, = 1 (fun i => i) 9, = 2 (fun i => i) 9, = 3 (fun i => i) 9, = 4 (fun i => i) 9, = 5 (fun i => i) 9, = 6 (fun i => i) 9, = 7 (fun i => i) 9, = 8 (fun i => i) 9, = 9 All goals completed! 🐙

Definition B.1.2

structure PosintDecimal where digits : List Digit nonempty : digits [] nonzero : digits.head nonempty 0
theorem PosintDecimal.congr' {p q:PosintDecimal} (h: p.digits = q.digits) : p = q := p:PosintDecimalq:PosintDecimalh:p.digits = q.digitsp = q q:PosintDecimalpd:List Digitnonempty✝:pd []nonzero✝:pd.head nonempty✝ 0h:{ digits := pd, nonempty := nonempty✝, nonzero := nonzero✝ }.digits = q.digits{ digits := pd, nonempty := nonempty✝, nonzero := nonzero✝ } = q pd:List Digitnonempty✝¹:pd []nonzero✝¹:pd.head nonempty✝¹ 0qd:List Digitnonempty✝:qd []nonzero✝:qd.head nonempty✝ 0h:{ digits := pd, nonempty := nonempty✝¹, nonzero := nonzero✝¹ }.digits = { digits := qd, nonempty := nonempty✝, nonzero := nonzero✝ }.digits{ digits := pd, nonempty := nonempty✝¹, nonzero := nonzero✝¹ } = { digits := qd, nonempty := nonempty✝, nonzero := nonzero✝ } All goals completed! 🐙theorem PosintDecimal.congr {p q:PosintDecimal} (h: p.digits.length = q.digits.length) (h': (n:) (h₁ : n < p.digits.length) (h₂: n < q.digits.length), p.digits.get n, h₁ = q.digits.get n, h₂ ) : p = q := p:PosintDecimalq:PosintDecimalh:p.digits.length = q.digits.lengthh': (n : ) (h₁ : n < p.digits.length) (h₂ : n < q.digits.length), p.digits.get n, h₁ = q.digits.get n, h₂p = q p:PosintDecimalq:PosintDecimalh:p.digits.length = q.digits.lengthh': (n : ) (h₁ : n < p.digits.length) (h₂ : n < q.digits.length), p.digits.get n, h₁ = q.digits.get n, h₂p.digits = q.digits All goals completed! 🐙abbrev PosintDecimal.head (p:PosintDecimal): Digit := p.digits.head p.nonemptytheorem PosintDecimal.head_ne_zero (p:PosintDecimal) : p.head 0 := p.nonzerotheorem PosintDecimal.head_ne_zero' (p:PosintDecimal) : (p.head:) 0 := p:PosintDecimalp.head 0 p:PosintDecimalthis:p.head = 0False p:PosintDecimalthis:p.head = 0p.head = 0 All goals completed! 🐙theorem PosintDecimal.length_pos (p:PosintDecimal) : 0 < p.digits.length := p:PosintDecimal0 < p.digits.length All goals completed! 🐙

A slightly clunky way of creating decimals.

def PosintDecimal.mk' (head:Digit) (tail:List Digit) (h: head 0) : PosintDecimal := { digits := head :: tail nonempty := head:Digittail:List Digith:head 0head :: tail [] All goals completed! 🐙 nonzero := h }
PosintDecimal.mk' 3 [1, 4]  : PosintDecimal
PosintDecimal.mk' 3 []  : PosintDecimal
PosintDecimal.mk' 1 [0]  : PosintDecimal

We are indexing digits in a decimal from left to right rather than from right to left, thus necessitating a reversal here.

@[coe] def PosintDecimal.toNat (p:PosintDecimal) : Nat := i:Fin p.digits.length, p.digits[p.digits.length - 1 - i].toNat * 10 ^ (i:)
instance PosintDecimal.instCoeNat : Coe PosintDecimal Nat where coe := toNatexample : (PosintDecimal.mk' 3 [1, 4] (3 0 All goals completed! 🐙):) = 314 := (PosintDecimal.mk' 3 [1, 4] ) = 314 All goals completed! 🐙

Remark B.1.3

@[simp] theorem PosintDecimal.ten_eq_ten : (mk' 1 [0] (1 0 All goals completed! 🐙):) = 10 := (mk' 1 [0] ) = 10 All goals completed! 🐙
theorem PosintDecimal.digit_eq {d:Digit} (h: d 0) : (mk' d [] h:) = d := d:Digith:d 0(mk' d [] h) = d All goals completed! 🐙theorem PosintDecimal.pos (p:PosintDecimal) : 0 < (p:) := p:PosintDecimal0 < p p:PosintDecimal0 < i, p.digits[p.digits.length - 1 - i] * 10 ^ i calc _ < (p.head:) * 10 ^ (p.digits.length - 1) := p:PosintDecimal0 < p.head * 10 ^ (p.digits.length - 1) p:PosintDecimalthis:?_mvar.57128 := PosintDecimal.head_ne_zero' _fvar.479590 < p.head * 10 ^ (p.digits.length - 1) All goals completed! 🐙 _ _ := p:PosintDecimalp.head * 10 ^ (p.digits.length - 1) i, p.digits[p.digits.length - 1 - i] * 10 ^ i p:PosintDecimalthis:?_mvar.58082 := PosintDecimal.length_pos _fvar.47959p.head * 10 ^ (p.digits.length - 1) i, p.digits[p.digits.length - 1 - i] * 10 ^ i set a : Fin p.digits.length := p.digits.length - 1, p:PosintDecimalthis:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := PosintDecimal.length_pos _fvar.47959p.digits.length - 1 < p.digits.length All goals completed! 🐙 p:PosintDecimalthis:?_mvar.58082 := PosintDecimal.length_pos _fvar.47959a:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.head * 10 ^ (p.digits.length - 1) = p.digits[p.digits.length - 1 - a] * 10 ^ ap:PosintDecimalthis:?_mvar.58082 := PosintDecimal.length_pos _fvar.47959a:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)IsOrderedAddMonoid p:PosintDecimalthis:?_mvar.58082 := PosintDecimal.length_pos _fvar.47959a:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) i Finset.univ, 0 p.digits[p.digits.length - 1 - i] * 10 ^ i p:PosintDecimalthis:?_mvar.58082 := PosintDecimal.length_pos _fvar.47959a:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.head * 10 ^ (p.digits.length - 1) = p.digits[p.digits.length - 1 - a] * 10 ^ a All goals completed! 🐙 p:PosintDecimalthis:?_mvar.58082 := PosintDecimal.length_pos _fvar.47959a:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)IsOrderedAddMonoid All goals completed! 🐙 All goals completed! 🐙

An operation implicit in the proof of Theorem B.1.4:

abbrev PosintDecimal.append (p:PosintDecimal) (d:Digit) : PosintDecimal := mk' p.head (p.digits.tail ++ [d]) p.head_ne_zero
@[simp] theorem PosintDecimal.append_toNat (p:PosintDecimal) (d:Digit) : (p.append d:) = d.toNat + 10 * p.toNat := p:PosintDecimald:Digit(p.append d) = d + 10 * p p:PosintDecimald:Digit x, (p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - x] * 10 ^ x = d + i, 10 * (p.digits[p.digits.length - 1 - i] * 10 ^ i) p:PosintDecimald:Digit(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - 0] * 10 ^ 0 + i, (p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - (Fin.succAbove 0 i)] * 10 ^ (Fin.succAbove 0 i) = d + i, 10 * (p.digits[p.digits.length - 1 - i] * 10 ^ i) p:PosintDecimald:Digit(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - 0] * 10 ^ 0 = dp:PosintDecimald:Digit i, (p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - (Fin.succAbove 0 i)] * 10 ^ (Fin.succAbove 0 i) = i, 10 * (p.digits[p.digits.length - 1 - i] * 10 ^ i) p:PosintDecimald:Digit(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - 0] * 10 ^ 0 = d All goals completed! 🐙 p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546 i, (p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - (Fin.succAbove 0 i)] * 10 ^ (Fin.succAbove 0 i) = i, 10 * (p.digits[p.digits.length - 1 - i] * 10 ^ i) p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - (Fin.succAbove 0 i)] * 10 ^ (Fin.succAbove 0 i) = 10 * (p.digits[p.digits.length - 1 - (Fin.cast ?e_a.convert_6✝ i)] * 10 ^ (Fin.cast ?e_a.convert_6✝ i))p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546(p.digits.tail ++ [d]).length = p.digits.length; p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546(p.digits.tail ++ [d]).length = p.digits.lengthp:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - (Fin.succAbove 0 i)] * 10 ^ (Fin.succAbove 0 i) = 10 * (p.digits[p.digits.length - 1 - (Fin.cast ?e_a.convert_6✝ i)] * 10 ^ (Fin.cast ?e_a.convert_6✝ i)); p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 + 1 - (Fin.succAbove 0 i)] * 10 ^ (Fin.succAbove 0 i) = 10 * (p.digits[p.digits.length - 1 - (Fin.cast i)] * 10 ^ (Fin.cast i)) p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 - i] * 10 ^ (i + 1) = 10 * (p.digits[p.digits.length - 1 - i] * 10 ^ i) p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 - i] * 10 ^ (i + 1) = p.digits[p.digits.length - 1 - i] * (10 ^ i * 10)p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univp.digits[p.digits.length - 1 - i] * (10 ^ i * 10) = 10 * (p.digits[p.digits.length - 1 - i] * 10 ^ i); p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univp.digits[p.digits.length - 1 - i] * (10 ^ i * 10) = 10 * (p.digits[p.digits.length - 1 - i] * 10 ^ i)p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 - i] * 10 ^ (i + 1) = p.digits[p.digits.length - 1 - i] * (10 ^ i * 10); p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 - i] * 10 ^ (i + 1) = p.digits[p.digits.length - 1 - i] * (10 ^ i * 10) p:PosintDecimald:Digitthis:?_mvar.105583 := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univ(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 - i] = p.digits[p.digits.length - 1 - i] have : p.head :: (p.digits.tail ++ [d]) = p.digits ++ [d] := p:PosintDecimald:Digit(p.append d) = d + 10 * p All goals completed! 🐙 have hlen : p.digits.length - 1 - i < (p.digits ++ [d]).length := p:PosintDecimald:Digit(p.append d) = d + 10 * p All goals completed! 🐙 calc _ = (p.digits ++ [d])[p.digits.length - 1 - i] := p:PosintDecimald:Digitthis✝:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := PosintDecimal.length_pos _fvar.65546i:Fin (p.digits.tail ++ [d]).lengtha✝:i Finset.univthis:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)hlen:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := PosintDecimal.append_toNat._proof_6 _fvar.65546 _fvar.65547 _fvar.105585 _fvar.107056 _fvar.107104 _fvar.126710(p.head :: (p.digits.tail ++ [d]))[p.digits.length - 1 - i] = (p.digits ++ [d])[p.digits.length - 1 - i] All goals completed! 🐙 _ = _ := List.getElem_append_left _theorem PosintDecimal.eq_append {p:PosintDecimal} (h: 2 p.digits.length) : (q:PosintDecimal) (d:Digit), p = q.append d := p:PosintDecimalh:2 p.digits.length q d, p = q.append d p:PosintDecimalh:2 p.digits.length d, p = (mk' p.head p.digits.tail.dropLast ).append d p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) d, p = (mk' p.head p.digits.tail.dropLast ).append d; p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p = (mk' p.head p.digits.tail.dropLast ).append a p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.digits = ((mk' p.head p.digits.tail.dropLast ).append a).digits p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.digits = { digits := p.head :: p.digits.tail.dropLast, nonempty := , nonzero := }.head :: (p.digits.tail.dropLast ++ [a]) p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.digits.head :: p.digits.tail = { digits := p.head :: (p.digits.head :: p.digits.tail).tail.dropLast, nonempty := , nonzero := }.head :: ((p.digits.head :: p.digits.tail).tail.dropLast ++ [a]) p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.digits.tail = (p.digits.head :: p.digits.tail).tail.dropLast ++ [a] p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)[a] = [p.digits.tail.getLast ?h.h.e_tail.convert_2]p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.digits.tail []; p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)p.digits.tail [] p:PosintDecimalh:2 p.digits.lengtha:Digit := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)1 < p.digits.length; All goals completed! 🐙

Theorem B.1.4 (Uniqueness and existence of decimal representations)

theorem PosintDecimal.exists_unique (n:) : n > 0 ∃! p:PosintDecimal, (p:) = n := n:n > 0 ∃! p, p = n -- this proof is written to follow the structure of the original text. n:0 > 0 ∃! p, p = 0n: (n : ), (∀ m n, m > 0 ∃! p, p = m) n + 1 > 0 ∃! p, p = n + 1 n:0 > 0 ∃! p, p = 0 All goals completed! 🐙 -- note: the variable `m` in the text is referred to as `m+1` here. (n : ), (∀ m n, m > 0 ∃! p, p = m) n + 1 > 0 ∃! p, p = n + 1; m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0∃! p, p = m + 1 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9∃! p, p = m + 1m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 m∃! p, p = m + 1 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9∃! p, p = m + 1 apply ExistsUnique.intro (mk' (.mk (show m+1 < 10 n:n > 0 ∃! p, p = n All goals completed! 🐙)) [] (m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9Digit.mk 0 All goals completed! 🐙)) m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9(mk' (Digit.mk ) [] ) = m + 1 All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1d = mk' (Digit.mk ) [] m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:d.digits.length < 2d = mk' (Digit.mk ) [] m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengthd = mk' (Digit.mk ) [] m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:d.digits.length < 2d = mk' (Digit.mk ) [] replace hdl : d.digits.length = 1 := n:n > 0 ∃! p, p = n All goals completed! 🐙 have _subsing : Subsingleton (Fin d.digits.length) := n:n > 0 ∃! p, p = n All goals completed! 🐙 let zero : Fin d.digits.length := 0, m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := of_eq_true (Eq.trans (Eq.trans (congrArg (fun x => Subsingleton (Fin x)) _fvar.137783) PosintDecimal.exists_unique._simp_1) (le_refl._simp_1 1))0 < d.digits.length All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhdl:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.137782_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.146187zero:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := 0, ?_mvar.146275hd:d.digits[0] = m + 1d = mk' (Digit.mk ) [] m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhdl:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.137782_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.146187zero:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := 0, ?_mvar.146275hd:d.digits[0] = m + 1d.digits.length = (mk' (Digit.mk ) [] ).digits.lengthm:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhdl:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.137782_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.146187zero:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := 0, ?_mvar.146275hd:d.digits[0] = m + 1 (n : ) (h₁ : n < d.digits.length) (h₂ : n < (mk' (Digit.mk ) [] ).digits.length), d.digits.get n, h₁ = (mk' (Digit.mk ) [] ).digits.get n, h₂ m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhdl:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.137782_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.146187zero:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := 0, ?_mvar.146275hd:d.digits[0] = m + 1d.digits.length = (mk' (Digit.mk ) [] ).digits.length All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhdl:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.137782_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.146187zero:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := 0, ?_mvar.146275hd:d.digits[0] = m + 1i:hi₁:i < d.digits.lengthhi₂:i < (mk' (Digit.mk ) [] ).digits.lengthd.digits.get i, hi₁ = (mk' (Digit.mk ) [] ).digits.get i, hi₂ replace hi₁ : i = 0 := n:n > 0 ∃! p, p = n All goals completed! 🐙 All goals completed! 🐙 have : d.toNat 10 := calc _ (d.head:) * 10^(d.digits.length-1) := m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengthd d.head * 10 ^ (d.digits.length - 1) set a : Fin d.digits.length := d.digits.length - 1, m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengthd.digits.length - 1 < d.digits.length All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengtha:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)d.head = d.digits[d.digits.length - 1 - a]m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengtha:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)IsOrderedAddMonoid m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengtha:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) i Finset.univ, 0 d.digits[d.digits.length - 1 - i] * 10 ^ i m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengtha:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)d.head = d.digits[d.digits.length - 1 - a] All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengtha:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)IsOrderedAddMonoid All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝¹:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengtha:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)i✝:Fin d.digits.lengtha✝:i✝ Finset.univ0 d.digits[d.digits.length - 1 - i✝] * 10 ^ i✝; All goals completed! 🐙 _ 1 * 10^(2-1) := m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengthd.head * 10 ^ (d.digits.length - 1) 1 * 10 ^ (2 - 1) m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.length1 d.headm:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.length1 10 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.length1 d.head m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.lengththis:?_mvar.168543 := PosintDecimal.head_ne_zero' _fvar.1376661 d.head; All goals completed! 🐙 All goals completed! 🐙 _ = 10 := m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:m < 9d:PosintDecimalhd:d = m + 1hdl:2 d.digits.length1 * 10 ^ (2 - 1) = 10 All goals completed! 🐙 All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 mthis:?_mvar.172628 := Nat.mod_add_div (_fvar.135518 + 1) 10∃! p, p = m + 1 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10this:(m + 1) % 10 + 10 * s = m + 1∃! p, p = m + 1 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1∃! p, p = m + 1 have hr : r < 10 := n:n > 0 ∃! p, p = n All goals completed! 🐙 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152s mm:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152s > 0m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152hind:∃! p, p = s∃! p, p = m + 1 m:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152s mm:hind: m_1 m, m_1 > 0 ∃! p, p = m_1a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152s > 0m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152hind:∃! p, p = s∃! p, p = m + 1 try m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152hind:∃! p, p = s∃! p, p = m + 1 m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), (fun p => p = s) y y = b∃! p, p = m + 1; m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = b∃! p, p = m + 1 m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = b(b.append (Digit.mk hr)) = m + 1m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = b (y : PosintDecimal), y = m + 1 y = b.append (Digit.mk hr) m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = b(b.append (Digit.mk hr)) = m + 1 All goals completed! 🐙 m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = ba:PosintDecimalha:a = m + 1a = b.append (Digit.mk hr) m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = ba:PosintDecimalha:a = m + 1hal:a.digits.length < 2a = b.append (Digit.mk hr)m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = ba:PosintDecimalha:a = m + 1hal:2 a.digits.lengtha = b.append (Digit.mk hr) m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = ba:PosintDecimalha:a = m + 1hal:a.digits.length < 2a = b.append (Digit.mk hr) replace hal : a.digits.length = 1 := n:n > 0 ∃! p, p = n All goals completed! 🐙 have _subsing : Subsingleton (Fin a.digits.length) := n:n > 0 ∃! p, p = n All goals completed! 🐙 let zero : Fin a.digits.length := 0, m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := PosintDecimal.exists_unique._proof_6 _fvar.135518 _fvar.135521 _fvar.135527 _fvar.135583 _fvar.173074b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = ba:PosintDecimalha:a = m + 1hal:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation)_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := of_eq_true (Eq.trans (Eq.trans (congrArg (fun x => Subsingleton (Fin x)) _fvar.190687) PosintDecimal.exists_unique._simp_1) (le_refl._simp_1 1))0 < a.digits.length All goals completed! 🐙 m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = ba:PosintDecimalhal:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.190686_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.203765zero:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := 0, ?_mvar.203853ha:a.digits[0] = m + 1a = b.append (Digit.mk hr) m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this✝:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = ba:PosintDecimalhal:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.190686_subsing:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := ?_mvar.203765zero:failed to pretty print expression (use 'set_option pp.rawOnError true' for raw representation) := 0, ?_mvar.203853ha:a.digits[0] = m + 1this:a.digits[0] < 10a = b.append (Digit.mk hr) All goals completed! 🐙 m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = bb':PosintDecimalb'₀:Digitha:(b'.append b'₀) = m + 1hal:2 (b'.append b'₀).digits.lengthb'.append b'₀ = b.append (Digit.mk hr) m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = bb':PosintDecimalb'₀:Digithal:2 (b'.append b'₀).digits.lengthha:b'₀ + 10 * b' = r + 10 * sb'.append b'₀ = b.append (Digit.mk hr) m:a✝:m + 1 > 0hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this✝:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = bb':PosintDecimalb'₀:Digithal:2 (b'.append b'₀).digits.lengthha:b'₀ + 10 * b' = r + 10 * sthis:b'₀ < 10b'.append b'₀ = b.append (Digit.mk hr) replace : (s:) = (b':) := n:n > 0 ∃! p, p = n All goals completed! 🐙 have hb'₀r: (b'₀:) = (r:) := n:n > 0 ∃! p, p = n All goals completed! 🐙 m:hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this✝:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = bb':PosintDecimalb'₀:Digithal:2 (b'.append b'₀).digits.lengthha:b'₀ + 10 * b' = r + 10 * sa✝:Truethis:s = b'hb'₀r:b'₀ = rb'.append b'₀ = b.append (Digit.mk hr) m:hm:9 ms: := (_fvar.135518 + 1) / 10r: := (_fvar.135518 + 1) % 10this✝:r + 10 * s = m + 1hr:_fvar.173033 < 10 := ?_mvar.173152b:PosintDecimalhb:b = shuniq: (y : PosintDecimal), y = s y = bb':PosintDecimalb'₀:Digithal:2 (b'.append b'₀).digits.lengthha:b'₀ + 10 * b' = r + 10 * sa✝:Truethis:s = b'hb'₀r:b'₀ = Digit.mk hrb'.append b'₀ = b.append (Digit.mk hr) All goals completed! 🐙
@[simp] theorem PosintDecimal.coe_inj (p q:PosintDecimal) : (p:) = (q:) p = q := p:PosintDecimalq:PosintDecimalp = q p = q p:PosintDecimalq:PosintDecimalp = q p = qp:PosintDecimalq:PosintDecimalp = q p = q p:PosintDecimalq:PosintDecimalp = q p = qp:PosintDecimalq:PosintDecimalp = q p = q p:PosintDecimalq:PosintDecimalh:p = qp = q p:PosintDecimalq:PosintDecimalh:p = qp = q All goals completed! 🐙 All goals completed! 🐙inductive IntDecimal where | zero : IntDecimal | pos : PosintDecimal IntDecimal | neg : PosintDecimal IntDecimaldef IntDecimal.toInt : IntDecimal Int | zero => 0 | pos p => p.toNat | neg p => -p.toNatinstance IntDecimal.instCoeInt : Coe IntDecimal Int where coe := toIntexample : (IntDecimal.neg (PosintDecimal.mk' 3 [1, 4] (3 0 All goals completed! 🐙)):) = -314 := (IntDecimal.neg (PosintDecimal.mk' 3 [1, 4] )).toInt = -314 All goals completed! 🐙theorem IntDecimal.Int_bij : Function.Bijective IntDecimal.toInt := Function.Bijective toInt Function.Injective toIntFunction.Surjective toInt Function.Injective toInt p:IntDecimalq:IntDecimalhpq:p.toInt = q.toIntp = q cases p with q:IntDecimalhpq:zero.toInt = q.toIntzero = q cases q with hpq:zero.toInt = zero.toIntzero = zero All goals completed! 🐙 q:PosintDecimalhpq:zero.toInt = (pos q).toIntzero = pos q q:PosintDecimalhpq:0 = qzero = pos q; All goals completed! 🐙 q:PosintDecimalhpq:zero.toInt = (neg q).toIntzero = neg q q:PosintDecimalhpq:q = 0zero = neg q; All goals completed! 🐙 q:IntDecimalp:PosintDecimalhpq:(pos p).toInt = q.toIntpos p = q cases q with p:PosintDecimalhpq:(pos p).toInt = zero.toIntpos p = zero p:PosintDecimalhpq:p = 0pos p = zero; All goals completed! 🐙 p:PosintDecimalq:PosintDecimalhpq:(pos p).toInt = (pos q).toIntpos p = pos q All goals completed! 🐙 p:PosintDecimalq:PosintDecimalhpq:(pos p).toInt = (neg q).toIntpos p = neg q p:PosintDecimalq:PosintDecimalhpq:p = 0 q = 0pos p = neg q; All goals completed! 🐙 q:IntDecimalp:PosintDecimalhpq:(neg p).toInt = q.toIntneg p = q cases q with p:PosintDecimalhpq:(neg p).toInt = zero.toIntneg p = zero p:PosintDecimalhpq:p = 0neg p = zero; All goals completed! 🐙 p:PosintDecimalq:PosintDecimalhpq:(neg p).toInt = (pos q).toIntneg p = pos q p:PosintDecimalq:PosintDecimalhpq:p = 0 q = 0neg p = pos q; All goals completed! 🐙 p:PosintDecimalq:PosintDecimalhpq:(neg p).toInt = (neg q).toIntneg p = neg q All goals completed! 🐙 n: a, a.toInt = n n:h:n < 0 a, a.toInt = n a, a.toInt = 0n:h:0 < n a, a.toInt = n n:h:n < 0 a, a.toInt = n n:h:n < 0m:e:-n = m a, a.toInt = n lift m to Nat using (n:h:n < 0m:e:-n = m0 m All goals completed! 🐙) choose p hp _ using PosintDecimal.exists_unique _ (show 0 < m Function.Bijective toInt All goals completed! 🐙) n:h:n < 0m:e:-n = mp:PosintDecimalhp:p = ma✝: (y : PosintDecimal), (fun p => p = m) y y = p(neg p).toInt = n All goals completed! 🐙 a, a.toInt = 0 zero.toInt = 0; All goals completed! 🐙 lift n to Nat using (n:h:0 < n0 n All goals completed! 🐙); n:h:0 < n a, a.toInt = n n:h:0 < np:PosintDecimalhp:p = na✝: (y : PosintDecimal), (fun p => p = n) y y = p a, a.toInt = n n:h:0 < np:PosintDecimalhp:p = na✝: (y : PosintDecimal), (fun p => p = n) y y = p(pos p).toInt = n All goals completed! 🐙abbrev PosintDecimal.digit (p:PosintDecimal) (i:) : Digit := if h: i < p.digits.length then p.digits[p.digits.length - i - 1] else 0abbrev PosintDecimal.carry (p q:PosintDecimal) : := Nat.rec 0 (fun i ε if ((p.digit i:) + (q.digit i:) + ε) < 10 then 0 else 1)theorem PosintDecimal.carry_zero (p q:PosintDecimal) : p.carry q 0 = 0 := p:PosintDecimalq:PosintDecimalp.carry q 0 = 0 All goals completed! 🐙theorem PosintDecimal.carry_succ (p q:PosintDecimal) (i:) : p.carry q (i+1) = if ((p.digit i:) + (q.digit i:) + p.carry q i < 10) then 0 else 1 := Nat.rec_add_one 0 (fun i ε if ((p.digit i:) + (q.digit i:) + ε) < 10 then 0 else 1) iabbrev PosintDecimal.sum_digit (p q:PosintDecimal) (i:) : := if (p.digit i + q.digit i + (p.carry q) i < 10) then p.digit i + q.digit i + (p.carry q) i else p.digit i + q.digit i + (p.carry q) i - 10

Exercise B.1.1

theorem declaration uses 'sorry'PosintDecimal.sum_digit_lt (p q:PosintDecimal) (i:) : p.sum_digit q i < 10 := p:PosintDecimalq:PosintDecimali:p.sum_digit q i < 10 All goals completed! 🐙

Define this number such that it satisfies the two following theorems.

def declaration uses 'sorry'PosintDecimal.sum_digit_top (p q:PosintDecimal) : := p:PosintDecimalq:PosintDecimal All goals completed! 🐙
theorem declaration uses 'sorry'PosintDecimal.leading_nonzero (p q:PosintDecimal) : p.sum_digit q (p.sum_digit_top q) 0 := sorrytheorem declaration uses 'sorry'PosintDecimal.out_of_range_eq_zero (p q:PosintDecimal) : i > (p.sum_digit_top q), p.sum_digit q i = 0 := sorrydef declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'PosintDecimal.longAddition (p q : PosintDecimal) : PosintDecimal where digits := sorry nonempty := sorry nonzero := sorrytheorem declaration uses 'sorry'PosintDecimal.sum_eq (p q:PosintDecimal) (i:) : (((p.longAddition q).digit i):) = p.sum_digit q i (p.longAddition q:) = p + q := p:PosintDecimalq:PosintDecimali:((p.longAddition q).digit i) = p.sum_digit q i (p.longAddition q) = p + q All goals completed! 🐙