Definition REFLEXIVITY := REFLEXIVITYTAC.Definition REFLEXIVITYTAC_msubst : rtac typ (expr typ func) :=
fun tus tvs n m c s e =>
  match e with
| (App (App (Inj (inr (Other (feq ty)))) l) r) =>
  match l with
  | App
      (App
         (App
            (App (Inj (inr (Smx fmsubst_eval_LR))) T1) T2)
         (Inj (inr (Const (fCexpr e1)))))
      (Inj (inr (Const (fllrr lr)))) =>
    let l' := rmsubst_eval_LR T1 T2 e1 lr in
    match @exprUnify (ctx_subst c) typ func _ _ _ _ _ 3
                                 tus tvs 0 l' r ty s with
    | Some s => RTac.Core.Solved s
    | None =>  RTac.Core.Fail
    end
  | _ => RTac.Core.Fail
  end
| _ => RTac.Core.Fail
end.Definition REFLEXIVITY_MSUBST := REFLEXIVITYTAC_msubst.Definition REFLEXIVITYTAC_msubst_efield : rtac typ (expr typ func) :=
fun tus tvs n m c s e =>
  match e with
| (App (App (Inj (inr (Other (feq ty)))) l) r) =>
  match l with
  | App (App (Inj (inr (Smx (fmsubst_efield_denote e)))) T1) T2 =>
    let l' := rmsubst_efield_denote T1 T2 e in
    match @exprUnify (ctx_subst c) typ func _ _ _ _ _ 3
                                 tus tvs 0 l' r ty s with
    | Some s => RTac.Core.Solved s
    | None =>  RTac.Core.Fail
    end
  | _ => RTac.Core.Fail
  end
| _ => RTac.Core.Fail
end.Definition REFLEXIVITY_MSUBST_EFIELD := REFLEXIVITYTAC_msubst_efield.Definition REFLEXIVITYTAC_nth_error : rtac typ (expr typ func) :=
fun tus tvs n m c s e =>
  match e with
| (App (App (Inj (inr (Other (feq ty)))) l) r) =>
  match l with
  | App (Inj (inr (Data (fnth_error ty n)))) xs =>
    let l' := rnth_error ty xs n in
    match @exprUnify (ctx_subst c) typ func _ _ _ _ _ 3
                                 tus tvs 0 l' r ty s with
    | Some s => RTac.Core.Solved s
    | None =>  RTac.Core.Fail
    end
  | _ => RTac.Core.Fail
  end
| _ => RTac.Core.Fail
end.Definition REFLEXIVITY_NTH_ERROR := REFLEXIVITYTAC_nth_error.Definition REFLEXIVITY_DENOTE (rtype : typ) {H: @RelDec.RelDec (typD rtype) eq}
{H0: RelDec.RelDec_Correct H} tbl : rtac typ (expr typ func) :=
   fun tus tvs lus lvs c s e => (
match e with
| (App (App (Inj (inr (Other (feq _)))) l) r) =>
  match func_defs.reflect tbl nil nil l rtype, func_defs.reflect tbl nil nil r rtype with
  | Some v1, Some v2 => if @RelDec.rel_dec _ eq H v1 v2 then Solved s else Fail
  | _, _ => Fail
  end
| _ => Fail
end).

Lemma REFLEXIVITY_DENOTE_sound (rtype : typ) {H: @RelDec.RelDec (typD rtype) eq} {H0: RelDec.RelDec_Correct H}: rtac_sound (REFLEXIVITY_DENOTE rtype tbl).