| author | nipkow | 
| Sun, 22 Feb 2009 17:25:28 +0100 | |
| changeset 30056 | 0a35bee25c20 | 
| parent 27214 | 0978b8e32fd0 | 
| child 30968 | 10fef94f40fc | 
| permissions | -rw-r--r-- | 
| 7998 | 1  | 
(*  | 
2  | 
Experimental theory: long division of polynomials  | 
|
3  | 
$Id$  | 
|
4  | 
Author: Clemens Ballarin, started 23 June 1999  | 
|
5  | 
*)  | 
|
6  | 
||
| 16417 | 7  | 
theory LongDiv imports PolyHomo begin  | 
| 7998 | 8  | 
|
| 21423 | 9  | 
definition  | 
10  | 
lcoeff :: "'a::ring up => 'a" where  | 
|
11  | 
"lcoeff p = coeff p (deg p)"  | 
|
| 7998 | 12  | 
|
| 21423 | 13  | 
definition  | 
14  | 
eucl_size :: "'a::zero up => nat" where  | 
|
15  | 
"eucl_size p = (if p = 0 then 0 else deg p + 1)"  | 
|
| 14723 | 16  | 
|
17  | 
lemma SUM_shrink_below_lemma:  | 
|
18  | 
"!! f::(nat=>'a::ring). (ALL i. i < m --> f i = 0) -->  | 
|
19  | 
  setsum (%i. f (i+m)) {..d} = setsum f {..m+d}"
 | 
|
20  | 
apply (induct_tac d)  | 
|
| 15481 | 21  | 
apply (induct_tac m)  | 
| 21423 | 22  | 
apply simp  | 
23  | 
apply force  | 
|
| 
22384
 
33a46e6c7f04
prefix of class interpretation not mandatory any longer
 
haftmann 
parents: 
21423 
diff
changeset
 | 
24  | 
apply (simp add: add_commute [of m])  | 
| 21423 | 25  | 
done  | 
26  | 
||
27  | 
lemma SUM_extend_below:  | 
|
28  | 
"!! f::(nat=>'a::ring).  | 
|
29  | 
     [| m <= n; !!i. i < m ==> f i = 0; P (setsum (%i. f (i+m)) {..n-m}) |]  
 | 
|
30  | 
     ==> P (setsum f {..n})"
 | 
|
31  | 
by (simp add: SUM_shrink_below_lemma add_diff_inverse leD)  | 
|
32  | 
||
33  | 
lemma up_repr2D:  | 
|
34  | 
"!! p::'a::ring up.  | 
|
35  | 
   [| deg p <= n; P (setsum (%i. monom (coeff p i) i) {..n}) |]  
 | 
|
36  | 
==> P p"  | 
|
37  | 
by (simp add: up_repr_le)  | 
|
38  | 
||
39  | 
||
40  | 
(* Start of LongDiv *)  | 
|
41  | 
||
42  | 
lemma deg_lcoeff_cancel:  | 
|
43  | 
  "!!p::('a::ring up).  
 | 
|
44  | 
[| deg p <= deg r; deg q <= deg r;  | 
|
45  | 
coeff p (deg r) = - (coeff q (deg r)); deg r ~= 0 |] ==>  | 
|
46  | 
deg (p + q) < deg r"  | 
|
| 
24742
 
73b8b42a36b6
removal of some "ref"s from res_axioms.ML; a side-effect is that the ordering
 
paulson 
parents: 
22384 
diff
changeset
 | 
47  | 
apply (rule le_less_trans [of _ "deg r - 1"])  | 
| 21423 | 48  | 
prefer 2  | 
49  | 
apply arith  | 
|
50  | 
apply (rule deg_aboveI)  | 
|
51  | 
apply (case_tac "deg r = m")  | 
|
52  | 
apply clarify  | 
|
53  | 
apply simp  | 
|
54  | 
(* case "deg q ~= m" *)  | 
|
55  | 
apply (subgoal_tac "deg p < m & deg q < m")  | 
|
56  | 
apply (simp (no_asm_simp) add: deg_aboveD)  | 
|
57  | 
apply arith  | 
|
58  | 
done  | 
|
59  | 
||
60  | 
lemma deg_lcoeff_cancel2:  | 
|
61  | 
  "!!p::('a::ring up).  
 | 
|
62  | 
[| deg p <= deg r; deg q <= deg r;  | 
|
63  | 
p ~= -q; coeff p (deg r) = - (coeff q (deg r)) |] ==>  | 
|
64  | 
deg (p + q) < deg r"  | 
|
65  | 
apply (rule deg_lcoeff_cancel)  | 
|
66  | 
apply assumption+  | 
|
67  | 
apply (rule classical)  | 
|
68  | 
apply clarify  | 
|
69  | 
apply (erule notE)  | 
|
70  | 
apply (rule_tac p = p in up_repr2D, assumption)  | 
|
71  | 
apply (rule_tac p = q in up_repr2D, assumption)  | 
|
72  | 
apply (rotate_tac -1)  | 
|
73  | 
apply (simp add: smult_l_minus)  | 
|
74  | 
done  | 
|
75  | 
||
76  | 
lemma long_div_eucl_size:  | 
|
77  | 
  "!!g::('a::ring up). g ~= 0 ==>  
 | 
|
78  | 
Ex (% (q, r, k).  | 
|
79  | 
(lcoeff g)^k *s f = q * g + r & (eucl_size r < eucl_size g))"  | 
|
80  | 
apply (rule_tac P = "%f. Ex (% (q, r, k) . (lcoeff g) ^k *s f = q * g + r & (eucl_size r < eucl_size g))" in wf_induct)  | 
|
81  | 
(* TO DO: replace by measure_induct *)  | 
|
82  | 
apply (rule_tac f = eucl_size in wf_measure)  | 
|
83  | 
apply (case_tac "eucl_size x < eucl_size g")  | 
|
84  | 
apply (rule_tac x = "(0, x, 0)" in exI)  | 
|
85  | 
apply (simp (no_asm_simp))  | 
|
86  | 
(* case "eucl_size x >= eucl_size g" *)  | 
|
87  | 
apply (drule_tac x = "lcoeff g *s x - (monom (lcoeff x) (deg x - deg g)) * g" in spec)  | 
|
88  | 
apply (erule impE)  | 
|
89  | 
apply (simp (no_asm_use) add: inv_image_def measure_def lcoeff_def)  | 
|
90  | 
apply (case_tac "x = 0")  | 
|
91  | 
apply (rotate_tac -1)  | 
|
92  | 
apply (simp add: eucl_size_def)  | 
|
93  | 
(* case "x ~= 0 *)  | 
|
94  | 
apply (rotate_tac -1)  | 
|
95  | 
apply (simp add: eucl_size_def)  | 
|
96  | 
apply (rule impI)  | 
|
97  | 
apply (rule deg_lcoeff_cancel2)  | 
|
98  | 
(* replace by linear arithmetic??? *)  | 
|
99  | 
apply (rule_tac [2] le_trans)  | 
|
100  | 
apply (rule_tac [2] deg_smult_ring)  | 
|
101  | 
prefer 2  | 
|
102  | 
apply simp  | 
|
103  | 
apply (simp (no_asm))  | 
|
104  | 
apply (rule le_trans)  | 
|
105  | 
apply (rule deg_mult_ring)  | 
|
106  | 
apply (rule le_trans)  | 
|
107  | 
(**)  | 
|
108  | 
apply (rule add_le_mono)  | 
|
109  | 
apply (rule le_refl)  | 
|
110  | 
(* term order forces to use this instead of add_le_mono1 *)  | 
|
111  | 
apply (rule deg_monom_ring)  | 
|
112  | 
apply (simp (no_asm_simp))  | 
|
113  | 
apply force  | 
|
114  | 
apply (simp (no_asm))  | 
|
115  | 
(**)  | 
|
116  | 
(* This change is probably caused by application of commutativity *)  | 
|
117  | 
apply (rule_tac m = "deg g" and n = "deg x" in SUM_extend)  | 
|
118  | 
apply (simp (no_asm))  | 
|
119  | 
apply (simp (no_asm_simp))  | 
|
120  | 
apply arith  | 
|
121  | 
apply (rule_tac m = "deg g" and n = "deg g" in SUM_extend_below)  | 
|
122  | 
apply (rule le_refl)  | 
|
123  | 
apply (simp (no_asm_simp))  | 
|
124  | 
apply arith  | 
|
125  | 
apply (simp (no_asm))  | 
|
126  | 
(**)  | 
|
127  | 
(* end of subproof deg f1 < deg f *)  | 
|
128  | 
apply (erule exE)  | 
|
129  | 
apply (rule_tac x = "((% (q,r,k) . (monom (lcoeff g ^ k * lcoeff x) (deg x - deg g) + q)) xa, (% (q,r,k) . r) xa, (% (q,r,k) . Suc k) xa) " in exI)  | 
|
130  | 
apply clarify  | 
|
131  | 
apply (drule sym)  | 
|
| 26342 | 132  | 
  apply (tactic {* simp_tac (@{simpset} addsimps [@{thm l_distr}, @{thm a_assoc}]
 | 
| 21423 | 133  | 
delsimprocs [ring_simproc]) 1 *})  | 
| 26342 | 134  | 
  apply (tactic {* asm_simp_tac (@{simpset} delsimprocs [ring_simproc]) 1 *})
 | 
135  | 
  apply (tactic {* simp_tac (@{simpset} addsimps [thm "minus_def", thm "smult_r_distr",
 | 
|
| 21423 | 136  | 
thm "smult_r_minus", thm "monom_mult_smult", thm "smult_assoc1", thm "smult_assoc2"]  | 
137  | 
delsimprocs [ring_simproc]) 1 *})  | 
|
138  | 
apply simp  | 
|
139  | 
done  | 
|
140  | 
||
| 27214 | 141  | 
ML {*
 | 
142  | 
 bind_thm ("long_div_ring_aux",
 | 
|
143  | 
    simplify (@{simpset} addsimps [@{thm eucl_size_def}]
 | 
|
144  | 
    delsimprocs [ring_simproc]) (@{thm long_div_eucl_size}))
 | 
|
145  | 
*}  | 
|
| 21423 | 146  | 
|
147  | 
lemma long_div_ring:  | 
|
148  | 
  "!!g::('a::ring up). g ~= 0 ==>  
 | 
|
149  | 
Ex (% (q, r, k).  | 
|
150  | 
(lcoeff g)^k *s f = q * g + r & (r = 0 | deg r < deg g))"  | 
|
| 27214 | 151  | 
apply (frule_tac f = f in long_div_ring_aux)  | 
| 26342 | 152  | 
  apply (tactic {* auto_tac (@{claset}, @{simpset} delsimprocs [ring_simproc]) *})
 | 
| 21423 | 153  | 
apply (case_tac "aa = 0")  | 
154  | 
apply blast  | 
|
155  | 
(* case "aa ~= 0 *)  | 
|
156  | 
apply (rotate_tac -1)  | 
|
157  | 
apply auto  | 
|
158  | 
done  | 
|
159  | 
||
160  | 
(* Next one fails *)  | 
|
161  | 
lemma long_div_unit:  | 
|
162  | 
  "!!g::('a::ring up). [| g ~= 0; (lcoeff g) dvd 1 |] ==>  
 | 
|
163  | 
Ex (% (q, r). f = q * g + r & (r = 0 | deg r < deg g))"  | 
|
164  | 
apply (frule_tac f = "f" in long_div_ring)  | 
|
165  | 
apply (erule exE)  | 
|
166  | 
apply (rule_tac x = "((% (q,r,k) . (inverse (lcoeff g ^k) *s q)) x, (% (q,r,k) . inverse (lcoeff g ^k) *s r) x) " in exI)  | 
|
167  | 
apply clarify  | 
|
168  | 
apply (rule conjI)  | 
|
169  | 
apply (drule sym)  | 
|
170  | 
   apply (tactic {* asm_simp_tac
 | 
|
| 26342 | 171  | 
     (@{simpset} addsimps [thm "smult_r_distr" RS sym, thm "smult_assoc2"]
 | 
| 21423 | 172  | 
delsimprocs [ring_simproc]) 1 *})  | 
173  | 
apply (simp (no_asm_simp) add: l_inverse_ring unit_power smult_assoc1 [symmetric])  | 
|
174  | 
(* degree property *)  | 
|
175  | 
apply (erule disjE)  | 
|
176  | 
apply (simp (no_asm_simp))  | 
|
177  | 
apply (rule disjI2)  | 
|
178  | 
apply (rule le_less_trans)  | 
|
179  | 
apply (rule deg_smult_ring)  | 
|
180  | 
apply (simp (no_asm_simp))  | 
|
181  | 
done  | 
|
182  | 
||
183  | 
lemma long_div_theorem:  | 
|
184  | 
  "!!g::('a::field up). g ~= 0 ==>  
 | 
|
185  | 
Ex (% (q, r). f = q * g + r & (r = 0 | deg r < deg g))"  | 
|
186  | 
apply (rule long_div_unit)  | 
|
187  | 
apply assumption  | 
|
188  | 
apply (simp (no_asm_simp) add: lcoeff_def lcoeff_nonzero field_ax)  | 
|
189  | 
done  | 
|
190  | 
||
191  | 
lemma uminus_zero: "- (0::'a::ring) = 0"  | 
|
192  | 
by simp  | 
|
193  | 
||
194  | 
lemma diff_zero_imp_eq: "!!a::'a::ring. a - b = 0 ==> a = b"  | 
|
195  | 
apply (rule_tac s = "a - (a - b) " in trans)  | 
|
| 26342 | 196  | 
   apply (tactic {* asm_simp_tac (@{simpset} delsimprocs [ring_simproc]) 1 *})
 | 
| 21423 | 197  | 
apply simp  | 
198  | 
apply (simp (no_asm))  | 
|
199  | 
done  | 
|
200  | 
||
201  | 
lemma eq_imp_diff_zero: "!!a::'a::ring. a = b ==> a + (-b) = 0"  | 
|
202  | 
by simp  | 
|
203  | 
||
204  | 
lemma long_div_quo_unique:  | 
|
205  | 
  "!!g::('a::field up). [| g ~= 0;  
 | 
|
206  | 
f = q1 * g + r1; (r1 = 0 | deg r1 < deg g);  | 
|
207  | 
f = q2 * g + r2; (r2 = 0 | deg r2 < deg g) |] ==> q1 = q2"  | 
|
208  | 
apply (subgoal_tac "(q1 - q2) * g = r2 - r1") (* 1 *)  | 
|
209  | 
apply (erule_tac V = "f = ?x" in thin_rl)  | 
|
210  | 
apply (erule_tac V = "f = ?x" in thin_rl)  | 
|
211  | 
apply (rule diff_zero_imp_eq)  | 
|
212  | 
apply (rule classical)  | 
|
213  | 
apply (erule disjE)  | 
|
214  | 
(* r1 = 0 *)  | 
|
215  | 
apply (erule disjE)  | 
|
216  | 
(* r2 = 0 *)  | 
|
| 26342 | 217  | 
     apply (tactic {* asm_full_simp_tac (@{simpset}
 | 
| 21423 | 218  | 
addsimps [thm "integral_iff", thm "minus_def", thm "l_zero", thm "uminus_zero"]  | 
219  | 
delsimprocs [ring_simproc]) 1 *})  | 
|
220  | 
(* r2 ~= 0 *)  | 
|
221  | 
apply (drule_tac f = "deg" and y = "r2 - r1" in arg_cong)  | 
|
| 26342 | 222  | 
    apply (tactic {* asm_full_simp_tac (@{simpset} addsimps
 | 
| 21423 | 223  | 
[thm "minus_def", thm "l_zero", thm "uminus_zero"] delsimprocs [ring_simproc]) 1 *})  | 
224  | 
(* r1 ~=0 *)  | 
|
225  | 
apply (erule disjE)  | 
|
226  | 
(* r2 = 0 *)  | 
|
227  | 
apply (drule_tac f = "deg" and y = "r2 - r1" in arg_cong)  | 
|
| 26342 | 228  | 
    apply (tactic {* asm_full_simp_tac (@{simpset} addsimps
 | 
| 21423 | 229  | 
[thm "minus_def", thm "l_zero", thm "uminus_zero"] delsimprocs [ring_simproc]) 1 *})  | 
230  | 
(* r2 ~= 0 *)  | 
|
231  | 
apply (drule_tac f = "deg" and y = "r2 - r1" in arg_cong)  | 
|
| 26342 | 232  | 
   apply (tactic {* asm_full_simp_tac (@{simpset} addsimps [thm "minus_def"]
 | 
| 21423 | 233  | 
delsimprocs [ring_simproc]) 1 *})  | 
234  | 
apply (drule order_eq_refl [THEN add_leD2])  | 
|
235  | 
apply (drule leD)  | 
|
236  | 
apply (erule notE, rule deg_add [THEN le_less_trans])  | 
|
237  | 
apply (simp (no_asm_simp))  | 
|
238  | 
(* proof of 1 *)  | 
|
239  | 
apply (rule diff_zero_imp_eq)  | 
|
240  | 
apply hypsubst  | 
|
241  | 
apply (drule_tac a = "?x+?y" in eq_imp_diff_zero)  | 
|
242  | 
apply simp  | 
|
243  | 
done  | 
|
244  | 
||
245  | 
lemma long_div_rem_unique:  | 
|
246  | 
  "!!g::('a::field up). [| g ~= 0;  
 | 
|
247  | 
f = q1 * g + r1; (r1 = 0 | deg r1 < deg g);  | 
|
248  | 
f = q2 * g + r2; (r2 = 0 | deg r2 < deg g) |] ==> r1 = r2"  | 
|
249  | 
apply (subgoal_tac "q1 = q2")  | 
|
| 
24742
 
73b8b42a36b6
removal of some "ref"s from res_axioms.ML; a side-effect is that the ordering
 
paulson 
parents: 
22384 
diff
changeset
 | 
250  | 
apply (metis a_comm a_lcancel m_comm)  | 
| 
 
73b8b42a36b6
removal of some "ref"s from res_axioms.ML; a side-effect is that the ordering
 
paulson 
parents: 
22384 
diff
changeset
 | 
251  | 
apply (metis a_comm l_zero long_div_quo_unique m_comm conc)  | 
| 14723 | 252  | 
done  | 
| 7998 | 253  | 
|
254  | 
end  |