src/ZF/Arith.ML
changeset 437 435875e4b21d
parent 435 ca5356bd315a
child 760 f0200e91b272
equal deleted inserted replaced
436:0cdc840297bb 437:435875e4b21d
   154  (fn _ =>
   154  (fn _ =>
   155   [ (nat_ind_tac "n" [] 1),
   155   [ (nat_ind_tac "n" [] 1),
   156     (ALLGOALS
   156     (ALLGOALS
   157      (asm_simp_tac (arith_ss addsimps [add_0_right, add_succ_right]))) ]);
   157      (asm_simp_tac (arith_ss addsimps [add_0_right, add_succ_right]))) ]);
   158 
   158 
       
   159 (*for a/c rewriting*)
   159 val add_left_commute = prove_goal Arith.thy
   160 val add_left_commute = prove_goal Arith.thy
   160     "!!m n k. [| m:nat;  n:nat;  k:nat |] ==> m#+(n#+k)=n#+(m#+k)"
   161     "!!m n k. [| m:nat;  n:nat |] ==> m#+(n#+k)=n#+(m#+k)"
   161  (fn _ => [rtac (add_commute RS trans) 1, 
   162  (fn _ => [asm_simp_tac (ZF_ss addsimps [add_assoc RS sym, add_commute]) 1]);
   162            rtac (add_assoc RS trans) 3, 
       
   163 	   rtac (add_commute RS subst_context) 4,
       
   164 	   REPEAT (ares_tac [add_type] 1)]);
       
   165 
   163 
   166 (*Addition is an AC-operator*)
   164 (*Addition is an AC-operator*)
   167 val add_ac = [add_assoc, add_commute, add_left_commute];
   165 val add_ac = [add_assoc, add_commute, add_left_commute];
   168 
   166 
   169 (*Cancellation law on the left*)
   167 (*Cancellation law on the left*)
   170 val [knat,eqn] = goal Arith.thy 
   168 val [eqn,knat] = goal Arith.thy 
   171     "[| k:nat;  k #+ m = k #+ n |] ==> m=n";
   169     "[| k #+ m = k #+ n;  k:nat |] ==> m=n";
   172 by (rtac (eqn RS rev_mp) 1);
   170 by (rtac (eqn RS rev_mp) 1);
   173 by (nat_ind_tac "k" [knat] 1);
   171 by (nat_ind_tac "k" [knat] 1);
   174 by (ALLGOALS (simp_tac arith_ss));
   172 by (ALLGOALS (simp_tac arith_ss));
   175 by (fast_tac ZF_cs 1);
   173 by (fast_tac ZF_cs 1);
   176 val add_left_cancel = result();
   174 val add_left_cancel = result();
   218 val mult_assoc = prove_goal Arith.thy 
   216 val mult_assoc = prove_goal Arith.thy 
   219     "!!m n k. [| m:nat;  n:nat;  k:nat |] ==> (m #* n) #* k = m #* (n #* k)"
   217     "!!m n k. [| m:nat;  n:nat;  k:nat |] ==> (m #* n) #* k = m #* (n #* k)"
   220  (fn _=>
   218  (fn _=>
   221   [ (etac nat_induct 1),
   219   [ (etac nat_induct 1),
   222     (ALLGOALS (asm_simp_tac (arith_ss addsimps [add_mult_distrib]))) ]);
   220     (ALLGOALS (asm_simp_tac (arith_ss addsimps [add_mult_distrib]))) ]);
       
   221 
       
   222 (*for a/c rewriting*)
       
   223 val mult_left_commute = prove_goal Arith.thy 
       
   224     "!!m n k. [| m:nat;  n:nat;  k:nat |] ==> m #* (n #* k) = n #* (m #* k)"
       
   225  (fn _ => [rtac (mult_commute RS trans) 1, 
       
   226            rtac (mult_assoc RS trans) 3, 
       
   227 	   rtac (mult_commute RS subst_context) 6,
       
   228 	   REPEAT (ares_tac [mult_type] 1)]);
       
   229 
       
   230 val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
   223 
   231 
   224 
   232 
   225 (*** Difference ***)
   233 (*** Difference ***)
   226 
   234 
   227 val diff_self_eq_0 = prove_goal Arith.thy 
   235 val diff_self_eq_0 = prove_goal Arith.thy 
   239 by (ALLGOALS (asm_simp_tac arith_ss));
   247 by (ALLGOALS (asm_simp_tac arith_ss));
   240 val add_diff_inverse = result();
   248 val add_diff_inverse = result();
   241 
   249 
   242 (*Subtraction is the inverse of addition. *)
   250 (*Subtraction is the inverse of addition. *)
   243 val [mnat,nnat] = goal Arith.thy
   251 val [mnat,nnat] = goal Arith.thy
   244     "[| m:nat;  n:nat |] ==> (n#+m) #-n = m";
   252     "[| m:nat;  n:nat |] ==> (n#+m) #- n = m";
   245 by (rtac (nnat RS nat_induct) 1);
   253 by (rtac (nnat RS nat_induct) 1);
   246 by (ALLGOALS (asm_simp_tac (arith_ss addsimps [mnat])));
   254 by (ALLGOALS (asm_simp_tac (arith_ss addsimps [mnat])));
   247 val diff_add_inverse = result();
   255 val diff_add_inverse = result();
       
   256 
       
   257 goal Arith.thy
       
   258     "!!m n. [| m:nat;  n:nat |] ==> (m#+n) #- n = m";
       
   259 by (res_inst_tac [("m1","m")] (add_commute RS ssubst) 1);
       
   260 by (REPEAT (ares_tac [diff_add_inverse] 1));
       
   261 val diff_add_inverse2 = result();
   248 
   262 
   249 val [mnat,nnat] = goal Arith.thy
   263 val [mnat,nnat] = goal Arith.thy
   250     "[| m:nat;  n:nat |] ==> n #- (n#+m) = 0";
   264     "[| m:nat;  n:nat |] ==> n #- (n#+m) = 0";
   251 by (rtac (nnat RS nat_induct) 1);
   265 by (rtac (nnat RS nat_induct) 1);
   252 by (ALLGOALS (asm_simp_tac (arith_ss addsimps [mnat])));
   266 by (ALLGOALS (asm_simp_tac (arith_ss addsimps [mnat])));
   309 
   323 
   310 (*Main Result.*)
   324 (*Main Result.*)
   311 goal Arith.thy
   325 goal Arith.thy
   312     "!!m n. [| 0<n;  m:nat;  n:nat |] ==> (m div n)#*n #+ m mod n = m";
   326     "!!m n. [| 0<n;  m:nat;  n:nat |] ==> (m div n)#*n #+ m mod n = m";
   313 by (etac complete_induct 1);
   327 by (etac complete_induct 1);
   314 by (res_inst_tac [("Q","x<n")] (excluded_middle RS disjE) 1);
   328 by (excluded_middle_tac "x<n" 1);
   315 (*case x<n*)
   329 (*case x<n*)
   316 by (asm_simp_tac (arith_ss addsimps [mod_less, div_less]) 2);
   330 by (asm_simp_tac (arith_ss addsimps [mod_less, div_less]) 2);
   317 (*case n le x*)
   331 (*case n le x*)
   318 by (asm_full_simp_tac
   332 by (asm_full_simp_tac
   319      (arith_ss addsimps [not_lt_iff_le, nat_into_Ord,
   333      (arith_ss addsimps [not_lt_iff_le, nat_into_Ord,