Theorem: Num.gcd_to_nat
File: Mathlib/Data/Num/Lemmas.lean

tactic: have : ∀ a b : Num, (a * b).natSize ≤ a.natSize + b.natSize := by
  intros
  simp only [natSize_to_nat, cast_mul]
  rw [Nat.size_le, pow_add]
  exact mul_lt_mul'' (Nat.lt_size_self _) (Nat.lt_size_self _) (Nat.zero_le _) (Nat.zero_le _)
state_before: ⊢ ∀ (a b : Num), ↑(a.gcd b) = (↑a).gcd ↑b
state_after: this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
⊢ ∀ (a b : Num), ↑(a.gcd b) = (↑a).gcd ↑b

tactic: intros
state_before: this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
⊢ ∀ (a b : Num), ↑(a.gcd b) = (↑a).gcd ↑b
state_after: this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
⊢ ↑(a✝.gcd b✝) = (↑a✝).gcd ↑b✝

tactic: unfold gcd
state_before: this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
⊢ ↑(a✝.gcd b✝) = (↑a✝).gcd ↑b✝
state_after: this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
⊢ ↑(if a✝ ≤ b✝ then gcdAux (a✝.natSize + b✝.natSize) a✝ b✝ else gcdAux (b✝.natSize + a✝.natSize) b✝ a✝) = (↑a✝).gcd ↑b✝

tactic: split_ifs with h
state_before: this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
⊢ ↑(if a✝ ≤ b✝ then gcdAux (a✝.natSize + b✝.natSize) a✝ b✝ else gcdAux (b✝.natSize + a✝.natSize) b✝ a✝) = (↑a✝).gcd ↑b✝
state_after: case pos
this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
h : a✝ ≤ b✝
⊢ ↑(gcdAux (a✝.natSize + b✝.natSize) a✝ b✝) = (↑a✝).gcd ↑b✝

case neg
this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
h : ¬a✝ ≤ b✝
⊢ ↑(gcdAux (b✝.natSize + a✝.natSize) b✝ a✝) = (↑a✝).gcd ↑b✝

tactic: intros
state_before: ⊢ ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
state_after: a✝ b✝ : Num
⊢ (a✝ * b✝).natSize ≤ a✝.natSize + b✝.natSize

tactic: simp only [natSize_to_nat, cast_mul]
state_before: a✝ b✝ : Num
⊢ (a✝ * b✝).natSize ≤ a✝.natSize + b✝.natSize
state_after: a✝ b✝ : Num
⊢ (↑a✝ * ↑b✝).size ≤ (↑a✝).size + (↑b✝).size

tactic: rw [Nat.size_le, pow_add]
state_before: a✝ b✝ : Num
⊢ (↑a✝ * ↑b✝).size ≤ (↑a✝).size + (↑b✝).size
state_after: a✝ b✝ : Num
⊢ ↑a✝ * ↑b✝ < 2 ^ (↑a✝).size * 2 ^ (↑b✝).size

tactic: exact mul_lt_mul'' (Nat.lt_size_self _) (Nat.lt_size_self _) (Nat.zero_le _) (Nat.zero_le _)
state_before: a✝ b✝ : Num
⊢ ↑a✝ * ↑b✝ < 2 ^ (↑a✝).size * 2 ^ (↑b✝).size
state_after: no goals

tactic: exact gcd_to_nat_aux h (this _ _)
state_before: case pos
this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
h : a✝ ≤ b✝
⊢ ↑(gcdAux (a✝.natSize + b✝.natSize) a✝ b✝) = (↑a✝).gcd ↑b✝
state_after: no goals

tactic: rw [Nat.gcd_comm]
state_before: case neg
this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
h : ¬a✝ ≤ b✝
⊢ ↑(gcdAux (b✝.natSize + a✝.natSize) b✝ a✝) = (↑a✝).gcd ↑b✝
state_after: case neg
this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
h : ¬a✝ ≤ b✝
⊢ ↑(gcdAux (b✝.natSize + a✝.natSize) b✝ a✝) = (↑b✝).gcd ↑a✝

tactic: exact gcd_to_nat_aux (le_of_not_le h) (this _ _)
state_before: case neg
this : ∀ (a b : Num), (a * b).natSize ≤ a.natSize + b.natSize
a✝ b✝ : Num
h : ¬a✝ ≤ b✝
⊢ ↑(gcdAux (b✝.natSize + a✝.natSize) b✝ a✝) = (↑b✝).gcd ↑a✝
state_after: no goals