src/HOL/Algebra/abstract/NatSum.ML
changeset 8863 77245f4a71ef
parent 8738 e583d8987abb
child 10962 cda180b1e2e0
equal deleted inserted replaced
8862:78643f8449c6 8863:77245f4a71ef
    35 by (etac rev_mp 1);
    35 by (etac rev_mp 1);
    36 by (res_inst_tac [("P", "%k. k <= n --> SUM k f = SUM k g")] nat_induct 1);
    36 by (res_inst_tac [("P", "%k. k <= n --> SUM k f = SUM k g")] nat_induct 1);
    37 (* Base case *)
    37 (* Base case *)
    38 by (simp_tac (simpset() addsimps [p_context]) 1);
    38 by (simp_tac (simpset() addsimps [p_context]) 1);
    39 (* Induction step *)
    39 (* Induction step *)
    40 by (rtac impI 1);
       
    41 by (etac impE 1);
       
    42 by (rtac Suc_leD 1);
       
    43 by (assume_tac 1);
       
    44 by (asm_simp_tac (simpset() addsimps [p_context]) 1);
    40 by (asm_simp_tac (simpset() addsimps [p_context]) 1);
    45 qed "SUM_cong";
    41 qed "SUM_cong";
    46 
    42 
    47 Addcongs [SUM_cong];
    43 Addcongs [SUM_cong];
    48 
    44 
    84 (* Induction step *)
    80 (* Induction step *)
    85 by (asm_simp_tac (simpset() addsimps [r_distr]) 1);
    81 by (asm_simp_tac (simpset() addsimps [r_distr]) 1);
    86 qed "SUM_rdistr";
    82 qed "SUM_rdistr";
    87 
    83 
    88 section "Results for the Construction of Polynomials";
    84 section "Results for the Construction of Polynomials";
    89 
       
    90 Goal "[| m <= j; Suc j <= n |] ==> (n - m) - Suc (j - m) = n - Suc j";
       
    91 by (asm_simp_tac (simpset() addsplits [nat_diff_split']) 1);
       
    92 qed "Suc_diff_lemma";
       
    93 
    85 
    94 Goal
    86 Goal
    95   "!!a::nat=>'a::ring. k <= n --> \
    87   "!!a::nat=>'a::ring. k <= n --> \
    96 \  SUM k (%j. SUM j (%i. a i * b (j-i)) * c (n-j)) = \
    88 \  SUM k (%j. SUM j (%i. a i * b (j-i)) * c (n-j)) = \
    97 \  SUM k (%j. a j * SUM (k-j) (%i. b i * c (n-j-i)))";
    89 \  SUM k (%j. a j * SUM (k-j) (%i. b i * c (n-j-i)))";
    99 (* Base case *)
    91 (* Base case *)
   100 by (simp_tac (simpset() addsimps [m_assoc]) 1);
    92 by (simp_tac (simpset() addsimps [m_assoc]) 1);
   101 (* Induction step *)
    93 (* Induction step *)
   102 by (rtac impI 1);
    94 by (rtac impI 1);
   103 by (etac impE 1);
    95 by (etac impE 1);
   104 by (rtac Suc_leD 1);
    96 by (arith_tac 1);
   105 by (assume_tac 1);
       
   106 by (asm_simp_tac
    97 by (asm_simp_tac
   107     (simpset() addsimps a_ac@
    98     (simpset() addsimps a_ac@
   108                         [Suc_diff_le, l_distr, r_distr, m_assoc, SUM_add]) 1);
    99                         [Suc_diff_le, l_distr, r_distr, m_assoc, SUM_add]) 1);
   109 by (asm_simp_tac
   100 by (asm_simp_tac (simpset() addsimps a_ac@ [SUM_ldistr, m_assoc]) 1);
   110     (simpset() addsimps a_ac@ [Suc_diff_lemma, SUM_ldistr, m_assoc]) 1);
   101 qed_spec_mp "poly_assoc_lemma1";
   111 qed "poly_assoc_lemma1";
       
   112 
   102 
   113 Goal
   103 Goal
   114   "!!a::nat=>'a::ring. \
   104   "!!a::nat=>'a::ring. \
   115 \  SUM n (%j. SUM j (%i. a i * b (j-i)) * c (n-j)) = \
   105 \  SUM n (%j. SUM j (%i. a i * b (j-i)) * c (n-j)) = \
   116 \  SUM n (%j. a j * SUM (n-j) (%i. b i * c (n-j-i)))";
   106 \  SUM n (%j. a j * SUM (n-j) (%i. b i * c (n-(j+i))))";
   117 by (rtac (poly_assoc_lemma1 RS mp) 1);
   107 by (asm_simp_tac (simpset() addsimps [poly_assoc_lemma1]) 1);
   118 by (rtac le_refl 1);
       
   119 qed "poly_assoc_lemma";
   108 qed "poly_assoc_lemma";
   120 
       
   121 goal Main.thy (* could go to Arith *)
       
   122   "!! n. Suc i <= n ==> Suc (a + (n - Suc i)) = a + (n - i)";
       
   123 by (asm_simp_tac (simpset() delsimps [add_Suc] addsimps [add_Suc_right RS sym, Suc_diff_Suc]) 1);
       
   124 qed "Suc_add_diff_Suc";
       
   125 
       
   126 goal Main.thy (* could go to Arith *)
       
   127   "!! n. [| Suc j <= n; i <= j |] ==> \
       
   128 \    n - Suc i - (n - Suc j) = n - i - (n - j)";
       
   129 by (res_inst_tac [("m1", "n - Suc i"), ("n1", "n - Suc j")]
       
   130   (diff_Suc_Suc RS subst) 1);
       
   131 by (subgoal_tac "Suc i <= n" 1);
       
   132 by (asm_simp_tac (simpset() delsimps [diff_Suc_Suc] addsimps [Suc_diff_Suc]) 1);
       
   133 by (fast_arith_tac 1);
       
   134 qed "diff_lemma2";
       
   135 
   109 
   136 Goal
   110 Goal
   137   "!! a::nat=>'a::ring. j <= n --> \
   111   "!! a::nat=>'a::ring. j <= n --> \
   138 \    SUM j (%i. a i * b (n-i)) = SUM j (%i. a (n-i-(n-j)) * b (i+(n-j)))";
   112 \    SUM j (%i. a i * b (n-i)) = SUM j (%i. a (n-i-(n-j)) * b (i+(n-j)))";
   139 by (induct_tac "j" 1);
   113 by (induct_tac "j" 1);
   140 (* Base case *)
   114 (* Base case *)
   141 by (Simp_tac 1);
   115 by (Simp_tac 1);
   142 (* Induction step *)
   116 (* Induction step *)
   143 by (rtac impI 1);
       
   144 by (etac impE 1);
       
   145 by (rtac Suc_leD 1);
       
   146 by (assume_tac 1);
       
   147 by (stac SUM_Suc2 1);
   117 by (stac SUM_Suc2 1);
   148 by (stac SUM_Suc 1);
   118 by (asm_simp_tac (simpset() addsimps [Suc_diff_Suc, a_comm]) 1);
   149 by (asm_simp_tac (simpset()
       
   150     addsimps [a_comm, Suc_add_diff_Suc, diff_diff_cancel, diff_lemma2]) 1);
       
   151 qed "poly_comm_lemma1";
   119 qed "poly_comm_lemma1";
   152 
   120 
   153 Goal
   121 Goal
   154  "!!a::nat=>'a::ring. SUM n (%i. a i * b (n-i)) = SUM n (%i. a (n-i) * b i)";
   122  "!!a::nat=>'a::ring. SUM n (%i. a i * b (n-i)) = SUM n (%i. a (n-i) * b i)";
   155 by (cut_inst_tac [("j", "n"), ("n", "n")] poly_comm_lemma1 1);
   123 by (cut_inst_tac [("j", "n"), ("n", "n")] poly_comm_lemma1 1);
   178 by (induct_tac "n" 1);
   146 by (induct_tac "n" 1);
   179 (* Base case *)
   147 (* Base case *)
   180 by (Simp_tac 1);
   148 by (Simp_tac 1);
   181 (* Induction step *)
   149 (* Induction step *)
   182 by (case_tac "m <= n" 1);
   150 by (case_tac "m <= n" 1);
   183 by (rtac impI 1);
       
   184 by (etac impE 1);
       
   185 by (Force_tac 1);
       
   186 by (etac conjE 1);
       
   187 by (dres_inst_tac [("x", "Suc n")] spec 1);
       
   188 by Auto_tac;
   151 by Auto_tac;
   189 by (subgoal_tac "m = Suc n" 1);
   152 by (subgoal_tac "m = Suc n" 1);
   190 by (Asm_simp_tac 1);
   153 by (Asm_simp_tac 1);
   191 by (fast_arith_tac 1);
   154 by (fast_arith_tac 1);
   192 val SUM_shrink_lemma = result();
   155 val SUM_shrink_lemma = result();
   235 \    SUM j (%k. SUM (j - k) (%i. f k * g i))";
   198 \    SUM j (%k. SUM (j - k) (%i. f k * g i))";
   236 by (induct_tac "j" 1);
   199 by (induct_tac "j" 1);
   237 (* Base case *)
   200 (* Base case *)
   238 by (Simp_tac 1);
   201 by (Simp_tac 1);
   239 (* Induction step *)
   202 (* Induction step *)
   240 by (simp_tac (simpset() addsimps [Suc_diff_le]) 1);
   203 by (simp_tac (simpset() addsimps [Suc_diff_le, SUM_add]) 1);
   241 by (simp_tac (simpset() addsimps [SUM_add]) 1);
       
   242 by (rtac impI 1);
       
   243 by (etac impE 1);
       
   244 by (dtac Suc_leD 1);
       
   245 by (assume_tac 1);
       
   246 by (asm_simp_tac (simpset() addsimps a_ac) 1);
   204 by (asm_simp_tac (simpset() addsimps a_ac) 1);
   247 val DiagSum_lemma = result();
   205 val DiagSum_lemma = result();
   248 
   206 
   249 Goal
   207 Goal
   250   "!!f::nat=>'a::ring. \
   208   "!!f::nat=>'a::ring. \