forked from ctraut/Taylor-Models-Isabelle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneric_Multivariate_Polynomials.thy
More file actions
2163 lines (1936 loc) · 79.5 KB
/
Copy pathGeneric_Multivariate_Polynomials.thy
File metadata and controls
2163 lines (1936 loc) · 79.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* Title: Multivariate_Polynomial.thy
Author: Amine Chaieb
Modified by Christoph Traut to work on the most general type possible, for the use in Taylor models.
*)
section \<open>Implementation and verification of multivariate polynomials\<close>
theory Generic_Multivariate_Polynomials
imports Complex_Main
"~~/src/HOL/Decision_Procs/Rat_Pair"
"~~/src/HOL/Decision_Procs/Polynomial_List"
"~~/src/HOL/Library/Float"
begin
subsection \<open>Datatype of polynomial expressions\<close>
datatype 'a poly = C 'a | Bound nat | Add "'a poly" "'a poly" | Sub "'a poly" "'a poly"
| Mul "'a poly" "'a poly"| Neg "'a poly"| Pw "'a poly" nat | CN "'a poly" nat "'a poly"
abbreviation poly_0 :: "'a::zero poly" ("0\<^sub>p") where "0\<^sub>p \<equiv> C 0"
abbreviation poly_p :: "'a \<Rightarrow> 'a poly" ("'((_)')\<^sub>p") where "(i)\<^sub>p \<equiv> C i"
subsection\<open>Boundedness, substitution and all that\<close>
primrec polysize:: "'a poly \<Rightarrow> nat"
where
"polysize (C c) = 1"
| "polysize (Bound n) = 1"
| "polysize (Neg p) = 1 + polysize p"
| "polysize (Add p q) = 1 + polysize p + polysize q"
| "polysize (Sub p q) = 1 + polysize p + polysize q"
| "polysize (Mul p q) = 1 + polysize p + polysize q"
| "polysize (Pw p n) = 1 + polysize p"
| "polysize (CN c n p) = 4 + polysize c + polysize p"
primrec polybound0:: "'a poly \<Rightarrow> bool" -- \<open>a poly is INDEPENDENT of Bound 0\<close>
where
"polybound0 (C c) \<longleftrightarrow> True"
| "polybound0 (Bound n) \<longleftrightarrow> n > 0"
| "polybound0 (Neg a) \<longleftrightarrow> polybound0 a"
| "polybound0 (Add a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
| "polybound0 (Sub a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
| "polybound0 (Mul a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
| "polybound0 (Pw p n) \<longleftrightarrow> polybound0 p"
| "polybound0 (CN c n p) \<longleftrightarrow> n \<noteq> 0 \<and> polybound0 c \<and> polybound0 p"
primrec polysubst0:: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" -- \<open>substitute a poly into a poly for Bound 0\<close>
where
"polysubst0 t (C c) = C c"
| "polysubst0 t (Bound n) = (if n = 0 then t else Bound n)"
| "polysubst0 t (Neg a) = Neg (polysubst0 t a)"
| "polysubst0 t (Add a b) = Add (polysubst0 t a) (polysubst0 t b)"
| "polysubst0 t (Sub a b) = Sub (polysubst0 t a) (polysubst0 t b)"
| "polysubst0 t (Mul a b) = Mul (polysubst0 t a) (polysubst0 t b)"
| "polysubst0 t (Pw p n) = Pw (polysubst0 t p) n"
| "polysubst0 t (CN c n p) =
(if n = 0 then Add (polysubst0 t c) (Mul t (polysubst0 t p))
else CN (polysubst0 t c) n (polysubst0 t p))"
fun decrpoly:: "'a poly \<Rightarrow> 'a poly"
where
"decrpoly (Bound n) = Bound (n - 1)"
| "decrpoly (Neg a) = Neg (decrpoly a)"
| "decrpoly (Add a b) = Add (decrpoly a) (decrpoly b)"
| "decrpoly (Sub a b) = Sub (decrpoly a) (decrpoly b)"
| "decrpoly (Mul a b) = Mul (decrpoly a) (decrpoly b)"
| "decrpoly (Pw p n) = Pw (decrpoly p) n"
| "decrpoly (CN c n p) = CN (decrpoly c) (n - 1) (decrpoly p)"
| "decrpoly a = a"
subsection \<open>Degrees and heads and coefficients\<close>
fun degree :: "'a poly \<Rightarrow> nat"
where
"degree (CN c 0 p) = 1 + degree p"
| "degree p = 0"
fun head :: "'a poly \<Rightarrow> 'a poly"
where
"head (CN c 0 p) = head p"
| "head p = p"
text \<open>More general notions of degree and head.\<close>
fun degreen :: "'a poly \<Rightarrow> nat \<Rightarrow> nat"
where
"degreen (CN c n p) = (\<lambda>m. if n = m then 1 + degreen p n else 0)"
| "degreen p = (\<lambda>m. 0)"
fun headn :: "'a poly \<Rightarrow> nat \<Rightarrow> 'a poly"
where
"headn (CN c n p) = (\<lambda>m. if n \<le> m then headn p m else CN c n p)"
| "headn p = (\<lambda>m. p)"
fun coefficients :: "'a poly \<Rightarrow> 'a poly list"
where
"coefficients (CN c 0 p) = c # coefficients p"
| "coefficients p = [p]"
fun isconstant :: "'a poly \<Rightarrow> bool"
where
"isconstant (CN c 0 p) = False"
| "isconstant p = True"
fun behead :: "'a::zero poly \<Rightarrow> 'a poly"
where
"behead (CN c 0 p) = (let p' = behead p in if p' = 0\<^sub>p then c else CN c 0 p')"
| "behead p = 0\<^sub>p"
fun headconst :: "'a poly \<Rightarrow> 'a"
where
"headconst (CN c n p) = headconst p"
| "headconst (C n) = n"
subsection \<open>Operations for normalization\<close>
declare if_cong[fundef_cong del]
declare let_cong[fundef_cong del]
fun polyadd :: "'a::{plus,zero} poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" (infixl "+\<^sub>p" 60)
where
"polyadd (C c) (C c') = C (c + c')"
| "polyadd (C c) (CN c' n' p') = CN (polyadd (C c) c') n' p'"
| "polyadd (CN c n p) (C c') = CN (polyadd c (C c')) n p"
| "polyadd (CN c n p) (CN c' n' p') =
(if n < n' then CN (polyadd c (CN c' n' p')) n p
else if n' < n then CN (polyadd (CN c n p) c') n' p'
else
let
cc' = polyadd c c';
pp' = polyadd p p'
in if pp' = 0\<^sub>p then cc' else CN cc' n pp')"
| "polyadd a b = Add a b"
fun polyneg :: "'a::uminus poly \<Rightarrow> 'a poly" ("~\<^sub>p")
where
"polyneg (C c) = C (-c)"
| "polyneg (CN c n p) = CN (polyneg c) n (polyneg p)"
| "polyneg a = Neg a"
definition polysub :: "'a::{plus,zero,uminus} poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" (infixl "-\<^sub>p" 60)
where "p -\<^sub>p q = polyadd p (polyneg q)"
fun polymul :: "'a::{plus,zero,times} poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" (infixl "*\<^sub>p" 60)
where
"polymul (C c) (C c') = C (c * c')"
| "polymul (C c) (CN c' n' p') =
(if c = 0 then 0\<^sub>p else CN (polymul (C c) c') n' (polymul (C c) p'))"
| "polymul (CN c n p) (C c') =
(if c' = 0 then 0\<^sub>p else CN (polymul c (C c')) n (polymul p (C c')))"
| "polymul (CN c n p) (CN c' n' p') =
(if n < n' then CN (polymul c (CN c' n' p')) n (polymul p (CN c' n' p'))
else if n' < n then CN (polymul (CN c n p) c') n' (polymul (CN c n p) p')
else polyadd (polymul (CN c n p) c') (CN 0\<^sub>p n' (polymul (CN c n p) p')))"
| "polymul a b = Mul a b"
declare if_cong[fundef_cong]
declare let_cong[fundef_cong]
fun polypow :: "nat \<Rightarrow> 'a::{plus,zero,times,one} poly \<Rightarrow> 'a poly"
where
"polypow 0 = (\<lambda>p. (1)\<^sub>p)"
| "polypow n =
(\<lambda>p.
let
q = polypow (n div 2) p;
d = polymul q q
in if even n then d else polymul p d)"
abbreviation poly_pow :: "'a::{plus,zero,times,one} poly \<Rightarrow> nat \<Rightarrow> 'a poly" (infixl "^\<^sub>p" 60)
where "a ^\<^sub>p k \<equiv> polypow k a"
function polynate :: "'a::{plus,uminus,zero,times,one} poly \<Rightarrow> 'a poly"
where
"polynate (Bound n) = CN 0\<^sub>p n (1)\<^sub>p"
| "polynate (Add p q) = polynate p +\<^sub>p polynate q"
| "polynate (Sub p q) = polynate p -\<^sub>p polynate q"
| "polynate (Mul p q) = polynate p *\<^sub>p polynate q"
| "polynate (Neg p) = ~\<^sub>p (polynate p)"
| "polynate (Pw p n) = polynate p ^\<^sub>p n"
| "polynate (CN c n p) = polynate (Add c (Mul (Bound n) p))"
| "polynate (C c) = C c"
by pat_completeness auto
termination by (relation "measure polysize") auto
fun poly_cmul :: "'a::{plus,times,zero} \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
where
"poly_cmul y (C x) = C (y * x)"
| "poly_cmul y (CN c n p) = CN (poly_cmul y c) n (poly_cmul y p)"
| "poly_cmul y p = C y *\<^sub>p p"
definition monic :: "'a::{plus,zero,times,one,inverse} poly \<Rightarrow> 'a poly \<times> bool"
where
"monic p =
(let h = headconst p
in if h = 0 then (p, False) else (poly_cmul(1 / h) p, True))"
subsection \<open>Pseudo-division\<close>
definition shift1 :: "'a::zero poly \<Rightarrow> 'a poly"
where "shift1 p = CN 0\<^sub>p 0 p"
abbreviation funpow :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a"
where "funpow \<equiv> compow"
partial_function (tailrec) polydivide_aux :: "'a::{plus,zero,uminus,times} poly \<Rightarrow> nat \<Rightarrow> 'a poly \<Rightarrow> nat \<Rightarrow> 'a poly \<Rightarrow> nat \<times> 'a poly"
where
"polydivide_aux a n p k s =
(if s = 0\<^sub>p then (k, s)
else
let
b = head s;
m = degree s
in
if m < n then (k,s)
else
let p' = funpow (m - n) shift1 p
in
if a = b then polydivide_aux a n p k (s -\<^sub>p p')
else polydivide_aux a n p (Suc k) ((a *\<^sub>p s) -\<^sub>p (b *\<^sub>p p')))"
definition polydivide :: "'a::{plus,zero,uminus,times} poly \<Rightarrow> 'a poly \<Rightarrow> nat \<times> 'a poly"
where "polydivide s p = polydivide_aux (head p) (degree p) p 0 s"
fun poly_deriv_aux :: "'a::{plus,zero,uminus,times,one} \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
where
"poly_deriv_aux n (CN c 0 p) = CN (poly_cmul n c) 0 (poly_deriv_aux (n + 1) p)"
| "poly_deriv_aux n p = poly_cmul n p"
fun poly_deriv :: "'a::{plus,zero,uminus,times,one} poly \<Rightarrow> 'a poly"
where
"poly_deriv (CN c 0 p) = poly_deriv_aux 1 p"
| "poly_deriv p = 0\<^sub>p"
subsection \<open>Semantics of the polynomial representation\<close>
primrec Ipoly :: "'a list \<Rightarrow> 'a poly \<Rightarrow> 'a::{plus,zero,minus,uminus,times,one,power}"
where
"Ipoly bs (C c) = c"
| "Ipoly bs (Bound n) = bs!n"
| "Ipoly bs (Neg a) = - Ipoly bs a"
| "Ipoly bs (Add a b) = Ipoly bs a + Ipoly bs b"
| "Ipoly bs (Sub a b) = Ipoly bs a - Ipoly bs b"
| "Ipoly bs (Mul a b) = Ipoly bs a * Ipoly bs b"
| "Ipoly bs (Pw t n) = Ipoly bs t ^ n"
| "Ipoly bs (CN c n p) = Ipoly bs c + (bs!n) * Ipoly bs p"
(*abbreviation Ipoly_syntax :: "'a poly \<Rightarrow> 'a list \<Rightarrow>'a::{plus,zero,minus,uminus,times,one,power}" ("\<lparr>_\<rparr>\<^sub>p\<^bsup>_\<^esup>")
where "\<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<equiv> Ipoly bs p"*)
lemmas RIpoly_eqs = Ipoly.simps
subsection \<open>Normal form and normalization\<close>
fun isnpolyh:: "'a::zero poly \<Rightarrow> nat \<Rightarrow> bool"
where
(* TODO: Inject normalization via a custom type class here? *)
(*"isnpolyh (C c) = (\<lambda>k. isnormNum c)"*)
"isnpolyh (C c) = (\<lambda>k. True)"
| "isnpolyh (CN c n p) = (\<lambda>k. n \<ge> k \<and> isnpolyh c (Suc n) \<and> isnpolyh p n \<and> p \<noteq> 0\<^sub>p)"
| "isnpolyh p = (\<lambda>k. False)"
lemma isnpolyh_mono: "n' \<le> n \<Longrightarrow> isnpolyh p n \<Longrightarrow> isnpolyh p n'"
by (induct p rule: isnpolyh.induct) auto
definition isnpoly :: "'a::zero poly \<Rightarrow> bool"
where "isnpoly p = isnpolyh p 0"
text \<open>polyadd preserves normal forms\<close>
lemma polyadd_normh: "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> isnpolyh (polyadd p q) (min n0 n1)"
proof (induct p q arbitrary: n0 n1 rule: polyadd.induct)
case (2 ab c' n' p' n0 n1)
from 2 have th1: "isnpolyh (C ab) (Suc n')"
by simp
from 2(3) have th2: "isnpolyh c' (Suc n')" and nplen1: "n' \<ge> n1"
by simp_all
with isnpolyh_mono have cp: "isnpolyh c' (Suc n')"
by simp
with 2(1)[OF th1 th2] have th3:"isnpolyh (C ab +\<^sub>p c') (Suc n')"
by simp
from nplen1 have n01len1: "min n0 n1 \<le> n'"
by simp
then show ?case using 2 th3
by simp
next
case (3 c' n' p' ab n1 n0)
from 3 have th1: "isnpolyh (C ab) (Suc n')"
by simp
from 3(2) have th2: "isnpolyh c' (Suc n')" and nplen1: "n' \<ge> n1"
by simp_all
with isnpolyh_mono have cp: "isnpolyh c' (Suc n')"
by simp
with 3(1)[OF th2 th1] have th3:"isnpolyh (c' +\<^sub>p C ab) (Suc n')"
by simp
from nplen1 have n01len1: "min n0 n1 \<le> n'"
by simp
then show ?case using 3 th3
by simp
next
case (4 c n p c' n' p' n0 n1)
then have nc: "isnpolyh c (Suc n)" and np: "isnpolyh p n"
by simp_all
from 4 have nc': "isnpolyh c' (Suc n')" and np': "isnpolyh p' n'"
by simp_all
from 4 have ngen0: "n \<ge> n0"
by simp
from 4 have n'gen1: "n' \<ge> n1"
by simp
consider (eq) "n = n'" | (lt) "n < n'" | (gt) "n > n'"
by arith
then show ?case
proof cases
case eq
with "4.hyps"(3)[OF nc nc']
have ncc':"isnpolyh (c +\<^sub>p c') (Suc n)"
by auto
then have ncc'n01: "isnpolyh (c +\<^sub>p c') (min n0 n1)"
apply(rule isnpolyh_mono[where n'="min n0 n1", rotated])
using ngen0 n'gen1
by auto
from eq "4.hyps"(4)[OF np np'] have npp': "isnpolyh (p +\<^sub>p p') n"
by simp
have minle: "min n0 n1 \<le> n'"
using ngen0 n'gen1 eq by simp
from minle npp' ncc'n01 4 eq ngen0 n'gen1 ncc' show ?thesis
by (simp add: Let_def)
next
case lt
have "min n0 n1 \<le> n0"
by simp
with 4 lt have th1:"min n0 n1 \<le> n"
by auto
from 4 have th21: "isnpolyh c (Suc n)"
by simp
from 4 have th22: "isnpolyh (CN c' n' p') n'"
by simp
from lt have th23: "min (Suc n) n' = Suc n"
by arith
from "4.hyps"(1)[OF th21 th22] have "isnpolyh (polyadd c (CN c' n' p')) (Suc n)"
using th23 by simp
with 4 lt th1 show ?thesis
by simp
next
case gt
then have gt': "n' < n \<and> \<not> n < n'"
by simp
have "min n0 n1 \<le> n1"
by simp
with 4 gt have th1: "min n0 n1 \<le> n'"
by auto
from 4 have th21: "isnpolyh c' (Suc n')"
by simp_all
from 4 have th22: "isnpolyh (CN c n p) n"
by simp
from gt have th23: "min n (Suc n') = Suc n'"
by arith
from "4.hyps"(2)[OF th22 th21] have "isnpolyh (polyadd (CN c n p) c') (Suc n')"
using th23 by simp
with 4 gt th1 show ?thesis
by simp
qed
qed auto
lemma polyadd[simp]:
fixes p :: "'a::ring_1 poly"
shows "Ipoly bs (polyadd p q) = Ipoly bs p + Ipoly bs q"
by (induct p q rule: polyadd.induct)
(auto simp add: Let_def field_simps distrib_left[symmetric] simp del: distrib_left_NO_MATCH)
lemma polyadd_norm: "isnpoly p \<Longrightarrow> isnpoly q \<Longrightarrow> isnpoly (polyadd p q)"
using polyadd_normh[of p 0 q 0] by (simp add: isnpoly_def)
text \<open>The degree of addition and other general lemmas needed for the normal form of polymul.\<close>
lemma polyadd_different_degreen:
assumes "isnpolyh p n0"
and "isnpolyh q n1"
and "degreen p m \<noteq> degreen q m"
and "m \<le> min n0 n1"
shows "degreen (polyadd p q) m = max (degreen p m) (degreen q m)"
using assms
proof (induct p q arbitrary: m n0 n1 rule: polyadd.induct)
case (4 c n p c' n' p' m n0 n1)
show ?case
proof (cases "n = n'")
case True
with 4(4)[of n n m] 4(3)[of "Suc n" "Suc n" m] 4(5-7)
show ?thesis by (auto simp: Let_def)
next
case False
with 4 show ?thesis by auto
qed
qed auto
lemma headnz[simp]: "isnpolyh p n \<Longrightarrow> p \<noteq> 0\<^sub>p \<Longrightarrow> headn p m \<noteq> 0\<^sub>p"
by (induct p arbitrary: n rule: headn.induct) auto
lemma degree_isnpolyh_Suc[simp]: "isnpolyh p (Suc n) \<Longrightarrow> degree p = 0"
by (induct p arbitrary: n rule: degree.induct) auto
lemma degreen_0[simp]: "isnpolyh p n \<Longrightarrow> m < n \<Longrightarrow> degreen p m = 0"
by (induct p arbitrary: n rule: degreen.induct) auto
lemma degree_isnpolyh_Suc': "n > 0 \<Longrightarrow> isnpolyh p n \<Longrightarrow> degree p = 0"
by (induct p arbitrary: n rule: degree.induct) auto
lemma degree_npolyhCN[simp]: "isnpolyh (CN c n p) n0 \<Longrightarrow> degree c = 0"
using degree_isnpolyh_Suc by auto
lemma degreen_npolyhCN[simp]: "isnpolyh (CN c n p) n0 \<Longrightarrow> degreen c n = 0"
using degreen_0 by auto
lemma degreen_polyadd:
assumes np: "isnpolyh p n0"
and nq: "isnpolyh q n1"
and m: "m \<le> max n0 n1"
shows "degreen (p +\<^sub>p q) m \<le> max (degreen p m) (degreen q m)"
using np nq m
proof (induct p q arbitrary: n0 n1 m rule: polyadd.induct)
case (2 c c' n' p' n0 n1)
then show ?case
by (cases n') simp_all
next
case (3 c n p c' n0 n1)
then show ?case
by (cases n) auto
next
case (4 c n p c' n' p' n0 n1 m)
show ?case
proof (cases "n = n'")
case True
with 4(4)[of n n m] 4(3)[of "Suc n" "Suc n" m] 4(5-7)
show ?thesis by (auto simp: Let_def)
next
case False
then show ?thesis by simp
qed
qed auto
lemma polyadd_eq_const_degreen:
assumes "isnpolyh p n0"
and "isnpolyh q n1"
and "polyadd p q = C c"
shows "degreen p m = degreen q m"
using assms
proof (induct p q arbitrary: m n0 n1 c rule: polyadd.induct)
case (4 c n p c' n' p' m n0 n1 x)
consider "n = n'" | "n > n' \<or> n < n'" by arith
then show ?case
proof cases
case 1
with 4 show ?thesis
by (cases "p +\<^sub>p p' = 0\<^sub>p") (auto simp add: Let_def)
next
case 2
with 4 show ?thesis by auto
qed
qed simp_all
lemma polymul_properties:
fixes p::"'a::field poly"
assumes np: "isnpolyh p n0"
and nq: "isnpolyh q n1"
and m: "m \<le> min n0 n1"
shows "isnpolyh (p *\<^sub>p q) (min n0 n1)"
and "p *\<^sub>p q = 0\<^sub>p \<longleftrightarrow> p = 0\<^sub>p \<or> q = 0\<^sub>p"
and "degreen (p *\<^sub>p q) m = (if p = 0\<^sub>p \<or> q = 0\<^sub>p then 0 else degreen p m + degreen q m)"
using np nq m
proof (induct p q arbitrary: n0 n1 m rule: polymul.induct)
case (2 c c' n' p')
{
case (1 n0 n1)
with "2.hyps"(4-6)[of n' n' n'] and "2.hyps"(1-3)[of "Suc n'" "Suc n'" n']
show ?case by (auto simp add: min_def)
next
case (2 n0 n1)
then show ?case by auto
next
case (3 n0 n1)
then show ?case using "2.hyps" by auto
}
next
case (3 c n p c')
{
case (1 n0 n1)
with "3.hyps"(4-6)[of n n n] and "3.hyps"(1-3)[of "Suc n" "Suc n" n]
show ?case by (auto simp add: min_def)
next
case (2 n0 n1)
then show ?case by auto
next
case (3 n0 n1)
then show ?case using "3.hyps" by auto
}
next
case (4 c n p c' n' p')
let ?cnp = "CN c n p" let ?cnp' = "CN c' n' p'"
{
case (1 n0 n1)
then have cnp: "isnpolyh ?cnp n"
and cnp': "isnpolyh ?cnp' n'"
and np: "isnpolyh p n"
and nc: "isnpolyh c (Suc n)"
and np': "isnpolyh p' n'"
and nc': "isnpolyh c' (Suc n')"
and nn0: "n \<ge> n0"
and nn1: "n' \<ge> n1"
by simp_all
{
assume "n < n'"
with "4.hyps"(4-5)[OF np cnp', of n] and "4.hyps"(1)[OF nc cnp', of n] nn0 cnp
have ?case by (simp add: min_def)
} moreover {
assume "n' < n"
with "4.hyps"(16-17)[OF cnp np', of "n'"] and "4.hyps"(13)[OF cnp nc', of "Suc n'"] nn1 cnp'
have ?case by (cases "Suc n' = n") (simp_all add: min_def)
} moreover {
assume "n' = n"
with "4.hyps"(16-17)[OF cnp np', of n] and "4.hyps"(13)[OF cnp nc', of n] cnp cnp' nn1 nn0
have ?case
apply (auto intro!: polyadd_normh)
apply (simp_all add: min_def isnpolyh_mono[OF nn0])
done
}
ultimately show ?case by arith
next
fix n0 n1 m
assume np: "isnpolyh ?cnp n0"
assume np':"isnpolyh ?cnp' n1"
assume m: "m \<le> min n0 n1"
let ?d = "degreen (?cnp *\<^sub>p ?cnp') m"
let ?d1 = "degreen ?cnp m"
let ?d2 = "degreen ?cnp' m"
let ?eq = "?d = (if ?cnp = 0\<^sub>p \<or> ?cnp' = 0\<^sub>p then 0 else ?d1 + ?d2)"
have "n' < n \<or> n < n' \<or> n' = n" by auto
moreover
{
assume "n' < n \<or> n < n'"
with "4.hyps"(3,6,18) np np' m have ?eq
by auto
}
moreover
{
assume nn': "n' = n"
then have nn: "\<not> n' < n \<and> \<not> n < n'" by arith
from "4.hyps"(16,18)[of n n' n]
"4.hyps"(13,14)[of n "Suc n'" n]
np np' nn'
have norm:
"isnpolyh ?cnp n"
"isnpolyh c' (Suc n)"
"isnpolyh (?cnp *\<^sub>p c') n"
"isnpolyh p' n"
"isnpolyh (?cnp *\<^sub>p p') n"
"isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n"
"?cnp *\<^sub>p c' = 0\<^sub>p \<longleftrightarrow> c' = 0\<^sub>p"
"?cnp *\<^sub>p p' \<noteq> 0\<^sub>p"
by (auto simp add: min_def)
{
assume mn: "m = n"
from "4.hyps"(17,18)[OF norm(1,4), of n]
"4.hyps"(13,15)[OF norm(1,2), of n] norm nn' mn
have degs:
"degreen (?cnp *\<^sub>p c') n = (if c' = 0\<^sub>p then 0 else ?d1 + degreen c' n)"
"degreen (?cnp *\<^sub>p p') n = ?d1 + degreen p' n"
by (simp_all add: min_def)
from degs norm have th1: "degreen (?cnp *\<^sub>p c') n < degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) n"
by simp
then have neq: "degreen (?cnp *\<^sub>p c') n \<noteq> degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) n"
by simp
have nmin: "n \<le> min n n"
by (simp add: min_def)
from polyadd_different_degreen[OF norm(3,6) neq nmin] th1
have deg: "degreen (CN c n p *\<^sub>p c' +\<^sub>p CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n =
degreen (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n"
by simp
from "4.hyps"(16-18)[OF norm(1,4), of n]
"4.hyps"(13-15)[OF norm(1,2), of n]
mn norm m nn' deg
have ?eq by simp
}
moreover
{
assume mn: "m \<noteq> n"
then have mn': "m < n"
using m np by auto
from nn' m np have max1: "m \<le> max n n"
by simp
then have min1: "m \<le> min n n"
by simp
then have min2: "m \<le> min n (Suc n)"
by simp
from "4.hyps"(16-18)[OF norm(1,4) min1]
"4.hyps"(13-15)[OF norm(1,2) min2]
degreen_polyadd[OF norm(3,6) max1]
have "degreen (?cnp *\<^sub>p c' +\<^sub>p CN 0\<^sub>p n (?cnp *\<^sub>p p')) m \<le>
max (degreen (?cnp *\<^sub>p c') m) (degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) m)"
using mn nn' np np' by simp
with "4.hyps"(16-18)[OF norm(1,4) min1]
"4.hyps"(13-15)[OF norm(1,2) min2]
degreen_0[OF norm(3) mn']
have ?eq using nn' mn np np' by clarsimp
}
ultimately have ?eq by blast
}
ultimately show ?eq by blast
}
{
case (2 n0 n1)
then have np: "isnpolyh ?cnp n0"
and np': "isnpolyh ?cnp' n1"
and m: "m \<le> min n0 n1"
by simp_all
then have mn: "m \<le> n" by simp
let ?c0p = "CN 0\<^sub>p n (?cnp *\<^sub>p p')"
{
assume C: "?cnp *\<^sub>p c' +\<^sub>p ?c0p = 0\<^sub>p" "n' = n"
then have nn: "\<not> n' < n \<and> \<not> n < n'"
by simp
from "4.hyps"(16-18) [of n n n]
"4.hyps"(13-15)[of n "Suc n" n]
np np' C(2) mn
have norm:
"isnpolyh ?cnp n"
"isnpolyh c' (Suc n)"
"isnpolyh (?cnp *\<^sub>p c') n"
"isnpolyh p' n"
"isnpolyh (?cnp *\<^sub>p p') n"
"isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n"
"?cnp *\<^sub>p c' = 0\<^sub>p \<longleftrightarrow> c' = 0\<^sub>p"
"?cnp *\<^sub>p p' \<noteq> 0\<^sub>p"
"degreen (?cnp *\<^sub>p c') n = (if c' = 0\<^sub>p then 0 else degreen ?cnp n + degreen c' n)"
"degreen (?cnp *\<^sub>p p') n = degreen ?cnp n + degreen p' n"
by (simp_all add: min_def)
from norm have cn: "isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n"
by simp
have degneq: "degreen (?cnp *\<^sub>p c') n < degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) n"
using norm by simp
from polyadd_eq_const_degreen[OF norm(3) cn C(1), where m="n"] degneq
have False by simp
}
then show ?case using "4.hyps" by clarsimp
}
qed auto
lemma polymul[simp]:
fixes p::"'a::field poly"
shows "Ipoly bs (p *\<^sub>p q) = Ipoly bs p * Ipoly bs q"
by (induct p q rule: polymul.induct) (auto simp add: field_simps)
lemma polymul_normh:
fixes p::"'a::field poly"
shows "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> isnpolyh (p *\<^sub>p q) (min n0 n1)"
using polymul_properties(1) by blast
lemma polymul_eq0_iff:
fixes p::"'a::field poly"
shows "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> p *\<^sub>p q = 0\<^sub>p \<longleftrightarrow> p = 0\<^sub>p \<or> q = 0\<^sub>p"
using polymul_properties(2) by blast
lemma polymul_degreen:
fixes p::"'a::field poly"
shows "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> m \<le> min n0 n1 \<Longrightarrow>
degreen (p *\<^sub>p q) m = (if p = 0\<^sub>p \<or> q = 0\<^sub>p then 0 else degreen p m + degreen q m)"
by (fact polymul_properties(3))
lemma polymul_norm:
fixes p::"'a::field poly"
shows "isnpoly p \<Longrightarrow> isnpoly q \<Longrightarrow> isnpoly (polymul p q)"
using polymul_normh[of "p" "0" "q" "0"] by (simp add: isnpoly_def)
lemma headconst_zero:
fixes p::"'a::zero poly"
shows "isnpolyh p n0 \<Longrightarrow> headconst p = 0 \<longleftrightarrow> p = 0\<^sub>p"
by (induct p arbitrary: n0 rule: headconst.induct) auto
(*lemma headconst_isnormNum: "isnpolyh p n0 \<Longrightarrow> isnormNum (headconst p)"
by (induct p arbitrary: n0) auto
lemma monic_eqI:
assumes np: "isnpolyh p n0"
shows "INum (headconst p) * Ipoly bs (fst (monic p)) =
(Ipoly bs p ::'a::{field_char_0,field, power})"
unfolding monic_def Let_def
proof (cases "headconst p = 0\<^sub>N", simp_all add: headconst_zero[OF np])
let ?h = "headconst p"
assume pz: "p \<noteq> 0\<^sub>p"
{
assume hz: "INum ?h = (0::'a)"
from headconst_isnormNum[OF np] have norm: "isnormNum ?h" "isnormNum 0\<^sub>N"
by simp_all
from isnormNum_unique[where ?'a = 'a, OF norm] hz have "?h = 0\<^sub>N"
by simp
with headconst_zero[OF np] have "p = 0\<^sub>p"
by blast
with pz have False
by blast
}
then show "INum (headconst p) = (0::'a) \<longrightarrow> \<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> = 0"
by blast
qed*)
text \<open>polyneg is a negation and preserves normal forms\<close>
lemma polyneg[simp]:
fixes p::"'a::ring_1 poly"
shows "Ipoly bs (polyneg p) = - Ipoly bs p"
by (induct p rule: polyneg.induct) auto
lemma polyneg0:
fixes p::"'a::ring_1 poly"
shows "isnpolyh p n \<Longrightarrow> (~\<^sub>p p) = 0\<^sub>p \<longleftrightarrow> p = 0\<^sub>p"
by (induct p arbitrary: n rule: polyneg.induct) auto
lemma polyneg_polyneg:
fixes p::"'a::ring_1 poly"
shows "isnpolyh p n0 \<Longrightarrow> ~\<^sub>p (~\<^sub>p p) = p"
by (induct p arbitrary: n0 rule: polyneg.induct) auto
lemma polyneg_normh:
fixes p::"'a::ring_1 poly"
shows "isnpolyh p n \<Longrightarrow> isnpolyh (polyneg p) n"
by (induct p arbitrary: n rule: polyneg.induct) (auto simp add: polyneg0)
lemma polyneg_norm:
fixes p::"'a::ring_1 poly"
shows "isnpoly p \<Longrightarrow> isnpoly (polyneg p)"
using polyneg_normh by (simp add: isnpoly_def)
text \<open>polysub is a substraction and preserves normal forms\<close>
lemma polysub[simp]:
fixes p::"'a::ring_1 poly"
shows "Ipoly bs (polysub p q) = Ipoly bs p - Ipoly bs q"
by (simp add: polysub_def)
lemma polysub_normh:
fixes p::"'a::ring_1 poly"
shows "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> isnpolyh (polysub p q) (min n0 n1)"
by (simp add: polysub_def polyneg_normh polyadd_normh)
lemma polysub_norm:
fixes p::"'a::ring_1 poly"
shows "isnpoly p \<Longrightarrow> isnpoly q \<Longrightarrow> isnpoly (polysub p q)"
proof-
assume "isnpoly p" "isnpoly q"
from polyadd_norm[OF _ polyneg_norm, OF this]
have "isnpoly (p +\<^sub>p ~\<^sub>p q)" .
thus "isnpoly (polysub p q)"
by (simp add: polysub_def)
qed
lemma polysub_same_0[simp]:
fixes p::"'a::ring_1 poly"
shows "isnpolyh p n0 \<Longrightarrow> polysub p p = 0\<^sub>p"
unfolding polysub_def split_def fst_conv snd_conv
by (induct p arbitrary: n0) (auto simp add: Let_def Nsub0[simplified Nsub_def])
lemma polysub_0:
fixes p::"'a::ring_1 poly"
shows "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> p -\<^sub>p q = 0\<^sub>p \<longleftrightarrow> p = q"
unfolding polysub_def split_def fst_conv snd_conv
by (induct p q arbitrary: n0 n1 rule:polyadd.induct)
(auto simp: Nsub0[simplified Nsub_def] Let_def)
text \<open>polypow is a power function and preserves normal forms\<close>
lemma polypow[simp]:
"Ipoly bs (polypow n p) = (Ipoly bs p :: 'a::field) ^ n"
proof (induct n rule: polypow.induct)
case 1
then show ?case
by simp
next
fix n assume hyp: "\<And>x. Ipoly bs (p ^\<^sub>p Suc n div 2) = Ipoly bs p ^ (Suc n div 2)"
let ?q = "polypow ((Suc n) div 2) p"
let ?d = "polymul ?q ?q"
have "odd (Suc n) \<or> even (Suc n)"
by simp
moreover
{
assume odd: "odd (Suc n)"
have th: "(Suc (Suc (Suc 0) * (Suc n div Suc (Suc 0)))) = Suc n div 2 + Suc n div 2 + 1"
by arith
from odd have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs (polymul p ?d)"
by (simp add: Let_def)
also have "\<dots> = (Ipoly bs p) * (Ipoly bs p)^(Suc n div 2) * (Ipoly bs p)^(Suc n div 2)"
using hyp by simp
also have "\<dots> = (Ipoly bs p) ^ (Suc n div 2 + Suc n div 2 + 1)"
by (simp only: power_add power_one_right) simp
also have "\<dots> = (Ipoly bs p) ^ (Suc (Suc (Suc 0) * (Suc n div Suc (Suc 0))))"
by (simp only: th)
finally have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs p ^ Suc n" unfolding numeral_2_eq_2 [symmetric]
using odd_two_times_div_two_nat [OF odd] by simp
}
moreover
{
assume even: "even (Suc n)"
from even have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs ?d"
by (simp add: Let_def)
also have "\<dots> = (Ipoly bs p) ^ (2 * (Suc n div 2))"
using hyp by (simp only: mult_2 power_add) simp
finally have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs p ^ Suc n" using even_two_times_div_two [OF even]
by simp
}
ultimately show "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs p ^ Suc n" by blast
qed
lemma polypow_normh:
fixes p :: "'a::field poly"
shows "isnpolyh p n \<Longrightarrow> isnpolyh (polypow k p) n"
proof (induct k arbitrary: n rule: polypow.induct)
case 1
then show ?case by auto
next
fix k n assume hyps: "(\<And>x n. isnpolyh p n \<Longrightarrow> isnpolyh (p ^\<^sub>p Suc k div 2) n)" "isnpolyh p n"
let ?q = "polypow (Suc k div 2) p"
let ?d = "polymul ?q ?q"
from hyps have th1: "isnpolyh ?q n" and th2: "isnpolyh p n"
by blast+
from polymul_normh[OF th1 th1] have dn: "isnpolyh ?d n"
by simp
from polymul_normh[OF th2 dn] have on: "isnpolyh (polymul p ?d) n"
by simp
from dn on show "isnpolyh (p ^\<^sub>p Suc k) n" by (simp, unfold Let_def) auto
qed
lemma polypow_norm:
fixes p :: "'a::field poly"
shows "isnpoly p \<Longrightarrow> isnpoly (polypow k p)"
by (simp add: polypow_normh isnpoly_def)
text \<open>Finally the whole normalization\<close>
lemma polynate [simp]:
"Ipoly bs (polynate p) = (Ipoly bs p :: 'a ::field)"
by (induct p rule: polynate.induct) auto
lemma polynate_norm[simp]:
fixes p :: "'a::field poly"
shows "isnpoly (polynate p)"
by (induct p rule: polynate.induct)
(simp_all add: polyadd_norm polymul_norm polysub_norm polyneg_norm polypow_norm,
simp_all add: isnpoly_def)
text \<open>shift1\<close>
lemma shift1:
fixes p :: "'a::ring_1 poly"
shows "Ipoly bs (shift1 p) = Ipoly bs (Mul (Bound 0) p)"
by (simp add: shift1_def)
lemma shift1_isnpoly:
assumes "isnpoly p"
and "p \<noteq> 0\<^sub>p"
shows "isnpoly (shift1 p) "
using assms by (simp add: shift1_def isnpoly_def)
lemma shift1_nz[simp]:"shift1 p \<noteq> 0\<^sub>p"
by (simp add: shift1_def)
lemma funpow_shift1_isnpoly: "isnpoly p \<Longrightarrow> p \<noteq> 0\<^sub>p \<Longrightarrow> isnpoly (funpow n shift1 p)"
by (induct n arbitrary: p) (auto simp add: shift1_isnpoly funpow_swap1)
lemma funpow_isnpolyh:
assumes "\<And>p. isnpolyh p n \<Longrightarrow> isnpolyh (f p) n"
and "isnpolyh p n"
shows "isnpolyh (funpow k f p) n"
using assms by (induct k arbitrary: p) auto
lemma funpow_shift1:
"(Ipoly bs (funpow n shift1 p) :: 'a :: {field_char_0,field}) =
Ipoly bs (Mul (Pw (Bound 0) n) p)"
by (induct n arbitrary: p) (simp_all add: shift1_isnpoly shift1)
lemma shift1_isnpolyh: "isnpolyh p n0 \<Longrightarrow> p \<noteq> 0\<^sub>p \<Longrightarrow> isnpolyh (shift1 p) 0"
using isnpolyh_mono[where n="n0" and n'="0" and p="p"] by (simp add: shift1_def)
lemma funpow_shift1_1:
"(Ipoly bs (funpow n shift1 p) :: 'a :: {field_char_0,field}) =
Ipoly bs (funpow n shift1 (1)\<^sub>p *\<^sub>p p)"
by (simp add: funpow_shift1)
lemma poly_cmul[simp]:
fixes p :: "'a::comm_ring_1 poly"
shows "Ipoly bs (poly_cmul c p) = Ipoly bs (Mul (C c) p)"
by (induct p, simp_all add: field_simps)
lemma behead:
assumes "isnpolyh p n"
shows "Ipoly bs (Add (Mul (head p) (Pw (Bound 0) (degree p))) (behead p)) =
(Ipoly bs p :: 'a :: {field_char_0,field})"
using assms
proof (induct p arbitrary: n rule: behead.induct)
case (1 c p n)
then have pn: "isnpolyh p n" by simp
from 1(1)[OF pn]
have th:"Ipoly bs (Add (Mul (head p) (Pw (Bound 0) (degree p))) (behead p)) = Ipoly bs p" .
then show ?case using "1.hyps"
apply (simp add: Let_def,cases "behead p = 0\<^sub>p")
apply (simp_all add: th[symmetric] field_simps)
done
qed (auto simp add: Let_def)
lemma behead_isnpolyh:
assumes "isnpolyh p n"
shows "isnpolyh (behead p) n"
using assms by (induct p rule: behead.induct) (auto simp add: Let_def isnpolyh_mono)
subsection \<open>Miscellaneous lemmas about indexes, decrementation, substitution etc ...\<close>
lemma isnpolyh_polybound0: "isnpolyh p (Suc n) \<Longrightarrow> polybound0 p"
proof (induct p arbitrary: n rule: poly.induct, auto, goal_cases)
case prems: (1 c n p n')
then have "n = Suc (n - 1)"
by simp
then have "isnpolyh p (Suc (n - 1))"
using \<open>isnpolyh p n\<close> by simp
with prems(2) show ?case
by simp
qed
lemma isconstant_polybound0: "isnpolyh p n0 \<Longrightarrow> isconstant p \<longleftrightarrow> polybound0 p"
by (induct p arbitrary: n0 rule: isconstant.induct) (auto simp add: isnpolyh_polybound0)
lemma decrpoly_zero[simp]: "decrpoly p = 0\<^sub>p \<longleftrightarrow> p = 0\<^sub>p"
by (induct p) auto
lemma decrpoly_normh: "isnpolyh p n0 \<Longrightarrow> polybound0 p \<Longrightarrow> isnpolyh (decrpoly p) (n0 - 1)"
apply (induct p arbitrary: n0)
apply auto
apply atomize
apply (rename_tac nat a b, erule_tac x = "Suc nat" in allE)
apply auto
done
lemma head_polybound0: "isnpolyh p n0 \<Longrightarrow> polybound0 (head p)"
by (induct p arbitrary: n0 rule: head.induct) (auto intro: isnpolyh_polybound0)
lemma polybound0_I:
assumes "polybound0 a"
shows "Ipoly (b # bs) a = Ipoly (b' # bs) a"
using assms by (induct a rule: poly.induct) auto
lemma polysubst0_I: "Ipoly (b # bs) (polysubst0 a t) = Ipoly ((Ipoly (b # bs) a) # bs) t"
by (induct t) simp_all
lemma polysubst0_I':
assumes "polybound0 a"
shows "Ipoly (b # bs) (polysubst0 a t) = Ipoly ((Ipoly (b' # bs) a) # bs) t"
by (induct t) (simp_all add: polybound0_I[OF assms, where b="b" and b'="b'"])
lemma decrpoly:
assumes "polybound0 t"
shows "Ipoly (x # bs) t = Ipoly bs (decrpoly t)"
using assms by (induct t rule: decrpoly.induct) simp_all
lemma polysubst0_polybound0:
assumes "polybound0 t"
shows "polybound0 (polysubst0 t a)"
using assms by (induct a rule: poly.induct) auto
lemma degree0_polybound0: "isnpolyh p n \<Longrightarrow> degree p = 0 \<Longrightarrow> polybound0 p"
by (induct p arbitrary: n rule: degree.induct) (auto simp add: isnpolyh_polybound0)
primrec maxindex :: "'a poly \<Rightarrow> nat"
where
"maxindex (Bound n) = n + 1"
| "maxindex (CN c n p) = max (n + 1) (max (maxindex c) (maxindex p))"
| "maxindex (Add p q) = max (maxindex p) (maxindex q)"
| "maxindex (Sub p q) = max (maxindex p) (maxindex q)"
| "maxindex (Mul p q) = max (maxindex p) (maxindex q)"
| "maxindex (Neg p) = maxindex p"
| "maxindex (Pw p n) = maxindex p"
| "maxindex (C x) = 0"
definition wf_bs :: "'a list \<Rightarrow> 'a poly \<Rightarrow> bool"
where "wf_bs bs p \<longleftrightarrow> length bs \<ge> maxindex p"
lemma wf_bs_coefficients: "wf_bs bs p \<Longrightarrow> \<forall>c \<in> set (coefficients p). wf_bs bs c"
proof (induct p rule: coefficients.induct)
case (1 c p)
show ?case
proof
fix x
assume xc: "x \<in> set (coefficients (CN c 0 p))"
then have "x = c \<or> x \<in> set (coefficients p)"
by simp