src/HOL/Library/Euclidean_Space.thy
changeset 31021 53642251a04f
parent 30960 fec1a04b7220
child 31034 736f521ad036
equal deleted inserted replaced
31020:9999a77590c3 31021:53642251a04f
   250   apply (intro_classes) by vector
   250   apply (intro_classes) by vector
   251 
   251 
   252 fun vector_power :: "('a::{one,times} ^'n) \<Rightarrow> nat \<Rightarrow> 'a^'n" where
   252 fun vector_power :: "('a::{one,times} ^'n) \<Rightarrow> nat \<Rightarrow> 'a^'n" where
   253   "vector_power x 0 = 1"
   253   "vector_power x 0 = 1"
   254   | "vector_power x (Suc n) = x * vector_power x n"
   254   | "vector_power x (Suc n) = x * vector_power x n"
   255 
       
   256 instance "^" :: (recpower,type) recpower ..
       
   257 
   255 
   258 instance "^" :: (semiring,type) semiring
   256 instance "^" :: (semiring,type) semiring
   259   apply (intro_classes) by (vector ring_simps)+
   257   apply (intro_classes) by (vector ring_simps)+
   260 
   258 
   261 instance "^" :: (semiring_0,type) semiring_0
   259 instance "^" :: (semiring_0,type) semiring_0
  2755 
  2753 
  2756 (* ------------------------------------------------------------------------- *)
  2754 (* ------------------------------------------------------------------------- *)
  2757 (* Geometric progression.                                                    *)
  2755 (* Geometric progression.                                                    *)
  2758 (* ------------------------------------------------------------------------- *)
  2756 (* ------------------------------------------------------------------------- *)
  2759 
  2757 
  2760 lemma sum_gp_basic: "((1::'a::{field, recpower}) - x) * setsum (\<lambda>i. x^i) {0 .. n} = (1 - x^(Suc n))"
  2758 lemma sum_gp_basic: "((1::'a::{field}) - x) * setsum (\<lambda>i. x^i) {0 .. n} = (1 - x^(Suc n))"
  2761   (is "?lhs = ?rhs")
  2759   (is "?lhs = ?rhs")
  2762 proof-
  2760 proof-
  2763   {assume x1: "x = 1" hence ?thesis by simp}
  2761   {assume x1: "x = 1" hence ?thesis by simp}
  2764   moreover
  2762   moreover
  2765   {assume x1: "x\<noteq>1"
  2763   {assume x1: "x\<noteq>1"
  2773     then have ?thesis by (simp add: ring_simps) }
  2771     then have ?thesis by (simp add: ring_simps) }
  2774   ultimately show ?thesis by metis
  2772   ultimately show ?thesis by metis
  2775 qed
  2773 qed
  2776 
  2774 
  2777 lemma sum_gp_multiplied: assumes mn: "m <= n"
  2775 lemma sum_gp_multiplied: assumes mn: "m <= n"
  2778   shows "((1::'a::{field, recpower}) - x) * setsum (op ^ x) {m..n} = x^m - x^ Suc n"
  2776   shows "((1::'a::{field}) - x) * setsum (op ^ x) {m..n} = x^m - x^ Suc n"
  2779   (is "?lhs = ?rhs")
  2777   (is "?lhs = ?rhs")
  2780 proof-
  2778 proof-
  2781   let ?S = "{0..(n - m)}"
  2779   let ?S = "{0..(n - m)}"
  2782   from mn have mn': "n - m \<ge> 0" by arith
  2780   from mn have mn': "n - m \<ge> 0" by arith
  2783   let ?f = "op + m"
  2781   let ?f = "op + m"
  2790   have "?lhs = x^m * ((1 - x) * setsum (op ^ x) {0..n - m})" by simp
  2788   have "?lhs = x^m * ((1 - x) * setsum (op ^ x) {0..n - m})" by simp
  2791   then show ?thesis unfolding sum_gp_basic using mn
  2789   then show ?thesis unfolding sum_gp_basic using mn
  2792     by (simp add: ring_simps power_add[symmetric])
  2790     by (simp add: ring_simps power_add[symmetric])
  2793 qed
  2791 qed
  2794 
  2792 
  2795 lemma sum_gp: "setsum (op ^ (x::'a::{field, recpower})) {m .. n} =
  2793 lemma sum_gp: "setsum (op ^ (x::'a::{field})) {m .. n} =
  2796    (if n < m then 0 else if x = 1 then of_nat ((n + 1) - m)
  2794    (if n < m then 0 else if x = 1 then of_nat ((n + 1) - m)
  2797                     else (x^ m - x^ (Suc n)) / (1 - x))"
  2795                     else (x^ m - x^ (Suc n)) / (1 - x))"
  2798 proof-
  2796 proof-
  2799   {assume nm: "n < m" hence ?thesis by simp}
  2797   {assume nm: "n < m" hence ?thesis by simp}
  2800   moreover
  2798   moreover
  2806     ultimately have ?thesis by metis
  2804     ultimately have ?thesis by metis
  2807   }
  2805   }
  2808   ultimately show ?thesis by metis
  2806   ultimately show ?thesis by metis
  2809 qed
  2807 qed
  2810 
  2808 
  2811 lemma sum_gp_offset: "setsum (op ^ (x::'a::{field,recpower})) {m .. m+n} =
  2809 lemma sum_gp_offset: "setsum (op ^ (x::'a::{field})) {m .. m+n} =
  2812   (if x = 1 then of_nat n + 1 else x^m * (1 - x^Suc n) / (1 - x))"
  2810   (if x = 1 then of_nat n + 1 else x^m * (1 - x^Suc n) / (1 - x))"
  2813   unfolding sum_gp[of x m "m + n"] power_Suc
  2811   unfolding sum_gp[of x m "m + n"] power_Suc
  2814   by (simp add: ring_simps power_add)
  2812   by (simp add: ring_simps power_add)
  2815 
  2813 
  2816 
  2814