SkullCoder

SKConversion

Nov 25th, 2019
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Section SKTranslation.
  2.   Definition S := (Lam (Lam (Lam ((2 0) (1 0))))).
  3.   Definition K := (Lam (Lam 1)).
  4.  
  5.   Notation Is := (S K K).
  6.  
  7.   Notation "s ≡ t" := (star (sym step) s t)(at level 71).
  8.  
  9.   Lemma EqComEqR s t t': t ≡ t' -> s t ≡ s t'.
  10.  Proof.
  11.    induction 1.
  12.    - constructor.
  13.    - destruct H.
  14.      + econstructor.
  15.        * left. apply stepAppR,H.
  16.        * assumption.
  17.      + econstructor.
  18.        * right. apply stepAppR,H.
  19.        * assumption.
  20.  Defined.
  21.  
  22.  Lemma EqComEqL s t s': s ≡ s' -> s t ≡ s' t.
  23.   Proof.
  24.     induction 1;trivial.
  25.     destruct H;econstructor;try eassumption;
  26.       [left|right];now apply stepAppL.
  27.   Defined.
  28.  
  29.   Lemma EqComEq s t s' t': s ≡ s' -> t ≡ t' -> s t ≡ s' t'.
  30.   Proof.
  31.     intros H H1.
  32.     etransitivity.
  33.     - apply EqComEqR,H1.
  34.     - now apply EqComEqL,H.
  35.   Defined.
  36.  
  37.   Lemma EqLam s s': s ≡ s' -> Lam s ≡ Lam s'.
  38.  Proof.
  39.    induction 1.
  40.    - reflexivity.
  41.    - transitivity (Lam x');trivial.
  42.       inv H;econstructor;[left| |right|];constructor;trivial.
  43.   Defined.
  44.  
  45.   Lemma StarLam s s': s≻* s' -> Lam s ≻* Lam s'.
  46.  Proof.
  47.    induction 1.
  48.    - constructor.
  49.    - econstructor.
  50.      + constructor. apply H.
  51.      + apply IHstar.
  52.  Defined.
  53.  
  54.  Lemma StarApp s s' t t': s≻* s' -> t ≻* t' -> s t ≻* s' t'.
  55.  Proof.
  56.    induction 1 in t, t' |- *;intros H1.
  57.     - induction H1.
  58.       + constructor.
  59.       + econstructor.
  60.         * constructor 4. apply H.
  61.         * apply IHstar.
  62.     - econstructor.
  63.       + constructor.
  64.         apply H.
  65.       + now apply IHstar.
  66.   Defined.
  67.  
  68.   Ltac reduce' := econstructor 2;[repeat constructor|cbn].
  69.  
  70.  Lemma Id: Lam 0 ≡ S K K.
  71.  Proof.
  72.    unfold S, K.
  73.    symmetry.
  74.    apply star_starsym.
  75.    do 4 reduce'.
  76.     constructor.
  77.   Defined.
  78.  
  79.   Lemma KLam s: K s ≡ Lam (rename Datatypes.S s).
  80.   Proof.
  81.     unfold K.
  82.     now reduce'.
  83.  Defined.
  84.  
  85.  Lemma AppLam s t: Lam (s t) ≡ S (Lam s) (Lam t).
  86.  Proof.
  87.    unfold S.
  88.    symmetry.
  89.    apply star_starsym.
  90.    reduce'.
  91.     reduce'.
  92.    reduce'.
  93.     eauto with *.
  94.     autorewrite with basic.
  95.     apply StarLam, StarApp.
  96.     - cbn.
  97.       unfold upr.
  98.       rewrite rename_subst.
  99.       autorewrite with basic.
  100.       unfold scomp.
  101.       unfold funcomp.
  102.       cbn.
  103.       admit.
  104.     - reduce'.
  105.      unfold upr.
  106.      rewrite rename_subst.
  107.      autorewrite with basic.
  108.      eauto with basic.
  109.      unfold funcomp.
  110.      admit.
  111.      (* induction t. *)
  112.      (* + cbn. induction x. *)
  113.      (*   * constructor. *)
  114.      (*   * constructor. *)
  115.      (* + cbn. *)
  116.      (*   apply StarApp;trivial. *)
  117.      (* + cbn. apply StarLam. *)
  118.      (*   rewrite upE. *)
  119.  Admitted. (* I strongly believe this is true *)
  120.  
  121.  Inductive onlySK : term -> Type :=
  122.    onlyK : onlySK K
  123.  | onlyS : onlySK S
  124.  | onlyVar x : onlySK (Var x)
  125.  | onlyApp s t: onlySK s -> onlySK t -> onlySK (s t).
  126.  
  127.  Inductive pureSK : term -> Type :=
  128.    pureK : pureSK K
  129.  | pureS : pureSK S
  130.  | pureApp s t: pureSK s -> pureSK t -> pureSK (s t).
  131.  
  132.  Lemma δ' s: onlySK s -> {t & prod (t ≡ Lam s) (onlySK t)}.
  133.   Proof.
  134.     induction 1 using onlySK_rect.
  135.     - exists (K K);split.
  136.       + apply KLam.
  137.       + do 2 constructor.
  138.     - exists (K S);split.
  139.       + apply KLam.
  140.       + do 2 constructor.
  141.     - destruct x.
  142.       + exists (S K K);split.
  143.         * symmetry. apply Id.
  144.         * repeat constructor.
  145.       + eexists;split.
  146.         * change (Var (Datatypes.S x)) with (rename Datatypes.S (x)).
  147.           apply KLam.
  148.         * repeat constructor.
  149.     - destruct IHonlySK1 as [? []].
  150.       destruct IHonlySK2 as [? []].
  151.       exists (S x x0);split.
  152.       + transitivity (S (Lam s) (Lam t)).
  153.         * repeat apply EqComEq;trivial.
  154.         * symmetry. apply AppLam.
  155.       + repeat constructor;trivial.
  156.   Defined.
  157.  
  158.   Lemma γ s: {t & prod (t ≡ s) (onlySK t)}.
  159.   Proof.
  160.     induction s as [x|s [s' [IHs H0]] t [t' [IHt H1]]|s [s' [IHs H]]] using term_rect.
  161.    - exists x;split;trivial.
  162.      constructor.
  163.    - eexists;split.
  164.      + apply EqComEq;eassumption.
  165.      + now constructor.
  166.    - destruct (δ' H) as [s'' [H1 H2]].
  167.       exists s'';split;trivial.
  168.       transitivity (Lam s');[|apply EqLam];trivial.
  169.  Defined.
  170.  
  171.  Definition succ := Lam(Lam(Lam(0 2))).
  172.  Eval cbn in (projT1(γ succ)).
  173.  
  174.  Lemma pureSKConv s n: (forall m, n<=m -> ~ free m s) -> forall m, n<=m -> ~free m (projT1(γ s)).
  175.  Proof.
  176.    induction s;intros H1 m H2 H3.
  177.    - now apply (H1 m).
  178.    - cbn in H3.
  179.  Abort.
  180.  
  181. End SKTranslation.
Advertisement
Add Comment
Please, Sign In to add comment