src/HOL/Computational_Algebra/Formal_Power_Series.thy
changeset 69085 9999d7823b8f
parent 69064 5840724b1d71
child 69260 0a9688695a1b
equal deleted inserted replaced
69084:c7c38c901267 69085:9999d7823b8f
  2256       by auto
  2256       by auto
  2257     from H have xsl: "length xs = k+1"
  2257     from H have xsl: "length xs = k+1"
  2258       by (simp add: natpermute_def)
  2258       by (simp add: natpermute_def)
  2259     from i have i': "i < length (replicate (k+1) 0)"   "i < k+1"
  2259     from i have i': "i < length (replicate (k+1) 0)"   "i < k+1"
  2260       unfolding length_replicate by presburger+
  2260       unfolding length_replicate by presburger+
  2261     have "xs = replicate (k+1) 0 [i := n]"
  2261     have "xs = (replicate (k+1) 0) [i := n]"
  2262     proof (rule nth_equalityI)
  2262     proof (rule nth_equalityI)
  2263       show "length xs = length (replicate (k + 1) 0[i := n])"
  2263       show "length xs = length ((replicate (k + 1) 0)[i := n])"
  2264         by (metis length_list_update length_replicate xsl)
  2264         by (metis length_list_update length_replicate xsl)
  2265       show "xs ! j = replicate (k + 1) 0[i := n] ! j" if "j < length xs" for j
  2265       show "xs ! j = (replicate (k + 1) 0)[i := n] ! j" if "j < length xs" for j
  2266       proof (cases "j = i")
  2266       proof (cases "j = i")
  2267         case True
  2267         case True
  2268         then show ?thesis
  2268         then show ?thesis
  2269           by (metis i'(1) i(2) nth_list_update)
  2269           by (metis i'(1) i(2) nth_list_update)
  2270       next
  2270       next
  2277   qed
  2277   qed
  2278   show "?B \<subseteq> ?A"
  2278   show "?B \<subseteq> ?A"
  2279   proof
  2279   proof
  2280     fix xs
  2280     fix xs
  2281     assume "xs \<in> ?B"
  2281     assume "xs \<in> ?B"
  2282     then obtain i where i: "i \<in> {0..k}" and xs: "xs = replicate (k + 1) 0 [i:=n]"
  2282     then obtain i where i: "i \<in> {0..k}" and xs: "xs = (replicate (k + 1) 0) [i:=n]"
  2283       by auto
  2283       by auto
  2284     have nxs: "n \<in> set xs"
  2284     have nxs: "n \<in> set xs"
  2285       unfolding xs
  2285       unfolding xs
  2286       apply (rule set_update_memI)
  2286       apply (rule set_update_memI)
  2287       using i apply simp
  2287       using i apply simp
  2290       by (simp only: xs length_replicate length_list_update)
  2290       by (simp only: xs length_replicate length_list_update)
  2291     have "sum_list xs = sum (nth xs) {0..<k+1}"
  2291     have "sum_list xs = sum (nth xs) {0..<k+1}"
  2292       unfolding sum_list_sum_nth xsl ..
  2292       unfolding sum_list_sum_nth xsl ..
  2293     also have "\<dots> = sum (\<lambda>j. if j = i then n else 0) {0..< k+1}"
  2293     also have "\<dots> = sum (\<lambda>j. if j = i then n else 0) {0..< k+1}"
  2294       by (rule sum.cong) (simp_all add: xs del: replicate.simps)
  2294       by (rule sum.cong) (simp_all add: xs del: replicate.simps)
  2295     also have "\<dots> = n" using i by (simp add: sum.delta)
  2295     also have "\<dots> = n" using i by (simp)
  2296     finally have "xs \<in> natpermute n (k + 1)"
  2296     finally have "xs \<in> natpermute n (k + 1)"
  2297       using xsl unfolding natpermute_def mem_Collect_eq by blast
  2297       using xsl unfolding natpermute_def mem_Collect_eq by blast
  2298     then show "xs \<in> ?A"
  2298     then show "xs \<in> ?A"
  2299       using nxs by blast
  2299       using nxs by blast
  2300   qed
  2300   qed
  2393 lemma natpermute_max_card:
  2393 lemma natpermute_max_card:
  2394   assumes n0: "n \<noteq> 0"
  2394   assumes n0: "n \<noteq> 0"
  2395   shows "card {xs \<in> natpermute n (k + 1). n \<in> set xs} = k + 1"
  2395   shows "card {xs \<in> natpermute n (k + 1). n \<in> set xs} = k + 1"
  2396   unfolding natpermute_contain_maximal
  2396   unfolding natpermute_contain_maximal
  2397 proof -
  2397 proof -
  2398   let ?A = "\<lambda>i. {replicate (k + 1) 0[i := n]}"
  2398   let ?A = "\<lambda>i. {(replicate (k + 1) 0)[i := n]}"
  2399   let ?K = "{0 ..k}"
  2399   let ?K = "{0 ..k}"
  2400   have fK: "finite ?K"
  2400   have fK: "finite ?K"
  2401     by simp
  2401     by simp
  2402   have fAK: "\<forall>i\<in>?K. finite (?A i)"
  2402   have fAK: "\<forall>i\<in>?K. finite (?A i)"
  2403     by auto
  2403     by auto
  2404   have d: "\<forall>i\<in> ?K. \<forall>j\<in> ?K. i \<noteq> j \<longrightarrow>
  2404   have d: "\<forall>i\<in> ?K. \<forall>j\<in> ?K. i \<noteq> j \<longrightarrow>
  2405     {replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
  2405     {(replicate (k + 1) 0)[i := n]} \<inter> {(replicate (k + 1) 0)[j := n]} = {}"
  2406   proof clarify
  2406   proof clarify
  2407     fix i j
  2407     fix i j
  2408     assume i: "i \<in> ?K" and j: "j \<in> ?K" and ij: "i \<noteq> j"
  2408     assume i: "i \<in> ?K" and j: "j \<in> ?K" and ij: "i \<noteq> j"
  2409     have False if eq: "replicate (k+1) 0 [i:=n] = replicate (k+1) 0 [j:= n]"
  2409     have False if eq: "(replicate (k+1) 0)[i:=n] = (replicate (k+1) 0)[j:= n]"
  2410     proof -
  2410     proof -
  2411       have "(replicate (k+1) 0 [i:=n] ! i) = n"
  2411       have "(replicate (k+1) 0) [i:=n] ! i = n"
  2412         using i by (simp del: replicate.simps)
  2412         using i by (simp del: replicate.simps)
  2413       moreover
  2413       moreover
  2414       have "(replicate (k+1) 0 [j:=n] ! i) = 0"
  2414       have "(replicate (k+1) 0) [j:=n] ! i = 0"
  2415         using i ij by (simp del: replicate.simps)
  2415         using i ij by (simp del: replicate.simps)
  2416       ultimately show ?thesis
  2416       ultimately show ?thesis
  2417         using eq n0 by (simp del: replicate.simps)
  2417         using eq n0 by (simp del: replicate.simps)
  2418     qed
  2418     qed
  2419     then show "{replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
  2419     then show "{(replicate (k + 1) 0)[i := n]} \<inter> {(replicate (k + 1) 0)[j := n]} = {}"
  2420       by auto
  2420       by auto
  2421   qed
  2421   qed
  2422   from card_UN_disjoint[OF fK fAK d]
  2422   from card_UN_disjoint[OF fK fAK d]
  2423   show "card (\<Union>i\<in>{0..k}. {replicate (k + 1) 0[i := n]}) = k + 1"
  2423   show "card (\<Union>i\<in>{0..k}. {(replicate (k + 1) 0)[i := n]}) = k + 1"
  2424     by simp
  2424     by simp
  2425 qed
  2425 qed
  2426 
  2426 
  2427 lemma fps_power_Suc_nth:
  2427 lemma fps_power_Suc_nth:
  2428   fixes f :: "'a :: comm_ring_1 fps"
  2428   fixes f :: "'a :: comm_ring_1 fps"
  2710         have "sum ?f ?Pnkn = sum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn"
  2710         have "sum ?f ?Pnkn = sum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn"
  2711         proof (rule sum.cong)
  2711         proof (rule sum.cong)
  2712           fix v assume v: "v \<in> {xs \<in> natpermute n (k + 1). n \<in> set xs}"
  2712           fix v assume v: "v \<in> {xs \<in> natpermute n (k + 1). n \<in> set xs}"
  2713           let ?ths = "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
  2713           let ?ths = "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
  2714             fps_radical r (Suc k) a $ n * r (Suc k) (a $ 0) ^ k"
  2714             fps_radical r (Suc k) a $ n * r (Suc k) (a $ 0) ^ k"
  2715           from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
  2715           from v obtain i where i: "i \<in> {0..k}" "v = (replicate (k+1) 0) [i:= n]"
  2716             unfolding natpermute_contain_maximal by auto
  2716             unfolding natpermute_contain_maximal by auto
  2717           have "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
  2717           have "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
  2718               (\<Prod>j\<in>{0..k}. if j = i then fps_radical r (Suc k) a $ n else r (Suc k) (a$0))"
  2718               (\<Prod>j\<in>{0..k}. if j = i then fps_radical r (Suc k) a $ n else r (Suc k) (a$0))"
  2719             apply (rule prod.cong, simp)
  2719             apply (rule prod.cong, simp)
  2720             using i r0
  2720             using i r0
  2845         have "sum ?g ?Pnkn = sum (\<lambda>v. a $ n * (?r$0)^k) ?Pnkn"
  2845         have "sum ?g ?Pnkn = sum (\<lambda>v. a $ n * (?r$0)^k) ?Pnkn"
  2846         proof (rule sum.cong)
  2846         proof (rule sum.cong)
  2847           fix v
  2847           fix v
  2848           assume v: "v \<in> {xs \<in> natpermute n (Suc k). n \<in> set xs}"
  2848           assume v: "v \<in> {xs \<in> natpermute n (Suc k). n \<in> set xs}"
  2849           let ?ths = "(\<Prod>j\<in>{0..k}. a $ v ! j) = a $ n * (?r$0)^k"
  2849           let ?ths = "(\<Prod>j\<in>{0..k}. a $ v ! j) = a $ n * (?r$0)^k"
  2850           from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
  2850           from v obtain i where i: "i \<in> {0..k}" "v = (replicate (k+1) 0) [i:= n]"
  2851             unfolding Suc_eq_plus1 natpermute_contain_maximal
  2851             unfolding Suc_eq_plus1 natpermute_contain_maximal
  2852             by (auto simp del: replicate.simps)
  2852             by (auto simp del: replicate.simps)
  2853           have "(\<Prod>j\<in>{0..k}. a $ v ! j) = (\<Prod>j\<in>{0..k}. if j = i then a $ n else r (Suc k) (b$0))"
  2853           have "(\<Prod>j\<in>{0..k}. a $ v ! j) = (\<Prod>j\<in>{0..k}. if j = i then a $ n else r (Suc k) (b$0))"
  2854             apply (rule prod.cong, simp)
  2854             apply (rule prod.cong, simp)
  2855             using i a0
  2855             using i a0