Automated LC review — now right here in the GuildUpload documents → AI discrepancy analysis → correction guide.
NEW Start LC Review →
← Lounge

Lean Code Example

Machine translated

-- Define the sum of natural numbers from 0 to n using a recursive function
def sumTo : Nat → Nat
| 0 => 0
| n + 1 => sumTo n + (n + 1)
-- Proposition to prove: 2 * sumTo n = n * (n + 1)
-- (Expressed by multiplying both sides by 2 to avoid division)
theorem two_mul_sumTo (n : Nat) : 2 * sumTo n = n * (n + 1) := by
induction n with
| zero =>
-- Base case (n = 0): Check if both sides equal 0
simp [sumTo]
| succ k ih =>
-- Inductive step (n = k + 1, inductive hypothesis ih: 2 * sumTo k = k * (k + 1))
simp [sumTo]
-- Show that 2 * (sumTo k + (k + 1)) = (k + 1) * (k + 1 + 1)
calc
2 * (sumTo k + (k + 1))
= 2 * sumTo k + 2 * (k + 1) := by ring
_ = k * (k + 1) + 2 * (k + 1) := by rw [ih]
_ = (k + 1) * (k + 1 + 1) := by ring
We are living in an era where humans must think like computers to understand mathematics.

Comments 0

No comments yet
0