src/HOL/IOA/NTP/Lemmas.ML
changeset 1266 3ae9fe3c0f68
parent 1051 4fcd0638e61d
child 1328 9a449a91425d
equal deleted inserted replaced
1265:6ef9a9893fd6 1266:3ae9fe3c0f68
    54 
    54 
    55 
    55 
    56 (* Arithmetic *)
    56 (* Arithmetic *)
    57 goal Arith.thy "n ~= 0 --> Suc(m+pred(n)) = m+n";
    57 goal Arith.thy "n ~= 0 --> Suc(m+pred(n)) = m+n";
    58   by (nat_ind_tac "n" 1);
    58   by (nat_ind_tac "n" 1);
    59   by (REPEAT(simp_tac arith_ss 1));
    59   by (REPEAT(Simp_tac 1));
    60 val Suc_pred_lemma = store_thm("Suc_pred_lemma", result() RS mp);
    60 val Suc_pred_lemma = store_thm("Suc_pred_lemma", result() RS mp);
    61 
    61 
    62 goal Arith.thy "x <= y --> x <= Suc(y)";
    62 goal Arith.thy "x <= y --> x <= Suc(y)";
    63   by (rtac impI 1);
    63   by (rtac impI 1);
    64   by (rtac (le_eq_less_or_eq RS iffD2) 1);
    64   by (rtac (le_eq_less_or_eq RS iffD2) 1);
    65   by (rtac disjI1 1);
    65   by (rtac disjI1 1);
    66   by (dtac (le_eq_less_or_eq RS iffD1) 1);
    66   by (dtac (le_eq_less_or_eq RS iffD1) 1);
    67   by (etac disjE 1);
    67   by (etac disjE 1);
    68   by (etac less_SucI 1);
    68   by (etac less_SucI 1);
    69   by (asm_simp_tac nat_ss 1);
    69   by (Asm_simp_tac 1);
    70 val leq_imp_leq_suc = store_thm("leq_imp_leq_suc", result() RS mp);
    70 val leq_imp_leq_suc = store_thm("leq_imp_leq_suc", result() RS mp);
    71 
    71 
    72 (* Same as previous! *)
    72 (* Same as previous! *)
    73 goal Arith.thy "(x::nat)<=y --> x<=Suc(y)";
    73 goal Arith.thy "(x::nat)<=y --> x<=Suc(y)";
    74   by (simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
    74   by (simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
    75 qed "leq_suc";
    75 qed "leq_suc";
    76 
    76 
    77 goal Arith.thy "((m::nat) + n = m + p) = (n = p)";
    77 goal Arith.thy "((m::nat) + n = m + p) = (n = p)";
    78   by (nat_ind_tac "m" 1);
    78   by (nat_ind_tac "m" 1);
    79   by (simp_tac arith_ss 1);
    79   by (Simp_tac 1);
    80   by (asm_simp_tac arith_ss 1);
    80   by (Asm_simp_tac 1);
    81 qed "left_plus_cancel";
    81 qed "left_plus_cancel";
    82 
    82 
    83 goal Arith.thy "((x::nat) + y = Suc(x + z)) = (y = Suc(z))";
    83 goal Arith.thy "((x::nat) + y = Suc(x + z)) = (y = Suc(z))";
    84   by (nat_ind_tac "x" 1);
    84   by (nat_ind_tac "x" 1);
    85   by (simp_tac arith_ss 1);
    85   by (Simp_tac 1);
    86   by (asm_simp_tac arith_ss 1);
    86   by (Asm_simp_tac 1);
    87 qed "left_plus_cancel_inside_succ";
    87 qed "left_plus_cancel_inside_succ";
    88 
    88 
    89 goal Arith.thy "(x ~= 0) = (? y. x = Suc(y))";
    89 goal Arith.thy "(x ~= 0) = (? y. x = Suc(y))";
    90   by (nat_ind_tac "x" 1);
    90   by (nat_ind_tac "x" 1);
    91   by (simp_tac arith_ss 1);
    91   by (Simp_tac 1);
    92   by (asm_simp_tac arith_ss 1);
    92   by (Asm_simp_tac 1);
    93   by (fast_tac HOL_cs 1);
    93   by (fast_tac HOL_cs 1);
    94 qed "nonzero_is_succ";
    94 qed "nonzero_is_succ";
    95 
    95 
    96 goal Arith.thy "(m::nat) < n --> m + p < n + p";
    96 goal Arith.thy "(m::nat) < n --> m + p < n + p";
    97   by (nat_ind_tac "p" 1);
    97   by (nat_ind_tac "p" 1);
    98   by (simp_tac arith_ss 1);
    98   by (Simp_tac 1);
    99   by (asm_simp_tac arith_ss 1);
    99   by (Asm_simp_tac 1);
   100 qed "less_add_same_less";
   100 qed "less_add_same_less";
   101 
   101 
   102 goal Arith.thy "(x::nat)<= y --> x<=y+k";
   102 goal Arith.thy "(x::nat)<= y --> x<=y+k";
   103   by (nat_ind_tac "k" 1);
   103   by (nat_ind_tac "k" 1);
   104   by (simp_tac arith_ss 1);
   104   by (Simp_tac 1);
   105   by (asm_full_simp_tac (arith_ss addsimps [leq_suc]) 1);
   105   by (asm_full_simp_tac (!simpset addsimps [leq_suc]) 1);
   106 qed "leq_add_leq";
   106 qed "leq_add_leq";
   107 
   107 
   108 goal Arith.thy "(x::nat) + y <= z --> x <= z";
   108 goal Arith.thy "(x::nat) + y <= z --> x <= z";
   109   by (nat_ind_tac "y" 1);
   109   by (nat_ind_tac "y" 1);
   110   by (simp_tac arith_ss 1);
   110   by (Simp_tac 1);
   111   by (asm_simp_tac arith_ss 1);
   111   by (Asm_simp_tac 1);
   112   by (rtac impI 1);
   112   by (rtac impI 1);
   113   by (dtac Suc_leD 1);
   113   by (dtac Suc_leD 1);
   114   by (fast_tac HOL_cs 1);
   114   by (fast_tac HOL_cs 1);
   115 qed "left_add_leq";
   115 qed "left_add_leq";
   116 
   116 
   127 qed "less_add_cong";
   127 qed "less_add_cong";
   128 
   128 
   129 goal Arith.thy "(A::nat) <= B --> C <= D --> A + C <= B + D";
   129 goal Arith.thy "(A::nat) <= B --> C <= D --> A + C <= B + D";
   130   by (rtac impI 1);
   130   by (rtac impI 1);
   131   by (rtac impI 1);
   131   by (rtac impI 1);
   132   by (asm_full_simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
   132   by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
   133   by (safe_tac HOL_cs);
   133   by (safe_tac HOL_cs);
   134   by (rtac (less_add_cong RS mp RS mp) 1);
   134   by (rtac (less_add_cong RS mp RS mp) 1);
   135   by (assume_tac 1);
   135   by (assume_tac 1);
   136   by (assume_tac 1);
   136   by (assume_tac 1);
   137   by (rtac (less_add_same_less RS mp) 1);
   137   by (rtac (less_add_same_less RS mp) 1);
   145 goal Arith.thy "(w <= y) --> ((x::nat) + y <= z) --> (x + w <= z)";
   145 goal Arith.thy "(w <= y) --> ((x::nat) + y <= z) --> (x + w <= z)";
   146   by (rtac impI 1); 
   146   by (rtac impI 1); 
   147   by (dtac (less_eq_add_cong RS mp) 1);
   147   by (dtac (less_eq_add_cong RS mp) 1);
   148   by (cut_facts_tac [le_refl] 1);
   148   by (cut_facts_tac [le_refl] 1);
   149   by (dres_inst_tac [("P","x<=x")] mp 1);by (assume_tac 1);
   149   by (dres_inst_tac [("P","x<=x")] mp 1);by (assume_tac 1);
   150   by (asm_full_simp_tac (HOL_ss addsimps [add_commute]) 1);
   150   by (asm_full_simp_tac (!simpset addsimps [add_commute]) 1);
   151   by (rtac impI 1);
   151   by (rtac impI 1);
   152   by (etac le_trans 1);
   152   by (etac le_trans 1);
   153   by (assume_tac 1);
   153   by (assume_tac 1);
   154 qed "leq_add_left_cong";
   154 qed "leq_add_left_cong";
   155 
   155 
   156 goal Arith.thy "(? x. y = Suc(x)) = (~(y = 0))";
   156 goal Arith.thy "(? x. y = Suc(x)) = (~(y = 0))";
   157   by (nat_ind_tac "y" 1);
   157   by (nat_ind_tac "y" 1);
   158   by (simp_tac arith_ss 1);
   158   by (Simp_tac 1);
   159   by (rtac iffI 1);
   159   by (rtac iffI 1);
   160   by (asm_full_simp_tac arith_ss 1);
   160   by (Asm_full_simp_tac 1);
   161   by (fast_tac HOL_cs 1);
   161   by (fast_tac HOL_cs 1);
   162 qed "suc_not_zero";
   162 qed "suc_not_zero";
   163 
   163 
   164 goal Arith.thy "Suc(x) <= y --> (? z. y = Suc(z))";
   164 goal Arith.thy "Suc(x) <= y --> (? z. y = Suc(z))";
   165   by (rtac impI 1);
   165   by (rtac impI 1);
   166   by (asm_full_simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
   166   by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
   167   by (safe_tac HOL_cs);
   167   by (safe_tac HOL_cs);
   168   by (fast_tac HOL_cs 2);
   168   by (fast_tac HOL_cs 2);
   169   by (asm_simp_tac (arith_ss addsimps [suc_not_zero]) 1);
   169   by (asm_simp_tac (!simpset addsimps [suc_not_zero]) 1);
   170   by (rtac ccontr 1);
   170   by (rtac ccontr 1);
   171   by (asm_full_simp_tac (arith_ss addsimps [suc_not_zero]) 1);
   171   by (asm_full_simp_tac (!simpset addsimps [suc_not_zero]) 1);
   172   by (hyp_subst_tac 1);
   172   by (hyp_subst_tac 1);
   173   by (asm_full_simp_tac arith_ss 1);
   173   by (Asm_full_simp_tac 1);
   174 qed "suc_leq_suc";
   174 qed "suc_leq_suc";
   175 
   175 
   176 goal Arith.thy "~0<n --> n = 0";
   176 goal Arith.thy "~0<n --> n = 0";
   177   by (nat_ind_tac "n" 1);
   177   by (nat_ind_tac "n" 1);
   178   by (asm_simp_tac arith_ss 1);
   178   by (Asm_simp_tac 1);
   179   by (safe_tac HOL_cs);
   179   by (safe_tac HOL_cs);
   180   by (asm_full_simp_tac arith_ss 1);
   180   by (Asm_full_simp_tac 1);
   181   by (asm_full_simp_tac arith_ss 1);
   181   by (Asm_full_simp_tac 1);
   182 qed "zero_eq";
   182 qed "zero_eq";
   183 
   183 
   184 goal Arith.thy "x < Suc(y) --> x<=y";
   184 goal Arith.thy "x < Suc(y) --> x<=y";
   185   by (nat_ind_tac "n" 1);
   185   by (nat_ind_tac "n" 1);
   186   by (asm_simp_tac arith_ss 1);
   186   by (Asm_simp_tac 1);
   187   by (safe_tac HOL_cs);
   187   by (safe_tac HOL_cs);
   188   by (etac less_imp_le 1);
   188   by (etac less_imp_le 1);
   189 qed "less_suc_imp_leq";
   189 qed "less_suc_imp_leq";
   190 
   190 
   191 goal Arith.thy "0<x --> Suc(pred(x)) = x";
   191 goal Arith.thy "0<x --> Suc(pred(x)) = x";
   192   by (nat_ind_tac "x" 1);
   192   by (nat_ind_tac "x" 1);
   193   by (simp_tac arith_ss 1);
   193   by (Simp_tac 1);
   194   by (asm_simp_tac arith_ss 1);
   194   by (Asm_simp_tac 1);
   195 qed "suc_pred_id";
   195 qed "suc_pred_id";
   196 
   196 
   197 goal Arith.thy "0<x --> (pred(x) = y) = (x = Suc(y))";
   197 goal Arith.thy "0<x --> (pred(x) = y) = (x = Suc(y))";
   198   by (nat_ind_tac "x" 1);
   198   by (nat_ind_tac "x" 1);
   199   by (simp_tac arith_ss 1);
   199   by (Simp_tac 1);
   200   by (asm_simp_tac arith_ss 1);
   200   by (Asm_simp_tac 1);
   201 qed "pred_suc";
   201 qed "pred_suc";
   202 
   202 
   203 goal Arith.thy "(x ~= 0) = (0<x)";
   203 goal Arith.thy "(x ~= 0) = (0<x)";
   204   by (nat_ind_tac "x" 1);
   204   by (nat_ind_tac "x" 1);
   205   by (simp_tac arith_ss 1);
   205   by (Simp_tac 1);
   206   by (asm_simp_tac arith_ss 1);
   206   by (Asm_simp_tac 1);
   207 qed "unzero_less";
   207 qed "unzero_less";
   208 
   208 
   209 (* Odd proof. Why do induction? *)
   209 (* Odd proof. Why do induction? *)
   210 goal Arith.thy "((x::nat) = y + z) --> (y <= x)";
   210 goal Arith.thy "((x::nat) = y + z) --> (y <= x)";
   211   by (nat_ind_tac "y" 1);
   211   by (nat_ind_tac "y" 1);
   212   by (simp_tac arith_ss 1);
   212   by (Simp_tac 1);
   213   by (simp_tac (arith_ss addsimps 
   213   by (simp_tac (!simpset addsimps [le_refl RS (leq_add_leq RS mp)]) 1);
   214                 [Suc_le_mono, le_refl RS (leq_add_leq RS mp)]) 1);
       
   215 qed "plus_leq_lem";
   214 qed "plus_leq_lem";
   216 
   215 
   217 (* Lists *)
   216 (* Lists *)
       
   217 
       
   218 val list_ss = simpset_of "List";
   218 
   219 
   219 goal List.thy "(xs @ (y#ys)) ~= []";
   220 goal List.thy "(xs @ (y#ys)) ~= []";
   220   by (list.induct_tac "xs" 1);
   221   by (list.induct_tac "xs" 1);
   221   by (simp_tac list_ss 1);
   222   by (simp_tac list_ss 1);
   222   by (asm_simp_tac list_ss 1);
   223   by (asm_simp_tac list_ss 1);