l3lab/ntp-mathlib huggingface dataset:
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by transfer
    zero_mul := by transfer
    mul_zero := by 

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
⊢ ∀ (a : ZNum), a * 0 = 0

Next tactic:
transfer
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by 

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
⊢ ∀ (a b c : ZNum), a * b * c = a * (b * c)

Next tactic:
transfer
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by transfer
    zero_mul := by transfer
    mul_zero := by transfer
    one_mul := by 

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
⊢ ∀ (a : ZNum), 1 * a = a

Next tactic:
transfer
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by transfer
    zero_mul := by transfer
    mul_zero := by transfer
    one_mul := by transfer
    mul_one := by 

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
⊢ ∀ (a : ZNum), a * 1 = a

Next tactic:
transfer
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by transfer
    zero_mul := by transfer
    mul_zero := by transfer
    one_mul := by transfer
    mul_one := by transfer
    left_distrib := by
      transfer
      simp [mul_add]
    right_distrib := by
      transfer
      simp [mul_add, _root_.mul_comm]
    mul_comm := mul_comm
    exists_pair_ne := ⟨0, 1, by 

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
⊢ 0 ≠ 1

Next tactic:
decide
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by transfer
    zero_mul := by transfer
    mul_zero := by transfer
    one_mul := by transfer
    mul_one := by transfer
    left_distrib := by
      transfer
      simp [mul_add]
    right_distrib := by
      transfer
      simp [mul_add, _root_.mul_comm]
    mul_comm := mul_comm
    exists_pair_ne := ⟨0, 1, by decide⟩
    add_le_add_left := add_le_add_left
    mul_pos := fun a b =>
      show 0 < a → 0 < b → 0 < a * b by
        transfer_rw
        apply mul_pos
    zero_le_one := by 

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
⊢ 0 ≤ 1

Next tactic:
decide
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by transfer
    zero_mul := by transfer
    mul_zero := by transfer
    one_mul := by transfer
    mul_one := by transfer
    left_distrib := by
      transfer
      simp [mul_add]
    right_distrib := by
      transfer
      simp [mul_add, _root_.mul_comm]
    mul_comm := mul_comm
    exists_pair_ne := ⟨0, 1, by decide⟩
    add_le_add_left := add_le_add_left
    mul_pos := fun a b =>
      show 0 < a → 0 < b → 0 < a * b by
        

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
a b : ZNum
⊢ 0 < a → 0 < b → 0 < a * b

Next tactic:
transfer_rw
instance linearOrderedCommRing : LinearOrderedCommRing ZNum :=
  { ZNum.linearOrder, ZNum.addCommGroup, ZNum.addMonoidWithOne with
    mul := (· * ·)
    mul_assoc := by transfer
    zero_mul := by transfer
    mul_zero := by transfer
    one_mul := by transfer
    mul_one := by transfer
    left_distrib := by
      transfer
      simp [mul_add]
    right_distrib := by
      transfer
      simp [mul_add, _root_.mul_comm]
    mul_comm := mul_comm
    exists_pair_ne := ⟨0, 1, by decide⟩
    add_le_add_left := add_le_add_left
    mul_pos := fun a b =>
      show 0 < a → 0 < b → 0 < a * b by
        transfer_rw
        

Proof state:
α : Type u_1
src✝² : LinearOrder ZNum := linearOrder
src✝¹ : AddCommGroup ZNum := addCommGroup
src✝ : AddMonoidWithOne ZNum := addMonoidWithOne
a b : ZNum
⊢ 0 < ↑a → 0 < ↑b → 0 < ↑a * ↑b

Next tactic:
apply mul_pos
@[simp, norm_cast]
theorem cast_sub [Ring α] (m n) : ((m - n : ZNum) : α) = m - n := by 

Proof state:
α : Type u_1
inst✝ : Ring α
m n : ZNum
⊢ ↑(m - n) = ↑m - ↑n

Next tactic:
simp [sub_eq_neg_add]
@[norm_cast] -- @[simp] -- Porting note: simp can prove this
theorem neg_of_int : ∀ n, ((-n : ℤ) : ZNum) = -n
  | (n + 1 : ℕ) => rfl
  | 0 => by 

Proof state:
α : Type u_1
⊢ ↑(-0) = -↑0

Next tactic:
rw [Int.cast_neg, Int.cast_zero]
@[simp]
theorem ofInt'_eq : ∀ n : ℤ, ZNum.ofInt' n = n
  | (n : ℕ) => rfl
  | -[n+1] => by
    

Proof state:
α : Type u_1
n : ℕ
⊢ ofInt' -[n+1] = ↑-[n+1]

Next tactic:
show Num.toZNumNeg (n + 1 : ℕ) = -(n + 1 : ℕ)
@[simp]
theorem ofInt'_eq : ∀ n : ℤ, ZNum.ofInt' n = n
  | (n : ℕ) => rfl
  | -[n+1] => by
    show Num.toZNumNeg (n + 1 : ℕ) = -(n + 1 : ℕ)
    

Proof state:
α : Type u_1
n : ℕ
⊢ Num.toZNumNeg ↑(n + 1) = -↑(n + 1)

Next tactic:
rw [← neg_inj, neg_neg, Nat.cast_succ, Num.add_one, Num.zneg_toZNumNeg, Num.toZNum_succ,
      Nat.cast_succ, ZNum.add_one]
@[simp]
theorem ofInt'_eq : ∀ n : ℤ, ZNum.ofInt' n = n
  | (n : ℕ) => rfl
  | -[n+1] => by
    show Num.toZNumNeg (n + 1 : ℕ) = -(n + 1 : ℕ)
    rw [← neg_inj, neg_neg, Nat.cast_succ, Num.add_one, Num.zneg_toZNumNeg, Num.toZNum_succ,
      Nat.cast_succ, ZNum.add_one]
    

Proof state:
α : Type u_1
n : ℕ
⊢ succ (Num.toZNum ↑n) = succ ↑n

Next tactic:
rfl
@[simp high, norm_cast]
theorem of_to_int (n : ZNum) : ((n : ℤ) : ZNum) = n := by 

Proof state:
α : Type u_1
n : ZNum
⊢ ↑↑n = n

Next tactic:
rw [← ofInt'_eq, of_to_int']
theorem to_of_int (n : ℤ) : ((n : ZNum) : ℤ) = n :=
  Int.inductionOn' n 0 (by 

Proof state:
α : Type u_1
n : ℤ
⊢ ↑↑0 = 0

Next tactic:
simp
theorem to_of_int (n : ℤ) : ((n : ZNum) : ℤ) = n :=
  Int.inductionOn' n 0 (by simp) (by 

Proof state:
α : Type u_1
n : ℤ
⊢ ∀ (k : ℤ), 0 ≤ k → ↑↑k = k → ↑↑(k + 1) = k + 1

Next tactic:
simp
theorem to_of_int (n : ℤ) : ((n : ZNum) : ℤ) = n :=
  Int.inductionOn' n 0 (by simp) (by simp) (by 

Proof state:
α : Type u_1
n : ℤ
⊢ ∀ k ≤ 0, ↑↑k = k → ↑↑(k - 1) = k - 1

Next tactic:
simp
@[simp]
theorem of_nat_toZNumNeg (n : ℕ) : Num.toZNumNeg n = -n := by 

Proof state:
α : Type u_1
n : ℕ
⊢ Num.toZNumNeg ↑n = -↑n

Next tactic:
rw [← of_nat_toZNum, Num.zneg_toZNum]
@[simp, norm_cast]
theorem of_int_cast [AddGroupWithOne α] (n : ℤ) : ((n : ZNum) : α) = n := by
  

Proof state:
α : Type u_1
inst✝ : AddGroupWithOne α
n : ℤ
⊢ ↑↑n = ↑n

Next tactic:
rw [← cast_to_int, to_of_int]
@[simp, norm_cast]
theorem of_nat_cast [AddGroupWithOne α] (n : ℕ) : ((n : ZNum) : α) = n := by
  

Proof state:
α : Type u_1
inst✝ : AddGroupWithOne α
n : ℕ
⊢ ↑↑n = ↑n

Next tactic:
rw [← Int.cast_ofNat, of_int_cast, Int.cast_ofNat]
@[simp, norm_cast]
theorem dvd_to_int (m n : ZNum) : (m : ℤ) ∣ n ↔ m ∣ n :=
  ⟨fun ⟨k, e⟩ => ⟨k, by 

Proof state:
α : Type u_1
m n : ZNum
x✝ : ↑m ∣ ↑n
k : ℤ
e : ↑n = ↑m * k
⊢ n = m * ↑k

Next tactic:
rw [← of_to_int n, e]
@[simp, norm_cast]
theorem dvd_to_int (m n : ZNum) : (m : ℤ) ∣ n ↔ m ∣ n :=
  ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_int n, e]; 

Proof state:
α : Type u_1
m n : ZNum
x✝ : ↑m ∣ ↑n
k : ℤ
e : ↑n = ↑m * k
⊢ ↑(↑m * k) = m * ↑k

Next tactic:
simp
@[simp, norm_cast]
theorem dvd_to_int (m n : ZNum) : (m : ℤ) ∣ n ↔ m ∣ n :=
  ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_int n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by 

Proof state:
α : Type u_1
m n : ZNum
x✝ : m ∣ n
k : ZNum
e : n = m * k
⊢ ↑n = ↑m * ↑k

Next tactic:
simp [e]
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  

Proof state:
n d : PosNum
q r : Num
h₁ : ↑r + ↑d * _root_.bit0 ↑q = ↑n
h₂ : ↑r < 2 * ↑d
⊢ ↑(divModAux d q r).2 + ↑d * ↑(divModAux d q r).1 = ↑n ∧ ↑(divModAux d q r).2 < ↑d

Next tactic:
unfold divModAux
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  

Proof state:
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)).2 +
        ↑d *
          ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).1 =
      ↑n ∧
    ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).2 <
      ↑d

Next 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
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  have : ∀ {r₂}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ (r : ℕ) = r₂ + d := by
    

Proof state:
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

Next tactic:
intro r₂
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  have : ∀ {r₂}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ (r : ℕ) = r₂ + d := by
    intro r₂
    

Proof state:
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

Next tactic:
apply Num.mem_ofZNum'.trans
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  have : ∀ {r₂}, Num.ofZNum' (Num.sub' r (Num.pos d)) = some r₂ ↔ (r : ℕ) = r₂ + d := by
    intro r₂
    apply Num.mem_ofZNum'.trans
    

Proof state:
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

Next tactic:
rw [← ZNum.to_int_inj, Num.cast_toZNum, Num.cast_sub', sub_eq_iff_eq_add, ← Int.coe_nat_inj']
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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']
    

Proof state:
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)

Next tactic:
simp
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  

Proof state:
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)).2 +
        ↑d *
          ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).1 =
      ↑n ∧
    ↑(match Num.ofZNum' (Num.sub' r (Num.pos d)) with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).2 <
      ↑d

Next tactic:
cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> 

Proof state:
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
⊢ ↑(match none with
            | some r' => (Num.bit1 q, r')
            | none => (Num.bit0 q, r)).2 +
        ↑d *
          ↑(match none with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).1 =
      ↑n ∧
    ↑(match none with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).2 <
      ↑d

Next tactic:
simp [divModAux]
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> 

Proof state:
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₂
⊢ ↑(match some r₂ with
            | some r' => (Num.bit1 q, r')
            | none => (Num.bit0 q, r)).2 +
        ↑d *
          ↑(match some r₂ with
              | some r' => (Num.bit1 q, r')
              | none => (Num.bit0 q, r)).1 =
      ↑n ∧
    ↑(match some r₂ with
          | some r' => (Num.bit1 q, r')
          | none => (Num.bit0 q, r)).2 <
      ↑d

Next tactic:
simp [divModAux]
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · 

Proof state:
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

Next tactic:
refine' ⟨h₁, lt_of_not_ge fun h => _⟩
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · refine' ⟨h₁, lt_of_not_ge fun h => _⟩
    

Proof state:
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

Next tactic:
cases' Nat.le.dest h with r₂ e'
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · refine' ⟨h₁, lt_of_not_ge fun h => _⟩
    cases' Nat.le.dest h with r₂ e'
    

Proof state:
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

Next tactic:
rw [← Num.to_of_nat r₂, add_comm] at e'
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · refine' ⟨h₁, lt_of_not_ge fun h => _⟩
    cases' Nat.le.dest h with r₂ e'
    rw [← Num.to_of_nat r₂, add_comm] at e'
    

Proof state:
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

Next tactic:
cases e.symm.trans (this.2 e'.symm)
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · refine' ⟨h₁, lt_of_not_ge fun h => _⟩
    cases' Nat.le.dest h with r₂ e'
    rw [← Num.to_of_nat r₂, add_comm] at e'
    cases e.symm.trans (this.2 e'.symm)
  · 

Proof state:
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

Next tactic:
have := this.1 e
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · refine' ⟨h₁, lt_of_not_ge fun h => _⟩
    cases' Nat.le.dest h with r₂ e'
    rw [← Num.to_of_nat r₂, add_comm] at e'
    cases e.symm.trans (this.2 e'.symm)
  · have := this.1 e
    

Proof state:
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

Next tactic:
constructor
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · refine' ⟨h₁, lt_of_not_ge fun h => _⟩
    cases' Nat.le.dest h with r₂ e'
    rw [← Num.to_of_nat r₂, add_comm] at e'
    cases e.symm.trans (this.2 e'.symm)
  · have := this.1 e
    constructor
    · 

Proof state:
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

Next tactic:
rwa [_root_.bit1, add_comm _ 1, mul_add, mul_one, ← add_assoc, ← this]
theorem divMod_to_nat_aux {n d : PosNum} {q r : Num} (h₁ : (r : ℕ) + d * _root_.bit0 (q : ℕ) = n)
    (h₂ : (r : ℕ) < 2 * d) :
    ((divModAux d q r).2 + d * (divModAux d q r).1 : ℕ) = ↑n ∧ ((divModAux d q r).2 : ℕ) < d := by
  unfold divModAux
  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
  cases' e : Num.ofZNum' (Num.sub' r (Num.pos d)) with r₂ <;> simp [divModAux]
  · refine' ⟨h₁, lt_of_not_ge fun h => _⟩
    cases' Nat.le.dest h with r₂ e'
    rw [← Num.to_of_nat r₂, add_comm] at e'
    cases e.symm.trans (this.2 e'.symm)
  · have := this.1 e
    constructor
    · rwa [_root_.bit1, add_comm _ 1, mul_add, mul_one, ← add_assoc, ← this]
    · 

Proof state:
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

Next tactic:
rwa [this, two_mul, add_lt_add_iff_right] at h₂
theorem divMod_to_nat (d n : PosNum) :
    (n / d : ℕ) = (divMod d n).1 ∧ (n % d : ℕ) = (divMod d n).2 := by
  

Proof state:
d n : PosNum
⊢ ↑n / ↑d = ↑(divMod d n).1 ∧ ↑n % ↑d = ↑(divMod d n).2

Next tactic:
rw [Nat.div_mod_unique (PosNum.cast_pos _)]