-
Notifications
You must be signed in to change notification settings - Fork 1
/
validsdp.v
2934 lines (2614 loc) · 107 KB
/
validsdp.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
(** * Main tactic for multivariate polynomial positivity. *)
From HB Require Import structures.
Require Import Ltac2.Ltac2.
Import Ltac2.Control.
Set Default Proof Mode "Classic".
Require Import ZArith.
From Flocq Require Import Core. Require Import Datatypes.
From Interval Require Import Float.Basic Real.Xreal.
From Interval Require Import Missing.Stdlib.
From CoqEAL.theory Require Import ssrcomplements.
From CoqEAL.refinements Require Import hrel refinements param seqmx seqmx_complements binnat binint binrat.
Require Import Reals Flocq.Core.Raux QArith Psatz FSetAVL.
From Bignums Require Import BigZ BigQ.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq.
From mathcomp Require Import choice finfun fintype tuple matrix order ssralg bigop.
From mathcomp Require Import ssrnum ssrint rat div.
From mathcomp.multinomials Require Import mpoly.
Require Import mathcomp.analysis.Rstruct.
Require Import iteri_ord libValidSDP.float_infnan_spec libValidSDP.real_matrix.
Import Refinements.Op.
Require Import cholesky_prog libValidSDP.coqinterval_infnan.
From CoqEAL.refinements Require Import multipoly. Import PolyAVL.
Require Import libValidSDP.zulp.
Require Import libValidSDP.misc ValidSDP.misc.
Require Export soswitness.
Import Order.Theory.
Import GRing.Theory.
Import Num.Theory.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope R_scope.
Coercion bigQ2R : BigQ.t_ >-> R.
Variant Assert := assert_false.
Inductive p_real_cst :=
| PConstR0
(* | PConstQz of bigZ *)
| PConstQq (_ : bigZ) (_ : bigN)
| PConstIZR (_ : BinNums.Z)
| PConstRdiv (_ : p_real_cst) (_ : positive)
| PConstRopp (_ : p_real_cst)
| PConstRinv (_ : positive).
Ltac2 get_real_cst t :=
let rec aux t :=
match! t with
(* | Z2R [?z]%bigZ *)
| bigQ2R (?z # ?n)%bigQ => constr:(PConstQq $z $n)
| R0 => constr:(PConstR0)
| Rdiv ?x (IZR (BinNums.Zpos ?y)) => let x := aux x in
constr:(PConstRdiv $x $y)
| Ropp ?x => let x := aux x in
constr:(PConstRopp $x)
| Rinv (IZR (BinNums.Zpos ?x)) => constr:(PConstRinv $x)
| IZR ?n => constr:(PConstIZR $n)
| _ => constr:(assert_false)
end in
aux t.
Fixpoint interp_p_real_cst (p : p_real_cst) : R :=
match p with
| PConstR0 => R0
(* | PConstQz z => Z2R [z]%bigZ *)
| PConstQq z n => bigQ2R (z # n)%bigQ
| PConstIZR n => IZR n
| PConstRdiv x y => Rdiv (interp_p_real_cst x) (IPR y)
| PConstRopp x => Ropp (interp_p_real_cst x)
| PConstRinv x => Rinv (IPR x)
end.
Fixpoint bigQ_of_p_real_cst (c : p_real_cst) : bigQ :=
let aux := bigQ_of_p_real_cst in
match c with
| PConstR0 => 0%bigQ
| PConstQq z n => (z # n)%bigQ
| PConstIZR n => BigQ.of_Q (inject_Z n)
| PConstRdiv x y => (aux x / BigQ.of_Q (inject_Z (Z.pos y)))%bigQ
| PConstRopp x => (- aux x)%bigQ
| PConstRinv x => (1 / BigQ.of_Q (inject_Z (Z.pos x)))%bigQ
end.
Lemma bigQ_of_p_real_cst_correct c :
bigQ2R (bigQ_of_p_real_cst c) = interp_p_real_cst c.
Proof.
have IQRp : forall p,
Q2R (BigQ.to_Q (BigQ.Qz (BigZ.Pos (BigN.of_pos p)))) = IPR p.
{ by move=> p; rewrite /Q2R /= BigN.spec_of_pos /= Rsimpl. }
elim c.
{ by rewrite /bigQ2R /Q2R /= /Rdiv Rmult_0_l. }
{ done. }
{ move=> [|p|p] /=.
{ by rewrite /bigQ2R /Q2R /= /Rdiv Rmult_0_l. }
{ by rewrite /bigQ2R IQRp /IZR. }
by rewrite /bigQ2R /IZR -IQRp -Q2R_opp. }
{ move=> c' Hc' p; rewrite /= -Hc' /Rdiv /bigQ2R /= -IQRp -Q2R_inv.
{ by rewrite -Q2R_mult; apply Q2R_Qeq; rewrite BigQ.spec_div. }
by rewrite /= BigN.spec_of_pos /Q2R /= Rsimpl. }
{ move=> p Hp; rewrite /= -Hp /bigQ2R -Q2R_opp; apply Q2R_Qeq, BigQ.spec_opp. }
move=> p; rewrite /bigQ2R /interp_p_real_cst -IQRp -Q2R_inv.
{ apply Q2R_Qeq; rewrite -(Qmult_1_l (Qinv _)) -/(BigQ.to_Q 1).
by rewrite -BigQ.spec_inv -BigQ.spec_mul. }
by rewrite /= BigN.spec_of_pos /Q2R /= Rsimpl.
Qed.
(* After requiring Ltac2, mathcomp's notation "... of ... & ..." doesn't work *)
Inductive p_abstr_poly :=
(* | Const of Poly.t *)
(* | Mult_scalar of Poly.Coeff.t * abstr_poly *)
| PConst (_ : p_real_cst)
| PVar (_ : nat)
| POpp (_ : p_abstr_poly)
| PAdd (_ : p_abstr_poly) (_ : p_abstr_poly)
| PSub (_ : p_abstr_poly) (_ : p_abstr_poly)
| PMul (_ : p_abstr_poly) (_ : p_abstr_poly)
| PPowN (_ : p_abstr_poly) (_ : binnat.N)
| PPown (_ : p_abstr_poly) (_ : nat)
| PCompose (_ : p_abstr_poly) (_ : seq p_abstr_poly)
.
Fixpoint all_prop (T : Type) (a : T -> Prop) (s : seq T) : Prop :=
match s with
| [::] => True
| x :: s' => a x /\ all_prop a s'
end.
Lemma all_prop_nthP T (P : T -> Prop) (s : seq T) (x0 : T) :
(forall i, (i < size s)%N -> P (nth x0 s i)) <-> all_prop P s.
Proof.
elim: s => [//|h t Ht] /=; split.
{ move=> H1; split; [by apply (H1 O)|].
by apply Ht => i Hi; apply (H1 i.+1). }
by move=> [Hh Ht'] [|i] Hi //=; apply Ht.
Qed.
Lemma all_prop_forall T1 T2 (P : T1 -> T2 -> Prop) (s : seq T1) :
all_prop (fun x : T1 => forall y : T2, P x y) s ->
forall y : T2, all_prop (fun x : T1 => P x y) s.
Proof.
elim: s => [|x s IHs] H y =>//=.
by have /= [H1 H2] := H; split; last exact: IHs.
Qed.
Lemma eq_map_all_prop T1 T2 (f1 f2 : T1 -> T2) (s : seq T1) :
all_prop (fun x : T1 => f1 x = f2 x) s ->
[seq f1 i | i <- s] =
[seq f2 i | i <- s].
Proof.
elim: s => [|x s IHs] H //=.
have /= [-> H2] := H; congr Datatypes.cons; exact: IHs.
Qed.
Lemma all_prop_cat (T : Type) (a : T -> Prop) (s1 s2 : seq T) :
all_prop a (s1 ++ s2) <-> all_prop a s1 /\ all_prop a s2.
Proof. by elim: s1 => [|x s1 IHs] //=; intuition. Qed.
Section Defix.
Variable (P : p_abstr_poly -> Prop).
Let P' := all_prop P.
Variable (f : forall p : p_real_cst, P (PConst p)).
Variable (f0 : forall n : nat, P (PVar n)) (f1 : forall p : p_abstr_poly, P p -> P (POpp p)).
Variable (f2 : forall p : p_abstr_poly, P p -> forall p0 : p_abstr_poly, P p0 -> P (PAdd p p0)).
Variable (f3 : forall p : p_abstr_poly, P p -> forall p0 : p_abstr_poly, P p0 -> P (PSub p p0)).
Variable (f4 : forall p : p_abstr_poly, P p -> forall p0 : p_abstr_poly, P p0 -> P (PMul p p0)).
Variable (f5 : forall p : p_abstr_poly, P p -> forall n : BinNums.N, P (PPowN p n)).
Variable (f6 : forall p : p_abstr_poly, P p -> forall n : nat, P (PPown p n)).
Variable (f7 : forall p : p_abstr_poly, P p -> forall l : seq p_abstr_poly, P' l -> P (PCompose p l)).
Fixpoint p_abstr_poly_ind' (p : p_abstr_poly) : P p :=
let fix p_abstr_poly_ind2 (l : seq p_abstr_poly) : P' l :=
match l as l0 return (P' l0) with
| [::] => I
| p :: l' => conj (p_abstr_poly_ind' p) (p_abstr_poly_ind2 l')
end in
match p as p0 return (P p0) with
| PConst p0 => f p0
| PVar n => f0 n
| POpp p0 => f1 (p_abstr_poly_ind' p0)
| PAdd p0 p1 => f2 (p_abstr_poly_ind' p0) (p_abstr_poly_ind' p1)
| PSub p0 p1 => f3 (p_abstr_poly_ind' p0) (p_abstr_poly_ind' p1)
| PMul p0 p1 => f4 (p_abstr_poly_ind' p0) (p_abstr_poly_ind' p1)
| PPowN p0 n => f5 (p_abstr_poly_ind' p0) n
| PPown p0 n => f6 (p_abstr_poly_ind' p0) n
| PCompose p0 l => f7 (p_abstr_poly_ind' p0) (p_abstr_poly_ind2 l)
end.
End Defix.
Fixpoint interp_p_abstr_poly (vm : seq R) (ap : p_abstr_poly) {struct ap} : R :=
match ap with
| PConst c => interp_p_real_cst c
| POpp p => Ropp (interp_p_abstr_poly vm p)
| PAdd p q => Rplus (interp_p_abstr_poly vm p) (interp_p_abstr_poly vm q)
| PSub p q => Rminus (interp_p_abstr_poly vm p) (interp_p_abstr_poly vm q)
| PMul p q => Rmult (interp_p_abstr_poly vm p) (interp_p_abstr_poly vm q)
| PPowN p n => powerRZ (interp_p_abstr_poly vm p) (Z.of_N n)
| PPown p n => pow (interp_p_abstr_poly vm p) n
| PVar i => seq.nth R0 vm i
| PCompose p qi => interp_p_abstr_poly (map (interp_p_abstr_poly vm) qi) p
end.
Ltac2 list_add a l :=
let rec aux a l n :=
match! l with
| Datatypes.nil => constr:(($n, Datatypes.cons $a $l))
| Datatypes.cons ?x ?l' =>
match Constr.equal a x with
| true => constr:(($n, $l))
| false =>
match! aux a l' constr:(S $n) with
| (?n, ?l) => constr:(($n, Datatypes.cons $x $l))
end
end
end in
aux a l constr:(O).
Variant Find_exc := not_found.
Variant Poly_exc := not_polynomial.
Variant Goal_exc := not_supported.
Variant Cant_concl := cannot_conclude.
(** [list_idx a l = idx], [idx] being the index of [a] in [l].
Otherwise return [not_found] *)
Ltac2 list_idx a l :=
let rec aux a l n :=
match! l with
| Datatypes.nil => constr:(not_found)
| Datatypes.cons ?x ?l =>
match Constr.equal a x with
| true => n
| false => aux a l constr:(S $n)
end
end in
aux a l constr:(O).
Ltac2 reverse t l :=
let rec aux l accu :=
match! l with
| Datatypes.nil => accu
| Datatypes.cons ?x ?l => aux l constr:(Datatypes.cons $x $accu)
end in
aux l constr:(@Datatypes.nil $t).
(** Define an opaque function to represent abstract real variables *)
Definition x_ (nx : nat) : R.
exact R0.
Qed.
Ltac2 newvar t nx :=
constr:(x_ $nx).
Ltac2 rec fold_right_ltac2 f l r :=
match l with
| [] => r
| e :: l => f e (fold_right_ltac2 f l r)
end.
Ltac2 rec fold_left_ltac2 f r l :=
match l with
| [] => r
| e :: l => fold_left_ltac2 f (f r e) l
end.
Ltac2 mcat s1 s2 :=
Message.concat (Message.concat s1 (Message.of_string " ")) s2.
Ltac2 string_of_ident_list s0 l :=
fold_left_ltac2 (fun r e => mcat r (Message.of_ident e)) s0 l.
Ltac2 mutable deb (str : message) := ().
(* Ltac2 Set deb := fun str => Message.print str. *)
Ltac2 deb_s s1 :=
deb (Message.of_string s1).
Ltac2 deb_sc s1 c1 :=
deb (mcat (Message.of_string s1)
(Message.of_constr c1)).
Ltac2 deb_scc s1 c1 c2 :=
deb (mcat (mcat (Message.of_string s1)
(Message.of_constr c1))
(Message.of_constr c2)).
Ltac2 deb_sccc s1 c1 c2 c3 :=
deb (mcat (mcat (mcat (Message.of_string s1)
(Message.of_constr c1))
(Message.of_constr c2))
(Message.of_string c3)).
Ltac2 deb_scccc s1 c1 c2 c3 c4 :=
deb (mcat (mcat (mcat (mcat (Message.of_string s1)
(Message.of_constr c1))
(Message.of_constr c2))
(Message.of_constr c3))
(Message.of_constr c4)).
Ltac2 deb_sccccc s1 c1 c2 c3 c4 c5 :=
deb (mcat (mcat (mcat (mcat (mcat (Message.of_string s1)
(Message.of_constr c1))
(Message.of_constr c2))
(Message.of_constr c3))
(Message.of_constr c4))
(Message.of_constr c5)).
Ltac2 deb_scccccc s1 c1 c2 c3 c4 c5 c6 :=
deb (mcat (mcat (mcat (mcat (mcat (mcat (Message.of_string s1)
(Message.of_constr c1))
(Message.of_constr c2))
(Message.of_constr c3))
(Message.of_constr c4))
(Message.of_constr c5))
(Message.of_constr c6)).
Ltac2 deb_sccs s1 c1 c2 s2 :=
deb (mcat (mcat (mcat (Message.of_string s1)
(Message.of_constr c1))
(Message.of_constr c2))
(Message.of_string s2)).
Ltac2 deb_csc c1 s1 c2 :=
deb (mcat (mcat (Message.of_constr c1)
(Message.of_string s1))
(Message.of_constr c2)).
Ltac2 deb_cscsc c1 s1 c2 s2 c3 :=
deb (mcat (mcat (mcat (mcat (Message.of_constr c1)
(Message.of_string s1))
(Message.of_constr c2))
(Message.of_string s2))
(Message.of_constr c3)).
Ltac2 fold_get_poly get_poly lq vm :=
deb_scc "fold_get_poly on .." lq vm;
let z0 := constr:((@Datatypes.nil p_abstr_poly, $vm)) in
let rec aux lq vm :=
match! lq with
| Datatypes.nil => z0
| Datatypes.cons ?q1 ?lq1 =>
match! aux lq1 vm with
(* | not_polynomial => k not_polynomial *)
| (?lq2, ?vm1) =>
match! get_poly q1 vm1 with
(* | not_polynomial => k not_polynomial *)
| (?q2, ?vm2) =>
constr:((Datatypes.cons $q2 $lq2, $vm2))
end
end
end in
aux lq vm.
Ltac2 failwith str :=
Control.throw (Tactic_failure (Some (Message.of_string str))).
Ltac2 failwith_c str c :=
Control.throw (Tactic_failure (Some (mcat
(Message.of_string str)
(Message.of_constr c)))).
Ltac2 check_unexpected_case f0 :=
let err () :=
failwith "Unexpected state. Please report this to the ValidSDP maintainers."
in
match! f0 with
| Rplus => err ()
| Rminus => err ()
| Ropp => err ()
| Rmult => err ()
| powerRZ => err ()
| pow => err ()
| Rdiv => err ()
| _ => ()
end.
(** [get_comp_poly tac0 tac1 t vm tac2] will check if [t] matches [?f ?x] *)
Ltac2 get_comp_poly get_poly_cur get_poly_pure t vm tac_var :=
deb_sccs "get_comp_poly on .. .." t vm "..";
let rec aux2 f0 f qi nx xx vm := (* Second step *)
(* f0 := initial value of f;
f := function to be parsed (head of term t);
qi := list of polynomial arguments;
nx := next index of abstract var (initially 0);
xx := list of abstract variables (initially empty);
vm := list of ambient variables;
*)
deb_scccccc "get_comp_poly.aux2 on" f0 f qi nx xx vm;
check_unexpected_case f0;
match! Constr.type f with
| R =>
let f :=
(* Std.eval_unfold [Std.VarRef f0, Std.AllOccurrences] f *)
Std.eval_hnf f in
let xx := reverse constr:(R) xx in
match! get_poly_pure f xx with
| not_polynomial => constr:(not_polynomial)
| (?p, _) => (* Ignore the returned xx (that shouldn't have changed) *)
match! fold_get_poly get_poly_cur qi vm with
(* | not_polynomial => k not_polynomial *)
| (?qi, ?vm) =>
constr:((PCompose $p $qi, $vm))
end
end
| forall x : R, _ =>
let x := newvar constr:(R) nx in
let fx := constr:($f $x) in
let xx := constr:(Datatypes.cons $x $xx) in
let nx := constr:(S $nx) in
aux2 f0 fx qi nx xx vm
end in
let rec aux1 t0 t qi vm := (* First step *)
(* t0 := initial value of t;
t := term to be parsed;
qi := list of polynomial arguments (initially empty);
vm := list of ambient variables;
*)
deb_scccc "get_comp_poly.aux1 on" t0 t qi vm;
match! t with
| ?p ?q =>
let qi1 := constr:(Datatypes.cons $q $qi) in
aux1 t0 p qi1 vm
| ?f =>
match! aux2 f f qi constr:(O) constr:(@Datatypes.nil R) vm with
| not_polynomial => (* If second step fails, return a PVar *)
match! list_add t0 vm with
| (?n, ?vm) => constr:((PVar $n, $vm))
end
| ?res => res
end
end in
(* Ensure [t] is a function applied to a real *)
match! t with
| ?fp ?xn =>
match! Constr.type xn with
| R => aux1 t t constr:(@Datatypes.nil R) vm
| _ => tac_var t vm
end
| _ => tac_var t vm
end.
(** [get_poly_pure t vm] creates no var.
Return [not_polynomial] if [t] isn't poly over [vm] *)
Ltac2 rec get_poly_pure t vm :=
deb_scc "get_poly_pure on" t vm;
let rec aux t vm :=
let aux_u o a :=
match! aux a vm with
| (?u, ?vm) => constr:(($o $u, $vm))
| not_polynomial => constr:(not_polynomial)
end in
let aux_u' o a b :=
match! aux a vm with
| (?u, ?vm) => constr:(($o $u $b, $vm))
| not_polynomial => constr:(not_polynomial)
end in
let aux_b o a b :=
match! aux b vm with
| (?v, ?vm) =>
match! aux a vm with
| (?u, ?vm) => constr:(($o $u $v, $vm))
| not_polynomial => constr:(not_polynomial)
end
| not_polynomial => constr:(not_polynomial)
end in
match! t with
| Rplus ?a ?b => aux_b constr:(PAdd) a b
| Rminus ?a ?b => aux_b constr:(PSub) a b
| Ropp ?a => aux_u constr:(POpp) a
| Rmult ?a ?b => aux_b constr:(PMul) a b
(* | Rsqr ?a => aux (Rmult a a) l *)
| powerRZ ?a ?b =>
match! b with
| Z.pos ?p => aux_u' constr:(PPowN) a constr:(N.pos $p)
| _ => failwith "Only constant, positive exponents are allowed"
end
| pow ?a ?n => aux_u' constr:(PPown) a n
| Rdiv ?a ?b => aux constr:(Rmult $a (Rinv $b)) vm (* Both are convertible *)
| _ =>
match! get_real_cst t with
| assert_false =>
(* Differs w.r.t. get_poly *)
let tac_var t vm :=
match! list_idx t vm with
| not_found =>
deb_csc t "doesn't_belong_to" vm;
constr:(not_polynomial)
| ?n =>
deb_cscsc t "belongs_to" vm "with_idx" n;
constr:((PVar $n, $vm))
end in
get_comp_poly get_poly_pure get_poly_pure t vm tac_var
| ?c => constr:((PConst $c, $vm))
end
end in
aux t vm.
Ltac2 rec get_poly t vm :=
deb_scc "get_poly on" t vm;
let rec aux t vm :=
let aux_u o a :=
match! aux a vm with
| (?u, ?vm) => constr:(($o $u, $vm))
(* | not_polynomial => k not_polynomial *)
end in
let aux_u' o a b :=
match! aux a vm with
| (?u, ?vm) => constr:(($o $u $b, $vm))
(* | not_polynomial => k not_polynomial *)
end in
let aux_b o a b :=
match! aux b vm with
| (?v, ?vm) =>
match! aux a vm with
| (?u, ?vm) => constr:(($o $u $v, $vm))
(* | not_polynomial => k not_polynomial *)
end
(* | not_polynomial => k not_polynomial *)
end in
match! t with
| Rplus ?a ?b => aux_b constr:(PAdd) a b
| Rminus ?a ?b => aux_b constr:(PSub) a b
| Ropp ?a => aux_u constr:(POpp) a
| Rmult ?a ?b => aux_b constr:(PMul) a b
(* | Rsqr ?a => aux (Rmult a a) l *)
| powerRZ ?a ?b =>
match! b with
| Z.pos ?p => aux_u' constr:(PPowN) a constr:(N.pos $p)
| _ => failwith "Only constant, positive exponents are allowed"
end
| pow ?a ?n => aux_u' constr:(PPown) a n
| Rdiv ?a ?b => aux constr:(Rmult $a (Rinv $b)) vm (* Both are convertible *)
| _ =>
match! get_real_cst t with
| assert_false =>
let tac_var t vm :=
match! list_add t vm with
| (?n, ?vm) => constr:((PVar $n, $vm))
end in
get_comp_poly get_poly get_poly_pure t vm tac_var
| ?c => constr:((PConst $c, $vm))
end
end in
aux t vm.
Inductive abstr_poly :=
| Const of bigQ
| Var of nat
| Add (_ : abstr_poly) (_ : abstr_poly)
| Sub (_ : abstr_poly) (_ : abstr_poly)
| Mul (_ : abstr_poly) (_ : abstr_poly)
| PowN (_ : abstr_poly) (_ : binnat.N)
| Compose (_ : abstr_poly) (_ : seq abstr_poly).
Section Defix'.
Variable (P : abstr_poly -> Prop).
Let P' := all_prop P.
Variable (f : forall t : bigQ, P (Const t)).
Variable (f0 : forall n : nat, P (Var n)).
Variable (f1 : forall a : abstr_poly, P a -> forall a0 : abstr_poly, P a0 -> P (Add a a0)).
Variable (f2 : forall a : abstr_poly, P a -> forall a0 : abstr_poly, P a0 -> P (Sub a a0)).
Variable (f3 : forall a : abstr_poly, P a -> forall a0 : abstr_poly, P a0 -> P (Mul a a0)).
Variable (f4 : forall a : abstr_poly, P a -> forall n : BinNums.N, P (PowN a n)).
Variable (f5 : forall a : abstr_poly, P a -> forall l : seq abstr_poly, P' l -> P (Compose a l)).
Fixpoint abstr_poly_ind' (p : abstr_poly) : P p :=
let fix abstr_poly_ind2 (l : seq abstr_poly) : P' l :=
match l as l0 return (P' l0) with
| [::] => I
| p :: l' => conj (abstr_poly_ind' p) (abstr_poly_ind2 l')
end in
match p as p0 return (P p0) with
| Const t => f t
| Var n => f0 n
| Add a0 a1 => f1 (abstr_poly_ind' a0) (abstr_poly_ind' a1)
| Sub a0 a1 => f2 (abstr_poly_ind' a0) (abstr_poly_ind' a1)
| Mul a0 a1 => f3 (abstr_poly_ind' a0) (abstr_poly_ind' a1)
| PowN a0 n => f4 (abstr_poly_ind' a0) n
| Compose a0 l => f5 (abstr_poly_ind' a0) (abstr_poly_ind2 l)
end.
End Defix'.
Fixpoint all_type (T : Type) (a : T -> Type) (s : seq T) : Type :=
match s with
| [::] => True
| x :: s' => a x * all_type a s'
end.
(*/-*)
Lemma all_type_nth T (P : T -> Type) (s : seq T) (x0 : T):
all_type P s -> forall i, (i < size s)%N -> P (nth x0 s i).
Proof. by elim: s => [//|? ? /= Hi [? ?] [//|?] ?]; apply Hi. Qed.
Lemma nth_all_type T (P : T -> Type) (s : seq T) (x0 : T):
(forall i, (i < size s)%N -> P (nth x0 s i)) -> all_type P s.
Proof.
elim: s => [//|h t Ht H]; split; [by apply (H O)|].
by apply Ht => i Hi; apply (H (S i)).
Qed.
Section Defix''.
Variable (P : abstr_poly -> Type).
Let P' := all_type P.
Variable (f : forall t : bigQ, P (Const t)).
Variable (f0 : forall n : nat, P (Var n)).
Variable (f1 : forall a : abstr_poly, P a -> forall a0 : abstr_poly, P a0 -> P (Add a a0)).
Variable (f2 : forall a : abstr_poly, P a -> forall a0 : abstr_poly, P a0 -> P (Sub a a0)).
Variable (f3 : forall a : abstr_poly, P a -> forall a0 : abstr_poly, P a0 -> P (Mul a a0)).
Variable (f4 : forall a : abstr_poly, P a -> forall n : BinNums.N, P (PowN a n)).
Variable (f5 : forall a : abstr_poly, P a -> forall l : seq abstr_poly, P' l -> P (Compose a l)).
Fixpoint abstr_poly_rect' (p : abstr_poly) : P p :=
let fix abstr_poly_rect2 (l : seq abstr_poly) : P' l :=
match l as l0 return (P' l0) with
| [::] => I
| p :: l' => (abstr_poly_rect' p, abstr_poly_rect2 l')
end in
match p as p0 return (P p0) with
| Const t => f t
| Var n => f0 n
| Add a0 a1 => f1 (abstr_poly_rect' a0) (abstr_poly_rect' a1)
| Sub a0 a1 => f2 (abstr_poly_rect' a0) (abstr_poly_rect' a1)
| Mul a0 a1 => f3 (abstr_poly_rect' a0) (abstr_poly_rect' a1)
| PowN a0 n => f4 (abstr_poly_rect' a0) n
| Compose a0 l => f5 (abstr_poly_rect' a0) (abstr_poly_rect2 l)
end.
End Defix''.
Fixpoint abstr_poly_of_p_abstr_poly (p : p_abstr_poly) : abstr_poly :=
match p with
| PConst c => Const (bigQ_of_p_real_cst c)
| PVar n => Var n
| POpp x => Sub (Const 0%bigQ) (abstr_poly_of_p_abstr_poly x)
| PAdd x y => Add (abstr_poly_of_p_abstr_poly x) (abstr_poly_of_p_abstr_poly y)
| PSub x y => Sub (abstr_poly_of_p_abstr_poly x) (abstr_poly_of_p_abstr_poly y)
| PMul x y => Mul (abstr_poly_of_p_abstr_poly x) (abstr_poly_of_p_abstr_poly y)
| PPowN x n => PowN (abstr_poly_of_p_abstr_poly x) n
| PPown x n => PowN (abstr_poly_of_p_abstr_poly x) (N.of_nat n)
| PCompose p qi => Compose (abstr_poly_of_p_abstr_poly p) (map abstr_poly_of_p_abstr_poly qi)
end.
Fixpoint interp_abstr_poly (vm : seq R) (p : abstr_poly) {struct p} : R :=
match p with
| Const c => bigQ2R c
| Add p q => Rplus (interp_abstr_poly vm p) (interp_abstr_poly vm q)
| Sub p q => Rminus (interp_abstr_poly vm p) (interp_abstr_poly vm q)
| Mul p q => Rmult (interp_abstr_poly vm p) (interp_abstr_poly vm q)
| PowN p n => powerRZ (interp_abstr_poly vm p) (Z.of_N n)
| Var i => seq.nth R0 vm i
| Compose p qi => interp_abstr_poly (map (interp_abstr_poly vm) qi) p
end.
Lemma abstr_poly_of_p_abstr_poly_correct (vm : seq R) (p : p_abstr_poly) :
interp_abstr_poly vm (abstr_poly_of_p_abstr_poly p) =
interp_p_abstr_poly vm p.
Proof.
elim/p_abstr_poly_ind': p vm => //.
{ move=> *; apply bigQ_of_p_real_cst_correct. }
{ move=> p IHp vm /=.
by rewrite (IHp vm) /bigQ2R /Q2R Rsimpl /Rminus Rplus_0_l. }
{ by move=> p1 IHp1 p2 IHp2 vm; rewrite /= (IHp1 vm) (IHp2 vm). }
{ by move=> p1 IHp1 p2 IHp2 vm; rewrite /= (IHp1 vm) (IHp2 vm). }
{ by move=> p1 IHp1 p2 IHp2 vm; rewrite /= (IHp1 vm) (IHp2 vm). }
{ by move=> p IHp n vm; rewrite /= (IHp vm). }
{ by move=> p IHp n vm; rewrite /= pow_powerRZ nat_N_Z (IHp vm). }
move=> pp IHpp qqi IHqqi vm; rewrite /=.
rewrite IHpp; f_equal.
rewrite -map_comp.
rewrite (eq_map_all_prop (f2 := interp_p_abstr_poly vm)) //.
exact: (all_prop_forall (P := fun p vm =>
interp_abstr_poly vm (abstr_poly_of_p_abstr_poly p) = interp_p_abstr_poly vm p)).
Qed.
(** Tip to leverage a Boolean condition *)
Definition sumb (b : bool) : {b = true} + {b = false} :=
if b is true then left erefl else right erefl.
Fixpoint interp_poly_ssr (n : nat) (ap : abstr_poly) {struct ap} : {mpoly rat[n]} :=
match ap with
| Const t => (bigQ2rat t)%:MP_[n]
| Var i =>
match n with
| O => 0%:MP_[O]
| S n' => 'X_(inord i)
end
| Add a0 a1 => (interp_poly_ssr n a0 + interp_poly_ssr n a1)%R
| Sub a0 a1 => (interp_poly_ssr n a0 - interp_poly_ssr n a1)%R
| Mul a0 a1 => (interp_poly_ssr n a0 * interp_poly_ssr n a1)%R
| PowN a0 n' => mpoly_exp (interp_poly_ssr n a0) n'
| Compose a0 qi =>
let qi' := map (interp_poly_ssr n) qi in
match sumb (size qi' == size qi) with
| right prf => 0%:MP_[n]
| left prf =>
comp_mpoly (tcast (eqP prf) (in_tuple qi'))
(interp_poly_ssr (size qi) a0)
end
end.
Fixpoint interp_poly_eff n (ap : abstr_poly) : effmpoly bigQ :=
match ap with
| Const c => @mpolyC_eff bigQ n c
| Var i => @mpvar_eff bigQ n 1%bigQ 1 (N.of_nat i)
| Add p q => mpoly_add_eff (interp_poly_eff n p) (interp_poly_eff n q)
| Sub p q => mpoly_sub_eff (interp_poly_eff n p) (interp_poly_eff n q)
| Mul p q => mpoly_mul_eff (interp_poly_eff n p) (interp_poly_eff n q)
| PowN p m => mpoly_exp_eff (n := n) (interp_poly_eff n p) m
| Compose p qi =>
let qi' := map (interp_poly_eff n) qi in
comp_mpoly_eff (n := n) qi' (interp_poly_eff (size qi) p)
end.
Fixpoint vars_ltn n (ap : abstr_poly) : bool :=
match ap with
| Const _ => true
| Var i => (i < n)%N
| Add p q | Sub p q | Mul p q => vars_ltn n p && vars_ltn n q
| PowN p _ => vars_ltn n p
| Compose p qi => all (vars_ltn n) qi && vars_ltn (size qi) p
end.
Lemma vars_ltn_ge (n n' : nat) (ap : abstr_poly) :
(n <= n')%N -> vars_ltn n ap -> vars_ltn n' ap.
Proof.
move=> Hn'; elim/abstr_poly_ind': ap.
{ by []. }
{ by move=> i /= Hi; move: Hn'; apply leq_trans. }
{ by move=> a0 Ha0 a1 Ha1 /= /andP [] Hn0 Hn1; rewrite Ha0 // Ha1. }
{ by move=> a0 Ha0 a1 Ha1 /= /andP [] Hn0 Hn1; rewrite Ha0 // Ha1. }
{ by move=> a0 Ha0 a1 Ha1 /= /andP [] Hn0 Hn1; rewrite Ha0 // Ha1. }
{ by []. }
move=> a Ha; case=> [//|h t] /= [] Hh Ht /andP [] /andP [] Hh' Ht' Ha'.
rewrite Hh //= Ha' andb_true_r.
apply/(all_nthP (Const 0)) => i Hi.
move: Ht => /all_prop_nthP; apply=> //.
by move: Ht' => /all_nthP; apply.
Qed.
Lemma interp_poly_ssr_correct (l : seq R) (n : nat) (ap : abstr_poly) :
size l = n -> vars_ltn n ap ->
let p := map_mpoly rat2R (interp_poly_ssr n ap) in
interp_abstr_poly l ap = p.@[fun i : 'I_n => nth R0 l i].
Proof.
elim/abstr_poly_ind': ap l n => //.
{ by move=> ? ? ? _ _ /=; rewrite map_mpolyC mevalC bigQ2R_rat. }
{ move=> ? ? [|?] ? //= ?.
try (by rewrite map_mpolyX mevalXU; f_equal; rewrite inordK) ||
by rewrite map_mpolyX mevalX; f_equal; rewrite inordK. }
{ move=> p Hp q Hq l n Hn /= /andP [] Hnp Hnq.
by rewrite (Hp _ _ Hn Hnp) (Hq _ _ Hn Hnq) !rmorphD. }
{ move=> p Hp q Hq l n Hn /= /andP [] Hnp Hnq.
by rewrite (Hp _ _ Hn Hnp) (Hq _ _ Hn Hnq) !rmorphB. }
{ move=> p Hp q Hq l n Hn /= /andP [] Hnp Hnq.
by rewrite (Hp _ _ Hn Hnp) (Hq _ _ Hn Hnq) !rmorphM. }
{ move=> p Hp m l n Hn /= Hnp; rewrite (Hp _ _ Hn Hnp).
rewrite -{1}[m]spec_NK /binnat.implem_N bin_of_natE nat_N_Z.
by rewrite -pow_powerRZ misc.pow_rexp !rmorphX. }
move=> p Hp qi Hqi l n Hn /= /andP [Hqi' Hp'].
case (sumb _) => [e|]; [|by rewrite size_map eqxx].
set qi' := map _ _.
rewrite (Hp qi' (size qi)); [|by rewrite /qi' /= size_map|by []].
rewrite (map_mpoly_comp _ _ (fmorph_inj _)) comp_mpoly_meval /=.
apply meval_eq => i.
rewrite tnth_map tcastE /tnth /= (set_nth_default 0%R (tnth_default _ _));
[|by rewrite /= size_map; case i].
rewrite (nth_map (Const 0)) => //.
move: Hqi => /all_prop_nthP Hqi.
move: Hqi' => /all_nthP Hqi'.
rewrite (Hqi _ _ _ _ n) => //; [|by apply Hqi'].
by rewrite (nth_map (Const 0)).
Qed.
Lemma interp_poly_ssr_correct' vm p :
let n := size vm in
let p' := abstr_poly_of_p_abstr_poly p in
let p'' := map_mpoly rat2R (interp_poly_ssr n p') in
vars_ltn n p' ->
interp_p_abstr_poly vm p = p''.@[fun i : 'I_n => nth R0 vm i].
Proof.
move=> *; rewrite -interp_poly_ssr_correct //.
by rewrite abstr_poly_of_p_abstr_poly_correct.
Qed.
(** ** Part 0: Definition of operational type classes *)
Class sempty_of setT := sempty : setT.
Class sadd_of T setT := sadd : T -> setT -> setT.
Class smem_of T setT := smem : T -> setT -> bool.
Class mul_monom_of monom := mul_monom_op : monom -> monom -> monom.
Class list_of_poly_of T monom polyT := list_of_poly_op :
polyT -> seq (monom * T).
Class polyC_of T polyT := polyC_op : T -> polyT.
Class polyX_of monom polyT := polyX_op : monom -> polyT.
Class poly_sub_of polyT := poly_sub_op : polyT -> polyT -> polyT.
Class poly_mul_of polyT := poly_mul_op : polyT -> polyT -> polyT.
Notation map_mx2_of B :=
(forall T T' (m n : nat), map_mx_of T T' (B T m n) (B T' m n)) (only parsing).
(** ** Part 1: Generic programs *)
Section generic_soscheck.
Context {n : nat}. (** number of variables of polynomials *)
Context {T : Type}. (** type of coefficients of polynomials *)
Context {monom : Type} {polyT : Type}.
Context `{!mul_monom_of monom, !list_of_poly_of T monom polyT}.
Context `{!polyC_of T polyT, !polyX_of monom polyT, !poly_sub_of polyT}.
Context {set : Type}.
Context `{!sempty_of set, !sadd_of monom set, !smem_of monom set}.
Context `{!zero_of T, !opp_of T, !leq_of T}.
Context {ord : nat -> Type} {mx : Type -> nat -> nat -> Type}.
Context `{!fun_of_of monom ord (mx monom)}.
Context `{!fun_of_of polyT ord (mx polyT)}.
Context {I0n : forall n, I0_class ord n.+1}.
Context {succ0n : forall n, succ0_class ord n.+1}.
Context {natof0n : forall n, nat_of_class ord n.+1}.
Context `{!I0_class ord 1}.
Definition max_coeff (p : polyT) : T :=
foldl (fun m mc => max m (max mc.2 (-mc.2)%C)) 0%C (list_of_poly_op p).
Context `{!trmx_of (mx polyT)}.
(* Multiplication of matrices of polynomials. *)
Context `{!hmul_of (mx polyT)}.
Context {fs : Float_round_up_infnan_spec}.
Let F := FIS fs.
Context {F2T : F -> T}. (* exact conversion *)
Context {T2F : T -> F}. (* overapproximation *)
Context `{!fun_of_of F ord (mx F), !row_of ord (mx F), !store_of F ord (mx F), !dotmulB0_of F ord (mx F)}.
Context `{!heq_of (mx F), !trmx_of (mx F)}.
Context `{!map_mx2_of mx}.
Section generic_soscheck_size.
Context {s : nat}.
Context `{!I0_class ord s, !succ0_class ord s, !nat_of_class ord s}.
Definition check_base (p : polyT) (z : mx monom s 1) : bool :=
let sm :=
iteri_ord s
(fun i =>
iteri_ord s
(fun j => sadd (mul_monom_op (fun_of_op z i I0)
(fun_of_op z j I0))))
sempty in
all (fun mc => smem mc.1 sm) (list_of_poly_op p).
(* Prove that p >= 0 by proving that Q - s \delta I is a positive
definite matrix with \delta >= max_coeff(p - z^T Q z) *)
Definition soscheck (p : polyT) (z : mx monom s 1) (Q : mx F s s) : bool :=
check_base p z &&
let r :=
let p' :=
let zp := map_mx_op polyX_op z in
let Q' := map_mx_op (polyC_op \o F2T) Q in
let p'm := (zp^T *m Q' *m zp)%HC in
(* TODO: profiling pour voir si nécessaire d'améliorer la ligne
* ci dessus (facteur 40 en Caml, mais peut être du même ordre de
* grandeur que la décomposition de Cholesky
* (effectivement, sur d'assez gros exemples, ça semble être le cas)) *)
fun_of_op p'm I0 I0 in
let pmp' := poly_sub_op p p' in
max_coeff pmp' in
posdef_check_itv (@float_infnan_spec.fieps fs) (@float_infnan_spec.fieta fs)
(@float_infnan_spec.finite fs) Q (T2F r).
End generic_soscheck_size.
Context `{!poly_mul_of polyT}.
Context {s : nat}.
Context `{!I0_class ord s, !succ0_class ord s, !nat_of_class ord s}.
Variant sz_witness :=
| Wit : polyT -> forall s, mx monom s.+1 1 -> mx F s.+1 s.+1 -> sz_witness.
(* Prove that /\_i pi >= 0 -> p >= 0 by proving that
- \forall i, pi >= 0 with zi, Qi as above
- p - \sum_i si pi >= 0 with z and Q as above *)
Definition soscheck_hyps
(pszQi : seq (polyT * sz_witness))
(p : polyT) (z : mx monom s 1) (Q : mx F s s) : bool :=
let p' :=
foldl
(fun p' (pszQ : polyT * sz_witness) =>
match pszQ.2 with
| Wit s _ _ _ => poly_sub_op p' (poly_mul_op s pszQ.1)
end) p pszQi in
soscheck p' z Q
&& all
(fun pzQ : polyT * sz_witness =>
match pzQ.2 with
| Wit s _ z Q => soscheck s z Q
end) pszQi.
Context `{!eq_of monom, !zero_of monom}.
Definition has_const (z : mx monom s 1) := (fun_of_op z I0 I0 == (0:monom))%C.
End generic_soscheck.
Module S := FSetAVL.Make MultinomOrd.
Section eff_soscheck.
(** *** General definitions for seqmx and effmpoly *)
Context {n : nat}. (** number of variables of polynomials *)
Context {T : Type}. (** type of coefficients of polynomials *)
Context `{!zero_of T, !one_of T, !opp_of T, !add_of T, !sub_of T, !mul_of T, !eq_of T}.
Let monom := seqmultinom.
Let polyT := effmpoly T.
Global Instance mul_monom_eff : mul_monom_of monom := mnm_add_seq.
Global Instance list_of_poly_eff : list_of_poly_of T monom polyT :=
list_of_mpoly_eff (T:=T).
Global Instance polyC_eff : polyC_of T polyT := @mpolyC_eff _ n.
Global Instance polyX_eff : polyX_of monom polyT := mpolyX_eff.
Global Instance poly_sub_eff : poly_sub_of polyT := mpoly_sub_eff.
Let set := S.t.
Global Instance sempty_eff : sempty_of set := S.empty.
Global Instance sadd_eff : sadd_of monom set := S.add.
Global Instance smem_eff : smem_of monom set := S.mem.
Context `{!leq_of T}.
Let ord := ord_instN.
Let mx := @hseqmx.
Context {s : nat}.
Global Instance fun_of_seqmx_monom : fun_of_of monom ord (mx monom) :=
@fun_of_seqmx _ [::].
Definition check_base_eff : polyT -> mx monom s.+1 1 -> bool :=
check_base (I0_class0:=I0_instN).
Definition max_coeff_eff : polyT -> T := max_coeff.
Context {fs : Float_round_up_infnan_spec}.
Let F := FIS fs.
Context {F2T : F -> T}. (* exact conversion *)
Context {T2F : T -> F}. (* overapproximation *)
Global Instance fun_of_seqmx_polyT : fun_of_of polyT ord (mx polyT) :=
@fun_of_seqmx _ mp0_eff.
Global Instance mulseqmx_polyT : hmul_of (mx polyT) :=
@mul_seqmx _ mp0_eff mpoly_add_eff mpoly_mul_eff.
Definition soscheck_eff : polyT -> mx monom s.+1 1 -> mx F s.+1 s.+1 -> bool :=
soscheck (F2T:=F2T) (T2F:=T2F).
Global Instance poly_mul_eff : poly_mul_of polyT := mpoly_mul_eff.
Definition soscheck_hyps_eff :
seq (polyT * sz_witness) ->
polyT -> mx monom s.+1 1 -> mx F s.+1 s.+1 -> bool :=
soscheck_hyps (set:=set) (F2T:=F2T) (T2F:=T2F)
(I0n:=fun n => O) (succ0n:=fun n => S) (natof0n:=fun _ => id).
Global Instance monom_eq_eff : eq_of monom := mnmc_eq_seq.
Definition has_const_eff {n : nat} : mx monom s.+1 1 -> bool :=
has_const (zero_of1 := @mnm0_seq n).
End eff_soscheck.
(** ** Part 2: Correctness proofs for proof-oriented types and programs *)
Section theory_soscheck.
(** *** Proof-oriented definitions, polymorphic w.r.t scalars *)
Context {n : nat} {T : comRingType}.
Let monom := 'X_{1..n}.
Let polyT := mpoly n T.