Library MetaCoq.Translations.standard_model


Infix "<=" := Nat.leb.

Definition default_term := tVar "constant_not_found".
Definition debug_term msg:= tVar ("debug: " ++ msg).

Print Typing Flags.


Fixpoint kproj (k : nat) (t : term) :=
  match k with
  | 0 ⇒ t
  | S kkproj k (proj1 t)
  end.

Notation app0 := (fun tsubst_app t [tRel 0]).

Fixpoint tsl (ΣE : tsl_context) (Γ : context) (t : term) {struct t}
  : tsl_result term :=
  match t with
  | tSort sΓ' <- tsl_ctx ΣE Γ ;;
              ret (tLambda (nNamed "γ") Γ' (tSort s))
  | tRel kΓ' <- tsl_ctx ΣE Γ ;;
             ret (tLambda (nNamed "γ") Γ' (proj2 (kproj k (tRel 0))))
  
  | tCast t c AΓ' <- tsl_ctx ΣE Γ ;;
                  t' <- tsl ΣE Γ t ;;
                  A' <- tsl ΣE Γ A ;;
                  ret (tLambda (nNamed "γ") Γ'
                               (tCast (app0 t') c (app0 A')))
  | tProd na A BΓ' <- tsl_ctx ΣE Γ ;;
                   A' <- tsl ΣE Γ A ;;
                   B' <- tsl ΣE (Γ ,, vass na A) B ;;
                   ret (tLambda (nNamed "γ") Γ'
                                (tProd na (app0 A')
                                   (subst_app B' [pair Γ' A' (tRel 1) (tRel 0)])))
  | tLambda na A tΓ' <- tsl_ctx ΣE Γ ;;
                     A' <- tsl ΣE Γ A ;;
                     t' <- tsl ΣE (Γ ,, vass na A) t ;;
                     ret (tLambda (nNamed "γ") Γ'
                            (tLambda na (app0 A')
                               (subst_app t' [pair Γ' (up A') (tRel 1) (tRel 0)])))
  | tLetIn na t A uΓ' <- tsl_ctx ΣE Γ ;;
                      t' <- tsl ΣE Γ t ;;
                      A' <- tsl ΣE Γ A ;;
                      u' <- tsl ΣE (Γ ,, vdef na t A) u ;;
                      ret (tLambda (nNamed "γ") Γ' (tLetIn na t' A' u'))
  | tApp t luΓ' <- tsl_ctx ΣE Γ ;;
                t' <- tsl ΣE Γ t ;;
                lu' <- monad_map (tsl ΣE Γ) lu ;;
                ret (tLambda (nNamed "γ") Γ' (mkApps (app0 t') (map app0 lu')))
  
  
  
  
  | tConst s univsΓ' <- tsl_ctx ΣE Γ ;;
                     t' <- lookup_tsl_table' (snd ΣE) (ConstRef s) ;;
                     ret (tLambda (nNamed "γ") Γ' (subst_app t' [ttt]))
  | tInd i univslookup_tsl_table' (snd ΣE) (IndRef i)
  | tConstruct i n univslookup_tsl_table' (snd ΣE) (ConstructRef i n)
  | tProj p tΓ' <- tsl_ctx ΣE Γ ;;
                t' <- tsl ΣE Γ t ;;
                ret (tLambda (nNamed "γ") Γ' (tProj p t'))

  | _ret t
  end
with tsl_ctx (ΣE : tsl_context) (Γ : context) {struct Γ} : tsl_result term :=
       match Γ with
       | [] ⇒ ret tUnit
       | {| decl_body := None; decl_type := A |} :: Γ
            Γ' <- tsl_ctx ΣE Γ ;;
            A' <- tsl ΣE Γ A ;;
            ret (pack Γ' A')
       | _todo
       end.

Instance param : Translation :=
  {| tsl_id := tsl_ident ;
     tsl_tm := fun ΣEtsl ΣE [] ;
     tsl_ty := Some (fun ΣE tt' <- tsl ΣE [] t ;; ret (subst_app t' [ttt])) ;
     tsl_ind := todo |}.

Definition toto := fun (f : A, AA) ⇒ f Type.
Goal nat.
Print totoᵗ.
Eval cbv delta beta in totoᵗ.

Definition FALSE := X, X.

Definition T := A, AA.

Definition tm := ((fun A (x:A) ⇒ x) (TypeType) (fun xx)).



Module Id1.
  Definition ID := A, AA.


  Lemma param_ID_identity (f : ID)
    : IDf A x, f A x = x.

  Definition toto := fun n : nat ⇒ (fun y ⇒ 0) (fun _ : Typen).

  Definition my_id : ID :=
    let n := 12 in (fun (_ : nat) yy) 4 (fun A x ⇒ (fun _ : natx) n).


  Definition free_thm_my_id : A x, my_id A x = x
    := param_ID_identity my_id my_idᵗ.
End Id1.

Module Id2.
  Definition ID := A x y (p : x = y :> A), x = y.


  Lemma param_ID_identity (f : ID)
    : IDf A x y p, f A x y p = p.

  Definition myf : ID
    := fun A x y peq_trans (eq_trans p (eq_sym p)) p.


  Definition free_thm_myf : A x y p, myf A x y p = p
    := param_ID_identity myf myfᵗ.
End Id2.

Module Vectors.
End Vectors.


Definition rev_type := A, list Alist A.

Module Axioms.

  Definition UIP := A (x y : A) (p q : x = y), p = q.



  Definition eq_eq {A Ax xy yp}
    : eqA Ax xy ypp # xᵗ = yᵗ.

  Definition eq_eqᵗ {A Ax xy yp}
    : p # xᵗ = yᵗ → eqA Ax xy yp.

  Definition eq_eq_equiv A Ax xy yp
    : eqA Ax xy yp <~> p # xᵗ = yᵗ.

  Theorem UIP_provably_parametric : h : UIP, UIPh.


  Definition wFunext
    := A (B : AType) (f g : x, B x), ( x, f x = g x) → f = g.


  Theorem wFunext_provably_parametric : h : wFunext, wFunexth.

  Definition Funext
    := A B (f g : x : A, B x), IsEquiv (@apD10 A B f g).


  Theorem wFunext_provably_parametric : h : Funext, Funexth.



Definition equiv_id A : isequiv A A (fun xx).
Defined.



Lemma eq_rectᵗ : eq_rect_Typeeq_rect.

Definition TC' := (ConstRef "Coq.Init.Logic.eq_rect", tConst "eq_rectᵗ" []) :: TC.

Definition eq_to_iso A B : A = B f, isequiv A B f.
Defined.

Definition UA := A B, isequiv _ _ (eq_to_iso A B).



Axiom ua : UA.

Goal UAua.