| author | wenzelm |
| Mon, 16 Dec 2024 22:53:31 +0100 | |
| changeset 81614 | afd27db5a15b |
| parent 81182 | fc5066122e68 |
| child 82187 | cddce3a4ef84 |
| permissions | -rw-r--r-- |
| 65435 | 1 |
(* Title: HOL/Computational_Algebra/Polynomial.thy |
| 29451 | 2 |
Author: Brian Huffman |
| 41959 | 3 |
Author: Clemens Ballarin |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4 |
Author: Amine Chaieb |
| 52380 | 5 |
Author: Florian Haftmann |
| 29451 | 6 |
*) |
7 |
||
| 60500 | 8 |
section \<open>Polynomials as type over a ring structure\<close> |
| 29451 | 9 |
|
10 |
theory Polynomial |
|
| 65417 | 11 |
imports |
|
68534
914e1bc7369a
Now based on Complex_Main, not HOL.Deriv
paulson <lp15@cam.ac.uk>
parents:
68532
diff
changeset
|
12 |
Complex_Main |
|
66453
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents:
65811
diff
changeset
|
13 |
"HOL-Library.More_List" |
|
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents:
65811
diff
changeset
|
14 |
"HOL-Library.Infinite_Set" |
|
80084
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
15 |
Primes |
| 29451 | 16 |
begin |
17 |
||
| 76207 | 18 |
context semidom_modulo |
19 |
begin |
|
20 |
||
21 |
lemma not_dvd_imp_mod_neq_0: |
|
22 |
\<open>a mod b \<noteq> 0\<close> if \<open>\<not> b dvd a\<close> |
|
23 |
using that mod_0_imp_dvd [of a b] by blast |
|
24 |
||
25 |
end |
|
26 |
||
| 60500 | 27 |
subsection \<open>Auxiliary: operations for lists (later) representing coefficients\<close> |
| 52380 | 28 |
|
|
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80786
diff
changeset
|
29 |
definition cCons :: "'a::zero \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixr \<open>##\<close> 65) |
| 65346 | 30 |
where "x ## xs = (if xs = [] \<and> x = 0 then [] else x # xs)" |
31 |
||
32 |
lemma cCons_0_Nil_eq [simp]: "0 ## [] = []" |
|
| 52380 | 33 |
by (simp add: cCons_def) |
34 |
||
| 65346 | 35 |
lemma cCons_Cons_eq [simp]: "x ## y # ys = x # y # ys" |
| 52380 | 36 |
by (simp add: cCons_def) |
37 |
||
| 65346 | 38 |
lemma cCons_append_Cons_eq [simp]: "x ## xs @ y # ys = x # xs @ y # ys" |
| 52380 | 39 |
by (simp add: cCons_def) |
40 |
||
| 65346 | 41 |
lemma cCons_not_0_eq [simp]: "x \<noteq> 0 \<Longrightarrow> x ## xs = x # xs" |
| 52380 | 42 |
by (simp add: cCons_def) |
43 |
||
44 |
lemma strip_while_not_0_Cons_eq [simp]: |
|
45 |
"strip_while (\<lambda>x. x = 0) (x # xs) = x ## strip_while (\<lambda>x. x = 0) xs" |
|
46 |
proof (cases "x = 0") |
|
| 65346 | 47 |
case False |
48 |
then show ?thesis by simp |
|
| 52380 | 49 |
next |
| 65346 | 50 |
case True |
51 |
show ?thesis |
|
| 52380 | 52 |
proof (induct xs rule: rev_induct) |
| 65346 | 53 |
case Nil |
54 |
with True show ?case by simp |
|
| 52380 | 55 |
next |
| 65346 | 56 |
case (snoc y ys) |
57 |
then show ?case |
|
| 52380 | 58 |
by (cases "y = 0") (simp_all add: append_Cons [symmetric] del: append_Cons) |
59 |
qed |
|
60 |
qed |
|
61 |
||
| 65346 | 62 |
lemma tl_cCons [simp]: "tl (x ## xs) = xs" |
| 52380 | 63 |
by (simp add: cCons_def) |
64 |
||
| 65346 | 65 |
|
| 61585 | 66 |
subsection \<open>Definition of type \<open>poly\<close>\<close> |
| 29451 | 67 |
|
| 61260 | 68 |
typedef (overloaded) 'a poly = "{f :: nat \<Rightarrow> 'a::zero. \<forall>\<^sub>\<infinity> n. f n = 0}"
|
| 63433 | 69 |
morphisms coeff Abs_poly |
70 |
by (auto intro!: ALL_MOST) |
|
| 29451 | 71 |
|
|
59487
adaa430fc0f7
default abstypes and default abstract equations make technical (no_code) annotation superfluous
haftmann
parents:
58881
diff
changeset
|
72 |
setup_lifting type_definition_poly |
| 52380 | 73 |
|
74 |
lemma poly_eq_iff: "p = q \<longleftrightarrow> (\<forall>n. coeff p n = coeff q n)" |
|
|
45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45605
diff
changeset
|
75 |
by (simp add: coeff_inject [symmetric] fun_eq_iff) |
| 29451 | 76 |
|
| 52380 | 77 |
lemma poly_eqI: "(\<And>n. coeff p n = coeff q n) \<Longrightarrow> p = q" |
78 |
by (simp add: poly_eq_iff) |
|
79 |
||
|
59983
cd2efd7d06bd
replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents:
59815
diff
changeset
|
80 |
lemma MOST_coeff_eq_0: "\<forall>\<^sub>\<infinity> n. coeff p n = 0" |
| 52380 | 81 |
using coeff [of p] by simp |
| 29451 | 82 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
83 |
lemma coeff_Abs_poly: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
84 |
assumes "\<And>i. i > n \<Longrightarrow> f i = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
85 |
shows "coeff (Abs_poly f) = f" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
86 |
proof (rule Abs_poly_inverse, clarify) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
87 |
have "eventually (\<lambda>i. i > n) cofinite" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
88 |
by (auto simp: MOST_nat) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
89 |
thus "eventually (\<lambda>i. f i = 0) cofinite" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
90 |
by eventually_elim (use assms in auto) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
91 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
92 |
|
| 29451 | 93 |
|
| 60500 | 94 |
subsection \<open>Degree of a polynomial\<close> |
| 29451 | 95 |
|
| 52380 | 96 |
definition degree :: "'a::zero poly \<Rightarrow> nat" |
| 65346 | 97 |
where "degree p = (LEAST n. \<forall>i>n. coeff p i = 0)" |
| 29451 | 98 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
99 |
lemma degree_cong: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
100 |
assumes "\<And>i. coeff p i = 0 \<longleftrightarrow> coeff q i = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
101 |
shows "degree p = degree q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
102 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
103 |
have "(\<lambda>n. \<forall>i>n. poly.coeff p i = 0) = (\<lambda>n. \<forall>i>n. poly.coeff q i = 0)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
104 |
using assms by (auto simp: fun_eq_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
105 |
thus ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
106 |
by (simp only: degree_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
107 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
108 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
109 |
lemma coeff_Abs_poly_If_le: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
110 |
"coeff (Abs_poly (\<lambda>i. if i \<le> n then f i else 0)) = (\<lambda>i. if i \<le> n then f i else 0)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
111 |
proof (rule Abs_poly_inverse, clarify) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
112 |
have "eventually (\<lambda>i. i > n) cofinite" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
113 |
by (auto simp: MOST_nat) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
114 |
thus "eventually (\<lambda>i. (if i \<le> n then f i else 0) = 0) cofinite" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
115 |
by eventually_elim auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
116 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
117 |
|
| 52380 | 118 |
lemma coeff_eq_0: |
119 |
assumes "degree p < n" |
|
120 |
shows "coeff p n = 0" |
|
| 29451 | 121 |
proof - |
|
59983
cd2efd7d06bd
replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents:
59815
diff
changeset
|
122 |
have "\<exists>n. \<forall>i>n. coeff p i = 0" |
|
cd2efd7d06bd
replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents:
59815
diff
changeset
|
123 |
using MOST_coeff_eq_0 by (simp add: MOST_nat) |
| 52380 | 124 |
then have "\<forall>i>degree p. coeff p i = 0" |
| 29451 | 125 |
unfolding degree_def by (rule LeastI_ex) |
| 52380 | 126 |
with assms show ?thesis by simp |
| 29451 | 127 |
qed |
128 |
||
129 |
lemma le_degree: "coeff p n \<noteq> 0 \<Longrightarrow> n \<le> degree p" |
|
130 |
by (erule contrapos_np, rule coeff_eq_0, simp) |
|
131 |
||
132 |
lemma degree_le: "\<forall>i>n. coeff p i = 0 \<Longrightarrow> degree p \<le> n" |
|
133 |
unfolding degree_def by (erule Least_le) |
|
134 |
||
135 |
lemma less_degree_imp: "n < degree p \<Longrightarrow> \<exists>i>n. coeff p i \<noteq> 0" |
|
136 |
unfolding degree_def by (drule not_less_Least, simp) |
|
137 |
||
138 |
||
| 60500 | 139 |
subsection \<open>The zero polynomial\<close> |
| 29451 | 140 |
|
141 |
instantiation poly :: (zero) zero |
|
142 |
begin |
|
143 |
||
| 52380 | 144 |
lift_definition zero_poly :: "'a poly" |
| 65390 | 145 |
is "\<lambda>_. 0" |
146 |
by (rule MOST_I) simp |
|
| 29451 | 147 |
|
148 |
instance .. |
|
| 52380 | 149 |
|
| 29451 | 150 |
end |
151 |
||
| 65346 | 152 |
lemma coeff_0 [simp]: "coeff 0 n = 0" |
| 52380 | 153 |
by transfer rule |
| 29451 | 154 |
|
| 65346 | 155 |
lemma degree_0 [simp]: "degree 0 = 0" |
| 29451 | 156 |
by (rule order_antisym [OF degree_le le0]) simp |
157 |
||
158 |
lemma leading_coeff_neq_0: |
|
| 52380 | 159 |
assumes "p \<noteq> 0" |
160 |
shows "coeff p (degree p) \<noteq> 0" |
|
| 29451 | 161 |
proof (cases "degree p") |
162 |
case 0 |
|
| 65346 | 163 |
from \<open>p \<noteq> 0\<close> obtain n where "coeff p n \<noteq> 0" |
164 |
by (auto simp add: poly_eq_iff) |
|
165 |
then have "n \<le> degree p" |
|
166 |
by (rule le_degree) |
|
167 |
with \<open>coeff p n \<noteq> 0\<close> and \<open>degree p = 0\<close> show "coeff p (degree p) \<noteq> 0" |
|
168 |
by simp |
|
| 29451 | 169 |
next |
170 |
case (Suc n) |
|
| 65346 | 171 |
from \<open>degree p = Suc n\<close> have "n < degree p" |
172 |
by simp |
|
173 |
then have "\<exists>i>n. coeff p i \<noteq> 0" |
|
174 |
by (rule less_degree_imp) |
|
175 |
then obtain i where "n < i" and "coeff p i \<noteq> 0" |
|
176 |
by blast |
|
177 |
from \<open>degree p = Suc n\<close> and \<open>n < i\<close> have "degree p \<le> i" |
|
178 |
by simp |
|
179 |
also from \<open>coeff p i \<noteq> 0\<close> have "i \<le> degree p" |
|
180 |
by (rule le_degree) |
|
| 29451 | 181 |
finally have "degree p = i" . |
| 60500 | 182 |
with \<open>coeff p i \<noteq> 0\<close> show "coeff p (degree p) \<noteq> 0" by simp |
| 29451 | 183 |
qed |
184 |
||
| 65346 | 185 |
lemma leading_coeff_0_iff [simp]: "coeff p (degree p) = 0 \<longleftrightarrow> p = 0" |
186 |
by (cases "p = 0") (simp_all add: leading_coeff_neq_0) |
|
| 29451 | 187 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
188 |
lemma degree_lessI: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
189 |
assumes "p \<noteq> 0 \<or> n > 0" "\<forall>k\<ge>n. coeff p k = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
190 |
shows "degree p < n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
191 |
proof (cases "p = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
192 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
193 |
show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
194 |
proof (rule ccontr) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
195 |
assume *: "\<not>(degree p < n)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
196 |
define d where "d = degree p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
197 |
from \<open>p \<noteq> 0\<close> have "coeff p d \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
198 |
by (auto simp: d_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
199 |
moreover have "coeff p d = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
200 |
using assms(2) * by (auto simp: not_less) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
201 |
ultimately show False by contradiction |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
202 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
203 |
qed (use assms in auto) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
204 |
|
| 76207 | 205 |
lemma eq_zero_or_degree_less: |
| 64795 | 206 |
assumes "degree p \<le> n" and "coeff p n = 0" |
207 |
shows "p = 0 \<or> degree p < n" |
|
208 |
proof (cases n) |
|
209 |
case 0 |
|
| 65346 | 210 |
with \<open>degree p \<le> n\<close> and \<open>coeff p n = 0\<close> have "coeff p (degree p) = 0" |
211 |
by simp |
|
| 64795 | 212 |
then have "p = 0" by simp |
213 |
then show ?thesis .. |
|
214 |
next |
|
215 |
case (Suc m) |
|
| 65346 | 216 |
from \<open>degree p \<le> n\<close> have "\<forall>i>n. coeff p i = 0" |
217 |
by (simp add: coeff_eq_0) |
|
218 |
with \<open>coeff p n = 0\<close> have "\<forall>i\<ge>n. coeff p i = 0" |
|
219 |
by (simp add: le_less) |
|
220 |
with \<open>n = Suc m\<close> have "\<forall>i>m. coeff p i = 0" |
|
221 |
by (simp add: less_eq_Suc_le) |
|
| 64795 | 222 |
then have "degree p \<le> m" |
223 |
by (rule degree_le) |
|
| 65346 | 224 |
with \<open>n = Suc m\<close> have "degree p < n" |
225 |
by (simp add: less_Suc_eq_le) |
|
| 64795 | 226 |
then show ?thesis .. |
227 |
qed |
|
228 |
||
229 |
lemma coeff_0_degree_minus_1: "coeff rrr dr = 0 \<Longrightarrow> degree rrr \<le> dr \<Longrightarrow> degree rrr \<le> dr - 1" |
|
230 |
using eq_zero_or_degree_less by fastforce |
|
231 |
||
| 29451 | 232 |
|
| 60500 | 233 |
subsection \<open>List-style constructor for polynomials\<close> |
| 29451 | 234 |
|
| 52380 | 235 |
lift_definition pCons :: "'a::zero \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
| 55415 | 236 |
is "\<lambda>a p. case_nat a (coeff p)" |
|
59983
cd2efd7d06bd
replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents:
59815
diff
changeset
|
237 |
by (rule MOST_SucD) (simp add: MOST_coeff_eq_0) |
| 29451 | 238 |
|
| 52380 | 239 |
lemmas coeff_pCons = pCons.rep_eq |
| 29455 | 240 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
241 |
lemma coeff_pCons': "poly.coeff (pCons c p) n = (if n = 0 then c else poly.coeff p (n - 1))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
242 |
by transfer'(auto split: nat.splits) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
243 |
|
| 65346 | 244 |
lemma coeff_pCons_0 [simp]: "coeff (pCons a p) 0 = a" |
| 52380 | 245 |
by transfer simp |
| 29455 | 246 |
|
| 65346 | 247 |
lemma coeff_pCons_Suc [simp]: "coeff (pCons a p) (Suc n) = coeff p n" |
| 29451 | 248 |
by (simp add: coeff_pCons) |
249 |
||
| 65346 | 250 |
lemma degree_pCons_le: "degree (pCons a p) \<le> Suc (degree p)" |
| 52380 | 251 |
by (rule degree_le) (simp add: coeff_eq_0 coeff_pCons split: nat.split) |
| 29451 | 252 |
|
| 65346 | 253 |
lemma degree_pCons_eq: "p \<noteq> 0 \<Longrightarrow> degree (pCons a p) = Suc (degree p)" |
| 72750 | 254 |
by (simp add: degree_pCons_le le_antisym le_degree) |
| 29451 | 255 |
|
| 65346 | 256 |
lemma degree_pCons_0: "degree (pCons a 0) = 0" |
| 72750 | 257 |
proof - |
258 |
have "degree (pCons a 0) \<le> Suc 0" |
|
259 |
by (metis (no_types) degree_0 degree_pCons_le) |
|
260 |
then show ?thesis |
|
261 |
by (metis coeff_0 coeff_pCons_Suc degree_0 eq_zero_or_degree_less less_Suc0) |
|
262 |
qed |
|
| 29451 | 263 |
|
| 65346 | 264 |
lemma degree_pCons_eq_if [simp]: "degree (pCons a p) = (if p = 0 then 0 else Suc (degree p))" |
| 72750 | 265 |
by (simp add: degree_pCons_0 degree_pCons_eq) |
| 29451 | 266 |
|
| 65346 | 267 |
lemma pCons_0_0 [simp]: "pCons 0 0 = 0" |
| 52380 | 268 |
by (rule poly_eqI) (simp add: coeff_pCons split: nat.split) |
| 29451 | 269 |
|
| 65346 | 270 |
lemma pCons_eq_iff [simp]: "pCons a p = pCons b q \<longleftrightarrow> a = b \<and> p = q" |
| 52380 | 271 |
proof safe |
| 29451 | 272 |
assume "pCons a p = pCons b q" |
| 65346 | 273 |
then have "coeff (pCons a p) 0 = coeff (pCons b q) 0" |
274 |
by simp |
|
275 |
then show "a = b" |
|
276 |
by simp |
|
| 29451 | 277 |
next |
278 |
assume "pCons a p = pCons b q" |
|
| 65346 | 279 |
then have "coeff (pCons a p) (Suc n) = coeff (pCons b q) (Suc n)" for n |
280 |
by simp |
|
281 |
then show "p = q" |
|
282 |
by (simp add: poly_eq_iff) |
|
| 29451 | 283 |
qed |
284 |
||
| 65346 | 285 |
lemma pCons_eq_0_iff [simp]: "pCons a p = 0 \<longleftrightarrow> a = 0 \<and> p = 0" |
| 29451 | 286 |
using pCons_eq_iff [of a p 0 0] by simp |
287 |
||
288 |
lemma pCons_cases [cases type: poly]: |
|
289 |
obtains (pCons) a q where "p = pCons a q" |
|
290 |
proof |
|
291 |
show "p = pCons (coeff p 0) (Abs_poly (\<lambda>n. coeff p (Suc n)))" |
|
| 52380 | 292 |
by transfer |
| 65346 | 293 |
(simp_all add: MOST_inj[where f=Suc and P="\<lambda>n. p n = 0" for p] fun_eq_iff Abs_poly_inverse |
294 |
split: nat.split) |
|
| 29451 | 295 |
qed |
296 |
||
297 |
lemma pCons_induct [case_names 0 pCons, induct type: poly]: |
|
298 |
assumes zero: "P 0" |
|
| 54856 | 299 |
assumes pCons: "\<And>a p. a \<noteq> 0 \<or> p \<noteq> 0 \<Longrightarrow> P p \<Longrightarrow> P (pCons a p)" |
| 29451 | 300 |
shows "P p" |
301 |
proof (induct p rule: measure_induct_rule [where f=degree]) |
|
302 |
case (less p) |
|
303 |
obtain a q where "p = pCons a q" by (rule pCons_cases) |
|
304 |
have "P q" |
|
305 |
proof (cases "q = 0") |
|
306 |
case True |
|
307 |
then show "P q" by (simp add: zero) |
|
308 |
next |
|
309 |
case False |
|
310 |
then have "degree (pCons a q) = Suc (degree q)" |
|
311 |
by (rule degree_pCons_eq) |
|
| 65346 | 312 |
with \<open>p = pCons a q\<close> have "degree q < degree p" |
313 |
by simp |
|
| 29451 | 314 |
then show "P q" |
315 |
by (rule less.hyps) |
|
316 |
qed |
|
| 54856 | 317 |
have "P (pCons a q)" |
318 |
proof (cases "a \<noteq> 0 \<or> q \<noteq> 0") |
|
319 |
case True |
|
| 60500 | 320 |
with \<open>P q\<close> show ?thesis by (auto intro: pCons) |
| 54856 | 321 |
next |
322 |
case False |
|
323 |
with zero show ?thesis by simp |
|
324 |
qed |
|
| 65346 | 325 |
with \<open>p = pCons a q\<close> show ?case |
326 |
by simp |
|
| 29451 | 327 |
qed |
328 |
||
| 60570 | 329 |
lemma degree_eq_zeroE: |
330 |
fixes p :: "'a::zero poly" |
|
331 |
assumes "degree p = 0" |
|
332 |
obtains a where "p = pCons a 0" |
|
333 |
proof - |
|
| 65346 | 334 |
obtain a q where p: "p = pCons a q" |
335 |
by (cases p) |
|
336 |
with assms have "q = 0" |
|
337 |
by (cases "q = 0") simp_all |
|
338 |
with p have "p = pCons a 0" |
|
339 |
by simp |
|
340 |
then show thesis .. |
|
| 60570 | 341 |
qed |
342 |
||
| 29451 | 343 |
|
| 62422 | 344 |
subsection \<open>Quickcheck generator for polynomials\<close> |
345 |
||
346 |
quickcheck_generator poly constructors: "0 :: _ poly", pCons |
|
347 |
||
348 |
||
| 60500 | 349 |
subsection \<open>List-style syntax for polynomials\<close> |
| 52380 | 350 |
|
|
80786
70076ba563d2
more specific "args" syntax, to support more markup for syntax consts;
wenzelm
parents:
80084
diff
changeset
|
351 |
syntax |
| 81090 | 352 |
"_poly" :: "args \<Rightarrow> 'a poly" (\<open>(\<open>indent=2 notation=\<open>mixfix polynomial enumeration\<close>\<close>[:_:])\<close>) |
| 81182 | 353 |
syntax_consts |
354 |
"_poly" \<rightleftharpoons> pCons |
|
| 52380 | 355 |
translations |
| 65346 | 356 |
"[:x, xs:]" \<rightleftharpoons> "CONST pCons x [:xs:]" |
357 |
"[:x:]" \<rightleftharpoons> "CONST pCons x 0" |
|
| 52380 | 358 |
|
359 |
||
| 60500 | 360 |
subsection \<open>Representation of polynomials by lists of coefficients\<close> |
| 52380 | 361 |
|
362 |
primrec Poly :: "'a::zero list \<Rightarrow> 'a poly" |
|
| 65346 | 363 |
where |
364 |
[code_post]: "Poly [] = 0" |
|
365 |
| [code_post]: "Poly (a # as) = pCons a (Poly as)" |
|
366 |
||
367 |
lemma Poly_replicate_0 [simp]: "Poly (replicate n 0) = 0" |
|
| 52380 | 368 |
by (induct n) simp_all |
369 |
||
| 65346 | 370 |
lemma Poly_eq_0: "Poly as = 0 \<longleftrightarrow> (\<exists>n. as = replicate n 0)" |
| 52380 | 371 |
by (induct as) (auto simp add: Cons_replicate_eq) |
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
372 |
|
| 65346 | 373 |
lemma Poly_append_replicate_zero [simp]: "Poly (as @ replicate n 0) = Poly as" |
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
374 |
by (induct as) simp_all |
|
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
375 |
|
| 65346 | 376 |
lemma Poly_snoc_zero [simp]: "Poly (as @ [0]) = Poly as" |
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
377 |
using Poly_append_replicate_zero [of as 1] by simp |
|
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
378 |
|
| 65346 | 379 |
lemma Poly_cCons_eq_pCons_Poly [simp]: "Poly (a ## p) = pCons a (Poly p)" |
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
380 |
by (simp add: cCons_def) |
|
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
381 |
|
| 65346 | 382 |
lemma Poly_on_rev_starting_with_0 [simp]: "hd as = 0 \<Longrightarrow> Poly (rev (tl as)) = Poly (rev as)" |
383 |
by (cases as) simp_all |
|
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
384 |
|
| 62065 | 385 |
lemma degree_Poly: "degree (Poly xs) \<le> length xs" |
| 65346 | 386 |
by (induct xs) simp_all |
387 |
||
388 |
lemma coeff_Poly_eq [simp]: "coeff (Poly xs) = nth_default 0 xs" |
|
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
389 |
by (induct xs) (simp_all add: fun_eq_iff coeff_pCons split: nat.splits) |
|
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
390 |
|
| 52380 | 391 |
definition coeffs :: "'a poly \<Rightarrow> 'a::zero list" |
| 65346 | 392 |
where "coeffs p = (if p = 0 then [] else map (\<lambda>i. coeff p i) [0 ..< Suc (degree p)])" |
393 |
||
394 |
lemma coeffs_eq_Nil [simp]: "coeffs p = [] \<longleftrightarrow> p = 0" |
|
| 52380 | 395 |
by (simp add: coeffs_def) |
396 |
||
| 65346 | 397 |
lemma not_0_coeffs_not_Nil: "p \<noteq> 0 \<Longrightarrow> coeffs p \<noteq> []" |
| 52380 | 398 |
by simp |
399 |
||
| 65346 | 400 |
lemma coeffs_0_eq_Nil [simp]: "coeffs 0 = []" |
| 52380 | 401 |
by simp |
|
29454
b0f586f38dd7
add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents:
29453
diff
changeset
|
402 |
|
| 65346 | 403 |
lemma coeffs_pCons_eq_cCons [simp]: "coeffs (pCons a p) = a ## coeffs p" |
| 52380 | 404 |
proof - |
| 65346 | 405 |
have *: "\<forall>m\<in>set ms. m > 0 \<Longrightarrow> map (case_nat x f) ms = map f (map (\<lambda>n. n - 1) ms)" |
406 |
for ms :: "nat list" and f :: "nat \<Rightarrow> 'a" and x :: "'a" |
|
407 |
by (induct ms) (auto split: nat.split) |
|
| 52380 | 408 |
show ?thesis |
| 65346 | 409 |
by (simp add: * coeffs_def upt_conv_Cons coeff_pCons map_decr_upt del: upt_Suc) |
| 52380 | 410 |
qed |
411 |
||
| 62065 | 412 |
lemma length_coeffs: "p \<noteq> 0 \<Longrightarrow> length (coeffs p) = degree p + 1" |
413 |
by (simp add: coeffs_def) |
|
| 64860 | 414 |
|
| 65346 | 415 |
lemma coeffs_nth: "p \<noteq> 0 \<Longrightarrow> n \<le> degree p \<Longrightarrow> coeffs p ! n = coeff p n" |
416 |
by (auto simp: coeffs_def simp del: upt_Suc) |
|
417 |
||
418 |
lemma coeff_in_coeffs: "p \<noteq> 0 \<Longrightarrow> n \<le> degree p \<Longrightarrow> coeff p n \<in> set (coeffs p)" |
|
419 |
using coeffs_nth [of p n, symmetric] by (simp add: length_coeffs) |
|
420 |
||
421 |
lemma not_0_cCons_eq [simp]: "p \<noteq> 0 \<Longrightarrow> a ## coeffs p = a # coeffs p" |
|
| 52380 | 422 |
by (simp add: cCons_def) |
423 |
||
| 65346 | 424 |
lemma Poly_coeffs [simp, code abstype]: "Poly (coeffs p) = p" |
| 54856 | 425 |
by (induct p) auto |
| 52380 | 426 |
|
| 65346 | 427 |
lemma coeffs_Poly [simp]: "coeffs (Poly as) = strip_while (HOL.eq 0) as" |
| 52380 | 428 |
proof (induct as) |
| 65346 | 429 |
case Nil |
430 |
then show ?case by simp |
|
| 52380 | 431 |
next |
432 |
case (Cons a as) |
|
| 65346 | 433 |
from replicate_length_same [of as 0] have "(\<forall>n. as \<noteq> replicate n 0) \<longleftrightarrow> (\<exists>a\<in>set as. a \<noteq> 0)" |
434 |
by (auto dest: sym [of _ as]) |
|
| 52380 | 435 |
with Cons show ?case by auto |
436 |
qed |
|
437 |
||
| 65390 | 438 |
lemma no_trailing_coeffs [simp]: |
439 |
"no_trailing (HOL.eq 0) (coeffs p)" |
|
440 |
by (induct p) auto |
|
441 |
||
442 |
lemma strip_while_coeffs [simp]: |
|
443 |
"strip_while (HOL.eq 0) (coeffs p) = coeffs p" |
|
444 |
by simp |
|
| 52380 | 445 |
|
| 65346 | 446 |
lemma coeffs_eq_iff: "p = q \<longleftrightarrow> coeffs p = coeffs q" |
447 |
(is "?P \<longleftrightarrow> ?Q") |
|
| 52380 | 448 |
proof |
| 65346 | 449 |
assume ?P |
450 |
then show ?Q by simp |
|
| 52380 | 451 |
next |
452 |
assume ?Q |
|
453 |
then have "Poly (coeffs p) = Poly (coeffs q)" by simp |
|
454 |
then show ?P by simp |
|
455 |
qed |
|
456 |
||
| 65346 | 457 |
lemma nth_default_coeffs_eq: "nth_default 0 (coeffs p) = coeff p" |
| 52380 | 458 |
by (simp add: fun_eq_iff coeff_Poly_eq [symmetric]) |
459 |
||
| 65346 | 460 |
lemma [code]: "coeff p = nth_default 0 (coeffs p)" |
| 52380 | 461 |
by (simp add: nth_default_coeffs_eq) |
462 |
||
463 |
lemma coeffs_eqI: |
|
464 |
assumes coeff: "\<And>n. coeff p n = nth_default 0 xs n" |
|
| 65390 | 465 |
assumes zero: "no_trailing (HOL.eq 0) xs" |
| 52380 | 466 |
shows "coeffs p = xs" |
467 |
proof - |
|
| 65390 | 468 |
from coeff have "p = Poly xs" |
469 |
by (simp add: poly_eq_iff) |
|
470 |
with zero show ?thesis by simp |
|
| 52380 | 471 |
qed |
472 |
||
| 65346 | 473 |
lemma degree_eq_length_coeffs [code]: "degree p = length (coeffs p) - 1" |
| 52380 | 474 |
by (simp add: coeffs_def) |
475 |
||
| 65346 | 476 |
lemma length_coeffs_degree: "p \<noteq> 0 \<Longrightarrow> length (coeffs p) = Suc (degree p)" |
477 |
by (induct p) (auto simp: cCons_def) |
|
478 |
||
479 |
lemma [code abstract]: "coeffs 0 = []" |
|
| 52380 | 480 |
by (fact coeffs_0_eq_Nil) |
481 |
||
| 65346 | 482 |
lemma [code abstract]: "coeffs (pCons a p) = a ## coeffs p" |
| 52380 | 483 |
by (fact coeffs_pCons_eq_cCons) |
484 |
||
| 65811 | 485 |
lemma set_coeffs_subset_singleton_0_iff [simp]: |
486 |
"set (coeffs p) \<subseteq> {0} \<longleftrightarrow> p = 0"
|
|
487 |
by (auto simp add: coeffs_def intro: classical) |
|
488 |
||
489 |
lemma set_coeffs_not_only_0 [simp]: |
|
490 |
"set (coeffs p) \<noteq> {0}"
|
|
491 |
by (auto simp add: set_eq_subset) |
|
492 |
||
493 |
lemma forall_coeffs_conv: |
|
494 |
"(\<forall>n. P (coeff p n)) \<longleftrightarrow> (\<forall>c \<in> set (coeffs p). P c)" if "P 0" |
|
495 |
using that by (auto simp add: coeffs_def) |
|
496 |
(metis atLeastLessThan_iff coeff_eq_0 not_less_iff_gr_or_eq zero_le) |
|
497 |
||
| 52380 | 498 |
instantiation poly :: ("{zero, equal}") equal
|
499 |
begin |
|
500 |
||
| 65346 | 501 |
definition [code]: "HOL.equal (p::'a poly) q \<longleftrightarrow> HOL.equal (coeffs p) (coeffs q)" |
| 52380 | 502 |
|
| 60679 | 503 |
instance |
504 |
by standard (simp add: equal equal_poly_def coeffs_eq_iff) |
|
| 52380 | 505 |
|
506 |
end |
|
507 |
||
| 60679 | 508 |
lemma [code nbe]: "HOL.equal (p :: _ poly) p \<longleftrightarrow> True" |
| 52380 | 509 |
by (fact equal_refl) |
|
29454
b0f586f38dd7
add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents:
29453
diff
changeset
|
510 |
|
| 52380 | 511 |
definition is_zero :: "'a::zero poly \<Rightarrow> bool" |
| 65346 | 512 |
where [code]: "is_zero p \<longleftrightarrow> List.null (coeffs p)" |
513 |
||
514 |
lemma is_zero_null [code_abbrev]: "is_zero p \<longleftrightarrow> p = 0" |
|
| 52380 | 515 |
by (simp add: is_zero_def null_def) |
516 |
||
| 65346 | 517 |
|
|
79672
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
518 |
text \<open>Reconstructing the polynomial from the list\<close> |
| 63145 | 519 |
\<comment> \<open>contributed by Sebastiaan J.C. Joosten and René Thiemann\<close> |
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
520 |
|
|
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
521 |
definition poly_of_list :: "'a::comm_monoid_add list \<Rightarrow> 'a poly" |
| 65346 | 522 |
where [simp]: "poly_of_list = Poly" |
523 |
||
524 |
lemma poly_of_list_impl [code abstract]: "coeffs (poly_of_list as) = strip_while (HOL.eq 0) as" |
|
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
525 |
by simp |
|
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
526 |
|
| 52380 | 527 |
|
| 60500 | 528 |
subsection \<open>Fold combinator for polynomials\<close> |
| 52380 | 529 |
|
530 |
definition fold_coeffs :: "('a::zero \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'a poly \<Rightarrow> 'b \<Rightarrow> 'b"
|
|
| 65346 | 531 |
where "fold_coeffs f p = foldr f (coeffs p)" |
532 |
||
533 |
lemma fold_coeffs_0_eq [simp]: "fold_coeffs f 0 = id" |
|
| 52380 | 534 |
by (simp add: fold_coeffs_def) |
535 |
||
| 65346 | 536 |
lemma fold_coeffs_pCons_eq [simp]: "f 0 = id \<Longrightarrow> fold_coeffs f (pCons a p) = f a \<circ> fold_coeffs f p" |
| 52380 | 537 |
by (simp add: fold_coeffs_def cCons_def fun_eq_iff) |
|
29454
b0f586f38dd7
add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents:
29453
diff
changeset
|
538 |
|
| 65346 | 539 |
lemma fold_coeffs_pCons_0_0_eq [simp]: "fold_coeffs f (pCons 0 0) = id" |
| 52380 | 540 |
by (simp add: fold_coeffs_def) |
541 |
||
542 |
lemma fold_coeffs_pCons_coeff_not_0_eq [simp]: |
|
543 |
"a \<noteq> 0 \<Longrightarrow> fold_coeffs f (pCons a p) = f a \<circ> fold_coeffs f p" |
|
544 |
by (simp add: fold_coeffs_def) |
|
545 |
||
546 |
lemma fold_coeffs_pCons_not_0_0_eq [simp]: |
|
547 |
"p \<noteq> 0 \<Longrightarrow> fold_coeffs f (pCons a p) = f a \<circ> fold_coeffs f p" |
|
548 |
by (simp add: fold_coeffs_def) |
|
549 |
||
| 64795 | 550 |
|
| 60500 | 551 |
subsection \<open>Canonical morphism on polynomials -- evaluation\<close> |
| 52380 | 552 |
|
| 72024 | 553 |
definition poly :: \<open>'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a\<close> |
554 |
where \<open>poly p a = horner_sum id a (coeffs p)\<close> |
|
555 |
||
556 |
lemma poly_eq_fold_coeffs: |
|
557 |
\<open>poly p = fold_coeffs (\<lambda>a f x. a + x * f x) p (\<lambda>x. 0)\<close> |
|
558 |
by (induction p) (auto simp add: fun_eq_iff poly_def) |
|
| 65346 | 559 |
|
560 |
lemma poly_0 [simp]: "poly 0 x = 0" |
|
| 52380 | 561 |
by (simp add: poly_def) |
| 65346 | 562 |
|
563 |
lemma poly_pCons [simp]: "poly (pCons a p) x = a + x * poly p x" |
|
| 52380 | 564 |
by (cases "p = 0 \<and> a = 0") (auto simp add: poly_def) |
|
29454
b0f586f38dd7
add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents:
29453
diff
changeset
|
565 |
|
| 65346 | 566 |
lemma poly_altdef: "poly p x = (\<Sum>i\<le>degree p. coeff p i * x ^ i)" |
567 |
for x :: "'a::{comm_semiring_0,semiring_1}"
|
|
| 62065 | 568 |
proof (induction p rule: pCons_induct) |
| 65346 | 569 |
case 0 |
570 |
then show ?case |
|
571 |
by simp |
|
572 |
next |
|
| 62065 | 573 |
case (pCons a p) |
| 65346 | 574 |
show ?case |
575 |
proof (cases "p = 0") |
|
576 |
case True |
|
577 |
then show ?thesis by simp |
|
578 |
next |
|
579 |
case False |
|
580 |
let ?p' = "pCons a p" |
|
581 |
note poly_pCons[of a p x] |
|
582 |
also note pCons.IH |
|
583 |
also have "a + x * (\<Sum>i\<le>degree p. coeff p i * x ^ i) = |
|
584 |
coeff ?p' 0 * x^0 + (\<Sum>i\<le>degree p. coeff ?p' (Suc i) * x^Suc i)" |
|
585 |
by (simp add: field_simps sum_distrib_left coeff_pCons) |
|
|
70113
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
paulson <lp15@cam.ac.uk>
parents:
70097
diff
changeset
|
586 |
also note sum.atMost_Suc_shift[symmetric] |
| 65346 | 587 |
also note degree_pCons_eq[OF \<open>p \<noteq> 0\<close>, of a, symmetric] |
588 |
finally show ?thesis . |
|
589 |
qed |
|
590 |
qed |
|
| 62065 | 591 |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
592 |
lemma poly_0_coeff_0: "poly p 0 = coeff p 0" |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
593 |
by (cases p) (auto simp: poly_altdef) |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
594 |
|
|
29454
b0f586f38dd7
add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents:
29453
diff
changeset
|
595 |
|
| 60500 | 596 |
subsection \<open>Monomials\<close> |
| 29451 | 597 |
|
| 52380 | 598 |
lift_definition monom :: "'a \<Rightarrow> nat \<Rightarrow> 'a::zero poly" |
599 |
is "\<lambda>a m n. if m = n then a else 0" |
|
|
59983
cd2efd7d06bd
replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents:
59815
diff
changeset
|
600 |
by (simp add: MOST_iff_cofinite) |
| 52380 | 601 |
|
| 65346 | 602 |
lemma coeff_monom [simp]: "coeff (monom a m) n = (if m = n then a else 0)" |
| 52380 | 603 |
by transfer rule |
| 29451 | 604 |
|
| 76207 | 605 |
lemma monom_0: "monom a 0 = [:a:]" |
| 52380 | 606 |
by (rule poly_eqI) (simp add: coeff_pCons split: nat.split) |
| 29451 | 607 |
|
| 65346 | 608 |
lemma monom_Suc: "monom a (Suc n) = pCons 0 (monom a n)" |
| 52380 | 609 |
by (rule poly_eqI) (simp add: coeff_pCons split: nat.split) |
| 29451 | 610 |
|
611 |
lemma monom_eq_0 [simp]: "monom 0 n = 0" |
|
| 52380 | 612 |
by (rule poly_eqI) simp |
| 29451 | 613 |
|
614 |
lemma monom_eq_0_iff [simp]: "monom a n = 0 \<longleftrightarrow> a = 0" |
|
| 52380 | 615 |
by (simp add: poly_eq_iff) |
| 29451 | 616 |
|
617 |
lemma monom_eq_iff [simp]: "monom a n = monom b n \<longleftrightarrow> a = b" |
|
| 52380 | 618 |
by (simp add: poly_eq_iff) |
| 29451 | 619 |
|
620 |
lemma degree_monom_le: "degree (monom a n) \<le> n" |
|
621 |
by (rule degree_le, simp) |
|
622 |
||
623 |
lemma degree_monom_eq: "a \<noteq> 0 \<Longrightarrow> degree (monom a n) = n" |
|
| 72750 | 624 |
by (metis coeff_monom leading_coeff_0_iff) |
| 29451 | 625 |
|
| 52380 | 626 |
lemma coeffs_monom [code abstract]: |
627 |
"coeffs (monom a n) = (if a = 0 then [] else replicate n 0 @ [a])" |
|
628 |
by (induct n) (simp_all add: monom_0 monom_Suc) |
|
629 |
||
| 65346 | 630 |
lemma fold_coeffs_monom [simp]: "a \<noteq> 0 \<Longrightarrow> fold_coeffs f (monom a n) = f 0 ^^ n \<circ> f a" |
| 52380 | 631 |
by (simp add: fold_coeffs_def coeffs_monom fun_eq_iff) |
632 |
||
| 65346 | 633 |
lemma poly_monom: "poly (monom a n) x = a * x ^ n" |
634 |
for a x :: "'a::comm_semiring_1" |
|
| 72024 | 635 |
by (cases "a = 0", simp_all) (induct n, simp_all add: mult.left_commute poly_eq_fold_coeffs) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
636 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
637 |
lemma monom_eq_iff': "monom c n = monom d m \<longleftrightarrow> c = d \<and> (c = 0 \<or> n = m)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
638 |
by (auto simp: poly_eq_iff) |
| 65346 | 639 |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
640 |
lemma monom_eq_const_iff: "monom c n = [:d:] \<longleftrightarrow> c = d \<and> (c = 0 \<or> n = 0)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
641 |
using monom_eq_iff'[of c n d 0] by (simp add: monom_0) |
| 64795 | 642 |
|
643 |
||
644 |
subsection \<open>Leading coefficient\<close> |
|
645 |
||
646 |
abbreviation lead_coeff:: "'a::zero poly \<Rightarrow> 'a" |
|
647 |
where "lead_coeff p \<equiv> coeff p (degree p)" |
|
648 |
||
649 |
lemma lead_coeff_pCons[simp]: |
|
650 |
"p \<noteq> 0 \<Longrightarrow> lead_coeff (pCons a p) = lead_coeff p" |
|
651 |
"p = 0 \<Longrightarrow> lead_coeff (pCons a p) = a" |
|
652 |
by auto |
|
653 |
||
654 |
lemma lead_coeff_monom [simp]: "lead_coeff (monom c n) = c" |
|
655 |
by (cases "c = 0") (simp_all add: degree_monom_eq) |
|
656 |
||
| 66799 | 657 |
lemma last_coeffs_eq_coeff_degree: |
658 |
"last (coeffs p) = lead_coeff p" if "p \<noteq> 0" |
|
659 |
using that by (simp add: coeffs_def) |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
660 |
|
| 64795 | 661 |
|
| 60500 | 662 |
subsection \<open>Addition and subtraction\<close> |
| 29451 | 663 |
|
664 |
instantiation poly :: (comm_monoid_add) comm_monoid_add |
|
665 |
begin |
|
666 |
||
| 52380 | 667 |
lift_definition plus_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
668 |
is "\<lambda>p q n. coeff p n + coeff q n" |
|
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
669 |
proof - |
| 60679 | 670 |
fix q p :: "'a poly" |
671 |
show "\<forall>\<^sub>\<infinity>n. coeff p n + coeff q n = 0" |
|
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
672 |
using MOST_coeff_eq_0[of p] MOST_coeff_eq_0[of q] by eventually_elim simp |
| 52380 | 673 |
qed |
| 29451 | 674 |
|
| 60679 | 675 |
lemma coeff_add [simp]: "coeff (p + q) n = coeff p n + coeff q n" |
| 52380 | 676 |
by (simp add: plus_poly.rep_eq) |
| 29451 | 677 |
|
| 60679 | 678 |
instance |
679 |
proof |
|
| 29451 | 680 |
fix p q r :: "'a poly" |
681 |
show "(p + q) + r = p + (q + r)" |
|
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57482
diff
changeset
|
682 |
by (simp add: poly_eq_iff add.assoc) |
| 29451 | 683 |
show "p + q = q + p" |
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57482
diff
changeset
|
684 |
by (simp add: poly_eq_iff add.commute) |
| 29451 | 685 |
show "0 + p = p" |
| 52380 | 686 |
by (simp add: poly_eq_iff) |
| 29451 | 687 |
qed |
688 |
||
689 |
end |
|
690 |
||
|
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
691 |
instantiation poly :: (cancel_comm_monoid_add) cancel_comm_monoid_add |
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
692 |
begin |
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
693 |
|
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
694 |
lift_definition minus_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
695 |
is "\<lambda>p q n. coeff p n - coeff q n" |
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
696 |
proof - |
| 60679 | 697 |
fix q p :: "'a poly" |
698 |
show "\<forall>\<^sub>\<infinity>n. coeff p n - coeff q n = 0" |
|
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
699 |
using MOST_coeff_eq_0[of p] MOST_coeff_eq_0[of q] by eventually_elim simp |
|
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
700 |
qed |
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
701 |
|
| 60679 | 702 |
lemma coeff_diff [simp]: "coeff (p - q) n = coeff p n - coeff q n" |
|
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
703 |
by (simp add: minus_poly.rep_eq) |
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
704 |
|
| 60679 | 705 |
instance |
706 |
proof |
|
| 29540 | 707 |
fix p q r :: "'a poly" |
|
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
708 |
show "p + q - p = q" |
| 52380 | 709 |
by (simp add: poly_eq_iff) |
|
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
710 |
show "p - q - r = p - (q + r)" |
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
711 |
by (simp add: poly_eq_iff diff_diff_eq) |
| 29540 | 712 |
qed |
713 |
||
|
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
714 |
end |
|
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59557
diff
changeset
|
715 |
|
| 29451 | 716 |
instantiation poly :: (ab_group_add) ab_group_add |
717 |
begin |
|
718 |
||
| 52380 | 719 |
lift_definition uminus_poly :: "'a poly \<Rightarrow> 'a poly" |
720 |
is "\<lambda>p n. - coeff p n" |
|
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
721 |
proof - |
| 60679 | 722 |
fix p :: "'a poly" |
723 |
show "\<forall>\<^sub>\<infinity>n. - coeff p n = 0" |
|
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
724 |
using MOST_coeff_eq_0 by simp |
| 52380 | 725 |
qed |
| 29451 | 726 |
|
727 |
lemma coeff_minus [simp]: "coeff (- p) n = - coeff p n" |
|
| 52380 | 728 |
by (simp add: uminus_poly.rep_eq) |
| 29451 | 729 |
|
| 60679 | 730 |
instance |
731 |
proof |
|
| 29451 | 732 |
fix p q :: "'a poly" |
733 |
show "- p + p = 0" |
|
| 52380 | 734 |
by (simp add: poly_eq_iff) |
| 29451 | 735 |
show "p - q = p + - q" |
|
54230
b1d955791529
more simplification rules on unary and binary minus
haftmann
parents:
52380
diff
changeset
|
736 |
by (simp add: poly_eq_iff) |
| 29451 | 737 |
qed |
738 |
||
739 |
end |
|
740 |
||
| 65346 | 741 |
lemma add_pCons [simp]: "pCons a p + pCons b q = pCons (a + b) (p + q)" |
742 |
by (rule poly_eqI) (simp add: coeff_pCons split: nat.split) |
|
743 |
||
744 |
lemma minus_pCons [simp]: "- pCons a p = pCons (- a) (- p)" |
|
745 |
by (rule poly_eqI) (simp add: coeff_pCons split: nat.split) |
|
746 |
||
747 |
lemma diff_pCons [simp]: "pCons a p - pCons b q = pCons (a - b) (p - q)" |
|
748 |
by (rule poly_eqI) (simp add: coeff_pCons split: nat.split) |
|
| 29451 | 749 |
|
| 29539 | 750 |
lemma degree_add_le_max: "degree (p + q) \<le> max (degree p) (degree q)" |
| 65346 | 751 |
by (rule degree_le) (auto simp add: coeff_eq_0) |
752 |
||
753 |
lemma degree_add_le: "degree p \<le> n \<Longrightarrow> degree q \<le> n \<Longrightarrow> degree (p + q) \<le> n" |
|
| 29539 | 754 |
by (auto intro: order_trans degree_add_le_max) |
755 |
||
| 65346 | 756 |
lemma degree_add_less: "degree p < n \<Longrightarrow> degree q < n \<Longrightarrow> degree (p + q) < n" |
| 29539 | 757 |
by (auto intro: le_less_trans degree_add_le_max) |
| 29453 | 758 |
|
| 72750 | 759 |
lemma degree_add_eq_right: assumes "degree p < degree q" shows "degree (p + q) = degree q" |
760 |
proof (cases "q = 0") |
|
761 |
case False |
|
762 |
show ?thesis |
|
763 |
proof (rule order_antisym) |
|
764 |
show "degree (p + q) \<le> degree q" |
|
765 |
by (simp add: assms degree_add_le order.strict_implies_order) |
|
766 |
show "degree q \<le> degree (p + q)" |
|
767 |
by (simp add: False assms coeff_eq_0 le_degree) |
|
768 |
qed |
|
769 |
qed (use assms in auto) |
|
| 29451 | 770 |
|
| 65346 | 771 |
lemma degree_add_eq_left: "degree q < degree p \<Longrightarrow> degree (p + q) = degree p" |
772 |
using degree_add_eq_right [of q p] by (simp add: add.commute) |
|
773 |
||
774 |
lemma degree_minus [simp]: "degree (- p) = degree p" |
|
775 |
by (simp add: degree_def) |
|
776 |
||
777 |
lemma lead_coeff_add_le: "degree p < degree q \<Longrightarrow> lead_coeff (p + q) = lead_coeff q" |
|
| 64795 | 778 |
by (metis coeff_add coeff_eq_0 monoid_add_class.add.left_neutral degree_add_eq_right) |
779 |
||
| 65346 | 780 |
lemma lead_coeff_minus: "lead_coeff (- p) = - lead_coeff p" |
| 64795 | 781 |
by (metis coeff_minus degree_minus) |
782 |
||
| 65346 | 783 |
lemma degree_diff_le_max: "degree (p - q) \<le> max (degree p) (degree q)" |
784 |
for p q :: "'a::ab_group_add poly" |
|
785 |
using degree_add_le [where p=p and q="-q"] by simp |
|
786 |
||
787 |
lemma degree_diff_le: "degree p \<le> n \<Longrightarrow> degree q \<le> n \<Longrightarrow> degree (p - q) \<le> n" |
|
788 |
for p q :: "'a::ab_group_add poly" |
|
789 |
using degree_add_le [of p n "- q"] by simp |
|
790 |
||
791 |
lemma degree_diff_less: "degree p < n \<Longrightarrow> degree q < n \<Longrightarrow> degree (p - q) < n" |
|
792 |
for p q :: "'a::ab_group_add poly" |
|
793 |
using degree_add_less [of p n "- q"] by simp |
|
| 29453 | 794 |
|
| 29451 | 795 |
lemma add_monom: "monom a n + monom b n = monom (a + b) n" |
| 52380 | 796 |
by (rule poly_eqI) simp |
| 29451 | 797 |
|
798 |
lemma diff_monom: "monom a n - monom b n = monom (a - b) n" |
|
| 52380 | 799 |
by (rule poly_eqI) simp |
| 29451 | 800 |
|
| 65346 | 801 |
lemma minus_monom: "- monom a n = monom (- a) n" |
| 52380 | 802 |
by (rule poly_eqI) simp |
| 29451 | 803 |
|
| 64267 | 804 |
lemma coeff_sum: "coeff (\<Sum>x\<in>A. p x) i = (\<Sum>x\<in>A. coeff (p x) i)" |
| 65346 | 805 |
by (induct A rule: infinite_finite_induct) simp_all |
| 29451 | 806 |
|
| 64267 | 807 |
lemma monom_sum: "monom (\<Sum>x\<in>A. a x) n = (\<Sum>x\<in>A. monom (a x) n)" |
808 |
by (rule poly_eqI) (simp add: coeff_sum) |
|
| 52380 | 809 |
|
810 |
fun plus_coeffs :: "'a::comm_monoid_add list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
|
| 65346 | 811 |
where |
812 |
"plus_coeffs xs [] = xs" |
|
813 |
| "plus_coeffs [] ys = ys" |
|
814 |
| "plus_coeffs (x # xs) (y # ys) = (x + y) ## plus_coeffs xs ys" |
|
| 52380 | 815 |
|
816 |
lemma coeffs_plus_eq_plus_coeffs [code abstract]: |
|
817 |
"coeffs (p + q) = plus_coeffs (coeffs p) (coeffs q)" |
|
818 |
proof - |
|
| 65346 | 819 |
have *: "nth_default 0 (plus_coeffs xs ys) n = nth_default 0 xs n + nth_default 0 ys n" |
820 |
for xs ys :: "'a list" and n |
|
821 |
proof (induct xs ys arbitrary: n rule: plus_coeffs.induct) |
|
| 65390 | 822 |
case (3 x xs y ys n) |
823 |
then show ?case |
|
824 |
by (cases n) (auto simp add: cCons_def) |
|
| 65346 | 825 |
qed simp_all |
| 65390 | 826 |
have **: "no_trailing (HOL.eq 0) (plus_coeffs xs ys)" |
827 |
if "no_trailing (HOL.eq 0) xs" and "no_trailing (HOL.eq 0) ys" |
|
828 |
for xs ys :: "'a list" |
|
829 |
using that by (induct xs ys rule: plus_coeffs.induct) (simp_all add: cCons_def) |
|
| 52380 | 830 |
show ?thesis |
| 65390 | 831 |
by (rule coeffs_eqI) (auto simp add: * nth_default_coeffs_eq intro: **) |
| 52380 | 832 |
qed |
833 |
||
| 65390 | 834 |
lemma coeffs_uminus [code abstract]: |
835 |
"coeffs (- p) = map uminus (coeffs p)" |
|
836 |
proof - |
|
837 |
have eq_0: "HOL.eq 0 \<circ> uminus = HOL.eq (0::'a)" |
|
838 |
by (simp add: fun_eq_iff) |
|
839 |
show ?thesis |
|
840 |
by (rule coeffs_eqI) (simp_all add: nth_default_map_eq nth_default_coeffs_eq no_trailing_map eq_0) |
|
841 |
qed |
|
| 52380 | 842 |
|
| 65346 | 843 |
lemma [code]: "p - q = p + - q" |
844 |
for p q :: "'a::ab_group_add poly" |
|
| 59557 | 845 |
by (fact diff_conv_add_uminus) |
| 52380 | 846 |
|
847 |
lemma poly_add [simp]: "poly (p + q) x = poly p x + poly q x" |
|
| 72750 | 848 |
proof (induction p arbitrary: q) |
849 |
case (pCons a p) |
|
850 |
then show ?case |
|
851 |
by (cases q) (simp add: algebra_simps) |
|
852 |
qed auto |
|
| 52380 | 853 |
|
| 65346 | 854 |
lemma poly_minus [simp]: "poly (- p) x = - poly p x" |
855 |
for x :: "'a::comm_ring" |
|
| 52380 | 856 |
by (induct p) simp_all |
857 |
||
| 65346 | 858 |
lemma poly_diff [simp]: "poly (p - q) x = poly p x - poly q x" |
859 |
for x :: "'a::comm_ring" |
|
|
54230
b1d955791529
more simplification rules on unary and binary minus
haftmann
parents:
52380
diff
changeset
|
860 |
using poly_add [of p "- q" x] by simp |
| 52380 | 861 |
|
| 64267 | 862 |
lemma poly_sum: "poly (\<Sum>k\<in>A. p k) x = (\<Sum>k\<in>A. poly (p k) x)" |
| 52380 | 863 |
by (induct A rule: infinite_finite_induct) simp_all |
| 29451 | 864 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
865 |
lemma poly_sum_list: "poly (\<Sum>p\<leftarrow>ps. p) y = (\<Sum>p\<leftarrow>ps. poly p y)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
866 |
by (induction ps) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
867 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
868 |
lemma poly_sum_mset: "poly (\<Sum>x\<in>#A. p x) y = (\<Sum>x\<in>#A. poly (p x) y)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
869 |
by (induction A) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
870 |
|
| 65346 | 871 |
lemma degree_sum_le: "finite S \<Longrightarrow> (\<And>p. p \<in> S \<Longrightarrow> degree (f p) \<le> n) \<Longrightarrow> degree (sum f S) \<le> n" |
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
872 |
proof (induct S rule: finite_induct) |
| 65346 | 873 |
case empty |
874 |
then show ?case by simp |
|
875 |
next |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
876 |
case (insert p S) |
| 65346 | 877 |
then have "degree (sum f S) \<le> n" "degree (f p) \<le> n" |
878 |
by auto |
|
879 |
then show ?case |
|
880 |
unfolding sum.insert[OF insert(1-2)] by (metis degree_add_le) |
|
881 |
qed |
|
882 |
||
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
883 |
lemma degree_sum_less: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
884 |
assumes "\<And>x. x \<in> A \<Longrightarrow> degree (f x) < n" "n > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
885 |
shows "degree (sum f A) < n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
886 |
using assms by (induction rule: infinite_finite_induct) (auto intro!: degree_add_less) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
887 |
|
| 65346 | 888 |
lemma poly_as_sum_of_monoms': |
889 |
assumes "degree p \<le> n" |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
890 |
shows "(\<Sum>i\<le>n. monom (coeff p i) i) = p" |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
891 |
proof - |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
892 |
have eq: "\<And>i. {..n} \<inter> {i} = (if i \<le> n then {i} else {})"
|
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
893 |
by auto |
| 65346 | 894 |
from assms show ?thesis |
895 |
by (simp add: poly_eq_iff coeff_sum coeff_eq_0 sum.If_cases eq |
|
896 |
if_distrib[where f="\<lambda>x. x * a" for a]) |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
897 |
qed |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
898 |
|
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
899 |
lemma poly_as_sum_of_monoms: "(\<Sum>i\<le>degree p. monom (coeff p i) i) = p" |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
900 |
by (intro poly_as_sum_of_monoms' order_refl) |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
901 |
|
| 62065 | 902 |
lemma Poly_snoc: "Poly (xs @ [x]) = Poly xs + monom x (length xs)" |
| 65346 | 903 |
by (induct xs) (simp_all add: monom_0 monom_Suc) |
| 62065 | 904 |
|
| 29451 | 905 |
|
| 60500 | 906 |
subsection \<open>Multiplication by a constant, polynomial multiplication and the unit polynomial\<close> |
| 29451 | 907 |
|
| 52380 | 908 |
lift_definition smult :: "'a::comm_semiring_0 \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
909 |
is "\<lambda>a p n. a * coeff p n" |
|
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
910 |
proof - |
| 65346 | 911 |
fix a :: 'a and p :: "'a poly" |
912 |
show "\<forall>\<^sub>\<infinity> i. a * coeff p i = 0" |
|
|
60040
1fa1023b13b9
move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents:
59983
diff
changeset
|
913 |
using MOST_coeff_eq_0[of p] by eventually_elim simp |
| 52380 | 914 |
qed |
| 29451 | 915 |
|
| 65346 | 916 |
lemma coeff_smult [simp]: "coeff (smult a p) n = a * coeff p n" |
| 52380 | 917 |
by (simp add: smult.rep_eq) |
| 29451 | 918 |
|
919 |
lemma degree_smult_le: "degree (smult a p) \<le> degree p" |
|
| 65346 | 920 |
by (rule degree_le) (simp add: coeff_eq_0) |
| 29451 | 921 |
|
| 29472 | 922 |
lemma smult_smult [simp]: "smult a (smult b p) = smult (a * b) p" |
| 65346 | 923 |
by (rule poly_eqI) (simp add: mult.assoc) |
| 29451 | 924 |
|
925 |
lemma smult_0_right [simp]: "smult a 0 = 0" |
|
| 65346 | 926 |
by (rule poly_eqI) simp |
| 29451 | 927 |
|
928 |
lemma smult_0_left [simp]: "smult 0 p = 0" |
|
| 65346 | 929 |
by (rule poly_eqI) simp |
| 29451 | 930 |
|
931 |
lemma smult_1_left [simp]: "smult (1::'a::comm_semiring_1) p = p" |
|
| 65346 | 932 |
by (rule poly_eqI) simp |
933 |
||
934 |
lemma smult_add_right: "smult a (p + q) = smult a p + smult a q" |
|
935 |
by (rule poly_eqI) (simp add: algebra_simps) |
|
936 |
||
937 |
lemma smult_add_left: "smult (a + b) p = smult a p + smult b p" |
|
938 |
by (rule poly_eqI) (simp add: algebra_simps) |
|
939 |
||
940 |
lemma smult_minus_right [simp]: "smult a (- p) = - smult a p" |
|
941 |
for a :: "'a::comm_ring" |
|
942 |
by (rule poly_eqI) simp |
|
943 |
||
944 |
lemma smult_minus_left [simp]: "smult (- a) p = - smult a p" |
|
945 |
for a :: "'a::comm_ring" |
|
946 |
by (rule poly_eqI) simp |
|
947 |
||
948 |
lemma smult_diff_right: "smult a (p - q) = smult a p - smult a q" |
|
949 |
for a :: "'a::comm_ring" |
|
950 |
by (rule poly_eqI) (simp add: algebra_simps) |
|
951 |
||
952 |
lemma smult_diff_left: "smult (a - b) p = smult a p - smult b p" |
|
953 |
for a b :: "'a::comm_ring" |
|
954 |
by (rule poly_eqI) (simp add: algebra_simps) |
|
| 29451 | 955 |
|
| 29472 | 956 |
lemmas smult_distribs = |
957 |
smult_add_left smult_add_right |
|
958 |
smult_diff_left smult_diff_right |
|
959 |
||
| 65346 | 960 |
lemma smult_pCons [simp]: "smult a (pCons b p) = pCons (a * b) (smult a p)" |
961 |
by (rule poly_eqI) (simp add: coeff_pCons split: nat.split) |
|
| 29451 | 962 |
|
963 |
lemma smult_monom: "smult a (monom b n) = monom (a * b) n" |
|
| 65346 | 964 |
by (induct n) (simp_all add: monom_0 monom_Suc) |
| 29451 | 965 |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
966 |
lemma smult_Poly: "smult c (Poly xs) = Poly (map ((*) c) xs)" |
| 65346 | 967 |
by (auto simp: poly_eq_iff nth_default_def) |
968 |
||
969 |
lemma degree_smult_eq [simp]: "degree (smult a p) = (if a = 0 then 0 else degree p)" |
|
970 |
for a :: "'a::{comm_semiring_0,semiring_no_zero_divisors}"
|
|
971 |
by (cases "a = 0") (simp_all add: degree_def) |
|
972 |
||
973 |
lemma smult_eq_0_iff [simp]: "smult a p = 0 \<longleftrightarrow> a = 0 \<or> p = 0" |
|
974 |
for a :: "'a::{comm_semiring_0,semiring_no_zero_divisors}"
|
|
| 52380 | 975 |
by (simp add: poly_eq_iff) |
| 65346 | 976 |
|
| 52380 | 977 |
lemma coeffs_smult [code abstract]: |
| 65346 | 978 |
"coeffs (smult a p) = (if a = 0 then [] else map (Groups.times a) (coeffs p))" |
979 |
for p :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
| 65390 | 980 |
proof - |
981 |
have eq_0: "HOL.eq 0 \<circ> times a = HOL.eq (0::'a)" if "a \<noteq> 0" |
|
982 |
using that by (simp add: fun_eq_iff) |
|
983 |
show ?thesis |
|
984 |
by (rule coeffs_eqI) (auto simp add: no_trailing_map nth_default_map_eq nth_default_coeffs_eq eq_0) |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
985 |
qed |
| 64795 | 986 |
|
987 |
lemma smult_eq_iff: |
|
| 65346 | 988 |
fixes b :: "'a :: field" |
989 |
assumes "b \<noteq> 0" |
|
990 |
shows "smult a p = smult b q \<longleftrightarrow> smult (a / b) p = q" |
|
991 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
| 64795 | 992 |
proof |
| 65346 | 993 |
assume ?lhs |
994 |
also from assms have "smult (inverse b) \<dots> = q" |
|
995 |
by simp |
|
996 |
finally show ?rhs |
|
997 |
by (simp add: field_simps) |
|
998 |
next |
|
999 |
assume ?rhs |
|
1000 |
with assms show ?lhs by auto |
|
1001 |
qed |
|
| 64795 | 1002 |
|
| 29451 | 1003 |
instantiation poly :: (comm_semiring_0) comm_semiring_0 |
1004 |
begin |
|
1005 |
||
| 65346 | 1006 |
definition "p * q = fold_coeffs (\<lambda>a p. smult a q + pCons 0 p) p 0" |
| 29474 | 1007 |
|
1008 |
lemma mult_poly_0_left: "(0::'a poly) * q = 0" |
|
| 52380 | 1009 |
by (simp add: times_poly_def) |
| 29474 | 1010 |
|
| 65346 | 1011 |
lemma mult_pCons_left [simp]: "pCons a p * q = smult a q + pCons 0 (p * q)" |
| 52380 | 1012 |
by (cases "p = 0 \<and> a = 0") (auto simp add: times_poly_def) |
| 29474 | 1013 |
|
1014 |
lemma mult_poly_0_right: "p * (0::'a poly) = 0" |
|
| 65346 | 1015 |
by (induct p) (simp_all add: mult_poly_0_left) |
1016 |
||
1017 |
lemma mult_pCons_right [simp]: "p * pCons a q = smult a p + pCons 0 (p * q)" |
|
1018 |
by (induct p) (simp_all add: mult_poly_0_left algebra_simps) |
|
| 29474 | 1019 |
|
1020 |
lemmas mult_poly_0 = mult_poly_0_left mult_poly_0_right |
|
1021 |
||
| 65346 | 1022 |
lemma mult_smult_left [simp]: "smult a p * q = smult a (p * q)" |
1023 |
by (induct p) (simp_all add: mult_poly_0 smult_add_right) |
|
1024 |
||
1025 |
lemma mult_smult_right [simp]: "p * smult a q = smult a (p * q)" |
|
1026 |
by (induct q) (simp_all add: mult_poly_0 smult_add_right) |
|
1027 |
||
1028 |
lemma mult_poly_add_left: "(p + q) * r = p * r + q * r" |
|
1029 |
for p q r :: "'a poly" |
|
1030 |
by (induct r) (simp_all add: mult_poly_0 smult_distribs algebra_simps) |
|
| 29451 | 1031 |
|
| 60679 | 1032 |
instance |
1033 |
proof |
|
| 29451 | 1034 |
fix p q r :: "'a poly" |
1035 |
show 0: "0 * p = 0" |
|
| 29474 | 1036 |
by (rule mult_poly_0_left) |
| 29451 | 1037 |
show "p * 0 = 0" |
| 29474 | 1038 |
by (rule mult_poly_0_right) |
| 29451 | 1039 |
show "(p + q) * r = p * r + q * r" |
| 29474 | 1040 |
by (rule mult_poly_add_left) |
| 29451 | 1041 |
show "(p * q) * r = p * (q * r)" |
| 65346 | 1042 |
by (induct p) (simp_all add: mult_poly_0 mult_poly_add_left) |
| 29451 | 1043 |
show "p * q = q * p" |
| 65346 | 1044 |
by (induct p) (simp_all add: mult_poly_0) |
| 29451 | 1045 |
qed |
1046 |
||
1047 |
end |
|
1048 |
||
| 63498 | 1049 |
lemma coeff_mult_degree_sum: |
| 65346 | 1050 |
"coeff (p * q) (degree p + degree q) = coeff p (degree p) * coeff q (degree q)" |
1051 |
by (induct p) (simp_all add: coeff_eq_0) |
|
| 63498 | 1052 |
|
1053 |
instance poly :: ("{comm_semiring_0,semiring_no_zero_divisors}") semiring_no_zero_divisors
|
|
1054 |
proof |
|
1055 |
fix p q :: "'a poly" |
|
1056 |
assume "p \<noteq> 0" and "q \<noteq> 0" |
|
| 65346 | 1057 |
have "coeff (p * q) (degree p + degree q) = coeff p (degree p) * coeff q (degree q)" |
| 63498 | 1058 |
by (rule coeff_mult_degree_sum) |
| 65346 | 1059 |
also from \<open>p \<noteq> 0\<close> \<open>q \<noteq> 0\<close> have "coeff p (degree p) * coeff q (degree q) \<noteq> 0" |
1060 |
by simp |
|
| 63498 | 1061 |
finally have "\<exists>n. coeff (p * q) n \<noteq> 0" .. |
| 65346 | 1062 |
then show "p * q \<noteq> 0" |
1063 |
by (simp add: poly_eq_iff) |
|
| 63498 | 1064 |
qed |
1065 |
||
| 29540 | 1066 |
instance poly :: (comm_semiring_0_cancel) comm_semiring_0_cancel .. |
1067 |
||
| 65346 | 1068 |
lemma coeff_mult: "coeff (p * q) n = (\<Sum>i\<le>n. coeff p i * coeff q (n-i))" |
| 29474 | 1069 |
proof (induct p arbitrary: n) |
| 65346 | 1070 |
case 0 |
1071 |
show ?case by simp |
|
| 29474 | 1072 |
next |
| 65346 | 1073 |
case (pCons a p n) |
1074 |
then show ?case |
|
|
70113
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
paulson <lp15@cam.ac.uk>
parents:
70097
diff
changeset
|
1075 |
by (cases n) (simp_all add: sum.atMost_Suc_shift del: sum.atMost_Suc) |
| 29474 | 1076 |
qed |
| 29451 | 1077 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1078 |
lemma coeff_mult_0: "coeff (p * q) 0 = coeff p 0 * coeff q 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1079 |
by (simp add: coeff_mult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1080 |
|
| 29474 | 1081 |
lemma degree_mult_le: "degree (p * q) \<le> degree p + degree q" |
| 72750 | 1082 |
proof (rule degree_le) |
1083 |
show "\<forall>i>degree p + degree q. coeff (p * q) i = 0" |
|
1084 |
by (induct p) (simp_all add: coeff_eq_0 coeff_pCons split: nat.split) |
|
1085 |
qed |
|
| 29451 | 1086 |
|
1087 |
lemma mult_monom: "monom a m * monom b n = monom (a * b) (m + n)" |
|
| 60679 | 1088 |
by (induct m) (simp add: monom_0 smult_monom, simp add: monom_Suc) |
| 29451 | 1089 |
|
1090 |
instantiation poly :: (comm_semiring_1) comm_semiring_1 |
|
1091 |
begin |
|
1092 |
||
| 65486 | 1093 |
lift_definition one_poly :: "'a poly" |
1094 |
is "\<lambda>n. of_bool (n = 0)" |
|
1095 |
by (rule MOST_SucD) simp |
|
1096 |
||
1097 |
lemma coeff_1 [simp]: |
|
1098 |
"coeff 1 n = of_bool (n = 0)" |
|
1099 |
by (simp add: one_poly.rep_eq) |
|
1100 |
||
1101 |
lemma one_pCons: |
|
1102 |
"1 = [:1:]" |
|
1103 |
by (simp add: poly_eq_iff coeff_pCons split: nat.splits) |
|
1104 |
||
1105 |
lemma pCons_one: |
|
1106 |
"[:1:] = 1" |
|
1107 |
by (simp add: one_pCons) |
|
| 29451 | 1108 |
|
| 60679 | 1109 |
instance |
| 65486 | 1110 |
by standard (simp_all add: one_pCons) |
| 29451 | 1111 |
|
1112 |
end |
|
1113 |
||
| 65486 | 1114 |
lemma poly_1 [simp]: |
1115 |
"poly 1 x = 1" |
|
1116 |
by (simp add: one_pCons) |
|
1117 |
||
1118 |
lemma one_poly_eq_simps [simp]: |
|
1119 |
"1 = [:1:] \<longleftrightarrow> True" |
|
1120 |
"[:1:] = 1 \<longleftrightarrow> True" |
|
1121 |
by (simp_all add: one_pCons) |
|
1122 |
||
1123 |
lemma degree_1 [simp]: |
|
1124 |
"degree 1 = 0" |
|
1125 |
by (simp add: one_pCons) |
|
1126 |
||
1127 |
lemma coeffs_1_eq [simp, code abstract]: |
|
1128 |
"coeffs 1 = [1]" |
|
1129 |
by (simp add: one_pCons) |
|
1130 |
||
1131 |
lemma smult_one [simp]: |
|
1132 |
"smult c 1 = [:c:]" |
|
1133 |
by (simp add: one_pCons) |
|
1134 |
||
1135 |
lemma monom_eq_1 [simp]: |
|
1136 |
"monom 1 0 = 1" |
|
1137 |
by (simp add: monom_0 one_pCons) |
|
1138 |
||
1139 |
lemma monom_eq_1_iff: |
|
1140 |
"monom c n = 1 \<longleftrightarrow> c = 1 \<and> n = 0" |
|
1141 |
using monom_eq_const_iff [of c n 1] by auto |
|
1142 |
||
1143 |
lemma monom_altdef: |
|
1144 |
"monom c n = smult c ([:0, 1:] ^ n)" |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
1145 |
by (induct n) (simp_all add: monom_0 monom_Suc) |
| 65486 | 1146 |
|
| 63498 | 1147 |
instance poly :: ("{comm_semiring_1,semiring_1_no_zero_divisors}") semiring_1_no_zero_divisors ..
|
| 52380 | 1148 |
instance poly :: (comm_ring) comm_ring .. |
1149 |
instance poly :: (comm_ring_1) comm_ring_1 .. |
|
| 63498 | 1150 |
instance poly :: (comm_ring_1) comm_semiring_1_cancel .. |
1151 |
||
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1152 |
lemma prod_smult: "(\<Prod>x\<in>A. smult (c x) (p x)) = smult (prod c A) (prod p A)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1153 |
by (induction A rule: infinite_finite_induct) (auto simp: mult_ac) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1154 |
|
| 65346 | 1155 |
lemma degree_power_le: "degree (p ^ n) \<le> degree p * n" |
| 52380 | 1156 |
by (induct n) (auto intro: order_trans degree_mult_le) |
1157 |
||
| 65346 | 1158 |
lemma coeff_0_power: "coeff (p ^ n) 0 = coeff p 0 ^ n" |
1159 |
by (induct n) (simp_all add: coeff_mult) |
|
1160 |
||
1161 |
lemma poly_smult [simp]: "poly (smult a p) x = a * poly p x" |
|
1162 |
by (induct p) (simp_all add: algebra_simps) |
|
1163 |
||
1164 |
lemma poly_mult [simp]: "poly (p * q) x = poly p x * poly q x" |
|
1165 |
by (induct p) (simp_all add: algebra_simps) |
|
1166 |
||
1167 |
lemma poly_power [simp]: "poly (p ^ n) x = poly p x ^ n" |
|
1168 |
for p :: "'a::comm_semiring_1 poly" |
|
| 52380 | 1169 |
by (induct n) simp_all |
1170 |
||
| 64272 | 1171 |
lemma poly_prod: "poly (\<Prod>k\<in>A. p k) x = (\<Prod>k\<in>A. poly (p k) x)" |
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
1172 |
by (induct A rule: infinite_finite_induct) simp_all |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
1173 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1174 |
lemma poly_prod_list: "poly (\<Prod>p\<leftarrow>ps. p) y = (\<Prod>p\<leftarrow>ps. poly p y)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1175 |
by (induction ps) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1176 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1177 |
lemma poly_prod_mset: "poly (\<Prod>x\<in>#A. p x) y = (\<Prod>x\<in>#A. poly (p x) y)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1178 |
by (induction A) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1179 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1180 |
lemma poly_const_pow: "[: c :] ^ n = [: c ^ n :]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1181 |
by (induction n) (auto simp: algebra_simps) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1182 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1183 |
lemma monom_power: "monom c n ^ k = monom (c ^ k) (n * k)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1184 |
by (induction k) (auto simp: mult_monom) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1185 |
|
| 67091 | 1186 |
lemma degree_prod_sum_le: "finite S \<Longrightarrow> degree (prod f S) \<le> sum (degree \<circ> f) S" |
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
1187 |
proof (induct S rule: finite_induct) |
| 65346 | 1188 |
case empty |
1189 |
then show ?case by simp |
|
1190 |
next |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
1191 |
case (insert a S) |
| 65346 | 1192 |
show ?case |
1193 |
unfolding prod.insert[OF insert(1-2)] sum.insert[OF insert(1-2)] |
|
1194 |
by (rule le_trans[OF degree_mult_le]) (use insert in auto) |
|
1195 |
qed |
|
1196 |
||
1197 |
lemma coeff_0_prod_list: "coeff (prod_list xs) 0 = prod_list (map (\<lambda>p. coeff p 0) xs)" |
|
1198 |
by (induct xs) (simp_all add: coeff_mult) |
|
1199 |
||
1200 |
lemma coeff_monom_mult: "coeff (monom c n * p) k = (if k < n then 0 else c * coeff p (k - n))" |
|
| 64795 | 1201 |
proof - |
1202 |
have "coeff (monom c n * p) k = (\<Sum>i\<le>k. (if n = i then c else 0) * coeff p (k - i))" |
|
1203 |
by (simp add: coeff_mult) |
|
1204 |
also have "\<dots> = (\<Sum>i\<le>k. (if n = i then c * coeff p (k - i) else 0))" |
|
1205 |
by (intro sum.cong) simp_all |
|
| 65346 | 1206 |
also have "\<dots> = (if k < n then 0 else c * coeff p (k - n))" |
| 66799 | 1207 |
by simp |
| 64795 | 1208 |
finally show ?thesis . |
1209 |
qed |
|
1210 |
||
| 65346 | 1211 |
lemma monom_1_dvd_iff': "monom 1 n dvd p \<longleftrightarrow> (\<forall>k<n. coeff p k = 0)" |
| 64795 | 1212 |
proof |
1213 |
assume "monom 1 n dvd p" |
|
| 65346 | 1214 |
then obtain r where "p = monom 1 n * r" |
1215 |
by (rule dvdE) |
|
1216 |
then show "\<forall>k<n. coeff p k = 0" |
|
1217 |
by (simp add: coeff_mult) |
|
| 64795 | 1218 |
next |
1219 |
assume zero: "(\<forall>k<n. coeff p k = 0)" |
|
1220 |
define r where "r = Abs_poly (\<lambda>k. coeff p (k + n))" |
|
1221 |
have "\<forall>\<^sub>\<infinity>k. coeff p (k + n) = 0" |
|
| 65346 | 1222 |
by (subst cofinite_eq_sequentially, subst eventually_sequentially_seg, |
| 64795 | 1223 |
subst cofinite_eq_sequentially [symmetric]) transfer |
| 65346 | 1224 |
then have coeff_r [simp]: "coeff r k = coeff p (k + n)" for k |
1225 |
unfolding r_def by (subst poly.Abs_poly_inverse) simp_all |
|
| 64795 | 1226 |
have "p = monom 1 n * r" |
| 65346 | 1227 |
by (rule poly_eqI, subst coeff_monom_mult) (simp_all add: zero) |
1228 |
then show "monom 1 n dvd p" by simp |
|
| 64795 | 1229 |
qed |
1230 |
||
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1231 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1232 |
subsection \<open>Mapping polynomials\<close> |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1233 |
|
| 65346 | 1234 |
definition map_poly :: "('a :: zero \<Rightarrow> 'b :: zero) \<Rightarrow> 'a poly \<Rightarrow> 'b poly"
|
1235 |
where "map_poly f p = Poly (map f (coeffs p))" |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1236 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1237 |
lemma map_poly_0 [simp]: "map_poly f 0 = 0" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1238 |
by (simp add: map_poly_def) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1239 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1240 |
lemma map_poly_1: "map_poly f 1 = [:f 1:]" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1241 |
by (simp add: map_poly_def) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1242 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1243 |
lemma map_poly_1' [simp]: "f 1 = 1 \<Longrightarrow> map_poly f 1 = 1" |
| 65486 | 1244 |
by (simp add: map_poly_def one_pCons) |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1245 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1246 |
lemma coeff_map_poly: |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1247 |
assumes "f 0 = 0" |
| 65346 | 1248 |
shows "coeff (map_poly f p) n = f (coeff p n)" |
1249 |
by (auto simp: assms map_poly_def nth_default_def coeffs_def not_less Suc_le_eq coeff_eq_0 |
|
1250 |
simp del: upt_Suc) |
|
1251 |
||
1252 |
lemma coeffs_map_poly [code abstract]: |
|
| 67399 | 1253 |
"coeffs (map_poly f p) = strip_while ((=) 0) (map f (coeffs p))" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1254 |
by (simp add: map_poly_def) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1255 |
|
| 65346 | 1256 |
lemma coeffs_map_poly': |
1257 |
assumes "\<And>x. x \<noteq> 0 \<Longrightarrow> f x \<noteq> 0" |
|
1258 |
shows "coeffs (map_poly f p) = map f (coeffs p)" |
|
| 66799 | 1259 |
using assms |
1260 |
by (auto simp add: coeffs_map_poly strip_while_idem_iff |
|
1261 |
last_coeffs_eq_coeff_degree no_trailing_unfold last_map) |
|
| 65390 | 1262 |
|
1263 |
lemma set_coeffs_map_poly: |
|
1264 |
"(\<And>x. f x = 0 \<longleftrightarrow> x = 0) \<Longrightarrow> set (coeffs (map_poly f p)) = f ` set (coeffs p)" |
|
1265 |
by (simp add: coeffs_map_poly') |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1266 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1267 |
lemma degree_map_poly: |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1268 |
assumes "\<And>x. x \<noteq> 0 \<Longrightarrow> f x \<noteq> 0" |
| 65346 | 1269 |
shows "degree (map_poly f p) = degree p" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1270 |
by (simp add: degree_eq_length_coeffs coeffs_map_poly' assms) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1271 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1272 |
lemma map_poly_eq_0_iff: |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1273 |
assumes "f 0 = 0" "\<And>x. x \<in> set (coeffs p) \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> f x \<noteq> 0" |
| 65346 | 1274 |
shows "map_poly f p = 0 \<longleftrightarrow> p = 0" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1275 |
proof - |
| 65346 | 1276 |
have "(coeff (map_poly f p) n = 0) = (coeff p n = 0)" for n |
1277 |
proof - |
|
1278 |
have "coeff (map_poly f p) n = f (coeff p n)" |
|
1279 |
by (simp add: coeff_map_poly assms) |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1280 |
also have "\<dots> = 0 \<longleftrightarrow> coeff p n = 0" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1281 |
proof (cases "n < length (coeffs p)") |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1282 |
case True |
| 65346 | 1283 |
then have "coeff p n \<in> set (coeffs p)" |
1284 |
by (auto simp: coeffs_def simp del: upt_Suc) |
|
1285 |
with assms show "f (coeff p n) = 0 \<longleftrightarrow> coeff p n = 0" |
|
1286 |
by auto |
|
1287 |
next |
|
1288 |
case False |
|
1289 |
then show ?thesis |
|
1290 |
by (auto simp: assms length_coeffs nth_default_coeffs_eq [symmetric] nth_default_def) |
|
1291 |
qed |
|
1292 |
finally show ?thesis . |
|
1293 |
qed |
|
1294 |
then show ?thesis by (auto simp: poly_eq_iff) |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1295 |
qed |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1296 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1297 |
lemma map_poly_smult: |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1298 |
assumes "f 0 = 0""\<And>c x. f (c * x) = f c * f x" |
| 65346 | 1299 |
shows "map_poly f (smult c p) = smult (f c) (map_poly f p)" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1300 |
by (intro poly_eqI) (simp_all add: assms coeff_map_poly) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1301 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1302 |
lemma map_poly_pCons: |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1303 |
assumes "f 0 = 0" |
| 65346 | 1304 |
shows "map_poly f (pCons c p) = pCons (f c) (map_poly f p)" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1305 |
by (intro poly_eqI) (simp_all add: assms coeff_map_poly coeff_pCons split: nat.splits) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1306 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1307 |
lemma map_poly_map_poly: |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1308 |
assumes "f 0 = 0" "g 0 = 0" |
| 65346 | 1309 |
shows "map_poly f (map_poly g p) = map_poly (f \<circ> g) p" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1310 |
by (intro poly_eqI) (simp add: coeff_map_poly assms) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1311 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1312 |
lemma map_poly_id [simp]: "map_poly id p = p" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1313 |
by (simp add: map_poly_def) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1314 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1315 |
lemma map_poly_id' [simp]: "map_poly (\<lambda>x. x) p = p" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1316 |
by (simp add: map_poly_def) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1317 |
|
| 65346 | 1318 |
lemma map_poly_cong: |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1319 |
assumes "(\<And>x. x \<in> set (coeffs p) \<Longrightarrow> f x = g x)" |
| 65346 | 1320 |
shows "map_poly f p = map_poly g p" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1321 |
proof - |
| 65346 | 1322 |
from assms have "map f (coeffs p) = map g (coeffs p)" |
1323 |
by (intro map_cong) simp_all |
|
1324 |
then show ?thesis |
|
1325 |
by (simp only: coeffs_eq_iff coeffs_map_poly) |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1326 |
qed |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1327 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1328 |
lemma map_poly_monom: "f 0 = 0 \<Longrightarrow> map_poly f (monom c n) = monom (f c) n" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1329 |
by (intro poly_eqI) (simp_all add: coeff_map_poly) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1330 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1331 |
lemma map_poly_idI: |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1332 |
assumes "\<And>x. x \<in> set (coeffs p) \<Longrightarrow> f x = x" |
| 65346 | 1333 |
shows "map_poly f p = p" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1334 |
using map_poly_cong[OF assms, of _ id] by simp |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1335 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1336 |
lemma map_poly_idI': |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1337 |
assumes "\<And>x. x \<in> set (coeffs p) \<Longrightarrow> f x = x" |
| 65346 | 1338 |
shows "p = map_poly f p" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1339 |
using map_poly_cong[OF assms, of _ id] by simp |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1340 |
|
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1341 |
lemma smult_conv_map_poly: "smult c p = map_poly (\<lambda>x. c * x) p" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1342 |
by (intro poly_eqI) (simp_all add: coeff_map_poly) |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1343 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1344 |
lemma poly_cnj: "cnj (poly p z) = poly (map_poly cnj p) (cnj z)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1345 |
by (simp add: poly_altdef degree_map_poly coeff_map_poly) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1346 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1347 |
lemma poly_cnj_real: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1348 |
assumes "\<And>n. poly.coeff p n \<in> \<real>" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1349 |
shows "cnj (poly p z) = poly p (cnj z)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1350 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1351 |
from assms have "map_poly cnj p = p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1352 |
by (intro poly_eqI) (auto simp: coeff_map_poly Reals_cnj_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1353 |
with poly_cnj[of p z] show ?thesis by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1354 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1355 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1356 |
lemma real_poly_cnj_root_iff: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1357 |
assumes "\<And>n. poly.coeff p n \<in> \<real>" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1358 |
shows "poly p (cnj z) = 0 \<longleftrightarrow> poly p z = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1359 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1360 |
have "poly p (cnj z) = cnj (poly p z)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1361 |
by (simp add: poly_cnj_real assms) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1362 |
also have "\<dots> = 0 \<longleftrightarrow> poly p z = 0" by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1363 |
finally show ?thesis . |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1364 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1365 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1366 |
lemma sum_to_poly: "(\<Sum>x\<in>A. [:f x:]) = [:\<Sum>x\<in>A. f x:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1367 |
by (induction A rule: infinite_finite_induct) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1368 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1369 |
lemma diff_to_poly: "[:c:] - [:d:] = [:c - d:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1370 |
by (simp add: poly_eq_iff mult_ac) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1371 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1372 |
lemma mult_to_poly: "[:c:] * [:d:] = [:c * d:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1373 |
by (simp add: poly_eq_iff mult_ac) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1374 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1375 |
lemma prod_to_poly: "(\<Prod>x\<in>A. [:f x:]) = [:\<Prod>x\<in>A. f x:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1376 |
by (induction A rule: infinite_finite_induct) (auto simp: mult_to_poly mult_ac) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1377 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1378 |
lemma poly_map_poly_cnj [simp]: "poly (map_poly cnj p) x = cnj (poly p (cnj x))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1379 |
by (induction p) (auto simp: map_poly_pCons) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1380 |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1381 |
|
| 65484 | 1382 |
subsection \<open>Conversions\<close> |
1383 |
||
1384 |
lemma of_nat_poly: |
|
1385 |
"of_nat n = [:of_nat n:]" |
|
| 65486 | 1386 |
by (induct n) (simp_all add: one_pCons) |
| 65484 | 1387 |
|
1388 |
lemma of_nat_monom: |
|
1389 |
"of_nat n = monom (of_nat n) 0" |
|
1390 |
by (simp add: of_nat_poly monom_0) |
|
1391 |
||
1392 |
lemma degree_of_nat [simp]: |
|
1393 |
"degree (of_nat n) = 0" |
|
| 62065 | 1394 |
by (simp add: of_nat_poly) |
1395 |
||
| 64795 | 1396 |
lemma lead_coeff_of_nat [simp]: |
| 65484 | 1397 |
"lead_coeff (of_nat n) = of_nat n" |
| 64795 | 1398 |
by (simp add: of_nat_poly) |
1399 |
||
| 65484 | 1400 |
lemma of_int_poly: |
1401 |
"of_int k = [:of_int k:]" |
|
| 64793 | 1402 |
by (simp only: of_int_of_nat of_nat_poly) simp |
1403 |
||
| 65484 | 1404 |
lemma of_int_monom: |
1405 |
"of_int k = monom (of_int k) 0" |
|
1406 |
by (simp add: of_int_poly monom_0) |
|
1407 |
||
1408 |
lemma degree_of_int [simp]: |
|
1409 |
"degree (of_int k) = 0" |
|
| 64795 | 1410 |
by (simp add: of_int_poly) |
1411 |
||
1412 |
lemma lead_coeff_of_int [simp]: |
|
| 65484 | 1413 |
"lead_coeff (of_int k) = of_int k" |
| 64793 | 1414 |
by (simp add: of_int_poly) |
| 62065 | 1415 |
|
|
79672
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1416 |
lemma poly_of_nat [simp]: "poly (of_nat n) x = of_nat n" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1417 |
by (simp add: of_nat_poly) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1418 |
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1419 |
lemma poly_of_int [simp]: "poly (of_int n) x = of_int n" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1420 |
by (simp add: of_int_poly) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1421 |
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1422 |
lemma poly_numeral [simp]: "poly (numeral n) x = numeral n" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1423 |
by (metis of_nat_numeral poly_of_nat) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
1424 |
|
| 62065 | 1425 |
lemma numeral_poly: "numeral n = [:numeral n:]" |
| 65484 | 1426 |
proof - |
1427 |
have "numeral n = of_nat (numeral n)" |
|
1428 |
by simp |
|
1429 |
also have "\<dots> = [:of_nat (numeral n):]" |
|
1430 |
by (simp add: of_nat_poly) |
|
1431 |
finally show ?thesis |
|
1432 |
by simp |
|
1433 |
qed |
|
1434 |
||
1435 |
lemma numeral_monom: |
|
1436 |
"numeral n = monom (numeral n) 0" |
|
1437 |
by (simp add: numeral_poly monom_0) |
|
1438 |
||
1439 |
lemma degree_numeral [simp]: |
|
1440 |
"degree (numeral n) = 0" |
|
1441 |
by (simp add: numeral_poly) |
|
| 52380 | 1442 |
|
| 65346 | 1443 |
lemma lead_coeff_numeral [simp]: |
| 64795 | 1444 |
"lead_coeff (numeral n) = numeral n" |
1445 |
by (simp add: numeral_poly) |
|
1446 |
||
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1447 |
lemma coeff_linear_poly_power: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1448 |
fixes c :: "'a :: semiring_1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1449 |
assumes "i \<le> n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1450 |
shows "coeff ([:a, b:] ^ n) i = of_nat (n choose i) * b ^ i * a ^ (n - i)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1451 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1452 |
have "[:a, b:] = monom b 1 + [:a:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1453 |
by (simp add: monom_altdef) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1454 |
also have "coeff (\<dots> ^ n) i = (\<Sum>k\<le>n. a^(n-k) * of_nat (n choose k) * (if k = i then b ^ k else 0))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1455 |
by (subst binomial_ring) (simp add: coeff_sum of_nat_poly monom_power poly_const_pow mult_ac) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1456 |
also have "\<dots> = (\<Sum>k\<in>{i}. a ^ (n - i) * b ^ i * of_nat (n choose k))"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1457 |
using assms by (intro sum.mono_neutral_cong_right) (auto simp: mult_ac) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1458 |
finally show *: ?thesis by (simp add: mult_ac) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1459 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1460 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1461 |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1462 |
|
| 60500 | 1463 |
subsection \<open>Lemmas about divisibility\<close> |
| 29979 | 1464 |
|
| 65346 | 1465 |
lemma dvd_smult: |
1466 |
assumes "p dvd q" |
|
1467 |
shows "p dvd smult a q" |
|
| 29979 | 1468 |
proof - |
| 65346 | 1469 |
from assms obtain k where "q = p * k" .. |
| 29979 | 1470 |
then have "smult a q = p * smult a k" by simp |
1471 |
then show "p dvd smult a q" .. |
|
1472 |
qed |
|
1473 |
||
| 65346 | 1474 |
lemma dvd_smult_cancel: "p dvd smult a q \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> p dvd q" |
1475 |
for a :: "'a::field" |
|
| 29979 | 1476 |
by (drule dvd_smult [where a="inverse a"]) simp |
1477 |
||
| 65346 | 1478 |
lemma dvd_smult_iff: "a \<noteq> 0 \<Longrightarrow> p dvd smult a q \<longleftrightarrow> p dvd q" |
1479 |
for a :: "'a::field" |
|
| 29979 | 1480 |
by (safe elim!: dvd_smult dvd_smult_cancel) |
1481 |
||
| 31663 | 1482 |
lemma smult_dvd_cancel: |
| 65346 | 1483 |
assumes "smult a p dvd q" |
1484 |
shows "p dvd q" |
|
| 31663 | 1485 |
proof - |
| 65346 | 1486 |
from assms obtain k where "q = smult a p * k" .. |
| 31663 | 1487 |
then have "q = p * smult a k" by simp |
1488 |
then show "p dvd q" .. |
|
1489 |
qed |
|
1490 |
||
| 65346 | 1491 |
lemma smult_dvd: "p dvd q \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> smult a p dvd q" |
1492 |
for a :: "'a::field" |
|
| 31663 | 1493 |
by (rule smult_dvd_cancel [where a="inverse a"]) simp |
1494 |
||
| 65346 | 1495 |
lemma smult_dvd_iff: "smult a p dvd q \<longleftrightarrow> (if a = 0 then q = 0 else p dvd q)" |
1496 |
for a :: "'a::field" |
|
| 31663 | 1497 |
by (auto elim: smult_dvd smult_dvd_cancel) |
1498 |
||
| 64795 | 1499 |
lemma is_unit_smult_iff: "smult c p dvd 1 \<longleftrightarrow> c dvd 1 \<and> p dvd 1" |
1500 |
proof - |
|
1501 |
have "smult c p = [:c:] * p" by simp |
|
1502 |
also have "\<dots> dvd 1 \<longleftrightarrow> c dvd 1 \<and> p dvd 1" |
|
1503 |
proof safe |
|
| 65346 | 1504 |
assume *: "[:c:] * p dvd 1" |
1505 |
then show "p dvd 1" |
|
1506 |
by (rule dvd_mult_right) |
|
1507 |
from * obtain q where q: "1 = [:c:] * p * q" |
|
1508 |
by (rule dvdE) |
|
1509 |
have "c dvd c * (coeff p 0 * coeff q 0)" |
|
1510 |
by simp |
|
1511 |
also have "\<dots> = coeff ([:c:] * p * q) 0" |
|
1512 |
by (simp add: mult.assoc coeff_mult) |
|
1513 |
also note q [symmetric] |
|
1514 |
finally have "c dvd coeff 1 0" . |
|
1515 |
then show "c dvd 1" by simp |
|
| 64795 | 1516 |
next |
1517 |
assume "c dvd 1" "p dvd 1" |
|
| 65346 | 1518 |
from this(1) obtain d where "1 = c * d" |
1519 |
by (rule dvdE) |
|
1520 |
then have "1 = [:c:] * [:d:]" |
|
| 65486 | 1521 |
by (simp add: one_pCons ac_simps) |
| 65346 | 1522 |
then have "[:c:] dvd 1" |
1523 |
by (rule dvdI) |
|
1524 |
from mult_dvd_mono[OF this \<open>p dvd 1\<close>] show "[:c:] * p dvd 1" |
|
1525 |
by simp |
|
| 64795 | 1526 |
qed |
1527 |
finally show ?thesis . |
|
1528 |
qed |
|
1529 |
||
| 29451 | 1530 |
|
| 60500 | 1531 |
subsection \<open>Polynomials form an integral domain\<close> |
| 29451 | 1532 |
|
| 63498 | 1533 |
instance poly :: (idom) idom .. |
| 29451 | 1534 |
|
|
65577
32d4117ad6e8
instance for polynomial rings with characteristic zero
haftmann
parents:
65486
diff
changeset
|
1535 |
instance poly :: ("{ring_char_0, comm_ring_1}") ring_char_0
|
|
32d4117ad6e8
instance for polynomial rings with characteristic zero
haftmann
parents:
65486
diff
changeset
|
1536 |
by standard (auto simp add: of_nat_poly intro: injI) |
|
32d4117ad6e8
instance for polynomial rings with characteristic zero
haftmann
parents:
65486
diff
changeset
|
1537 |
|
|
80084
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1538 |
lemma semiring_char_poly [simp]: "CHAR('a :: comm_semiring_1 poly) = CHAR('a)"
|
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1539 |
by (rule CHAR_eqI) (auto simp: of_nat_poly of_nat_eq_0_iff_char_dvd) |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1540 |
|
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1541 |
instance poly :: ("{semiring_prime_char,comm_semiring_1}") semiring_prime_char
|
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1542 |
by (rule semiring_prime_charI) auto |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1543 |
instance poly :: ("{comm_semiring_prime_char,comm_semiring_1}") comm_semiring_prime_char
|
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1544 |
by standard |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1545 |
instance poly :: ("{comm_ring_prime_char,comm_semiring_1}") comm_ring_prime_char
|
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1546 |
by standard |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1547 |
instance poly :: ("{idom_prime_char,comm_semiring_1}") idom_prime_char
|
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1548 |
by standard |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
1549 |
|
| 65346 | 1550 |
lemma degree_mult_eq: "p \<noteq> 0 \<Longrightarrow> q \<noteq> 0 \<Longrightarrow> degree (p * q) = degree p + degree q" |
1551 |
for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
1552 |
by (rule order_antisym [OF degree_mult_le le_degree]) (simp add: coeff_mult_degree_sum) |
|
| 29451 | 1553 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1554 |
lemma degree_prod_sum_eq: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1555 |
"(\<And>x. x \<in> A \<Longrightarrow> f x \<noteq> 0) \<Longrightarrow> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1556 |
degree (prod f A :: 'a :: idom poly) = (\<Sum>x\<in>A. degree (f x))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1557 |
by (induction A rule: infinite_finite_induct) (auto simp: degree_mult_eq) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1558 |
|
| 76194 | 1559 |
lemma dvd_imp_degree: |
1560 |
\<open>degree x \<le> degree y\<close> if \<open>x dvd y\<close> \<open>x \<noteq> 0\<close> \<open>y \<noteq> 0\<close> |
|
1561 |
for x y :: \<open>'a::{comm_semiring_1,semiring_no_zero_divisors} poly\<close>
|
|
1562 |
proof - |
|
1563 |
from \<open>x dvd y\<close> obtain z where \<open>y = x * z\<close> .. |
|
1564 |
with \<open>x \<noteq> 0\<close> \<open>y \<noteq> 0\<close> show ?thesis |
|
1565 |
by (simp add: degree_mult_eq) |
|
1566 |
qed |
|
1567 |
||
|
73109
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1568 |
lemma degree_prod_eq_sum_degree: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1569 |
fixes A :: "'a set" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1570 |
and f :: "'a \<Rightarrow> 'b::idom poly" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1571 |
assumes f0: "\<forall>i\<in>A. f i \<noteq> 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1572 |
shows "degree (\<Prod>i\<in>A. (f i)) = (\<Sum>i\<in>A. degree (f i))" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1573 |
using assms |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1574 |
by (induction A rule: infinite_finite_induct) (auto simp: degree_mult_eq) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1575 |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1576 |
lemma degree_mult_eq_0: |
| 65346 | 1577 |
"degree (p * q) = 0 \<longleftrightarrow> p = 0 \<or> q = 0 \<or> (p \<noteq> 0 \<and> q \<noteq> 0 \<and> degree p = 0 \<and> degree q = 0)" |
1578 |
for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
1579 |
by (auto simp: degree_mult_eq) |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
1580 |
|
|
66550
e5d82cf3c387
Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents:
66453
diff
changeset
|
1581 |
lemma degree_power_eq: "p \<noteq> 0 \<Longrightarrow> degree ((p :: 'a :: idom poly) ^ n) = n * degree p" |
|
e5d82cf3c387
Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents:
66453
diff
changeset
|
1582 |
by (induction n) (simp_all add: degree_mult_eq) |
|
e5d82cf3c387
Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents:
66453
diff
changeset
|
1583 |
|
| 60570 | 1584 |
lemma degree_mult_right_le: |
| 63498 | 1585 |
fixes p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
| 60570 | 1586 |
assumes "q \<noteq> 0" |
1587 |
shows "degree p \<le> degree (p * q)" |
|
1588 |
using assms by (cases "p = 0") (simp_all add: degree_mult_eq) |
|
1589 |
||
| 65346 | 1590 |
lemma coeff_degree_mult: "coeff (p * q) (degree (p * q)) = coeff q (degree q) * coeff p (degree p)" |
1591 |
for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
1592 |
by (cases "p = 0 \<or> q = 0") (auto simp: degree_mult_eq coeff_mult_degree_sum mult_ac) |
|
1593 |
||
1594 |
lemma dvd_imp_degree_le: "p dvd q \<Longrightarrow> q \<noteq> 0 \<Longrightarrow> degree p \<le> degree q" |
|
1595 |
for p q :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
|
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
1596 |
by (erule dvdE, hypsubst, subst degree_mult_eq) auto |
| 29451 | 1597 |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
1598 |
lemma divides_degree: |
| 65346 | 1599 |
fixes p q :: "'a ::{comm_semiring_1,semiring_no_zero_divisors} poly"
|
1600 |
assumes "p dvd q" |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
1601 |
shows "degree p \<le> degree q \<or> q = 0" |
| 65346 | 1602 |
by (metis dvd_imp_degree_le assms) |
1603 |
||
| 63498 | 1604 |
lemma const_poly_dvd_iff: |
| 65346 | 1605 |
fixes c :: "'a::{comm_semiring_1,semiring_no_zero_divisors}"
|
| 63498 | 1606 |
shows "[:c:] dvd p \<longleftrightarrow> (\<forall>n. c dvd coeff p n)" |
1607 |
proof (cases "c = 0 \<or> p = 0") |
|
| 65346 | 1608 |
case True |
1609 |
then show ?thesis |
|
1610 |
by (auto intro!: poly_eqI) |
|
1611 |
next |
|
| 63498 | 1612 |
case False |
1613 |
show ?thesis |
|
1614 |
proof |
|
1615 |
assume "[:c:] dvd p" |
|
| 65346 | 1616 |
then show "\<forall>n. c dvd coeff p n" |
| 76121 | 1617 |
by (auto simp: coeffs_def) |
| 63498 | 1618 |
next |
1619 |
assume *: "\<forall>n. c dvd coeff p n" |
|
| 65346 | 1620 |
define mydiv where "mydiv x y = (SOME z. x = y * z)" for x y :: 'a |
| 63498 | 1621 |
have mydiv: "x = y * mydiv x y" if "y dvd x" for x y |
1622 |
using that unfolding mydiv_def dvd_def by (rule someI_ex) |
|
1623 |
define q where "q = Poly (map (\<lambda>a. mydiv a c) (coeffs p))" |
|
1624 |
from False * have "p = q * [:c:]" |
|
| 65346 | 1625 |
by (intro poly_eqI) |
1626 |
(auto simp: q_def nth_default_def not_less length_coeffs_degree coeffs_nth |
|
1627 |
intro!: coeff_eq_0 mydiv) |
|
1628 |
then show "[:c:] dvd p" |
|
1629 |
by (simp only: dvd_triv_right) |
|
| 63498 | 1630 |
qed |
| 65346 | 1631 |
qed |
1632 |
||
1633 |
lemma const_poly_dvd_const_poly_iff [simp]: "[:a:] dvd [:b:] \<longleftrightarrow> a dvd b" |
|
1634 |
for a b :: "'a::{comm_semiring_1,semiring_no_zero_divisors}"
|
|
| 63498 | 1635 |
by (subst const_poly_dvd_iff) (auto simp: coeff_pCons split: nat.splits) |
1636 |
||
| 65346 | 1637 |
lemma lead_coeff_mult: "lead_coeff (p * q) = lead_coeff p * lead_coeff q" |
1638 |
for p q :: "'a::{comm_semiring_0, semiring_no_zero_divisors} poly"
|
|
1639 |
by (cases "p = 0 \<or> q = 0") (auto simp: coeff_mult_degree_sum degree_mult_eq) |
|
1640 |
||
|
73109
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1641 |
lemma lead_coeff_prod: "lead_coeff (prod f A) = (\<Prod>x\<in>A. lead_coeff (f x))" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1642 |
for f :: "'a \<Rightarrow> 'b::{comm_semiring_1, semiring_no_zero_divisors} poly"
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1643 |
by (induction A rule: infinite_finite_induct) (auto simp: lead_coeff_mult) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
1644 |
|
| 65346 | 1645 |
lemma lead_coeff_smult: "lead_coeff (smult c p) = c * lead_coeff p" |
1646 |
for p :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
| 64795 | 1647 |
proof - |
1648 |
have "smult c p = [:c:] * p" by simp |
|
1649 |
also have "lead_coeff \<dots> = c * lead_coeff p" |
|
1650 |
by (subst lead_coeff_mult) simp_all |
|
1651 |
finally show ?thesis . |
|
1652 |
qed |
|
1653 |
||
1654 |
lemma lead_coeff_1 [simp]: "lead_coeff 1 = 1" |
|
1655 |
by simp |
|
1656 |
||
| 65346 | 1657 |
lemma lead_coeff_power: "lead_coeff (p ^ n) = lead_coeff p ^ n" |
1658 |
for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
|
|
1659 |
by (induct n) (simp_all add: lead_coeff_mult) |
|
| 64795 | 1660 |
|
| 29451 | 1661 |
|
| 60500 | 1662 |
subsection \<open>Polynomials form an ordered integral domain\<close> |
| 29878 | 1663 |
|
| 63498 | 1664 |
definition pos_poly :: "'a::linordered_semidom poly \<Rightarrow> bool" |
| 65346 | 1665 |
where "pos_poly p \<longleftrightarrow> 0 < coeff p (degree p)" |
1666 |
||
1667 |
lemma pos_poly_pCons: "pos_poly (pCons a p) \<longleftrightarrow> pos_poly p \<or> (p = 0 \<and> 0 < a)" |
|
1668 |
by (simp add: pos_poly_def) |
|
| 29878 | 1669 |
|
1670 |
lemma not_pos_poly_0 [simp]: "\<not> pos_poly 0" |
|
| 65346 | 1671 |
by (simp add: pos_poly_def) |
1672 |
||
1673 |
lemma pos_poly_add: "pos_poly p \<Longrightarrow> pos_poly q \<Longrightarrow> pos_poly (p + q)" |
|
| 72750 | 1674 |
proof (induction p arbitrary: q) |
1675 |
case (pCons a p) |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
1676 |
then show ?case |
| 72750 | 1677 |
by (cases q; force simp add: pos_poly_pCons add_pos_pos) |
1678 |
qed auto |
|
| 29878 | 1679 |
|
| 65346 | 1680 |
lemma pos_poly_mult: "pos_poly p \<Longrightarrow> pos_poly q \<Longrightarrow> pos_poly (p * q)" |
| 72750 | 1681 |
by (simp add: pos_poly_def coeff_degree_mult) |
| 29878 | 1682 |
|
| 65346 | 1683 |
lemma pos_poly_total: "p = 0 \<or> pos_poly p \<or> pos_poly (- p)" |
1684 |
for p :: "'a::linordered_idom poly" |
|
1685 |
by (induct p) (auto simp: pos_poly_pCons) |
|
1686 |
||
1687 |
lemma pos_poly_coeffs [code]: "pos_poly p \<longleftrightarrow> (let as = coeffs p in as \<noteq> [] \<and> last as > 0)" |
|
1688 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
| 52380 | 1689 |
proof |
| 65346 | 1690 |
assume ?rhs |
1691 |
then show ?lhs |
|
1692 |
by (auto simp add: pos_poly_def last_coeffs_eq_coeff_degree) |
|
| 52380 | 1693 |
next |
| 65346 | 1694 |
assume ?lhs |
1695 |
then have *: "0 < coeff p (degree p)" |
|
1696 |
by (simp add: pos_poly_def) |
|
1697 |
then have "p \<noteq> 0" |
|
1698 |
by auto |
|
1699 |
with * show ?rhs |
|
1700 |
by (simp add: last_coeffs_eq_coeff_degree) |
|
| 52380 | 1701 |
qed |
1702 |
||
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34973
diff
changeset
|
1703 |
instantiation poly :: (linordered_idom) linordered_idom |
| 29878 | 1704 |
begin |
1705 |
||
| 65346 | 1706 |
definition "x < y \<longleftrightarrow> pos_poly (y - x)" |
1707 |
||
1708 |
definition "x \<le> y \<longleftrightarrow> x = y \<or> pos_poly (y - x)" |
|
1709 |
||
1710 |
definition "\<bar>x::'a poly\<bar> = (if x < 0 then - x else x)" |
|
1711 |
||
1712 |
definition "sgn (x::'a poly) = (if x = 0 then 0 else if 0 < x then 1 else - 1)" |
|
| 29878 | 1713 |
|
| 60679 | 1714 |
instance |
1715 |
proof |
|
1716 |
fix x y z :: "'a poly" |
|
| 29878 | 1717 |
show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x" |
1718 |
unfolding less_eq_poly_def less_poly_def |
|
| 72750 | 1719 |
using pos_poly_add by force |
1720 |
then show "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y" |
|
1721 |
using less_eq_poly_def less_poly_def by force |
|
| 60679 | 1722 |
show "x \<le> x" |
| 65346 | 1723 |
by (simp add: less_eq_poly_def) |
| 60679 | 1724 |
show "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z" |
| 72750 | 1725 |
using less_eq_poly_def pos_poly_add by fastforce |
| 60679 | 1726 |
show "x \<le> y \<Longrightarrow> z + x \<le> z + y" |
| 72750 | 1727 |
by (simp add: less_eq_poly_def) |
| 29878 | 1728 |
show "x \<le> y \<or> y \<le> x" |
1729 |
unfolding less_eq_poly_def |
|
1730 |
using pos_poly_total [of "x - y"] |
|
1731 |
by auto |
|
| 60679 | 1732 |
show "x < y \<Longrightarrow> 0 < z \<Longrightarrow> z * x < z * y" |
| 65346 | 1733 |
by (simp add: less_poly_def right_diff_distrib [symmetric] pos_poly_mult) |
| 29878 | 1734 |
show "\<bar>x\<bar> = (if x < 0 then - x else x)" |
1735 |
by (rule abs_poly_def) |
|
1736 |
show "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)" |
|
1737 |
by (rule sgn_poly_def) |
|
1738 |
qed |
|
1739 |
||
1740 |
end |
|
1741 |
||
| 60500 | 1742 |
text \<open>TODO: Simplification rules for comparisons\<close> |
| 29878 | 1743 |
|
1744 |
||
| 60500 | 1745 |
subsection \<open>Synthetic division and polynomial roots\<close> |
| 52380 | 1746 |
|
| 65346 | 1747 |
subsubsection \<open>Synthetic division\<close> |
1748 |
||
| 69597 | 1749 |
text \<open>Synthetic division is simply division by the linear polynomial \<^term>\<open>x - c\<close>.\<close> |
| 52380 | 1750 |
|
1751 |
definition synthetic_divmod :: "'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a poly \<times> 'a" |
|
| 65346 | 1752 |
where "synthetic_divmod p c = fold_coeffs (\<lambda>a (q, r). (pCons r q, a + c * r)) p (0, 0)" |
| 52380 | 1753 |
|
1754 |
definition synthetic_div :: "'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a poly" |
|
| 65346 | 1755 |
where "synthetic_div p c = fst (synthetic_divmod p c)" |
1756 |
||
1757 |
lemma synthetic_divmod_0 [simp]: "synthetic_divmod 0 c = (0, 0)" |
|
| 52380 | 1758 |
by (simp add: synthetic_divmod_def) |
1759 |
||
1760 |
lemma synthetic_divmod_pCons [simp]: |
|
1761 |
"synthetic_divmod (pCons a p) c = (\<lambda>(q, r). (pCons r q, a + c * r)) (synthetic_divmod p c)" |
|
1762 |
by (cases "p = 0 \<and> a = 0") (auto simp add: synthetic_divmod_def) |
|
1763 |
||
| 65346 | 1764 |
lemma synthetic_div_0 [simp]: "synthetic_div 0 c = 0" |
1765 |
by (simp add: synthetic_div_def) |
|
| 52380 | 1766 |
|
1767 |
lemma synthetic_div_unique_lemma: "smult c p = pCons a p \<Longrightarrow> p = 0" |
|
| 65346 | 1768 |
by (induct p arbitrary: a) simp_all |
1769 |
||
1770 |
lemma snd_synthetic_divmod: "snd (synthetic_divmod p c) = poly p c" |
|
1771 |
by (induct p) (simp_all add: split_def) |
|
| 52380 | 1772 |
|
1773 |
lemma synthetic_div_pCons [simp]: |
|
1774 |
"synthetic_div (pCons a p) c = pCons (poly p c) (synthetic_div p c)" |
|
| 65346 | 1775 |
by (simp add: synthetic_div_def split_def snd_synthetic_divmod) |
1776 |
||
1777 |
lemma synthetic_div_eq_0_iff: "synthetic_div p c = 0 \<longleftrightarrow> degree p = 0" |
|
| 63649 | 1778 |
proof (induct p) |
1779 |
case 0 |
|
1780 |
then show ?case by simp |
|
1781 |
next |
|
1782 |
case (pCons a p) |
|
1783 |
then show ?case by (cases p) simp |
|
1784 |
qed |
|
| 52380 | 1785 |
|
| 65346 | 1786 |
lemma degree_synthetic_div: "degree (synthetic_div p c) = degree p - 1" |
| 63649 | 1787 |
by (induct p) (simp_all add: synthetic_div_eq_0_iff) |
| 52380 | 1788 |
|
1789 |
lemma synthetic_div_correct: |
|
1790 |
"p + smult c (synthetic_div p c) = pCons (poly p c) (synthetic_div p c)" |
|
1791 |
by (induct p) simp_all |
|
1792 |
||
| 65346 | 1793 |
lemma synthetic_div_unique: "p + smult c q = pCons r q \<Longrightarrow> r = poly p c \<and> q = synthetic_div p c" |
| 72750 | 1794 |
proof (induction p arbitrary: q r) |
1795 |
case 0 |
|
1796 |
then show ?case |
|
1797 |
using synthetic_div_unique_lemma by fastforce |
|
1798 |
next |
|
1799 |
case (pCons a p) |
|
1800 |
then show ?case |
|
1801 |
by (cases q; force) |
|
1802 |
qed |
|
| 65346 | 1803 |
|
1804 |
lemma synthetic_div_correct': "[:-c, 1:] * synthetic_div p c + [:poly p c:] = p" |
|
1805 |
for c :: "'a::comm_ring_1" |
|
1806 |
using synthetic_div_correct [of p c] by (simp add: algebra_simps) |
|
1807 |
||
1808 |
||
| 64795 | 1809 |
subsubsection \<open>Polynomial roots\<close> |
| 65346 | 1810 |
|
1811 |
lemma poly_eq_0_iff_dvd: "poly p c = 0 \<longleftrightarrow> [:- c, 1:] dvd p" |
|
1812 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
1813 |
for c :: "'a::comm_ring_1" |
|
| 52380 | 1814 |
proof |
| 65346 | 1815 |
assume ?lhs |
1816 |
with synthetic_div_correct' [of c p] have "p = [:-c, 1:] * synthetic_div p c" by simp |
|
1817 |
then show ?rhs .. |
|
| 52380 | 1818 |
next |
| 65346 | 1819 |
assume ?rhs |
| 52380 | 1820 |
then obtain k where "p = [:-c, 1:] * k" by (rule dvdE) |
| 65346 | 1821 |
then show ?lhs by simp |
| 52380 | 1822 |
qed |
1823 |
||
| 65346 | 1824 |
lemma dvd_iff_poly_eq_0: "[:c, 1:] dvd p \<longleftrightarrow> poly p (- c) = 0" |
1825 |
for c :: "'a::comm_ring_1" |
|
| 52380 | 1826 |
by (simp add: poly_eq_0_iff_dvd) |
1827 |
||
| 65346 | 1828 |
lemma poly_roots_finite: "p \<noteq> 0 \<Longrightarrow> finite {x. poly p x = 0}"
|
1829 |
for p :: "'a::{comm_ring_1,ring_no_zero_divisors} poly"
|
|
| 52380 | 1830 |
proof (induct n \<equiv> "degree p" arbitrary: p) |
| 65346 | 1831 |
case 0 |
| 52380 | 1832 |
then obtain a where "a \<noteq> 0" and "p = [:a:]" |
| 65346 | 1833 |
by (cases p) (simp split: if_splits) |
1834 |
then show "finite {x. poly p x = 0}"
|
|
1835 |
by simp |
|
| 52380 | 1836 |
next |
| 65346 | 1837 |
case (Suc n) |
| 52380 | 1838 |
show "finite {x. poly p x = 0}"
|
1839 |
proof (cases "\<exists>x. poly p x = 0") |
|
1840 |
case False |
|
1841 |
then show "finite {x. poly p x = 0}" by simp
|
|
1842 |
next |
|
1843 |
case True |
|
1844 |
then obtain a where "poly p a = 0" .. |
|
| 65346 | 1845 |
then have "[:-a, 1:] dvd p" |
1846 |
by (simp only: poly_eq_0_iff_dvd) |
|
| 52380 | 1847 |
then obtain k where k: "p = [:-a, 1:] * k" .. |
| 65346 | 1848 |
with \<open>p \<noteq> 0\<close> have "k \<noteq> 0" |
1849 |
by auto |
|
| 52380 | 1850 |
with k have "degree p = Suc (degree k)" |
1851 |
by (simp add: degree_mult_eq del: mult_pCons_left) |
|
| 65346 | 1852 |
with \<open>Suc n = degree p\<close> have "n = degree k" |
1853 |
by simp |
|
1854 |
from this \<open>k \<noteq> 0\<close> have "finite {x. poly k x = 0}"
|
|
1855 |
by (rule Suc.hyps) |
|
1856 |
then have "finite (insert a {x. poly k x = 0})"
|
|
1857 |
by simp |
|
| 52380 | 1858 |
then show "finite {x. poly p x = 0}"
|
| 57862 | 1859 |
by (simp add: k Collect_disj_eq del: mult_pCons_left) |
| 52380 | 1860 |
qed |
1861 |
qed |
|
1862 |
||
| 65346 | 1863 |
lemma poly_eq_poly_eq_iff: "poly p = poly q \<longleftrightarrow> p = q" |
1864 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
1865 |
for p q :: "'a::{comm_ring_1,ring_no_zero_divisors,ring_char_0} poly"
|
|
| 52380 | 1866 |
proof |
| 65346 | 1867 |
assume ?rhs |
1868 |
then show ?lhs by simp |
|
| 52380 | 1869 |
next |
| 65346 | 1870 |
assume ?lhs |
1871 |
have "poly p = poly 0 \<longleftrightarrow> p = 0" for p :: "'a poly" |
|
| 72750 | 1872 |
proof (cases "p = 0") |
1873 |
case False |
|
1874 |
then show ?thesis |
|
1875 |
by (auto simp add: infinite_UNIV_char_0 dest: poly_roots_finite) |
|
1876 |
qed auto |
|
| 65346 | 1877 |
from \<open>?lhs\<close> and this [of "p - q"] show ?rhs |
1878 |
by auto |
|
| 52380 | 1879 |
qed |
1880 |
||
| 65346 | 1881 |
lemma poly_all_0_iff_0: "(\<forall>x. poly p x = 0) \<longleftrightarrow> p = 0" |
1882 |
for p :: "'a::{ring_char_0,comm_ring_1,ring_no_zero_divisors} poly"
|
|
| 52380 | 1883 |
by (auto simp add: poly_eq_poly_eq_iff [symmetric]) |
1884 |
||
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1885 |
lemma card_poly_roots_bound: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1886 |
fixes p :: "'a::{comm_ring_1,ring_no_zero_divisors} poly"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1887 |
assumes "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1888 |
shows "card {x. poly p x = 0} \<le> degree p"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1889 |
using assms |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1890 |
proof (induction "degree p" arbitrary: p rule: less_induct) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1891 |
case (less p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1892 |
show ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1893 |
proof (cases "\<exists>x. poly p x = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1894 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1895 |
hence "{x. poly p x = 0} = {}" by blast
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1896 |
thus ?thesis by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1897 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1898 |
case True |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1899 |
then obtain x where x: "poly p x = 0" by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1900 |
hence "[:-x, 1:] dvd p" by (subst (asm) poly_eq_0_iff_dvd) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1901 |
then obtain q where q: "p = [:-x, 1:] * q" by (auto simp: dvd_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1902 |
with \<open>p \<noteq> 0\<close> have [simp]: "q \<noteq> 0" by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1903 |
have deg: "degree p = Suc (degree q)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1904 |
by (subst q, subst degree_mult_eq) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1905 |
have "card {x. poly p x = 0} \<le> card (insert x {x. poly q x = 0})"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1906 |
by (intro card_mono) (auto intro: poly_roots_finite simp: q) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1907 |
also have "\<dots> \<le> Suc (card {x. poly q x = 0})"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1908 |
by (rule card_insert_le_m1) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1909 |
also from deg have "card {x. poly q x = 0} \<le> degree q"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1910 |
using \<open>p \<noteq> 0\<close> and q by (intro less) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1911 |
also have "Suc \<dots> = degree p" by (simp add: deg) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1912 |
finally show ?thesis by - simp_all |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1913 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1914 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1915 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1916 |
lemma poly_eqI_degree: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1917 |
fixes p q :: "'a :: {comm_ring_1, ring_no_zero_divisors} poly"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1918 |
assumes "\<And>x. x \<in> A \<Longrightarrow> poly p x = poly q x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1919 |
assumes "card A > degree p" "card A > degree q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1920 |
shows "p = q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1921 |
proof (rule ccontr) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1922 |
assume neq: "p \<noteq> q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1923 |
have "degree (p - q) \<le> max (degree p) (degree q)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1924 |
by (rule degree_diff_le_max) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1925 |
also from assms have "\<dots> < card A" by linarith |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1926 |
also have "\<dots> \<le> card {x. poly (p - q) x = 0}"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1927 |
using neq and assms by (intro card_mono poly_roots_finite) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1928 |
finally have "degree (p - q) < card {x. poly (p - q) x = 0}" .
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1929 |
moreover have "degree (p - q) \<ge> card {x. poly (p - q) x = 0}"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1930 |
using neq by (intro card_poly_roots_bound) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1931 |
ultimately show False by linarith |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1932 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1933 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
1934 |
|
| 65346 | 1935 |
|
| 64795 | 1936 |
subsubsection \<open>Order of polynomial roots\<close> |
|
29977
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1937 |
|
| 52380 | 1938 |
definition order :: "'a::idom \<Rightarrow> 'a poly \<Rightarrow> nat" |
| 65346 | 1939 |
where "order a p = (LEAST n. \<not> [:-a, 1:] ^ Suc n dvd p)" |
1940 |
||
1941 |
lemma coeff_linear_power: "coeff ([:a, 1:] ^ n) n = 1" |
|
1942 |
for a :: "'a::comm_semiring_1" |
|
| 72750 | 1943 |
proof (induct n) |
1944 |
case (Suc n) |
|
1945 |
have "degree ([:a, 1:] ^ n) \<le> 1 * n" |
|
1946 |
by (metis One_nat_def degree_pCons_eq_if degree_power_le one_neq_zero one_pCons) |
|
1947 |
then have "coeff ([:a, 1:] ^ n) (Suc n) = 0" |
|
1948 |
by (simp add: coeff_eq_0) |
|
1949 |
then show ?case |
|
1950 |
using Suc.hyps by fastforce |
|
1951 |
qed auto |
|
| 65346 | 1952 |
|
1953 |
lemma degree_linear_power: "degree ([:a, 1:] ^ n) = n" |
|
1954 |
for a :: "'a::comm_semiring_1" |
|
| 72750 | 1955 |
proof (rule order_antisym) |
1956 |
show "degree ([:a, 1:] ^ n) \<le> n" |
|
1957 |
by (metis One_nat_def degree_pCons_eq_if degree_power_le mult.left_neutral one_neq_zero one_pCons) |
|
1958 |
qed (simp add: coeff_linear_power le_degree) |
|
|
29977
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1959 |
|
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1960 |
lemma order_1: "[:-a, 1:] ^ order a p dvd p" |
| 72750 | 1961 |
proof (cases "p = 0") |
1962 |
case False |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
1963 |
show ?thesis |
| 72750 | 1964 |
proof (cases "order a p") |
1965 |
case (Suc n) |
|
1966 |
then show ?thesis |
|
1967 |
by (metis lessI not_less_Least order_def) |
|
1968 |
qed auto |
|
1969 |
qed auto |
|
1970 |
||
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
1971 |
lemma order_2: |
|
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
1972 |
assumes "p \<noteq> 0" |
| 72750 | 1973 |
shows "\<not> [:-a, 1:] ^ Suc (order a p) dvd p" |
1974 |
proof - |
|
1975 |
have False if "[:- a, 1:] ^ Suc (degree p) dvd p" |
|
1976 |
using dvd_imp_degree_le [OF that] |
|
1977 |
by (metis Suc_n_not_le_n assms degree_linear_power) |
|
1978 |
then show ?thesis |
|
1979 |
unfolding order_def |
|
1980 |
by (metis (no_types, lifting) LeastI) |
|
1981 |
qed |
|
| 65346 | 1982 |
|
1983 |
lemma order: "p \<noteq> 0 \<Longrightarrow> [:-a, 1:] ^ order a p dvd p \<and> \<not> [:-a, 1:] ^ Suc (order a p) dvd p" |
|
1984 |
by (rule conjI [OF order_1 order_2]) |
|
|
29977
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1985 |
|
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1986 |
lemma order_degree: |
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1987 |
assumes p: "p \<noteq> 0" |
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1988 |
shows "order a p \<le> degree p" |
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1989 |
proof - |
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1990 |
have "order a p = degree ([:-a, 1:] ^ order a p)" |
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1991 |
by (simp only: degree_linear_power) |
| 65346 | 1992 |
also from order_1 p have "\<dots> \<le> degree p" |
1993 |
by (rule dvd_imp_degree_le) |
|
|
29977
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1994 |
finally show ?thesis . |
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1995 |
qed |
|
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
1996 |
|
| 72750 | 1997 |
lemma order_root: "poly p a = 0 \<longleftrightarrow> p = 0 \<or> order a p \<noteq> 0" (is "?lhs = ?rhs") |
1998 |
proof |
|
1999 |
show "?lhs \<Longrightarrow> ?rhs" |
|
2000 |
by (metis One_nat_def order_2 poly_eq_0_iff_dvd power_one_right) |
|
2001 |
show "?rhs \<Longrightarrow> ?lhs" |
|
2002 |
by (meson dvd_power dvd_trans neq0_conv order_1 poly_0 poly_eq_0_iff_dvd) |
|
2003 |
qed |
|
|
29977
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
2004 |
|
| 62065 | 2005 |
lemma order_0I: "poly p a \<noteq> 0 \<Longrightarrow> order a p = 0" |
2006 |
by (subst (asm) order_root) auto |
|
2007 |
||
| 64795 | 2008 |
lemma order_unique_lemma: |
2009 |
fixes p :: "'a::idom poly" |
|
2010 |
assumes "[:-a, 1:] ^ n dvd p" "\<not> [:-a, 1:] ^ Suc n dvd p" |
|
| 72750 | 2011 |
shows "order a p = n" |
| 65346 | 2012 |
unfolding Polynomial.order_def |
| 72750 | 2013 |
by (metis (mono_tags, lifting) Least_equality assms not_less_eq_eq power_le_dvd) |
2014 |
||
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
2015 |
lemma order_mult: |
| 72750 | 2016 |
assumes "p * q \<noteq> 0" shows "order a (p * q) = order a p + order a q" |
| 64795 | 2017 |
proof - |
| 72750 | 2018 |
define i where "i \<equiv> order a p" |
2019 |
define j where "j \<equiv> order a q" |
|
2020 |
define t where "t \<equiv> [:-a, 1:]" |
|
| 64795 | 2021 |
have t_dvd_iff: "\<And>u. t dvd u \<longleftrightarrow> poly u a = 0" |
| 65346 | 2022 |
by (simp add: t_def dvd_iff_poly_eq_0) |
| 72750 | 2023 |
have dvd: "t ^ i dvd p" "t ^ j dvd q" and "\<not> t ^ Suc i dvd p" "\<not> t ^ Suc j dvd q" |
2024 |
using assms i_def j_def order_1 order_2 t_def by auto |
|
2025 |
then have "\<not> t ^ Suc(i + j) dvd p * q" |
|
2026 |
by (elim dvdE) (simp add: power_add t_dvd_iff) |
|
2027 |
moreover have "t ^ (i + j) dvd p * q" |
|
2028 |
using dvd by (simp add: mult_dvd_mono power_add) |
|
2029 |
ultimately show "order a (p * q) = i + j" |
|
2030 |
using order_unique_lemma t_def by blast |
|
| 64795 | 2031 |
qed |
2032 |
||
| 72750 | 2033 |
|
| 64795 | 2034 |
lemma order_smult: |
| 65346 | 2035 |
assumes "c \<noteq> 0" |
| 64795 | 2036 |
shows "order x (smult c p) = order x p" |
2037 |
proof (cases "p = 0") |
|
| 65346 | 2038 |
case True |
2039 |
then show ?thesis |
|
2040 |
by simp |
|
2041 |
next |
|
| 64795 | 2042 |
case False |
2043 |
have "smult c p = [:c:] * p" by simp |
|
| 65346 | 2044 |
also from assms False have "order x \<dots> = order x [:c:] + order x p" |
| 64795 | 2045 |
by (subst order_mult) simp_all |
| 65346 | 2046 |
also have "order x [:c:] = 0" |
2047 |
by (rule order_0I) (use assms in auto) |
|
2048 |
finally show ?thesis |
|
2049 |
by simp |
|
2050 |
qed |
|
| 64795 | 2051 |
|
|
79672
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2052 |
lemma order_gt_0_iff: "p \<noteq> 0 \<Longrightarrow> order x p > 0 \<longleftrightarrow> poly p x = 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2053 |
by (subst order_root) auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2054 |
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2055 |
lemma order_eq_0_iff: "p \<noteq> 0 \<Longrightarrow> order x p = 0 \<longleftrightarrow> poly p x \<noteq> 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2056 |
by (subst order_root) auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2057 |
|
| 72750 | 2058 |
text \<open>Next three lemmas contributed by Wenda Li\<close> |
| 65346 | 2059 |
lemma order_1_eq_0 [simp]:"order x 1 = 0" |
| 64795 | 2060 |
by (metis order_root poly_1 zero_neq_one) |
2061 |
||
|
68532
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
2062 |
lemma order_uminus[simp]: "order x (-p) = order x p" |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
2063 |
by (metis neg_equal_0_iff_equal order_smult smult_1_left smult_minus_left) |
|
68532
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
2064 |
|
| 65346 | 2065 |
lemma order_power_n_n: "order a ([:-a,1:]^n)=n" |
| 64795 | 2066 |
proof (induct n) (*might be proved more concisely using nat_less_induct*) |
2067 |
case 0 |
|
| 65346 | 2068 |
then show ?case |
2069 |
by (metis order_root poly_1 power_0 zero_neq_one) |
|
2070 |
next |
|
| 64795 | 2071 |
case (Suc n) |
| 65346 | 2072 |
have "order a ([:- a, 1:] ^ Suc n) = order a ([:- a, 1:] ^ n) + order a [:-a,1:]" |
|
73932
fd21b4a93043
added opaque_combs and renamed hide_lams to opaque_lifting
desharna
parents:
73510
diff
changeset
|
2073 |
by (metis (no_types, opaque_lifting) One_nat_def add_Suc_right monoid_add_class.add.right_neutral |
| 64795 | 2074 |
one_neq_zero order_mult pCons_eq_0_iff power_add power_eq_0_iff power_one_right) |
| 65346 | 2075 |
moreover have "order a [:-a,1:] = 1" |
2076 |
unfolding order_def |
|
2077 |
proof (rule Least_equality, rule notI) |
|
2078 |
assume "[:- a, 1:] ^ Suc 1 dvd [:- a, 1:]" |
|
2079 |
then have "degree ([:- a, 1:] ^ Suc 1) \<le> degree ([:- a, 1:])" |
|
2080 |
by (rule dvd_imp_degree_le) auto |
|
2081 |
then show False |
|
2082 |
by auto |
|
2083 |
next |
|
2084 |
fix y |
|
2085 |
assume *: "\<not> [:- a, 1:] ^ Suc y dvd [:- a, 1:]" |
|
2086 |
show "1 \<le> y" |
|
2087 |
proof (rule ccontr) |
|
2088 |
assume "\<not> 1 \<le> y" |
|
2089 |
then have "y = 0" by auto |
|
2090 |
then have "[:- a, 1:] ^ Suc y dvd [:- a, 1:]" by auto |
|
2091 |
with * show False by auto |
|
| 64795 | 2092 |
qed |
| 65346 | 2093 |
qed |
2094 |
ultimately show ?case |
|
2095 |
using Suc by auto |
|
| 64795 | 2096 |
qed |
2097 |
||
| 65346 | 2098 |
lemma order_0_monom [simp]: "c \<noteq> 0 \<Longrightarrow> order 0 (monom c n) = n" |
2099 |
using order_power_n_n[of 0 n] by (simp add: monom_altdef order_smult) |
|
2100 |
||
2101 |
lemma dvd_imp_order_le: "q \<noteq> 0 \<Longrightarrow> p dvd q \<Longrightarrow> Polynomial.order a p \<le> Polynomial.order a q" |
|
| 76121 | 2102 |
by (auto simp: order_mult) |
| 64795 | 2103 |
|
| 65346 | 2104 |
text \<open>Now justify the standard squarefree decomposition, i.e. \<open>f / gcd f f'\<close>.\<close> |
| 64795 | 2105 |
|
2106 |
lemma order_divides: "[:-a, 1:] ^ n dvd p \<longleftrightarrow> p = 0 \<or> n \<le> order a p" |
|
| 72750 | 2107 |
by (meson dvd_0_right not_less_eq_eq order_1 order_2 power_le_dvd) |
| 64795 | 2108 |
|
2109 |
lemma order_decomp: |
|
2110 |
assumes "p \<noteq> 0" |
|
2111 |
shows "\<exists>q. p = [:- a, 1:] ^ order a p * q \<and> \<not> [:- a, 1:] dvd q" |
|
2112 |
proof - |
|
| 65346 | 2113 |
from assms have *: "[:- a, 1:] ^ order a p dvd p" |
2114 |
and **: "\<not> [:- a, 1:] ^ Suc (order a p) dvd p" |
|
2115 |
by (auto dest: order) |
|
2116 |
from * obtain q where q: "p = [:- a, 1:] ^ order a p * q" .. |
|
2117 |
with ** have "\<not> [:- a, 1:] ^ Suc (order a p) dvd [:- a, 1:] ^ order a p * q" |
|
| 64795 | 2118 |
by simp |
2119 |
then have "\<not> [:- a, 1:] ^ order a p * [:- a, 1:] dvd [:- a, 1:] ^ order a p * q" |
|
2120 |
by simp |
|
| 65346 | 2121 |
with idom_class.dvd_mult_cancel_left [of "[:- a, 1:] ^ order a p" "[:- a, 1:]" q] |
2122 |
have "\<not> [:- a, 1:] dvd q" by auto |
|
2123 |
with q show ?thesis by blast |
|
| 64795 | 2124 |
qed |
2125 |
||
| 65346 | 2126 |
lemma monom_1_dvd_iff: "p \<noteq> 0 \<Longrightarrow> monom 1 n dvd p \<longleftrightarrow> n \<le> order 0 p" |
2127 |
using order_divides[of 0 n p] by (simp add: monom_altdef) |
|
| 64795 | 2128 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2129 |
lemma poly_root_order_induct [case_names 0 no_roots root]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2130 |
fixes p :: "'a :: idom poly" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2131 |
assumes "P 0" "\<And>p. (\<And>x. poly p x \<noteq> 0) \<Longrightarrow> P p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2132 |
"\<And>p x n. n > 0 \<Longrightarrow> poly p x \<noteq> 0 \<Longrightarrow> P p \<Longrightarrow> P ([:-x, 1:] ^ n * p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2133 |
shows "P p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2134 |
proof (induction "degree p" arbitrary: p rule: less_induct) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2135 |
case (less p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2136 |
consider "p = 0" | "p \<noteq> 0" "\<exists>x. poly p x = 0" | "\<And>x. poly p x \<noteq> 0" by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2137 |
thus ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2138 |
proof cases |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2139 |
case 3 |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2140 |
with assms(2)[of p] show ?thesis by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2141 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2142 |
case 2 |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2143 |
then obtain x where x: "poly p x = 0" by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2144 |
have "[:-x, 1:] ^ order x p dvd p" by (intro order_1) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2145 |
then obtain q where q: "p = [:-x, 1:] ^ order x p * q" by (auto simp: dvd_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2146 |
with 2 have [simp]: "q \<noteq> 0" by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2147 |
have order_pos: "order x p > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2148 |
using \<open>p \<noteq> 0\<close> and x by (auto simp: order_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2149 |
have "order x p = order x p + order x q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2150 |
by (subst q, subst order_mult) (auto simp: order_power_n_n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2151 |
hence [simp]: "order x q = 0" by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2152 |
have deg: "degree p = order x p + degree q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2153 |
by (subst q, subst degree_mult_eq) (auto simp: degree_power_eq) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2154 |
with order_pos have "degree q < degree p" by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2155 |
hence "P q" by (rule less) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2156 |
with order_pos have "P ([:-x, 1:] ^ order x p * q)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2157 |
by (intro assms(3)) (auto simp: order_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2158 |
with q show ?thesis by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2159 |
qed (simp_all add: assms(1)) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2160 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2161 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2162 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2163 |
context |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2164 |
includes multiset.lifting |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2165 |
begin |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2166 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2167 |
lift_definition proots :: "('a :: idom) poly \<Rightarrow> 'a multiset" is
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2168 |
"\<lambda>(p :: 'a poly) (x :: 'a). if p = 0 then 0 else order x p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2169 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2170 |
fix p :: "'a poly" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2171 |
show "finite {x. 0 < (if p = 0 then 0 else order x p)}"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2172 |
by (cases "p = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2173 |
(auto simp: order_gt_0_iff intro: finite_subset[OF _ poly_roots_finite[of p]]) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2174 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2175 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2176 |
lemma proots_0 [simp]: "proots (0 :: 'a :: idom poly) = {#}"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2177 |
by transfer' auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2178 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2179 |
lemma proots_1 [simp]: "proots (1 :: 'a :: idom poly) = {#}"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2180 |
by transfer' auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2181 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2182 |
lemma proots_const [simp]: "proots [: x :] = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2183 |
by transfer' (auto split: if_splits simp: fun_eq_iff order_eq_0_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2184 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2185 |
lemma proots_numeral [simp]: "proots (numeral n) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2186 |
by (simp add: numeral_poly) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2187 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2188 |
lemma count_proots [simp]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2189 |
"p \<noteq> 0 \<Longrightarrow> count (proots p) a = order a p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2190 |
by transfer' auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2191 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2192 |
lemma set_count_proots [simp]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2193 |
"p \<noteq> 0 \<Longrightarrow> set_mset (proots p) = {x. poly p x = 0}"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2194 |
by (auto simp: set_mset_def order_gt_0_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2195 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2196 |
lemma proots_uminus [simp]: "proots (-p) = proots p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2197 |
by (cases "p = 0"; rule multiset_eqI) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2198 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2199 |
lemma proots_smult [simp]: "c \<noteq> 0 \<Longrightarrow> proots (smult c p) = proots p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2200 |
by (cases "p = 0"; rule multiset_eqI) (auto simp: order_smult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2201 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2202 |
lemma proots_mult: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2203 |
assumes "p \<noteq> 0" "q \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2204 |
shows "proots (p * q) = proots p + proots q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2205 |
using assms by (intro multiset_eqI) (auto simp: order_mult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2206 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2207 |
lemma proots_prod: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2208 |
assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2209 |
shows "proots (\<Prod>x\<in>A. f x) = (\<Sum>x\<in>A. proots (f x))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2210 |
using assms by (induction A rule: infinite_finite_induct) (auto simp: proots_mult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2211 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2212 |
lemma proots_prod_mset: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2213 |
assumes "0 \<notin># A" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2214 |
shows "proots (\<Prod>p\<in>#A. p) = (\<Sum>p\<in>#A. proots p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2215 |
using assms by (induction A) (auto simp: proots_mult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2216 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2217 |
lemma proots_prod_list: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2218 |
assumes "0 \<notin> set ps" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2219 |
shows "proots (\<Prod>p\<leftarrow>ps. p) = (\<Sum>p\<leftarrow>ps. proots p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2220 |
using assms by (induction ps) (auto simp: proots_mult prod_list_zero_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2221 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2222 |
lemma proots_power: "proots (p ^ n) = repeat_mset n (proots p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2223 |
proof (cases "p = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2224 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2225 |
thus ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2226 |
by (induction n) (auto simp: proots_mult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2227 |
qed (auto simp: power_0_left) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2228 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2229 |
lemma proots_linear_factor [simp]: "proots [:x, 1:] = {#-x#}"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2230 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2231 |
have "order (-x) [:x, 1:] > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2232 |
by (subst order_gt_0_iff) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2233 |
moreover have "order (-x) [:x, 1:] \<le> degree [:x, 1:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2234 |
by (rule order_degree) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2235 |
moreover have "order y [:x, 1:] = 0" if "y \<noteq> -x" for y |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2236 |
by (rule order_0I) (use that in \<open>auto simp: add_eq_0_iff\<close>) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2237 |
ultimately show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2238 |
by (intro multiset_eqI) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2239 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2240 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2241 |
lemma size_proots_le: "size (proots p) \<le> degree p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2242 |
proof (induction p rule: poly_root_order_induct) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2243 |
case (no_roots p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2244 |
hence "proots p = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2245 |
by (simp add: multiset_eqI order_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2246 |
thus ?case by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2247 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2248 |
case (root p x n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2249 |
have [simp]: "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2250 |
using root.hyps by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2251 |
from root.IH show ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2252 |
by (auto simp: proots_mult proots_power degree_mult_eq degree_power_eq) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2253 |
qed auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2254 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2255 |
end |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2256 |
|
|
29977
d76b830366bc
move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents:
29904
diff
changeset
|
2257 |
|
| 62065 | 2258 |
subsection \<open>Additional induction rules on polynomials\<close> |
2259 |
||
2260 |
text \<open> |
|
| 65346 | 2261 |
An induction rule for induction over the roots of a polynomial with a certain property. |
| 62065 | 2262 |
(e.g. all positive roots) |
2263 |
\<close> |
|
2264 |
lemma poly_root_induct [case_names 0 no_roots root]: |
|
2265 |
fixes p :: "'a :: idom poly" |
|
2266 |
assumes "Q 0" |
|
| 65346 | 2267 |
and "\<And>p. (\<And>a. P a \<Longrightarrow> poly p a \<noteq> 0) \<Longrightarrow> Q p" |
2268 |
and "\<And>a p. P a \<Longrightarrow> Q p \<Longrightarrow> Q ([:a, -1:] * p)" |
|
2269 |
shows "Q p" |
|
| 62065 | 2270 |
proof (induction "degree p" arbitrary: p rule: less_induct) |
2271 |
case (less p) |
|
2272 |
show ?case |
|
2273 |
proof (cases "p = 0") |
|
| 65346 | 2274 |
case True |
2275 |
with assms(1) show ?thesis by simp |
|
2276 |
next |
|
2277 |
case False |
|
2278 |
show ?thesis |
|
| 62065 | 2279 |
proof (cases "\<exists>a. P a \<and> poly p a = 0") |
2280 |
case False |
|
| 65346 | 2281 |
then show ?thesis by (intro assms(2)) blast |
| 62065 | 2282 |
next |
2283 |
case True |
|
| 65346 | 2284 |
then obtain a where a: "P a" "poly p a = 0" |
| 62065 | 2285 |
by blast |
| 65346 | 2286 |
then have "-[:-a, 1:] dvd p" |
| 62065 | 2287 |
by (subst minus_dvd_iff) (simp add: poly_eq_0_iff_dvd) |
2288 |
then obtain q where q: "p = [:a, -1:] * q" by (elim dvdE) simp |
|
| 65346 | 2289 |
with False have "q \<noteq> 0" by auto |
| 62065 | 2290 |
have "degree p = Suc (degree q)" |
| 65346 | 2291 |
by (subst q, subst degree_mult_eq) (simp_all add: \<open>q \<noteq> 0\<close>) |
2292 |
then have "Q q" by (intro less) simp |
|
2293 |
with a(1) have "Q ([:a, -1:] * q)" |
|
| 62065 | 2294 |
by (rule assms(3)) |
2295 |
with q show ?thesis by simp |
|
2296 |
qed |
|
| 65346 | 2297 |
qed |
| 62065 | 2298 |
qed |
2299 |
||
| 65346 | 2300 |
lemma dropWhile_replicate_append: |
| 67399 | 2301 |
"dropWhile ((=) a) (replicate n a @ ys) = dropWhile ((=) a) ys" |
| 65346 | 2302 |
by (induct n) simp_all |
| 62065 | 2303 |
|
2304 |
lemma Poly_append_replicate_0: "Poly (xs @ replicate n 0) = Poly xs" |
|
2305 |
by (subst coeffs_eq_iff) (simp_all add: strip_while_def dropWhile_replicate_append) |
|
2306 |
||
2307 |
text \<open> |
|
| 65346 | 2308 |
An induction rule for simultaneous induction over two polynomials, |
| 62065 | 2309 |
prepending one coefficient in each step. |
2310 |
\<close> |
|
2311 |
lemma poly_induct2 [case_names 0 pCons]: |
|
2312 |
assumes "P 0 0" "\<And>a p b q. P p q \<Longrightarrow> P (pCons a p) (pCons b q)" |
|
| 65346 | 2313 |
shows "P p q" |
| 62065 | 2314 |
proof - |
| 63040 | 2315 |
define n where "n = max (length (coeffs p)) (length (coeffs q))" |
2316 |
define xs where "xs = coeffs p @ (replicate (n - length (coeffs p)) 0)" |
|
2317 |
define ys where "ys = coeffs q @ (replicate (n - length (coeffs q)) 0)" |
|
| 65346 | 2318 |
have "length xs = length ys" |
| 62065 | 2319 |
by (simp add: xs_def ys_def n_def) |
| 65346 | 2320 |
then have "P (Poly xs) (Poly ys)" |
2321 |
by (induct rule: list_induct2) (simp_all add: assms) |
|
2322 |
also have "Poly xs = p" |
|
| 62065 | 2323 |
by (simp add: xs_def Poly_append_replicate_0) |
| 65346 | 2324 |
also have "Poly ys = q" |
| 62065 | 2325 |
by (simp add: ys_def Poly_append_replicate_0) |
2326 |
finally show ?thesis . |
|
2327 |
qed |
|
2328 |
||
| 65346 | 2329 |
|
| 60500 | 2330 |
subsection \<open>Composition of polynomials\<close> |
| 29478 | 2331 |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
2332 |
(* Several lemmas contributed by René Thiemann and Akihisa Yamada *) |
|
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
2333 |
|
| 52380 | 2334 |
definition pcompose :: "'a::comm_semiring_0 poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
| 65346 | 2335 |
where "pcompose p q = fold_coeffs (\<lambda>a c. [:a:] + q * c) p 0" |
| 52380 | 2336 |
|
|
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80786
diff
changeset
|
2337 |
notation pcompose (infixl \<open>\<circ>\<^sub>p\<close> 71) |
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
2338 |
|
| 65346 | 2339 |
lemma pcompose_0 [simp]: "pcompose 0 q = 0" |
| 52380 | 2340 |
by (simp add: pcompose_def) |
| 65346 | 2341 |
|
2342 |
lemma pcompose_pCons: "pcompose (pCons a p) q = [:a:] + q * pcompose p q" |
|
| 52380 | 2343 |
by (cases "p = 0 \<and> a = 0") (auto simp add: pcompose_def) |
2344 |
||
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2345 |
lemma pcompose_altdef: "pcompose p q = poly (map_poly (\<lambda>x. [:x:]) p) q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2346 |
by (induction p) (simp_all add: map_poly_pCons pcompose_pCons) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2347 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2348 |
lemma coeff_pcompose_0 [simp]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2349 |
"coeff (pcompose p q) 0 = poly p (coeff q 0)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2350 |
by (induction p) (simp_all add: coeff_mult_0 pcompose_pCons) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2351 |
|
| 65346 | 2352 |
lemma pcompose_1: "pcompose 1 p = 1" |
2353 |
for p :: "'a::comm_semiring_1 poly" |
|
| 65486 | 2354 |
by (auto simp: one_pCons pcompose_pCons) |
| 65346 | 2355 |
|
2356 |
lemma poly_pcompose: "poly (pcompose p q) x = poly p (poly q x)" |
|
| 52380 | 2357 |
by (induct p) (simp_all add: pcompose_pCons) |
2358 |
||
| 65346 | 2359 |
lemma degree_pcompose_le: "degree (pcompose p q) \<le> degree p * degree q" |
| 72750 | 2360 |
proof (induction p) |
2361 |
case (pCons a p) |
|
2362 |
then show ?case |
|
2363 |
proof (clarsimp simp add: pcompose_pCons) |
|
2364 |
assume "degree (p \<circ>\<^sub>p q) \<le> degree p * degree q" "p \<noteq> 0" |
|
2365 |
then have "degree (q * p \<circ>\<^sub>p q) \<le> degree q + degree p * degree q" |
|
2366 |
by (meson add_le_cancel_left degree_mult_le dual_order.trans pCons.IH) |
|
2367 |
then show "degree ([:a:] + q * p \<circ>\<^sub>p q) \<le> degree q + degree p * degree q" |
|
2368 |
by (simp add: degree_add_le) |
|
2369 |
qed |
|
2370 |
qed auto |
|
| 65346 | 2371 |
|
2372 |
lemma pcompose_add: "pcompose (p + q) r = pcompose p r + pcompose q r" |
|
2373 |
for p q r :: "'a::{comm_semiring_0, ab_semigroup_add} poly"
|
|
| 62065 | 2374 |
proof (induction p q rule: poly_induct2) |
| 65346 | 2375 |
case 0 |
2376 |
then show ?case by simp |
|
2377 |
next |
|
| 62065 | 2378 |
case (pCons a p b q) |
| 65346 | 2379 |
have "pcompose (pCons a p + pCons b q) r = [:a + b:] + r * pcompose p r + r * pcompose q r" |
| 62065 | 2380 |
by (simp_all add: pcompose_pCons pCons.IH algebra_simps) |
2381 |
also have "[:a + b:] = [:a:] + [:b:]" by simp |
|
| 72750 | 2382 |
also have "\<dots> + r * pcompose p r + r * pcompose q r = pcompose (pCons a p) r + pcompose (pCons b q) r" |
| 62065 | 2383 |
by (simp only: pcompose_pCons add_ac) |
2384 |
finally show ?case . |
|
| 65346 | 2385 |
qed |
2386 |
||
2387 |
lemma pcompose_uminus: "pcompose (-p) r = -pcompose p r" |
|
2388 |
for p r :: "'a::comm_ring poly" |
|
2389 |
by (induct p) (simp_all add: pcompose_pCons) |
|
2390 |
||
2391 |
lemma pcompose_diff: "pcompose (p - q) r = pcompose p r - pcompose q r" |
|
2392 |
for p q r :: "'a::comm_ring poly" |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
2393 |
using pcompose_add[of p "-q"] by (simp add: pcompose_uminus) |
| 62065 | 2394 |
|
| 65346 | 2395 |
lemma pcompose_smult: "pcompose (smult a p) r = smult a (pcompose p r)" |
2396 |
for p r :: "'a::comm_semiring_0 poly" |
|
2397 |
by (induct p) (simp_all add: pcompose_pCons pcompose_add smult_add_right) |
|
2398 |
||
2399 |
lemma pcompose_mult: "pcompose (p * q) r = pcompose p r * pcompose q r" |
|
2400 |
for p q r :: "'a::comm_semiring_0 poly" |
|
2401 |
by (induct p arbitrary: q) (simp_all add: pcompose_add pcompose_smult pcompose_pCons algebra_simps) |
|
2402 |
||
2403 |
lemma pcompose_assoc: "pcompose p (pcompose q r) = pcompose (pcompose p q) r" |
|
2404 |
for p q r :: "'a::comm_semiring_0 poly" |
|
2405 |
by (induct p arbitrary: q) (simp_all add: pcompose_pCons pcompose_add pcompose_mult) |
|
2406 |
||
2407 |
lemma pcompose_idR[simp]: "pcompose p [: 0, 1 :] = p" |
|
2408 |
for p :: "'a::comm_semiring_1 poly" |
|
2409 |
by (induct p) (simp_all add: pcompose_pCons) |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
2410 |
|
| 64267 | 2411 |
lemma pcompose_sum: "pcompose (sum f A) p = sum (\<lambda>i. pcompose (f i) p) A" |
| 65346 | 2412 |
by (induct A rule: infinite_finite_induct) (simp_all add: pcompose_1 pcompose_add) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2413 |
|
| 64272 | 2414 |
lemma pcompose_prod: "pcompose (prod f A) p = prod (\<lambda>i. pcompose (f i) p) A" |
| 65346 | 2415 |
by (induct A rule: infinite_finite_induct) (simp_all add: pcompose_1 pcompose_mult) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2416 |
|
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
2417 |
lemma pcompose_const [simp]: "pcompose [:a:] q = [:a:]" |
|
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
2418 |
by (subst pcompose_pCons) simp |
| 62065 | 2419 |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
2420 |
lemma pcompose_0': "pcompose p 0 = [:coeff p 0:]" |
|
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64272
diff
changeset
|
2421 |
by (induct p) (auto simp add: pcompose_pCons) |
| 62065 | 2422 |
|
| 65346 | 2423 |
lemma degree_pcompose: "degree (pcompose p q) = degree p * degree q" |
2424 |
for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
| 62065 | 2425 |
proof (induct p) |
2426 |
case 0 |
|
| 65346 | 2427 |
then show ?case by auto |
| 62065 | 2428 |
next |
2429 |
case (pCons a p) |
|
| 65346 | 2430 |
consider "degree (q * pcompose p q) = 0" | "degree (q * pcompose p q) > 0" |
2431 |
by blast |
|
2432 |
then show ?case |
|
2433 |
proof cases |
|
2434 |
case prems: 1 |
|
2435 |
show ?thesis |
|
2436 |
proof (cases "p = 0") |
|
| 62065 | 2437 |
case True |
| 65346 | 2438 |
then show ?thesis by auto |
| 62065 | 2439 |
next |
| 65346 | 2440 |
case False |
2441 |
from prems have "degree q = 0 \<or> pcompose p q = 0" |
|
2442 |
by (auto simp add: degree_mult_eq_0) |
|
2443 |
moreover have False if "pcompose p q = 0" "degree q \<noteq> 0" |
|
2444 |
proof - |
|
2445 |
from pCons.hyps(2) that have "degree p = 0" |
|
2446 |
by auto |
|
2447 |
then obtain a1 where "p = [:a1:]" |
|
2448 |
by (metis degree_pCons_eq_if old.nat.distinct(2) pCons_cases) |
|
2449 |
with \<open>pcompose p q = 0\<close> \<open>p \<noteq> 0\<close> show False |
|
2450 |
by auto |
|
2451 |
qed |
|
2452 |
ultimately have "degree (pCons a p) * degree q = 0" |
|
2453 |
by auto |
|
2454 |
moreover have "degree (pcompose (pCons a p) q) = 0" |
|
2455 |
proof - |
|
2456 |
from prems have "0 = max (degree [:a:]) (degree (q * pcompose p q))" |
|
2457 |
by simp |
|
2458 |
also have "\<dots> \<ge> degree ([:a:] + q * pcompose p q)" |
|
2459 |
by (rule degree_add_le_max) |
|
2460 |
finally show ?thesis |
|
2461 |
by (auto simp add: pcompose_pCons) |
|
2462 |
qed |
|
| 62065 | 2463 |
ultimately show ?thesis by simp |
2464 |
qed |
|
| 65346 | 2465 |
next |
2466 |
case prems: 2 |
|
2467 |
then have "p \<noteq> 0" "q \<noteq> 0" "pcompose p q \<noteq> 0" |
|
2468 |
by auto |
|
2469 |
from prems degree_add_eq_right [of "[:a:]"] |
|
2470 |
have "degree (pcompose (pCons a p) q) = degree (q * pcompose p q)" |
|
2471 |
by (auto simp: pcompose_pCons) |
|
2472 |
with pCons.hyps(2) degree_mult_eq[OF \<open>q\<noteq>0\<close> \<open>pcompose p q\<noteq>0\<close>] show ?thesis |
|
2473 |
by auto |
|
2474 |
qed |
|
| 62065 | 2475 |
qed |
2476 |
||
2477 |
lemma pcompose_eq_0: |
|
| 65346 | 2478 |
fixes p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
2479 |
assumes "pcompose p q = 0" "degree q > 0" |
|
|
62128
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents:
62072
diff
changeset
|
2480 |
shows "p = 0" |
| 62065 | 2481 |
proof - |
| 65346 | 2482 |
from assms degree_pcompose [of p q] have "degree p = 0" |
2483 |
by auto |
|
2484 |
then obtain a where "p = [:a:]" |
|
| 62065 | 2485 |
by (metis degree_pCons_eq_if gr0_conv_Suc neq0_conv pCons_cases) |
| 65346 | 2486 |
with assms(1) have "a = 0" |
2487 |
by auto |
|
2488 |
with \<open>p = [:a:]\<close> show ?thesis |
|
2489 |
by simp |
|
| 62065 | 2490 |
qed |
2491 |
||
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2492 |
lemma pcompose_eq_0_iff: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2493 |
fixes p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2494 |
assumes "degree q > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2495 |
shows "pcompose p q = 0 \<longleftrightarrow> p = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2496 |
using pcompose_eq_0[OF _ assms] by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2497 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2498 |
lemma coeff_pcompose_linear: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2499 |
"coeff (pcompose p [:0, a :: 'a :: comm_semiring_1:]) i = a ^ i * coeff p i" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2500 |
by (induction p arbitrary: i) (auto simp: pcompose_pCons coeff_pCons mult_ac split: nat.splits) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2501 |
|
| 62065 | 2502 |
lemma lead_coeff_comp: |
| 65346 | 2503 |
fixes p q :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
|
2504 |
assumes "degree q > 0" |
|
| 62065 | 2505 |
shows "lead_coeff (pcompose p q) = lead_coeff p * lead_coeff q ^ (degree p)" |
2506 |
proof (induct p) |
|
2507 |
case 0 |
|
| 65346 | 2508 |
then show ?case by auto |
| 62065 | 2509 |
next |
2510 |
case (pCons a p) |
|
| 65346 | 2511 |
consider "degree (q * pcompose p q) = 0" | "degree (q * pcompose p q) > 0" |
2512 |
by blast |
|
2513 |
then show ?case |
|
2514 |
proof cases |
|
2515 |
case prems: 1 |
|
2516 |
then have "pcompose p q = 0" |
|
2517 |
by (metis assms degree_0 degree_mult_eq_0 neq0_conv) |
|
2518 |
with pcompose_eq_0[OF _ \<open>degree q > 0\<close>] have "p = 0" |
|
2519 |
by simp |
|
2520 |
then show ?thesis |
|
2521 |
by auto |
|
2522 |
next |
|
2523 |
case prems: 2 |
|
2524 |
then have "degree [:a:] < degree (q * pcompose p q)" |
|
2525 |
by simp |
|
2526 |
then have "lead_coeff ([:a:] + q * p \<circ>\<^sub>p q) = lead_coeff (q * p \<circ>\<^sub>p q)" |
|
2527 |
by (rule lead_coeff_add_le) |
|
2528 |
then have "lead_coeff (pcompose (pCons a p) q) = lead_coeff (q * pcompose p q)" |
|
2529 |
by (simp add: pcompose_pCons) |
|
2530 |
also have "\<dots> = lead_coeff q * (lead_coeff p * lead_coeff q ^ degree p)" |
|
2531 |
using pCons.hyps(2) lead_coeff_mult[of q "pcompose p q"] by simp |
|
2532 |
also have "\<dots> = lead_coeff p * lead_coeff q ^ (degree p + 1)" |
|
2533 |
by (auto simp: mult_ac) |
|
2534 |
finally show ?thesis by auto |
|
2535 |
qed |
|
| 62065 | 2536 |
qed |
2537 |
||
|
79672
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2538 |
lemma coeff_pcompose_monom_linear [simp]: |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2539 |
fixes p :: "'a :: comm_ring_1 poly" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2540 |
shows "coeff (pcompose p (monom c (Suc 0))) k = c ^ k * coeff p k" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2541 |
by (induction p arbitrary: k) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2542 |
(auto simp: coeff_pCons coeff_monom_mult pcompose_pCons split: nat.splits) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2543 |
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2544 |
lemma of_nat_mult_conv_smult: "of_nat n * P = smult (of_nat n) P" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2545 |
by (simp add: monom_0 of_nat_monom) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2546 |
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2547 |
lemma numeral_mult_conv_smult: "numeral n * P = smult (numeral n) P" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2548 |
by (simp add: numeral_poly) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2549 |
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2550 |
lemma sum_order_le_degree: |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2551 |
assumes "p \<noteq> 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2552 |
shows "(\<Sum>x | poly p x = 0. order x p) \<le> degree p" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2553 |
using assms |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2554 |
proof (induction "degree p" arbitrary: p rule: less_induct) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2555 |
case (less p) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2556 |
show ?case |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2557 |
proof (cases "\<exists>x. poly p x = 0") |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2558 |
case False |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2559 |
thus ?thesis |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2560 |
by auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2561 |
next |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2562 |
case True |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2563 |
then obtain x where x: "poly p x = 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2564 |
by auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2565 |
have "[:-x, 1:] ^ order x p dvd p" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2566 |
by (simp add: order_1) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2567 |
then obtain q where q: "p = [:-x, 1:] ^ order x p * q" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2568 |
by (elim dvdE) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2569 |
have [simp]: "q \<noteq> 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2570 |
using q less.prems by auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2571 |
have "order x p = order x p + order x q" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2572 |
by (subst q, subst order_mult) (auto simp: order_power_n_n) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2573 |
hence "order x q = 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2574 |
by auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2575 |
hence [simp]: "poly q x \<noteq> 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2576 |
by (simp add: order_root) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2577 |
have deg_p: "degree p = degree q + order x p" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2578 |
by (subst q, subst degree_mult_eq) (auto simp: degree_power_eq) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2579 |
moreover have "order x p > 0" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2580 |
using x less.prems by (simp add: order_root) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2581 |
ultimately have "degree q < degree p" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2582 |
by linarith |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2583 |
hence "(\<Sum>x | poly q x = 0. order x q) \<le> degree q" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2584 |
by (intro less.hyps) auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2585 |
hence "order x p + (\<Sum>x | poly q x = 0. order x q) \<le> degree p" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2586 |
by (simp add: deg_p) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2587 |
also have "{y. poly q y = 0} = {y. poly p y = 0} - {x}"
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2588 |
by (subst q) auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2589 |
also have "(\<Sum>y \<in> {y. poly p y = 0} - {x}. order y q) =
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2590 |
(\<Sum>y \<in> {y. poly p y = 0} - {x}. order y p)"
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2591 |
by (intro sum.cong refl, subst q) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2592 |
(auto simp: order_mult order_power_n_n intro!: order_0I) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2593 |
also have "order x p + \<dots> = (\<Sum>y \<in> insert x ({y. poly p y = 0} - {x}). order y p)"
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2594 |
using \<open>p \<noteq> 0\<close> by (subst sum.insert) (auto simp: poly_roots_finite) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2595 |
also have "insert x ({y. poly p y = 0} - {x}) = {y. poly p y = 0}"
|
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2596 |
using \<open>poly p x = 0\<close> by auto |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2597 |
finally show ?thesis . |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2598 |
qed |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
2599 |
qed |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2600 |
|
|
73109
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2601 |
subsection \<open>Closure properties of coefficients\<close> |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2602 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2603 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2604 |
context |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2605 |
fixes R :: "'a :: comm_semiring_1 set" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2606 |
assumes R_0: "0 \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2607 |
assumes R_plus: "\<And>x y. x \<in> R \<Longrightarrow> y \<in> R \<Longrightarrow> x + y \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2608 |
assumes R_mult: "\<And>x y. x \<in> R \<Longrightarrow> y \<in> R \<Longrightarrow> x * y \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2609 |
begin |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2610 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2611 |
lemma coeff_mult_semiring_closed: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2612 |
assumes "\<And>i. coeff p i \<in> R" "\<And>i. coeff q i \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2613 |
shows "coeff (p * q) i \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2614 |
proof - |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2615 |
have R_sum: "sum f A \<in> R" if "\<And>x. x \<in> A \<Longrightarrow> f x \<in> R" for A and f :: "nat \<Rightarrow> 'a" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2616 |
using that by (induction A rule: infinite_finite_induct) (auto intro: R_0 R_plus) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2617 |
show ?thesis |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2618 |
unfolding coeff_mult by (auto intro!: R_sum R_mult assms) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2619 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2620 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2621 |
lemma coeff_pcompose_semiring_closed: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2622 |
assumes "\<And>i. coeff p i \<in> R" "\<And>i. coeff q i \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2623 |
shows "coeff (pcompose p q) i \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2624 |
using assms(1) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2625 |
proof (induction p arbitrary: i) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2626 |
case (pCons a p i) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2627 |
have [simp]: "a \<in> R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2628 |
using pCons.prems[of 0] by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2629 |
have "coeff p i \<in> R" for i |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2630 |
using pCons.prems[of "Suc i"] by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2631 |
hence "coeff (p \<circ>\<^sub>p q) i \<in> R" for i |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2632 |
using pCons.prems by (intro pCons.IH) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2633 |
thus ?case |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2634 |
by (auto simp: pcompose_pCons coeff_pCons split: nat.splits |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2635 |
intro!: assms R_plus coeff_mult_semiring_closed) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2636 |
qed auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2637 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2638 |
end |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2639 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2640 |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2641 |
subsection \<open>Shifting polynomials\<close> |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2642 |
|
| 65346 | 2643 |
definition poly_shift :: "nat \<Rightarrow> 'a::zero poly \<Rightarrow> 'a poly" |
2644 |
where "poly_shift n p = Abs_poly (\<lambda>i. coeff p (i + n))" |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2645 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2646 |
lemma nth_default_drop: "nth_default x (drop n xs) m = nth_default x xs (m + n)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2647 |
by (auto simp add: nth_default_def add_ac) |
| 65346 | 2648 |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2649 |
lemma nth_default_take: "nth_default x (take n xs) m = (if m < n then nth_default x xs m else x)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2650 |
by (auto simp add: nth_default_def add_ac) |
| 65346 | 2651 |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2652 |
lemma coeff_poly_shift: "coeff (poly_shift n p) i = coeff p (i + n)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2653 |
proof - |
| 65346 | 2654 |
from MOST_coeff_eq_0[of p] obtain m where "\<forall>k>m. coeff p k = 0" |
2655 |
by (auto simp: MOST_nat) |
|
2656 |
then have "\<forall>k>m. coeff p (k + n) = 0" |
|
2657 |
by auto |
|
2658 |
then have "\<forall>\<^sub>\<infinity>k. coeff p (k + n) = 0" |
|
2659 |
by (auto simp: MOST_nat) |
|
2660 |
then show ?thesis |
|
2661 |
by (simp add: poly_shift_def poly.Abs_poly_inverse) |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2662 |
qed |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2663 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2664 |
lemma poly_shift_id [simp]: "poly_shift 0 = (\<lambda>x. x)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2665 |
by (simp add: poly_eq_iff fun_eq_iff coeff_poly_shift) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2666 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2667 |
lemma poly_shift_0 [simp]: "poly_shift n 0 = 0" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2668 |
by (simp add: poly_eq_iff coeff_poly_shift) |
| 65346 | 2669 |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2670 |
lemma poly_shift_1: "poly_shift n 1 = (if n = 0 then 1 else 0)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2671 |
by (simp add: poly_eq_iff coeff_poly_shift) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2672 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2673 |
lemma poly_shift_monom: "poly_shift n (monom c m) = (if m \<ge> n then monom c (m - n) else 0)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2674 |
by (auto simp add: poly_eq_iff coeff_poly_shift) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2675 |
|
| 65390 | 2676 |
lemma coeffs_shift_poly [code abstract]: |
2677 |
"coeffs (poly_shift n p) = drop n (coeffs p)" |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2678 |
proof (cases "p = 0") |
| 65346 | 2679 |
case True |
2680 |
then show ?thesis by simp |
|
2681 |
next |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2682 |
case False |
| 65346 | 2683 |
then show ?thesis |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2684 |
by (intro coeffs_eqI) |
| 65390 | 2685 |
(simp_all add: coeff_poly_shift nth_default_drop nth_default_coeffs_eq) |
| 65346 | 2686 |
qed |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2687 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2688 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2689 |
subsection \<open>Truncating polynomials\<close> |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2690 |
|
| 65346 | 2691 |
definition poly_cutoff |
2692 |
where "poly_cutoff n p = Abs_poly (\<lambda>k. if k < n then coeff p k else 0)" |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2693 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2694 |
lemma coeff_poly_cutoff: "coeff (poly_cutoff n p) k = (if k < n then coeff p k else 0)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2695 |
unfolding poly_cutoff_def |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2696 |
by (subst poly.Abs_poly_inverse) (auto simp: MOST_nat intro: exI[of _ n]) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2697 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2698 |
lemma poly_cutoff_0 [simp]: "poly_cutoff n 0 = 0" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2699 |
by (simp add: poly_eq_iff coeff_poly_cutoff) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2700 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2701 |
lemma poly_cutoff_1 [simp]: "poly_cutoff n 1 = (if n = 0 then 0 else 1)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2702 |
by (simp add: poly_eq_iff coeff_poly_cutoff) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2703 |
|
| 65346 | 2704 |
lemma coeffs_poly_cutoff [code abstract]: |
| 67399 | 2705 |
"coeffs (poly_cutoff n p) = strip_while ((=) 0) (take n (coeffs p))" |
2706 |
proof (cases "strip_while ((=) 0) (take n (coeffs p)) = []") |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2707 |
case True |
| 65346 | 2708 |
then have "coeff (poly_cutoff n p) k = 0" for k |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2709 |
unfolding coeff_poly_cutoff |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2710 |
by (auto simp: nth_default_coeffs_eq [symmetric] nth_default_def set_conv_nth) |
| 65346 | 2711 |
then have "poly_cutoff n p = 0" |
2712 |
by (simp add: poly_eq_iff) |
|
2713 |
then show ?thesis |
|
2714 |
by (subst True) simp_all |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2715 |
next |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2716 |
case False |
| 67399 | 2717 |
have "no_trailing ((=) 0) (strip_while ((=) 0) (take n (coeffs p)))" |
| 65346 | 2718 |
by simp |
| 67399 | 2719 |
with False have "last (strip_while ((=) 0) (take n (coeffs p))) \<noteq> 0" |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2720 |
unfolding no_trailing_unfold by auto |
| 65346 | 2721 |
then show ?thesis |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2722 |
by (intro coeffs_eqI) |
| 65390 | 2723 |
(simp_all add: coeff_poly_cutoff nth_default_take nth_default_coeffs_eq) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2724 |
qed |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2725 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2726 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2727 |
subsection \<open>Reflecting polynomials\<close> |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2728 |
|
| 65346 | 2729 |
definition reflect_poly :: "'a::zero poly \<Rightarrow> 'a poly" |
2730 |
where "reflect_poly p = Poly (rev (coeffs p))" |
|
2731 |
||
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2732 |
lemma coeffs_reflect_poly [code abstract]: |
| 67399 | 2733 |
"coeffs (reflect_poly p) = rev (dropWhile ((=) 0) (coeffs p))" |
| 65346 | 2734 |
by (simp add: reflect_poly_def) |
2735 |
||
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2736 |
lemma reflect_poly_0 [simp]: "reflect_poly 0 = 0" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2737 |
by (simp add: reflect_poly_def) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2738 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2739 |
lemma reflect_poly_1 [simp]: "reflect_poly 1 = 1" |
| 65486 | 2740 |
by (simp add: reflect_poly_def one_pCons) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2741 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2742 |
lemma coeff_reflect_poly: |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2743 |
"coeff (reflect_poly p) n = (if n > degree p then 0 else coeff p (degree p - n))" |
| 65346 | 2744 |
by (cases "p = 0") |
2745 |
(auto simp add: reflect_poly_def nth_default_def |
|
2746 |
rev_nth degree_eq_length_coeffs coeffs_nth not_less |
|
2747 |
dest: le_imp_less_Suc) |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2748 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2749 |
lemma coeff_0_reflect_poly_0_iff [simp]: "coeff (reflect_poly p) 0 = 0 \<longleftrightarrow> p = 0" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2750 |
by (simp add: coeff_reflect_poly) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2751 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2752 |
lemma reflect_poly_at_0_eq_0_iff [simp]: "poly (reflect_poly p) 0 = 0 \<longleftrightarrow> p = 0" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2753 |
by (simp add: coeff_reflect_poly poly_0_coeff_0) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2754 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2755 |
lemma reflect_poly_pCons': |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2756 |
"p \<noteq> 0 \<Longrightarrow> reflect_poly (pCons c p) = reflect_poly p + monom c (Suc (degree p))" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2757 |
by (intro poly_eqI) |
| 65346 | 2758 |
(auto simp: coeff_reflect_poly coeff_pCons not_less Suc_diff_le split: nat.split) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2759 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2760 |
lemma reflect_poly_const [simp]: "reflect_poly [:a:] = [:a:]" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2761 |
by (cases "a = 0") (simp_all add: reflect_poly_def) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2762 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2763 |
lemma poly_reflect_poly_nz: |
| 65346 | 2764 |
"x \<noteq> 0 \<Longrightarrow> poly (reflect_poly p) x = x ^ degree p * poly p (inverse x)" |
2765 |
for x :: "'a::field" |
|
2766 |
by (induct rule: pCons_induct) (simp_all add: field_simps reflect_poly_pCons' poly_monom) |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2767 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2768 |
lemma coeff_0_reflect_poly [simp]: "coeff (reflect_poly p) 0 = lead_coeff p" |
| 64794 | 2769 |
by (simp add: coeff_reflect_poly) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2770 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2771 |
lemma poly_reflect_poly_0 [simp]: "poly (reflect_poly p) 0 = lead_coeff p" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2772 |
by (simp add: poly_0_coeff_0) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2773 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2774 |
lemma reflect_poly_reflect_poly [simp]: "coeff p 0 \<noteq> 0 \<Longrightarrow> reflect_poly (reflect_poly p) = p" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2775 |
by (cases p rule: pCons_cases) (simp add: reflect_poly_def ) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2776 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2777 |
lemma degree_reflect_poly_le: "degree (reflect_poly p) \<le> degree p" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2778 |
by (simp add: degree_eq_length_coeffs coeffs_reflect_poly length_dropWhile_le diff_le_mono) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2779 |
|
| 65346 | 2780 |
lemma reflect_poly_pCons: "a \<noteq> 0 \<Longrightarrow> reflect_poly (pCons a p) = Poly (rev (a # coeffs p))" |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2781 |
by (subst coeffs_eq_iff) (simp add: coeffs_reflect_poly) |
| 65346 | 2782 |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2783 |
lemma degree_reflect_poly_eq [simp]: "coeff p 0 \<noteq> 0 \<Longrightarrow> degree (reflect_poly p) = degree p" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2784 |
by (cases p rule: pCons_cases) (simp add: reflect_poly_pCons degree_eq_length_coeffs) |
| 65346 | 2785 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2786 |
lemma reflect_poly_eq_0_iff [simp]: "reflect_poly p = 0 \<longleftrightarrow> p = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2787 |
using coeff_0_reflect_poly_0_iff by fastforce |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
2788 |
|
| 63498 | 2789 |
(* TODO: does this work with zero divisors as well? Probably not. *) |
| 65346 | 2790 |
lemma reflect_poly_mult: "reflect_poly (p * q) = reflect_poly p * reflect_poly q" |
2791 |
for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2792 |
proof (cases "p = 0 \<or> q = 0") |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2793 |
case False |
| 65346 | 2794 |
then have [simp]: "p \<noteq> 0" "q \<noteq> 0" by auto |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2795 |
show ?thesis |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2796 |
proof (rule poly_eqI) |
| 65346 | 2797 |
show "coeff (reflect_poly (p * q)) i = coeff (reflect_poly p * reflect_poly q) i" for i |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2798 |
proof (cases "i \<le> degree (p * q)") |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2799 |
case True |
| 64811 | 2800 |
define A where "A = {..i} \<inter> {i - degree q..degree p}"
|
2801 |
define B where "B = {..degree p} \<inter> {degree p - i..degree (p*q) - i}"
|
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2802 |
let ?f = "\<lambda>j. degree p - j" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2803 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2804 |
from True have "coeff (reflect_poly (p * q)) i = coeff (p * q) (degree (p * q) - i)" |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2805 |
by (simp add: coeff_reflect_poly) |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2806 |
also have "\<dots> = (\<Sum>j\<le>degree (p * q) - i. coeff p j * coeff q (degree (p * q) - i - j))" |
| 65346 | 2807 |
by (simp add: coeff_mult) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2808 |
also have "\<dots> = (\<Sum>j\<in>B. coeff p j * coeff q (degree (p * q) - i - j))" |
| 64267 | 2809 |
by (intro sum.mono_neutral_right) (auto simp: B_def degree_mult_eq not_le coeff_eq_0) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2810 |
also from True have "\<dots> = (\<Sum>j\<in>A. coeff p (degree p - j) * coeff q (degree q - (i - j)))" |
| 64267 | 2811 |
by (intro sum.reindex_bij_witness[of _ ?f ?f]) |
| 65346 | 2812 |
(auto simp: A_def B_def degree_mult_eq add_ac) |
2813 |
also have "\<dots> = |
|
2814 |
(\<Sum>j\<le>i. |
|
2815 |
if j \<in> {i - degree q..degree p}
|
|
2816 |
then coeff p (degree p - j) * coeff q (degree q - (i - j)) |
|
2817 |
else 0)" |
|
| 64267 | 2818 |
by (subst sum.inter_restrict [symmetric]) (simp_all add: A_def) |
| 65346 | 2819 |
also have "\<dots> = coeff (reflect_poly p * reflect_poly q) i" |
2820 |
by (fastforce simp: coeff_mult coeff_reflect_poly intro!: sum.cong) |
|
2821 |
finally show ?thesis . |
|
| 64267 | 2822 |
qed (auto simp: coeff_mult coeff_reflect_poly coeff_eq_0 degree_mult_eq intro!: sum.neutral) |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2823 |
qed |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2824 |
qed auto |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2825 |
|
| 65346 | 2826 |
lemma reflect_poly_smult: "reflect_poly (smult c p) = smult c (reflect_poly p)" |
2827 |
for p :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2828 |
using reflect_poly_mult[of "[:c:]" p] by simp |
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2829 |
|
| 65346 | 2830 |
lemma reflect_poly_power: "reflect_poly (p ^ n) = reflect_poly p ^ n" |
2831 |
for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
|
|
2832 |
by (induct n) (simp_all add: reflect_poly_mult) |
|
2833 |
||
2834 |
lemma reflect_poly_prod: "reflect_poly (prod f A) = prod (\<lambda>x. reflect_poly (f x)) A" |
|
2835 |
for f :: "_ \<Rightarrow> _::{comm_semiring_0,semiring_no_zero_divisors} poly"
|
|
2836 |
by (induct A rule: infinite_finite_induct) (simp_all add: reflect_poly_mult) |
|
2837 |
||
2838 |
lemma reflect_poly_prod_list: "reflect_poly (prod_list xs) = prod_list (map reflect_poly xs)" |
|
2839 |
for xs :: "_::{comm_semiring_0,semiring_no_zero_divisors} poly list"
|
|
2840 |
by (induct xs) (simp_all add: reflect_poly_mult) |
|
2841 |
||
| 65390 | 2842 |
lemma reflect_poly_Poly_nz: |
2843 |
"no_trailing (HOL.eq 0) xs \<Longrightarrow> reflect_poly (Poly xs) = Poly (rev xs)" |
|
| 65346 | 2844 |
by (simp add: reflect_poly_def) |
2845 |
||
2846 |
lemmas reflect_poly_simps = |
|
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2847 |
reflect_poly_0 reflect_poly_1 reflect_poly_const reflect_poly_smult reflect_poly_mult |
| 64272 | 2848 |
reflect_poly_power reflect_poly_prod reflect_poly_prod_list |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2849 |
|
|
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
2850 |
|
| 64795 | 2851 |
subsection \<open>Derivatives\<close> |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2852 |
|
| 63498 | 2853 |
function pderiv :: "('a :: {comm_semiring_1,semiring_no_zero_divisors}) poly \<Rightarrow> 'a poly"
|
| 65346 | 2854 |
where "pderiv (pCons a p) = (if p = 0 then 0 else p + pCons 0 (pderiv p))" |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2855 |
by (auto intro: pCons_cases) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2856 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2857 |
termination pderiv |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2858 |
by (relation "measure degree") simp_all |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2859 |
|
|
63027
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
2860 |
declare pderiv.simps[simp del] |
|
8de0ebee3f1c
several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents:
62422
diff
changeset
|
2861 |
|
| 65346 | 2862 |
lemma pderiv_0 [simp]: "pderiv 0 = 0" |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2863 |
using pderiv.simps [of 0 0] by simp |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2864 |
|
| 65346 | 2865 |
lemma pderiv_pCons: "pderiv (pCons a p) = p + pCons 0 (pderiv p)" |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2866 |
by (simp add: pderiv.simps) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2867 |
|
| 65346 | 2868 |
lemma pderiv_1 [simp]: "pderiv 1 = 0" |
| 65486 | 2869 |
by (simp add: one_pCons pderiv_pCons) |
| 65346 | 2870 |
|
2871 |
lemma pderiv_of_nat [simp]: "pderiv (of_nat n) = 0" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2872 |
and pderiv_numeral [simp]: "pderiv (numeral m) = 0" |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2873 |
by (simp_all add: of_nat_poly numeral_poly pderiv_pCons) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2874 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2875 |
lemma coeff_pderiv: "coeff (pderiv p) n = of_nat (Suc n) * coeff p (Suc n)" |
| 65346 | 2876 |
by (induct p arbitrary: n) |
2877 |
(auto simp add: pderiv_pCons coeff_pCons algebra_simps split: nat.split) |
|
2878 |
||
2879 |
fun pderiv_coeffs_code :: "'a::{comm_semiring_1,semiring_no_zero_divisors} \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
2880 |
where |
|
2881 |
"pderiv_coeffs_code f (x # xs) = cCons (f * x) (pderiv_coeffs_code (f+1) xs)" |
|
2882 |
| "pderiv_coeffs_code f [] = []" |
|
2883 |
||
2884 |
definition pderiv_coeffs :: "'a::{comm_semiring_1,semiring_no_zero_divisors} list \<Rightarrow> 'a list"
|
|
2885 |
where "pderiv_coeffs xs = pderiv_coeffs_code 1 (tl xs)" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2886 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2887 |
(* Efficient code for pderiv contributed by René Thiemann and Akihisa Yamada *) |
| 65346 | 2888 |
lemma pderiv_coeffs_code: |
2889 |
"nth_default 0 (pderiv_coeffs_code f xs) n = (f + of_nat n) * nth_default 0 xs n" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2890 |
proof (induct xs arbitrary: f n) |
| 65346 | 2891 |
case Nil |
2892 |
then show ?case by simp |
|
2893 |
next |
|
2894 |
case (Cons x xs) |
|
2895 |
show ?case |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2896 |
proof (cases n) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2897 |
case 0 |
| 65346 | 2898 |
then show ?thesis |
2899 |
by (cases "pderiv_coeffs_code (f + 1) xs = [] \<and> f * x = 0") (auto simp: cCons_def) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2900 |
next |
| 65346 | 2901 |
case n: (Suc m) |
2902 |
show ?thesis |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2903 |
proof (cases "pderiv_coeffs_code (f + 1) xs = [] \<and> f * x = 0") |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2904 |
case False |
| 65346 | 2905 |
then have "nth_default 0 (pderiv_coeffs_code f (x # xs)) n = |
2906 |
nth_default 0 (pderiv_coeffs_code (f + 1) xs) m" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2907 |
by (auto simp: cCons_def n) |
| 65346 | 2908 |
also have "\<dots> = (f + of_nat n) * nth_default 0 xs m" |
2909 |
by (simp add: Cons n add_ac) |
|
2910 |
finally show ?thesis |
|
2911 |
by (simp add: n) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2912 |
next |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2913 |
case True |
| 65346 | 2914 |
have empty: "pderiv_coeffs_code g xs = [] \<Longrightarrow> g + of_nat m = 0 \<or> nth_default 0 xs m = 0" for g |
2915 |
proof (induct xs arbitrary: g m) |
|
2916 |
case Nil |
|
2917 |
then show ?case by simp |
|
2918 |
next |
|
2919 |
case (Cons x xs) |
|
2920 |
from Cons(2) have empty: "pderiv_coeffs_code (g + 1) xs = []" and g: "g = 0 \<or> x = 0" |
|
2921 |
by (auto simp: cCons_def split: if_splits) |
|
2922 |
note IH = Cons(1)[OF empty] |
|
2923 |
from IH[of m] IH[of "m - 1"] g show ?case |
|
2924 |
by (cases m) (auto simp: field_simps) |
|
2925 |
qed |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2926 |
from True have "nth_default 0 (pderiv_coeffs_code f (x # xs)) n = 0" |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2927 |
by (auto simp: cCons_def n) |
| 65346 | 2928 |
moreover from True have "(f + of_nat n) * nth_default 0 (x # xs) n = 0" |
2929 |
by (simp add: n) (use empty[of "f+1"] in \<open>auto simp: field_simps\<close>) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2930 |
ultimately show ?thesis by simp |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2931 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2932 |
qed |
| 65346 | 2933 |
qed |
2934 |
||
2935 |
lemma coeffs_pderiv_code [code abstract]: "coeffs (pderiv p) = pderiv_coeffs (coeffs p)" |
|
2936 |
unfolding pderiv_coeffs_def |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2937 |
proof (rule coeffs_eqI, unfold pderiv_coeffs_code coeff_pderiv, goal_cases) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2938 |
case (1 n) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2939 |
have id: "coeff p (Suc n) = nth_default 0 (map (\<lambda>i. coeff p (Suc i)) [0..<degree p]) n" |
| 65346 | 2940 |
by (cases "n < degree p") (auto simp: nth_default_def coeff_eq_0) |
2941 |
show ?case |
|
2942 |
unfolding coeffs_def map_upt_Suc by (auto simp: id) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2943 |
next |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2944 |
case 2 |
| 65346 | 2945 |
obtain n :: 'a and xs where defs: "tl (coeffs p) = xs" "1 = n" |
2946 |
by simp |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2947 |
from 2 show ?case |
| 65346 | 2948 |
unfolding defs by (induct xs arbitrary: n) (auto simp: cCons_def) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2949 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2950 |
|
| 65346 | 2951 |
lemma pderiv_eq_0_iff: "pderiv p = 0 \<longleftrightarrow> degree p = 0" |
2952 |
for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
|
|
| 72750 | 2953 |
proof (cases "degree p") |
2954 |
case 0 |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
2955 |
then show ?thesis |
| 72750 | 2956 |
by (metis degree_eq_zeroE pderiv.simps) |
2957 |
next |
|
2958 |
case (Suc n) |
|
2959 |
then show ?thesis |
|
|
73109
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2960 |
using coeff_0 coeff_pderiv degree_0 leading_coeff_0_iff mult_eq_0_iff nat.distinct(1) of_nat_eq_0_iff |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
2961 |
by (metis coeff_0 coeff_pderiv degree_0 leading_coeff_0_iff mult_eq_0_iff nat.distinct(1) of_nat_eq_0_iff) |
| 72750 | 2962 |
qed |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2963 |
|
| 65346 | 2964 |
lemma degree_pderiv: "degree (pderiv p) = degree p - 1" |
2965 |
for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
|
|
| 72750 | 2966 |
proof - |
2967 |
have "degree p - 1 \<le> degree (pderiv p)" |
|
2968 |
proof (cases "degree p") |
|
2969 |
case (Suc n) |
|
2970 |
then show ?thesis |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
2971 |
by (metis coeff_pderiv degree_0 diff_Suc_1 le_degree leading_coeff_0_iff mult_eq_0_iff nat.distinct(1) of_nat_eq_0_iff) |
| 72750 | 2972 |
qed auto |
2973 |
moreover have "\<forall>i>degree p - 1. coeff (pderiv p) i = 0" |
|
2974 |
by (simp add: coeff_eq_0 coeff_pderiv) |
|
2975 |
ultimately show ?thesis |
|
2976 |
using order_antisym [OF degree_le] by blast |
|
2977 |
qed |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2978 |
|
| 65346 | 2979 |
lemma not_dvd_pderiv: |
2980 |
fixes p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
|
|
2981 |
assumes "degree p \<noteq> 0" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2982 |
shows "\<not> p dvd pderiv p" |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2983 |
proof |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2984 |
assume dvd: "p dvd pderiv p" |
| 65346 | 2985 |
then obtain q where p: "pderiv p = p * q" |
2986 |
unfolding dvd_def by auto |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2987 |
from dvd have le: "degree p \<le> degree (pderiv p)" |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2988 |
by (simp add: assms dvd_imp_degree_le pderiv_eq_0_iff) |
| 65346 | 2989 |
from assms and this [unfolded degree_pderiv] |
2990 |
show False by auto |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2991 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2992 |
|
| 65346 | 2993 |
lemma dvd_pderiv_iff [simp]: "p dvd pderiv p \<longleftrightarrow> degree p = 0" |
2994 |
for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
|
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2995 |
using not_dvd_pderiv[of p] by (auto simp: pderiv_eq_0_iff [symmetric]) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2996 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2997 |
lemma pderiv_singleton [simp]: "pderiv [:a:] = 0" |
| 65346 | 2998 |
by (simp add: pderiv_pCons) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
2999 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3000 |
lemma pderiv_add: "pderiv (p + q) = pderiv p + pderiv q" |
| 65346 | 3001 |
by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3002 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3003 |
lemma pderiv_minus: "pderiv (- p :: 'a :: idom poly) = - pderiv p" |
| 65346 | 3004 |
by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3005 |
|
| 63498 | 3006 |
lemma pderiv_diff: "pderiv ((p :: _ :: idom poly) - q) = pderiv p - pderiv q" |
| 65346 | 3007 |
by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3008 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3009 |
lemma pderiv_smult: "pderiv (smult a p) = smult a (pderiv p)" |
| 65346 | 3010 |
by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3011 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3012 |
lemma pderiv_mult: "pderiv (p * q) = p * pderiv q + q * pderiv p" |
| 65346 | 3013 |
by (induct p) (auto simp: pderiv_add pderiv_smult pderiv_pCons algebra_simps) |
3014 |
||
3015 |
lemma pderiv_power_Suc: "pderiv (p ^ Suc n) = smult (of_nat (Suc n)) (p ^ n) * pderiv p" |
|
| 72750 | 3016 |
proof (induction n) |
3017 |
case (Suc n) |
|
3018 |
then show ?case |
|
3019 |
by (simp add: pderiv_mult smult_add_left algebra_simps) |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
3020 |
qed auto |
| 65346 | 3021 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3022 |
lemma pderiv_power: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3023 |
"pderiv (p ^ n) = smult (of_nat n) (p ^ (n - 1) * pderiv p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3024 |
by (cases n) (simp_all add: pderiv_power_Suc del: power_Suc) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3025 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3026 |
lemma pderiv_monom: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3027 |
"pderiv (monom c n) = monom (of_nat n * c) (n - 1)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3028 |
by (cases n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3029 |
(simp_all add: monom_altdef pderiv_power_Suc pderiv_smult pderiv_pCons mult_ac del: power_Suc) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3030 |
|
|
66550
e5d82cf3c387
Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents:
66453
diff
changeset
|
3031 |
lemma pderiv_pcompose: "pderiv (pcompose p q) = pcompose (pderiv p) q * pderiv q" |
|
e5d82cf3c387
Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents:
66453
diff
changeset
|
3032 |
by (induction p rule: pCons_induct) |
|
e5d82cf3c387
Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents:
66453
diff
changeset
|
3033 |
(auto simp: pcompose_pCons pderiv_add pderiv_mult pderiv_pCons pcompose_add algebra_simps) |
|
e5d82cf3c387
Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents:
66453
diff
changeset
|
3034 |
|
| 65346 | 3035 |
lemma pderiv_prod: "pderiv (prod f (as)) = (\<Sum>a\<in>as. prod f (as - {a}) * pderiv (f a))"
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3036 |
proof (induct as rule: infinite_finite_induct) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3037 |
case (insert a as) |
| 65346 | 3038 |
then have id: "prod f (insert a as) = f a * prod f as" |
3039 |
"\<And>g. sum g (insert a as) = g a + sum g as" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3040 |
"insert a as - {a} = as"
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3041 |
by auto |
| 65346 | 3042 |
have "prod f (insert a as - {b}) = f a * prod f (as - {b})" if "b \<in> as" for b
|
3043 |
proof - |
|
3044 |
from \<open>a \<notin> as\<close> that have *: "insert a as - {b} = insert a (as - {b})"
|
|
3045 |
by auto |
|
3046 |
show ?thesis |
|
3047 |
unfolding * by (subst prod.insert) (use insert in auto) |
|
3048 |
qed |
|
3049 |
then show ?case |
|
| 64267 | 3050 |
unfolding id pderiv_mult insert(3) sum_distrib_left |
| 65346 | 3051 |
by (auto simp add: ac_simps intro!: sum.cong) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3052 |
qed auto |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3053 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3054 |
lemma coeff_higher_pderiv: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3055 |
"coeff ((pderiv ^^ m) f) n = pochhammer (of_nat (Suc n)) m * coeff f (n + m)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3056 |
by (induction m arbitrary: n) (simp_all add: coeff_pderiv pochhammer_rec algebra_simps) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3057 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3058 |
lemma higher_pderiv_0 [simp]: "(pderiv ^^ n) 0 = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3059 |
by (induction n) simp_all |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3060 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3061 |
lemma higher_pderiv_add: "(pderiv ^^ n) (p + q) = (pderiv ^^ n) p + (pderiv ^^ n) q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3062 |
by (induction n arbitrary: p q) (simp_all del: funpow.simps add: funpow_Suc_right pderiv_add) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3063 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3064 |
lemma higher_pderiv_smult: "(pderiv ^^ n) (smult c p) = smult c ((pderiv ^^ n) p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3065 |
by (induction n arbitrary: p) (simp_all del: funpow.simps add: funpow_Suc_right pderiv_smult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3066 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3067 |
lemma higher_pderiv_monom: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3068 |
"m \<le> n + 1 \<Longrightarrow> (pderiv ^^ m) (monom c n) = monom (pochhammer (int n - int m + 1) m * c) (n - m)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3069 |
proof (induction m arbitrary: c n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3070 |
case (Suc m) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3071 |
thus ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3072 |
by (cases n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3073 |
(simp_all del: funpow.simps add: funpow_Suc_right pderiv_monom pochhammer_rec' Suc.IH) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3074 |
qed simp_all |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3075 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3076 |
lemma higher_pderiv_monom_eq_zero: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3077 |
"m > n + 1 \<Longrightarrow> (pderiv ^^ m) (monom c n) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3078 |
proof (induction m arbitrary: c n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3079 |
case (Suc m) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3080 |
thus ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3081 |
by (cases n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3082 |
(simp_all del: funpow.simps add: funpow_Suc_right pderiv_monom pochhammer_rec' Suc.IH) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3083 |
qed simp_all |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3084 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3085 |
lemma higher_pderiv_sum: "(pderiv ^^ n) (sum f A) = (\<Sum>x\<in>A. (pderiv ^^ n) (f x))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3086 |
by (induction A rule: infinite_finite_induct) (simp_all add: higher_pderiv_add) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3087 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3088 |
lemma higher_pderiv_sum_mset: "(pderiv ^^ n) (sum_mset A) = (\<Sum>p\<in>#A. (pderiv ^^ n) p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3089 |
by (induction A) (simp_all add: higher_pderiv_add) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3090 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3091 |
lemma higher_pderiv_sum_list: "(pderiv ^^ n) (sum_list ps) = (\<Sum>p\<leftarrow>ps. (pderiv ^^ n) p)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3092 |
by (induction ps) (simp_all add: higher_pderiv_add) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3093 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3094 |
lemma degree_higher_pderiv: "Polynomial.degree ((pderiv ^^ n) p) = Polynomial.degree p - n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3095 |
for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3096 |
by (induction n) (auto simp: degree_pderiv) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3097 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3098 |
|
| 65346 | 3099 |
lemma DERIV_pow2: "DERIV (\<lambda>x. x ^ Suc n) x :> real (Suc n) * (x ^ n)" |
3100 |
by (rule DERIV_cong, rule DERIV_pow) simp |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3101 |
declare DERIV_pow2 [simp] DERIV_pow [simp] |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3102 |
|
| 65346 | 3103 |
lemma DERIV_add_const: "DERIV f x :> D \<Longrightarrow> DERIV (\<lambda>x. a + f x :: 'a::real_normed_field) x :> D" |
3104 |
by (rule DERIV_cong, rule DERIV_add) auto |
|
3105 |
||
3106 |
lemma poly_DERIV [simp]: "DERIV (\<lambda>x. poly p x) x :> poly (pderiv p) x" |
|
3107 |
by (induct p) (auto intro!: derivative_eq_intros simp add: pderiv_pCons) |
|
3108 |
||
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
3109 |
lemma poly_isCont[simp]: |
|
68532
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3110 |
fixes x::"'a::real_normed_field" |
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3111 |
shows "isCont (\<lambda>x. poly p x) x" |
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3112 |
by (rule poly_DERIV [THEN DERIV_isCont]) |
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3113 |
|
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3114 |
lemma tendsto_poly [tendsto_intros]: "(f \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. poly p (f x)) \<longlongrightarrow> poly p a) F" |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
3115 |
for f :: "_ \<Rightarrow> 'a::real_normed_field" |
|
68532
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3116 |
by (rule isCont_tendsto_compose [OF poly_isCont]) |
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3117 |
|
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3118 |
lemma continuous_within_poly: "continuous (at z within s) (poly p)" |
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3119 |
for z :: "'a::{real_normed_field}"
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
3120 |
by (simp add: continuous_within tendsto_poly) |
|
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
3121 |
|
|
68532
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3122 |
lemma continuous_poly [continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. poly p (f x))" |
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3123 |
for f :: "_ \<Rightarrow> 'a::real_normed_field" |
|
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3124 |
unfolding continuous_def by (rule tendsto_poly) |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
3125 |
|
| 65346 | 3126 |
lemma continuous_on_poly [continuous_intros]: |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3127 |
fixes p :: "'a :: {real_normed_field} poly"
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3128 |
assumes "continuous_on A f" |
| 65346 | 3129 |
shows "continuous_on A (\<lambda>x. poly p (f x))" |
|
68532
f8b98d31ad45
Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents:
67399
diff
changeset
|
3130 |
by (metis DERIV_continuous_on assms continuous_on_compose2 poly_DERIV subset_UNIV) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3131 |
|
| 65346 | 3132 |
text \<open>Consequences of the derivative theorem above.\<close> |
3133 |
||
3134 |
lemma poly_differentiable[simp]: "(\<lambda>x. poly p x) differentiable (at x)" |
|
3135 |
for x :: real |
|
3136 |
by (simp add: real_differentiable_def) (blast intro: poly_DERIV) |
|
3137 |
||
3138 |
lemma poly_IVT_pos: "a < b \<Longrightarrow> poly p a < 0 \<Longrightarrow> 0 < poly p b \<Longrightarrow> \<exists>x. a < x \<and> x < b \<and> poly p x = 0" |
|
3139 |
for a b :: real |
|
|
72219
0f38c96a0a74
tidying up some theorem statements
paulson <lp15@cam.ac.uk>
parents:
72024
diff
changeset
|
3140 |
using IVT [of "poly p" a 0 b] by (auto simp add: order_le_less) |
| 65346 | 3141 |
|
3142 |
lemma poly_IVT_neg: "a < b \<Longrightarrow> 0 < poly p a \<Longrightarrow> poly p b < 0 \<Longrightarrow> \<exists>x. a < x \<and> x < b \<and> poly p x = 0" |
|
3143 |
for a b :: real |
|
3144 |
using poly_IVT_pos [where p = "- p"] by simp |
|
3145 |
||
3146 |
lemma poly_IVT: "a < b \<Longrightarrow> poly p a * poly p b < 0 \<Longrightarrow> \<exists>x>a. x < b \<and> poly p x = 0" |
|
3147 |
for p :: "real poly" |
|
3148 |
by (metis less_not_sym mult_less_0_iff poly_IVT_neg poly_IVT_pos) |
|
3149 |
||
3150 |
lemma poly_MVT: "a < b \<Longrightarrow> \<exists>x. a < x \<and> x < b \<and> poly p b - poly p a = (b - a) * poly (pderiv p) x" |
|
3151 |
for a b :: real |
|
| 72750 | 3152 |
by (simp add: MVT2) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3153 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3154 |
lemma poly_MVT': |
| 65346 | 3155 |
fixes a b :: real |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3156 |
assumes "{min a b..max a b} \<subseteq> A"
|
| 65346 | 3157 |
shows "\<exists>x\<in>A. poly p b - poly p a = (b - a) * poly (pderiv p) x" |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3158 |
proof (cases a b rule: linorder_cases) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3159 |
case less |
| 74362 | 3160 |
from poly_MVT[OF less, of p] obtain x |
3161 |
where "a < x" "x < b" "poly p b - poly p a = (b - a) * poly (pderiv p) x" |
|
3162 |
by auto |
|
| 65346 | 3163 |
then show ?thesis by (intro bexI[of _ x]) (auto intro!: subsetD[OF assms]) |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3164 |
next |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3165 |
case greater |
| 74362 | 3166 |
from poly_MVT[OF greater, of p] obtain x |
3167 |
where "b < x" "x < a" "poly p a - poly p b = (a - b) * poly (pderiv p) x" by auto |
|
| 65346 | 3168 |
then show ?thesis by (intro bexI[of _ x]) (auto simp: algebra_simps intro!: subsetD[OF assms]) |
3169 |
qed (use assms in auto) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3170 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3171 |
lemma poly_pinfty_gt_lc: |
| 63649 | 3172 |
fixes p :: "real poly" |
| 65346 | 3173 |
assumes "lead_coeff p > 0" |
| 65347 | 3174 |
shows "\<exists>n. \<forall> x \<ge> n. poly p x \<ge> lead_coeff p" |
| 63649 | 3175 |
using assms |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3176 |
proof (induct p) |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3177 |
case 0 |
| 63649 | 3178 |
then show ?case by auto |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3179 |
next |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3180 |
case (pCons a p) |
| 63649 | 3181 |
from this(1) consider "a \<noteq> 0" "p = 0" | "p \<noteq> 0" by auto |
3182 |
then show ?case |
|
3183 |
proof cases |
|
3184 |
case 1 |
|
3185 |
then show ?thesis by auto |
|
3186 |
next |
|
3187 |
case 2 |
|
3188 |
with pCons obtain n1 where gte_lcoeff: "\<forall>x\<ge>n1. lead_coeff p \<le> poly p x" |
|
3189 |
by auto |
|
3190 |
from pCons(3) \<open>p \<noteq> 0\<close> have gt_0: "lead_coeff p > 0" by auto |
|
3191 |
define n where "n = max n1 (1 + \<bar>a\<bar> / lead_coeff p)" |
|
3192 |
have "lead_coeff (pCons a p) \<le> poly (pCons a p) x" if "n \<le> x" for x |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3193 |
proof - |
| 63649 | 3194 |
from gte_lcoeff that have "lead_coeff p \<le> poly p x" |
3195 |
by (auto simp: n_def) |
|
3196 |
with gt_0 have "\<bar>a\<bar> / lead_coeff p \<ge> \<bar>a\<bar> / poly p x" and "poly p x > 0" |
|
3197 |
by (auto intro: frac_le) |
|
| 65346 | 3198 |
with \<open>n \<le> x\<close>[unfolded n_def] have "x \<ge> 1 + \<bar>a\<bar> / poly p x" |
| 63649 | 3199 |
by auto |
3200 |
with \<open>lead_coeff p \<le> poly p x\<close> \<open>poly p x > 0\<close> \<open>p \<noteq> 0\<close> |
|
3201 |
show "lead_coeff (pCons a p) \<le> poly (pCons a p) x" |
|
3202 |
by (auto simp: field_simps) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3203 |
qed |
| 63649 | 3204 |
then show ?thesis by blast |
3205 |
qed |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3206 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3207 |
|
| 64795 | 3208 |
lemma lemma_order_pderiv1: |
3209 |
"pderiv ([:- a, 1:] ^ Suc n * q) = [:- a, 1:] ^ Suc n * pderiv q + |
|
3210 |
smult (of_nat (Suc n)) (q * [:- a, 1:] ^ n)" |
|
| 65346 | 3211 |
by (simp only: pderiv_mult pderiv_power_Suc) (simp del: power_Suc of_nat_Suc add: pderiv_pCons) |
| 64795 | 3212 |
|
3213 |
lemma lemma_order_pderiv: |
|
3214 |
fixes p :: "'a :: field_char_0 poly" |
|
| 65346 | 3215 |
assumes n: "0 < n" |
3216 |
and pd: "pderiv p \<noteq> 0" |
|
3217 |
and pe: "p = [:- a, 1:] ^ n * q" |
|
3218 |
and nd: "\<not> [:- a, 1:] dvd q" |
|
3219 |
shows "n = Suc (order a (pderiv p))" |
|
| 64795 | 3220 |
proof - |
| 65346 | 3221 |
from assms have "pderiv ([:- a, 1:] ^ n * q) \<noteq> 0" |
3222 |
by auto |
|
3223 |
from assms obtain n' where "n = Suc n'" "0 < Suc n'" "pderiv ([:- a, 1:] ^ Suc n' * q) \<noteq> 0" |
|
3224 |
by (cases n) auto |
|
| 72750 | 3225 |
have "order a (pderiv ([:- a, 1:] ^ Suc n' * q)) = n'" |
| 64795 | 3226 |
proof (rule order_unique_lemma) |
3227 |
show "[:- a, 1:] ^ n' dvd pderiv ([:- a, 1:] ^ Suc n' * q)" |
|
| 72750 | 3228 |
unfolding lemma_order_pderiv1 |
3229 |
proof (rule dvd_add) |
|
3230 |
show "[:- a, 1:] ^ n' dvd [:- a, 1:] ^ Suc n' * pderiv q" |
|
3231 |
by (metis dvdI dvd_mult2 power_Suc2) |
|
3232 |
show "[:- a, 1:] ^ n' dvd smult (of_nat (Suc n')) (q * [:- a, 1:] ^ n')" |
|
3233 |
by (metis dvd_smult dvd_triv_right) |
|
3234 |
qed |
|
3235 |
have "k dvd k * pderiv q + smult (of_nat (Suc n')) l \<Longrightarrow> k dvd l" for k l |
|
3236 |
by (auto simp del: of_nat_Suc simp: dvd_add_right_iff dvd_smult_iff) |
|
3237 |
then show "\<not> [:- a, 1:] ^ Suc n' dvd pderiv ([:- a, 1:] ^ Suc n' * q)" |
|
3238 |
unfolding lemma_order_pderiv1 |
|
3239 |
by (metis nd dvd_mult_cancel_right power_not_zero pCons_eq_0_iff power_Suc zero_neq_one) |
|
| 64795 | 3240 |
qed |
3241 |
then show ?thesis |
|
3242 |
by (metis \<open>n = Suc n'\<close> pe) |
|
3243 |
qed |
|
3244 |
||
| 72750 | 3245 |
lemma order_pderiv: "order a p = Suc (order a (pderiv p))" |
3246 |
if "pderiv p \<noteq> 0" "order a p \<noteq> 0" |
|
| 65346 | 3247 |
for p :: "'a::field_char_0 poly" |
| 72750 | 3248 |
proof (cases "p = 0") |
3249 |
case False |
|
3250 |
obtain q where "p = [:- a, 1:] ^ order a p * q \<and> \<not> [:- a, 1:] dvd q" |
|
3251 |
using False order_decomp by blast |
|
3252 |
then show ?thesis |
|
3253 |
using lemma_order_pderiv that by blast |
|
3254 |
qed (use that in auto) |
|
| 64795 | 3255 |
|
3256 |
lemma poly_squarefree_decomp_order: |
|
| 65346 | 3257 |
fixes p :: "'a::field_char_0 poly" |
3258 |
assumes "pderiv p \<noteq> 0" |
|
3259 |
and p: "p = q * d" |
|
3260 |
and p': "pderiv p = e * d" |
|
3261 |
and d: "d = r * p + s * pderiv p" |
|
| 64795 | 3262 |
shows "order a q = (if order a p = 0 then 0 else 1)" |
3263 |
proof (rule classical) |
|
| 65346 | 3264 |
assume 1: "\<not> ?thesis" |
| 64795 | 3265 |
from \<open>pderiv p \<noteq> 0\<close> have "p \<noteq> 0" by auto |
3266 |
with p have "order a p = order a q + order a d" |
|
3267 |
by (simp add: order_mult) |
|
| 65346 | 3268 |
with 1 have "order a p \<noteq> 0" |
3269 |
by (auto split: if_splits) |
|
| 72750 | 3270 |
from \<open>pderiv p \<noteq> 0\<close> \<open>pderiv p = e * d\<close> have oapp: "order a (pderiv p) = order a e + order a d" |
| 65346 | 3271 |
by (simp add: order_mult) |
| 72750 | 3272 |
from \<open>pderiv p \<noteq> 0\<close> \<open>order a p \<noteq> 0\<close> have oap: "order a p = Suc (order a (pderiv p))" |
| 65346 | 3273 |
by (rule order_pderiv) |
3274 |
from \<open>p \<noteq> 0\<close> \<open>p = q * d\<close> have "d \<noteq> 0" |
|
3275 |
by simp |
|
| 72750 | 3276 |
have "[:- a, 1:] ^ order a (pderiv p) dvd r * p" |
3277 |
by (metis dvd_trans dvd_triv_right oap order_1 power_Suc) |
|
3278 |
then have "([:-a, 1:] ^ (order a (pderiv p))) dvd d" |
|
3279 |
by (simp add: d order_1) |
|
| 65346 | 3280 |
with \<open>d \<noteq> 0\<close> have "order a (pderiv p) \<le> order a d" |
3281 |
by (simp add: order_divides) |
|
| 64795 | 3282 |
show ?thesis |
3283 |
using \<open>order a p = order a q + order a d\<close> |
|
| 72750 | 3284 |
and oapp oap |
| 65346 | 3285 |
and \<open>order a (pderiv p) \<le> order a d\<close> |
| 64795 | 3286 |
by auto |
3287 |
qed |
|
3288 |
||
| 65346 | 3289 |
lemma poly_squarefree_decomp_order2: |
| 65347 | 3290 |
"pderiv p \<noteq> 0 \<Longrightarrow> p = q * d \<Longrightarrow> pderiv p = e * d \<Longrightarrow> |
3291 |
d = r * p + s * pderiv p \<Longrightarrow> \<forall>a. order a q = (if order a p = 0 then 0 else 1)" |
|
3292 |
for p :: "'a::field_char_0 poly" |
|
3293 |
by (blast intro: poly_squarefree_decomp_order) |
|
| 64795 | 3294 |
|
| 65346 | 3295 |
lemma order_pderiv2: |
| 65347 | 3296 |
"pderiv p \<noteq> 0 \<Longrightarrow> order a p \<noteq> 0 \<Longrightarrow> order a (pderiv p) = n \<longleftrightarrow> order a p = Suc n" |
3297 |
for p :: "'a::field_char_0 poly" |
|
3298 |
by (auto dest: order_pderiv) |
|
| 64795 | 3299 |
|
3300 |
definition rsquarefree :: "'a::idom poly \<Rightarrow> bool" |
|
3301 |
where "rsquarefree p \<longleftrightarrow> p \<noteq> 0 \<and> (\<forall>a. order a p = 0 \<or> order a p = 1)" |
|
3302 |
||
| 65347 | 3303 |
lemma pderiv_iszero: "pderiv p = 0 \<Longrightarrow> \<exists>h. p = [:h:]" |
3304 |
for p :: "'a::{semidom,semiring_char_0} poly"
|
|
| 64795 | 3305 |
by (cases p) (auto simp: pderiv_eq_0_iff split: if_splits) |
3306 |
||
| 65347 | 3307 |
lemma rsquarefree_roots: "rsquarefree p \<longleftrightarrow> (\<forall>a. \<not> (poly p a = 0 \<and> poly (pderiv p) a = 0))" |
3308 |
for p :: "'a::field_char_0 poly" |
|
| 72750 | 3309 |
proof (cases "p = 0") |
3310 |
case False |
|
3311 |
show ?thesis |
|
3312 |
proof (cases "pderiv p = 0") |
|
3313 |
case True |
|
3314 |
with \<open>p \<noteq> 0\<close> pderiv_iszero show ?thesis |
|
3315 |
by (force simp add: order_0I rsquarefree_def) |
|
3316 |
next |
|
3317 |
case False |
|
3318 |
with \<open>p \<noteq> 0\<close> order_pderiv2 show ?thesis |
|
3319 |
by (force simp add: rsquarefree_def order_root) |
|
3320 |
qed |
|
3321 |
qed (simp add: rsquarefree_def) |
|
| 64795 | 3322 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3323 |
lemma rsquarefree_root_order: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3324 |
assumes "rsquarefree p" "poly p z = 0" "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3325 |
shows "order z p = 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3326 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3327 |
from assms have "order z p \<in> {0, 1}" by (auto simp: rsquarefree_def)
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3328 |
moreover from assms have "order z p > 0" by (auto simp: order_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3329 |
ultimately show "order z p = 1" by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3330 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3331 |
|
| 64795 | 3332 |
lemma poly_squarefree_decomp: |
| 65347 | 3333 |
fixes p :: "'a::field_char_0 poly" |
3334 |
assumes "pderiv p \<noteq> 0" |
|
| 64795 | 3335 |
and "p = q * d" |
3336 |
and "pderiv p = e * d" |
|
3337 |
and "d = r * p + s * pderiv p" |
|
| 65347 | 3338 |
shows "rsquarefree q \<and> (\<forall>a. poly q a = 0 \<longleftrightarrow> poly p a = 0)" |
| 64795 | 3339 |
proof - |
3340 |
from \<open>pderiv p \<noteq> 0\<close> have "p \<noteq> 0" by auto |
|
3341 |
with \<open>p = q * d\<close> have "q \<noteq> 0" by simp |
|
| 65347 | 3342 |
from assms have "\<forall>a. order a q = (if order a p = 0 then 0 else 1)" |
3343 |
by (rule poly_squarefree_decomp_order2) |
|
| 64795 | 3344 |
with \<open>p \<noteq> 0\<close> \<open>q \<noteq> 0\<close> show ?thesis |
3345 |
by (simp add: rsquarefree_def order_root) |
|
3346 |
qed |
|
3347 |
||
|
79672
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
3348 |
lemma has_field_derivative_poly [derivative_intros]: |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
3349 |
assumes "(f has_field_derivative f') (at x within A)" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
3350 |
shows "((\<lambda>x. poly p (f x)) has_field_derivative |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
3351 |
(f' * poly (pderiv p) (f x))) (at x within A)" |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
3352 |
using DERIV_chain[OF poly_DERIV assms, of p] by (simp add: o_def mult_ac) |
|
76720aeab21e
New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents:
76386
diff
changeset
|
3353 |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3354 |
|
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3355 |
subsection \<open>Algebraic numbers\<close> |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3356 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3357 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3358 |
lemma intpolyE: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3359 |
assumes "\<And>i. poly.coeff p i \<in> \<int>" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3360 |
obtains q where "p = map_poly of_int q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3361 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3362 |
have "\<forall>i\<in>{..Polynomial.degree p}. \<exists>x. poly.coeff p i = of_int x"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3363 |
using assms by (auto simp: Ints_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3364 |
from bchoice[OF this] obtain f |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3365 |
where f: "\<And>i. i \<le> Polynomial.degree p \<Longrightarrow> poly.coeff p i = of_int (f i)" by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3366 |
define q where "q = Poly (map f [0..<Suc (Polynomial.degree p)])" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3367 |
have "p = map_poly of_int q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3368 |
by (intro poly_eqI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3369 |
(auto simp: coeff_map_poly q_def nth_default_def f coeff_eq_0 simp del: upt_Suc) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3370 |
with that show ?thesis by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3371 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3372 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3373 |
lemma ratpolyE: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3374 |
assumes "\<And>i. poly.coeff p i \<in> \<rat>" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3375 |
obtains q where "p = map_poly of_rat q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3376 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3377 |
have "\<forall>i\<in>{..Polynomial.degree p}. \<exists>x. poly.coeff p i = of_rat x"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3378 |
using assms by (auto simp: Rats_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3379 |
from bchoice[OF this] obtain f |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3380 |
where f: "\<And>i. i \<le> Polynomial.degree p \<Longrightarrow> poly.coeff p i = of_rat (f i)" by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3381 |
define q where "q = Poly (map f [0..<Suc (Polynomial.degree p)])" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3382 |
have "p = map_poly of_rat q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3383 |
by (intro poly_eqI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3384 |
(auto simp: coeff_map_poly q_def nth_default_def f coeff_eq_0 simp del: upt_Suc) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3385 |
with that show ?thesis by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3386 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3387 |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3388 |
text \<open> |
| 65346 | 3389 |
Algebraic numbers can be defined in two equivalent ways: all real numbers that are |
3390 |
roots of rational polynomials or of integer polynomials. The Algebraic-Numbers AFP entry |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3391 |
uses the rational definition, but we need the integer definition. |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3392 |
|
| 65346 | 3393 |
The equivalence is obvious since any rational polynomial can be multiplied with the |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3394 |
LCM of its coefficients, yielding an integer polynomial with the same roots. |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3395 |
\<close> |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3396 |
|
| 65347 | 3397 |
definition algebraic :: "'a :: field_char_0 \<Rightarrow> bool" |
3398 |
where "algebraic x \<longleftrightarrow> (\<exists>p. (\<forall>i. coeff p i \<in> \<int>) \<and> p \<noteq> 0 \<and> poly p x = 0)" |
|
3399 |
||
3400 |
lemma algebraicI: "(\<And>i. coeff p i \<in> \<int>) \<Longrightarrow> p \<noteq> 0 \<Longrightarrow> poly p x = 0 \<Longrightarrow> algebraic x" |
|
3401 |
unfolding algebraic_def by blast |
|
| 65346 | 3402 |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3403 |
lemma algebraicE: |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3404 |
assumes "algebraic x" |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3405 |
obtains p where "\<And>i. coeff p i \<in> \<int>" "p \<noteq> 0" "poly p x = 0" |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3406 |
using assms unfolding algebraic_def by blast |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3407 |
|
| 65347 | 3408 |
lemma algebraic_altdef: "algebraic x \<longleftrightarrow> (\<exists>p. (\<forall>i. coeff p i \<in> \<rat>) \<and> p \<noteq> 0 \<and> poly p x = 0)" |
3409 |
for p :: "'a::field_char_0 poly" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3410 |
proof safe |
| 65347 | 3411 |
fix p |
3412 |
assume rat: "\<forall>i. coeff p i \<in> \<rat>" and root: "poly p x = 0" and nz: "p \<noteq> 0" |
|
| 63040 | 3413 |
define cs where "cs = coeffs p" |
| 65347 | 3414 |
from rat have "\<forall>c\<in>range (coeff p). \<exists>c'. c = of_rat c'" |
3415 |
unfolding Rats_def by blast |
|
| 63060 | 3416 |
then obtain f where f: "coeff p i = of_rat (f (coeff p i))" for i |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3417 |
by (subst (asm) bchoice_iff) blast |
| 63040 | 3418 |
define cs' where "cs' = map (quotient_of \<circ> f) (coeffs p)" |
3419 |
define d where "d = Lcm (set (map snd cs'))" |
|
3420 |
define p' where "p' = smult (of_int d) p" |
|
| 65346 | 3421 |
|
| 65347 | 3422 |
have "coeff p' n \<in> \<int>" for n |
3423 |
proof (cases "n \<le> degree p") |
|
3424 |
case True |
|
3425 |
define c where "c = coeff p n" |
|
3426 |
define a where "a = fst (quotient_of (f (coeff p n)))" |
|
3427 |
define b where "b = snd (quotient_of (f (coeff p n)))" |
|
3428 |
have b_pos: "b > 0" |
|
3429 |
unfolding b_def using quotient_of_denom_pos' by simp |
|
3430 |
have "coeff p' n = of_int d * coeff p n" |
|
3431 |
by (simp add: p'_def) |
|
3432 |
also have "coeff p n = of_rat (of_int a / of_int b)" |
|
3433 |
unfolding a_def b_def |
|
3434 |
by (subst quotient_of_div [of "f (coeff p n)", symmetric]) (simp_all add: f [symmetric]) |
|
3435 |
also have "of_int d * \<dots> = of_rat (of_int (a*d) / of_int b)" |
|
3436 |
by (simp add: of_rat_mult of_rat_divide) |
|
3437 |
also from nz True have "b \<in> snd ` set cs'" |
|
3438 |
by (force simp: cs'_def o_def b_def coeffs_def simp del: upt_Suc) |
|
3439 |
then have "b dvd (a * d)" |
|
3440 |
by (simp add: d_def) |
|
3441 |
then have "of_int (a * d) / of_int b \<in> (\<int> :: rat set)" |
|
3442 |
by (rule of_int_divide_in_Ints) |
|
3443 |
then have "of_rat (of_int (a * d) / of_int b) \<in> \<int>" by (elim Ints_cases) auto |
|
3444 |
finally show ?thesis . |
|
3445 |
next |
|
3446 |
case False |
|
3447 |
then show ?thesis |
|
3448 |
by (auto simp: p'_def not_le coeff_eq_0) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3449 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3450 |
moreover have "set (map snd cs') \<subseteq> {0<..}"
|
| 65346 | 3451 |
unfolding cs'_def using quotient_of_denom_pos' by (auto simp: coeffs_def simp del: upt_Suc) |
| 65347 | 3452 |
then have "d \<noteq> 0" |
3453 |
unfolding d_def by (induct cs') simp_all |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3454 |
with nz have "p' \<noteq> 0" by (simp add: p'_def) |
| 65347 | 3455 |
moreover from root have "poly p' x = 0" |
3456 |
by (simp add: p'_def) |
|
3457 |
ultimately show "algebraic x" |
|
3458 |
unfolding algebraic_def by blast |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3459 |
next |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3460 |
assume "algebraic x" |
| 63060 | 3461 |
then obtain p where p: "coeff p i \<in> \<int>" "poly p x = 0" "p \<noteq> 0" for i |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3462 |
by (force simp: algebraic_def) |
| 65347 | 3463 |
moreover have "coeff p i \<in> \<int> \<Longrightarrow> coeff p i \<in> \<rat>" for i |
3464 |
by (elim Ints_cases) simp |
|
3465 |
ultimately show "\<exists>p. (\<forall>i. coeff p i \<in> \<rat>) \<and> p \<noteq> 0 \<and> poly p x = 0" by auto |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3466 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3467 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3468 |
lemma algebraicI': "(\<And>i. coeff p i \<in> \<rat>) \<Longrightarrow> p \<noteq> 0 \<Longrightarrow> poly p x = 0 \<Longrightarrow> algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3469 |
unfolding algebraic_altdef by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3470 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3471 |
lemma algebraicE': |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3472 |
assumes "algebraic (x :: 'a :: field_char_0)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3473 |
obtains p where "p \<noteq> 0" "poly (map_poly of_int p) x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3474 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3475 |
from assms obtain q where q: "\<And>i. coeff q i \<in> \<int>" "q \<noteq> 0" "poly q x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3476 |
by (erule algebraicE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3477 |
moreover from this(1) obtain q' where q': "q = map_poly of_int q'" by (erule intpolyE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3478 |
moreover have "q' \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3479 |
using q' q by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3480 |
ultimately show ?thesis by (intro that[of q']) simp_all |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3481 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3482 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3483 |
lemma algebraicE'_nonzero: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3484 |
assumes "algebraic (x :: 'a :: field_char_0)" "x \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3485 |
obtains p where "p \<noteq> 0" "coeff p 0 \<noteq> 0" "poly (map_poly of_int p) x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3486 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3487 |
from assms(1) obtain p where p: "p \<noteq> 0" "poly (map_poly of_int p) x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3488 |
by (erule algebraicE') |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3489 |
define n :: nat where "n = order 0 p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3490 |
have "monom 1 n dvd p" by (simp add: monom_1_dvd_iff p n_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3491 |
then obtain q where q: "p = monom 1 n * q" by (erule dvdE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3492 |
have [simp]: "map_poly of_int (monom 1 n * q) = monom (1 :: 'a) n * map_poly of_int q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3493 |
by (induction n) (auto simp: monom_0 monom_Suc map_poly_pCons) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3494 |
from p have "q \<noteq> 0" "poly (map_poly of_int q) x = 0" by (auto simp: q poly_monom assms(2)) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3495 |
moreover from this have "order 0 p = n + order 0 q" by (simp add: q order_mult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3496 |
hence "order 0 q = 0" by (simp add: n_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3497 |
with \<open>q \<noteq> 0\<close> have "poly q 0 \<noteq> 0" by (simp add: order_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3498 |
ultimately show ?thesis using that[of q] by (auto simp: poly_0_coeff_0) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3499 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3500 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3501 |
lemma rat_imp_algebraic: "x \<in> \<rat> \<Longrightarrow> algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3502 |
proof (rule algebraicI') |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3503 |
show "poly [:-x, 1:] x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3504 |
by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3505 |
qed (auto simp: coeff_pCons split: nat.splits) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3506 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3507 |
lemma algebraic_0 [simp, intro]: "algebraic 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3508 |
and algebraic_1 [simp, intro]: "algebraic 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3509 |
and algebraic_numeral [simp, intro]: "algebraic (numeral n)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3510 |
and algebraic_of_nat [simp, intro]: "algebraic (of_nat k)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3511 |
and algebraic_of_int [simp, intro]: "algebraic (of_int m)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3512 |
by (simp_all add: rat_imp_algebraic) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3513 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3514 |
lemma algebraic_ii [simp, intro]: "algebraic \<i>" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3515 |
proof (rule algebraicI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3516 |
show "poly [:1, 0, 1:] \<i> = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3517 |
by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3518 |
qed (auto simp: coeff_pCons split: nat.splits) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3519 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3520 |
lemma algebraic_minus [intro]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3521 |
assumes "algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3522 |
shows "algebraic (-x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3523 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3524 |
from assms obtain p where p: "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3525 |
by (elim algebraicE) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3526 |
define s where "s = (if even (degree p) then 1 else -1 :: 'a)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3527 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3528 |
define q where "q = Polynomial.smult s (pcompose p [:0, -1:])" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3529 |
have "poly q (-x) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3530 |
using p by (auto simp: q_def poly_pcompose s_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3531 |
moreover have "q \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3532 |
using p by (auto simp: q_def s_def pcompose_eq_0_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3533 |
find_theorems "pcompose _ _ = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3534 |
moreover have "coeff q i \<in> \<int>" for i |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3535 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3536 |
have "coeff (pcompose p [:0, -1:]) i \<in> \<int>" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3537 |
using p by (intro coeff_pcompose_semiring_closed) (auto simp: coeff_pCons split: nat.splits) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3538 |
thus ?thesis by (simp add: q_def s_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3539 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3540 |
ultimately show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3541 |
by (auto simp: algebraic_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3542 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3543 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3544 |
lemma algebraic_minus_iff [simp]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3545 |
"algebraic (-x) \<longleftrightarrow> algebraic (x :: 'a :: field_char_0)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3546 |
using algebraic_minus[of x] algebraic_minus[of "-x"] by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3547 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3548 |
lemma algebraic_inverse [intro]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3549 |
assumes "algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3550 |
shows "algebraic (inverse x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3551 |
proof (cases "x = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3552 |
case [simp]: False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3553 |
from assms obtain p where p: "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3554 |
by (elim algebraicE) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3555 |
show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3556 |
proof (rule algebraicI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3557 |
show "poly (reflect_poly p) (inverse x) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3558 |
using assms p by (simp add: poly_reflect_poly_nz) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3559 |
qed (use assms p in \<open>auto simp: coeff_reflect_poly\<close>) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3560 |
qed auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3561 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3562 |
lemma algebraic_root: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3563 |
assumes "algebraic y" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3564 |
and "poly p x = y" and "\<forall>i. coeff p i \<in> \<int>" and "lead_coeff p = 1" and "degree p > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3565 |
shows "algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3566 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3567 |
from assms obtain q where q: "poly q y = 0" "\<forall>i. coeff q i \<in> \<int>" "q \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3568 |
by (elim algebraicE) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3569 |
show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3570 |
proof (rule algebraicI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3571 |
from assms q show "pcompose q p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3572 |
by (auto simp: pcompose_eq_0_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3573 |
from assms q show "coeff (pcompose q p) i \<in> \<int>" for i |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3574 |
by (intro allI coeff_pcompose_semiring_closed) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3575 |
show "poly (pcompose q p) x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3576 |
using assms q by (simp add: poly_pcompose) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3577 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3578 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3579 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3580 |
lemma algebraic_abs_real [simp]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3581 |
"algebraic \<bar>x :: real\<bar> \<longleftrightarrow> algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3582 |
by (auto simp: abs_if) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3583 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3584 |
lemma algebraic_nth_root_real [intro]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3585 |
assumes "algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3586 |
shows "algebraic (root n x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3587 |
proof (cases "n = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3588 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3589 |
show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3590 |
proof (rule algebraic_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3591 |
show "poly (monom 1 n) (root n x) = (if even n then \<bar>x\<bar> else x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3592 |
using sgn_power_root[of n x] False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3593 |
by (auto simp add: poly_monom sgn_if split: if_splits) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3594 |
qed (use False assms in \<open>auto simp: degree_monom_eq\<close>) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3595 |
qed auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3596 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3597 |
lemma algebraic_sqrt [intro]: "algebraic x \<Longrightarrow> algebraic (sqrt x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3598 |
by (auto simp: sqrt_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3599 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3600 |
lemma algebraic_csqrt [intro]: "algebraic x \<Longrightarrow> algebraic (csqrt x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3601 |
by (rule algebraic_root[where p = "monom 1 2"]) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3602 |
(auto simp: poly_monom degree_monom_eq) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3603 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3604 |
lemma algebraic_cnj [intro]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3605 |
assumes "algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3606 |
shows "algebraic (cnj x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3607 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3608 |
from assms obtain p where p: "poly p x = 0" "\<forall>i. coeff p i \<in> \<int>" "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3609 |
by (elim algebraicE) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3610 |
show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3611 |
proof (rule algebraicI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3612 |
show "poly (map_poly cnj p) (cnj x) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3613 |
using p by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3614 |
show "map_poly cnj p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3615 |
using p by (auto simp: map_poly_eq_0_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3616 |
show "coeff (map_poly cnj p) i \<in> \<int>" for i |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3617 |
using p by (auto simp: coeff_map_poly) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3618 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3619 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3620 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3621 |
lemma algebraic_cnj_iff [simp]: "algebraic (cnj x) \<longleftrightarrow> algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3622 |
using algebraic_cnj[of x] algebraic_cnj[of "cnj x"] by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3623 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3624 |
lemma algebraic_of_real [intro]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3625 |
assumes "algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3626 |
shows "algebraic (of_real x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3627 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3628 |
from assms obtain p where p: "p \<noteq> 0" "poly (map_poly of_int p) x = 0" by (erule algebraicE') |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3629 |
have 1: "map_poly of_int p \<noteq> (0 :: 'a poly)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3630 |
using p by (metis coeff_0 coeff_map_poly leading_coeff_0_iff of_int_eq_0_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3631 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3632 |
have "poly (map_poly of_int p) (of_real x :: 'a) = of_real (poly (map_poly of_int p) x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3633 |
by (simp add: poly_altdef degree_map_poly coeff_map_poly) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3634 |
also note p(2) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3635 |
finally have 2: "poly (map_poly of_int p) (of_real x :: 'a) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3636 |
by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3637 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3638 |
from 1 2 show "algebraic (of_real x :: 'a)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3639 |
by (intro algebraicI[of "map_poly of_int p"]) (auto simp: coeff_map_poly) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3640 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3641 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3642 |
lemma algebraic_of_real_iff [simp]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3643 |
"algebraic (of_real x :: 'a :: {real_algebra_1,field_char_0}) \<longleftrightarrow> algebraic x"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3644 |
proof |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3645 |
assume "algebraic (of_real x :: 'a)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3646 |
then obtain p where p: "p \<noteq> 0" "poly (map_poly of_int p) (of_real x :: 'a) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3647 |
by (erule algebraicE') |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3648 |
have 1: "(map_poly of_int p :: real poly) \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3649 |
using p by (metis coeff_0 coeff_map_poly leading_coeff_0_iff of_int_0 of_int_eq_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3650 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3651 |
note p(2) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3652 |
also have "poly (map_poly of_int p) (of_real x :: 'a) = of_real (poly (map_poly of_int p) x)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3653 |
by (simp add: poly_altdef degree_map_poly coeff_map_poly) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3654 |
also have "\<dots> = 0 \<longleftrightarrow> poly (map_poly of_int p) x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3655 |
using of_real_eq_0_iff by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3656 |
finally have 2: "poly (map_poly real_of_int p) x = 0" . |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3657 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3658 |
from 1 and 2 show "algebraic x" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3659 |
by (intro algebraicI[of "map_poly of_int p"]) (auto simp: coeff_map_poly) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3660 |
qed auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
3661 |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3662 |
|
|
73109
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3663 |
subsection \<open>Algebraic integers\<close> |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3664 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3665 |
inductive algebraic_int :: "'a :: field \<Rightarrow> bool" where |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3666 |
"\<lbrakk>lead_coeff p = 1; \<forall>i. coeff p i \<in> \<int>; poly p x = 0\<rbrakk> \<Longrightarrow> algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3667 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3668 |
lemma algebraic_int_altdef_ipoly: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3669 |
fixes x :: "'a :: field_char_0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3670 |
shows "algebraic_int x \<longleftrightarrow> (\<exists>p. poly (map_poly of_int p) x = 0 \<and> lead_coeff p = 1)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3671 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3672 |
assume "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3673 |
then obtain p where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3674 |
by (auto elim: algebraic_int.cases) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3675 |
define the_int where "the_int = (\<lambda>x::'a. THE r. x = of_int r)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3676 |
define p' where "p' = map_poly the_int p" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3677 |
have of_int_the_int: "of_int (the_int x) = x" if "x \<in> \<int>" for x |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3678 |
unfolding the_int_def by (rule sym, rule theI') (insert that, auto simp: Ints_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3679 |
have the_int_0_iff: "the_int x = 0 \<longleftrightarrow> x = 0" if "x \<in> \<int>" for x |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3680 |
using of_int_the_int[OF that] by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3681 |
have [simp]: "the_int 0 = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3682 |
by (subst the_int_0_iff) auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3683 |
have "map_poly of_int p' = map_poly (of_int \<circ> the_int) p" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3684 |
by (simp add: p'_def map_poly_map_poly) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3685 |
also from p of_int_the_int have "\<dots> = p" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3686 |
by (subst poly_eq_iff) (auto simp: coeff_map_poly) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3687 |
finally have p_p': "map_poly of_int p' = p" . |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3688 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3689 |
show "(\<exists>p. poly (map_poly of_int p) x = 0 \<and> lead_coeff p = 1)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3690 |
proof (intro exI conjI notI) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3691 |
from p show "poly (map_poly of_int p') x = 0" by (simp add: p_p') |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3692 |
next |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3693 |
show "lead_coeff p' = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3694 |
using p by (simp flip: p_p' add: degree_map_poly coeff_map_poly) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3695 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3696 |
next |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3697 |
assume "\<exists>p. poly (map_poly of_int p) x = 0 \<and> lead_coeff p = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3698 |
then obtain p where p: "poly (map_poly of_int p) x = 0" "lead_coeff p = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3699 |
by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3700 |
define p' where "p' = (map_poly of_int p :: 'a poly)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3701 |
from p have "lead_coeff p' = 1" "poly p' x = 0" "\<forall>i. coeff p' i \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3702 |
by (auto simp: p'_def coeff_map_poly degree_map_poly) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3703 |
thus "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3704 |
by (intro algebraic_int.intros) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3705 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3706 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3707 |
theorem rational_algebraic_int_is_int: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3708 |
assumes "algebraic_int x" and "x \<in> \<rat>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3709 |
shows "x \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3710 |
proof - |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3711 |
from assms(2) obtain a b where ab: "b > 0" "Rings.coprime a b" and x_eq: "x = of_int a / of_int b" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3712 |
by (auto elim: Rats_cases') |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3713 |
from \<open>b > 0\<close> have [simp]: "b \<noteq> 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3714 |
by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3715 |
from assms(1) obtain p |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3716 |
where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3717 |
by (auto simp: algebraic_int.simps) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3718 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3719 |
define q :: "'a poly" where "q = [:-of_int a, of_int b:]" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3720 |
have "poly q x = 0" "q \<noteq> 0" "\<forall>i. coeff q i \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3721 |
by (auto simp: x_eq q_def coeff_pCons split: nat.splits) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3722 |
define n where "n = degree p" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3723 |
have "n > 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3724 |
using p by (intro Nat.gr0I) (auto simp: n_def elim!: degree_eq_zeroE) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3725 |
have "(\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i - 1))) \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3726 |
using p by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3727 |
then obtain R where R: "of_int R = (\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i - 1)))" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3728 |
by (auto simp: Ints_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3729 |
have [simp]: "coeff p n = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3730 |
using p by (auto simp: n_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3731 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3732 |
have "0 = poly p x * of_int b ^ n" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3733 |
using p by simp |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3734 |
also have "\<dots> = (\<Sum>i\<le>n. coeff p i * x ^ i * of_int b ^ n)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3735 |
by (simp add: poly_altdef n_def sum_distrib_right) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3736 |
also have "\<dots> = (\<Sum>i\<le>n. coeff p i * of_int (a ^ i * b ^ (n - i)))" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3737 |
by (intro sum.cong) (auto simp: x_eq field_simps simp flip: power_add) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3738 |
also have "{..n} = insert n {..<n}"
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3739 |
using \<open>n > 0\<close> by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3740 |
also have "(\<Sum>i\<in>\<dots>. coeff p i * of_int (a ^ i * b ^ (n - i))) = |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3741 |
coeff p n * of_int (a ^ n) + (\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i)))" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3742 |
by (subst sum.insert) auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3743 |
also have "(\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i))) = |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3744 |
(\<Sum>i<n. coeff p i * of_int (a ^ i * b * b ^ (n - i - 1)))" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3745 |
by (intro sum.cong) (auto simp flip: power_add power_Suc simp: Suc_diff_Suc) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3746 |
also have "\<dots> = of_int (b * R)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3747 |
by (simp add: R sum_distrib_left sum_distrib_right mult_ac) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3748 |
finally have "of_int (a ^ n) = (-of_int (b * R) :: 'a)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3749 |
by (auto simp: add_eq_0_iff) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3750 |
hence "a ^ n = -b * R" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3751 |
by (simp flip: of_int_mult of_int_power of_int_minus) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3752 |
hence "b dvd a ^ n" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3753 |
by simp |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3754 |
with \<open>Rings.coprime a b\<close> have "b dvd 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3755 |
by (meson coprime_power_left_iff dvd_refl not_coprimeI) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3756 |
with x_eq and \<open>b > 0\<close> show ?thesis |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3757 |
by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3758 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3759 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3760 |
lemma algebraic_int_imp_algebraic [dest]: "algebraic_int x \<Longrightarrow> algebraic x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3761 |
by (auto simp: algebraic_int.simps algebraic_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3762 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3763 |
lemma int_imp_algebraic_int: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3764 |
assumes "x \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3765 |
shows "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3766 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3767 |
show "\<forall>i. coeff [:-x, 1:] i \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3768 |
using assms by (auto simp: coeff_pCons split: nat.splits) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3769 |
qed auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3770 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3771 |
lemma algebraic_int_0 [simp, intro]: "algebraic_int 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3772 |
and algebraic_int_1 [simp, intro]: "algebraic_int 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3773 |
and algebraic_int_numeral [simp, intro]: "algebraic_int (numeral n)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3774 |
and algebraic_int_of_nat [simp, intro]: "algebraic_int (of_nat k)" |
|
73114
9bf36baa8686
Corrected lemma that was too specific in HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents:
73109
diff
changeset
|
3775 |
and algebraic_int_of_int [simp, intro]: "algebraic_int (of_int m)" |
|
73109
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3776 |
by (simp_all add: int_imp_algebraic_int) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3777 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3778 |
lemma algebraic_int_ii [simp, intro]: "algebraic_int \<i>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3779 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3780 |
show "poly [:1, 0, 1:] \<i> = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3781 |
by simp |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3782 |
qed (auto simp: coeff_pCons split: nat.splits) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3783 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3784 |
lemma algebraic_int_minus [intro]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3785 |
assumes "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3786 |
shows "algebraic_int (-x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3787 |
proof - |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3788 |
from assms obtain p where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3789 |
by (auto simp: algebraic_int.simps) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3790 |
define s where "s = (if even (degree p) then 1 else -1 :: 'a)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3791 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3792 |
define q where "q = Polynomial.smult s (pcompose p [:0, -1:])" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3793 |
have "lead_coeff q = s * lead_coeff (pcompose p [:0, -1:])" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3794 |
by (simp add: q_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3795 |
also have "lead_coeff (pcompose p [:0, -1:]) = lead_coeff p * (- 1) ^ degree p" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3796 |
by (subst lead_coeff_comp) auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3797 |
finally have "poly q (-x) = 0" and "lead_coeff q = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3798 |
using p by (auto simp: q_def poly_pcompose s_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3799 |
moreover have "coeff q i \<in> \<int>" for i |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3800 |
proof - |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3801 |
have "coeff (pcompose p [:0, -1:]) i \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3802 |
using p by (intro coeff_pcompose_semiring_closed) (auto simp: coeff_pCons split: nat.splits) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3803 |
thus ?thesis by (simp add: q_def s_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3804 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3805 |
ultimately show ?thesis |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3806 |
by (auto simp: algebraic_int.simps) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3807 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3808 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3809 |
lemma algebraic_int_minus_iff [simp]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3810 |
"algebraic_int (-x) \<longleftrightarrow> algebraic_int (x :: 'a :: field_char_0)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3811 |
using algebraic_int_minus[of x] algebraic_int_minus[of "-x"] by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3812 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3813 |
lemma algebraic_int_inverse [intro]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3814 |
assumes "poly p x = 0" and "\<forall>i. coeff p i \<in> \<int>" and "coeff p 0 = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3815 |
shows "algebraic_int (inverse x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3816 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3817 |
from assms have [simp]: "x \<noteq> 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3818 |
by (auto simp: poly_0_coeff_0) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3819 |
show "poly (reflect_poly p) (inverse x) = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3820 |
using assms by (simp add: poly_reflect_poly_nz) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3821 |
qed (use assms in \<open>auto simp: coeff_reflect_poly\<close>) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3822 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3823 |
lemma algebraic_int_root: |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
3824 |
assumes "algebraic_int y" |
|
73109
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3825 |
and "poly p x = y" and "\<forall>i. coeff p i \<in> \<int>" and "lead_coeff p = 1" and "degree p > 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3826 |
shows "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3827 |
proof - |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3828 |
from assms obtain q where q: "poly q y = 0" "\<forall>i. coeff q i \<in> \<int>" "lead_coeff q = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3829 |
by (auto simp: algebraic_int.simps) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3830 |
show ?thesis |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3831 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3832 |
from assms q show "lead_coeff (pcompose q p) = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3833 |
by (subst lead_coeff_comp) auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3834 |
from assms q show "\<forall>i. coeff (pcompose q p) i \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3835 |
by (intro allI coeff_pcompose_semiring_closed) auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3836 |
show "poly (pcompose q p) x = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3837 |
using assms q by (simp add: poly_pcompose) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3838 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3839 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3840 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3841 |
lemma algebraic_int_abs_real [simp]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3842 |
"algebraic_int \<bar>x :: real\<bar> \<longleftrightarrow> algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3843 |
by (auto simp: abs_if) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3844 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3845 |
lemma algebraic_int_nth_root_real [intro]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3846 |
assumes "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3847 |
shows "algebraic_int (root n x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3848 |
proof (cases "n = 0") |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3849 |
case False |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3850 |
show ?thesis |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3851 |
proof (rule algebraic_int_root) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3852 |
show "poly (monom 1 n) (root n x) = (if even n then \<bar>x\<bar> else x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3853 |
using sgn_power_root[of n x] False |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3854 |
by (auto simp add: poly_monom sgn_if split: if_splits) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3855 |
qed (use False assms in \<open>auto simp: degree_monom_eq\<close>) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3856 |
qed auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3857 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3858 |
lemma algebraic_int_sqrt [intro]: "algebraic_int x \<Longrightarrow> algebraic_int (sqrt x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3859 |
by (auto simp: sqrt_def) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3860 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3861 |
lemma algebraic_int_csqrt [intro]: "algebraic_int x \<Longrightarrow> algebraic_int (csqrt x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3862 |
by (rule algebraic_int_root[where p = "monom 1 2"]) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3863 |
(auto simp: poly_monom degree_monom_eq) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3864 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3865 |
lemma algebraic_int_cnj [intro]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3866 |
assumes "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3867 |
shows "algebraic_int (cnj x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3868 |
proof - |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3869 |
from assms obtain p where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3870 |
by (auto simp: algebraic_int.simps) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3871 |
show ?thesis |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3872 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3873 |
show "poly (map_poly cnj p) (cnj x) = 0" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3874 |
using p by simp |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3875 |
show "lead_coeff (map_poly cnj p) = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3876 |
using p by (simp add: coeff_map_poly degree_map_poly) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3877 |
show "\<forall>i. coeff (map_poly cnj p) i \<in> \<int>" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3878 |
using p by (auto simp: coeff_map_poly) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3879 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3880 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3881 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3882 |
lemma algebraic_int_cnj_iff [simp]: "algebraic_int (cnj x) \<longleftrightarrow> algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3883 |
using algebraic_int_cnj[of x] algebraic_int_cnj[of "cnj x"] by auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3884 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3885 |
lemma algebraic_int_of_real [intro]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3886 |
assumes "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3887 |
shows "algebraic_int (of_real x)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3888 |
proof - |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3889 |
from assms obtain p where p: "poly p x = 0" "\<forall>i. coeff p i \<in> \<int>" "lead_coeff p = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3890 |
by (auto simp: algebraic_int.simps) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3891 |
show "algebraic_int (of_real x :: 'a)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3892 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3893 |
have "poly (map_poly of_real p) (of_real x) = (of_real (poly p x) :: 'a)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3894 |
by (induction p) (auto simp: map_poly_pCons) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3895 |
thus "poly (map_poly of_real p) (of_real x) = (0 :: 'a)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3896 |
using p by simp |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3897 |
qed (use p in \<open>auto simp: coeff_map_poly degree_map_poly\<close>) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3898 |
qed |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3899 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3900 |
lemma algebraic_int_of_real_iff [simp]: |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3901 |
"algebraic_int (of_real x :: 'a :: {field_char_0, real_algebra_1}) \<longleftrightarrow> algebraic_int x"
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3902 |
proof |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3903 |
assume "algebraic_int (of_real x :: 'a)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3904 |
then obtain p |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3905 |
where p: "poly (map_poly of_int p) (of_real x :: 'a) = 0" "lead_coeff p = 1" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3906 |
by (auto simp: algebraic_int_altdef_ipoly) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3907 |
show "algebraic_int x" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3908 |
unfolding algebraic_int_altdef_ipoly |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3909 |
proof (intro exI[of _ p] conjI) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3910 |
have "of_real (poly (map_poly real_of_int p) x) = poly (map_poly of_int p) (of_real x :: 'a)" |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3911 |
by (induction p) (auto simp: map_poly_pCons) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3912 |
also note p(1) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3913 |
finally show "poly (map_poly real_of_int p) x = 0" by simp |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3914 |
qed (use p in auto) |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3915 |
qed auto |
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3916 |
|
|
783406dd051e
some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents:
72750
diff
changeset
|
3917 |
|
| 64795 | 3918 |
subsection \<open>Division of polynomials\<close> |
3919 |
||
3920 |
subsubsection \<open>Division in general\<close> |
|
| 65346 | 3921 |
|
| 64795 | 3922 |
instantiation poly :: (idom_divide) idom_divide |
3923 |
begin |
|
3924 |
||
| 65347 | 3925 |
fun divide_poly_main :: "'a \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a poly" |
3926 |
where |
|
3927 |
"divide_poly_main lc q r d dr (Suc n) = |
|
3928 |
(let cr = coeff r dr; a = cr div lc; mon = monom a n in |
|
| 67369 | 3929 |
if False \<or> a * lc = cr then \<comment> \<open>\<open>False \<or>\<close> is only because of problem in function-package\<close> |
| 65347 | 3930 |
divide_poly_main |
3931 |
lc |
|
3932 |
(q + mon) |
|
3933 |
(r - mon * d) |
|
3934 |
d (dr - 1) n else 0)" |
|
3935 |
| "divide_poly_main lc q r d dr 0 = q" |
|
3936 |
||
3937 |
definition divide_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
|
3938 |
where "divide_poly f g = |
|
3939 |
(if g = 0 then 0 |
|
3940 |
else |
|
3941 |
divide_poly_main (coeff g (degree g)) 0 f g (degree f) |
|
3942 |
(1 + length (coeffs f) - length (coeffs g)))" |
|
| 64795 | 3943 |
|
3944 |
lemma divide_poly_main: |
|
3945 |
assumes d: "d \<noteq> 0" "lc = coeff d (degree d)" |
|
| 65347 | 3946 |
and "degree (d * r) \<le> dr" "divide_poly_main lc q (d * r) d dr n = q'" |
3947 |
and "n = 1 + dr - degree d \<or> dr = 0 \<and> n = 0 \<and> d * r = 0" |
|
| 64795 | 3948 |
shows "q' = q + r" |
| 65347 | 3949 |
using assms(3-) |
| 64795 | 3950 |
proof (induct n arbitrary: q r dr) |
| 65347 | 3951 |
case (Suc n) |
| 64795 | 3952 |
let ?rr = "d * r" |
3953 |
let ?a = "coeff ?rr dr" |
|
3954 |
let ?qq = "?a div lc" |
|
3955 |
define b where [simp]: "b = monom ?qq n" |
|
3956 |
let ?rrr = "d * (r - b)" |
|
3957 |
let ?qqq = "q + b" |
|
3958 |
note res = Suc(3) |
|
| 65347 | 3959 |
from Suc(4) have dr: "dr = n + degree d" by auto |
3960 |
from d have lc: "lc \<noteq> 0" by auto |
|
| 64795 | 3961 |
have "coeff (b * d) dr = coeff b n * coeff d (degree d)" |
3962 |
proof (cases "?qq = 0") |
|
| 65347 | 3963 |
case True |
3964 |
then show ?thesis by simp |
|
3965 |
next |
|
| 64795 | 3966 |
case False |
| 65347 | 3967 |
then have n: "n = degree b" |
3968 |
by (simp add: degree_monom_eq) |
|
3969 |
show ?thesis |
|
3970 |
unfolding n dr by (simp add: coeff_mult_degree_sum) |
|
3971 |
qed |
|
3972 |
also have "\<dots> = lc * coeff b n" |
|
3973 |
by (simp add: d) |
|
| 64795 | 3974 |
finally have c2: "coeff (b * d) dr = lc * coeff b n" . |
| 65347 | 3975 |
have rrr: "?rrr = ?rr - b * d" |
3976 |
by (simp add: field_simps) |
|
| 64795 | 3977 |
have c1: "coeff (d * r) dr = lc * coeff r n" |
3978 |
proof (cases "degree r = n") |
|
3979 |
case True |
|
| 65347 | 3980 |
with Suc(2) show ?thesis |
3981 |
unfolding dr using coeff_mult_degree_sum[of d r] d by (auto simp: ac_simps) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
3982 |
next |
| 64795 | 3983 |
case False |
| 65347 | 3984 |
from dr Suc(2) have "degree r \<le> n" |
3985 |
by auto |
|
3986 |
(metis add.commute add_le_cancel_left d(1) degree_0 degree_mult_eq |
|
3987 |
diff_is_0_eq diff_zero le_cases) |
|
3988 |
with False have r_n: "degree r < n" |
|
3989 |
by auto |
|
3990 |
then have right: "lc * coeff r n = 0" |
|
3991 |
by (simp add: coeff_eq_0) |
|
3992 |
have "coeff (d * r) dr = coeff (d * r) (degree d + n)" |
|
3993 |
by (simp add: dr ac_simps) |
|
3994 |
also from r_n have "\<dots> = 0" |
|
| 65346 | 3995 |
by (metis False Suc.prems(1) add.commute add_left_imp_eq coeff_degree_mult coeff_eq_0 |
| 64795 | 3996 |
coeff_mult_degree_sum degree_mult_le dr le_eq_less_or_eq) |
| 65347 | 3997 |
finally show ?thesis |
3998 |
by (simp only: right) |
|
| 64795 | 3999 |
qed |
| 65346 | 4000 |
have c0: "coeff ?rrr dr = 0" |
| 65347 | 4001 |
and id: "lc * (coeff (d * r) dr div lc) = coeff (d * r) dr" |
4002 |
unfolding rrr coeff_diff c2 |
|
| 64795 | 4003 |
unfolding b_def coeff_monom coeff_smult c1 using lc by auto |
4004 |
from res[unfolded divide_poly_main.simps[of lc q] Let_def] id |
|
| 65346 | 4005 |
have res: "divide_poly_main lc ?qqq ?rrr d (dr - 1) n = q'" |
| 64795 | 4006 |
by (simp del: divide_poly_main.simps add: field_simps) |
| 65346 | 4007 |
note IH = Suc(1)[OF _ res] |
| 65347 | 4008 |
from Suc(4) have dr: "dr = n + degree d" by auto |
4009 |
from Suc(2) have deg_rr: "degree ?rr \<le> dr" by auto |
|
| 64795 | 4010 |
have deg_bd: "degree (b * d) \<le> dr" |
| 65347 | 4011 |
unfolding dr b_def by (rule order.trans[OF degree_mult_le]) (auto simp: degree_monom_le) |
4012 |
have "degree ?rrr \<le> dr" |
|
4013 |
unfolding rrr by (rule degree_diff_le[OF deg_rr deg_bd]) |
|
| 64795 | 4014 |
with c0 have deg_rrr: "degree ?rrr \<le> (dr - 1)" |
4015 |
by (rule coeff_0_degree_minus_1) |
|
| 65346 | 4016 |
have "n = 1 + (dr - 1) - degree d \<or> dr - 1 = 0 \<and> n = 0 \<and> ?rrr = 0" |
| 64795 | 4017 |
proof (cases dr) |
4018 |
case 0 |
|
| 65347 | 4019 |
with Suc(4) have 0: "dr = 0" "n = 0" "degree d = 0" |
4020 |
by auto |
|
4021 |
with deg_rrr have "degree ?rrr = 0" |
|
4022 |
by simp |
|
4023 |
from degree_eq_zeroE[OF this] obtain a where rrr: "?rrr = [:a:]" |
|
4024 |
by metis |
|
4025 |
show ?thesis |
|
4026 |
unfolding 0 using c0 unfolding rrr 0 by simp |
|
4027 |
next |
|
4028 |
case _: Suc |
|
4029 |
with Suc(4) show ?thesis by auto |
|
4030 |
qed |
|
4031 |
from IH[OF deg_rrr this] show ?case |
|
4032 |
by simp |
|
| 64795 | 4033 |
next |
| 65347 | 4034 |
case 0 |
| 65346 | 4035 |
show ?case |
| 64795 | 4036 |
proof (cases "r = 0") |
4037 |
case True |
|
| 65347 | 4038 |
with 0 show ?thesis by auto |
| 64795 | 4039 |
next |
4040 |
case False |
|
| 65347 | 4041 |
from d False have "degree (d * r) = degree d + degree r" |
4042 |
by (subst degree_mult_eq) auto |
|
4043 |
with 0 d show ?thesis by auto |
|
| 64795 | 4044 |
qed |
| 65346 | 4045 |
qed |
| 64795 | 4046 |
|
4047 |
lemma divide_poly_main_0: "divide_poly_main 0 0 r d dr n = 0" |
|
4048 |
proof (induct n arbitrary: r d dr) |
|
| 65347 | 4049 |
case 0 |
4050 |
then show ?case by simp |
|
4051 |
next |
|
4052 |
case Suc |
|
4053 |
show ?case |
|
4054 |
unfolding divide_poly_main.simps[of _ _ r] Let_def |
|
| 64795 | 4055 |
by (simp add: Suc del: divide_poly_main.simps) |
| 65347 | 4056 |
qed |
| 64795 | 4057 |
|
4058 |
lemma divide_poly: |
|
4059 |
assumes g: "g \<noteq> 0" |
|
| 65346 | 4060 |
shows "(f * g) div g = (f :: 'a poly)" |
4061 |
proof - |
|
| 65347 | 4062 |
have len: "length (coeffs f) = Suc (degree f)" if "f \<noteq> 0" for f :: "'a poly" |
4063 |
using that unfolding degree_eq_length_coeffs by auto |
|
4064 |
have "divide_poly_main (coeff g (degree g)) 0 (g * f) g (degree (g * f)) |
|
4065 |
(1 + length (coeffs (g * f)) - length (coeffs g)) = (f * g) div g" |
|
4066 |
by (simp add: divide_poly_def Let_def ac_simps) |
|
| 64795 | 4067 |
note main = divide_poly_main[OF g refl le_refl this] |
4068 |
have "(f * g) div g = 0 + f" |
|
4069 |
proof (rule main, goal_cases) |
|
4070 |
case 1 |
|
4071 |
show ?case |
|
4072 |
proof (cases "f = 0") |
|
4073 |
case True |
|
| 65347 | 4074 |
with g show ?thesis |
4075 |
by (auto simp: degree_eq_length_coeffs) |
|
| 64795 | 4076 |
next |
4077 |
case False |
|
4078 |
with g have fg: "g * f \<noteq> 0" by auto |
|
| 65347 | 4079 |
show ?thesis |
4080 |
unfolding len[OF fg] len[OF g] by auto |
|
| 64795 | 4081 |
qed |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4082 |
qed |
| 65346 | 4083 |
then show ?thesis by simp |
| 64795 | 4084 |
qed |
4085 |
||
| 65347 | 4086 |
lemma divide_poly_0: "f div 0 = 0" |
4087 |
for f :: "'a poly" |
|
| 64795 | 4088 |
by (simp add: divide_poly_def Let_def divide_poly_main_0) |
4089 |
||
4090 |
instance |
|
4091 |
by standard (auto simp: divide_poly divide_poly_0) |
|
4092 |
||
4093 |
end |
|
4094 |
||
4095 |
instance poly :: (idom_divide) algebraic_semidom .. |
|
4096 |
||
| 65346 | 4097 |
lemma div_const_poly_conv_map_poly: |
| 64795 | 4098 |
assumes "[:c:] dvd p" |
| 65347 | 4099 |
shows "p div [:c:] = map_poly (\<lambda>x. x div c) p" |
| 64795 | 4100 |
proof (cases "c = 0") |
| 65347 | 4101 |
case True |
4102 |
then show ?thesis |
|
4103 |
by (auto intro!: poly_eqI simp: coeff_map_poly) |
|
4104 |
next |
|
| 64795 | 4105 |
case False |
| 65347 | 4106 |
from assms obtain q where p: "p = [:c:] * q" by (rule dvdE) |
| 64795 | 4107 |
moreover {
|
| 65347 | 4108 |
have "smult c q = [:c:] * q" |
4109 |
by simp |
|
4110 |
also have "\<dots> div [:c:] = q" |
|
4111 |
by (rule nonzero_mult_div_cancel_left) (use False in auto) |
|
| 64795 | 4112 |
finally have "smult c q div [:c:] = q" . |
4113 |
} |
|
4114 |
ultimately show ?thesis by (intro poly_eqI) (auto simp: coeff_map_poly False) |
|
| 65347 | 4115 |
qed |
| 64795 | 4116 |
|
4117 |
lemma is_unit_monom_0: |
|
4118 |
fixes a :: "'a::field" |
|
4119 |
assumes "a \<noteq> 0" |
|
4120 |
shows "is_unit (monom a 0)" |
|
4121 |
proof |
|
4122 |
from assms show "1 = monom a 0 * monom (inverse a) 0" |
|
4123 |
by (simp add: mult_monom) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4124 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4125 |
|
| 65347 | 4126 |
lemma is_unit_triv: "a \<noteq> 0 \<Longrightarrow> is_unit [:a:]" |
4127 |
for a :: "'a::field" |
|
4128 |
by (simp add: is_unit_monom_0 monom_0 [symmetric]) |
|
| 64795 | 4129 |
|
4130 |
lemma is_unit_iff_degree: |
|
| 65347 | 4131 |
fixes p :: "'a::field poly" |
4132 |
assumes "p \<noteq> 0" |
|
4133 |
shows "is_unit p \<longleftrightarrow> degree p = 0" |
|
4134 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
| 64795 | 4135 |
proof |
| 65347 | 4136 |
assume ?rhs |
4137 |
then obtain a where "p = [:a:]" |
|
4138 |
by (rule degree_eq_zeroE) |
|
4139 |
with assms show ?lhs |
|
4140 |
by (simp add: is_unit_triv) |
|
| 64795 | 4141 |
next |
| 65347 | 4142 |
assume ?lhs |
| 64795 | 4143 |
then obtain q where "q \<noteq> 0" "p * q = 1" .. |
4144 |
then have "degree (p * q) = degree 1" |
|
4145 |
by simp |
|
4146 |
with \<open>p \<noteq> 0\<close> \<open>q \<noteq> 0\<close> have "degree p + degree q = 0" |
|
4147 |
by (simp add: degree_mult_eq) |
|
| 65347 | 4148 |
then show ?rhs by simp |
| 64795 | 4149 |
qed |
4150 |
||
| 65347 | 4151 |
lemma is_unit_pCons_iff: "is_unit (pCons a p) \<longleftrightarrow> p = 0 \<and> a \<noteq> 0" |
4152 |
for p :: "'a::field poly" |
|
4153 |
by (cases "p = 0") (auto simp: is_unit_triv is_unit_iff_degree) |
|
4154 |
||
| 72610 | 4155 |
lemma is_unit_monom_trivial: "is_unit p \<Longrightarrow> monom (coeff p (degree p)) 0 = p" |
| 65347 | 4156 |
for p :: "'a::field poly" |
4157 |
by (cases p) (simp_all add: monom_0 is_unit_pCons_iff) |
|
4158 |
||
4159 |
lemma is_unit_const_poly_iff: "[:c:] dvd 1 \<longleftrightarrow> c dvd 1" |
|
4160 |
for c :: "'a::{comm_semiring_1,semiring_no_zero_divisors}"
|
|
| 65486 | 4161 |
by (auto simp: one_pCons) |
| 64795 | 4162 |
|
4163 |
lemma is_unit_polyE: |
|
4164 |
fixes p :: "'a :: {comm_semiring_1,semiring_no_zero_divisors} poly"
|
|
| 65347 | 4165 |
assumes "p dvd 1" |
4166 |
obtains c where "p = [:c:]" "c dvd 1" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4167 |
proof - |
| 64795 | 4168 |
from assms obtain q where "1 = p * q" |
4169 |
by (rule dvdE) |
|
4170 |
then have "p \<noteq> 0" and "q \<noteq> 0" |
|
4171 |
by auto |
|
4172 |
from \<open>1 = p * q\<close> have "degree 1 = degree (p * q)" |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4173 |
by simp |
| 64795 | 4174 |
also from \<open>p \<noteq> 0\<close> and \<open>q \<noteq> 0\<close> have "\<dots> = degree p + degree q" |
4175 |
by (simp add: degree_mult_eq) |
|
4176 |
finally have "degree p = 0" by simp |
|
4177 |
with degree_eq_zeroE obtain c where c: "p = [:c:]" . |
|
| 65347 | 4178 |
with \<open>p dvd 1\<close> have "c dvd 1" |
| 64795 | 4179 |
by (simp add: is_unit_const_poly_iff) |
| 65347 | 4180 |
with c show thesis .. |
| 64795 | 4181 |
qed |
4182 |
||
4183 |
lemma is_unit_polyE': |
|
| 65347 | 4184 |
fixes p :: "'a::field poly" |
4185 |
assumes "is_unit p" |
|
| 64795 | 4186 |
obtains a where "p = monom a 0" and "a \<noteq> 0" |
4187 |
proof - |
|
| 65347 | 4188 |
obtain a q where "p = pCons a q" |
4189 |
by (cases p) |
|
| 64795 | 4190 |
with assms have "p = [:a:]" and "a \<noteq> 0" |
4191 |
by (simp_all add: is_unit_pCons_iff) |
|
4192 |
with that show thesis by (simp add: monom_0) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4193 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4194 |
|
| 65347 | 4195 |
lemma is_unit_poly_iff: "p dvd 1 \<longleftrightarrow> (\<exists>c. p = [:c:] \<and> c dvd 1)" |
4196 |
for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
|
|
| 64795 | 4197 |
by (auto elim: is_unit_polyE simp add: is_unit_const_poly_iff) |
4198 |
||
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4199 |
lemma root_imp_reducible_poly: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4200 |
fixes x :: "'a :: field" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4201 |
assumes "poly p x = 0" and "degree p > 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4202 |
shows "\<not>irreducible p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4203 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4204 |
from assms have "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4205 |
by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4206 |
define q where "q = [:-x, 1:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4207 |
have "q dvd p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4208 |
using assms by (simp add: poly_eq_0_iff_dvd q_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4209 |
then obtain r where p_eq: "p = q * r" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4210 |
by (elim dvdE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4211 |
have [simp]: "q \<noteq> 0" "r \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4212 |
using \<open>p \<noteq> 0\<close> by (auto simp: p_eq) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4213 |
have "degree p = Suc (degree r)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4214 |
unfolding p_eq by (subst degree_mult_eq) (auto simp: q_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4215 |
with assms(2) have "degree r > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4216 |
by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4217 |
hence "\<not>r dvd 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4218 |
by (auto simp: is_unit_poly_iff) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4219 |
moreover have "\<not>q dvd 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4220 |
by (auto simp: is_unit_poly_iff q_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4221 |
ultimately show ?thesis using p_eq |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4222 |
by (auto simp: irreducible_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4223 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4224 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4225 |
lemma reducible_polyI: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4226 |
fixes p :: "'a :: field poly" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4227 |
assumes "p = q * r" "degree q > 0" "degree r > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4228 |
shows "\<not>irreducible p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4229 |
using assms unfolding irreducible_def |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4230 |
by (metis (no_types, opaque_lifting) is_unitE is_unit_iff_degree not_gr0) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
4231 |
|
| 65346 | 4232 |
|
| 64795 | 4233 |
subsubsection \<open>Pseudo-Division\<close> |
4234 |
||
| 65347 | 4235 |
text \<open>This part is by René Thiemann and Akihisa Yamada.\<close> |
4236 |
||
4237 |
fun pseudo_divmod_main :: |
|
4238 |
"'a :: comm_ring_1 \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a poly \<times> 'a poly" |
|
4239 |
where |
|
4240 |
"pseudo_divmod_main lc q r d dr (Suc n) = |
|
4241 |
(let |
|
| 76194 | 4242 |
rr = smult lc r; |
| 65347 | 4243 |
qq = coeff r dr; |
4244 |
rrr = rr - monom qq n * d; |
|
4245 |
qqq = smult lc q + monom qq n |
|
4246 |
in pseudo_divmod_main lc qqq rrr d (dr - 1) n)" |
|
4247 |
| "pseudo_divmod_main lc q r d dr 0 = (q,r)" |
|
4248 |
||
4249 |
definition pseudo_divmod :: "'a :: comm_ring_1 poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<times> 'a poly" |
|
4250 |
where "pseudo_divmod p q \<equiv> |
|
4251 |
if q = 0 then (0, p) |
|
4252 |
else |
|
4253 |
pseudo_divmod_main (coeff q (degree q)) 0 p q (degree p) |
|
4254 |
(1 + length (coeffs p) - length (coeffs q))" |
|
4255 |
||
4256 |
lemma pseudo_divmod_main: |
|
4257 |
assumes d: "d \<noteq> 0" "lc = coeff d (degree d)" |
|
4258 |
and "degree r \<le> dr" "pseudo_divmod_main lc q r d dr n = (q',r')" |
|
4259 |
and "n = 1 + dr - degree d \<or> dr = 0 \<and> n = 0 \<and> r = 0" |
|
| 64795 | 4260 |
shows "(r' = 0 \<or> degree r' < degree d) \<and> smult (lc^n) (d * q + r) = d * q' + r'" |
| 65347 | 4261 |
using assms(3-) |
| 64795 | 4262 |
proof (induct n arbitrary: q r dr) |
| 65347 | 4263 |
case 0 |
4264 |
then show ?case by auto |
|
4265 |
next |
|
4266 |
case (Suc n) |
|
| 64795 | 4267 |
let ?rr = "smult lc r" |
4268 |
let ?qq = "coeff r dr" |
|
4269 |
define b where [simp]: "b = monom ?qq n" |
|
4270 |
let ?rrr = "?rr - b * d" |
|
4271 |
let ?qqq = "smult lc q + b" |
|
4272 |
note res = Suc(3) |
|
| 65346 | 4273 |
from res[unfolded pseudo_divmod_main.simps[of lc q] Let_def] |
4274 |
have res: "pseudo_divmod_main lc ?qqq ?rrr d (dr - 1) n = (q',r')" |
|
| 64795 | 4275 |
by (simp del: pseudo_divmod_main.simps) |
| 65347 | 4276 |
from Suc(4) have dr: "dr = n + degree d" by auto |
| 64795 | 4277 |
have "coeff (b * d) dr = coeff b n * coeff d (degree d)" |
4278 |
proof (cases "?qq = 0") |
|
| 65347 | 4279 |
case True |
4280 |
then show ?thesis by auto |
|
4281 |
next |
|
| 64795 | 4282 |
case False |
| 65347 | 4283 |
then have n: "n = degree b" |
4284 |
by (simp add: degree_monom_eq) |
|
4285 |
show ?thesis |
|
4286 |
unfolding n dr by (simp add: coeff_mult_degree_sum) |
|
4287 |
qed |
|
4288 |
also have "\<dots> = lc * coeff b n" by (simp add: d) |
|
| 64795 | 4289 |
finally have "coeff (b * d) dr = lc * coeff b n" . |
| 65347 | 4290 |
moreover have "coeff ?rr dr = lc * coeff r dr" |
4291 |
by simp |
|
4292 |
ultimately have c0: "coeff ?rrr dr = 0" |
|
4293 |
by auto |
|
4294 |
from Suc(4) have dr: "dr = n + degree d" by auto |
|
4295 |
have deg_rr: "degree ?rr \<le> dr" |
|
4296 |
using Suc(2) degree_smult_le dual_order.trans by blast |
|
| 64795 | 4297 |
have deg_bd: "degree (b * d) \<le> dr" |
| 65347 | 4298 |
unfolding dr by (rule order.trans[OF degree_mult_le]) (auto simp: degree_monom_le) |
| 64795 | 4299 |
have "degree ?rrr \<le> dr" |
4300 |
using degree_diff_le[OF deg_rr deg_bd] by auto |
|
| 65347 | 4301 |
with c0 have deg_rrr: "degree ?rrr \<le> (dr - 1)" |
4302 |
by (rule coeff_0_degree_minus_1) |
|
| 64795 | 4303 |
have "n = 1 + (dr - 1) - degree d \<or> dr - 1 = 0 \<and> n = 0 \<and> ?rrr = 0" |
4304 |
proof (cases dr) |
|
4305 |
case 0 |
|
4306 |
with Suc(4) have 0: "dr = 0" "n = 0" "degree d = 0" by auto |
|
4307 |
with deg_rrr have "degree ?rrr = 0" by simp |
|
| 65347 | 4308 |
then have "\<exists>a. ?rrr = [:a:]" |
4309 |
by (metis degree_pCons_eq_if old.nat.distinct(2) pCons_cases) |
|
4310 |
from this obtain a where rrr: "?rrr = [:a:]" |
|
4311 |
by auto |
|
4312 |
show ?thesis |
|
4313 |
unfolding 0 using c0 unfolding rrr 0 by simp |
|
4314 |
next |
|
4315 |
case _: Suc |
|
4316 |
with Suc(4) show ?thesis by auto |
|
4317 |
qed |
|
| 64795 | 4318 |
note IH = Suc(1)[OF deg_rrr res this] |
4319 |
show ?case |
|
4320 |
proof (intro conjI) |
|
| 65347 | 4321 |
from IH show "r' = 0 \<or> degree r' < degree d" |
4322 |
by blast |
|
| 64795 | 4323 |
show "smult (lc ^ Suc n) (d * q + r) = d * q' + r'" |
4324 |
unfolding IH[THEN conjunct2,symmetric] |
|
4325 |
by (simp add: field_simps smult_add_right) |
|
4326 |
qed |
|
| 65347 | 4327 |
qed |
| 64795 | 4328 |
|
4329 |
lemma pseudo_divmod: |
|
| 65347 | 4330 |
assumes g: "g \<noteq> 0" |
4331 |
and *: "pseudo_divmod f g = (q,r)" |
|
4332 |
shows "smult (coeff g (degree g) ^ (Suc (degree f) - degree g)) f = g * q + r" (is ?A) |
|
4333 |
and "r = 0 \<or> degree r < degree g" (is ?B) |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4334 |
proof - |
| 64795 | 4335 |
from *[unfolded pseudo_divmod_def Let_def] |
| 65347 | 4336 |
have "pseudo_divmod_main (coeff g (degree g)) 0 f g (degree f) |
4337 |
(1 + length (coeffs f) - length (coeffs g)) = (q, r)" |
|
4338 |
by (auto simp: g) |
|
| 64795 | 4339 |
note main = pseudo_divmod_main[OF _ _ _ this, OF g refl le_refl] |
| 65347 | 4340 |
from g have "1 + length (coeffs f) - length (coeffs g) = 1 + degree f - degree g \<or> |
4341 |
degree f = 0 \<and> 1 + length (coeffs f) - length (coeffs g) = 0 \<and> f = 0" |
|
4342 |
by (cases "f = 0"; cases "coeffs g") (auto simp: degree_eq_length_coeffs) |
|
4343 |
note main' = main[OF this] |
|
4344 |
then show "r = 0 \<or> degree r < degree g" by auto |
|
| 65346 | 4345 |
show "smult (coeff g (degree g) ^ (Suc (degree f) - degree g)) f = g * q + r" |
| 65347 | 4346 |
by (subst main'[THEN conjunct2, symmetric], simp add: degree_eq_length_coeffs, |
4347 |
cases "f = 0"; cases "coeffs g", use g in auto) |
|
| 64795 | 4348 |
qed |
| 65346 | 4349 |
|
| 64795 | 4350 |
definition "pseudo_mod_main lc r d dr n = snd (pseudo_divmod_main lc 0 r d dr n)" |
4351 |
||
4352 |
lemma snd_pseudo_divmod_main: |
|
4353 |
"snd (pseudo_divmod_main lc q r d dr n) = snd (pseudo_divmod_main lc q' r d dr n)" |
|
| 65347 | 4354 |
by (induct n arbitrary: q q' lc r d dr) (simp_all add: Let_def) |
4355 |
||
4356 |
definition pseudo_mod :: "'a::{comm_ring_1,semiring_1_no_zero_divisors} poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
|
|
4357 |
where "pseudo_mod f g = snd (pseudo_divmod f g)" |
|
| 65346 | 4358 |
|
| 64795 | 4359 |
lemma pseudo_mod: |
| 65347 | 4360 |
fixes f g :: "'a::{comm_ring_1,semiring_1_no_zero_divisors} poly"
|
| 64795 | 4361 |
defines "r \<equiv> pseudo_mod f g" |
4362 |
assumes g: "g \<noteq> 0" |
|
| 65347 | 4363 |
shows "\<exists>a q. a \<noteq> 0 \<and> smult a f = g * q + r" "r = 0 \<or> degree r < degree g" |
| 65346 | 4364 |
proof - |
| 64795 | 4365 |
let ?cg = "coeff g (degree g)" |
4366 |
let ?cge = "?cg ^ (Suc (degree f) - degree g)" |
|
4367 |
define a where "a = ?cge" |
|
| 65347 | 4368 |
from r_def[unfolded pseudo_mod_def] obtain q where pdm: "pseudo_divmod f g = (q, r)" |
4369 |
by (cases "pseudo_divmod f g") auto |
|
| 65346 | 4370 |
from pseudo_divmod[OF g pdm] have id: "smult a f = g * q + r" and "r = 0 \<or> degree r < degree g" |
| 65347 | 4371 |
by (auto simp: a_def) |
| 64795 | 4372 |
show "r = 0 \<or> degree r < degree g" by fact |
| 65347 | 4373 |
from g have "a \<noteq> 0" |
4374 |
by (auto simp: a_def) |
|
4375 |
with id show "\<exists>a q. a \<noteq> 0 \<and> smult a f = g * q + r" |
|
4376 |
by auto |
|
| 64795 | 4377 |
qed |
| 65346 | 4378 |
|
| 64795 | 4379 |
lemma fst_pseudo_divmod_main_as_divide_poly_main: |
4380 |
assumes d: "d \<noteq> 0" |
|
4381 |
defines lc: "lc \<equiv> coeff d (degree d)" |
|
| 65347 | 4382 |
shows "fst (pseudo_divmod_main lc q r d dr n) = |
4383 |
divide_poly_main lc (smult (lc^n) q) (smult (lc^n) r) d dr n" |
|
4384 |
proof (induct n arbitrary: q r dr) |
|
4385 |
case 0 |
|
4386 |
then show ?case by simp |
|
| 64795 | 4387 |
next |
4388 |
case (Suc n) |
|
| 65347 | 4389 |
note lc0 = leading_coeff_neq_0[OF d, folded lc] |
4390 |
then have "pseudo_divmod_main lc q r d dr (Suc n) = |
|
| 64795 | 4391 |
pseudo_divmod_main lc (smult lc q + monom (coeff r dr) n) |
4392 |
(smult lc r - monom (coeff r dr) n * d) d (dr - 1) n" |
|
4393 |
by (simp add: Let_def ac_simps) |
|
| 65347 | 4394 |
also have "fst \<dots> = divide_poly_main lc |
| 64795 | 4395 |
(smult (lc^n) (smult lc q + monom (coeff r dr) n)) |
4396 |
(smult (lc^n) (smult lc r - monom (coeff r dr) n * d)) |
|
4397 |
d (dr - 1) n" |
|
| 65347 | 4398 |
by (simp only: Suc[unfolded divide_poly_main.simps Let_def]) |
4399 |
also have "\<dots> = divide_poly_main lc (smult (lc ^ Suc n) q) (smult (lc ^ Suc n) r) d dr (Suc n)" |
|
4400 |
unfolding smult_monom smult_distribs mult_smult_left[symmetric] |
|
4401 |
using lc0 by (simp add: Let_def ac_simps) |
|
4402 |
finally show ?case . |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4403 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4404 |
|
| 64795 | 4405 |
|
4406 |
subsubsection \<open>Division in polynomials over fields\<close> |
|
4407 |
||
4408 |
lemma pseudo_divmod_field: |
|
| 65347 | 4409 |
fixes g :: "'a::field poly" |
4410 |
assumes g: "g \<noteq> 0" |
|
4411 |
and *: "pseudo_divmod f g = (q,r)" |
|
| 64795 | 4412 |
defines "c \<equiv> coeff g (degree g) ^ (Suc (degree f) - degree g)" |
4413 |
shows "f = g * smult (1/c) q + smult (1/c) r" |
|
4414 |
proof - |
|
| 65347 | 4415 |
from leading_coeff_neq_0[OF g] have c0: "c \<noteq> 0" |
4416 |
by (auto simp: c_def) |
|
4417 |
from pseudo_divmod(1)[OF g *, folded c_def] have "smult c f = g * q + r" |
|
4418 |
by auto |
|
4419 |
also have "smult (1 / c) \<dots> = g * smult (1 / c) q + smult (1 / c) r" |
|
4420 |
by (simp add: smult_add_right) |
|
4421 |
finally show ?thesis |
|
4422 |
using c0 by auto |
|
| 64795 | 4423 |
qed |
4424 |
||
4425 |
lemma divide_poly_main_field: |
|
| 65347 | 4426 |
fixes d :: "'a::field poly" |
4427 |
assumes d: "d \<noteq> 0" |
|
| 64795 | 4428 |
defines lc: "lc \<equiv> coeff d (degree d)" |
| 65347 | 4429 |
shows "divide_poly_main lc q r d dr n = |
4430 |
fst (pseudo_divmod_main lc (smult ((1 / lc)^n) q) (smult ((1 / lc)^n) r) d dr n)" |
|
4431 |
unfolding lc by (subst fst_pseudo_divmod_main_as_divide_poly_main) (auto simp: d power_one_over) |
|
| 64795 | 4432 |
|
4433 |
lemma divide_poly_field: |
|
| 65347 | 4434 |
fixes f g :: "'a::field poly" |
| 64795 | 4435 |
defines "f' \<equiv> smult ((1 / coeff g (degree g)) ^ (Suc (degree f) - degree g)) f" |
| 65347 | 4436 |
shows "f div g = fst (pseudo_divmod f' g)" |
| 64795 | 4437 |
proof (cases "g = 0") |
| 65347 | 4438 |
case True |
4439 |
show ?thesis |
|
4440 |
unfolding divide_poly_def pseudo_divmod_def Let_def f'_def True |
|
4441 |
by (simp add: divide_poly_main_0) |
|
| 64795 | 4442 |
next |
4443 |
case False |
|
| 65347 | 4444 |
from leading_coeff_neq_0[OF False] have "degree f' = degree f" |
4445 |
by (auto simp: f'_def) |
|
4446 |
then show ?thesis |
|
4447 |
using length_coeffs_degree[of f'] length_coeffs_degree[of f] |
|
4448 |
unfolding divide_poly_def pseudo_divmod_def Let_def |
|
4449 |
divide_poly_main_field[OF False] |
|
4450 |
length_coeffs_degree[OF False] |
|
4451 |
f'_def |
|
4452 |
by force |
|
| 64795 | 4453 |
qed |
4454 |
||
| 65347 | 4455 |
instantiation poly :: ("{semidom_divide_unit_factor,idom_divide}") normalization_semidom
|
| 64795 | 4456 |
begin |
4457 |
||
4458 |
definition unit_factor_poly :: "'a poly \<Rightarrow> 'a poly" |
|
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4459 |
where "unit_factor_poly p = [:unit_factor (lead_coeff p):]" |
| 64795 | 4460 |
|
4461 |
definition normalize_poly :: "'a poly \<Rightarrow> 'a poly" |
|
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4462 |
where "normalize p = p div [:unit_factor (lead_coeff p):]" |
| 64795 | 4463 |
|
| 65347 | 4464 |
instance |
4465 |
proof |
|
| 64795 | 4466 |
fix p :: "'a poly" |
4467 |
show "unit_factor p * normalize p = p" |
|
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4468 |
proof (cases "p = 0") |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4469 |
case True |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4470 |
then show ?thesis |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4471 |
by (simp add: unit_factor_poly_def normalize_poly_def) |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4472 |
next |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4473 |
case False |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4474 |
then have "lead_coeff p \<noteq> 0" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4475 |
by simp |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4476 |
then have *: "unit_factor (lead_coeff p) \<noteq> 0" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4477 |
using unit_factor_is_unit [of "lead_coeff p"] by auto |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4478 |
then have "unit_factor (lead_coeff p) dvd 1" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4479 |
by (auto intro: unit_factor_is_unit) |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4480 |
then have **: "unit_factor (lead_coeff p) dvd c" for c |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4481 |
by (rule dvd_trans) simp |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4482 |
have ***: "unit_factor (lead_coeff p) * (c div unit_factor (lead_coeff p)) = c" for c |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4483 |
proof - |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4484 |
from ** obtain b where "c = unit_factor (lead_coeff p) * b" .. |
| 65347 | 4485 |
with False * show ?thesis by simp |
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4486 |
qed |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4487 |
have "p div [:unit_factor (lead_coeff p):] = |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4488 |
map_poly (\<lambda>c. c div unit_factor (lead_coeff p)) p" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4489 |
by (simp add: const_poly_dvd_iff div_const_poly_conv_map_poly **) |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4490 |
then show ?thesis |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4491 |
by (simp add: normalize_poly_def unit_factor_poly_def |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4492 |
smult_conv_map_poly map_poly_map_poly o_def ***) |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4493 |
qed |
| 64795 | 4494 |
next |
4495 |
fix p :: "'a poly" |
|
4496 |
assume "is_unit p" |
|
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4497 |
then obtain c where p: "p = [:c:]" "c dvd 1" |
| 64795 | 4498 |
by (auto simp: is_unit_poly_iff) |
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4499 |
then show "unit_factor p = p" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4500 |
by (simp add: unit_factor_poly_def monom_0 is_unit_unit_factor) |
| 64795 | 4501 |
next |
| 65347 | 4502 |
fix p :: "'a poly" |
4503 |
assume "p \<noteq> 0" |
|
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4504 |
then show "is_unit (unit_factor p)" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4505 |
by (simp add: unit_factor_poly_def monom_0 is_unit_poly_iff unit_factor_is_unit) |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4506 |
next |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
4507 |
fix a b :: "'a poly" assume "is_unit a" |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4508 |
thus "unit_factor (a * b) = a * unit_factor b" |
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4509 |
by (auto simp: unit_factor_poly_def lead_coeff_mult unit_factor_mult elim!: is_unit_polyE) |
| 64795 | 4510 |
qed (simp_all add: normalize_poly_def unit_factor_poly_def monom_0 lead_coeff_mult unit_factor_mult) |
4511 |
||
4512 |
end |
|
4513 |
||
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
4514 |
instance poly :: ("{semidom_divide_unit_factor,idom_divide,normalization_semidom_multiplicative}")
|
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4515 |
normalization_semidom_multiplicative |
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4516 |
by intro_classes (auto simp: unit_factor_poly_def lead_coeff_mult unit_factor_mult) |
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4517 |
|
| 65347 | 4518 |
lemma normalize_poly_eq_map_poly: "normalize p = map_poly (\<lambda>x. x div unit_factor (lead_coeff p)) p" |
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4519 |
proof - |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4520 |
have "[:unit_factor (lead_coeff p):] dvd p" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4521 |
by (metis unit_factor_poly_def unit_factor_self) |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4522 |
then show ?thesis |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4523 |
by (simp add: normalize_poly_def div_const_poly_conv_map_poly) |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4524 |
qed |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4525 |
|
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4526 |
lemma coeff_normalize [simp]: |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4527 |
"coeff (normalize p) n = coeff p n div unit_factor (lead_coeff p)" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4528 |
by (simp add: normalize_poly_eq_map_poly coeff_map_poly) |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4529 |
|
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4530 |
class field_unit_factor = field + unit_factor + |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4531 |
assumes unit_factor_field [simp]: "unit_factor = id" |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4532 |
begin |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4533 |
|
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4534 |
subclass semidom_divide_unit_factor |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4535 |
proof |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4536 |
fix a |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4537 |
assume "a \<noteq> 0" |
| 65347 | 4538 |
then have "1 = a * inverse a" by simp |
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4539 |
then have "a dvd 1" .. |
| 65347 | 4540 |
then show "unit_factor a dvd 1" by simp |
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4541 |
qed simp_all |
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4542 |
|
|
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4543 |
end |
| 64795 | 4544 |
|
4545 |
lemma unit_factor_pCons: |
|
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4546 |
"unit_factor (pCons a p) = (if p = 0 then [:unit_factor a:] else unit_factor p)" |
| 64795 | 4547 |
by (simp add: unit_factor_poly_def) |
4548 |
||
| 65347 | 4549 |
lemma normalize_monom [simp]: "normalize (monom a n) = monom (normalize a) n" |
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4550 |
by (cases "a = 0") (simp_all add: map_poly_monom normalize_poly_eq_map_poly degree_monom_eq) |
| 64795 | 4551 |
|
| 65347 | 4552 |
lemma unit_factor_monom [simp]: "unit_factor (monom a n) = [:unit_factor a:]" |
| 64795 | 4553 |
by (cases "a = 0") (simp_all add: unit_factor_poly_def degree_monom_eq) |
4554 |
||
4555 |
lemma normalize_const_poly: "normalize [:c:] = [:normalize c:]" |
|
|
64848
c50db2128048
slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents:
64811
diff
changeset
|
4556 |
by (simp add: normalize_poly_eq_map_poly map_poly_pCons) |
| 64795 | 4557 |
|
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4558 |
lemma normalize_smult: |
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4559 |
fixes c :: "'a :: {normalization_semidom_multiplicative, idom_divide}"
|
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
4560 |
shows "normalize (smult c p) = smult (normalize c) (normalize p)" |
| 64795 | 4561 |
proof - |
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4562 |
have "smult c p = [:c:] * p" by simp |
| 64795 | 4563 |
also have "normalize \<dots> = smult (normalize c) (normalize p)" |
4564 |
by (subst normalize_mult) (simp add: normalize_const_poly) |
|
4565 |
finally show ?thesis . |
|
|
62352
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4566 |
qed |
|
35a9e1cbb5b3
separated potentially conflicting type class instance into separate theory
haftmann
parents:
62351
diff
changeset
|
4567 |
|
| 76194 | 4568 |
instantiation poly :: (field) idom_modulo |
4569 |
begin |
|
4570 |
||
4571 |
definition modulo_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
|
4572 |
where mod_poly_def: "f mod g = |
|
4573 |
(if g = 0 then f else pseudo_mod (smult ((1 / lead_coeff g) ^ (Suc (degree f) - degree g)) f) g)" |
|
4574 |
||
4575 |
instance |
|
4576 |
proof |
|
4577 |
fix x y :: "'a poly" |
|
4578 |
show "x div y * y + x mod y = x" |
|
4579 |
proof (cases "y = 0") |
|
4580 |
case True |
|
4581 |
then show ?thesis |
|
4582 |
by (simp add: divide_poly_0 mod_poly_def) |
|
4583 |
next |
|
4584 |
case False |
|
4585 |
then have "pseudo_divmod (smult ((1 / lead_coeff y) ^ (Suc (degree x) - degree y)) x) y = |
|
4586 |
(x div y, x mod y)" |
|
4587 |
by (simp add: divide_poly_field mod_poly_def pseudo_mod_def) |
|
4588 |
with False pseudo_divmod [OF False this] show ?thesis |
|
4589 |
by (simp add: power_mult_distrib [symmetric] ac_simps) |
|
4590 |
qed |
|
4591 |
qed |
|
4592 |
||
4593 |
end |
|
4594 |
||
4595 |
lemma pseudo_divmod_eq_div_mod: |
|
4596 |
\<open>pseudo_divmod f g = (f div g, f mod g)\<close> if \<open>lead_coeff g = 1\<close> |
|
4597 |
using that by (auto simp add: divide_poly_field mod_poly_def pseudo_mod_def) |
|
4598 |
||
4599 |
lemma degree_mod_less_degree: |
|
4600 |
\<open>degree (x mod y) < degree y\<close> if \<open>y \<noteq> 0\<close> \<open>\<not> y dvd x\<close> |
|
4601 |
proof - |
|
4602 |
from pseudo_mod(2) [of y] \<open>y \<noteq> 0\<close> |
|
4603 |
have *: \<open>pseudo_mod f y \<noteq> 0 \<Longrightarrow> degree (pseudo_mod f y) < degree y\<close> for f |
|
4604 |
by blast |
|
4605 |
from \<open>\<not> y dvd x\<close> have \<open>x mod y \<noteq> 0\<close> |
|
4606 |
by blast |
|
4607 |
with \<open>y \<noteq> 0\<close> show ?thesis |
|
4608 |
by (auto simp add: mod_poly_def intro: *) |
|
4609 |
qed |
|
4610 |
||
4611 |
instantiation poly :: (field) unique_euclidean_ring |
|
4612 |
begin |
|
4613 |
||
4614 |
definition euclidean_size_poly :: "'a poly \<Rightarrow> nat" |
|
4615 |
where "euclidean_size_poly p = (if p = 0 then 0 else 2 ^ degree p)" |
|
4616 |
||
4617 |
definition division_segment_poly :: "'a poly \<Rightarrow> 'a poly" |
|
4618 |
where [simp]: "division_segment_poly p = 1" |
|
4619 |
||
4620 |
instance proof |
|
4621 |
show \<open>(q * p + r) div p = q\<close> if \<open>p \<noteq> 0\<close> |
|
4622 |
and \<open>euclidean_size r < euclidean_size p\<close> for q p r :: \<open>'a poly\<close> |
|
4623 |
proof (cases \<open>r = 0\<close>) |
|
4624 |
case True |
|
4625 |
with that show ?thesis |
|
4626 |
by simp |
|
4627 |
next |
|
4628 |
case False |
|
4629 |
with \<open>p \<noteq> 0\<close> \<open>euclidean_size r < euclidean_size p\<close> |
|
4630 |
have \<open>degree r < degree p\<close> |
|
4631 |
by (simp add: euclidean_size_poly_def) |
|
| 76208 | 4632 |
with \<open>r \<noteq> 0\<close> have \<open>\<not> p dvd r\<close> |
4633 |
by (auto dest: dvd_imp_degree) |
|
4634 |
have \<open>(q * p + r) div p = q \<and> (q * p + r) mod p = r\<close> |
|
4635 |
proof (rule ccontr) |
|
4636 |
assume \<open>\<not> ?thesis\<close> |
|
4637 |
moreover have *: \<open>((q * p + r) div p - q) * p = r - (q * p + r) mod p\<close> |
|
4638 |
by (simp add: algebra_simps) |
|
4639 |
ultimately have \<open>(q * p + r) div p \<noteq> q\<close> and \<open>(q * p + r) mod p \<noteq> r\<close> |
|
4640 |
using \<open>p \<noteq> 0\<close> by auto |
|
4641 |
from \<open>\<not> p dvd r\<close> have \<open>\<not> p dvd (q * p + r)\<close> |
|
4642 |
by simp |
|
4643 |
with \<open>p \<noteq> 0\<close> have \<open>degree ((q * p + r) mod p) < degree p\<close> |
|
4644 |
by (rule degree_mod_less_degree) |
|
4645 |
with \<open>degree r < degree p\<close> \<open>(q * p + r) mod p \<noteq> r\<close> |
|
4646 |
have \<open>degree (r - (q * p + r) mod p) < degree p\<close> |
|
4647 |
by (auto intro: degree_diff_less) |
|
4648 |
also have \<open>degree p \<le> degree ((q * p + r) div p - q) + degree p\<close> |
|
4649 |
by simp |
|
4650 |
also from \<open>(q * p + r) div p \<noteq> q\<close> \<open>p \<noteq> 0\<close> |
|
4651 |
have \<open>\<dots> = degree (((q * p + r) div p - q) * p)\<close> |
|
4652 |
by (simp add: degree_mult_eq) |
|
4653 |
also from * have \<open>\<dots> = degree (r - (q * p + r) mod p)\<close> |
|
4654 |
by simp |
|
4655 |
finally have \<open>degree (r - (q * p + r) mod p) < degree (r - (q * p + r) mod p)\<close> . |
|
4656 |
then show False |
|
4657 |
by simp |
|
4658 |
qed |
|
4659 |
then show \<open>(q * p + r) div p = q\<close> .. |
|
| 76194 | 4660 |
qed |
| 76208 | 4661 |
qed (auto simp: euclidean_size_poly_def degree_mult_eq power_add intro: degree_mod_less_degree) |
| 76194 | 4662 |
|
4663 |
end |
|
4664 |
||
4665 |
lemma euclidean_relation_polyI [case_names by0 divides euclidean_relation]: |
|
4666 |
\<open>(x div y, x mod y) = (q, r)\<close> |
|
4667 |
if by0: \<open>y = 0 \<Longrightarrow> q = 0 \<and> r = x\<close> |
|
4668 |
and divides: \<open>y \<noteq> 0 \<Longrightarrow> y dvd x \<Longrightarrow> r = 0 \<and> x = q * y\<close> |
|
4669 |
and euclidean_relation: \<open>y \<noteq> 0 \<Longrightarrow> \<not> y dvd x \<Longrightarrow> degree r < degree y \<and> x = q * y + r\<close> |
|
4670 |
by (rule euclidean_relationI) |
|
4671 |
(use that in \<open>simp_all add: euclidean_size_poly_def\<close>) |
|
4672 |
||
| 76207 | 4673 |
lemma div_poly_eq_0_iff: |
4674 |
\<open>x div y = 0 \<longleftrightarrow> x = 0 \<or> y = 0 \<or> degree x < degree y\<close> for x y :: \<open>'a::field poly\<close> |
|
4675 |
by (simp add: unique_euclidean_semiring_class.div_eq_0_iff euclidean_size_poly_def) |
|
4676 |
||
| 76208 | 4677 |
lemma div_poly_less: |
4678 |
\<open>x div y = 0\<close> if \<open>degree x < degree y\<close> for x y :: \<open>'a::field poly\<close> |
|
4679 |
using that by (simp add: div_poly_eq_0_iff) |
|
4680 |
||
4681 |
lemma mod_poly_less: |
|
4682 |
\<open>x mod y = x\<close> if \<open>degree x < degree y\<close> |
|
4683 |
using that by (simp add: mod_eq_self_iff_div_eq_0 div_poly_eq_0_iff) |
|
4684 |
||
| 76194 | 4685 |
lemma degree_div_less: |
| 76208 | 4686 |
\<open>degree (x div y) < degree x\<close> |
4687 |
if \<open>degree x > 0\<close> \<open>degree y > 0\<close> |
|
4688 |
for x y :: \<open>'a::field poly\<close> |
|
4689 |
proof (cases \<open>x div y = 0\<close>) |
|
4690 |
case True |
|
4691 |
with \<open>degree x > 0\<close> show ?thesis |
|
4692 |
by simp |
|
4693 |
next |
|
4694 |
case False |
|
4695 |
from that have \<open>x \<noteq> 0\<close> \<open>y \<noteq> 0\<close> |
|
4696 |
and *: \<open>degree (x div y * y + x mod y) > 0\<close> |
|
4697 |
by auto |
|
4698 |
show ?thesis |
|
4699 |
proof (cases \<open>y dvd x\<close>) |
|
| 76194 | 4700 |
case True |
| 76208 | 4701 |
then obtain z where \<open>x = y * z\<close> .. |
4702 |
then have \<open>degree (x div y) < degree (x div y * y)\<close> |
|
4703 |
using \<open>y \<noteq> 0\<close> \<open>x \<noteq> 0\<close> \<open>degree y > 0\<close> by (simp add: degree_mult_eq) |
|
4704 |
with \<open>y dvd x\<close> show ?thesis |
|
4705 |
by simp |
|
| 76194 | 4706 |
next |
4707 |
case False |
|
| 76208 | 4708 |
with \<open>y \<noteq> 0\<close> have \<open>degree (x mod y) < degree y\<close> |
4709 |
by (rule degree_mod_less_degree) |
|
4710 |
with \<open>y \<noteq> 0\<close> \<open>x div y \<noteq> 0\<close> have \<open>degree (x mod y) < degree (x div y * y)\<close> |
|
4711 |
by (simp add: degree_mult_eq) |
|
4712 |
then have \<open>degree (x div y * y + x mod y) = degree (x div y * y)\<close> |
|
4713 |
by (rule degree_add_eq_left) |
|
4714 |
with \<open>y \<noteq> 0\<close> \<open>x div y \<noteq> 0\<close> \<open>degree y > 0\<close> show ?thesis |
|
4715 |
by (simp add: degree_mult_eq) |
|
| 76194 | 4716 |
qed |
| 76208 | 4717 |
qed |
| 76194 | 4718 |
|
4719 |
lemma degree_mod_less': "b \<noteq> 0 \<Longrightarrow> a mod b \<noteq> 0 \<Longrightarrow> degree (a mod b) < degree b" |
|
| 76208 | 4720 |
by (rule degree_mod_less_degree) auto |
4721 |
||
4722 |
lemma degree_mod_less: "y \<noteq> 0 \<Longrightarrow> x mod y = 0 \<or> degree (x mod y) < degree y" |
|
4723 |
using degree_mod_less' by blast |
|
| 64795 | 4724 |
|
| 76207 | 4725 |
lemma div_smult_left: \<open>smult a x div y = smult a (x div y)\<close> (is ?Q) |
4726 |
and mod_smult_left: \<open>smult a x mod y = smult a (x mod y)\<close> (is ?R) |
|
4727 |
for x y :: \<open>'a::field poly\<close> |
|
4728 |
proof - |
|
4729 |
have \<open>(smult a x div y, smult a x mod y) = (smult a (x div y), smult a (x mod y))\<close> |
|
4730 |
proof (cases \<open>a = 0\<close>) |
|
4731 |
case True |
|
4732 |
then show ?thesis |
|
4733 |
by simp |
|
4734 |
next |
|
4735 |
case False |
|
| 76245 | 4736 |
show ?thesis |
4737 |
by (rule euclidean_relation_polyI) |
|
4738 |
(use False in \<open>simp_all add: dvd_smult_iff degree_mod_less_degree flip: smult_add_right\<close>) |
|
| 76207 | 4739 |
qed |
4740 |
then show ?Q and ?R |
|
4741 |
by simp_all |
|
4742 |
qed |
|
4743 |
||
4744 |
lemma poly_div_minus_left [simp]: "(- x) div y = - (x div y)" |
|
4745 |
for x y :: "'a::field poly" |
|
4746 |
using div_smult_left [of "- 1::'a"] by simp |
|
4747 |
||
4748 |
lemma poly_mod_minus_left [simp]: "(- x) mod y = - (x mod y)" |
|
4749 |
for x y :: "'a::field poly" |
|
4750 |
using mod_smult_left [of "- 1::'a"] by simp |
|
4751 |
||
4752 |
lemma poly_div_add_left: \<open>(x + y) div z = x div z + y div z\<close> (is ?Q) |
|
4753 |
and poly_mod_add_left: \<open>(x + y) mod z = x mod z + y mod z\<close> (is ?R) |
|
4754 |
for x y z :: \<open>'a::field poly\<close> |
|
4755 |
proof - |
|
4756 |
have \<open>((x + y) div z, (x + y) mod z) = (x div z + y div z, x mod z + y mod z)\<close> |
|
| 76245 | 4757 |
proof (induction rule: euclidean_relation_polyI) |
| 76207 | 4758 |
case by0 |
4759 |
then show ?case by simp |
|
| 72750 | 4760 |
next |
| 76207 | 4761 |
case divides |
4762 |
then obtain w where \<open>x + y = z * w\<close> |
|
4763 |
by blast |
|
4764 |
then have y: \<open>y = z * w - x\<close> |
|
4765 |
by (simp add: algebra_simps) |
|
4766 |
from \<open>z \<noteq> 0\<close> show ?case |
|
4767 |
using mod_mult_self4 [of z w \<open>- x\<close>] div_mult_self4 [of z w \<open>- x\<close>] |
|
4768 |
by (simp add: algebra_simps y) |
|
4769 |
next |
|
4770 |
case euclidean_relation |
|
4771 |
then have \<open>degree (x mod z + y mod z) < degree z\<close> |
|
4772 |
using degree_mod_less_degree [of z x] degree_mod_less_degree [of z y] |
|
4773 |
dvd_add_right_iff [of z x y] dvd_add_left_iff [of z y x] |
|
4774 |
by (cases \<open>z dvd x \<or> z dvd y\<close>) (auto intro: degree_add_less) |
|
4775 |
moreover have \<open>x + y = (x div z + y div z) * z + (x mod z + y mod z)\<close> |
|
4776 |
by (simp add: algebra_simps) |
|
4777 |
ultimately show ?case |
|
4778 |
by simp |
|
4779 |
qed |
|
4780 |
then show ?Q and ?R |
|
4781 |
by simp_all |
|
4782 |
qed |
|
4783 |
||
4784 |
lemma poly_div_diff_left: "(x - y) div z = x div z - y div z" |
|
4785 |
for x y z :: "'a::field poly" |
|
4786 |
by (simp only: diff_conv_add_uminus poly_div_add_left poly_div_minus_left) |
|
4787 |
||
4788 |
lemma poly_mod_diff_left: "(x - y) mod z = x mod z - y mod z" |
|
4789 |
for x y z :: "'a::field poly" |
|
4790 |
by (simp only: diff_conv_add_uminus poly_mod_add_left poly_mod_minus_left) |
|
4791 |
||
4792 |
lemma div_smult_right: \<open>x div smult a y = smult (inverse a) (x div y)\<close> (is ?Q) |
|
4793 |
and mod_smult_right: \<open>x mod smult a y = (if a = 0 then x else x mod y)\<close> (is ?R) |
|
4794 |
proof - |
|
4795 |
have \<open>(x div smult a y, x mod smult a y) = (smult (inverse a) (x div y), (if a = 0 then x else x mod y))\<close> |
|
| 76245 | 4796 |
proof (induction rule: euclidean_relation_polyI) |
| 76207 | 4797 |
case by0 |
4798 |
then show ?case by auto |
|
4799 |
next |
|
4800 |
case divides |
|
4801 |
moreover define w where \<open>w = x div y\<close> |
|
4802 |
ultimately have \<open>x = y * w\<close> |
|
4803 |
by (simp add: smult_dvd_iff) |
|
4804 |
with divides show ?case |
|
4805 |
by simp |
|
4806 |
next |
|
4807 |
case euclidean_relation |
|
| 72750 | 4808 |
then show ?case |
| 76207 | 4809 |
by (simp add: smult_dvd_iff degree_mod_less_degree) |
| 72750 | 4810 |
qed |
| 76207 | 4811 |
then show ?Q and ?R |
4812 |
by simp_all |
|
4813 |
qed |
|
4814 |
||
| 76386 | 4815 |
lemma mod_mult_unit_eq: |
4816 |
\<open>x mod (z * y) = x mod y\<close> |
|
4817 |
if \<open>is_unit z\<close> |
|
4818 |
for x y z :: \<open>'a::field poly\<close> |
|
4819 |
proof (cases \<open>y = 0\<close>) |
|
4820 |
case True |
|
4821 |
then show ?thesis |
|
4822 |
by simp |
|
4823 |
next |
|
4824 |
case False |
|
4825 |
moreover have \<open>z \<noteq> 0\<close> |
|
4826 |
using that by auto |
|
4827 |
moreover define a where \<open>a = lead_coeff z\<close> |
|
4828 |
ultimately have \<open>z = [:a:]\<close> \<open>a \<noteq> 0\<close> |
|
4829 |
using that monom_0 [of a] by (simp_all add: is_unit_monom_trivial) |
|
4830 |
then show ?thesis |
|
4831 |
by (simp add: mod_smult_right) |
|
4832 |
qed |
|
4833 |
||
| 76207 | 4834 |
lemma poly_div_minus_right [simp]: "x div (- y) = - (x div y)" |
4835 |
for x y :: "'a::field poly" |
|
4836 |
using div_smult_right [of _ "- 1::'a"] by (simp add: nonzero_inverse_minus_eq) |
|
4837 |
||
4838 |
lemma poly_mod_minus_right [simp]: "x mod (- y) = x mod y" |
|
4839 |
for x y :: "'a::field poly" |
|
4840 |
using mod_smult_right [of _ "- 1::'a"] by simp |
|
4841 |
||
4842 |
lemma poly_div_mult_right: \<open>x div (y * z) = (x div y) div z\<close> (is ?Q) |
|
4843 |
and poly_mod_mult_right: \<open>x mod (y * z) = y * (x div y mod z) + x mod y\<close> (is ?R) |
|
4844 |
for x y z :: \<open>'a::field poly\<close> |
|
4845 |
proof - |
|
4846 |
have \<open>(x div (y * z), x mod (y * z)) = ((x div y) div z, y * (x div y mod z) + x mod y)\<close> |
|
| 76245 | 4847 |
proof (induction rule: euclidean_relation_polyI) |
| 76207 | 4848 |
case by0 |
4849 |
then show ?case by auto |
|
4850 |
next |
|
4851 |
case divides |
|
4852 |
then show ?case by auto |
|
4853 |
next |
|
4854 |
case euclidean_relation |
|
4855 |
then have \<open>y \<noteq> 0\<close> \<open>z \<noteq> 0\<close> |
|
4856 |
by simp_all |
|
4857 |
with \<open>\<not> y * z dvd x\<close> have \<open>degree (y * (x div y mod z) + x mod y) < degree (y * z)\<close> |
|
4858 |
using degree_mod_less_degree [of y x] degree_mod_less_degree [of z \<open>x div y\<close>] |
|
4859 |
degree_add_eq_left [of \<open>x mod y\<close> \<open>y * (x div y mod z)\<close>] |
|
4860 |
by (cases \<open>z dvd x div y\<close>; cases \<open>y dvd x\<close>) |
|
4861 |
(auto simp add: degree_mult_eq not_dvd_imp_mod_neq_0 dvd_div_iff_mult) |
|
4862 |
moreover have \<open>x = x div y div z * (y * z) + (y * (x div y mod z) + x mod y)\<close> |
|
4863 |
by (simp add: field_simps flip: distrib_left) |
|
4864 |
ultimately show ?case |
|
4865 |
by simp |
|
4866 |
qed |
|
4867 |
then show ?Q and ?R |
|
4868 |
by simp_all |
|
4869 |
qed |
|
| 64795 | 4870 |
|
| 76208 | 4871 |
lemma dvd_pCons_imp_dvd_pCons_mod: |
4872 |
\<open>y dvd pCons a (x mod y)\<close> if \<open>y dvd pCons a x\<close> |
|
4873 |
proof - |
|
4874 |
have \<open>pCons a x = pCons a (x div y * y + x mod y)\<close> |
|
4875 |
by simp |
|
4876 |
also have \<open>\<dots> = pCons 0 (x div y * y) + pCons a (x mod y)\<close> |
|
4877 |
by simp |
|
4878 |
also have \<open>pCons 0 (x div y * y) = (x div y * monom 1 (Suc 0)) * y\<close> |
|
4879 |
by (simp add: monom_Suc) |
|
4880 |
finally show \<open>y dvd pCons a (x mod y)\<close> |
|
4881 |
using \<open>y dvd pCons a x\<close> by simp |
|
4882 |
qed |
|
4883 |
||
4884 |
lemma degree_less_if_less_eqI: |
|
4885 |
\<open>degree x < degree y\<close> if \<open>degree x \<le> degree y\<close> \<open>coeff x (degree y) = 0\<close> \<open>x \<noteq> 0\<close> |
|
4886 |
proof (cases \<open>degree x = degree y\<close>) |
|
4887 |
case True |
|
4888 |
with \<open>coeff x (degree y) = 0\<close> have \<open>lead_coeff x = 0\<close> |
|
4889 |
by simp |
|
4890 |
then have \<open>x = 0\<close> |
|
4891 |
by simp |
|
4892 |
with \<open>x \<noteq> 0\<close> show ?thesis |
|
4893 |
by simp |
|
4894 |
next |
|
4895 |
case False |
|
4896 |
with \<open>degree x \<le> degree y\<close> show ?thesis |
|
4897 |
by simp |
|
4898 |
qed |
|
4899 |
||
| 64811 | 4900 |
lemma div_pCons_eq: |
| 76208 | 4901 |
\<open>pCons a p div q = (if q = 0 then 0 else pCons (coeff (pCons a (p mod q)) (degree q) / lead_coeff q) (p div q))\<close> (is ?Q) |
4902 |
and mod_pCons_eq: |
|
4903 |
\<open>pCons a p mod q = (if q = 0 then pCons a p else pCons a (p mod q) - smult (coeff (pCons a (p mod q)) (degree q) / lead_coeff q) q)\<close> (is ?R) |
|
4904 |
for x y :: \<open>'a::field poly\<close> |
|
4905 |
proof - |
|
4906 |
have \<open>?Q\<close> and \<open>?R\<close> if \<open>q = 0\<close> |
|
4907 |
using that by simp_all |
|
4908 |
moreover have \<open>?Q\<close> and \<open>?R\<close> if \<open>q \<noteq> 0\<close> |
|
4909 |
proof - |
|
4910 |
define b where \<open>b = coeff (pCons a (p mod q)) (degree q) / lead_coeff q\<close> |
|
4911 |
have \<open>(pCons a p div q, pCons a p mod q) = |
|
4912 |
(pCons b (p div q), (pCons a (p mod q) - smult b q))\<close> (is \<open>_ = (?q, ?r)\<close>) |
|
| 76245 | 4913 |
proof (induction rule: euclidean_relation_polyI) |
| 76208 | 4914 |
case by0 |
4915 |
with \<open>q \<noteq> 0\<close> show ?case by simp |
|
4916 |
next |
|
4917 |
case divides |
|
4918 |
show ?case |
|
4919 |
proof (cases \<open>pCons a (p mod q) = 0\<close>) |
|
4920 |
case True |
|
4921 |
then show ?thesis |
|
4922 |
by (auto simp add: b_def) |
|
4923 |
next |
|
4924 |
case False |
|
4925 |
have \<open>q dvd pCons a (p mod q)\<close> |
|
4926 |
using \<open>q dvd pCons a p\<close> by (rule dvd_pCons_imp_dvd_pCons_mod) |
|
4927 |
then obtain s where *: \<open>pCons a (p mod q) = q * s\<close> .. |
|
4928 |
with False have \<open>s \<noteq> 0\<close> |
|
4929 |
by auto |
|
4930 |
from \<open>q \<noteq> 0\<close> have \<open>degree (pCons a (p mod q)) \<le> degree q\<close> |
|
4931 |
by (auto simp add: Suc_le_eq intro: degree_mod_less_degree) |
|
4932 |
moreover from \<open>s \<noteq> 0\<close> have \<open>degree q \<le> degree (pCons a (p mod q))\<close> |
|
4933 |
by (simp add: degree_mult_right_le *) |
|
4934 |
ultimately have \<open>degree (pCons a (p mod q)) = degree q\<close> |
|
4935 |
by (rule order.antisym) |
|
4936 |
with \<open>s \<noteq> 0\<close> \<open>q \<noteq> 0\<close> have \<open>degree s = 0\<close> |
|
4937 |
by (simp add: * degree_mult_eq) |
|
4938 |
then obtain c where \<open>s = [:c:]\<close> |
|
4939 |
by (rule degree_eq_zeroE) |
|
4940 |
also have \<open>c = b\<close> |
|
4941 |
using \<open>q \<noteq> 0\<close> by (simp add: b_def * \<open>s = [:c:]\<close>) |
|
4942 |
finally have \<open>smult b q = pCons a (p mod q)\<close> |
|
4943 |
by (simp add: *) |
|
4944 |
then show ?thesis |
|
4945 |
by simp |
|
4946 |
qed |
|
4947 |
next |
|
4948 |
case euclidean_relation |
|
4949 |
then have \<open>degree q > 0\<close> |
|
4950 |
using is_unit_iff_degree by blast |
|
4951 |
from \<open>q \<noteq> 0\<close> have \<open>degree (pCons a (p mod q)) \<le> degree q\<close> |
|
4952 |
by (auto simp add: Suc_le_eq intro: degree_mod_less_degree) |
|
4953 |
moreover have \<open>degree (smult b q) \<le> degree q\<close> |
|
4954 |
by (rule degree_smult_le) |
|
4955 |
ultimately have \<open>degree (pCons a (p mod q) - smult b q) \<le> degree q\<close> |
|
4956 |
by (rule degree_diff_le) |
|
4957 |
moreover have \<open>coeff (pCons a (p mod q) - smult b q) (degree q) = 0\<close> |
|
4958 |
using \<open>degree q > 0\<close> by (auto simp add: b_def) |
|
4959 |
ultimately have \<open>degree (pCons a (p mod q) - smult b q) < degree q\<close> |
|
4960 |
using \<open>degree q > 0\<close> |
|
4961 |
by (cases \<open>pCons a (p mod q) = smult b q\<close>) |
|
4962 |
(auto intro: degree_less_if_less_eqI) |
|
4963 |
then show ?case |
|
4964 |
by simp |
|
4965 |
qed |
|
4966 |
with \<open>q \<noteq> 0\<close> show ?Q and ?R |
|
4967 |
by (simp_all add: b_def) |
|
4968 |
qed |
|
4969 |
ultimately show ?Q and ?R |
|
4970 |
by simp_all |
|
4971 |
qed |
|
| 64811 | 4972 |
|
4973 |
lemma div_mod_fold_coeffs: |
|
| 65347 | 4974 |
"(p div q, p mod q) = |
4975 |
(if q = 0 then (0, p) |
|
4976 |
else |
|
4977 |
fold_coeffs |
|
4978 |
(\<lambda>a (s, r). |
|
4979 |
let b = coeff (pCons a r) (degree q) / coeff q (degree q) |
|
4980 |
in (pCons b s, pCons a r - smult b q)) p (0, 0))" |
|
4981 |
by (rule sym, induct p) (auto simp: div_pCons_eq mod_pCons_eq Let_def) |
|
4982 |
||
| 64795 | 4983 |
lemma mod_pCons: |
| 65347 | 4984 |
fixes a :: "'a::field" |
4985 |
and x y :: "'a::field poly" |
|
| 64795 | 4986 |
assumes y: "y \<noteq> 0" |
| 65347 | 4987 |
defines "b \<equiv> coeff (pCons a (x mod y)) (degree y) / coeff y (degree y)" |
4988 |
shows "(pCons a x) mod y = pCons a (x mod y) - smult b y" |
|
4989 |
unfolding b_def |
|
| 76207 | 4990 |
by (simp add: mod_pCons_eq) |
| 64795 | 4991 |
|
| 65346 | 4992 |
|
| 64795 | 4993 |
subsubsection \<open>List-based versions for fast implementation\<close> |
4994 |
(* Subsection by: |
|
4995 |
Sebastiaan Joosten |
|
4996 |
René Thiemann |
|
4997 |
Akihisa Yamada |
|
4998 |
*) |
|
| 65347 | 4999 |
fun minus_poly_rev_list :: "'a :: group_add list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
5000 |
where |
|
5001 |
"minus_poly_rev_list (x # xs) (y # ys) = (x - y) # (minus_poly_rev_list xs ys)" |
|
5002 |
| "minus_poly_rev_list xs [] = xs" |
|
5003 |
| "minus_poly_rev_list [] (y # ys) = []" |
|
5004 |
||
5005 |
fun pseudo_divmod_main_list :: |
|
5006 |
"'a::comm_ring_1 \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list \<times> 'a list" |
|
5007 |
where |
|
5008 |
"pseudo_divmod_main_list lc q r d (Suc n) = |
|
5009 |
(let |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5010 |
rr = map ((*) lc) r; |
| 65347 | 5011 |
a = hd r; |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5012 |
qqq = cCons a (map ((*) lc) q); |
|
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5013 |
rrr = tl (if a = 0 then rr else minus_poly_rev_list rr (map ((*) a) d)) |
| 65347 | 5014 |
in pseudo_divmod_main_list lc qqq rrr d n)" |
5015 |
| "pseudo_divmod_main_list lc q r d 0 = (q, r)" |
|
5016 |
||
5017 |
fun pseudo_mod_main_list :: "'a::comm_ring_1 \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list" |
|
5018 |
where |
|
5019 |
"pseudo_mod_main_list lc r d (Suc n) = |
|
5020 |
(let |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5021 |
rr = map ((*) lc) r; |
| 65347 | 5022 |
a = hd r; |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5023 |
rrr = tl (if a = 0 then rr else minus_poly_rev_list rr (map ((*) a) d)) |
| 65347 | 5024 |
in pseudo_mod_main_list lc rrr d n)" |
5025 |
| "pseudo_mod_main_list lc r d 0 = r" |
|
5026 |
||
5027 |
||
5028 |
fun divmod_poly_one_main_list :: |
|
5029 |
"'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list \<times> 'a list" |
|
5030 |
where |
|
5031 |
"divmod_poly_one_main_list q r d (Suc n) = |
|
5032 |
(let |
|
5033 |
a = hd r; |
|
5034 |
qqq = cCons a q; |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5035 |
rr = tl (if a = 0 then r else minus_poly_rev_list r (map ((*) a) d)) |
| 65347 | 5036 |
in divmod_poly_one_main_list qqq rr d n)" |
5037 |
| "divmod_poly_one_main_list q r d 0 = (q, r)" |
|
5038 |
||
5039 |
fun mod_poly_one_main_list :: "'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list" |
|
5040 |
where |
|
5041 |
"mod_poly_one_main_list r d (Suc n) = |
|
5042 |
(let |
|
5043 |
a = hd r; |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5044 |
rr = tl (if a = 0 then r else minus_poly_rev_list r (map ((*) a) d)) |
| 65347 | 5045 |
in mod_poly_one_main_list rr d n)" |
5046 |
| "mod_poly_one_main_list r d 0 = r" |
|
5047 |
||
5048 |
definition pseudo_divmod_list :: "'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> 'a list \<times> 'a list" |
|
5049 |
where "pseudo_divmod_list p q = |
|
5050 |
(if q = [] then ([], p) |
|
5051 |
else |
|
5052 |
(let rq = rev q; |
|
5053 |
(qu,re) = pseudo_divmod_main_list (hd rq) [] (rev p) rq (1 + length p - length q) |
|
5054 |
in (qu, rev re)))" |
|
5055 |
||
5056 |
definition pseudo_mod_list :: "'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
|
5057 |
where "pseudo_mod_list p q = |
|
5058 |
(if q = [] then p |
|
5059 |
else |
|
5060 |
(let |
|
5061 |
rq = rev q; |
|
5062 |
re = pseudo_mod_main_list (hd rq) (rev p) rq (1 + length p - length q) |
|
5063 |
in rev re))" |
|
5064 |
||
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5065 |
lemma minus_zero_does_nothing: "minus_poly_rev_list x (map ((*) 0) y) = x" |
| 65347 | 5066 |
for x :: "'a::ring list" |
5067 |
by (induct x y rule: minus_poly_rev_list.induct) auto |
|
5068 |
||
5069 |
lemma length_minus_poly_rev_list [simp]: "length (minus_poly_rev_list xs ys) = length xs" |
|
5070 |
by (induct xs ys rule: minus_poly_rev_list.induct) auto |
|
| 64795 | 5071 |
|
5072 |
lemma if_0_minus_poly_rev_list: |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5073 |
"(if a = 0 then x else minus_poly_rev_list x (map ((*) a) y)) = |
|
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5074 |
minus_poly_rev_list x (map ((*) a) y)" |
| 65347 | 5075 |
for a :: "'a::ring" |
5076 |
by(cases "a = 0") (simp_all add: minus_zero_does_nothing) |
|
5077 |
||
5078 |
lemma Poly_append: "Poly (a @ b) = Poly a + monom 1 (length a) * Poly b" |
|
5079 |
for a :: "'a::comm_semiring_1 list" |
|
5080 |
by (induct a) (auto simp: monom_0 monom_Suc) |
|
5081 |
||
5082 |
lemma minus_poly_rev_list: "length p \<ge> length q \<Longrightarrow> |
|
5083 |
Poly (rev (minus_poly_rev_list (rev p) (rev q))) = |
|
5084 |
Poly p - monom 1 (length p - length q) * Poly q" |
|
5085 |
for p q :: "'a :: comm_ring_1 list" |
|
| 64795 | 5086 |
proof (induct "rev p" "rev q" arbitrary: p q rule: minus_poly_rev_list.induct) |
| 65346 | 5087 |
case (1 x xs y ys) |
| 65347 | 5088 |
then have "length (rev q) \<le> length (rev p)" |
5089 |
by simp |
|
5090 |
from this[folded 1(2,3)] have ys_xs: "length ys \<le> length xs" |
|
5091 |
by simp |
|
5092 |
then have *: "Poly (rev (minus_poly_rev_list xs ys)) = |
|
5093 |
Poly (rev xs) - monom 1 (length xs - length ys) * Poly (rev ys)" |
|
5094 |
by (subst "1.hyps"(1)[of "rev xs" "rev ys", unfolded rev_rev_ident length_rev]) auto |
|
5095 |
have "Poly p - monom 1 (length p - length q) * Poly q = |
|
5096 |
Poly (rev (rev p)) - monom 1 (length (rev (rev p)) - length (rev (rev q))) * Poly (rev (rev q))" |
|
| 64795 | 5097 |
by simp |
| 65347 | 5098 |
also have "\<dots> = |
5099 |
Poly (rev (x # xs)) - monom 1 (length (x # xs) - length (y # ys)) * Poly (rev (y # ys))" |
|
| 64795 | 5100 |
unfolding 1(2,3) by simp |
| 65347 | 5101 |
also from ys_xs have "\<dots> = |
5102 |
Poly (rev xs) + monom x (length xs) - |
|
5103 |
(monom 1 (length xs - length ys) * Poly (rev ys) + monom y (length xs))" |
|
5104 |
by (simp add: Poly_append distrib_left mult_monom smult_monom) |
|
| 64795 | 5105 |
also have "\<dots> = Poly (rev (minus_poly_rev_list xs ys)) + monom (x - y) (length xs)" |
| 65347 | 5106 |
unfolding * diff_monom[symmetric] by simp |
| 64795 | 5107 |
finally show ?case |
| 65347 | 5108 |
by (simp add: 1(2,3)[symmetric] smult_monom Poly_append) |
| 64795 | 5109 |
qed auto |
5110 |
||
5111 |
lemma smult_monom_mult: "smult a (monom b n * f) = monom (a * b) n * f" |
|
5112 |
using smult_monom [of a _ n] by (metis mult_smult_left) |
|
5113 |
||
5114 |
lemma head_minus_poly_rev_list: |
|
| 65347 | 5115 |
"length d \<le> length r \<Longrightarrow> d \<noteq> [] \<Longrightarrow> |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5116 |
hd (minus_poly_rev_list (map ((*) (last d)) r) (map ((*) (hd r)) (rev d))) = 0" |
| 65347 | 5117 |
for d r :: "'a::comm_ring list" |
5118 |
proof (induct r) |
|
5119 |
case Nil |
|
5120 |
then show ?case by simp |
|
5121 |
next |
|
| 64795 | 5122 |
case (Cons a rs) |
| 65347 | 5123 |
then show ?case by (cases "rev d") (simp_all add: ac_simps) |
5124 |
qed |
|
| 64795 | 5125 |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5126 |
lemma Poly_map: "Poly (map ((*) a) p) = smult a (Poly p)" |
| 64795 | 5127 |
proof (induct p) |
| 65347 | 5128 |
case Nil |
5129 |
then show ?case by simp |
|
5130 |
next |
|
5131 |
case (Cons x xs) |
|
5132 |
then show ?case by (cases "Poly xs = 0") auto |
|
5133 |
qed |
|
| 64795 | 5134 |
|
5135 |
lemma last_coeff_is_hd: "xs \<noteq> [] \<Longrightarrow> coeff (Poly xs) (length xs - 1) = hd (rev xs)" |
|
5136 |
by (simp_all add: hd_conv_nth rev_nth nth_default_nth nth_append) |
|
5137 |
||
| 65347 | 5138 |
lemma pseudo_divmod_main_list_invar: |
5139 |
assumes leading_nonzero: "last d \<noteq> 0" |
|
5140 |
and lc: "last d = lc" |
|
5141 |
and "d \<noteq> []" |
|
5142 |
and "pseudo_divmod_main_list lc q (rev r) (rev d) n = (q', rev r')" |
|
5143 |
and "n = 1 + length r - length d" |
|
5144 |
shows "pseudo_divmod_main lc (monom 1 n * Poly q) (Poly r) (Poly d) (length r - 1) n = |
|
5145 |
(Poly q', Poly r')" |
|
5146 |
using assms(4-) |
|
5147 |
proof (induct n arbitrary: r q) |
|
5148 |
case (Suc n) |
|
5149 |
from Suc.prems have *: "\<not> Suc (length r) \<le> length d" |
|
5150 |
by simp |
|
5151 |
with \<open>d \<noteq> []\<close> have "r \<noteq> []" |
|
5152 |
using Suc_leI length_greater_0_conv list.size(3) by fastforce |
|
| 64795 | 5153 |
let ?a = "(hd (rev r))" |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5154 |
let ?rr = "map ((*) lc) (rev r)" |
|
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5155 |
let ?rrr = "rev (tl (minus_poly_rev_list ?rr (map ((*) ?a) (rev d))))" |
|
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5156 |
let ?qq = "cCons ?a (map ((*) lc) q)" |
| 65347 | 5157 |
from * Suc(3) have n: "n = (1 + length r - length d - 1)" |
5158 |
by simp |
|
5159 |
from * have rr_val:"(length ?rrr) = (length r - 1)" |
|
5160 |
by auto |
|
5161 |
with \<open>r \<noteq> []\<close> * have rr_smaller: "(1 + length r - length d - 1) = (1 + length ?rrr - length d)" |
|
5162 |
by auto |
|
5163 |
from * have id: "Suc (length r) - length d = Suc (length r - length d)" |
|
5164 |
by auto |
|
5165 |
from Suc.prems * |
|
| 64795 | 5166 |
have "pseudo_divmod_main_list lc ?qq (rev ?rrr) (rev d) (1 + length r - length d - 1) = (q', rev r')" |
| 65347 | 5167 |
by (simp add: Let_def if_0_minus_poly_rev_list id) |
5168 |
with n have v: "pseudo_divmod_main_list lc ?qq (rev ?rrr) (rev d) n = (q', rev r')" |
|
5169 |
by auto |
|
5170 |
from * have sucrr:"Suc (length r) - length d = Suc (length r - length d)" |
|
5171 |
using Suc_diff_le not_less_eq_eq by blast |
|
5172 |
from Suc(3) \<open>r \<noteq> []\<close> have n_ok : "n = 1 + (length ?rrr) - length d" |
|
5173 |
by simp |
|
| 65346 | 5174 |
have cong: "\<And>x1 x2 x3 x4 y1 y2 y3 y4. x1 = y1 \<Longrightarrow> x2 = y2 \<Longrightarrow> x3 = y3 \<Longrightarrow> x4 = y4 \<Longrightarrow> |
| 65347 | 5175 |
pseudo_divmod_main lc x1 x2 x3 x4 n = pseudo_divmod_main lc y1 y2 y3 y4 n" |
5176 |
by simp |
|
5177 |
have hd_rev: "coeff (Poly r) (length r - Suc 0) = hd (rev r)" |
|
5178 |
using last_coeff_is_hd[OF \<open>r \<noteq> []\<close>] by simp |
|
5179 |
show ?case |
|
5180 |
unfolding Suc.hyps(1)[OF v n_ok, symmetric] pseudo_divmod_main.simps Let_def |
|
| 64795 | 5181 |
proof (rule cong[OF _ _ refl], goal_cases) |
| 65346 | 5182 |
case 1 |
| 65347 | 5183 |
show ?case |
5184 |
by (simp add: monom_Suc hd_rev[symmetric] smult_monom Poly_map) |
|
| 64795 | 5185 |
next |
| 65346 | 5186 |
case 2 |
5187 |
show ?case |
|
| 64795 | 5188 |
proof (subst Poly_on_rev_starting_with_0, goal_cases) |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5189 |
show "hd (minus_poly_rev_list (map ((*) lc) (rev r)) (map ((*) (hd (rev r))) (rev d))) = 0" |
| 65347 | 5190 |
by (fold lc, subst head_minus_poly_rev_list, insert * \<open>d \<noteq> []\<close>, auto) |
5191 |
from * have "length d \<le> length r" |
|
5192 |
by simp |
|
| 64795 | 5193 |
then show "smult lc (Poly r) - monom (coeff (Poly r) (length r - 1)) n * Poly d = |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5194 |
Poly (rev (minus_poly_rev_list (map ((*) lc) (rev r)) (map ((*) (hd (rev r))) (rev d))))" |
| 64795 | 5195 |
by (fold rev_map) (auto simp add: n smult_monom_mult Poly_map hd_rev [symmetric] |
| 65347 | 5196 |
minus_poly_rev_list) |
| 64795 | 5197 |
qed |
5198 |
qed simp |
|
5199 |
qed simp |
|
5200 |
||
| 65390 | 5201 |
lemma pseudo_divmod_impl [code]: |
5202 |
"pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))" |
|
5203 |
for f g :: "'a::comm_ring_1 poly" |
|
| 65347 | 5204 |
proof (cases "g = 0") |
5205 |
case False |
|
| 65390 | 5206 |
then have "last (coeffs g) \<noteq> 0" |
5207 |
and "last (coeffs g) = lead_coeff g" |
|
5208 |
and "coeffs g \<noteq> []" |
|
5209 |
by (simp_all add: last_coeffs_eq_coeff_degree) |
|
5210 |
moreover obtain q r where qr: "pseudo_divmod_main_list |
|
5211 |
(last (coeffs g)) (rev []) |
|
5212 |
(rev (coeffs f)) (rev (coeffs g)) |
|
5213 |
(1 + length (coeffs f) - |
|
5214 |
length (coeffs g)) = (q, rev (rev r))" |
|
| 65347 | 5215 |
by force |
| 65390 | 5216 |
ultimately have "(Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g |
5217 |
(length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))" |
|
5218 |
by (subst pseudo_divmod_main_list_invar [symmetric]) auto |
|
5219 |
moreover have "pseudo_divmod_main_list |
|
5220 |
(hd (rev (coeffs g))) [] |
|
5221 |
(rev (coeffs f)) (rev (coeffs g)) |
|
5222 |
(1 + length (coeffs f) - |
|
5223 |
length (coeffs g)) = (q, r)" |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
5224 |
by (metis hd_rev qr rev.simps(1) rev_swap) |
| 65390 | 5225 |
ultimately show ?thesis |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
5226 |
by (simp add: degree_eq_length_coeffs pseudo_divmod_def pseudo_divmod_list_def) |
| 64795 | 5227 |
next |
5228 |
case True |
|
| 65347 | 5229 |
then show ?thesis |
| 65390 | 5230 |
by (auto simp add: pseudo_divmod_def pseudo_divmod_list_def) |
| 64795 | 5231 |
qed |
5232 |
||
| 65347 | 5233 |
lemma pseudo_mod_main_list: |
5234 |
"snd (pseudo_divmod_main_list l q xs ys n) = pseudo_mod_main_list l xs ys n" |
|
5235 |
by (induct n arbitrary: l q xs ys) (auto simp: Let_def) |
|
5236 |
||
5237 |
lemma pseudo_mod_impl[code]: "pseudo_mod f g = poly_of_list (pseudo_mod_list (coeffs f) (coeffs g))" |
|
| 64795 | 5238 |
proof - |
| 65346 | 5239 |
have snd_case: "\<And>f g p. snd ((\<lambda>(x,y). (f x, g y)) p) = g (snd p)" |
| 64795 | 5240 |
by auto |
5241 |
show ?thesis |
|
| 65347 | 5242 |
unfolding pseudo_mod_def pseudo_divmod_impl pseudo_divmod_list_def |
5243 |
pseudo_mod_list_def Let_def |
|
5244 |
by (simp add: snd_case pseudo_mod_main_list) |
|
| 64795 | 5245 |
qed |
5246 |
||
5247 |
||
5248 |
subsubsection \<open>Improved Code-Equations for Polynomial (Pseudo) Division\<close> |
|
5249 |
||
| 65347 | 5250 |
lemma pdivmod_via_pseudo_divmod: |
| 76194 | 5251 |
\<open>(f div g, f mod g) = |
| 65347 | 5252 |
(if g = 0 then (0, f) |
5253 |
else |
|
5254 |
let |
|
| 76194 | 5255 |
ilc = inverse (lead_coeff g); |
| 65347 | 5256 |
h = smult ilc g; |
5257 |
(q,r) = pseudo_divmod f h |
|
| 76194 | 5258 |
in (smult ilc q, r))\<close> |
5259 |
(is \<open>?l = ?r\<close>) |
|
5260 |
proof (cases \<open>g = 0\<close>) |
|
| 65347 | 5261 |
case True |
5262 |
then show ?thesis by simp |
|
5263 |
next |
|
| 64795 | 5264 |
case False |
| 76194 | 5265 |
define ilc where \<open>ilc = inverse (lead_coeff g)\<close> |
5266 |
define h where \<open>h = smult ilc g\<close> |
|
5267 |
from False have \<open>lead_coeff h = 1\<close> |
|
| 76207 | 5268 |
and \<open>ilc \<noteq> 0\<close> |
| 76194 | 5269 |
by (auto simp: h_def ilc_def) |
5270 |
define q r where \<open>q = f div h\<close> and \<open>r = f mod h\<close> |
|
5271 |
with \<open>lead_coeff h = 1\<close> have p: \<open>pseudo_divmod f h = (q, r)\<close> |
|
5272 |
by (simp add: pseudo_divmod_eq_div_mod) |
|
| 76207 | 5273 |
from \<open>ilc \<noteq> 0\<close> have \<open>(f div g, f mod g) = (smult ilc q, r)\<close> |
5274 |
by (auto simp: h_def div_smult_right mod_smult_right q_def r_def) |
|
| 76194 | 5275 |
also have \<open>(smult ilc q, r) = ?r\<close> |
5276 |
using \<open>g \<noteq> 0\<close> by (auto simp: Let_def p simp flip: h_def ilc_def) |
|
5277 |
finally show ?thesis . |
|
| 65347 | 5278 |
qed |
5279 |
||
5280 |
lemma pdivmod_via_pseudo_divmod_list: |
|
5281 |
"(f div g, f mod g) = |
|
5282 |
(let cg = coeffs g in |
|
5283 |
if cg = [] then (0, f) |
|
5284 |
else |
|
5285 |
let |
|
5286 |
cf = coeffs f; |
|
5287 |
ilc = inverse (last cg); |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5288 |
ch = map ((*) ilc) cg; |
| 65347 | 5289 |
(q, r) = pseudo_divmod_main_list 1 [] (rev cf) (rev ch) (1 + length cf - length cg) |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5290 |
in (poly_of_list (map ((*) ilc) q), poly_of_list (rev r)))" |
| 64795 | 5291 |
proof - |
| 65347 | 5292 |
note d = pdivmod_via_pseudo_divmod pseudo_divmod_impl pseudo_divmod_list_def |
| 64795 | 5293 |
show ?thesis |
5294 |
proof (cases "g = 0") |
|
| 65347 | 5295 |
case True |
5296 |
with d show ?thesis by auto |
|
| 64795 | 5297 |
next |
5298 |
case False |
|
5299 |
define ilc where "ilc = inverse (coeff g (degree g))" |
|
| 65347 | 5300 |
from False have ilc: "ilc \<noteq> 0" |
5301 |
by (auto simp: ilc_def) |
|
5302 |
with False have id: "g = 0 \<longleftrightarrow> False" "coeffs g = [] \<longleftrightarrow> False" |
|
| 65346 | 5303 |
"last (coeffs g) = coeff g (degree g)" |
| 65347 | 5304 |
"coeffs (smult ilc g) = [] \<longleftrightarrow> False" |
| 65346 | 5305 |
by (auto simp: last_coeffs_eq_coeff_degree) |
5306 |
have id2: "hd (rev (coeffs (smult ilc g))) = 1" |
|
| 64795 | 5307 |
by (subst hd_rev, insert id ilc, auto simp: coeffs_smult, subst last_map, auto simp: id ilc_def) |
| 65346 | 5308 |
have id3: "length (coeffs (smult ilc g)) = length (coeffs g)" |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5309 |
"rev (coeffs (smult ilc g)) = rev (map ((*) ilc) (coeffs g))" |
| 65347 | 5310 |
unfolding coeffs_smult using ilc by auto |
5311 |
obtain q r where pair: |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5312 |
"pseudo_divmod_main_list 1 [] (rev (coeffs f)) (rev (map ((*) ilc) (coeffs g))) |
| 65347 | 5313 |
(1 + length (coeffs f) - length (coeffs g)) = (q, r)" |
5314 |
by force |
|
5315 |
show ?thesis |
|
5316 |
unfolding d Let_def id if_False ilc_def[symmetric] map_prod_def[symmetric] id2 |
|
5317 |
unfolding id3 pair map_prod_def split |
|
5318 |
by (auto simp: Poly_map) |
|
| 64795 | 5319 |
qed |
5320 |
qed |
|
5321 |
||
5322 |
lemma pseudo_divmod_main_list_1: "pseudo_divmod_main_list 1 = divmod_poly_one_main_list" |
|
5323 |
proof (intro ext, goal_cases) |
|
5324 |
case (1 q r d n) |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5325 |
have *: "map ((*) 1) xs = xs" for xs :: "'a list" |
| 65347 | 5326 |
by (induct xs) auto |
5327 |
show ?case |
|
5328 |
by (induct n arbitrary: q r d) (auto simp: * Let_def) |
|
| 64795 | 5329 |
qed |
5330 |
||
| 65347 | 5331 |
fun divide_poly_main_list :: "'a::idom_divide \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list" |
5332 |
where |
|
5333 |
"divide_poly_main_list lc q r d (Suc n) = |
|
5334 |
(let |
|
5335 |
cr = hd r |
|
5336 |
in if cr = 0 then divide_poly_main_list lc (cCons cr q) (tl r) d n else let |
|
5337 |
a = cr div lc; |
|
5338 |
qq = cCons a q; |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5339 |
rr = minus_poly_rev_list r (map ((*) a) d) |
| 65347 | 5340 |
in if hd rr = 0 then divide_poly_main_list lc qq (tl rr) d n else [])" |
5341 |
| "divide_poly_main_list lc q r d 0 = q" |
|
5342 |
||
5343 |
lemma divide_poly_main_list_simp [simp]: |
|
5344 |
"divide_poly_main_list lc q r d (Suc n) = |
|
5345 |
(let |
|
5346 |
cr = hd r; |
|
5347 |
a = cr div lc; |
|
5348 |
qq = cCons a q; |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5349 |
rr = minus_poly_rev_list r (map ((*) a) d) |
| 64795 | 5350 |
in if hd rr = 0 then divide_poly_main_list lc qq (tl rr) d n else [])" |
5351 |
by (simp add: Let_def minus_zero_does_nothing) |
|
5352 |
||
5353 |
declare divide_poly_main_list.simps(1)[simp del] |
|
5354 |
||
| 65347 | 5355 |
definition divide_poly_list :: "'a::idom_divide poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
5356 |
where "divide_poly_list f g = |
|
5357 |
(let cg = coeffs g in |
|
5358 |
if cg = [] then g |
|
5359 |
else |
|
5360 |
let |
|
5361 |
cf = coeffs f; |
|
5362 |
cgr = rev cg |
|
5363 |
in poly_of_list (divide_poly_main_list (hd cgr) [] (rev cf) cgr (1 + length cf - length cg)))" |
|
| 64795 | 5364 |
|
| 64811 | 5365 |
lemmas pdivmod_via_divmod_list = pdivmod_via_pseudo_divmod_list[unfolded pseudo_divmod_main_list_1] |
| 64795 | 5366 |
|
5367 |
lemma mod_poly_one_main_list: "snd (divmod_poly_one_main_list q r d n) = mod_poly_one_main_list r d n" |
|
| 65347 | 5368 |
by (induct n arbitrary: q r d) (auto simp: Let_def) |
5369 |
||
5370 |
lemma mod_poly_code [code]: |
|
5371 |
"f mod g = |
|
5372 |
(let cg = coeffs g in |
|
5373 |
if cg = [] then f |
|
5374 |
else |
|
5375 |
let |
|
5376 |
cf = coeffs f; |
|
5377 |
ilc = inverse (last cg); |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5378 |
ch = map ((*) ilc) cg; |
| 65347 | 5379 |
r = mod_poly_one_main_list (rev cf) (rev ch) (1 + length cf - length cg) |
5380 |
in poly_of_list (rev r))" |
|
5381 |
(is "_ = ?rhs") |
|
| 64795 | 5382 |
proof - |
| 65347 | 5383 |
have "snd (f div g, f mod g) = ?rhs" |
5384 |
unfolding pdivmod_via_divmod_list Let_def mod_poly_one_main_list [symmetric, of _ _ _ Nil] |
|
5385 |
by (auto split: prod.splits) |
|
5386 |
then show ?thesis by simp |
|
| 64795 | 5387 |
qed |
5388 |
||
| 65347 | 5389 |
definition div_field_poly_impl :: "'a :: field poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" |
5390 |
where "div_field_poly_impl f g = |
|
5391 |
(let cg = coeffs g in |
|
5392 |
if cg = [] then 0 |
|
5393 |
else |
|
5394 |
let |
|
5395 |
cf = coeffs f; |
|
5396 |
ilc = inverse (last cg); |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5397 |
ch = map ((*) ilc) cg; |
| 65347 | 5398 |
q = fst (divmod_poly_one_main_list [] (rev cf) (rev ch) (1 + length cf - length cg)) |
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5399 |
in poly_of_list ((map ((*) ilc) q)))" |
| 64795 | 5400 |
|
| 65346 | 5401 |
text \<open>We do not declare the following lemma as code equation, since then polynomial division |
5402 |
on non-fields will no longer be executable. However, a code-unfold is possible, since |
|
| 64795 | 5403 |
\<open>div_field_poly_impl\<close> is a bit more efficient than the generic polynomial division.\<close> |
| 67399 | 5404 |
lemma div_field_poly_impl[code_unfold]: "(div) = div_field_poly_impl" |
| 64795 | 5405 |
proof (intro ext) |
5406 |
fix f g :: "'a poly" |
|
| 65347 | 5407 |
have "fst (f div g, f mod g) = div_field_poly_impl f g" |
5408 |
unfolding div_field_poly_impl_def pdivmod_via_divmod_list Let_def |
|
5409 |
by (auto split: prod.splits) |
|
| 64811 | 5410 |
then show "f div g = div_field_poly_impl f g" |
5411 |
by simp |
|
| 64795 | 5412 |
qed |
5413 |
||
5414 |
lemma divide_poly_main_list: |
|
5415 |
assumes lc0: "lc \<noteq> 0" |
|
| 65347 | 5416 |
and lc: "last d = lc" |
5417 |
and d: "d \<noteq> []" |
|
5418 |
and "n = (1 + length r - length d)" |
|
5419 |
shows "Poly (divide_poly_main_list lc q (rev r) (rev d) n) = |
|
5420 |
divide_poly_main lc (monom 1 n * Poly q) (Poly r) (Poly d) (length r - 1) n" |
|
5421 |
using assms(4-) |
|
5422 |
proof (induct "n" arbitrary: r q) |
|
5423 |
case (Suc n) |
|
5424 |
from Suc.prems have ifCond: "\<not> Suc (length r) \<le> length d" |
|
5425 |
by simp |
|
5426 |
with d have r: "r \<noteq> []" |
|
5427 |
using Suc_leI length_greater_0_conv list.size(3) by fastforce |
|
5428 |
then obtain rr lcr where r: "r = rr @ [lcr]" |
|
5429 |
by (cases r rule: rev_cases) auto |
|
| 65346 | 5430 |
from d lc obtain dd where d: "d = dd @ [lc]" |
| 65347 | 5431 |
by (cases d rule: rev_cases) auto |
5432 |
from Suc(2) ifCond have n: "n = 1 + length rr - length d" |
|
5433 |
by (auto simp: r) |
|
5434 |
from ifCond have len: "length dd \<le> length rr" |
|
5435 |
by (simp add: r d) |
|
| 64795 | 5436 |
show ?case |
5437 |
proof (cases "lcr div lc * lc = lcr") |
|
5438 |
case False |
|
| 65347 | 5439 |
with r d show ?thesis |
5440 |
unfolding Suc(2)[symmetric] |
|
| 64795 | 5441 |
by (auto simp add: Let_def nth_default_append) |
5442 |
next |
|
5443 |
case True |
|
| 65347 | 5444 |
with r d have id: |
5445 |
"?thesis \<longleftrightarrow> |
|
5446 |
Poly (divide_poly_main_list lc (cCons (lcr div lc) q) |
|
|
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
69022
diff
changeset
|
5447 |
(rev (rev (minus_poly_rev_list (rev rr) (rev (map ((*) (lcr div lc)) dd))))) (rev d) n) = |
| 65347 | 5448 |
divide_poly_main lc |
5449 |
(monom 1 (Suc n) * Poly q + monom (lcr div lc) n) |
|
5450 |
(Poly r - monom (lcr div lc) n * Poly d) |
|
5451 |
(Poly d) (length rr - 1) n" |
|
5452 |
by (cases r rule: rev_cases; cases "d" rule: rev_cases) |
|
5453 |
(auto simp add: Let_def rev_map nth_default_append) |
|
| 65346 | 5454 |
have cong: "\<And>x1 x2 x3 x4 y1 y2 y3 y4. x1 = y1 \<Longrightarrow> x2 = y2 \<Longrightarrow> x3 = y3 \<Longrightarrow> x4 = y4 \<Longrightarrow> |
| 65347 | 5455 |
divide_poly_main lc x1 x2 x3 x4 n = divide_poly_main lc y1 y2 y3 y4 n" |
5456 |
by simp |
|
5457 |
show ?thesis |
|
5458 |
unfolding id |
|
| 64795 | 5459 |
proof (subst Suc(1), simp add: n, |
| 65347 | 5460 |
subst minus_poly_rev_list, force simp: len, rule cong[OF _ _ refl], goal_cases) |
| 65346 | 5461 |
case 2 |
| 64795 | 5462 |
have "monom lcr (length rr) = monom (lcr div lc) (length rr - length dd) * monom lc (length dd)" |
5463 |
by (simp add: mult_monom len True) |
|
| 65346 | 5464 |
then show ?case unfolding r d Poly_append n ring_distribs |
| 64795 | 5465 |
by (auto simp: Poly_map smult_monom smult_monom_mult) |
5466 |
qed (auto simp: len monom_Suc smult_monom) |
|
5467 |
qed |
|
5468 |
qed simp |
|
5469 |
||
| 65346 | 5470 |
lemma divide_poly_list[code]: "f div g = divide_poly_list f g" |
| 64795 | 5471 |
proof - |
5472 |
note d = divide_poly_def divide_poly_list_def |
|
5473 |
show ?thesis |
|
5474 |
proof (cases "g = 0") |
|
5475 |
case True |
|
| 65347 | 5476 |
show ?thesis by (auto simp: d True) |
| 64795 | 5477 |
next |
5478 |
case False |
|
| 65347 | 5479 |
then obtain cg lcg where cg: "coeffs g = cg @ [lcg]" |
5480 |
by (cases "coeffs g" rule: rev_cases) auto |
|
5481 |
with False have id: "(g = 0) = False" "(cg @ [lcg] = []) = False" |
|
5482 |
by auto |
|
| 65346 | 5483 |
from cg False have lcg: "coeff g (degree g) = lcg" |
| 64795 | 5484 |
using last_coeffs_eq_coeff_degree last_snoc by force |
| 65347 | 5485 |
with False have "lcg \<noteq> 0" by auto |
5486 |
from cg Poly_coeffs [of g] have ltp: "Poly (cg @ [lcg]) = g" |
|
5487 |
by auto |
|
5488 |
show ?thesis |
|
5489 |
unfolding d cg Let_def id if_False poly_of_list_def |
|
5490 |
by (subst divide_poly_main_list, insert False cg \<open>lcg \<noteq> 0\<close>) |
|
5491 |
(auto simp: lcg ltp, simp add: degree_eq_length_coeffs) |
|
| 64795 | 5492 |
qed |
|
63317
ca187a9f66da
Various additions to polynomials, FPSs, Gamma function
eberlm
parents:
63145
diff
changeset
|
5493 |
qed |
| 52380 | 5494 |
|
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5495 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5496 |
subsection \<open>Primality and irreducibility in polynomial rings\<close> |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5497 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5498 |
lemma prod_mset_const_poly: "(\<Prod>x\<in>#A. [:f x:]) = [:prod_mset (image_mset f A):]" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5499 |
by (induct A) (simp_all add: ac_simps) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5500 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5501 |
lemma irreducible_const_poly_iff: |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5502 |
fixes c :: "'a :: {comm_semiring_1,semiring_no_zero_divisors}"
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5503 |
shows "irreducible [:c:] \<longleftrightarrow> irreducible c" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5504 |
proof |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5505 |
assume A: "irreducible c" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5506 |
show "irreducible [:c:]" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5507 |
proof (rule irreducibleI) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5508 |
fix a b assume ab: "[:c:] = a * b" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5509 |
hence "degree [:c:] = degree (a * b)" by (simp only: ) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5510 |
also from A ab have "a \<noteq> 0" "b \<noteq> 0" by auto |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5511 |
hence "degree (a * b) = degree a + degree b" by (simp add: degree_mult_eq) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5512 |
finally have "degree a = 0" "degree b = 0" by auto |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5513 |
then obtain a' b' where ab': "a = [:a':]" "b = [:b':]" by (auto elim!: degree_eq_zeroE) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5514 |
from ab have "coeff [:c:] 0 = coeff (a * b) 0" by (simp only: ) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5515 |
hence "c = a' * b'" by (simp add: ab' mult_ac) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5516 |
from A and this have "a' dvd 1 \<or> b' dvd 1" by (rule irreducibleD) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5517 |
with ab' show "a dvd 1 \<or> b dvd 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5518 |
by (auto simp add: is_unit_const_poly_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5519 |
qed (insert A, auto simp: irreducible_def is_unit_poly_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5520 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5521 |
assume A: "irreducible [:c:]" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5522 |
then have "c \<noteq> 0" and "\<not> c dvd 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5523 |
by (auto simp add: irreducible_def is_unit_const_poly_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5524 |
then show "irreducible c" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5525 |
proof (rule irreducibleI) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5526 |
fix a b assume ab: "c = a * b" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5527 |
hence "[:c:] = [:a:] * [:b:]" by (simp add: mult_ac) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5528 |
from A and this have "[:a:] dvd 1 \<or> [:b:] dvd 1" by (rule irreducibleD) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5529 |
then show "a dvd 1 \<or> b dvd 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5530 |
by (auto simp add: is_unit_const_poly_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5531 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5532 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5533 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5534 |
lemma lift_prime_elem_poly: |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5535 |
assumes "prime_elem (c :: 'a :: semidom)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5536 |
shows "prime_elem [:c:]" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5537 |
proof (rule prime_elemI) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5538 |
fix a b assume *: "[:c:] dvd a * b" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5539 |
from * have dvd: "c dvd coeff (a * b) n" for n |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5540 |
by (subst (asm) const_poly_dvd_iff) blast |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5541 |
{
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5542 |
define m where "m = (GREATEST m. \<not>c dvd coeff b m)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5543 |
assume "\<not>[:c:] dvd b" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5544 |
hence A: "\<exists>i. \<not>c dvd coeff b i" by (subst (asm) const_poly_dvd_iff) blast |
| 71586 | 5545 |
have B: "\<And>i. \<not>c dvd coeff b i \<Longrightarrow> i \<le> degree b" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5546 |
by (auto intro: le_degree) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5547 |
have coeff_m: "\<not>c dvd coeff b m" unfolding m_def by (rule GreatestI_ex_nat[OF A B]) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5548 |
have "i \<le> m" if "\<not>c dvd coeff b i" for i |
| 71586 | 5549 |
unfolding m_def by (metis (mono_tags, lifting) B Greatest_le_nat that) |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5550 |
hence dvd_b: "c dvd coeff b i" if "i > m" for i using that by force |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5551 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5552 |
have "c dvd coeff a i" for i |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5553 |
proof (induction i rule: nat_descend_induct[of "degree a"]) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5554 |
case (base i) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5555 |
thus ?case by (simp add: coeff_eq_0) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5556 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5557 |
case (descend i) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5558 |
let ?A = "{..i+m} - {i}"
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5559 |
have "c dvd coeff (a * b) (i + m)" by (rule dvd) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5560 |
also have "coeff (a * b) (i + m) = (\<Sum>k\<le>i + m. coeff a k * coeff b (i + m - k))" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5561 |
by (simp add: coeff_mult) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5562 |
also have "{..i+m} = insert i ?A" by auto
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5563 |
also have "(\<Sum>k\<in>\<dots>. coeff a k * coeff b (i + m - k)) = |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5564 |
coeff a i * coeff b m + (\<Sum>k\<in>?A. coeff a k * coeff b (i + m - k))" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5565 |
(is "_ = _ + ?S") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5566 |
by (subst sum.insert) simp_all |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5567 |
finally have eq: "c dvd coeff a i * coeff b m + ?S" . |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5568 |
moreover have "c dvd ?S" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5569 |
proof (rule dvd_sum) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5570 |
fix k assume k: "k \<in> {..i+m} - {i}"
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5571 |
show "c dvd coeff a k * coeff b (i + m - k)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5572 |
proof (cases "k < i") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5573 |
case False |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5574 |
with k have "c dvd coeff a k" by (intro descend.IH) simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5575 |
thus ?thesis by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5576 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5577 |
case True |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5578 |
hence "c dvd coeff b (i + m - k)" by (intro dvd_b) simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5579 |
thus ?thesis by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5580 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5581 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5582 |
ultimately have "c dvd coeff a i * coeff b m" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5583 |
by (simp add: dvd_add_left_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5584 |
with assms coeff_m show "c dvd coeff a i" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5585 |
by (simp add: prime_elem_dvd_mult_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5586 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5587 |
hence "[:c:] dvd a" by (subst const_poly_dvd_iff) blast |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5588 |
} |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5589 |
then show "[:c:] dvd a \<or> [:c:] dvd b" by blast |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5590 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5591 |
from assms show "[:c:] \<noteq> 0" and "\<not> [:c:] dvd 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5592 |
by (simp_all add: prime_elem_def is_unit_const_poly_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5593 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5594 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5595 |
lemma prime_elem_const_poly_iff: |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5596 |
fixes c :: "'a :: semidom" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5597 |
shows "prime_elem [:c:] \<longleftrightarrow> prime_elem c" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5598 |
proof |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5599 |
assume A: "prime_elem [:c:]" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5600 |
show "prime_elem c" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5601 |
proof (rule prime_elemI) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5602 |
fix a b assume "c dvd a * b" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5603 |
hence "[:c:] dvd [:a:] * [:b:]" by (simp add: mult_ac) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5604 |
from A and this have "[:c:] dvd [:a:] \<or> [:c:] dvd [:b:]" by (rule prime_elem_dvd_multD) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5605 |
thus "c dvd a \<or> c dvd b" by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5606 |
qed (insert A, auto simp: prime_elem_def is_unit_poly_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5607 |
qed (auto intro: lift_prime_elem_poly) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5608 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5609 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5610 |
subsection \<open>Content and primitive part of a polynomial\<close> |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5611 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5612 |
definition content :: "'a::semiring_gcd poly \<Rightarrow> 'a" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5613 |
where "content p = gcd_list (coeffs p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5614 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5615 |
lemma content_eq_fold_coeffs [code]: "content p = fold_coeffs gcd p 0" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5616 |
by (simp add: content_def Gcd_fin.set_eq_fold fold_coeffs_def foldr_fold fun_eq_iff ac_simps) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5617 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5618 |
lemma content_0 [simp]: "content 0 = 0" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5619 |
by (simp add: content_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5620 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5621 |
lemma content_1 [simp]: "content 1 = 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5622 |
by (simp add: content_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5623 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5624 |
lemma content_const [simp]: "content [:c:] = normalize c" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5625 |
by (simp add: content_def cCons_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5626 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5627 |
lemma const_poly_dvd_iff_dvd_content: "[:c:] dvd p \<longleftrightarrow> c dvd content p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5628 |
for c :: "'a::semiring_gcd" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5629 |
proof (cases "p = 0") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5630 |
case True |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5631 |
then show ?thesis by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5632 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5633 |
case False |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5634 |
have "[:c:] dvd p \<longleftrightarrow> (\<forall>n. c dvd coeff p n)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5635 |
by (rule const_poly_dvd_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5636 |
also have "\<dots> \<longleftrightarrow> (\<forall>a\<in>set (coeffs p). c dvd a)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5637 |
proof safe |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5638 |
fix n :: nat |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5639 |
assume "\<forall>a\<in>set (coeffs p). c dvd a" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5640 |
then show "c dvd coeff p n" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5641 |
by (cases "n \<le> degree p") (auto simp: coeff_eq_0 coeffs_def split: if_splits) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5642 |
qed (auto simp: coeffs_def simp del: upt_Suc split: if_splits) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5643 |
also have "\<dots> \<longleftrightarrow> c dvd content p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5644 |
by (simp add: content_def dvd_Gcd_fin_iff dvd_mult_unit_iff) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5645 |
finally show ?thesis . |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5646 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5647 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5648 |
lemma content_dvd [simp]: "[:content p:] dvd p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5649 |
by (subst const_poly_dvd_iff_dvd_content) simp_all |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5650 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5651 |
lemma content_dvd_coeff [simp]: "content p dvd coeff p n" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5652 |
proof (cases "p = 0") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5653 |
case True |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5654 |
then show ?thesis |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5655 |
by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5656 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5657 |
case False |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5658 |
then show ?thesis |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5659 |
by (cases "n \<le> degree p") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5660 |
(auto simp add: content_def not_le coeff_eq_0 coeff_in_coeffs intro: Gcd_fin_dvd) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5661 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5662 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5663 |
lemma content_dvd_coeffs: "c \<in> set (coeffs p) \<Longrightarrow> content p dvd c" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5664 |
by (simp add: content_def Gcd_fin_dvd) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5665 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5666 |
lemma normalize_content [simp]: "normalize (content p) = content p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5667 |
by (simp add: content_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5668 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5669 |
lemma is_unit_content_iff [simp]: "is_unit (content p) \<longleftrightarrow> content p = 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5670 |
proof |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5671 |
assume "is_unit (content p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5672 |
then have "normalize (content p) = 1" by (simp add: is_unit_normalize del: normalize_content) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5673 |
then show "content p = 1" by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5674 |
qed auto |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5675 |
|
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5676 |
lemma content_smult [simp]: |
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5677 |
fixes c :: "'a :: {normalization_semidom_multiplicative, semiring_gcd}"
|
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5678 |
shows "content (smult c p) = normalize c * content p" |
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5679 |
by (simp add: content_def coeffs_smult Gcd_fin_mult normalize_mult) |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5680 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5681 |
lemma content_eq_zero_iff [simp]: "content p = 0 \<longleftrightarrow> p = 0" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5682 |
by (auto simp: content_def simp: poly_eq_iff coeffs_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5683 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5684 |
definition primitive_part :: "'a :: semiring_gcd poly \<Rightarrow> 'a poly" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5685 |
where "primitive_part p = map_poly (\<lambda>x. x div content p) p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5686 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5687 |
lemma primitive_part_0 [simp]: "primitive_part 0 = 0" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5688 |
by (simp add: primitive_part_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5689 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5690 |
lemma content_times_primitive_part [simp]: "smult (content p) (primitive_part p) = p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5691 |
for p :: "'a :: semiring_gcd poly" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5692 |
proof (cases "p = 0") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5693 |
case True |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5694 |
then show ?thesis by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5695 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5696 |
case False |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5697 |
then show ?thesis |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5698 |
unfolding primitive_part_def |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5699 |
by (auto simp: smult_conv_map_poly map_poly_map_poly o_def content_dvd_coeffs |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5700 |
intro: map_poly_idI) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5701 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5702 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5703 |
lemma primitive_part_eq_0_iff [simp]: "primitive_part p = 0 \<longleftrightarrow> p = 0" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5704 |
proof (cases "p = 0") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5705 |
case True |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5706 |
then show ?thesis by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5707 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5708 |
case False |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5709 |
then have "primitive_part p = map_poly (\<lambda>x. x div content p) p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5710 |
by (simp add: primitive_part_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5711 |
also from False have "\<dots> = 0 \<longleftrightarrow> p = 0" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5712 |
by (intro map_poly_eq_0_iff) (auto simp: dvd_div_eq_0_iff content_dvd_coeffs) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5713 |
finally show ?thesis |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5714 |
using False by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5715 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5716 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5717 |
lemma content_primitive_part [simp]: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5718 |
fixes p :: "'a :: {normalization_semidom_multiplicative, semiring_gcd} poly"
|
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5719 |
assumes "p \<noteq> 0" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5720 |
shows "content (primitive_part p) = 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5721 |
proof - |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5722 |
have "p = smult (content p) (primitive_part p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5723 |
by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5724 |
also have "content \<dots> = content (primitive_part p) * content p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5725 |
by (simp del: content_times_primitive_part add: ac_simps) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5726 |
finally have "1 * content p = content (primitive_part p) * content p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5727 |
by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5728 |
then have "1 * content p div content p = content (primitive_part p) * content p div content p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5729 |
by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5730 |
with assms show ?thesis |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5731 |
by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5732 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5733 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5734 |
lemma content_decompose: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5735 |
obtains p' :: "'a :: {normalization_semidom_multiplicative, semiring_gcd} poly"
|
|
68790
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5736 |
where "p = smult (content p) p'" "content p' = 1" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5737 |
proof (cases "p = 0") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5738 |
case True |
|
68790
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5739 |
then have "p = smult (content p) 1" "content 1 = 1" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5740 |
by simp_all |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5741 |
then show ?thesis .. |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5742 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5743 |
case False |
|
68790
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5744 |
then have "p = smult (content p) (primitive_part p)" "content (primitive_part p) = 1" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5745 |
by simp_all |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5746 |
then show ?thesis .. |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5747 |
qed |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
5748 |
|
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5749 |
lemma content_dvd_contentI [intro]: "p dvd q \<Longrightarrow> content p dvd content q" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5750 |
using const_poly_dvd_iff_dvd_content content_dvd dvd_trans by blast |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5751 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5752 |
lemma primitive_part_const_poly [simp]: "primitive_part [:x:] = [:unit_factor x:]" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5753 |
by (simp add: primitive_part_def map_poly_pCons) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5754 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5755 |
lemma primitive_part_prim: "content p = 1 \<Longrightarrow> primitive_part p = p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5756 |
by (auto simp: primitive_part_def) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5757 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5758 |
lemma degree_primitive_part [simp]: "degree (primitive_part p) = degree p" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5759 |
proof (cases "p = 0") |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5760 |
case True |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5761 |
then show ?thesis by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5762 |
next |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5763 |
case False |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5764 |
have "p = smult (content p) (primitive_part p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5765 |
by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5766 |
also from False have "degree \<dots> = degree (primitive_part p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5767 |
by (subst degree_smult_eq) simp_all |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5768 |
finally show ?thesis .. |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5769 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5770 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5771 |
lemma smult_content_normalize_primitive_part [simp]: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5772 |
fixes p :: "'a :: {normalization_semidom_multiplicative, semiring_gcd, idom_divide} poly"
|
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5773 |
shows "smult (content p) (normalize (primitive_part p)) = normalize p" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5774 |
proof - |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5775 |
have "smult (content p) (normalize (primitive_part p)) = |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5776 |
normalize ([:content p:] * primitive_part p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5777 |
by (subst normalize_mult) (simp_all add: normalize_const_poly) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5778 |
also have "[:content p:] * primitive_part p = p" by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5779 |
finally show ?thesis . |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5780 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5781 |
|
|
68790
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5782 |
context |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5783 |
begin |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5784 |
|
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5785 |
private |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5786 |
|
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5787 |
lemma content_1_mult: |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5788 |
fixes f g :: "'a :: {semiring_gcd, factorial_semiring} poly"
|
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5789 |
assumes "content f = 1" "content g = 1" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5790 |
shows "content (f * g) = 1" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5791 |
proof (cases "f * g = 0") |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5792 |
case False |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5793 |
from assms have "f \<noteq> 0" "g \<noteq> 0" by auto |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5794 |
|
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5795 |
hence "f * g \<noteq> 0" by auto |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5796 |
{
|
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5797 |
assume "\<not>is_unit (content (f * g))" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5798 |
with False have "\<exists>p. p dvd content (f * g) \<and> prime p" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5799 |
by (intro prime_divisor_exists) simp_all |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5800 |
then obtain p where "p dvd content (f * g)" "prime p" by blast |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5801 |
from \<open>p dvd content (f * g)\<close> have "[:p:] dvd f * g" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5802 |
by (simp add: const_poly_dvd_iff_dvd_content) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5803 |
moreover from \<open>prime p\<close> have "prime_elem [:p:]" by (simp add: lift_prime_elem_poly) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5804 |
ultimately have "[:p:] dvd f \<or> [:p:] dvd g" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5805 |
by (simp add: prime_elem_dvd_mult_iff) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5806 |
with assms have "is_unit p" by (simp add: const_poly_dvd_iff_dvd_content) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5807 |
with \<open>prime p\<close> have False by simp |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5808 |
} |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5809 |
hence "is_unit (content (f * g))" by blast |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5810 |
hence "normalize (content (f * g)) = 1" by (simp add: is_unit_normalize del: normalize_content) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5811 |
thus ?thesis by simp |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5812 |
qed (insert assms, auto) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5813 |
|
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5814 |
lemma content_mult: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5815 |
fixes p q :: "'a :: {factorial_semiring, semiring_gcd, normalization_semidom_multiplicative} poly"
|
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5816 |
shows "content (p * q) = content p * content q" |
|
68790
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5817 |
proof (cases "p * q = 0") |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5818 |
case False |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5819 |
then have "p \<noteq> 0" and "q \<noteq> 0" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5820 |
by simp_all |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5821 |
then have *: "content (primitive_part p * primitive_part q) = 1" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5822 |
by (auto intro: content_1_mult) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5823 |
have "p * q = smult (content p) (primitive_part p) * smult (content q) (primitive_part q)" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5824 |
by simp |
|
68790
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5825 |
also have "\<dots> = smult (content p * content q) (primitive_part p * primitive_part q)" |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5826 |
by (metis mult.commute mult_smult_right smult_smult) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5827 |
with * show ?thesis |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5828 |
by (simp add: normalize_mult) |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5829 |
next |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5830 |
case True |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5831 |
then show ?thesis |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5832 |
by auto |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5833 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5834 |
|
|
68790
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5835 |
end |
|
851a9d9746c6
prefer constructive primitive_part over implicit content_decompose
haftmann
parents:
68534
diff
changeset
|
5836 |
|
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5837 |
lemma primitive_part_mult: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5838 |
fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide,
|
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5839 |
normalization_semidom_multiplicative} poly" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5840 |
shows "primitive_part (p * q) = primitive_part p * primitive_part q" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5841 |
proof - |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5842 |
have "primitive_part (p * q) = p * q div [:content (p * q):]" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5843 |
by (simp add: primitive_part_def div_const_poly_conv_map_poly) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5844 |
also have "\<dots> = (p div [:content p:]) * (q div [:content q:])" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5845 |
by (subst div_mult_div_if_dvd) (simp_all add: content_mult mult_ac) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5846 |
also have "\<dots> = primitive_part p * primitive_part q" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5847 |
by (simp add: primitive_part_def div_const_poly_conv_map_poly) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5848 |
finally show ?thesis . |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5849 |
qed |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5850 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5851 |
lemma primitive_part_smult: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5852 |
fixes p :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide,
|
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5853 |
normalization_semidom_multiplicative} poly" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5854 |
shows "primitive_part (smult a p) = smult (unit_factor a) (primitive_part p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5855 |
proof - |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5856 |
have "smult a p = [:a:] * p" by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5857 |
also have "primitive_part \<dots> = smult (unit_factor a) (primitive_part p)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5858 |
by (subst primitive_part_mult) simp_all |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5859 |
finally show ?thesis . |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
5860 |
qed |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5861 |
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5862 |
lemma primitive_part_dvd_primitive_partI [intro]: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5863 |
fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide,
|
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5864 |
normalization_semidom_multiplicative} poly" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5865 |
shows "p dvd q \<Longrightarrow> primitive_part p dvd primitive_part q" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5866 |
by (auto elim!: dvdE simp: primitive_part_mult) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5867 |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
5868 |
lemma content_prod_mset: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5869 |
fixes A :: "'a :: {factorial_semiring, semiring_Gcd, normalization_semidom_multiplicative}
|
|
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5870 |
poly multiset" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5871 |
shows "content (prod_mset A) = prod_mset (image_mset content A)" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5872 |
by (induction A) (simp_all add: content_mult mult_ac) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5873 |
|
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
5874 |
lemma content_prod_eq_1_iff: |
|
71398
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents:
70113
diff
changeset
|
5875 |
fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, normalization_semidom_multiplicative} poly"
|
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5876 |
shows "content (p * q) = 1 \<longleftrightarrow> content p = 1 \<and> content q = 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5877 |
proof safe |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5878 |
assume A: "content (p * q) = 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5879 |
{
|
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5880 |
fix p q :: "'a poly" assume "content p * content q = 1" |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5881 |
hence "1 = content p * content q" by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5882 |
hence "content p dvd 1" by (rule dvdI) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5883 |
hence "content p = 1" by simp |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5884 |
} note B = this |
|
73510
c526eb2c7ca0
removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents:
73114
diff
changeset
|
5885 |
from A B[of p q] B [of q p] show "content p = 1" "content q = 1" |
|
66805
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5886 |
by (simp_all add: content_mult mult_ac) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5887 |
qed (auto simp: content_mult) |
|
274b4edca859
Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents:
66799
diff
changeset
|
5888 |
|
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5889 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5890 |
subsection \<open>A typeclass for algebraically closed fields\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5891 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5892 |
(* TODO: Move! *) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5893 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5894 |
text \<open> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5895 |
Since the required sort constraints are not available inside the class, we have to resort |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5896 |
to a somewhat awkward way of writing the definition of algebraically closed fields: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5897 |
\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5898 |
class alg_closed_field = field + |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5899 |
assumes alg_closed: "n > 0 \<Longrightarrow> f n \<noteq> 0 \<Longrightarrow> \<exists>x. (\<Sum>k\<le>n. f k * x ^ k) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5900 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5901 |
text \<open> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5902 |
We can then however easily show the equivalence to the proper definition: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5903 |
\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5904 |
lemma alg_closed_imp_poly_has_root: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5905 |
assumes "degree (p :: 'a :: alg_closed_field poly) > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5906 |
shows "\<exists>x. poly p x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5907 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5908 |
have "\<exists>x. (\<Sum>k\<le>degree p. coeff p k * x ^ k) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5909 |
using assms by (intro alg_closed) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5910 |
thus ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5911 |
by (simp add: poly_altdef) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5912 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5913 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5914 |
lemma alg_closedI [Pure.intro]: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5915 |
assumes "\<And>p :: 'a poly. degree p > 0 \<Longrightarrow> lead_coeff p = 1 \<Longrightarrow> \<exists>x. poly p x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5916 |
shows "OFCLASS('a :: field, alg_closed_field_class)"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5917 |
proof |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5918 |
fix n :: nat and f :: "nat \<Rightarrow> 'a" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5919 |
assume n: "n > 0" "f n \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5920 |
define p where "p = Abs_poly (\<lambda>k. if k \<le> n then f k else 0)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5921 |
have coeff_p: "coeff p k = (if k \<le> n then f k else 0)" for k |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5922 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5923 |
have "eventually (\<lambda>k. k > n) cofinite" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5924 |
by (auto simp: MOST_nat) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5925 |
hence "eventually (\<lambda>k. (if k \<le> n then f k else 0) = 0) cofinite" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5926 |
by eventually_elim auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5927 |
thus ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5928 |
unfolding p_def by (subst Abs_poly_inverse) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5929 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5930 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5931 |
from n have "degree p \<ge> n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5932 |
by (intro le_degree) (auto simp: coeff_p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5933 |
moreover have "degree p \<le> n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5934 |
by (intro degree_le) (auto simp: coeff_p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5935 |
ultimately have deg_p: "degree p = n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5936 |
by linarith |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5937 |
from deg_p and n have [simp]: "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5938 |
by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5939 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5940 |
define p' where "p' = smult (inverse (lead_coeff p)) p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5941 |
have deg_p': "degree p' = degree p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5942 |
by (auto simp: p'_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5943 |
have lead_coeff_p' [simp]: "lead_coeff p' = 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5944 |
by (auto simp: p'_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5945 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5946 |
from deg_p and deg_p' and n have "degree p' > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5947 |
by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5948 |
from assms[OF this] obtain x where "poly p' x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5949 |
by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5950 |
hence "poly p x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5951 |
by (simp add: p'_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5952 |
also have "poly p x = (\<Sum>k\<le>n. f k * x ^ k)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5953 |
unfolding poly_altdef by (intro sum.cong) (auto simp: deg_p coeff_p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5954 |
finally show "\<exists>x. (\<Sum>k\<le>n. f k * x ^ k) = 0" .. |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5955 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5956 |
|
|
80084
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5957 |
lemma (in alg_closed_field) nth_root_exists: |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5958 |
assumes "n > 0" |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5959 |
shows "\<exists>y. y ^ n = (x :: 'a)" |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5960 |
proof - |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5961 |
define f where "f = (\<lambda>i. if i = 0 then -x else if i = n then 1 else 0)" |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5962 |
have "\<exists>x. (\<Sum>k\<le>n. f k * x ^ k) = 0" |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5963 |
by (rule alg_closed) (use assms in \<open>auto simp: f_def\<close>) |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5964 |
also have "(\<lambda>x. \<Sum>k\<le>n. f k * x ^ k) = (\<lambda>x. \<Sum>k\<in>{0,n}. f k * x ^ k)"
|
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5965 |
by (intro ext sum.mono_neutral_right) (auto simp: f_def) |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5966 |
finally show "\<exists>y. y ^ n = x" |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5967 |
using assms by (simp add: f_def) |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
80061
diff
changeset
|
5968 |
qed |
|
80061
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5969 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5970 |
text \<open> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5971 |
We can now prove by induction that every polynomial of degree \<open>n\<close> splits into a product of |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5972 |
\<open>n\<close> linear factors: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5973 |
\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5974 |
lemma alg_closed_imp_factorization: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5975 |
fixes p :: "'a :: alg_closed_field poly" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5976 |
assumes "p \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5977 |
shows "\<exists>A. size A = degree p \<and> p = smult (lead_coeff p) (\<Prod>x\<in>#A. [:-x, 1:])" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5978 |
using assms |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5979 |
proof (induction "degree p" arbitrary: p rule: less_induct) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5980 |
case (less p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5981 |
show ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5982 |
proof (cases "degree p = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5983 |
case True |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5984 |
thus ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5985 |
by (intro exI[of _ "{#}"]) (auto elim!: degree_eq_zeroE)
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5986 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5987 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5988 |
then obtain x where x: "poly p x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5989 |
using alg_closed_imp_poly_has_root by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5990 |
hence "[:-x, 1:] dvd p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5991 |
using poly_eq_0_iff_dvd by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5992 |
then obtain q where p_eq: "p = [:-x, 1:] * q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5993 |
by (elim dvdE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5994 |
have "q \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5995 |
using less.prems p_eq by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5996 |
moreover from this have deg: "degree p = Suc (degree q)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5997 |
unfolding p_eq by (subst degree_mult_eq) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5998 |
ultimately obtain A where A: "size A = degree q" "q = smult (lead_coeff q) (\<Prod>x\<in>#A. [:-x, 1:])" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
5999 |
using less.hyps[of q] by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6000 |
have "smult (lead_coeff p) (\<Prod>y\<in>#add_mset x A. [:- y, 1:]) = |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6001 |
[:- x, 1:] * smult (lead_coeff q) (\<Prod>y\<in>#A. [:- y, 1:])" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6002 |
unfolding p_eq lead_coeff_mult by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6003 |
also note A(2) [symmetric] |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6004 |
also note p_eq [symmetric] |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6005 |
finally show ?thesis using A(1) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6006 |
by (intro exI[of _ "add_mset x A"]) (auto simp: deg) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6007 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6008 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6009 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6010 |
text \<open> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6011 |
As an alternative characterisation of algebraic closure, one can also say that any |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6012 |
polynomial of degree at least 2 splits into non-constant factors: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6013 |
\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6014 |
lemma alg_closed_imp_reducible: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6015 |
assumes "degree (p :: 'a :: alg_closed_field poly) > 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6016 |
shows "\<not>irreducible p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6017 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6018 |
have "degree p > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6019 |
using assms by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6020 |
then obtain z where z: "poly p z = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6021 |
using alg_closed_imp_poly_has_root[of p] by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6022 |
then have dvd: "[:-z, 1:] dvd p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6023 |
by (subst dvd_iff_poly_eq_0) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6024 |
then obtain q where q: "p = [:-z, 1:] * q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6025 |
by (erule dvdE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6026 |
have [simp]: "q \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6027 |
using assms q by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6028 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6029 |
show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6030 |
proof (rule reducible_polyI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6031 |
show "p = [:-z, 1:] * q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6032 |
by fact |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6033 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6034 |
have "degree p = degree ([:-z, 1:] * q)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6035 |
by (simp only: q) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6036 |
also have "\<dots> = degree q + 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6037 |
by (subst degree_mult_eq) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6038 |
finally show "degree q > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6039 |
using assms by linarith |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6040 |
qed auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6041 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6042 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6043 |
text \<open> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6044 |
When proving algebraic closure through reducibility, we can assume w.l.o.g. that the polynomial |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6045 |
is monic and has a non-zero constant coefficient: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6046 |
\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6047 |
lemma alg_closedI_reducible: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6048 |
assumes "\<And>p :: 'a poly. degree p > 1 \<Longrightarrow> lead_coeff p = 1 \<Longrightarrow> coeff p 0 \<noteq> 0 \<Longrightarrow> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6049 |
\<not>irreducible p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6050 |
shows "OFCLASS('a :: field, alg_closed_field_class)"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6051 |
proof |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6052 |
fix p :: "'a poly" assume p: "degree p > 0" "lead_coeff p = 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6053 |
show "\<exists>x. poly p x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6054 |
proof (cases "coeff p 0 = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6055 |
case True |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6056 |
hence "poly p 0 = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6057 |
by (simp add: poly_0_coeff_0) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6058 |
thus ?thesis by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6059 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6060 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6061 |
from p and this show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6062 |
proof (induction "degree p" arbitrary: p rule: less_induct) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6063 |
case (less p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6064 |
show ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6065 |
proof (cases "degree p = 1") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6066 |
case True |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6067 |
then obtain a b where p: "p = [:a, b:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6068 |
by (cases p) (auto split: if_splits elim!: degree_eq_zeroE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6069 |
from True have [simp]: "b \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6070 |
by (auto simp: p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6071 |
have "poly p (-a/b) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6072 |
by (auto simp: p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6073 |
thus ?thesis by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6074 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6075 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6076 |
hence "degree p > 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6077 |
using less.prems by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6078 |
from assms[OF \<open>degree p > 1\<close> \<open>lead_coeff p = 1\<close> \<open>coeff p 0 \<noteq> 0\<close>] |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6079 |
have "\<not>irreducible p" by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6080 |
then obtain r s where rs: "degree r > 0" "degree s > 0" "p = r * s" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6081 |
using less.prems unfolding irreducible_def |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6082 |
by (metis is_unit_iff_degree mult_not_zero zero_less_iff_neq_zero) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6083 |
hence "coeff r 0 \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6084 |
using \<open>coeff p 0 \<noteq> 0\<close> by (auto simp: coeff_mult_0) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6085 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6086 |
define r' where "r' = smult (inverse (lead_coeff r)) r" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6087 |
have [simp]: "degree r' = degree r" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6088 |
by (simp add: r'_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6089 |
have lc: "lead_coeff r' = 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6090 |
using rs by (auto simp: r'_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6091 |
have nz: "coeff r' 0 \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6092 |
using \<open>coeff r 0 \<noteq> 0\<close> by (auto simp: r'_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6093 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6094 |
have "degree r < degree r + degree s" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6095 |
using rs by linarith |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6096 |
also have "\<dots> = degree (r * s)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6097 |
using rs(3) less.prems by (subst degree_mult_eq) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6098 |
also have "r * s = p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6099 |
using rs(3) by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6100 |
finally have "\<exists>x. poly r' x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6101 |
by (intro less) (use lc rs nz in auto) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6102 |
thus ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6103 |
using rs(3) by (auto simp: r'_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6104 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6105 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6106 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6107 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6108 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6109 |
text \<open> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6110 |
Using a clever Tschirnhausen transformation mentioned e.g. in the article by |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6111 |
Nowak~\<^cite>\<open>"nowak2000"\<close>, we can also assume w.l.o.g. that the coefficient $a_{n-1}$ is zero.
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6112 |
\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6113 |
lemma alg_closedI_reducible_coeff_deg_minus_one_eq_0: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6114 |
assumes "\<And>p :: 'a poly. degree p > 1 \<Longrightarrow> lead_coeff p = 1 \<Longrightarrow> coeff p (degree p - 1) = 0 \<Longrightarrow> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6115 |
coeff p 0 \<noteq> 0 \<Longrightarrow> \<not>irreducible p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6116 |
shows "OFCLASS('a :: field_char_0, alg_closed_field_class)"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6117 |
proof (rule alg_closedI_reducible, goal_cases) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6118 |
case (1 p) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6119 |
define n where [simp]: "n = degree p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6120 |
define a where "a = coeff p (n - 1)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6121 |
define r where "r = [: -a / of_nat n, 1 :]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6122 |
define s where "s = [: a / of_nat n, 1 :]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6123 |
define q where "q = pcompose p r" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6124 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6125 |
have "n > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6126 |
using 1 by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6127 |
have r_altdef: "r = monom 1 1 + [:-a / of_nat n:]" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6128 |
by (simp add: r_def monom_altdef) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6129 |
have deg_q: "degree q = n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6130 |
by (simp add: q_def r_def degree_pcompose) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6131 |
have lc_q: "lead_coeff q = 1" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6132 |
unfolding q_def using 1 by (subst lead_coeff_comp) (simp_all add: r_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6133 |
have "q \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6134 |
using 1 deg_q by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6135 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6136 |
have "coeff q (n - 1) = |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6137 |
(\<Sum>i\<le>n. \<Sum>k\<le>i. coeff p i * (of_nat (i choose k) * |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6138 |
((-a / of_nat n) ^ (i - k) * (if k = n - 1 then 1 else 0))))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6139 |
unfolding q_def pcompose_altdef poly_altdef r_altdef |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6140 |
by (simp_all add: degree_map_poly coeff_map_poly coeff_sum binomial_ring sum_distrib_left poly_const_pow |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6141 |
sum_distrib_right mult_ac monom_power coeff_monom_mult of_nat_poly cong: if_cong) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6142 |
also have "\<dots> = (\<Sum>i\<le>n. \<Sum>k\<in>(if i \<ge> n - 1 then {n-1} else {}).
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6143 |
coeff p i * (of_nat (i choose k) * (-a / of_nat n) ^ (i - k)))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6144 |
by (rule sum.cong [OF refl], rule sum.mono_neutral_cong_right) (auto split: if_splits) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6145 |
also have "\<dots> = (\<Sum>i\<in>{n-1,n}. \<Sum>k\<in>(if i \<ge> n - 1 then {n-1} else {}).
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6146 |
coeff p i * (of_nat (i choose k) * (-a / of_nat n) ^ (i - k)))" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6147 |
by (rule sum.mono_neutral_right) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6148 |
also have "\<dots> = a - of_nat (n choose (n - 1)) * a / of_nat n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6149 |
using 1 by (simp add: a_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6150 |
also have "n choose (n - 1) = n" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6151 |
using \<open>n > 0\<close> by (subst binomial_symmetric) auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6152 |
also have "a - of_nat n * a / of_nat n = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6153 |
using \<open>n > 0\<close> by simp |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6154 |
finally have "coeff q (n - 1) = 0" . |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6155 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6156 |
show ?case |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6157 |
proof (cases "coeff q 0 = 0") |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6158 |
case True |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6159 |
hence "poly p (- (a / of_nat (degree p))) = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6160 |
by (auto simp: q_def r_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6161 |
thus ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6162 |
by (rule root_imp_reducible_poly) (use 1 in auto) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6163 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6164 |
case False |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6165 |
hence "\<not>irreducible q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6166 |
using assms[of q] and lc_q and 1 and \<open>coeff q (n - 1) = 0\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6167 |
by (auto simp: deg_q) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6168 |
then obtain u v where uv: "degree u > 0" "degree v > 0" "q = u * v" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6169 |
using \<open>q \<noteq> 0\<close> 1 deg_q unfolding irreducible_def |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6170 |
by (metis degree_mult_eq_0 is_unit_iff_degree n_def neq0_conv not_one_less_zero) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6171 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6172 |
have "p = pcompose q s" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6173 |
by (simp add: q_def r_def s_def pcompose_pCons flip: pcompose_assoc) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6174 |
also have "q = u * v" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6175 |
by fact |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6176 |
finally have "p = pcompose u s * pcompose v s" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6177 |
by (simp add: pcompose_mult) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6178 |
moreover have "degree (pcompose u s) > 0" "degree (pcompose v s) > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6179 |
using uv by (simp_all add: s_def degree_pcompose) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6180 |
ultimately show "\<not>irreducible p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6181 |
using 1 by (intro reducible_polyI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6182 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6183 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6184 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6185 |
text \<open> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6186 |
As a consequence of the full factorisation lemma proven above, we can also show that any |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6187 |
polynomial with at least two different roots splits into two non-constant coprime factors: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6188 |
\<close> |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6189 |
lemma alg_closed_imp_poly_splits_coprime: |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6190 |
assumes "degree (p :: 'a :: {alg_closed_field} poly) > 1"
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6191 |
assumes "poly p x = 0" "poly p y = 0" "x \<noteq> y" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6192 |
obtains r s where "degree r > 0" "degree s > 0" "coprime r s" "p = r * s" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6193 |
proof - |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6194 |
define n where "n = order x p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6195 |
have "n > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6196 |
using assms by (metis degree_0 gr0I n_def not_one_less_zero order_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6197 |
have "[:-x, 1:] ^ n dvd p" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6198 |
unfolding n_def by (simp add: order_1) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6199 |
then obtain q where p_eq: "p = [:-x, 1:] ^ n * q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6200 |
by (elim dvdE) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6201 |
from assms have [simp]: "q \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6202 |
by (auto simp: p_eq) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6203 |
have "order x p = n + Polynomial.order x q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6204 |
unfolding p_eq by (subst order_mult) (auto simp: order_power_n_n) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6205 |
hence "Polynomial.order x q = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6206 |
by (simp add: n_def) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6207 |
hence "poly q x \<noteq> 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6208 |
by (simp add: order_root) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6209 |
|
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6210 |
show ?thesis |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6211 |
proof (rule that) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6212 |
show "coprime ([:-x, 1:] ^ n) q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6213 |
proof (rule coprimeI) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6214 |
fix d |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6215 |
assume d: "d dvd [:-x, 1:] ^ n" "d dvd q" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6216 |
have "degree d = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6217 |
proof (rule ccontr) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6218 |
assume "\<not>(degree d = 0)" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6219 |
then obtain z where z: "poly d z = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6220 |
using alg_closed_imp_poly_has_root by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6221 |
moreover from this and d(1) have "poly ([:-x, 1:] ^ n) z = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6222 |
using dvd_trans poly_eq_0_iff_dvd by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6223 |
ultimately have "poly d x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6224 |
by auto |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6225 |
with d(2) have "poly q x = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6226 |
using dvd_trans poly_eq_0_iff_dvd by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6227 |
with \<open>poly q x \<noteq> 0\<close> show False by contradiction |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6228 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6229 |
thus "is_unit d" using d |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6230 |
by (metis \<open>q \<noteq> 0\<close> dvd_0_left is_unit_iff_degree) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6231 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6232 |
next |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6233 |
have "poly q y = 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6234 |
using \<open>poly p y = 0\<close> \<open>x \<noteq> y\<close> by (auto simp: p_eq) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6235 |
with \<open>q \<noteq> 0\<close> show "degree q > 0" |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6236 |
using order_degree order_gt_0_iff order_less_le_trans by blast |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6237 |
qed (use \<open>n > 0\<close> in \<open>simp_all add: p_eq degree_power_eq\<close>) |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6238 |
qed |
|
4c1347e172b1
moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents:
79672
diff
changeset
|
6239 |
|
|
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80786
diff
changeset
|
6240 |
no_notation cCons (infixr \<open>##\<close> 65) |
| 31663 | 6241 |
|
| 29478 | 6242 |
end |