Zulip Chat Archive

Stream: new members

Topic: Help with Lean


Ken Roe (Jul 10 2018 at 13:32):

I just started using Lean. Can someone help me by telling me what I need to replace "sorry" with to prove this theorem:

def beq_nat : ℕ → ℕ → bool
| beq_nat 0 0 := tt
| beq_nat (x+1) (y+1) := (beq_nat x y)
| beq_nat a b := ff

example : beq_nat 3 3=tt := by sorry.

Kenny Lau (Jul 10 2018 at 13:34):

your definition does not compile

Patrick Massot (Jul 10 2018 at 13:34):

def beq_nat :     bool
| 0 0 := tt
| (x+1) (y+1) := (beq_nat x y)
| a b := ff

example : beq_nat 3 3=tt := rfl

Patrick Massot (Jul 10 2018 at 13:35):

strange definition

Kenny Lau (Jul 10 2018 at 13:35):

I don't think it's strange

Kenny Lau (Jul 10 2018 at 13:35):

it's a viable way to prove that equality is decidable

Patrick Massot (Jul 10 2018 at 13:35):

it's less efficient than using the maths preamble

Ken Roe (Jul 10 2018 at 13:36):

I get the following using "rfl":

impHeap.lean:35:28: error
type mismatch, term
rfl
has type
?m_2 = ?m_2
but is expected to have type
beq_nat 3 3 = tt

Kenny Lau (Jul 10 2018 at 13:37):

we changed the definition

Kenny Lau (Jul 10 2018 at 13:37):

your original definition does not compile

Ken Roe (Jul 10 2018 at 13:40):

How do I fix the definition?

Patrick Massot (Jul 10 2018 at 13:40):

see my message

Kenny Lau (Jul 10 2018 at 13:41):

we already gave you the new definition

Kenny Lau (Jul 10 2018 at 13:41):

def beq_nat :     bool
| 0 0 := tt
| (x+1) (y+1) := (beq_nat x y)
| a b := ff

example : beq_nat 3 3=tt := rfl

:point_up: https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/subject/Help.20with.20Lean/near/129411605

Ken Roe (Jul 10 2018 at 13:47):

Thanks--didn't notice they were different. It appears the syntax for recursive definitions changed from Lean 2.0. This definition (copied from the Lean 2.0 tutorial) also fails:

definition fib : nat → nat
| fib 0 := 1
| fib 1 := 1
| fib (a+2) := fib (a+1) + fib a

Kenny Lau (Jul 10 2018 at 13:47):

how old is Lean 2.0 lol

Kenny Lau (Jul 10 2018 at 13:48):

I don't think I ever used Lean 2.0

Kenny Lau (Jul 10 2018 at 13:48):

definition fib : nat  nat
| 0 := 1
| 1 := 1
| (a+2) := fib (a+1) + fib a

Patrick Massot (Jul 10 2018 at 15:16):

You shouldn't be reading anything written for Lean 2. This is all difficult enough without adding this layer of confusion. Reading https://leanprover.github.io/theorem_proving_in_lean/ will already bring you a long way


Last updated: Dec 20 2023 at 11:08 UTC