Zulip Chat Archive

Stream: general

Topic: easy inductive proof - noob to syntax


Quinn (Mar 05 2024 at 21:12):

inductive even :   Prop :=
| even_zero : even 0
| even_add_two :  n, even n  even (n + 2)

theorem even_property (n : ) (h : even n) :  k, n = 2 * k :=
begin
    induction h with n h IH.
    { use 0, simp, },
    { cases ih with k hk, use k + 1, simp only [hk], linarith, }.
end

I know this proof in coq, but in lean my error message is

[0/6] Building LeanDelendum.Basic
error: > LEAN_PATH=./.lake/build/lib LD_LIBRARY_PATH=./.lake/build/lib /nix/store/mrb3i1b78iysik1lhsij5jdihjyja59n-lean4-4.5.0/bin/lean ./././LeanDelendum/Basic.lean -R ././. -o ./.lake/build/lib/LeanDelendum/Basic.olean -i ./.lake/build/lib/LeanDelendum/Basic.ilean -c ./.lake/build/ir/LeanDelendum/Basic.c
error: stdout:
./././LeanDelendum/Basic.lean:5:54: error: typeclass instance problem is stuck, it is often due to metavariables
  HMul Nat ?m.344 
./././LeanDelendum/Basic.lean:7:16: error: unexpected token 'with'; expected command
./././LeanDelendum/Basic.lean:10:0: error: invalid 'end', insufficient scopes

Quinn (Mar 05 2024 at 21:13):

i don't see the typeclasses, is the inductive a typeclass under the hood? that would be the reverse of coq, haha

Quinn (Mar 05 2024 at 21:14):

also what's a metavariable, in this context?

Julian Berman (Mar 05 2024 at 21:16):

That looks like Lean 3 syntax, which is dead.

Julian Berman (Mar 05 2024 at 21:16):

(And your error message is indeed saying you're using Lean 4)

Quinn (Mar 05 2024 at 21:19):

excellent.

Quinn (Mar 05 2024 at 21:19):

Thank you.

Quinn (Mar 05 2024 at 21:30):

what is "declaration has free variable"? the variable is clearly bounded!

inductive Even :   Prop :=
| even_zero : Even 0
| even_add_two (n : ) : Even n  Even (n + 2)

Quinn (Mar 05 2024 at 21:30):

oh am i naive to assume 0 and 2 literals will fly with \N?

Shreyas Srinivas (Mar 05 2024 at 22:00):

This works:

import Mathlib.Tactic

namespace Playground

  inductive Even :   Prop where
    | even_zero : Even 0
    | even_add_two (n : ) : Even n  Even (n + 2)

end Playground

Shreyas Srinivas (Mar 05 2024 at 22:01):

The abbreviation doesn't represent Natural Numbers outside Mathlib if I recall correctly.

Kyle Miller (Mar 05 2024 at 22:16):

Indeed, it's defined in Mathlib.Init.Data.Nat.Notation


Last updated: May 02 2025 at 03:31 UTC