Theorem: Nat.sqrt.lt_iter_succ_sq
File: Mathlib/Data/Nat/Defs.lean

tactic: unfold sqrt.iter
state_before: a b c d m n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
⊢ n < (iter n guess + 1) * (iter n guess + 1)
state_after: a b c d m n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
⊢ n <
    ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1) *
      ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1)

tactic: let m := (guess + n / guess) / 2
state_before: a b c d m n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
⊢ n <
    ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1) *
      ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1)
state_after: a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
⊢ n <
    ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1) *
      ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1)

tactic: dsimp
state_before: a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
⊢ n <
    ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1) *
      ((let next := (guess + n / guess) / 2;
        if _h : next < guess then iter n next else guess) +
        1)
state_after: a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
⊢ n <
    ((if (guess + n / guess) / 2 < guess then iter n ((guess + n / guess) / 2) else guess) + 1) *
      ((if (guess + n / guess) / 2 < guess then iter n ((guess + n / guess) / 2) else guess) + 1)

tactic: split_ifs with h
state_before: a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
⊢ n <
    ((if (guess + n / guess) / 2 < guess then iter n ((guess + n / guess) / 2) else guess) + 1) *
      ((if (guess + n / guess) / 2 < guess then iter n ((guess + n / guess) / 2) else guess) + 1)
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ n < (iter n ((guess + n / guess) / 2) + 1) * (iter n ((guess + n / guess) / 2) + 1)

case neg
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : ¬(guess + n / guess) / 2 < guess
⊢ n < (guess + 1) * (guess + 1)

tactic: suffices n < (m + 1) * (m + 1) by
  simpa only [dif_pos h] using sqrt.lt_iter_succ_sq n m this
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ n < (iter n ((guess + n / guess) / 2) + 1) * (iter n ((guess + n / guess) / 2) + 1)
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ n < (m + 1) * (m + 1)

tactic: refine Nat.lt_of_mul_lt_mul_left ?_ (a := 4 * (guess * guess))
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ n < (m + 1) * (m + 1)
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ 4 * (guess * guess) * n < 4 * (guess * guess) * ((m + 1) * (m + 1))

tactic: apply Nat.lt_of_le_of_lt AM_GM
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ 4 * (guess * guess) * n < 4 * (guess * guess) * ((m + 1) * (m + 1))
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ (guess * guess + n) * (guess * guess + n) < 4 * (guess * guess) * ((m + 1) * (m + 1))

tactic: rw [show (4 : ℕ) = 2 * 2 from rfl]
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ (guess * guess + n) * (guess * guess + n) < 4 * (guess * guess) * ((m + 1) * (m + 1))
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ (guess * guess + n) * (guess * guess + n) < 2 * 2 * (guess * guess) * ((m + 1) * (m + 1))

tactic: rw [Nat.mul_mul_mul_comm 2, Nat.mul_mul_mul_comm (2 * guess)]
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ (guess * guess + n) * (guess * guess + n) < 2 * 2 * (guess * guess) * ((m + 1) * (m + 1))
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ (guess * guess + n) * (guess * guess + n) < 2 * guess * (m + 1) * (2 * guess * (m + 1))

tactic: refine Nat.mul_self_lt_mul_self (?_ : _ < _ * ((_ / 2) + 1))
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ (guess * guess + n) * (guess * guess + n) < 2 * guess * (m + 1) * (2 * guess * (m + 1))
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ guess * guess + n < 2 * guess * ((guess + n / guess) / 2 + 1)

tactic: rw [← add_div_right _ (by decide), Nat.mul_comm 2, Nat.mul_assoc,
  show guess + n / guess + 2 = (guess + n / guess + 1) + 1 from rfl]
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ guess * guess + n < 2 * guess * ((guess + n / guess) / 2 + 1)
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ guess * guess + n < guess * (2 * ((guess + n / guess + 1 + 1) / 2))

tactic: have aux_lemma {a : ℕ} : a ≤ 2 * ((a + 1) / 2) := by omega
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ guess * guess + n < guess * (2 * ((guess + n / guess + 1 + 1) / 2))
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
aux_lemma : ∀ {a : ℕ}, a ≤ 2 * ((a + 1) / 2)
⊢ guess * guess + n < guess * (2 * ((guess + n / guess + 1 + 1) / 2))

tactic: refine lt_of_lt_of_le ?_ (Nat.mul_le_mul_left _ aux_lemma)
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
aux_lemma : ∀ {a : ℕ}, a ≤ 2 * ((a + 1) / 2)
⊢ guess * guess + n < guess * (2 * ((guess + n / guess + 1 + 1) / 2))
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
aux_lemma : ∀ {a : ℕ}, a ≤ 2 * ((a + 1) / 2)
⊢ guess * guess + n < guess * (guess + n / guess + 1)

tactic: rw [Nat.add_assoc, Nat.mul_add]
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
aux_lemma : ∀ {a : ℕ}, a ≤ 2 * ((a + 1) / 2)
⊢ guess * guess + n < guess * (guess + n / guess + 1)
state_after: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
aux_lemma : ∀ {a : ℕ}, a ≤ 2 * ((a + 1) / 2)
⊢ guess * guess + n < guess * guess + guess * (n / guess + 1)

tactic: exact Nat.add_lt_add_left (lt_mul_div_succ _ (lt_of_le_of_lt (Nat.zero_le m) h)) _
state_before: case pos
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
aux_lemma : ∀ {a : ℕ}, a ≤ 2 * ((a + 1) / 2)
⊢ guess * guess + n < guess * guess + guess * (n / guess + 1)
state_after: no goals

tactic: simpa only [dif_pos h] using sqrt.lt_iter_succ_sq n m this
state_before: a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
this : n < (m + 1) * (m + 1)
⊢ n < (iter n ((guess + n / guess) / 2) + 1) * (iter n ((guess + n / guess) / 2) + 1)
state_after: no goals

tactic: decide
state_before: a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
⊢ 0 < 2
state_after: no goals

tactic: omega
state_before: a✝ b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : (guess + n / guess) / 2 < guess
a : ℕ
⊢ a ≤ 2 * ((a + 1) / 2)
state_after: no goals

tactic: simpa only [dif_neg h] using hn
state_before: case neg
a b c d m✝ n✝ k : ℕ
p q : ℕ → Prop
n guess : ℕ
hn : n < (guess + 1) * (guess + 1)
m : ℕ := (guess + n / guess) / 2
h : ¬(guess + n / guess) / 2 < guess
⊢ n < (guess + 1) * (guess + 1)
state_after: no goals