/
CPolynomials.v
2775 lines (2496 loc) · 73.3 KB
/
CPolynomials.v
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
(* Copyright © 1998-2006
* Henk Barendregt
* Luís Cruz-Filipe
* Herman Geuvers
* Mariusz Giero
* Rik van Ginneken
* Dimitri Hendriks
* Sébastien Hinderer
* Bart Kirkels
* Pierre Letouzey
* Iris Loeb
* Lionel Mamane
* Milad Niqui
* Russell O’Connor
* Randy Pollack
* Nickolay V. Shmyrev
* Bas Spitters
* Dan Synek
* Freek Wiedijk
* Jan Zwanenburg
*
* This work is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This work is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this work; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
(** printing _X_ %\ensuremath{x}% *)
(** printing _C_ %\ensuremath\diamond% *)
(** printing [+X*] %\ensuremath{+x\times}% #+x×# *)
(** printing RX %\ensuremath{R[x]}% #R[x]# *)
(** printing FX %\ensuremath{F[x]}% #F[x]# *)
Require Import CRing_Homomorphisms.
Require Import Rational.
(**
* Polynomials
The first section only proves the polynomials form a ring.
Section%~\ref{section:poly-equality}% gives some basic properties of
equality and induction of polynomials.
** Definition of polynomials; they form a ring
%\label{section:poly-ring}%
*)
Section CPoly_CRing.
(**
%\begin{convention}% Let [CR] be a ring.
%\end{convention}%
*)
Variable CR : CRing.
(**
The intuition behind the type [cpoly] is the following
- [(cpoly CR)] is $CR[X]$ #CR[X]#;
- [cpoly_zero] is the `empty' polynomial with no coefficients;
- [(cpoly_linear c p)] is [c[+]X[*]p]
*)
Inductive cpoly : Type :=
| cpoly_zero : cpoly
| cpoly_linear : CR -> cpoly -> cpoly.
Definition cpoly_constant (c : CR) : cpoly := cpoly_linear c cpoly_zero.
Definition cpoly_one : cpoly := cpoly_constant [1].
(**
Some useful induction lemmas for doubly quantified propositions.
*)
Lemma Ccpoly_double_ind0 : forall P : cpoly -> cpoly -> CProp,
(forall p, P p cpoly_zero) -> (forall p, P cpoly_zero p) ->
(forall p q c d, P p q -> P (cpoly_linear c p) (cpoly_linear d q)) -> forall p q, P p q.
Proof.
simple induction p; auto.
simple induction q; auto.
Qed.
Lemma Ccpoly_double_sym_ind0 : forall P : cpoly -> cpoly -> CProp,
Csymmetric P -> (forall p, P p cpoly_zero) ->
(forall p q c d, P p q -> P (cpoly_linear c p) (cpoly_linear d q)) -> forall p q, P p q.
Proof.
intros.
apply Ccpoly_double_ind0; auto.
Qed.
Lemma Ccpoly_double_ind0' : forall P : cpoly -> cpoly -> CProp,
(forall p, P cpoly_zero p) -> (forall p c, P (cpoly_linear c p) cpoly_zero) ->
(forall p q c d, P p q -> P (cpoly_linear c p) (cpoly_linear d q)) -> forall p q, P p q.
Proof.
simple induction p; auto.
simple induction q; auto.
Qed.
Lemma cpoly_double_ind0 : forall P : cpoly -> cpoly -> Prop,
(forall p, P p cpoly_zero) -> (forall p, P cpoly_zero p) ->
(forall p q c d, P p q -> P (cpoly_linear c p) (cpoly_linear d q)) -> forall p q, P p q.
Proof.
simple induction p; auto.
simple induction q; auto.
Qed.
Lemma cpoly_double_sym_ind0 : forall P : cpoly -> cpoly -> Prop,
Tsymmetric P -> (forall p, P p cpoly_zero) ->
(forall p q c d, P p q -> P (cpoly_linear c p) (cpoly_linear d q)) -> forall p q, P p q.
Proof.
intros.
apply cpoly_double_ind0; auto.
Qed.
Lemma cpoly_double_ind0' : forall P : cpoly -> cpoly -> Prop,
(forall p, P cpoly_zero p) -> (forall p c, P (cpoly_linear c p) cpoly_zero) ->
(forall p q c d, P p q -> P (cpoly_linear c p) (cpoly_linear d q)) -> forall p q, P p q.
Proof.
simple induction p; auto.
simple induction q; auto.
Qed.
(**
*** The polynomials form a setoid
*)
Fixpoint cpoly_eq_zero (p : cpoly) : Prop :=
match p with
| cpoly_zero => True
| cpoly_linear c p1 => c [=] [0] /\ cpoly_eq_zero p1
end.
Fixpoint cpoly_eq (p q : cpoly) {struct p} : Prop :=
match p with
| cpoly_zero => cpoly_eq_zero q
| cpoly_linear c p1 =>
match q with
| cpoly_zero => cpoly_eq_zero p
| cpoly_linear d q1 => c [=] d /\ cpoly_eq p1 q1
end
end.
Lemma cpoly_eq_p_zero : forall p, cpoly_eq p cpoly_zero = cpoly_eq_zero p.
Proof.
simple induction p; auto.
Qed.
Fixpoint cpoly_ap_zero (p : cpoly) : CProp :=
match p with
| cpoly_zero => False
| cpoly_linear c p1 => c [#] [0] or cpoly_ap_zero p1
end.
Fixpoint cpoly_ap (p q : cpoly) {struct p} : CProp :=
match p with
| cpoly_zero => cpoly_ap_zero q
| cpoly_linear c p1 =>
match q with
| cpoly_zero => cpoly_ap_zero p
| cpoly_linear d q1 => c [#] d or cpoly_ap p1 q1
end
end.
Lemma cpoly_ap_p_zero : forall p, cpoly_ap_zero p = cpoly_ap p cpoly_zero.
Proof.
simple induction p; auto.
Qed.
Lemma irreflexive_cpoly_ap : irreflexive cpoly_ap.
Proof.
red in |- *.
intro p; induction p as [| s p Hrecp].
intro H; elim H.
intro H.
elim H.
apply ap_irreflexive_unfolded.
assumption.
Qed.
Lemma symmetric_cpoly_ap : Csymmetric cpoly_ap.
Proof.
red in |- *.
intros x y.
pattern x, y in |- *.
apply Ccpoly_double_ind0'.
simpl in |- *; simple induction p; auto.
simpl in |- *; auto.
simpl in |- *.
intros p q c d H H0.
elim H0; intro H1.
left.
apply ap_symmetric_unfolded.
assumption.
auto.
Qed.
Lemma cotransitive_cpoly_ap : cotransitive cpoly_ap.
Proof.
red in |- *.
intros x y.
pattern x, y in |- *.
apply Ccpoly_double_sym_ind0.
red in |- *; intros p q H H0 r.
generalize (symmetric_cpoly_ap _ _ H0); intro H1.
elim (H H1 r); intro H2; [ right | left ]; apply symmetric_cpoly_ap; assumption.
simpl in |- *; intros p H z.
generalize H.
pattern p, z in |- *.
apply Ccpoly_double_ind0'.
simpl in |- *; intros q H0; elim H0.
simpl in |- *; auto.
simpl in |- *; intros r q c d H0 H1.
elim H1; intro H2.
generalize (ap_cotransitive_unfolded _ _ _ H2 d); intro H3.
elim H3; auto.
rewrite cpoly_ap_p_zero in H2.
elim (H0 H2); auto.
right; right; rewrite cpoly_ap_p_zero; assumption.
intros p q c d H H0 r.
simpl in H0.
elim H0; intro H1.
induction r as [| s r Hrecr].
simpl in |- *.
generalize (ap_cotransitive_unfolded _ _ _ H1 [0]); intro H2.
elim H2; auto.
intro H3.
right; left; apply ap_symmetric_unfolded; assumption.
simpl in |- *.
generalize (ap_cotransitive_unfolded _ _ _ H1 s); intro H2.
elim H2; auto.
induction r as [| s r Hrecr].
simpl in |- *.
cut (cpoly_ap_zero p or cpoly_ap_zero q).
intro H2; elim H2; auto.
generalize H1; pattern p, q in |- *; apply Ccpoly_double_ind0.
simpl in |- *.
intros r H2.
left; rewrite cpoly_ap_p_zero; assumption.
auto.
simpl in |- *.
intros p0 q0 c0 d0 H2 H3.
elim H3; intro H4.
elim (ap_cotransitive_unfolded _ _ _ H4 [0]); intro H5.
auto.
right; left; apply ap_symmetric_unfolded; assumption.
elim (H2 H4); auto.
simpl in |- *.
elim (H H1 r); auto.
Qed.
Lemma tight_apart_cpoly_ap : tight_apart cpoly_eq cpoly_ap.
Proof.
red in |- *.
intros x y.
pattern x, y in |- *.
apply cpoly_double_ind0'.
simple induction p.
simpl in |- *.
unfold iff in |- *.
unfold Not in |- *.
split.
auto.
intros H H0; inversion H0.
simpl in |- *.
intros s c H.
cut (Not (s [#] [0]) <-> s [=] [0]).
unfold Not in |- *.
intro H0.
elim H0; intros H1 H2.
split.
intro H3.
split; auto.
elim H; intros H4 H5.
apply H4.
intro H6.
auto.
intros H3 H4.
elim H3; intros H5 H6.
elim H4; intros H7.
auto.
elim H; intros H8 H9.
unfold Not in H8.
elim H9; assumption.
apply (ap_tight CR).
simple induction p.
simpl in |- *.
intro c.
cut (Not (c [#] [0]) <-> c [=] [0]).
unfold Not in |- *.
intro H.
elim H; intros H0 H1.
split.
auto.
intros H2 H3.
elim H3; intro H4.
tauto.
elim H4.
apply (ap_tight CR).
simpl in |- *.
intros s c H d.
generalize (H d).
generalize (ap_tight CR d [0]).
generalize (ap_tight CR s [0]).
unfold Not in |- *.
intros H0 H1 H2.
elim H0; clear H0; intros H3 H4.
elim H1; clear H1; intros H0 H5.
elim H2; clear H2; intros H1 H6.
tauto.
simpl in |- *.
unfold Not in |- *.
intros p q c d H.
elim H; intros H0 H1.
split.
intro H2.
split.
generalize (ap_tight CR c d).
unfold Not in |- *; tauto.
tauto.
intros H2 H3.
elim H3.
elim H2.
intros H4 H5 H6.
generalize (ap_tight CR c d).
unfold Not in |- *.
tauto.
elim H2.
auto.
Qed.
Lemma cpoly_is_CSetoid : is_CSetoid _ cpoly_eq cpoly_ap.
Proof.
apply Build_is_CSetoid.
exact irreflexive_cpoly_ap.
exact symmetric_cpoly_ap.
exact cotransitive_cpoly_ap.
exact tight_apart_cpoly_ap.
Qed.
Definition cpoly_csetoid := Build_CSetoid _ _ _ cpoly_is_CSetoid.
Canonical Structure cpoly_csetoid.
Canonical Structure cpoly_setoid := cs_crr cpoly_csetoid.
(**
Now that we know that the polynomials form a setoid, we can use the
notation with [ [#] ] and [ [=] ]. In order to use this notation,
we introduce [cpoly_zero_cs] and [cpoly_linear_cs], so that Coq
recognizes we are talking about a setoid.
We formulate the induction properties and
the most basic properties of equality and apartness
in terms of these generators.
*)
Let cpoly_zero_cs : cpoly_csetoid := cpoly_zero.
Let cpoly_linear_cs c (p : cpoly_csetoid) : cpoly_csetoid := cpoly_linear c p.
Lemma Ccpoly_ind_cs : forall P : cpoly_csetoid -> CProp,
P cpoly_zero_cs -> (forall p c, P p -> P (cpoly_linear_cs c p)) -> forall p, P p.
Proof.
simple induction p; auto.
Qed.
Lemma Ccpoly_double_ind0_cs : forall P : cpoly_csetoid -> cpoly_csetoid -> CProp,
(forall p, P p cpoly_zero_cs) -> (forall p, P cpoly_zero_cs p) ->
(forall p q c d, P p q -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q)) -> forall p q, P p q.
Proof.
simple induction p.
auto.
simple induction q.
auto.
simpl in X1.
unfold cpoly_linear_cs in X1.
auto.
Qed.
Lemma Ccpoly_double_sym_ind0_cs : forall P : cpoly_csetoid -> cpoly_csetoid -> CProp,
Csymmetric P -> (forall p, P p cpoly_zero_cs) ->
(forall p q c d, P p q -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q)) -> forall p q, P p q.
Proof.
intros.
apply Ccpoly_double_ind0; auto.
Qed.
Lemma cpoly_ind_cs : forall P : cpoly_csetoid -> Prop,
P cpoly_zero_cs -> (forall p c, P p -> P (cpoly_linear_cs c p)) -> forall p, P p.
Proof.
simple induction p; auto.
Qed.
Lemma cpoly_double_ind0_cs : forall P : cpoly_csetoid -> cpoly_csetoid -> Prop,
(forall p, P p cpoly_zero_cs) -> (forall p, P cpoly_zero_cs p) ->
(forall p q c d, P p q -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q)) -> forall p q, P p q.
Proof.
simple induction p.
auto.
simple induction q.
auto.
simpl in H1.
unfold cpoly_linear_cs in H1.
auto.
Qed.
Lemma cpoly_double_sym_ind0_cs : forall P : cpoly_csetoid -> cpoly_csetoid -> Prop,
Tsymmetric P -> (forall p, P p cpoly_zero_cs) ->
(forall p q c d, P p q -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q)) -> forall p q, P p q.
Proof.
intros.
apply cpoly_double_ind0; auto.
Qed.
Lemma cpoly_lin_eq_zero_ : forall p c,
cpoly_linear_cs c p [=] cpoly_zero_cs -> c [=] [0] /\ p [=] cpoly_zero_cs.
Proof.
unfold cpoly_linear_cs in |- *.
unfold cpoly_zero_cs in |- *.
simpl in |- *.
intros p c H.
elim H; intros.
split; auto.
rewrite cpoly_eq_p_zero.
assumption.
Qed.
Lemma _cpoly_lin_eq_zero : forall p c,
c [=] [0] /\ p [=] cpoly_zero_cs -> cpoly_linear_cs c p [=] cpoly_zero_cs.
Proof.
unfold cpoly_linear_cs in |- *.
unfold cpoly_zero_cs in |- *.
simpl in |- *.
intros p c H.
elim H; intros.
split; auto.
rewrite <- cpoly_eq_p_zero.
assumption.
Qed.
Lemma cpoly_zero_eq_lin_ : forall p c,
cpoly_zero_cs [=] cpoly_linear_cs c p -> c [=] [0] /\ cpoly_zero_cs [=] p.
Proof.
auto.
Qed.
Lemma _cpoly_zero_eq_lin : forall p c,
c [=] [0] /\ cpoly_zero_cs [=] p -> cpoly_zero_cs [=] cpoly_linear_cs c p.
Proof.
auto.
Qed.
Lemma cpoly_lin_eq_lin_ : forall p q c d,
cpoly_linear_cs c p [=] cpoly_linear_cs d q -> c [=] d /\ p [=] q.
Proof.
auto.
Qed.
Lemma _cpoly_lin_eq_lin : forall p q c d,
c [=] d /\ p [=] q -> cpoly_linear_cs c p [=] cpoly_linear_cs d q.
Proof.
auto.
Qed.
Lemma cpoly_lin_ap_zero_ : forall p c,
cpoly_linear_cs c p [#] cpoly_zero_cs -> c [#] [0] or p [#] cpoly_zero_cs.
Proof.
unfold cpoly_zero_cs in |- *.
intros p c H.
cut (cpoly_ap (cpoly_linear c p) cpoly_zero); auto.
intro H0.
simpl in H0.
elim H0; auto.
right.
rewrite <- cpoly_ap_p_zero.
assumption.
Qed.
Lemma _cpoly_lin_ap_zero : forall p c,
c [#] [0] or p [#] cpoly_zero_cs -> cpoly_linear_cs c p [#] cpoly_zero_cs.
Proof.
unfold cpoly_zero_cs in |- *.
intros.
simpl in |- *.
elim X; try auto.
intros.
right.
rewrite cpoly_ap_p_zero.
assumption.
Qed.
Lemma cpoly_lin_ap_zero : forall p c,
(cpoly_linear_cs c p [#] cpoly_zero_cs) = (c [#] [0] or p [#] cpoly_zero_cs).
Proof.
intros.
simpl in |- *.
unfold cpoly_zero_cs in |- *.
rewrite cpoly_ap_p_zero.
reflexivity.
Qed.
Lemma cpoly_zero_ap_lin_ : forall p c,
cpoly_zero_cs [#] cpoly_linear_cs c p -> c [#] [0] or cpoly_zero_cs [#] p.
Proof.
intros.
simpl in |- *.
assumption.
Qed.
Lemma _cpoly_zero_ap_lin : forall p c,
c [#] [0] or cpoly_zero_cs [#] p -> cpoly_zero_cs [#] cpoly_linear_cs c p.
Proof.
intros.
simpl in |- *.
assumption.
Qed.
Lemma cpoly_zero_ap_lin : forall p c,
(cpoly_zero_cs [#] cpoly_linear_cs c p) = (c [#] [0] or cpoly_zero_cs [#] p).
Proof. reflexivity. Qed.
Lemma cpoly_lin_ap_lin_ : forall p q c d,
cpoly_linear_cs c p [#] cpoly_linear_cs d q -> c [#] d or p [#] q.
Proof. auto. Qed.
Lemma _cpoly_lin_ap_lin : forall p q c d,
c [#] d or p [#] q -> cpoly_linear_cs c p [#] cpoly_linear_cs d q.
Proof. auto. Qed.
Lemma cpoly_lin_ap_lin : forall p q c d,
(cpoly_linear_cs c p [#] cpoly_linear_cs d q) = (c [#] d or p [#] q).
Proof. reflexivity. Qed.
Lemma cpoly_linear_strext : bin_fun_strext _ _ _ cpoly_linear_cs.
Proof.
unfold bin_fun_strext in |- *.
intros until 1.
apply cpoly_lin_ap_lin_;assumption.
Qed.
Lemma cpoly_linear_wd : bin_fun_wd _ _ _ cpoly_linear_cs.
Proof.
apply bin_fun_strext_imp_wd. now repeat intro.
Qed.
Definition cpoly_linear_fun := Build_CSetoid_bin_fun _ _ _ _ cpoly_linear_strext.
Lemma Ccpoly_double_comp_ind : forall P : cpoly_csetoid -> cpoly_csetoid -> CProp,
(forall p1 p2 q1 q2, p1 [=] p2 -> q1 [=] q2 -> P p1 q1 -> P p2 q2) ->
P cpoly_zero_cs cpoly_zero_cs ->
(forall p q c d, P p q -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q)) -> forall p q, P p q.
Proof.
intros.
apply Ccpoly_double_ind0_cs.
intro p0; pattern p0 in |- *; apply Ccpoly_ind_cs;[assumption|].
intros p1 c. intros.
apply X with (cpoly_linear_cs c p1) (cpoly_linear_cs [0] cpoly_zero_cs).
algebra.
apply _cpoly_lin_eq_zero.
split; algebra.
apply X1; assumption.
intro p0; pattern p0 in |- *; apply Ccpoly_ind_cs.
assumption.
intros.
apply X with (cpoly_linear_cs [0] cpoly_zero_cs) (cpoly_linear_cs c p1).
apply _cpoly_lin_eq_zero;split; algebra.
algebra.
apply X1; assumption.
now apply X1.
Qed.
Lemma Ccpoly_triple_comp_ind :
forall P : cpoly_csetoid -> cpoly_csetoid -> cpoly_csetoid -> CProp,
(forall p1 p2 q1 q2 r1 r2,
p1 [=] p2 -> q1 [=] q2 -> r1 [=] r2 -> P p1 q1 r1 -> P p2 q2 r2) ->
P cpoly_zero_cs cpoly_zero_cs cpoly_zero_cs ->
(forall p q r c d e,
P p q r -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q) (cpoly_linear_cs e r)) ->
forall p q r, P p q r.
Proof.
do 6 intro.
pattern p, q in |- *.
apply Ccpoly_double_comp_ind.
intros.
apply X with p1 q1 r.
assumption.
assumption.
algebra.
apply X2.
intro r; pattern r in |- *; apply Ccpoly_ind_cs.
assumption.
intros.
apply X with (cpoly_linear_cs [0] cpoly_zero_cs) (cpoly_linear_cs [0] cpoly_zero_cs)
(cpoly_linear_cs c p0).
apply _cpoly_lin_eq_zero; split; algebra.
apply _cpoly_lin_eq_zero; split; algebra.
algebra.
apply X1.
assumption.
do 6 intro.
pattern r in |- *; apply Ccpoly_ind_cs.
apply X with (cpoly_linear_cs c p0) (cpoly_linear_cs d q0) (cpoly_linear_cs [0] cpoly_zero_cs).
algebra.
algebra.
apply _cpoly_lin_eq_zero; split; algebra.
apply X1.
apply X2.
intros.
apply X1.
apply X2.
Qed.
Lemma cpoly_double_comp_ind : forall P : cpoly_csetoid -> cpoly_csetoid -> Prop,
(forall p1 p2 q1 q2, p1 [=] p2 -> q1 [=] q2 -> P p1 q1 -> P p2 q2) ->
P cpoly_zero_cs cpoly_zero_cs ->
(forall p q c d, P p q -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q)) -> forall p q, P p q.
Proof.
intros.
apply cpoly_double_ind0_cs.
intro p0; pattern p0 in |- *; apply cpoly_ind_cs.
assumption.
intros.
apply H with (cpoly_linear_cs c p1) (cpoly_linear_cs [0] cpoly_zero_cs).
algebra.
apply _cpoly_lin_eq_zero.
split; algebra.
apply H1.
assumption.
intro p0; pattern p0 in |- *; apply cpoly_ind_cs.
assumption.
intros.
apply H with (cpoly_linear_cs [0] cpoly_zero_cs) (cpoly_linear_cs c p1).
apply _cpoly_lin_eq_zero.
split; algebra.
algebra.
now apply H1.
now apply H1.
Qed.
Lemma cpoly_triple_comp_ind :
forall P : cpoly_csetoid -> cpoly_csetoid -> cpoly_csetoid -> Prop,
(forall p1 p2 q1 q2 r1 r2,
p1 [=] p2 -> q1 [=] q2 -> r1 [=] r2 -> P p1 q1 r1 -> P p2 q2 r2) ->
P cpoly_zero_cs cpoly_zero_cs cpoly_zero_cs ->
(forall p q r c d e,
P p q r -> P (cpoly_linear_cs c p) (cpoly_linear_cs d q) (cpoly_linear_cs e r)) ->
forall p q r, P p q r.
Proof.
do 6 intro.
pattern p, q in |- *.
apply cpoly_double_comp_ind.
intros.
apply H with p1 q1 r.
assumption.
assumption.
algebra.
apply H4.
intro r; pattern r in |- *; apply cpoly_ind_cs.
assumption.
intros.
apply H with (cpoly_linear_cs [0] cpoly_zero_cs) (cpoly_linear_cs [0] cpoly_zero_cs)
(cpoly_linear_cs c p0).
apply _cpoly_lin_eq_zero; split; algebra.
apply _cpoly_lin_eq_zero; split; algebra.
algebra.
apply H1.
assumption.
do 6 intro.
pattern r in |- *; apply cpoly_ind_cs.
apply H with (cpoly_linear_cs c p0) (cpoly_linear_cs d q0) (cpoly_linear_cs [0] cpoly_zero_cs).
algebra.
algebra.
apply _cpoly_lin_eq_zero; split; algebra.
apply H1.
apply H2.
intros.
apply H1.
apply H2.
Qed.
(**
*** The polynomials form a semi-group and a monoid
*)
Fixpoint cpoly_plus (p q : cpoly) {struct p} : cpoly :=
match p with
| cpoly_zero => q
| cpoly_linear c p1 =>
match q with
| cpoly_zero => p
| cpoly_linear d q1 => cpoly_linear (c[+]d) (cpoly_plus p1 q1)
end
end.
Definition cpoly_plus_cs (p q : cpoly_csetoid) : cpoly_csetoid := cpoly_plus p q.
Lemma cpoly_zero_plus : forall p, cpoly_plus_cs cpoly_zero_cs p = p.
Proof.
auto.
Qed.
Lemma cpoly_plus_zero : forall p, cpoly_plus_cs p cpoly_zero_cs = p.
Proof.
simple induction p.
auto.
auto.
Qed.
Lemma cpoly_lin_plus_lin : forall p q c d,
cpoly_plus_cs (cpoly_linear_cs c p) (cpoly_linear_cs d q) =
cpoly_linear_cs (c[+]d) (cpoly_plus_cs p q).
Proof.
auto.
Qed.
Lemma cpoly_plus_commutative : forall p q, cpoly_plus_cs p q [=] cpoly_plus_cs q p.
Proof.
intros.
pattern p, q in |- *.
apply cpoly_double_sym_ind0_cs.
unfold Tsymmetric in |- *.
intros.
algebra.
intro p0.
rewrite cpoly_zero_plus.
rewrite cpoly_plus_zero.
algebra.
intros.
repeat rewrite cpoly_lin_plus_lin.
apply _cpoly_lin_eq_lin.
split.
algebra.
assumption.
Qed.
Lemma cpoly_plus_q_ap_q : forall p q, cpoly_plus_cs p q [#] q -> p [#] cpoly_zero_cs.
Proof.
intro p; pattern p in |- *; apply Ccpoly_ind_cs.
intro.
rewrite cpoly_zero_plus.
intro H.
elimtype False.
apply (ap_irreflexive _ _ H).
do 4 intro.
pattern q in |- *; apply Ccpoly_ind_cs.
rewrite cpoly_plus_zero.
auto.
do 3 intro.
rewrite cpoly_lin_plus_lin.
intros.
cut (c[+]c0 [#] c0 or cpoly_plus_cs p0 p1 [#] p1).
intros.
2: apply cpoly_lin_ap_lin_.
2: assumption.
cut (c [#] [0] or p0 [#] cpoly_zero_cs).
intro. apply _cpoly_lin_ap_zero. assumption.
elim X1; intro.
left.
apply cg_ap_cancel_rht with c0.
astepr c0. auto.
right.
generalize (X _ b); intro.
assumption.
Qed.
Lemma cpoly_p_plus_ap_p : forall p q, cpoly_plus_cs p q [#] p -> q [#] cpoly_zero.
Proof.
intros.
apply cpoly_plus_q_ap_q with p.
apply ap_wdl_unfolded with (cpoly_plus_cs p q).
assumption.
apply cpoly_plus_commutative.
Qed.
Lemma cpoly_ap_zero_plus : forall p q,
cpoly_plus_cs p q [#] cpoly_zero_cs -> p [#] cpoly_zero_cs or q [#] cpoly_zero_cs.
Proof.
intros p q; pattern p, q in |- *; apply Ccpoly_double_sym_ind0_cs.
unfold Csymmetric in |- *.
intros x y H H0.
elim H.
auto. auto.
astepl (cpoly_plus_cs y x). auto.
apply cpoly_plus_commutative.
intros p0 H.
left.
rewrite cpoly_plus_zero in H.
assumption.
intros p0 q0 c d.
rewrite cpoly_lin_plus_lin.
intros.
cut (c[+]d [#] [0] or cpoly_plus_cs p0 q0 [#] cpoly_zero_cs).
2: apply cpoly_lin_ap_zero_.
2: assumption.
clear X0.
intros H0.
elim H0; intro H1.
cut (c[+]d [#] [0][+][0]).
intro H2.
elim (cs_bin_op_strext _ _ _ _ _ _ H2); intro H3.
left.
simpl in |- *.
left.
assumption.
right.
cut (d [#] [0] or q0 [#] cpoly_zero_cs).
intro H4.
apply _cpoly_lin_ap_zero.
auto.
left.
assumption.
astepr ([0]:CR). auto.
elim (X H1); intro.
left.
cut (c [#] [0] or p0 [#] cpoly_zero_cs).
intro; apply _cpoly_lin_ap_zero.
auto.
right.
assumption.
right.
cut (d [#] [0] or q0 [#] cpoly_zero_cs).
intro.
apply _cpoly_lin_ap_zero.
auto.
right.
assumption.
Qed.
Lemma cpoly_plus_op_strext : bin_op_strext cpoly_csetoid cpoly_plus_cs.
Proof.
unfold bin_op_strext in |- *.
unfold bin_fun_strext in |- *.
intros x1 x2.
pattern x1, x2 in |- *.
apply Ccpoly_double_sym_ind0_cs.
unfold Csymmetric in |- *.
intros.
generalize (ap_symmetric_unfolded _ _ _ X0); intro H1.
generalize (X _ _ H1); intro H2.
elim H2; intro H3; generalize (ap_symmetric_unfolded _ _ _ H3); auto.
intro p; pattern p in |- *; apply Ccpoly_ind_cs.
intro; intro H.
simpl in |- *; auto.
intros s c H y1 y2.
pattern y1, y2 in |- *.
apply Ccpoly_double_ind0_cs.
intros p0 H0.
apply cpoly_ap_zero_plus.
apply H0.
intro p0.
intro H0.
elim (ap_cotransitive _ _ _ H0 cpoly_zero_cs); auto.
do 4 intro.
intros.
cut (c[+]c0 [#] d or cpoly_plus_cs s p0 [#] q).
2: apply cpoly_lin_ap_lin_; assumption.
clear X0; intro H1.
elim H1; intro H2.
cut (c[+]c0 [#] [0][+]d).
intro H3.
elim (cs_bin_op_strext _ _ _ _ _ _ H3).
intro H4.
left.
apply _cpoly_lin_ap_zero.
auto.
intro.
right.
apply _cpoly_lin_ap_lin.
auto.
astepr d. auto.
elim (H _ _ H2); auto.
intro.
left.
apply _cpoly_lin_ap_zero.
auto.
right.
apply _cpoly_lin_ap_lin.
auto.
do 7 intro.
pattern y1, y2 in |- *.
apply Ccpoly_double_ind0_cs.
intro p0; pattern p0 in |- *; apply Ccpoly_ind_cs.
auto.
intros.
cut (c[+]c0 [#] d or cpoly_plus_cs p p1 [#] q).
intro H2.
2: apply cpoly_lin_ap_lin_.
2: auto.
elim H2; intro H3.
cut (c[+]c0 [#] d[+][0]).
intro H4.
elim (cs_bin_op_strext _ _ _ _ _ _ H4).
intro.
left.
apply _cpoly_lin_ap_lin.
auto.
intro.
right.
apply _cpoly_lin_ap_zero.
auto.
astepr d. auto.
elim X with p1 cpoly_zero_cs.
intro.
left.
apply _cpoly_lin_ap_lin.
auto.
right.
apply _cpoly_lin_ap_zero.
auto.
rewrite cpoly_plus_zero.
assumption.
intro p0; pattern p0 in |- *; apply Ccpoly_ind_cs.
auto.
intros.
cut (c [#] d[+]c0 or p [#] cpoly_plus_cs q p1).
2: apply cpoly_lin_ap_lin_.
2: assumption.
clear X1; intro H1.
elim H1; intro H2.
cut (c[+][0] [#] d[+]c0).
intro H3.
elim (cs_bin_op_strext _ _ _ _ _ _ H3).
intro.
left.
unfold cpoly_linear_cs in |- *; simpl in |- *; auto.
intro.
right.
left.
apply ap_symmetric_unfolded.
assumption.
astepl c. auto.
elim X with cpoly_zero_cs p1.
intro.
left.
unfold cpoly_linear_cs in |- *; simpl in |- *; auto.
intro.
right.
right; auto.
rewrite cpoly_plus_zero.
assumption.
intros.
elim X1; intro H2.
elim (cs_bin_op_strext _ _ _ _ _ _ H2); auto.
intro.
left.
left; auto.
intro. right.
left; auto.
simpl in H2.
elim (X _ _ H2).
intro.
left; right; auto.
right; right; auto.
Qed.
Lemma cpoly_plus_op_wd : bin_op_wd cpoly_csetoid cpoly_plus_cs.
Proof.
unfold bin_op_wd in |- *.
apply bin_fun_strext_imp_wd.
exact cpoly_plus_op_strext.
Qed.
Definition cpoly_plus_op := Build_CSetoid_bin_op _ _ cpoly_plus_op_strext.
Lemma cpoly_plus_associative : associative cpoly_plus_op.
Proof.
unfold associative in |- *.
intros p q r.
change (cpoly_plus_cs p (cpoly_plus_cs q r) [=] cpoly_plus_cs (cpoly_plus_cs p q) r) in |- *.
pattern p, q, r in |- *; apply cpoly_triple_comp_ind.
intros.
apply eq_transitive_unfolded with (cpoly_plus_cs p1 (cpoly_plus_cs q1 r1)).
apply eq_symmetric_unfolded.
apply cpoly_plus_op_wd.
assumption.
apply cpoly_plus_op_wd.
assumption.
assumption.
astepl (cpoly_plus_cs (cpoly_plus_cs p1 q1) r1).
apply cpoly_plus_op_wd.
apply cpoly_plus_op_wd.
assumption.
assumption.
assumption.
simpl in |- *.
auto.
intros.
repeat rewrite cpoly_lin_plus_lin.
apply _cpoly_lin_eq_lin.
split.
algebra.
assumption.
Qed.