src/ZF/Induct/Comb.thy
changeset 15775 d8dd2fffa692
parent 13573 37b22343c35a
child 15863 78db9506cc78
equal deleted inserted replaced
15774:9df37a0e935d 15775:d8dd2fffa692
    20 
    20 
    21 consts comb :: i
    21 consts comb :: i
    22 datatype comb =
    22 datatype comb =
    23     K
    23     K
    24   | S
    24   | S
    25   | app ("p \<in> comb", "q \<in> comb")    (infixl "#" 90)
    25   | app ("p \<in> comb", "q \<in> comb")    (infixl "@@" 90)
    26 
    26 
    27 text {*
    27 text {*
    28   Inductive definition of contractions, @{text "-1->"} and
    28   Inductive definition of contractions, @{text "-1->"} and
    29   (multi-step) reductions, @{text "--->"}.
    29   (multi-step) reductions, @{text "--->"}.
    30 *}
    30 *}
    31 
    31 
    32 consts
    32 consts
    33   contract  :: i
    33   contract  :: i
    34 syntax
    34 syntax
    35   "_contract" :: "[i,i] => o"    (infixl "-1->" 50)
    35   "_contract"       :: "[i,i] => o"    (infixl "-1->" 50)
    36   "_contract_multi" :: "[i,i] => o"    (infixl "--->" 50)
    36   "_contract_multi" :: "[i,i] => o"    (infixl "--->" 50)
    37 translations
    37 translations
    38   "p -1-> q" == "<p,q> \<in> contract"
    38   "p -1-> q" == "<p,q> \<in> contract"
    39   "p ---> q" == "<p,q> \<in> contract^*"
    39   "p ---> q" == "<p,q> \<in> contract^*"
    40 
    40 
       
    41 syntax (xsymbols)
       
    42   "app"    :: "[i, i] => i"    	     (infixl "\<bullet>" 90)
       
    43 
    41 inductive
    44 inductive
    42   domains "contract" \<subseteq> "comb \<times> comb"
    45   domains "contract" \<subseteq> "comb \<times> comb"
    43   intros
    46   intros
    44     K:   "[| p \<in> comb;  q \<in> comb |] ==> K#p#q -1-> p"
    47     K:   "[| p \<in> comb;  q \<in> comb |] ==> K\<bullet>p\<bullet>q -1-> p"
    45     S:   "[| p \<in> comb;  q \<in> comb;  r \<in> comb |] ==> S#p#q#r -1-> (p#r)#(q#r)"
    48     S:   "[| p \<in> comb;  q \<in> comb;  r \<in> comb |] ==> S\<bullet>p\<bullet>q\<bullet>r -1-> (p\<bullet>r)\<bullet>(q\<bullet>r)"
    46     Ap1: "[| p-1->q;  r \<in> comb |] ==> p#r -1-> q#r"
    49     Ap1: "[| p-1->q;  r \<in> comb |] ==> p\<bullet>r -1-> q\<bullet>r"
    47     Ap2: "[| p-1->q;  r \<in> comb |] ==> r#p -1-> r#q"
    50     Ap2: "[| p-1->q;  r \<in> comb |] ==> r\<bullet>p -1-> r\<bullet>q"
    48   type_intros comb.intros
    51   type_intros comb.intros
    49 
    52 
    50 text {*
    53 text {*
    51   Inductive definition of parallel contractions, @{text "=1=>"} and
    54   Inductive definition of parallel contractions, @{text "=1=>"} and
    52   (multi-step) parallel reductions, @{text "===>"}.
    55   (multi-step) parallel reductions, @{text "===>"}.
    63 
    66 
    64 inductive
    67 inductive
    65   domains "parcontract" \<subseteq> "comb \<times> comb"
    68   domains "parcontract" \<subseteq> "comb \<times> comb"
    66   intros
    69   intros
    67     refl: "[| p \<in> comb |] ==> p =1=> p"
    70     refl: "[| p \<in> comb |] ==> p =1=> p"
    68     K:    "[| p \<in> comb;  q \<in> comb |] ==> K#p#q =1=> p"
    71     K:    "[| p \<in> comb;  q \<in> comb |] ==> K\<bullet>p\<bullet>q =1=> p"
    69     S:    "[| p \<in> comb;  q \<in> comb;  r \<in> comb |] ==> S#p#q#r =1=> (p#r)#(q#r)"
    72     S:    "[| p \<in> comb;  q \<in> comb;  r \<in> comb |] ==> S\<bullet>p\<bullet>q\<bullet>r =1=> (p\<bullet>r)\<bullet>(q\<bullet>r)"
    70     Ap:   "[| p=1=>q;  r=1=>s |] ==> p#r =1=> q#s"
    73     Ap:   "[| p=1=>q;  r=1=>s |] ==> p\<bullet>r =1=> q\<bullet>s"
    71   type_intros comb.intros
    74   type_intros comb.intros
    72 
    75 
    73 text {*
    76 text {*
    74   Misc definitions.
    77   Misc definitions.
    75 *}
    78 *}
    76 
    79 
    77 constdefs
    80 constdefs
    78   I :: i
    81   I :: i
    79   "I == S#K#K"
    82   "I == S\<bullet>K\<bullet>K"
    80 
    83 
    81   diamond :: "i => o"
    84   diamond :: "i => o"
    82   "diamond(r) ==
    85   "diamond(r) ==
    83     \<forall>x y. <x,y>\<in>r --> (\<forall>y'. <x,y'>\<in>r --> (\<exists>z. <y,z>\<in>r & <y',z> \<in> r))"
    86     \<forall>x y. <x,y>\<in>r --> (\<forall>y'. <x,y'>\<in>r --> (\<exists>z. <y,z>\<in>r & <y',z> \<in> r))"
    84 
    87 
   103    apply auto
   106    apply auto
   104    apply (best intro: r_into_trancl trans_trancl [THEN transD]
   107    apply (best intro: r_into_trancl trans_trancl [THEN transD]
   105      dest: diamond_strip_lemmaD)+
   108      dest: diamond_strip_lemmaD)+
   106   done
   109   done
   107 
   110 
   108 inductive_cases Ap_E [elim!]: "p#q \<in> comb"
   111 inductive_cases Ap_E [elim!]: "p\<bullet>q \<in> comb"
   109 
   112 
   110 declare comb.intros [intro!]
   113 declare comb.intros [intro!]
   111 
   114 
   112 
   115 
   113 subsection {* Results about Contraction *}
   116 subsection {* Results about Contraction *}
   136   contract.K [THEN rtrancl_into_rtrancl2]
   139   contract.K [THEN rtrancl_into_rtrancl2]
   137   contract.S [THEN rtrancl_into_rtrancl2]
   140   contract.S [THEN rtrancl_into_rtrancl2]
   138   contract.Ap1 [THEN rtrancl_into_rtrancl2]
   141   contract.Ap1 [THEN rtrancl_into_rtrancl2]
   139   contract.Ap2 [THEN rtrancl_into_rtrancl2]
   142   contract.Ap2 [THEN rtrancl_into_rtrancl2]
   140 
   143 
   141 lemma "p \<in> comb ==> I#p ---> p"
   144 lemma "p \<in> comb ==> I\<bullet>p ---> p"
   142   -- {* Example only: not used *}
   145   -- {* Example only: not used *}
   143   by (unfold I_def) (blast intro: reduction_rls)
   146   by (unfold I_def) (blast intro: reduction_rls)
   144 
   147 
   145 lemma comb_I: "I \<in> comb"
   148 lemma comb_I: "I \<in> comb"
   146   by (unfold I_def) blast
   149   by (unfold I_def) blast
   151 text {* Derive a case for each combinator constructor. *}
   154 text {* Derive a case for each combinator constructor. *}
   152 
   155 
   153 inductive_cases
   156 inductive_cases
   154       K_contractE [elim!]: "K -1-> r"
   157       K_contractE [elim!]: "K -1-> r"
   155   and S_contractE [elim!]: "S -1-> r"
   158   and S_contractE [elim!]: "S -1-> r"
   156   and Ap_contractE [elim!]: "p#q -1-> r"
   159   and Ap_contractE [elim!]: "p\<bullet>q -1-> r"
   157 
   160 
   158 declare contract.Ap1 [intro] contract.Ap2 [intro]
   161 declare contract.Ap1 [intro] contract.Ap2 [intro]
   159 
   162 
   160 lemma I_contract_E: "I -1-> r ==> P"
   163 lemma I_contract_E: "I -1-> r ==> P"
   161   by (auto simp add: I_def)
   164   by (auto simp add: I_def)
   162 
   165 
   163 lemma K1_contractD: "K#p -1-> r ==> (\<exists>q. r = K#q & p -1-> q)"
   166 lemma K1_contractD: "K\<bullet>p -1-> r ==> (\<exists>q. r = K\<bullet>q & p -1-> q)"
   164   by auto
   167   by auto
   165 
   168 
   166 lemma Ap_reduce1: "[| p ---> q;  r \<in> comb |] ==> p#r ---> q#r"
   169 lemma Ap_reduce1: "[| p ---> q;  r \<in> comb |] ==> p\<bullet>r ---> q\<bullet>r"
   167   apply (frule rtrancl_type [THEN subsetD, THEN SigmaD1])
   170   apply (frule rtrancl_type [THEN subsetD, THEN SigmaD1])
   168   apply (drule field_contract_eq [THEN equalityD1, THEN subsetD])
   171   apply (drule field_contract_eq [THEN equalityD1, THEN subsetD])
   169   apply (erule rtrancl_induct)
   172   apply (erule rtrancl_induct)
   170    apply (blast intro: reduction_rls)
   173    apply (blast intro: reduction_rls)
   171   apply (erule trans_rtrancl [THEN transD])
   174   apply (erule trans_rtrancl [THEN transD])
   172   apply (blast intro: contract_combD2 reduction_rls)
   175   apply (blast intro: contract_combD2 reduction_rls)
   173   done
   176   done
   174 
   177 
   175 lemma Ap_reduce2: "[| p ---> q;  r \<in> comb |] ==> r#p ---> r#q"
   178 lemma Ap_reduce2: "[| p ---> q;  r \<in> comb |] ==> r\<bullet>p ---> r\<bullet>q"
   176   apply (frule rtrancl_type [THEN subsetD, THEN SigmaD1])
   179   apply (frule rtrancl_type [THEN subsetD, THEN SigmaD1])
   177   apply (drule field_contract_eq [THEN equalityD1, THEN subsetD])
   180   apply (drule field_contract_eq [THEN equalityD1, THEN subsetD])
   178   apply (erule rtrancl_induct)
   181   apply (erule rtrancl_induct)
   179    apply (blast intro: reduction_rls)
   182    apply (blast intro: reduction_rls)
   180   apply (blast intro: trans_rtrancl [THEN transD] 
   183   apply (blast intro: trans_rtrancl [THEN transD] 
   181                       contract_combD2 reduction_rls)
   184                       contract_combD2 reduction_rls)
   182   done
   185   done
   183 
   186 
   184 text {* Counterexample to the diamond property for @{text "-1->"}. *}
   187 text {* Counterexample to the diamond property for @{text "-1->"}. *}
   185 
   188 
   186 lemma KIII_contract1: "K#I#(I#I) -1-> I"
   189 lemma KIII_contract1: "K\<bullet>I\<bullet>(I\<bullet>I) -1-> I"
   187   by (blast intro: comb.intros contract.K comb_I)
   190   by (blast intro: comb.intros contract.K comb_I)
   188 
   191 
   189 lemma KIII_contract2: "K#I#(I#I) -1-> K#I#((K#I)#(K#I))"
   192 lemma KIII_contract2: "K\<bullet>I\<bullet>(I\<bullet>I) -1-> K\<bullet>I\<bullet>((K\<bullet>I)\<bullet>(K\<bullet>I))"
   190   by (unfold I_def) (blast intro: comb.intros contract.intros)
   193   by (unfold I_def) (blast intro: comb.intros contract.intros)
   191 
   194 
   192 lemma KIII_contract3: "K#I#((K#I)#(K#I)) -1-> I"
   195 lemma KIII_contract3: "K\<bullet>I\<bullet>((K\<bullet>I)\<bullet>(K\<bullet>I)) -1-> I"
   193   by (blast intro: comb.intros contract.K comb_I)
   196   by (blast intro: comb.intros contract.K comb_I)
   194 
   197 
   195 lemma not_diamond_contract: "\<not> diamond(contract)"
   198 lemma not_diamond_contract: "\<not> diamond(contract)"
   196   apply (unfold diamond_def)
   199   apply (unfold diamond_def)
   197   apply (blast intro: KIII_contract1 KIII_contract2 KIII_contract3
   200   apply (blast intro: KIII_contract1 KIII_contract2 KIII_contract3
   212 
   215 
   213 text {* Derive a case for each combinator constructor. *}
   216 text {* Derive a case for each combinator constructor. *}
   214 inductive_cases
   217 inductive_cases
   215       K_parcontractE [elim!]: "K =1=> r"
   218       K_parcontractE [elim!]: "K =1=> r"
   216   and S_parcontractE [elim!]: "S =1=> r"
   219   and S_parcontractE [elim!]: "S =1=> r"
   217   and Ap_parcontractE [elim!]: "p#q =1=> r"
   220   and Ap_parcontractE [elim!]: "p\<bullet>q =1=> r"
   218 
   221 
   219 declare parcontract.intros [intro]
   222 declare parcontract.intros [intro]
   220 
   223 
   221 
   224 
   222 subsection {* Basic properties of parallel contraction *}
   225 subsection {* Basic properties of parallel contraction *}
   223 
   226 
   224 lemma K1_parcontractD [dest!]:
   227 lemma K1_parcontractD [dest!]:
   225     "K#p =1=> r ==> (\<exists>p'. r = K#p' & p =1=> p')"
   228     "K\<bullet>p =1=> r ==> (\<exists>p'. r = K\<bullet>p' & p =1=> p')"
   226   by auto
   229   by auto
   227 
   230 
   228 lemma S1_parcontractD [dest!]:
   231 lemma S1_parcontractD [dest!]:
   229     "S#p =1=> r ==> (\<exists>p'. r = S#p' & p =1=> p')"
   232     "S\<bullet>p =1=> r ==> (\<exists>p'. r = S\<bullet>p' & p =1=> p')"
   230   by auto
   233   by auto
   231 
   234 
   232 lemma S2_parcontractD [dest!]:
   235 lemma S2_parcontractD [dest!]:
   233     "S#p#q =1=> r ==> (\<exists>p' q'. r = S#p'#q' & p =1=> p' & q =1=> q')"
   236     "S\<bullet>p\<bullet>q =1=> r ==> (\<exists>p' q'. r = S\<bullet>p'\<bullet>q' & p =1=> p' & q =1=> q')"
   234   by auto
   237   by auto
   235 
   238 
   236 lemma diamond_parcontract: "diamond(parcontract)"
   239 lemma diamond_parcontract: "diamond(parcontract)"
   237   -- {* Church-Rosser property for parallel contraction *}
   240   -- {* Church-Rosser property for parallel contraction *}
   238   apply (unfold diamond_def)
   241   apply (unfold diamond_def)