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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
(* $Id$ *)
Require Import Setoid_ring_theory.
Require Import Quote.
Set Implicit Arguments.
Unset Boxed Definitions.
Lemma index_eq_prop : forall n m:index, Is_true (index_eq n m) -> n = m.
Proof.
simple induction n; simple induction m; simpl in |- *;
try reflexivity || contradiction.
intros; rewrite (H i0); trivial.
intros; rewrite (H i0); trivial.
Qed.
Section setoid.
Variable A : Type.
Variable Aequiv : A -> A -> Prop.
Variable Aplus : A -> A -> A.
Variable Amult : A -> A -> A.
Variable Aone : A.
Variable Azero : A.
Variable Aopp : A -> A.
Variable Aeq : A -> A -> bool.
Variable S : Setoid_Theory A Aequiv.
Add Setoid A Aequiv S as Asetoid.
Variable plus_morph :
forall a a0:A, Aequiv a a0 ->
forall a1 a2:A, Aequiv a1 a2 ->
Aequiv (Aplus a a1) (Aplus a0 a2).
Variable mult_morph :
forall a a0:A, Aequiv a a0 ->
forall a1 a2:A, Aequiv a1 a2 ->
Aequiv (Amult a a1) (Amult a0 a2).
Variable opp_morph : forall a a0:A, Aequiv a a0 -> Aequiv (Aopp a) (Aopp a0).
Add Morphism Aplus : Aplus_ext.
intros; apply plus_morph; assumption.
Qed.
Add Morphism Amult : Amult_ext.
intros; apply mult_morph; assumption.
Qed.
Add Morphism Aopp : Aopp_ext.
exact opp_morph.
Qed.
Let equiv_refl := Seq_refl A Aequiv S.
Let equiv_sym := Seq_sym A Aequiv S.
Let equiv_trans := Seq_trans A Aequiv S.
Hint Resolve equiv_refl equiv_trans.
Hint Immediate equiv_sym.
Section semi_setoid_rings.
(* Section definitions. *)
(******************************************)
(* Normal abtract Polynomials *)
(******************************************)
(* DEFINITIONS :
- A varlist is a sorted product of one or more variables : x, x*y*z
- A monom is a constant, a varlist or the product of a constant by a varlist
variables. 2*x*y, x*y*z, 3 are monoms : 2*3, x*3*y, 4*x*3 are NOT.
- A canonical sum is either a monom or an ordered sum of monoms
(the order on monoms is defined later)
- A normal polynomial it either a constant or a canonical sum or a constant
plus a canonical sum
*)
(* varlist is isomorphic to (list var), but we built a special inductive
for efficiency *)
Inductive varlist : Type :=
| Nil_var : varlist
| Cons_var : index -> varlist -> varlist.
Inductive canonical_sum : Type :=
| Nil_monom : canonical_sum
| Cons_monom : A -> varlist -> canonical_sum -> canonical_sum
| Cons_varlist : varlist -> canonical_sum -> canonical_sum.
(* Order on monoms *)
(* That's the lexicographic order on varlist, extended by :
- A constant is less than every monom
- The relation between two varlist is preserved by multiplication by a
constant.
Examples :
3 < x < y
x*y < x*y*y*z
2*x*y < x*y*y*z
x*y < 54*x*y*y*z
4*x*y < 59*x*y*y*z
*)
Fixpoint varlist_eq (x y:varlist) {struct y} : bool :=
match x, y with
| Nil_var, Nil_var => true
| Cons_var i xrest, Cons_var j yrest =>
andb (index_eq i j) (varlist_eq xrest yrest)
| _, _ => false
end.
Fixpoint varlist_lt (x y:varlist) {struct y} : bool :=
match x, y with
| Nil_var, Cons_var _ _ => true
| Cons_var i xrest, Cons_var j yrest =>
if index_lt i j
then true
else andb (index_eq i j) (varlist_lt xrest yrest)
| _, _ => false
end.
(* merges two variables lists *)
Fixpoint varlist_merge (l1:varlist) : varlist -> varlist :=
match l1 with
| Cons_var v1 t1 =>
(fix vm_aux (l2:varlist) : varlist :=
match l2 with
| Cons_var v2 t2 =>
if index_lt v1 v2
then Cons_var v1 (varlist_merge t1 l2)
else Cons_var v2 (vm_aux t2)
| Nil_var => l1
end)
| Nil_var => fun l2 => l2
end.
(* returns the sum of two canonical sums *)
Fixpoint canonical_sum_merge (s1:canonical_sum) :
canonical_sum -> canonical_sum :=
match s1 with
| Cons_monom c1 l1 t1 =>
(fix csm_aux (s2:canonical_sum) : canonical_sum :=
match s2 with
| Cons_monom c2 l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus c1 c2) l1 (canonical_sum_merge t1 t2)
else
if varlist_lt l1 l2
then Cons_monom c1 l1 (canonical_sum_merge t1 s2)
else Cons_monom c2 l2 (csm_aux t2)
| Cons_varlist l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus c1 Aone) l1 (canonical_sum_merge t1 t2)
else
if varlist_lt l1 l2
then Cons_monom c1 l1 (canonical_sum_merge t1 s2)
else Cons_varlist l2 (csm_aux t2)
| Nil_monom => s1
end)
| Cons_varlist l1 t1 =>
(fix csm_aux2 (s2:canonical_sum) : canonical_sum :=
match s2 with
| Cons_monom c2 l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus Aone c2) l1 (canonical_sum_merge t1 t2)
else
if varlist_lt l1 l2
then Cons_varlist l1 (canonical_sum_merge t1 s2)
else Cons_monom c2 l2 (csm_aux2 t2)
| Cons_varlist l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus Aone Aone) l1 (canonical_sum_merge t1 t2)
else
if varlist_lt l1 l2
then Cons_varlist l1 (canonical_sum_merge t1 s2)
else Cons_varlist l2 (csm_aux2 t2)
| Nil_monom => s1
end)
| Nil_monom => fun s2 => s2
end.
(* Insertion of a monom in a canonical sum *)
Fixpoint monom_insert (c1:A) (l1:varlist) (s2:canonical_sum) {struct s2} :
canonical_sum :=
match s2 with
| Cons_monom c2 l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus c1 c2) l1 t2
else
if varlist_lt l1 l2
then Cons_monom c1 l1 s2
else Cons_monom c2 l2 (monom_insert c1 l1 t2)
| Cons_varlist l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus c1 Aone) l1 t2
else
if varlist_lt l1 l2
then Cons_monom c1 l1 s2
else Cons_varlist l2 (monom_insert c1 l1 t2)
| Nil_monom => Cons_monom c1 l1 Nil_monom
end.
Fixpoint varlist_insert (l1:varlist) (s2:canonical_sum) {struct s2} :
canonical_sum :=
match s2 with
| Cons_monom c2 l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus Aone c2) l1 t2
else
if varlist_lt l1 l2
then Cons_varlist l1 s2
else Cons_monom c2 l2 (varlist_insert l1 t2)
| Cons_varlist l2 t2 =>
if varlist_eq l1 l2
then Cons_monom (Aplus Aone Aone) l1 t2
else
if varlist_lt l1 l2
then Cons_varlist l1 s2
else Cons_varlist l2 (varlist_insert l1 t2)
| Nil_monom => Cons_varlist l1 Nil_monom
end.
(* Computes c0*s *)
Fixpoint canonical_sum_scalar (c0:A) (s:canonical_sum) {struct s} :
canonical_sum :=
match s with
| Cons_monom c l t => Cons_monom (Amult c0 c) l (canonical_sum_scalar c0 t)
| Cons_varlist l t => Cons_monom c0 l (canonical_sum_scalar c0 t)
| Nil_monom => Nil_monom
end.
(* Computes l0*s *)
Fixpoint canonical_sum_scalar2 (l0:varlist) (s:canonical_sum) {struct s} :
canonical_sum :=
match s with
| Cons_monom c l t =>
monom_insert c (varlist_merge l0 l) (canonical_sum_scalar2 l0 t)
| Cons_varlist l t =>
varlist_insert (varlist_merge l0 l) (canonical_sum_scalar2 l0 t)
| Nil_monom => Nil_monom
end.
(* Computes c0*l0*s *)
Fixpoint canonical_sum_scalar3 (c0:A) (l0:varlist)
(s:canonical_sum) {struct s} : canonical_sum :=
match s with
| Cons_monom c l t =>
monom_insert (Amult c0 c) (varlist_merge l0 l)
(canonical_sum_scalar3 c0 l0 t)
| Cons_varlist l t =>
monom_insert c0 (varlist_merge l0 l) (canonical_sum_scalar3 c0 l0 t)
| Nil_monom => Nil_monom
end.
(* returns the product of two canonical sums *)
Fixpoint canonical_sum_prod (s1 s2:canonical_sum) {struct s1} :
canonical_sum :=
match s1 with
| Cons_monom c1 l1 t1 =>
canonical_sum_merge (canonical_sum_scalar3 c1 l1 s2)
(canonical_sum_prod t1 s2)
| Cons_varlist l1 t1 =>
canonical_sum_merge (canonical_sum_scalar2 l1 s2)
(canonical_sum_prod t1 s2)
| Nil_monom => Nil_monom
end.
(* The type to represent concrete semi-setoid-ring polynomials *)
Inductive setspolynomial : Type :=
| SetSPvar : index -> setspolynomial
| SetSPconst : A -> setspolynomial
| SetSPplus : setspolynomial -> setspolynomial -> setspolynomial
| SetSPmult : setspolynomial -> setspolynomial -> setspolynomial.
Fixpoint setspolynomial_normalize (p:setspolynomial) : canonical_sum :=
match p with
| SetSPplus l r =>
canonical_sum_merge (setspolynomial_normalize l)
(setspolynomial_normalize r)
| SetSPmult l r =>
canonical_sum_prod (setspolynomial_normalize l)
(setspolynomial_normalize r)
| SetSPconst c => Cons_monom c Nil_var Nil_monom
| SetSPvar i => Cons_varlist (Cons_var i Nil_var) Nil_monom
end.
Fixpoint canonical_sum_simplify (s:canonical_sum) : canonical_sum :=
match s with
| Cons_monom c l t =>
if Aeq c Azero
then canonical_sum_simplify t
else
if Aeq c Aone
then Cons_varlist l (canonical_sum_simplify t)
else Cons_monom c l (canonical_sum_simplify t)
| Cons_varlist l t => Cons_varlist l (canonical_sum_simplify t)
| Nil_monom => Nil_monom
end.
Definition setspolynomial_simplify (x:setspolynomial) :=
canonical_sum_simplify (setspolynomial_normalize x).
Variable vm : varmap A.
Definition interp_var (i:index) := varmap_find Azero i vm.
Definition ivl_aux :=
(fix ivl_aux (x:index) (t:varlist) {struct t} : A :=
match t with
| Nil_var => interp_var x
| Cons_var x' t' => Amult (interp_var x) (ivl_aux x' t')
end).
Definition interp_vl (l:varlist) :=
match l with
| Nil_var => Aone
| Cons_var x t => ivl_aux x t
end.
Definition interp_m (c:A) (l:varlist) :=
match l with
| Nil_var => c
| Cons_var x t => Amult c (ivl_aux x t)
end.
Definition ics_aux :=
(fix ics_aux (a:A) (s:canonical_sum) {struct s} : A :=
match s with
| Nil_monom => a
| Cons_varlist l t => Aplus a (ics_aux (interp_vl l) t)
| Cons_monom c l t => Aplus a (ics_aux (interp_m c l) t)
end).
Definition interp_setcs (s:canonical_sum) : A :=
match s with
| Nil_monom => Azero
| Cons_varlist l t => ics_aux (interp_vl l) t
| Cons_monom c l t => ics_aux (interp_m c l) t
end.
Fixpoint interp_setsp (p:setspolynomial) : A :=
match p with
| SetSPconst c => c
| SetSPvar i => interp_var i
| SetSPplus p1 p2 => Aplus (interp_setsp p1) (interp_setsp p2)
| SetSPmult p1 p2 => Amult (interp_setsp p1) (interp_setsp p2)
end.
(* End interpretation. *)
Unset Implicit Arguments.
(* Section properties. *)
Variable T : Semi_Setoid_Ring_Theory Aequiv Aplus Amult Aone Azero Aeq.
Hint Resolve (SSR_plus_comm T).
Hint Resolve (SSR_plus_assoc T).
Hint Resolve (SSR_plus_assoc2 S T).
Hint Resolve (SSR_mult_comm T).
Hint Resolve (SSR_mult_assoc T).
Hint Resolve (SSR_mult_assoc2 S T).
Hint Resolve (SSR_plus_zero_left T).
Hint Resolve (SSR_plus_zero_left2 S T).
Hint Resolve (SSR_mult_one_left T).
Hint Resolve (SSR_mult_one_left2 S T).
Hint Resolve (SSR_mult_zero_left T).
Hint Resolve (SSR_mult_zero_left2 S T).
Hint Resolve (SSR_distr_left T).
Hint Resolve (SSR_distr_left2 S T).
Hint Resolve (SSR_plus_reg_left T).
Hint Resolve (SSR_plus_permute S plus_morph T).
Hint Resolve (SSR_mult_permute S mult_morph T).
Hint Resolve (SSR_distr_right S plus_morph T).
Hint Resolve (SSR_distr_right2 S plus_morph T).
Hint Resolve (SSR_mult_zero_right S T).
Hint Resolve (SSR_mult_zero_right2 S T).
Hint Resolve (SSR_plus_zero_right S T).
Hint Resolve (SSR_plus_zero_right2 S T).
Hint Resolve (SSR_mult_one_right S T).
Hint Resolve (SSR_mult_one_right2 S T).
Hint Resolve (SSR_plus_reg_right S T).
Hint Resolve refl_equal sym_equal trans_equal.
(*Hints Resolve refl_eqT sym_eqT trans_eqT.*)
Hint Immediate T.
Lemma varlist_eq_prop : forall x y:varlist, Is_true (varlist_eq x y) -> x = y.
Proof.
simple induction x; simple induction y; contradiction || (try reflexivity).
simpl in |- *; intros.
generalize (andb_prop2 _ _ H1); intros; elim H2; intros.
rewrite (index_eq_prop _ _ H3); rewrite (H v0 H4); reflexivity.
Qed.
Remark ivl_aux_ok :
forall (v:varlist) (i:index),
Aequiv (ivl_aux i v) (Amult (interp_var i) (interp_vl v)).
Proof.
simple induction v; simpl in |- *; intros.
trivial.
rewrite (H i); trivial.
Qed.
Lemma varlist_merge_ok :
forall x y:varlist,
Aequiv (interp_vl (varlist_merge x y)) (Amult (interp_vl x) (interp_vl y)).
Proof.
simple induction x.
simpl in |- *; trivial.
simple induction y.
simpl in |- *; trivial.
simpl in |- *; intros.
elim (index_lt i i0); simpl in |- *; intros.
rewrite (ivl_aux_ok v i).
rewrite (ivl_aux_ok v0 i0).
rewrite (ivl_aux_ok (varlist_merge v (Cons_var i0 v0)) i).
rewrite (H (Cons_var i0 v0)).
simpl in |- *.
rewrite (ivl_aux_ok v0 i0).
eauto.
rewrite (ivl_aux_ok v i).
rewrite (ivl_aux_ok v0 i0).
rewrite
(ivl_aux_ok
((fix vm_aux (l2:varlist) : varlist :=
match l2 with
| Nil_var => Cons_var i v
| Cons_var v2 t2 =>
if index_lt i v2
then Cons_var i (varlist_merge v l2)
else Cons_var v2 (vm_aux t2)
end) v0) i0).
rewrite H0.
rewrite (ivl_aux_ok v i).
eauto.
Qed.
Remark ics_aux_ok :
forall (x:A) (s:canonical_sum),
Aequiv (ics_aux x s) (Aplus x (interp_setcs s)).
Proof.
simple induction s; simpl in |- *; intros; trivial.
Qed.
Remark interp_m_ok :
forall (x:A) (l:varlist), Aequiv (interp_m x l) (Amult x (interp_vl l)).
Proof.
destruct l as [| i v]; trivial.
Qed.
Hint Resolve ivl_aux_ok.
Hint Resolve ics_aux_ok.
Hint Resolve interp_m_ok.
(* Hints Resolve ivl_aux_ok ics_aux_ok interp_m_ok. *)
Lemma canonical_sum_merge_ok :
forall x y:canonical_sum,
Aequiv (interp_setcs (canonical_sum_merge x y))
(Aplus (interp_setcs x) (interp_setcs y)).
Proof.
simple induction x; simpl in |- *.
trivial.
simple induction y; simpl in |- *; intros.
eauto.
generalize (varlist_eq_prop v v0).
elim (varlist_eq v v0).
intros; rewrite (H1 I).
simpl in |- *.
rewrite (ics_aux_ok (interp_m a v0) c).
rewrite (ics_aux_ok (interp_m a0 v0) c0).
rewrite (ics_aux_ok (interp_m (Aplus a a0) v0) (canonical_sum_merge c c0)).
rewrite (H c0).
rewrite (interp_m_ok (Aplus a a0) v0).
rewrite (interp_m_ok a v0).
rewrite (interp_m_ok a0 v0).
setoid_replace (Amult (Aplus a a0) (interp_vl v0)) with
(Aplus (Amult a (interp_vl v0)) (Amult a0 (interp_vl v0)));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (Amult a (interp_vl v0)) (Amult a0 (interp_vl v0)))
(Aplus (interp_setcs c) (interp_setcs c0))) with
(Aplus (Amult a (interp_vl v0))
(Aplus (Amult a0 (interp_vl v0))
(Aplus (interp_setcs c) (interp_setcs c0))));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (Amult a (interp_vl v0)) (interp_setcs c))
(Aplus (Amult a0 (interp_vl v0)) (interp_setcs c0))) with
(Aplus (Amult a (interp_vl v0))
(Aplus (interp_setcs c)
(Aplus (Amult a0 (interp_vl v0)) (interp_setcs c0))));
[ idtac | trivial ].
auto.
elim (varlist_lt v v0); simpl in |- *.
intro.
rewrite
(ics_aux_ok (interp_m a v) (canonical_sum_merge c (Cons_monom a0 v0 c0)))
.
rewrite (ics_aux_ok (interp_m a v) c).
rewrite (ics_aux_ok (interp_m a0 v0) c0).
rewrite (H (Cons_monom a0 v0 c0)); simpl in |- *.
rewrite (ics_aux_ok (interp_m a0 v0) c0); auto.
intro.
rewrite
(ics_aux_ok (interp_m a0 v0)
((fix csm_aux (s2:canonical_sum) : canonical_sum :=
match s2 with
| Nil_monom => Cons_monom a v c
| Cons_monom c2 l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus a c2) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_monom a v (canonical_sum_merge c s2)
else Cons_monom c2 l2 (csm_aux t2)
| Cons_varlist l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus a Aone) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_monom a v (canonical_sum_merge c s2)
else Cons_varlist l2 (csm_aux t2)
end) c0)).
rewrite H0.
rewrite (ics_aux_ok (interp_m a v) c);
rewrite (ics_aux_ok (interp_m a0 v0) c0); simpl in |- *;
auto.
generalize (varlist_eq_prop v v0).
elim (varlist_eq v v0).
intros; rewrite (H1 I).
simpl in |- *.
rewrite (ics_aux_ok (interp_m (Aplus a Aone) v0) (canonical_sum_merge c c0));
rewrite (ics_aux_ok (interp_m a v0) c);
rewrite (ics_aux_ok (interp_vl v0) c0).
rewrite (H c0).
rewrite (interp_m_ok (Aplus a Aone) v0).
rewrite (interp_m_ok a v0).
setoid_replace (Amult (Aplus a Aone) (interp_vl v0)) with
(Aplus (Amult a (interp_vl v0)) (Amult Aone (interp_vl v0)));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (Amult a (interp_vl v0)) (Amult Aone (interp_vl v0)))
(Aplus (interp_setcs c) (interp_setcs c0))) with
(Aplus (Amult a (interp_vl v0))
(Aplus (Amult Aone (interp_vl v0))
(Aplus (interp_setcs c) (interp_setcs c0))));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (Amult a (interp_vl v0)) (interp_setcs c))
(Aplus (interp_vl v0) (interp_setcs c0))) with
(Aplus (Amult a (interp_vl v0))
(Aplus (interp_setcs c) (Aplus (interp_vl v0) (interp_setcs c0))));
[ idtac | trivial ].
setoid_replace (Amult Aone (interp_vl v0)) with (interp_vl v0);
[ idtac | trivial ].
auto.
elim (varlist_lt v v0); simpl in |- *.
intro.
rewrite
(ics_aux_ok (interp_m a v) (canonical_sum_merge c (Cons_varlist v0 c0)))
; rewrite (ics_aux_ok (interp_m a v) c);
rewrite (ics_aux_ok (interp_vl v0) c0).
rewrite (H (Cons_varlist v0 c0)); simpl in |- *.
rewrite (ics_aux_ok (interp_vl v0) c0).
auto.
intro.
rewrite
(ics_aux_ok (interp_vl v0)
((fix csm_aux (s2:canonical_sum) : canonical_sum :=
match s2 with
| Nil_monom => Cons_monom a v c
| Cons_monom c2 l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus a c2) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_monom a v (canonical_sum_merge c s2)
else Cons_monom c2 l2 (csm_aux t2)
| Cons_varlist l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus a Aone) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_monom a v (canonical_sum_merge c s2)
else Cons_varlist l2 (csm_aux t2)
end) c0)); rewrite H0.
rewrite (ics_aux_ok (interp_m a v) c); rewrite (ics_aux_ok (interp_vl v0) c0);
simpl in |- *.
auto.
simple induction y; simpl in |- *; intros.
trivial.
generalize (varlist_eq_prop v v0).
elim (varlist_eq v v0).
intros; rewrite (H1 I).
simpl in |- *.
rewrite (ics_aux_ok (interp_m (Aplus Aone a) v0) (canonical_sum_merge c c0));
rewrite (ics_aux_ok (interp_vl v0) c);
rewrite (ics_aux_ok (interp_m a v0) c0); rewrite (H c0).
rewrite (interp_m_ok (Aplus Aone a) v0); rewrite (interp_m_ok a v0).
setoid_replace (Amult (Aplus Aone a) (interp_vl v0)) with
(Aplus (Amult Aone (interp_vl v0)) (Amult a (interp_vl v0)));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (Amult Aone (interp_vl v0)) (Amult a (interp_vl v0)))
(Aplus (interp_setcs c) (interp_setcs c0))) with
(Aplus (Amult Aone (interp_vl v0))
(Aplus (Amult a (interp_vl v0))
(Aplus (interp_setcs c) (interp_setcs c0))));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (interp_vl v0) (interp_setcs c))
(Aplus (Amult a (interp_vl v0)) (interp_setcs c0))) with
(Aplus (interp_vl v0)
(Aplus (interp_setcs c)
(Aplus (Amult a (interp_vl v0)) (interp_setcs c0))));
[ idtac | trivial ].
auto.
elim (varlist_lt v v0); simpl in |- *; intros.
rewrite
(ics_aux_ok (interp_vl v) (canonical_sum_merge c (Cons_monom a v0 c0)))
; rewrite (ics_aux_ok (interp_vl v) c);
rewrite (ics_aux_ok (interp_m a v0) c0).
rewrite (H (Cons_monom a v0 c0)); simpl in |- *.
rewrite (ics_aux_ok (interp_m a v0) c0); auto.
rewrite
(ics_aux_ok (interp_m a v0)
((fix csm_aux2 (s2:canonical_sum) : canonical_sum :=
match s2 with
| Nil_monom => Cons_varlist v c
| Cons_monom c2 l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus Aone c2) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_varlist v (canonical_sum_merge c s2)
else Cons_monom c2 l2 (csm_aux2 t2)
| Cons_varlist l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus Aone Aone) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_varlist v (canonical_sum_merge c s2)
else Cons_varlist l2 (csm_aux2 t2)
end) c0)); rewrite H0.
rewrite (ics_aux_ok (interp_vl v) c); rewrite (ics_aux_ok (interp_m a v0) c0);
simpl in |- *; auto.
generalize (varlist_eq_prop v v0).
elim (varlist_eq v v0); intros.
rewrite (H1 I); simpl in |- *.
rewrite
(ics_aux_ok (interp_m (Aplus Aone Aone) v0) (canonical_sum_merge c c0))
; rewrite (ics_aux_ok (interp_vl v0) c);
rewrite (ics_aux_ok (interp_vl v0) c0); rewrite (H c0).
rewrite (interp_m_ok (Aplus Aone Aone) v0).
setoid_replace (Amult (Aplus Aone Aone) (interp_vl v0)) with
(Aplus (Amult Aone (interp_vl v0)) (Amult Aone (interp_vl v0)));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (Amult Aone (interp_vl v0)) (Amult Aone (interp_vl v0)))
(Aplus (interp_setcs c) (interp_setcs c0))) with
(Aplus (Amult Aone (interp_vl v0))
(Aplus (Amult Aone (interp_vl v0))
(Aplus (interp_setcs c) (interp_setcs c0))));
[ idtac | trivial ].
setoid_replace
(Aplus (Aplus (interp_vl v0) (interp_setcs c))
(Aplus (interp_vl v0) (interp_setcs c0))) with
(Aplus (interp_vl v0)
(Aplus (interp_setcs c) (Aplus (interp_vl v0) (interp_setcs c0))));
[ idtac | trivial ].
setoid_replace (Amult Aone (interp_vl v0)) with (interp_vl v0); auto.
elim (varlist_lt v v0); simpl in |- *.
rewrite
(ics_aux_ok (interp_vl v) (canonical_sum_merge c (Cons_varlist v0 c0)))
; rewrite (ics_aux_ok (interp_vl v) c);
rewrite (ics_aux_ok (interp_vl v0) c0); rewrite (H (Cons_varlist v0 c0));
simpl in |- *.
rewrite (ics_aux_ok (interp_vl v0) c0); auto.
rewrite
(ics_aux_ok (interp_vl v0)
((fix csm_aux2 (s2:canonical_sum) : canonical_sum :=
match s2 with
| Nil_monom => Cons_varlist v c
| Cons_monom c2 l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus Aone c2) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_varlist v (canonical_sum_merge c s2)
else Cons_monom c2 l2 (csm_aux2 t2)
| Cons_varlist l2 t2 =>
if varlist_eq v l2
then Cons_monom (Aplus Aone Aone) v (canonical_sum_merge c t2)
else
if varlist_lt v l2
then Cons_varlist v (canonical_sum_merge c s2)
else Cons_varlist l2 (csm_aux2 t2)
end) c0)); rewrite H0.
rewrite (ics_aux_ok (interp_vl v) c); rewrite (ics_aux_ok (interp_vl v0) c0);
simpl in |- *; auto.
Qed.
Lemma monom_insert_ok :
forall (a:A) (l:varlist) (s:canonical_sum),
Aequiv (interp_setcs (monom_insert a l s))
(Aplus (Amult a (interp_vl l)) (interp_setcs s)).
Proof.
simple induction s; intros.
simpl in |- *; rewrite (interp_m_ok a l); trivial.
simpl in |- *; generalize (varlist_eq_prop l v); elim (varlist_eq l v).
intro Hr; rewrite (Hr I); simpl in |- *.
rewrite (ics_aux_ok (interp_m (Aplus a a0) v) c);
rewrite (ics_aux_ok (interp_m a0 v) c).
rewrite (interp_m_ok (Aplus a a0) v); rewrite (interp_m_ok a0 v).
setoid_replace (Amult (Aplus a a0) (interp_vl v)) with
(Aplus (Amult a (interp_vl v)) (Amult a0 (interp_vl v)));
[ idtac | trivial ].
auto.
elim (varlist_lt l v); simpl in |- *; intros.
rewrite (ics_aux_ok (interp_m a0 v) c).
rewrite (interp_m_ok a0 v); rewrite (interp_m_ok a l).
auto.
rewrite (ics_aux_ok (interp_m a0 v) (monom_insert a l c));
rewrite (ics_aux_ok (interp_m a0 v) c); rewrite H.
auto.
simpl in |- *.
generalize (varlist_eq_prop l v); elim (varlist_eq l v).
intro Hr; rewrite (Hr I); simpl in |- *.
rewrite (ics_aux_ok (interp_m (Aplus a Aone) v) c);
rewrite (ics_aux_ok (interp_vl v) c).
rewrite (interp_m_ok (Aplus a Aone) v).
setoid_replace (Amult (Aplus a Aone) (interp_vl v)) with
(Aplus (Amult a (interp_vl v)) (Amult Aone (interp_vl v)));
[ idtac | trivial ].
setoid_replace (Amult Aone (interp_vl v)) with (interp_vl v);
[ idtac | trivial ].
auto.
elim (varlist_lt l v); simpl in |- *; intros; auto.
rewrite (ics_aux_ok (interp_vl v) (monom_insert a l c)); rewrite H.
rewrite (ics_aux_ok (interp_vl v) c); auto.
Qed.
Lemma varlist_insert_ok :
forall (l:varlist) (s:canonical_sum),
Aequiv (interp_setcs (varlist_insert l s))
(Aplus (interp_vl l) (interp_setcs s)).
Proof.
simple induction s; simpl in |- *; intros.
trivial.
generalize (varlist_eq_prop l v); elim (varlist_eq l v).
intro Hr; rewrite (Hr I); simpl in |- *.
rewrite (ics_aux_ok (interp_m (Aplus Aone a) v) c);
rewrite (ics_aux_ok (interp_m a v) c).
rewrite (interp_m_ok (Aplus Aone a) v); rewrite (interp_m_ok a v).
setoid_replace (Amult (Aplus Aone a) (interp_vl v)) with
(Aplus (Amult Aone (interp_vl v)) (Amult a (interp_vl v)));
[ idtac | trivial ].
setoid_replace (Amult Aone (interp_vl v)) with (interp_vl v); auto.
elim (varlist_lt l v); simpl in |- *; intros; auto.
rewrite (ics_aux_ok (interp_m a v) (varlist_insert l c));
rewrite (ics_aux_ok (interp_m a v) c).
rewrite (interp_m_ok a v).
rewrite H; auto.
generalize (varlist_eq_prop l v); elim (varlist_eq l v).
intro Hr; rewrite (Hr I); simpl in |- *.
rewrite (ics_aux_ok (interp_m (Aplus Aone Aone) v) c);
rewrite (ics_aux_ok (interp_vl v) c).
rewrite (interp_m_ok (Aplus Aone Aone) v).
setoid_replace (Amult (Aplus Aone Aone) (interp_vl v)) with
(Aplus (Amult Aone (interp_vl v)) (Amult Aone (interp_vl v)));
[ idtac | trivial ].
setoid_replace (Amult Aone (interp_vl v)) with (interp_vl v); auto.
elim (varlist_lt l v); simpl in |- *; intros; auto.
rewrite (ics_aux_ok (interp_vl v) (varlist_insert l c)).
rewrite H.
rewrite (ics_aux_ok (interp_vl v) c); auto.
Qed.
Lemma canonical_sum_scalar_ok :
forall (a:A) (s:canonical_sum),
Aequiv (interp_setcs (canonical_sum_scalar a s))
(Amult a (interp_setcs s)).
Proof.
simple induction s; simpl in |- *; intros.
trivial.
rewrite (ics_aux_ok (interp_m (Amult a a0) v) (canonical_sum_scalar a c));
rewrite (ics_aux_ok (interp_m a0 v) c).
rewrite (interp_m_ok (Amult a a0) v); rewrite (interp_m_ok a0 v).
rewrite H.
setoid_replace (Amult a (Aplus (Amult a0 (interp_vl v)) (interp_setcs c)))
with (Aplus (Amult a (Amult a0 (interp_vl v))) (Amult a (interp_setcs c)));
[ idtac | trivial ].
auto.
rewrite (ics_aux_ok (interp_m a v) (canonical_sum_scalar a c));
rewrite (ics_aux_ok (interp_vl v) c); rewrite H.
rewrite (interp_m_ok a v).
auto.
Qed.
Lemma canonical_sum_scalar2_ok :
forall (l:varlist) (s:canonical_sum),
Aequiv (interp_setcs (canonical_sum_scalar2 l s))
(Amult (interp_vl l) (interp_setcs s)).
Proof.
simple induction s; simpl in |- *; intros; auto.
rewrite (monom_insert_ok a (varlist_merge l v) (canonical_sum_scalar2 l c)).
rewrite (ics_aux_ok (interp_m a v) c).
rewrite (interp_m_ok a v).
rewrite H.
rewrite (varlist_merge_ok l v).
setoid_replace
(Amult (interp_vl l) (Aplus (Amult a (interp_vl v)) (interp_setcs c))) with
(Aplus (Amult (interp_vl l) (Amult a (interp_vl v)))
(Amult (interp_vl l) (interp_setcs c)));
[ idtac | trivial ].
auto.
rewrite (varlist_insert_ok (varlist_merge l v) (canonical_sum_scalar2 l c)).
rewrite (ics_aux_ok (interp_vl v) c).
rewrite H.
rewrite (varlist_merge_ok l v).
auto.
Qed.
Lemma canonical_sum_scalar3_ok :
forall (c:A) (l:varlist) (s:canonical_sum),
Aequiv (interp_setcs (canonical_sum_scalar3 c l s))
(Amult c (Amult (interp_vl l) (interp_setcs s))).
Proof.
simple induction s; simpl in |- *; intros.
rewrite (SSR_mult_zero_right S T (interp_vl l)).
auto.
rewrite
(monom_insert_ok (Amult c a) (varlist_merge l v)
(canonical_sum_scalar3 c l c0)).
rewrite (ics_aux_ok (interp_m a v) c0).
rewrite (interp_m_ok a v).
rewrite H.
rewrite (varlist_merge_ok l v).
setoid_replace
(Amult (interp_vl l) (Aplus (Amult a (interp_vl v)) (interp_setcs c0))) with
(Aplus (Amult (interp_vl l) (Amult a (interp_vl v)))
(Amult (interp_vl l) (interp_setcs c0)));
[ idtac | trivial ].
setoid_replace
(Amult c
(Aplus (Amult (interp_vl l) (Amult a (interp_vl v)))
(Amult (interp_vl l) (interp_setcs c0)))) with
(Aplus (Amult c (Amult (interp_vl l) (Amult a (interp_vl v))))
(Amult c (Amult (interp_vl l) (interp_setcs c0))));
[ idtac | trivial ].
setoid_replace (Amult (Amult c a) (Amult (interp_vl l) (interp_vl v))) with
(Amult c (Amult a (Amult (interp_vl l) (interp_vl v))));
[ idtac | trivial ].
auto.
rewrite
(monom_insert_ok c (varlist_merge l v) (canonical_sum_scalar3 c l c0))
.
rewrite (ics_aux_ok (interp_vl v) c0).
rewrite H.
rewrite (varlist_merge_ok l v).
setoid_replace
(Aplus (Amult c (Amult (interp_vl l) (interp_vl v)))
(Amult c (Amult (interp_vl l) (interp_setcs c0)))) with
(Amult c
(Aplus (Amult (interp_vl l) (interp_vl v))
(Amult (interp_vl l) (interp_setcs c0))));
[ idtac | trivial ].
auto.
Qed.
Lemma canonical_sum_prod_ok :
forall x y:canonical_sum,
Aequiv (interp_setcs (canonical_sum_prod x y))
(Amult (interp_setcs x) (interp_setcs y)).
Proof.
simple induction x; simpl in |- *; intros.
trivial.
rewrite
(canonical_sum_merge_ok (canonical_sum_scalar3 a v y)
(canonical_sum_prod c y)).
rewrite (canonical_sum_scalar3_ok a v y).
rewrite (ics_aux_ok (interp_m a v) c).
rewrite (interp_m_ok a v).
rewrite (H y).
setoid_replace (Amult a (Amult (interp_vl v) (interp_setcs y))) with
(Amult (Amult a (interp_vl v)) (interp_setcs y));
[ idtac | trivial ].
setoid_replace
(Amult (Aplus (Amult a (interp_vl v)) (interp_setcs c)) (interp_setcs y))
with
(Aplus (Amult (Amult a (interp_vl v)) (interp_setcs y))
(Amult (interp_setcs c) (interp_setcs y)));
[ idtac | trivial ].
trivial.
rewrite
(canonical_sum_merge_ok (canonical_sum_scalar2 v y) (canonical_sum_prod c y))
.
rewrite (canonical_sum_scalar2_ok v y).
rewrite (ics_aux_ok (interp_vl v) c).
rewrite (H y).
trivial.
Qed.
Theorem setspolynomial_normalize_ok :
forall p:setspolynomial,
Aequiv (interp_setcs (setspolynomial_normalize p)) (interp_setsp p).
Proof.
simple induction p; simpl in |- *; intros; trivial.
rewrite
(canonical_sum_merge_ok (setspolynomial_normalize s)
(setspolynomial_normalize s0)).
rewrite H; rewrite H0; trivial.
rewrite
(canonical_sum_prod_ok (setspolynomial_normalize s)
(setspolynomial_normalize s0)).
rewrite H; rewrite H0; trivial.
Qed.
Lemma canonical_sum_simplify_ok :
forall s:canonical_sum,
Aequiv (interp_setcs (canonical_sum_simplify s)) (interp_setcs s).
Proof.
simple induction s; simpl in |- *; intros.
trivial.
generalize (SSR_eq_prop T a Azero).
elim (Aeq a Azero).
simpl in |- *.
intros.
rewrite (ics_aux_ok (interp_m a v) c).
rewrite (interp_m_ok a v).
rewrite (H0 I).
setoid_replace (Amult Azero (interp_vl v)) with Azero;
[ idtac | trivial ].
rewrite H.
trivial.
intros; simpl in |- *.
generalize (SSR_eq_prop T a Aone).
elim (Aeq a Aone).
intros.
rewrite (ics_aux_ok (interp_m a v) c).
rewrite (interp_m_ok a v).
rewrite (H1 I).
simpl in |- *.
rewrite (ics_aux_ok (interp_vl v) (canonical_sum_simplify c)).
rewrite H.
auto.
simpl in |- *.
intros.
rewrite (ics_aux_ok (interp_m a v) (canonical_sum_simplify c)).
rewrite (ics_aux_ok (interp_m a v) c).
rewrite H; trivial.
rewrite (ics_aux_ok (interp_vl v) (canonical_sum_simplify c)).
rewrite H.
auto.
Qed.
Theorem setspolynomial_simplify_ok :
forall p:setspolynomial,
Aequiv (interp_setcs (setspolynomial_simplify p)) (interp_setsp p).
Proof.
intro.
unfold setspolynomial_simplify in |- *.
rewrite (canonical_sum_simplify_ok (setspolynomial_normalize p)).
exact (setspolynomial_normalize_ok p).
Qed.
End semi_setoid_rings.
Implicit Arguments Cons_varlist.
Implicit Arguments Cons_monom.
Implicit Arguments SetSPconst.
Implicit Arguments SetSPplus.
Implicit Arguments SetSPmult.
Section setoid_rings.
Set Implicit Arguments.
Variable vm : varmap A.
Variable T : Setoid_Ring_Theory Aequiv Aplus Amult Aone Azero Aopp Aeq.
Hint Resolve (STh_plus_comm T).
Hint Resolve (STh_plus_assoc T).
Hint Resolve (STh_plus_assoc2 S T).
Hint Resolve (STh_mult_sym T).
Hint Resolve (STh_mult_assoc T).
Hint Resolve (STh_mult_assoc2 S T).
Hint Resolve (STh_plus_zero_left T).
Hint Resolve (STh_plus_zero_left2 S T).
Hint Resolve (STh_mult_one_left T).
Hint Resolve (STh_mult_one_left2 S T).
Hint Resolve (STh_mult_zero_left S plus_morph mult_morph T).
Hint Resolve (STh_mult_zero_left2 S plus_morph mult_morph T).
Hint Resolve (STh_distr_left T).
Hint Resolve (STh_distr_left2 S T).
Hint Resolve (STh_plus_reg_left S plus_morph T).
Hint Resolve (STh_plus_permute S plus_morph T).
Hint Resolve (STh_mult_permute S mult_morph T).
Hint Resolve (STh_distr_right S plus_morph T).
Hint Resolve (STh_distr_right2 S plus_morph T).
Hint Resolve (STh_mult_zero_right S plus_morph mult_morph T).
Hint Resolve (STh_mult_zero_right2 S plus_morph mult_morph T).
Hint Resolve (STh_plus_zero_right S T).
Hint Resolve (STh_plus_zero_right2 S T).
Hint Resolve (STh_mult_one_right S T).
Hint Resolve (STh_mult_one_right2 S T).
Hint Resolve (STh_plus_reg_right S plus_morph T).
Hint Resolve refl_equal sym_equal trans_equal.
(*Hints Resolve refl_eqT sym_eqT trans_eqT.*)
Hint Immediate T.
(*** Definitions *)
Inductive setpolynomial : Type :=
| SetPvar : index -> setpolynomial
| SetPconst : A -> setpolynomial
| SetPplus : setpolynomial -> setpolynomial -> setpolynomial
| SetPmult : setpolynomial -> setpolynomial -> setpolynomial
| SetPopp : setpolynomial -> setpolynomial.
Fixpoint setpolynomial_normalize (x:setpolynomial) : canonical_sum :=
match x with
| SetPplus l r =>
canonical_sum_merge (setpolynomial_normalize l)
(setpolynomial_normalize r)
| SetPmult l r =>
canonical_sum_prod (setpolynomial_normalize l)
(setpolynomial_normalize r)
| SetPconst c => Cons_monom c Nil_var Nil_monom
| SetPvar i => Cons_varlist (Cons_var i Nil_var) Nil_monom
| SetPopp p =>
canonical_sum_scalar3 (Aopp Aone) Nil_var (setpolynomial_normalize p)
end.
Definition setpolynomial_simplify (x:setpolynomial) :=
canonical_sum_simplify (setpolynomial_normalize x).
Fixpoint setspolynomial_of (x:setpolynomial) : setspolynomial :=
match x with
| SetPplus l r => SetSPplus (setspolynomial_of l) (setspolynomial_of r)
| SetPmult l r => SetSPmult (setspolynomial_of l) (setspolynomial_of r)
| SetPconst c => SetSPconst c
| SetPvar i => SetSPvar i
| SetPopp p => SetSPmult (SetSPconst (Aopp Aone)) (setspolynomial_of p)
end.
(*** Interpretation *)
Fixpoint interp_setp (p:setpolynomial) : A :=
match p with
| SetPconst c => c
| SetPvar i => varmap_find Azero i vm
| SetPplus p1 p2 => Aplus (interp_setp p1) (interp_setp p2)
| SetPmult p1 p2 => Amult (interp_setp p1) (interp_setp p2)
| SetPopp p1 => Aopp (interp_setp p1)
end.
(*** Properties *)
Unset Implicit Arguments.
Lemma setspolynomial_of_ok :
forall p:setpolynomial,
Aequiv (interp_setp p) (interp_setsp vm (setspolynomial_of p)).
simple induction p; trivial; simpl in |- *; intros.
rewrite H; rewrite H0; trivial.
rewrite H; rewrite H0; trivial.
rewrite H.
rewrite
(STh_opp_mult_left2 S plus_morph mult_morph T Aone
(interp_setsp vm (setspolynomial_of s))).
rewrite (STh_mult_one_left T (interp_setsp vm (setspolynomial_of s))).
trivial.
Qed.
Theorem setpolynomial_normalize_ok :
forall p:setpolynomial,
setpolynomial_normalize p = setspolynomial_normalize (setspolynomial_of p).
simple induction p; trivial; simpl in |- *; intros.
rewrite H; rewrite H0; reflexivity.
rewrite H; rewrite H0; reflexivity.
rewrite H; simpl in |- *.
elim
(canonical_sum_scalar3 (Aopp Aone) Nil_var
(setspolynomial_normalize (setspolynomial_of s)));
[ reflexivity
| simpl in |- *; intros; rewrite H0; reflexivity
| simpl in |- *; intros; rewrite H0; reflexivity ].
Qed.
Theorem setpolynomial_simplify_ok :
forall p:setpolynomial,
Aequiv (interp_setcs vm (setpolynomial_simplify p)) (interp_setp p).
intro.
unfold setpolynomial_simplify in |- *.
rewrite (setspolynomial_of_ok p).
rewrite setpolynomial_normalize_ok.
rewrite
(canonical_sum_simplify_ok vm
(Semi_Setoid_Ring_Theory_of A Aequiv S Aplus Amult Aone Azero Aopp Aeq
plus_morph mult_morph T)
(setspolynomial_normalize (setspolynomial_of p)))
.
rewrite
(setspolynomial_normalize_ok vm
(Semi_Setoid_Ring_Theory_of A Aequiv S Aplus Amult Aone Azero Aopp Aeq
plus_morph mult_morph T) (setspolynomial_of p))
.
trivial.
Qed.
End setoid_rings.
End setoid.
|