Zulip Chat Archive
Stream: new members
Topic: Need help for proving List membership theorem
Mikaël Mayer (Jul 29 2025 at 03:27):
Hello, I'm new to Lean4, and I'm struggling to do something that I thought would be simple. Even ChatGPT and Claude answered things that did not work and many times in a row.
Basically, I have the following code.
inductive Expr : Type where
| name (c : String)
| tree (e1 e2 : Expr)
def freeVars(e : Expr) : List String :=
match e with
| .name n => [n]
| .tree left right => freeVars left ++ freeVars right
def fresh (x : String) (e : Expr) : Bool :=
x ∉ (freeVars e)
theorem fresh_tree :
fresh x (.tree left right) =
fresh x left ∧ fresh x right := by
simp [fresh, freeVars]
and I can't find a way to complete the proof.
If you could recommend extensions that can also help me find tactics that can apply, I'm pretty clueless as well. I tried using calc, Bool.decide_eq_true, etc.
Bryan Gin-ge Chen (Jul 29 2025 at 03:35):
Looks like you're just missing parentheses in fresh_tree:
inductive Expr : Type where
| name (c : String)
| tree (e1 e2 : Expr)
def freeVars(e : Expr) : List String :=
match e with
| .name n => [n]
| .tree left right => freeVars left ++ freeVars right
def fresh (x : String) (e : Expr) : Bool :=
x ∉ (freeVars e)
theorem fresh_tree :
fresh x (.tree left right) =
(fresh x left ∧ fresh x right) := by
simp [fresh, freeVars] -- No goals
Patrick Massot (Jul 29 2025 at 10:17):
Note also your issue with parentheses would go away if you used the idiomatic ↔ instead of an equality of propositions.
Notification Bot (Jul 29 2025 at 10:17):
This topic was moved here from #lean4 > Need help for proving List membership theorem by Patrick Massot.
Mikaël Mayer (Jul 29 2025 at 10:23):
This is excellent feedback thank you so much !
Kenny Lau (Jul 29 2025 at 10:27):
and also Prop instead of Bool.
Last updated: Dec 20 2025 at 21:32 UTC