Zulip Chat Archive

Stream: lean4

Topic: Lean inserts unused variables in an example


Bulhwi Cha (May 12 2025 at 13:13):

#eval Lean.versionString -- output: "4.20.0-rc5"

variable (p q r : Prop)

theorem thm0 : p  q  q  p := by
  sorry
/- goal:
p q : Prop ⊢ p ∧ q ↔ q ∧ p
-/

example : p  q  q  p := by
  sorry
/- goal:
p q r : Prop ⊢ p ∧ q ↔ q ∧ p
-/

Lean didn't insert the variable r in the theorem thm0. However, it did in the example above. Was this intended?

Edward van de Meent (May 12 2025 at 13:27):

i suspect it is intended? the change in variable behaviour was done at a point when example already existed, so i'd say so?

Bulhwi Cha (May 12 2025 at 14:02):

This behavior of the variable command makes it hard to predict which variables Lean won't insert into which examples.

Mario Carneiro (May 12 2025 at 14:02):

this is intended

Bulhwi Cha (May 12 2025 at 14:03):

What was the reason behind this decision?

Mario Carneiro (May 12 2025 at 14:03):

the reason for the difference is that def/example has different elaboration behavior from theorem, theorem doesn't let you refer to variables in the body which are not in the statement or included

Mario Carneiro (May 12 2025 at 14:04):

variable (x : Nat)
def foo : Nat := x
example : Nat := x
theorem bar : Nat := x -- unknown identifier 'x'

Bulhwi Cha (May 12 2025 at 14:05):

variable (p : Prop) (x : p)
def foo : p := x
example : p := x
theorem bar : p := x -- unknown identifier 'x'

Bulhwi Cha (May 12 2025 at 14:09):

Let me put it this way: the example command was supposed to behave like the def keyword. Am I correct?

Bulhwi Cha (May 12 2025 at 14:13):

Now I got it. Thanks!

Jz Pan (May 12 2025 at 14:19):

Bulhwi Cha said:

the example command was supposed to behave like the def keyword

Yes, and there exists noncomputable example


Last updated: Dec 20 2025 at 21:32 UTC