Section FreeVariables.
Context {X: Const}.
Fixpoint vars (s: exp X) :=
match s with
| var x => [x]
| const x => nil
| lambda s => map pred (remove eq_dec 0 (vars s))
| app s1 s2 => vars s1 ++ vars s2
end.
Inductive varof (x: nat) : exp X -> Prop :=
| varofVar: varof x (var x)
| varofAppL (s t: exp X): varof x s -> varof x (s t)
| varofAppR (s t: exp X): varof x t -> varof x (s t)
| varofLambda s: varof (S x) s -> varof x (lambda s).
Hint Constructors varof : core.

Lemma vars_varof x s:
x ∈ vars s -> varof x s.