Ltac value_context := try now
match goal with
| |- bound _ ?t = true =>
eapply bound_ge with (k := 0); [ change (closed t); auto 3 with cbv | omega ]
end.
Ltac dvalue' :=
match goal with
(* | |- rClosed ?phi _ => now (apply rClosed_decb_correct;[assumption|vm_compute;reflexivity]) *)
| |- closed _ => cbn; unfold closed
| |- bound _ (if ?c then _ else _) = true => destruct c
| |- bound _ (L.var _) = true => now constructor;omega
| |- bound _ (L.app _ _) = true => constructor
| |- bound _ (L.lambda _) = true => constructor
| |- bound ?s _ = true => value_context || (unfold s;simpl)
| |- context [ andb _ _ ] => rewrite Bool.andb_true_r; dvalue'
| |-  andb _ _ = _ => eapply Bool.andb_true_iff; split; dvalue'
end.
Ltac dvalue := (try (progress unfold convert;cbv -[bound]; cbn)); repeat dvalue'; try (cbn; repeat dvalue').
Ltac value' :=
match goal with
| [ |- proc _ ] => (try eassumption; auto 3 with cbv; split; value')
| [ |- lam _ ] => (try eassumption; auto 3 with cbv; eexists; reflexivity)
| [ |- lam (if ?c then _ else _) ] => destruct c;(try eassumption; auto 3 with cbv; eexists; reflexivity)
| [ |- closed _ ] => (try eassumption; auto 3 with cbv; value_context); dvalue
| [ |-  _ ] => idtac
end (*|| value*).
Tactic Notation "value" := value'.

Lemma beta s t u : lam u -> subst s 0 u = t -> (lambda s) u ≻ t.
Tactic Notation "rewrite_cls" open_constr(t) :=
let H := fresh "H" in
enough (H : closed t); [rewrite (closed_subst _ _ H) | value]; clear H.