src/HOL/Lambda/Eta.ML
changeset 2031 03a843f0f447
parent 1974 b50f96543dec
child 2057 4d7a4b25a11f
equal deleted inserted replaced
2030:474b3f208789 2031:03a843f0f447
    24 AddSEs (beta_cases@eta_cases);
    24 AddSEs (beta_cases@eta_cases);
    25 
    25 
    26 section "Arithmetic lemmas";
    26 section "Arithmetic lemmas";
    27 
    27 
    28 goal HOL.thy "!!P. P ==> P=True";
    28 goal HOL.thy "!!P. P ==> P=True";
    29 by(fast_tac HOL_cs 1);
    29 by (fast_tac HOL_cs 1);
    30 qed "True_eq";
    30 qed "True_eq";
    31 
    31 
    32 Addsimps [less_not_sym RS True_eq];
    32 Addsimps [less_not_sym RS True_eq];
    33 
    33 
    34 goal Arith.thy "i < j --> pred i < j";
    34 goal Arith.thy "i < j --> pred i < j";
    35 by(nat_ind_tac "j" 1);
    35 by (nat_ind_tac "j" 1);
    36 by(ALLGOALS(asm_simp_tac(!simpset addsimps [less_Suc_eq])));
    36 by (ALLGOALS(asm_simp_tac(!simpset addsimps [less_Suc_eq])));
    37 by(nat_ind_tac "j1" 1);
    37 by (nat_ind_tac "j1" 1);
    38 by(ALLGOALS Asm_simp_tac);
    38 by (ALLGOALS Asm_simp_tac);
    39 qed_spec_mp "less_imp_pred_less";
    39 qed_spec_mp "less_imp_pred_less";
    40 
    40 
    41 goal Arith.thy "i<j --> ~ pred j < i";
    41 goal Arith.thy "i<j --> ~ pred j < i";
    42 by(nat_ind_tac "j" 1);
    42 by (nat_ind_tac "j" 1);
    43 by(ALLGOALS(asm_simp_tac(!simpset addsimps [less_Suc_eq])));
    43 by (ALLGOALS(asm_simp_tac(!simpset addsimps [less_Suc_eq])));
    44 qed_spec_mp "less_imp_not_pred_less";
    44 qed_spec_mp "less_imp_not_pred_less";
    45 Addsimps [less_imp_not_pred_less];
    45 Addsimps [less_imp_not_pred_less];
    46 
    46 
    47 goal Nat.thy "i < j --> j < Suc(Suc i) --> j = Suc i";
    47 goal Nat.thy "i < j --> j < Suc(Suc i) --> j = Suc i";
    48 by(nat_ind_tac "j" 1);
    48 by (nat_ind_tac "j" 1);
    49 by(ALLGOALS Simp_tac);
    49 by (ALLGOALS Simp_tac);
    50 by(simp_tac(!simpset addsimps [less_Suc_eq])1);
    50 by (simp_tac(!simpset addsimps [less_Suc_eq])1);
    51 by(fast_tac (HOL_cs addDs [less_not_sym]) 1);
    51 by (fast_tac (HOL_cs addDs [less_not_sym]) 1);
    52 qed_spec_mp "less_interval1";
    52 qed_spec_mp "less_interval1";
    53 
    53 
    54 
    54 
    55 section "decr and free";
    55 section "decr and free";
    56 
    56 
    57 goal Eta.thy "!i k. free (lift t k) i = \
    57 goal Eta.thy "!i k. free (lift t k) i = \
    58 \                   (i < k & free t i | k < i & free t (pred i))";
    58 \                   (i < k & free t i | k < i & free t (pred i))";
    59 by(db.induct_tac "t" 1);
    59 by (db.induct_tac "t" 1);
    60 by(ALLGOALS(asm_full_simp_tac (addsplit (!simpset) addcongs [conj_cong])));
    60 by (ALLGOALS(asm_full_simp_tac (addsplit (!simpset) addcongs [conj_cong])));
    61 by(fast_tac HOL_cs 2);
    61 by (fast_tac HOL_cs 2);
    62 by(safe_tac (HOL_cs addSIs [iffI]));
    62 by (safe_tac (HOL_cs addSIs [iffI]));
    63 by (dtac Suc_mono 1);
    63 by (dtac Suc_mono 1);
    64 by(ALLGOALS(Asm_full_simp_tac));
    64 by (ALLGOALS(Asm_full_simp_tac));
    65 by(dtac less_trans_Suc 1 THEN atac 1);
    65 by (dtac less_trans_Suc 1 THEN atac 1);
    66 by(dtac less_trans_Suc 2 THEN atac 2);
    66 by (dtac less_trans_Suc 2 THEN atac 2);
    67 by(ALLGOALS(Asm_full_simp_tac));
    67 by (ALLGOALS(Asm_full_simp_tac));
    68 qed "free_lift";
    68 qed "free_lift";
    69 Addsimps [free_lift];
    69 Addsimps [free_lift];
    70 
    70 
    71 goal Eta.thy "!i k t. free (s[t/k]) i = \
    71 goal Eta.thy "!i k t. free (s[t/k]) i = \
    72 \              (free s k & free t i | free s (if i<k then i else Suc i))";
    72 \              (free s k & free t i | free s (if i<k then i else Suc i))";
    73 by(db.induct_tac "s" 1);
    73 by (db.induct_tac "s" 1);
    74 by(ALLGOALS(asm_full_simp_tac (addsplit (!simpset) addsimps
    74 by (ALLGOALS(asm_full_simp_tac (addsplit (!simpset) addsimps
    75 [less_not_refl2,less_not_refl2 RS not_sym])));
    75 [less_not_refl2,less_not_refl2 RS not_sym])));
    76 by(fast_tac HOL_cs 2);
    76 by (fast_tac HOL_cs 2);
    77 by(safe_tac (HOL_cs addSIs [iffI]));
    77 by (safe_tac (HOL_cs addSIs [iffI]));
    78 by(ALLGOALS(Asm_simp_tac));
    78 by (ALLGOALS(Asm_simp_tac));
    79 by(fast_tac (HOL_cs addEs [less_imp_not_pred_less RS notE]) 1);
    79 by (fast_tac (HOL_cs addEs [less_imp_not_pred_less RS notE]) 1);
    80 by(fast_tac (HOL_cs addDs [less_not_sym]) 1);
    80 by (fast_tac (HOL_cs addDs [less_not_sym]) 1);
    81 by (dtac Suc_mono 1);
    81 by (dtac Suc_mono 1);
    82 by(dtac less_interval1 1 THEN atac 1);
    82 by (dtac less_interval1 1 THEN atac 1);
    83 by(asm_full_simp_tac (!simpset addsimps [eq_sym_conv]) 1);
    83 by (asm_full_simp_tac (!simpset addsimps [eq_sym_conv]) 1);
    84 by(dtac less_trans_Suc 1 THEN atac 1);
    84 by (dtac less_trans_Suc 1 THEN atac 1);
    85 by(Asm_full_simp_tac 1);
    85 by (Asm_full_simp_tac 1);
    86 qed "free_subst";
    86 qed "free_subst";
    87 Addsimps [free_subst];
    87 Addsimps [free_subst];
    88 
    88 
    89 goal Eta.thy "!!s. s -e> t ==> !i. free t i = free s i";
    89 goal Eta.thy "!!s. s -e> t ==> !i. free t i = free s i";
    90 by (etac eta.induct 1);
    90 by (etac eta.induct 1);
    91 by(ALLGOALS(asm_simp_tac (!simpset addsimps [decr_def] addcongs [conj_cong])));
    91 by (ALLGOALS(asm_simp_tac (!simpset addsimps [decr_def] addcongs [conj_cong])));
    92 qed_spec_mp "free_eta";
    92 qed_spec_mp "free_eta";
    93 
    93 
    94 goal Eta.thy "!!s. [| s -e> t; ~free s i |] ==> ~free t i";
    94 goal Eta.thy "!!s. [| s -e> t; ~free s i |] ==> ~free t i";
    95 by(asm_simp_tac (!simpset addsimps [free_eta]) 1);
    95 by (asm_simp_tac (!simpset addsimps [free_eta]) 1);
    96 qed "not_free_eta";
    96 qed "not_free_eta";
    97 
    97 
    98 goal Eta.thy "!i t u. ~free s i --> s[t/i] = s[u/i]";
    98 goal Eta.thy "!i t u. ~free s i --> s[t/i] = s[u/i]";
    99 by(db.induct_tac "s" 1);
    99 by (db.induct_tac "s" 1);
   100 by(ALLGOALS(simp_tac (addsplit (!simpset))));
   100 by (ALLGOALS(simp_tac (addsplit (!simpset))));
   101 by(fast_tac HOL_cs 1);
   101 by (fast_tac HOL_cs 1);
   102 by(fast_tac HOL_cs 1);
   102 by (fast_tac HOL_cs 1);
   103 qed_spec_mp "subst_not_free";
   103 qed_spec_mp "subst_not_free";
   104 
   104 
   105 goalw Eta.thy [decr_def] "!!s. ~free s i ==> s[t/i] = decr s i";
   105 goalw Eta.thy [decr_def] "!!s. ~free s i ==> s[t/i] = decr s i";
   106 by (etac subst_not_free 1);
   106 by (etac subst_not_free 1);
   107 qed "subst_decr";
   107 qed "subst_decr";
   108 
   108 
   109 goal Eta.thy "!!s. s -e> t ==> !u i. s[u/i] -e> t[u/i]";
   109 goal Eta.thy "!!s. s -e> t ==> !u i. s[u/i] -e> t[u/i]";
   110 by (etac eta.induct 1);
   110 by (etac eta.induct 1);
   111 by(ALLGOALS(asm_simp_tac (!simpset addsimps [subst_subst RS sym,decr_def])));
   111 by (ALLGOALS(asm_simp_tac (!simpset addsimps [subst_subst RS sym,decr_def])));
   112 by(asm_simp_tac (!simpset addsimps [subst_decr]) 1);
   112 by (asm_simp_tac (!simpset addsimps [subst_decr]) 1);
   113 qed_spec_mp "eta_subst";
   113 qed_spec_mp "eta_subst";
   114 Addsimps [eta_subst];
   114 Addsimps [eta_subst];
   115 
   115 
   116 goalw Eta.thy [decr_def] "!!s. s -e> t ==> decr s i -e> decr t i";
   116 goalw Eta.thy [decr_def] "!!s. s -e> t ==> decr s i -e> decr t i";
   117 by (etac eta_subst 1);
   117 by (etac eta_subst 1);
   120 section "Confluence of -e>";
   120 section "Confluence of -e>";
   121 
   121 
   122 goalw Eta.thy [square_def,id_def]  "square eta eta (eta^=) (eta^=)";
   122 goalw Eta.thy [square_def,id_def]  "square eta eta (eta^=) (eta^=)";
   123 by (rtac (impI RS allI RS allI) 1);
   123 by (rtac (impI RS allI RS allI) 1);
   124 by (etac eta.induct 1);
   124 by (etac eta.induct 1);
   125 by(ALLGOALS(fast_tac (!claset addSEs [eta_decr,not_free_eta] addss !simpset)));
   125 by (ALLGOALS(fast_tac (!claset addSEs [eta_decr,not_free_eta] addss !simpset)));
   126 val lemma = result();
   126 val lemma = result();
   127 
   127 
   128 goal Eta.thy "confluent(eta)";
   128 goal Eta.thy "confluent(eta)";
   129 by(rtac (lemma RS square_reflcl_confluent) 1);
   129 by (rtac (lemma RS square_reflcl_confluent) 1);
   130 qed "eta_confluent";
   130 qed "eta_confluent";
   131 
   131 
   132 section "Congruence rules for -e>>";
   132 section "Congruence rules for -e>>";
   133 
   133 
   134 goal Eta.thy "!!s. s -e>> s' ==> Fun s -e>> Fun s'";
   134 goal Eta.thy "!!s. s -e>> s' ==> Fun s -e>> Fun s'";
   153 
   153 
   154 section "Commutation of -> and -e>";
   154 section "Commutation of -> and -e>";
   155 
   155 
   156 goal Eta.thy "!!s t. s -> t ==> (!i. free t i --> free s i)";
   156 goal Eta.thy "!!s t. s -> t ==> (!i. free t i --> free s i)";
   157 by (etac beta.induct 1);
   157 by (etac beta.induct 1);
   158 by(ALLGOALS(Asm_full_simp_tac));
   158 by (ALLGOALS(Asm_full_simp_tac));
   159 qed_spec_mp "free_beta";
   159 qed_spec_mp "free_beta";
   160 
   160 
   161 goalw Eta.thy [decr_def] "!!s t. s -> t ==> (!i. decr s i -> decr t i)";
   161 goalw Eta.thy [decr_def] "!!s t. s -> t ==> (!i. decr s i -> decr t i)";
   162 by (etac beta.induct 1);
   162 by (etac beta.induct 1);
   163 by(ALLGOALS(asm_full_simp_tac (!simpset addsimps [subst_subst RS sym])));
   163 by (ALLGOALS(asm_full_simp_tac (!simpset addsimps [subst_subst RS sym])));
   164 qed_spec_mp "beta_decr";
   164 qed_spec_mp "beta_decr";
   165 
   165 
   166 goalw Eta.thy [decr_def]
   166 goalw Eta.thy [decr_def]
   167   "decr (Var i) k = (if i<=k then Var i else Var(pred i))";
   167   "decr (Var i) k = (if i<=k then Var i else Var(pred i))";
   168 by(simp_tac (addsplit (!simpset) addsimps [le_def]) 1);
   168 by (simp_tac (addsplit (!simpset) addsimps [le_def]) 1);
   169 qed "decr_Var";
   169 qed "decr_Var";
   170 Addsimps [decr_Var];
   170 Addsimps [decr_Var];
   171 
   171 
   172 goalw Eta.thy [decr_def] "decr (s@t) i = (decr s i)@(decr t i)";
   172 goalw Eta.thy [decr_def] "decr (s@t) i = (decr s i)@(decr t i)";
   173 by(Simp_tac 1);
   173 by (Simp_tac 1);
   174 qed "decr_App";
   174 qed "decr_App";
   175 Addsimps [decr_App];
   175 Addsimps [decr_App];
   176 
   176 
   177 goalw Eta.thy [decr_def] "decr (Fun s) i = Fun (decr s (Suc i))";
   177 goalw Eta.thy [decr_def] "decr (Fun s) i = Fun (decr s (Suc i))";
   178 by(Simp_tac 1);
   178 by (Simp_tac 1);
   179 qed "decr_Fun";
   179 qed "decr_Fun";
   180 Addsimps [decr_Fun];
   180 Addsimps [decr_Fun];
   181 
   181 
   182 goal Eta.thy "!i. ~free t (Suc i) --> decr t i = decr t (Suc i)";
   182 goal Eta.thy "!i. ~free t (Suc i) --> decr t i = decr t (Suc i)";
   183 by(db.induct_tac "t" 1);
   183 by (db.induct_tac "t" 1);
   184 by(ALLGOALS(asm_simp_tac (addsplit (!simpset) addsimps [le_def, less_Suc_eq])));
   184 by (ALLGOALS(asm_simp_tac (addsplit (!simpset) addsimps [le_def, less_Suc_eq])));
   185 by(fast_tac HOL_cs 1);
   185 by (fast_tac HOL_cs 1);
   186 qed "decr_not_free";
   186 qed "decr_not_free";
   187 Addsimps [decr_not_free];
   187 Addsimps [decr_not_free];
   188 
   188 
   189 goal Eta.thy "!!s t. s -e> t ==> (!i. lift s i -e> lift t i)";
   189 goal Eta.thy "!!s t. s -e> t ==> (!i. lift s i -e> lift t i)";
   190 by (etac eta.induct 1);
   190 by (etac eta.induct 1);
   191 by(ALLGOALS(asm_simp_tac (addsplit (!simpset) addsimps [decr_def])));
   191 by (ALLGOALS(asm_simp_tac (addsplit (!simpset) addsimps [decr_def])));
   192 by(asm_simp_tac (addsplit (!simpset) addsimps [subst_decr]) 1);
   192 by (asm_simp_tac (addsplit (!simpset) addsimps [subst_decr]) 1);
   193 qed_spec_mp "eta_lift";
   193 qed_spec_mp "eta_lift";
   194 Addsimps [eta_lift];
   194 Addsimps [eta_lift];
   195 
   195 
   196 goal Eta.thy "!s t i. s -e> t --> u[s/i] -e>> u[t/i]";
   196 goal Eta.thy "!s t i. s -e> t --> u[s/i] -e>> u[t/i]";
   197 by(db.induct_tac "u" 1);
   197 by (db.induct_tac "u" 1);
   198 by(ALLGOALS(asm_simp_tac (addsplit (!simpset))));
   198 by (ALLGOALS(asm_simp_tac (addsplit (!simpset))));
   199 by(fast_tac (!claset addIs [r_into_rtrancl]) 1);
   199 by (fast_tac (!claset addIs [r_into_rtrancl]) 1);
   200 by(fast_tac (!claset addSIs [rtrancl_eta_App]) 1);
   200 by (fast_tac (!claset addSIs [rtrancl_eta_App]) 1);
   201 by(fast_tac (!claset addSIs [rtrancl_eta_Fun,eta_lift]) 1);
   201 by (fast_tac (!claset addSIs [rtrancl_eta_Fun,eta_lift]) 1);
   202 qed_spec_mp "rtrancl_eta_subst";
   202 qed_spec_mp "rtrancl_eta_subst";
   203 
   203 
   204 goalw Eta.thy [square_def] "square beta eta (eta^*) (beta^=)";
   204 goalw Eta.thy [square_def] "square beta eta (eta^*) (beta^=)";
   205 by (rtac (impI RS allI RS allI) 1);
   205 by (rtac (impI RS allI RS allI) 1);
   206 by (etac beta.induct 1);
   206 by (etac beta.induct 1);
   207 by(strip_tac 1);
   207 by (strip_tac 1);
   208 by (eresolve_tac eta_cases 1);
   208 by (eresolve_tac eta_cases 1);
   209 by (eresolve_tac eta_cases 1);
   209 by (eresolve_tac eta_cases 1);
   210 by(fast_tac (!claset addss (!simpset addsimps [subst_decr])) 1);
   210 by (fast_tac (!claset addss (!simpset addsimps [subst_decr])) 1);
   211 by(slow_tac (!claset addIs [r_into_rtrancl,eta_subst]) 1);
   211 by (slow_tac (!claset addIs [r_into_rtrancl,eta_subst]) 1);
   212 by(slow_tac (!claset addIs [rtrancl_eta_subst]) 1);
   212 by (slow_tac (!claset addIs [rtrancl_eta_subst]) 1);
   213 by(slow_tac (!claset addIs [r_into_rtrancl,rtrancl_eta_AppL]) 1);
   213 by (slow_tac (!claset addIs [r_into_rtrancl,rtrancl_eta_AppL]) 1);
   214 by(slow_tac (!claset addIs [r_into_rtrancl,rtrancl_eta_AppR]) 1);
   214 by (slow_tac (!claset addIs [r_into_rtrancl,rtrancl_eta_AppR]) 1);
   215 by(slow_tac (!claset addIs [r_into_rtrancl,rtrancl_eta_Fun,free_beta,beta_decr]
   215 by (slow_tac (!claset addIs [r_into_rtrancl,rtrancl_eta_Fun,free_beta,beta_decr]
   216                   addss (!simpset addsimps[subst_decr,symmetric decr_def])) 1);
   216                   addss (!simpset addsimps[subst_decr,symmetric decr_def])) 1);
   217 qed "square_beta_eta";
   217 qed "square_beta_eta";
   218 
   218 
   219 goal Eta.thy "confluent(beta Un eta)";
   219 goal Eta.thy "confluent(beta Un eta)";
   220 by(REPEAT(ares_tac [square_rtrancl_reflcl_commute,confluent_Un,
   220 by (REPEAT(ares_tac [square_rtrancl_reflcl_commute,confluent_Un,
   221                     beta_confluent,eta_confluent,square_beta_eta] 1));
   221                     beta_confluent,eta_confluent,square_beta_eta] 1));
   222 qed "confluent_beta_eta";
   222 qed "confluent_beta_eta";
   223 
   223 
   224 
   224 
   225 section "Implicit definition of -e>: Fun(lift s 0 @ Var 0) -e> s";
   225 section "Implicit definition of -e>: Fun(lift s 0 @ Var 0) -e> s";
   226 
   226 
   227 goal Eta.thy "!i. (~free s i) = (? t. s = lift t i)";
   227 goal Eta.thy "!i. (~free s i) = (? t. s = lift t i)";
   228 by(db.induct_tac "s" 1);
   228 by (db.induct_tac "s" 1);
   229   by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
   229   by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
   230   by(SELECT_GOAL(safe_tac HOL_cs)1);
   230   by(SELECT_GOAL(safe_tac HOL_cs)1);
   231    by(res_inst_tac [("m","nat"),("n","i")] nat_less_cases 1);
   231    by(res_inst_tac [("m","nat"),("n","i")] nat_less_cases 1);
   232      by(res_inst_tac [("x","Var nat")] exI 1);
   232      by(res_inst_tac [("x","Var nat")] exI 1);
   233      by(Asm_simp_tac 1);
   233      by(Asm_simp_tac 1);
   256  by(res_inst_tac [("db","t")] db_case_distinction 1);
   256  by(res_inst_tac [("db","t")] db_case_distinction 1);
   257    by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
   257    by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
   258   by(Simp_tac 1);
   258   by(Simp_tac 1);
   259   by(fast_tac HOL_cs 1);
   259   by(fast_tac HOL_cs 1);
   260  by(Simp_tac 1);
   260  by(Simp_tac 1);
   261 by(Asm_simp_tac 1);
   261 by (Asm_simp_tac 1);
   262 be thin_rl 1;
   262 by (etac thin_rl 1);
   263 br allI 1;
   263 by (rtac allI 1);
   264 br iffI 1;
   264 by (rtac iffI 1);
   265  be exE 1;
   265  be exE 1;
   266  by(res_inst_tac [("x","Fun t")] exI 1);
   266  by(res_inst_tac [("x","Fun t")] exI 1);
   267  by(Asm_simp_tac 1);
   267  by(Asm_simp_tac 1);
   268 be exE 1;
   268 by (etac exE 1);
   269 be rev_mp 1;
   269 by (etac rev_mp 1);
   270 by(res_inst_tac [("db","t")] db_case_distinction 1);
   270 by (res_inst_tac [("db","t")] db_case_distinction 1);
   271   by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
   271   by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
   272  by(Simp_tac 1);
   272  by(Simp_tac 1);
   273 by(Simp_tac 1);
   273 by (Simp_tac 1);
   274 by(fast_tac HOL_cs 1);
   274 by (fast_tac HOL_cs 1);
   275 qed_spec_mp "not_free_iff_lifted";
   275 qed_spec_mp "not_free_iff_lifted";
   276 
   276 
   277 goalw Eta.thy [decr_def]
   277 goalw Eta.thy [decr_def]
   278  "(!s. (~free s 0) --> R(Fun(s @ Var 0))(decr s 0)) = \
   278  "(!s. (~free s 0) --> R(Fun(s @ Var 0))(decr s 0)) = \
   279 \ (!s. R(Fun(lift s 0 @ Var 0))(s))";
   279 \ (!s. R(Fun(lift s 0 @ Var 0))(s))";
   280 by(fast_tac (HOL_cs addss (!simpset addsimps [lemma,not_free_iff_lifted])) 1);
   280 by (fast_tac (HOL_cs addss (!simpset addsimps [lemma,not_free_iff_lifted])) 1);
   281 qed "explicit_is_implicit";
   281 qed "explicit_is_implicit";