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
⊢ ↑(d.divModAux q r).2 + ↑d * ↑(d.divModAux q r).1 = ↑n ∧ ↑(d.divModAux q r).2 < ↑d
state_after: n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
⊢ ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
            | some r' => (q.bit1, r')
            | none => (q.bit0, r)).2 +
        ↑d *
          ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
              | some r' => (q.bit1, r')
              | none => (q.bit0, r)).1 =
      ↑n ∧
    ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
          | some r' => (q.bit1, r')
          | none => (q.bit0, r)).2 <
      ↑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.natCast_inj]
  simp
state_before: n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
⊢ ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
            | some r' => (q.bit1, r')
            | none => (q.bit0, r)).2 +
        ↑d *
          ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
              | some r' => (q.bit1, r')
              | none => (q.bit0, r)).1 =
      ↑n ∧
    ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
          | some r' => (q.bit1, r')
          | none => (q.bit0, r)).2 <
      ↑d
state_after: n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
⊢ ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
            | some r' => (q.bit1, r')
            | none => (q.bit0, r)).2 +
        ↑d *
          ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
              | some r' => (q.bit1, r')
              | none => (q.bit0, r)).1 =
      ↑n ∧
    ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
          | some r' => (q.bit1, r')
          | none => (q.bit0, r)).2 <
      ↑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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
⊢ ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
            | some r' => (q.bit1, r')
            | none => (q.bit0, r)).2 +
        ↑d *
          ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
              | some r' => (q.bit1, r')
              | none => (q.bit0, r)).1 =
      ↑n ∧
    ↑(match Num.ofZNum' (r.sub' (Num.pos d)) with
          | some r' => (q.bit1, r')
          | none => (q.bit0, r)).2 <
      ↑d
state_after: case none
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (Num.pos d)) = some r₂
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n ∧ ↑r₂ < ↑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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
state_after: n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ Num.ofZNum' (r.sub' (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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
state_after: n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ r.sub' (Num.pos d) = r₂.toZNum ↔ ↑r = ↑r₂ + ↑d

tactic: rw [← ZNum.to_int_inj, Num.cast_toZNum, Num.cast_sub', sub_eq_iff_eq_add, ← Int.natCast_inj]
state_before: n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
r₂ : Num
⊢ r.sub' (Num.pos d) = r₂.toZNum ↔ ↑r = ↑r₂ + ↑d
state_after: 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: 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)
state_after: no goals

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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (Num.pos d)) = none
⊢ ↑r + ↑d * _root_.bit0 ↑q = ↑n ∧ ↑r < ↑d
state_after: case none
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this : ∀ {r₂ : Num}, Num.ofZNum' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (Num.pos d)) = none
h : ↑r ≥ ↑d
⊢ False

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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (Num.pos d)) = none
h : ↑r ≥ ↑d
⊢ False
state_after: 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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑d + r₂ = ↑r
⊢ 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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑d + r₂ = ↑r
⊢ False
state_after: 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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑↑r₂ + ↑d = ↑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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
e : Num.ofZNum' (r.sub' (Num.pos d)) = none
h : ↑r ≥ ↑d
r₂ : ℕ
e' : ↑↑r₂ + ↑d = ↑r
⊢ False
state_after: no goals

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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (Num.pos d)) = some r₂
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n ∧ ↑r₂ < ↑d
state_after: case some
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
this✝ : ∀ {r₂ : Num}, Num.ofZNum' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n ∧ ↑r₂ < ↑d
state_after: 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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ + ↑d * _root_.bit1 ↑q = ↑n
state_after: no goals

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' (r.sub' (Num.pos d)) = some r₂ ↔ ↑r = ↑r₂ + ↑d
r₂ : Num
e : Num.ofZNum' (r.sub' (Num.pos d)) = some r₂
this : ↑r = ↑r₂ + ↑d
⊢ ↑r₂ < ↑d
state_after: no goals