Instance dec_step (t : trm) : Dec (exists t', step t t') :=
{| dec := _ |}.
Inductive appears_free_in : id -> trm -> Prop :=
| afi_var : forall i,
appears_free_in i (tvar i)
| afi_app1 : forall i t1 t2,
appears_free_in i t1 -> appears_free_in i (tapp t1 t2)
| afi_app2 : forall i t1 t2,
appears_free_in i t2 -> appears_free_in i (tapp t1 t2)
| afi_abs : forall i y T11 t12,
y <> i  ->
appears_free_in i t12 ->
appears_free_in i (tabs y T11 t12)
| afi_if1 : forall i t1 t2 t3,
appears_free_in i t1 ->
appears_free_in i (tif t1 t2 t3)
| afi_if2 : forall i t1 t2 t3,
appears_free_in i t2 ->
appears_free_in i (tif t1 t2 t3)
| afi_if3 : forall i t1 t2 t3,
appears_free_in i t3 ->
appears_free_in i (tif t1 t2 t3).
Hint Constructors appears_free_in.
Derive ArbitrarySizedSuchThat for (fun i => appears_free_in i t).
Derive SizeMonotonicSuchThatOpt for (fun i => appears_free_in i t).
Derive SizedProofEqs for (fun i => appears_free_in i t).
Derive GenSizedSuchThatCorrect for (fun i => appears_free_in i t).
Derive GenSizedSuchThatSizeMonotonicOpt for (fun i => appears_free_in i t).
Instance appears_free_in_gen_correct t : SuchThatCorrect (fun i => appears_free_in i t)
(@arbitraryST _ (fun i => appears_free_in i t) _).
Admitted.
Definition closed (t:trm) :=
forall x, ~ appears_free_in x t.
Instance dec_closed t : Dec (closed t). Admitted.
Instance dec_bind x Gamma : Dec (exists T, bind Gamma x T).
Admitted.

(* Specifications: *)
Lemma free_in_context : forall x t,
appears_free_in x t ->
forall T Gamma,
Gamma |- t \typ T ->
exists T', bind Gamma x T'.