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

tactic: rw [Nat.div_mod_unique (PosNum.cast_pos _)]
state_before: d n : PosNum
⊢ ↑n / ↑d = ↑(d.divMod n).1 ∧ ↑n % ↑d = ↑(d.divMod n).2
state_after: d n : PosNum
⊢ ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d

tactic: induction' n with n IH n IH
state_before: d n : PosNum
⊢ ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
state_after: case one
d : PosNum
⊢ ↑(d.divMod one).2 + ↑d * ↑(d.divMod one).1 = ↑one ∧ ↑(d.divMod one).2 < ↑d

case bit1
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(d.divMod n.bit1).2 + ↑d * ↑(d.divMod n.bit1).1 = ↑n.bit1 ∧ ↑(d.divMod n.bit1).2 < ↑d

case bit0
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(d.divMod n.bit0).2 + ↑d * ↑(d.divMod n.bit0).1 = ↑n.bit0 ∧ ↑(d.divMod n.bit0).2 < ↑d

tactic: exact
  divMod_to_nat_aux (by simp) (Nat.mul_le_mul_left 2 (PosNum.cast_pos d : (0 : ℕ) < d))
state_before: case one
d : PosNum
⊢ ↑(d.divMod one).2 + ↑d * ↑(d.divMod one).1 = ↑one ∧ ↑(d.divMod one).2 < ↑d
state_after: no goals

tactic: simp
state_before: d : PosNum
⊢ ↑1 + ↑d * _root_.bit0 ↑0 = ↑one
state_after: no goals

tactic: unfold divMod
state_before: case bit1
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(d.divMod n.bit1).2 + ↑d * ↑(d.divMod n.bit1).1 = ↑n.bit1 ∧ ↑(d.divMod n.bit1).2 < ↑d
state_after: case bit1
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit1).2 +
        ↑d *
          ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit1).1 =
      ↑n.bit1 ∧
    ↑(match d.divMod n with
          | (q, r₁) => d.divModAux q r₁.bit1).2 <
      ↑d

tactic: revert IH
state_before: case bit1
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit1).2 +
        ↑d *
          ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit1).1 =
      ↑n.bit1 ∧
    ↑(match d.divMod n with
          | (q, r₁) => d.divModAux q r₁.bit1).2 <
      ↑d
state_after: case bit1
d n : PosNum
⊢ ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d →
    ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit1).2 +
          ↑d *
            ↑(match d.divMod n with
                | (q, r₁) => d.divModAux q r₁.bit1).1 =
        ↑n.bit1 ∧
      ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit1).2 <
        ↑d

tactic: cases' divMod d n with q r
state_before: case bit1
d n : PosNum
⊢ ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d →
    ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit1).2 +
          ↑d *
            ↑(match d.divMod n with
                | (q, r₁) => d.divModAux q r₁.bit1).1 =
        ↑n.bit1 ∧
      ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit1).2 <
        ↑d
state_after: case bit1.mk
d n : PosNum
q r : Num
⊢ ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d →
    ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit1).2 +
          ↑d *
            ↑(match (q, r) with
                | (q, r₁) => d.divModAux q r₁.bit1).1 =
        ↑n.bit1 ∧
      ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit1).2 <
        ↑d

tactic: intro IH
state_before: case bit1.mk
d n : PosNum
q r : Num
⊢ ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d →
    ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit1).2 +
          ↑d *
            ↑(match (q, r) with
                | (q, r₁) => d.divModAux q r₁.bit1).1 =
        ↑n.bit1 ∧
      ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit1).2 <
        ↑d
state_after: case bit1.mk
d n : PosNum
q r : Num
IH : ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d
⊢ ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit1).2 +
        ↑d *
          ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit1).1 =
      ↑n.bit1 ∧
    ↑(match (q, r) with
          | (q, r₁) => d.divModAux q r₁.bit1).2 <
      ↑d

tactic: simp only [divMod] at IH ⊢
state_before: case bit1.mk
d n : PosNum
q r : Num
IH : ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d
⊢ ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit1).2 +
        ↑d *
          ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit1).1 =
      ↑n.bit1 ∧
    ↑(match (q, r) with
          | (q, r₁) => d.divModAux q r₁.bit1).2 <
      ↑d
state_after: case bit1.mk
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ ↑(d.divModAux q r.bit1).2 + ↑d * ↑(d.divModAux q r.bit1).1 = ↑n.bit1 ∧ ↑(d.divModAux q r.bit1).2 < ↑d

tactic: apply divMod_to_nat_aux <;> simp
state_before: case bit1.mk
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ ↑(d.divModAux q r.bit1).2 + ↑d * ↑(d.divModAux q r.bit1).1 = ↑n.bit1 ∧ ↑(d.divModAux q r.bit1).2 < ↑d
state_after: case bit1.mk.h₁
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit1 ↑r + ↑d * _root_.bit0 ↑q = _root_.bit1 ↑n

case bit1.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit1 ↑r < 2 * ↑d

tactic: rw [_root_.bit1, _root_.bit1, add_right_comm, bit0_eq_two_mul (n : ℕ), ← IH.1, mul_add, ←
  bit0_eq_two_mul, mul_left_comm, ← bit0_eq_two_mul]
state_before: case bit1.mk.h₁
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit1 ↑r + ↑d * _root_.bit0 ↑q = _root_.bit1 ↑n
state_after: no goals

tactic: rw [← bit0_eq_two_mul]
state_before: case bit1.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit1 ↑r < 2 * ↑d
state_after: case bit1.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit1 ↑r < _root_.bit0 ↑d

tactic: exact Nat.bit1_lt_bit0 IH.2
state_before: case bit1.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit1 ↑r < _root_.bit0 ↑d
state_after: no goals

tactic: unfold divMod
state_before: case bit0
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(d.divMod n.bit0).2 + ↑d * ↑(d.divMod n.bit0).1 = ↑n.bit0 ∧ ↑(d.divMod n.bit0).2 < ↑d
state_after: case bit0
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit0).2 +
        ↑d *
          ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit0).1 =
      ↑n.bit0 ∧
    ↑(match d.divMod n with
          | (q, r₁) => d.divModAux q r₁.bit0).2 <
      ↑d

tactic: revert IH
state_before: case bit0
d n : PosNum
IH : ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d
⊢ ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit0).2 +
        ↑d *
          ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit0).1 =
      ↑n.bit0 ∧
    ↑(match d.divMod n with
          | (q, r₁) => d.divModAux q r₁.bit0).2 <
      ↑d
state_after: case bit0
d n : PosNum
⊢ ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d →
    ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit0).2 +
          ↑d *
            ↑(match d.divMod n with
                | (q, r₁) => d.divModAux q r₁.bit0).1 =
        ↑n.bit0 ∧
      ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit0).2 <
        ↑d

tactic: cases' divMod d n with q r
state_before: case bit0
d n : PosNum
⊢ ↑(d.divMod n).2 + ↑d * ↑(d.divMod n).1 = ↑n ∧ ↑(d.divMod n).2 < ↑d →
    ↑(match d.divMod n with
              | (q, r₁) => d.divModAux q r₁.bit0).2 +
          ↑d *
            ↑(match d.divMod n with
                | (q, r₁) => d.divModAux q r₁.bit0).1 =
        ↑n.bit0 ∧
      ↑(match d.divMod n with
            | (q, r₁) => d.divModAux q r₁.bit0).2 <
        ↑d
state_after: case bit0.mk
d n : PosNum
q r : Num
⊢ ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d →
    ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit0).2 +
          ↑d *
            ↑(match (q, r) with
                | (q, r₁) => d.divModAux q r₁.bit0).1 =
        ↑n.bit0 ∧
      ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit0).2 <
        ↑d

tactic: intro IH
state_before: case bit0.mk
d n : PosNum
q r : Num
⊢ ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d →
    ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit0).2 +
          ↑d *
            ↑(match (q, r) with
                | (q, r₁) => d.divModAux q r₁.bit0).1 =
        ↑n.bit0 ∧
      ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit0).2 <
        ↑d
state_after: case bit0.mk
d n : PosNum
q r : Num
IH : ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d
⊢ ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit0).2 +
        ↑d *
          ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit0).1 =
      ↑n.bit0 ∧
    ↑(match (q, r) with
          | (q, r₁) => d.divModAux q r₁.bit0).2 <
      ↑d

tactic: simp only [divMod] at IH ⊢
state_before: case bit0.mk
d n : PosNum
q r : Num
IH : ↑(q, r).2 + ↑d * ↑(q, r).1 = ↑n ∧ ↑(q, r).2 < ↑d
⊢ ↑(match (q, r) with
            | (q, r₁) => d.divModAux q r₁.bit0).2 +
        ↑d *
          ↑(match (q, r) with
              | (q, r₁) => d.divModAux q r₁.bit0).1 =
      ↑n.bit0 ∧
    ↑(match (q, r) with
          | (q, r₁) => d.divModAux q r₁.bit0).2 <
      ↑d
state_after: case bit0.mk
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ ↑(d.divModAux q r.bit0).2 + ↑d * ↑(d.divModAux q r.bit0).1 = ↑n.bit0 ∧ ↑(d.divModAux q r.bit0).2 < ↑d

tactic: apply divMod_to_nat_aux <;> simp
state_before: case bit0.mk
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ ↑(d.divModAux q r.bit0).2 + ↑d * ↑(d.divModAux q r.bit0).1 = ↑n.bit0 ∧ ↑(d.divModAux q r.bit0).2 < ↑d
state_after: case bit0.mk.h₁
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit0 ↑r + ↑d * _root_.bit0 ↑q = _root_.bit0 ↑n

case bit0.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit0 ↑r < 2 * ↑d

tactic: rw [bit0_eq_two_mul (n : ℕ), ← IH.1, mul_add, ← bit0_eq_two_mul, mul_left_comm, ←
  bit0_eq_two_mul]
state_before: case bit0.mk.h₁
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit0 ↑r + ↑d * _root_.bit0 ↑q = _root_.bit0 ↑n
state_after: no goals

tactic: rw [← bit0_eq_two_mul]
state_before: case bit0.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit0 ↑r < 2 * ↑d
state_after: case bit0.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit0 ↑r < _root_.bit0 ↑d

tactic: exact Nat.bit0_lt IH.2
state_before: case bit0.mk.h₂
d n : PosNum
q r : Num
IH : ↑r + ↑d * ↑q = ↑n ∧ ↑r < ↑d
⊢ _root_.bit0 ↑r < _root_.bit0 ↑d
state_after: no goals