(* * Copyright (c) 2009 Robert Dockins and Aquinas Hobor. * *)
(* Coq development: using indirection theory to model types in l-calculus *)

(* Specifications: *)
Lemma exp_to_val_to_exp : forall v H,
exp_to_val (val_to_exp v) H = v.
Lemma forces2exprType: forall w v tau,
forces w v (%tau) ->
forall v', expr_type (val_to_exp v) tau (w,v').
Lemma exprType_value : forall w e tau m v
(H:isValue e),
forces w v (mtype_valid m) ->
expr_type e tau (w,v) ->
forces w (exp_to_val e H) (%tau).
Lemma expr_type_search_rule : forall (G Q tau sigma:pred world) (f:expr -> expr),
forall e a,
closed (f e) ->
expr_type e tau a ->
(Q) a ->
(|>G) a ->
forall
(HQ: boxy extendM Q)
(HG: boxy extendM G)
(Hstep : forall m m' x y, step (m,x) (m',y) -> step (m,f x) (m',f y))
(Hredex:
forall k v e m (H:isValue e),
closed (f e) ->
(|>G) (k,v) ->
Q (k,v) ->
mtype_valid m (k,v) ->
(%tau) (k,exp_to_val e H) ->
expr_type (f e) sigma (k,v))
(Hsearch:
forall e a,
closed (f e) ->
G a ->
Q a ->
expr_type e tau a ->
expr_type (f e) sigma a),
expr_type (f e) sigma a.
Lemma subst_env_valid_closed :  forall env G e a,
closed' (length G) e ->
etype_valid env G a ->
closed (subst_env env e).
Lemma etype_valid_lookup: forall G x tau w env v,
nth_error G x = Some tau ->
etype_valid env G (w,v) ->
exists v,
nth_error env x = Some v /\ forces w v (%tau).
Lemma etype_valid_val : forall G env m v v',
etype_valid env G (m,v) ->
etype_valid env G (m,v').
Lemma expr_type_val' : forall tau,
TT |-- ALL v:value, ALL e:expr, %(expr_type e tau --> with_val v (expr_type e tau)).
Lemma expr_type_val : forall e tau k v v',
expr_type e tau (k,v) ->
expr_type e tau (k,v').
Lemma openValue_valid_value : forall env G a e,
openValue e ->
closed' (length G) e ->
etype_valid env G a ->
isValue (subst_env env e).