Section tbled.
Variable tbl : SymEnv.functions RType_typ.
Let RSym_sym := RSym_sym tbl.
Existing Instance RSym_sym.
Let RSym_sym_ok :  RSymOk RSym_sym := _.
Existing Instance RSym_sym_ok.
Let Expr_expr_fs := Expr_expr_fs tbl.
Existing Instance Expr_expr_fs.
Let Expr_ok_fs := Expr_ok_fs tbl.
Existing Instance Expr_ok_fs.
Existing Instance MA.
Definition reflect tus tvs e (ty : typ)
:= @exprD _ _ _ Expr_expr_fs tus tvs e ty.
intros. congruence.
Qed.
intros.
unfold as_tree in H.
repeat
match goal with
| [ H : match ?x with _ => _  end = _ |- _ ] => destruct x;
try (apply some_none in H; contradiction) end.
congruence.
inversion H. subst. auto.
Admitted. (*Qed.*)
intros.
unfold as_tree in H.
repeat
match goal with
| [ H : match ?x with _ => _  end = _ |- _ ] => destruct x; simpl in H;  try congruence end.
inversion H. subst. auto.
Admitted.
Ltac destruct_as_tree :=
repeat
match goal with
| [ H : context [ match as_tree ?x with _ => _ end] |- _] => destruct (as_tree x) eqn:?
| [ H : as_tree _ = Some (inl (_ , _ , _, _)) |- _ ] => apply as_tree_l in H
| [ H : as_tree _ = Some (inr _) |- _ ] => apply as_tree_r in H
| [ H : as_tree _ = Some (inl (?p, _, _)) |- _ ] => destruct p
| [ H : as_tree _ = Some (inl (?p, _)) |- _ ] => destruct p
| [ H : as_tree _ = Some (inl ?p) |- _ ] => destruct p
| [ H : as_tree _ = Some ?p |- _ ] => destruct p
end;
subst.
Ltac solve_exprD := solve_exprD.solve_exprD tbl.
Opaque type_cast.
unfold RSym_sym.
induction i; intros; simpl in *;
destruct (as_tree tr) eqn:?; destruct_as_tree; solve_exprD; unfold none_reif; solve_exprD.
Qed.

Lemma set_reif_exprD :
forall tus tvs typ i vr e v ev,
exprD' tus tvs (typtree typ) e = Some ev ->
exprD' tus tvs typ vr = Some v ->
exists r, exprD' tus tvs (typtree typ) (set_reif i vr e typ) = Some r.