n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
⊢ ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
            | some r' => (Num.bit1 q, r')
            | none => (Num.bit0 q, r)).snd +
        ↑d *
          ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).fst =
      ↑n ∧
    ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).snd <
      ↑d
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
⊢ ↑(divModAux d q r).snd + ↑d * ↑(divModAux d q r).fst = ↑n ∧ ↑(divModAux d q r).snd < ↑d
unfold divModAux
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
⊢ ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
            | some r' => (Num.bit1 q, r')
            | none => (Num.bit0 q, r)).snd +
        ↑d *
          ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).fst =
      ↑n ∧
    ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).snd <
      ↑d
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
⊢ ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
            | some r' => (Num.bit1 q, r')
            | none => (Num.bit0 q, r)).snd +
        ↑d *
          ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).fst =
      ↑n ∧
    ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).snd <
      ↑d
have : ∀ {r₂}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ (r : ℕ) = r₂ + d := by
  intro r₂
  apply Num.mem_ofZNum'.trans
  rw [← ZNum.to_int_inj, Num.cast_toZNum, Num.cast_sub', sub_eq_iff_eq_add, ← Int.coe_nat_inj']
  simp
case none
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
⊢ ↑r + ↑d * _root_.bit0 ↑q = ↑n ∧ ↑r < ↑d

case some
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n ∧ ↑r₂ < ↑d
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
⊢ ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
            | some r' => (Num.bit1 q, r')
            | none => (Num.bit0 q, r)).snd +
        ↑d *
          ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).fst =
      ↑n ∧
    ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).snd <
      ↑d
cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
⊢ ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
intro r₂
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ Num.sub' r (Num.pos d) = Num.toZNum r₂ ↔ ↑r = ↑r₂ + ↑d
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
apply Num.mem_ofZNum'.trans
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ ↑r = ↑r₂ + ↑(Num.pos d) ↔ ↑↑r = ↑(↑r₂ + ↑d)
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ Num.sub' r (Num.pos d) = Num.toZNum r₂ ↔ ↑r = ↑r₂ + ↑d
rw [← ZNum.to_int_inj, Num.cast_toZNum, Num.cast_sub', sub_eq_iff_eq_add, ← Int.coe_nat_inj']
no goals
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ ↑r = ↑r₂ + ↑(Num.pos d) ↔ ↑↑r = ↑(↑r₂ + ↑d)
simp
case none
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
h : ↑r ≥ ↑d
⊢ False
case none
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
⊢ ↑r + ↑d * _root_.bit0 ↑q = ↑n ∧ ↑r < ↑d
refine' ⟨h₁, lt_of_not_ge fun h => _⟩
case none.intro
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑d + r₂ = ↑r
⊢ False
case none
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
h : ↑r ≥ ↑d
⊢ False
cases' Nat.le.dest h with r₂ e'
case none.intro
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑↑r₂ + ↑d = ↑r
⊢ False
case none.intro
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑d + r₂ = ↑r
⊢ False
rw [← Num.to_of_nat r₂, add_comm] at e'
no goals
case none.intro
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑↑r₂ + ↑d = ↑r
⊢ False
cases e.symm.trans (this.2 e'.symm)
case some
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this✝ : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n ∧ ↑r₂ < ↑d
case some
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n ∧ ↑r₂ < ↑d
have := this.1 e
case some.left
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this✝ : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n

case some.right
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this✝ : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ < ↑d
case some
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this✝ : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n ∧ ↑r₂ < ↑d
constructor
no goals
case some.left
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this✝ : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n
rwa [_root_.bit1, add_comm _ 1, mul_add, mul_one, ← add_assoc, ← this]
no goals
case some.right
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this✝ : ∀ {r₂ : Num}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ < ↑d
rwa [this, two_mul, add_lt_add_iff_right] at h₂