Theorem: PosNum.divMod_to_nat_aux
File: Mathlib/Data/Num/Lemmas.lean

tactic: unfold divModAux
state_before: 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

tactic: 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
state_before: 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

tactic: cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
state_before: 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

tactic: intro r₂
state_before: 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

tactic: apply Num.mem_ofZNum'.trans
state_before: 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

tactic: rw [← ZNum.to_int_inj, Num.cast_toZNum, Num.cast_sub', sub_eq_iff_eq_add, ← Int.coe_nat_inj']
state_before: 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

tactic: simp
state_before: 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)

tactic: refine' ⟨h₁, lt_of_not_ge fun h => _⟩
state_before: 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

tactic: cases' Nat.le.dest h with r₂ e'
state_before: 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

tactic: rw [← Num.to_of_nat r₂, add_comm] at e'
state_before: 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

tactic: cases e.symm.trans (this.2 e'.symm)
state_before: 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

tactic: have := this.1 e
state_before: 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

tactic: constructor
state_before: 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

tactic: rwa [_root_.bit1, add_comm _ 1, mul_add, mul_one, ← add_assoc, ← this]
state_before: 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

tactic: rwa [this, two_mul, add_lt_add_iff_right] at h₂
state_before: 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