src/HOL/Algebra/poly/UnivPoly2.thy
changeset 32960 69916a850301
parent 32456 341c83339aeb
child 33657 a4179bf442d1
equal deleted inserted replaced
32959:23a8c5ac35f8 32960:69916a850301
    98 
    98 
    99 instantiation up :: ("{plus, zero}") plus
    99 instantiation up :: ("{plus, zero}") plus
   100 begin
   100 begin
   101 
   101 
   102 definition
   102 definition
   103   up_add_def:	"p + q = Abs_UP (%n. Rep_UP p n + Rep_UP q n)"
   103   up_add_def: "p + q = Abs_UP (%n. Rep_UP p n + Rep_UP q n)"
   104 
   104 
   105 instance ..
   105 instance ..
   106 
   106 
   107 end
   107 end
   108 
   108 
   131 instantiation up :: ("{times, comm_monoid_add}") times
   131 instantiation up :: ("{times, comm_monoid_add}") times
   132 begin
   132 begin
   133 
   133 
   134 definition
   134 definition
   135   up_mult_def:  "p * q = Abs_UP (%n::nat. setsum
   135   up_mult_def:  "p * q = Abs_UP (%n::nat. setsum
   136 		     (%i. Rep_UP p i * Rep_UP q (n-i)) {..n})"
   136                      (%i. Rep_UP p i * Rep_UP q (n-i)) {..n})"
   137 
   137 
   138 instance ..
   138 instance ..
   139 
   139 
   140 end
   140 end
   141 
   141 
   199     fix f g
   199     fix f g
   200     assume fup: "(f::nat=>'a::ring) : UP" and gup: "(g::nat=>'a::ring) : UP"
   200     assume fup: "(f::nat=>'a::ring) : UP" and gup: "(g::nat=>'a::ring) : UP"
   201     have "(%i. f i + g i) : UP"
   201     have "(%i. f i + g i) : UP"
   202     proof -
   202     proof -
   203       from fup obtain n where boundn: "bound n f"
   203       from fup obtain n where boundn: "bound n f"
   204 	by (unfold UP_def) fast
   204         by (unfold UP_def) fast
   205       from gup obtain m where boundm: "bound m g"
   205       from gup obtain m where boundm: "bound m g"
   206 	by (unfold UP_def) fast
   206         by (unfold UP_def) fast
   207       have "bound (max n m) (%i. (f i + g i))"
   207       have "bound (max n m) (%i. (f i + g i))"
   208       proof
   208       proof
   209 	fix i
   209         fix i
   210 	assume "max n m < i"
   210         assume "max n m < i"
   211 	with boundn and boundm show "f i + g i = 0"
   211         with boundn and boundm show "f i + g i = 0"
   212           by (fastsimp simp add: algebra_simps)
   212           by (fastsimp simp add: algebra_simps)
   213       qed
   213       qed
   214       then show "(%i. (f i + g i)) : UP"
   214       then show "(%i. (f i + g i)) : UP"
   215 	by (unfold UP_def) fast
   215         by (unfold UP_def) fast
   216     qed
   216     qed
   217   }
   217   }
   218   then show ?thesis
   218   then show ?thesis
   219     by (simp add: coeff_def up_add_def Abs_UP_inverse Rep_UP)
   219     by (simp add: coeff_def up_add_def Abs_UP_inverse Rep_UP)
   220 qed
   220 qed
   226     fix f g
   226     fix f g
   227     assume fup: "(f::nat=>'a::ring) : UP" and gup: "(g::nat=>'a::ring) : UP"
   227     assume fup: "(f::nat=>'a::ring) : UP" and gup: "(g::nat=>'a::ring) : UP"
   228     have "(%n. setsum (%i. f i * g (n-i)) {..n}) : UP"
   228     have "(%n. setsum (%i. f i * g (n-i)) {..n}) : UP"
   229     proof -
   229     proof -
   230       from fup obtain n where "bound n f"
   230       from fup obtain n where "bound n f"
   231 	by (unfold UP_def) fast
   231         by (unfold UP_def) fast
   232       from gup obtain m where "bound m g"
   232       from gup obtain m where "bound m g"
   233 	by (unfold UP_def) fast
   233         by (unfold UP_def) fast
   234       have "bound (n + m) (%n. setsum (%i. f i * g (n-i)) {..n})"
   234       have "bound (n + m) (%n. setsum (%i. f i * g (n-i)) {..n})"
   235       proof
   235       proof
   236 	fix k
   236         fix k
   237 	assume bound: "n + m < k"
   237         assume bound: "n + m < k"
   238 	{
   238         {
   239 	  fix i
   239           fix i
   240 	  have "f i * g (k-i) = 0"
   240           have "f i * g (k-i) = 0"
   241 	  proof cases
   241           proof cases
   242 	    assume "n < i"
   242             assume "n < i"
   243 	    with `bound n f` show ?thesis by (auto simp add: algebra_simps)
   243             with `bound n f` show ?thesis by (auto simp add: algebra_simps)
   244 	  next
   244           next
   245 	    assume "~ (n < i)"
   245             assume "~ (n < i)"
   246 	    with bound have "m < k-i" by arith
   246             with bound have "m < k-i" by arith
   247 	    with `bound m g` show ?thesis by (auto simp add: algebra_simps)
   247             with `bound m g` show ?thesis by (auto simp add: algebra_simps)
   248 	  qed
   248           qed
   249 	}
   249         }
   250 	then show "setsum (%i. f i * g (k-i)) {..k} = 0"
   250         then show "setsum (%i. f i * g (k-i)) {..k} = 0"
   251 	  by (simp add: algebra_simps)
   251           by (simp add: algebra_simps)
   252       qed
   252       qed
   253       then show "(%n. setsum (%i. f i * g (n-i)) {..n}) : UP"
   253       then show "(%n. setsum (%i. f i * g (n-i)) {..n}) : UP"
   254 	by (unfold UP_def) fast
   254         by (unfold UP_def) fast
   255     qed
   255     qed
   256   }
   256   }
   257   then show ?thesis
   257   then show ?thesis
   258     by (simp add: coeff_def up_mult_def Abs_UP_inverse Rep_UP)
   258     by (simp add: coeff_def up_mult_def Abs_UP_inverse Rep_UP)
   259 qed
   259 qed
   288   proof (rule up_eqI)
   288   proof (rule up_eqI)
   289     fix n 
   289     fix n 
   290     {
   290     {
   291       fix k and a b c :: "nat=>'a::ring"
   291       fix k and a b c :: "nat=>'a::ring"
   292       have "k <= n ==> 
   292       have "k <= n ==> 
   293 	setsum (%j. setsum (%i. a i * b (j-i)) {..j} * c (n-j)) {..k} = 
   293         setsum (%j. setsum (%i. a i * b (j-i)) {..j} * c (n-j)) {..k} = 
   294 	setsum (%j. a j * setsum  (%i. b i * c (n-j-i)) {..k-j}) {..k}"
   294         setsum (%j. a j * setsum  (%i. b i * c (n-j-i)) {..k-j}) {..k}"
   295 	(is "_ ==> ?eq k")
   295         (is "_ ==> ?eq k")
   296       proof (induct k)
   296       proof (induct k)
   297 	case 0 show ?case by simp
   297         case 0 show ?case by simp
   298       next
   298       next
   299 	case (Suc k)
   299         case (Suc k)
   300 	then have "k <= n" by arith
   300         then have "k <= n" by arith
   301 	then have "?eq k" by (rule Suc)
   301         then have "?eq k" by (rule Suc)
   302 	then show ?case
   302         then show ?case
   303 	  by (simp add: Suc_diff_le natsum_ldistr)
   303           by (simp add: Suc_diff_le natsum_ldistr)
   304       qed
   304       qed
   305     }
   305     }
   306     then show "coeff ((p * q) * r) n = coeff (p * (q * r)) n"
   306     then show "coeff ((p * q) * r) n = coeff (p * (q * r)) n"
   307       by simp
   307       by simp
   308   qed
   308   qed
   324     fix n 
   324     fix n 
   325     {
   325     {
   326       fix k
   326       fix k
   327       fix a b :: "nat=>'a::ring"
   327       fix a b :: "nat=>'a::ring"
   328       have "k <= n ==> 
   328       have "k <= n ==> 
   329 	setsum (%i. a i * b (n-i)) {..k} =
   329         setsum (%i. a i * b (n-i)) {..k} =
   330 	setsum (%i. a (k-i) * b (i+n-k)) {..k}"
   330         setsum (%i. a (k-i) * b (i+n-k)) {..k}"
   331 	(is "_ ==> ?eq k")
   331         (is "_ ==> ?eq k")
   332       proof (induct k)
   332       proof (induct k)
   333 	case 0 show ?case by simp
   333         case 0 show ?case by simp
   334       next
   334       next
   335 	case (Suc k) then show ?case by (subst natsum_Suc2) simp
   335         case (Suc k) then show ?case by (subst natsum_Suc2) simp
   336       qed
   336       qed
   337     }
   337     }
   338     then show "coeff (p * q) n = coeff (q * p) n"
   338     then show "coeff (p * q) n = coeff (q * p) n"
   339       by simp
   339       by simp
   340   qed
   340   qed