-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_function.ml
More file actions
1060 lines (801 loc) · 34.3 KB
/
print_function.ml
File metadata and controls
1060 lines (801 loc) · 34.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
open Pervasives;;
open Cpf0;;
open Vector;;
open SemiRing;;
(****************************************************************************)
(* Natural numbers *)
(* Print vector of type int in column format. *)
let rec print_vec_int_column = function
| Coq_nil -> print_string "nil \n"
| Coq_cons (i, n, ts) ->
print_int i; print_string " (d = ";
print_int n; print_string ")\n"; print_vec_int_column ts;;
(* Print vector of type int in row format. *)
let rec print_vec_int_row = function
| Coq_nil -> print_string "nil \n"
| Coq_cons (i, n, ts) ->
print_int i; print_string " (d = ";
print_int n; print_string ") "; print_vec_int_row ts;;
(* [vec_iter] function print a list of vector *)
let rec vec_iter f = function
| Coq_nil -> ()
| Coq_cons (a, _, l) -> f a; print_string " "; vec_iter f l;;
(* [print_matrix] print a matrix of type int with column format. *)
let print_matrix i = vec_iter (print_vec_int_column) i;;
(* [vec_iter_args] is a function that print an [arg] (square matrix)
in matrix interpretation *)
let rec vec_iter_args f = function
| Coq_nil -> ()
| Coq_cons (a, _, l) -> f a; print_string "\n"; vec_iter_args f l;;
(* [print_define_args] is a function that print a list of [args] (list
of square matrix) in matrix interpretation over domain natural
numbers. *)
let print_define_args args =
vec_iter_args (vec_iter_args (print_vec_int_column)) args;;
(* [print_matrixInt] is a function that print [const] and [args] in
matrix interpretation. *)
(*
let print_matrixInt p =
let () = print_string "\n~~~~~~~~~~~~~~~~~~~~~\n";
print_string "\n MatrixInt both const and args are: " in
print_string "\n - const: \n";
print_vec_int_column p.const;
print_string "\n - args: \n" ;
print_define_args p.args;;*)
(****************************************************************************)
(* Arctic natural numbers *)
(* [print_coqArcInt] function print a type ArcInt where MinusInf
output as '-00' *)
let print_coqArcInt i =
match i with
| Pos n -> print_string "Pos "; print_int n
| MinusInf -> print_string "MinusInf";;
(* [print_vec_arc_column] is a function print vector of type arctic
int in the column format. *)
let rec print_vec_arc_column = function
| Coq_nil -> print_string "nil \n"
| Coq_cons (i, n, ts) -> print_coqArcInt i; print_string " (d= ";
print_int n; print_string ")\n"; print_vec_arc_column ts;;
(* [print_matrix_arc] is a function print matrix of type arctic int in
a column format. *)
let print_matrix_arc i = vec_iter (print_vec_arc_column) i;;
(* [print_define_args_arcnat] is a function that print a list of
[args_arcnat] (list of square matrix) in matrix interpretation over
domain arctic natural numbers. *)
let print_define_args_arcnat args =
vec_iter_args (vec_iter_args (print_vec_arc_column)) args;;
(* [print_matrixArcNat] is a function that print [const_arcnat] and
[args_arcnat] in matrix interpretation over arctic natural numbers *)
(*
let print_matrixArcNat p =
let () = print_string "\n~~~~~~~~~~~~~~~~~~~~~\n";
print_string "\n MatrixArcnat both const and args are: " in
print_string "\n - const: \n";
print_vec_arc_column p.const;
print_string "\n - args: \n" ;
print_define_args_arcnat p.args;;*)
(****************************************************************************)
(* Arctic integer numbers *)
let print_coqArcBZ i =
match i with
| SemiRing.Fin n -> print_string "Fin "; print_int n
| SemiRing.MinusInfBZ -> print_string "MinusInfBZ";;
(* [print_vec_arc_column] is a function print vector of type arctic
int in the column format. *)
let rec print_vec_arcbz_column = function
| Coq_nil -> print_string "nil \n"
| Coq_cons (i, n, ts) -> print_coqArcBZ i; print_string " (d= ";
print_int n; print_string ")\n"; print_vec_arcbz_column ts;;
(* [print_matrix_arc] is a function print matrix of type arctic int in
a column format. *)
let print_matrix_arcbz i = vec_iter (print_vec_arcbz_column) i;;
(* [print_define_args_arcnat] is a function that print a list of
[args_arcnat] (list of square matrix) in matrix interpretation over
domain arctic natural numbers. *)
let print_define_args_arcbz args =
vec_iter_args (vec_iter_args (print_vec_arcbz_column)) args;;
(* [print_matrixArcNat] is a function that print [const_arcnat] and
[args_arcnat] in matrix interpretation over arctic natural numbers *)
(*
let print_matrixArcBZ p =
let () = print_string "\n~~~~~~~~~~~~~~~~~~~~~\n";
print_string "\n MatrixArcBZ both const and args are: " in
print_string "\n - const: \n";
print_vec_arcbz_column p.const;
print_string "\n - args: \n" ;
print_define_args_arcbz p.args;;*)
(****************************************************************************)
(* Polynomial function *)
let print_poly (i, v) =
print_string " Coefficient: ";
print_int i; print_string "\n monom n: "; print_vec_int_column v;;
(* [print_list_poly] print a list of coefficient. *)
let rec print_list_poly l =
match l with
| [] -> print_string " Empty list\n"
| x :: l' -> print_poly x; print_string " :: "; print_list_poly l';;
(****************************************************************************)
(* Define value for polynomial function for polynomial interpretation over
domain natural numbers *)
open Polynom2;;
open Peano;;
open BinPos;;
open Cpf_util;;
open Cpf2color;;
(** Coefficient *)
let define_poly_coefficient_3 =
Polynomial_coefficient (Coefficient_number (Number_integer 3));;
let define_poly_coefficient_4 =
Polynomial_coefficient (Coefficient_number (Number_integer 4));;
let poly_coef_poly n = function
| Polynomial_coefficient c ->
(match color_coef_N c with
| Ok d -> Ok (pconst n d)
| Ko e -> Ko e)
| _ -> Ko TpolyMax;;
(*
let convert_poly_coef_poly n =
match poly_coef_poly n define_poly_coefficient_3 with
| Ok p -> p
| Ko _ -> (pzero 0);;*)
(* where n = 1 *)
(*
let print_convert_poly_test_coef_poly_color =
let () = print_string "\n---------------------\n";
print_string "\n Print [Polynomial_coefficient]\n" in
print_list_poly (convert_poly_coef_poly 1);;*)
(** Variable *)
let define_poly_variable_0 = Polynomial_variable 0;;
let define_poly_variable_1 = Polynomial_variable 1;;
let define_poly_variable_2 = Polynomial_variable 2;;
(* [Polynomial_variable] in [color_poly] in [poly.v] *)
(*
let poly_variable_poly n = function
| Polynomial_variable x ->
let x0 = minus (Pos.to_nat x) (succ 0) in
if lt_dec x0 n then Ok (pxi n x0) else Ko EpolyVarTooBig
| _ -> Ko TpolyMax;;*)
(* [color_poly] in the case of [Polynomial_variable]; convert
polynomial Cpf0 type to [poly] of CoLoR type *)
(*
let convert_poly_variable_0_poly n =
match poly_variable_poly n define_poly_variable_0 with
| Ok p -> p
| Ko _ -> (pzero 0);; (* If it is error it will return pzero *)*)
(*
let convert_poly_variable_1_poly n =
match poly_variable_poly n define_poly_variable_1 with
| Ok p -> p
| Ko _ -> (pzero 0);;*)
(* where n = 1 *)
(*
let print_convert_poly_variable_0_poly_color =
let () = print_string "\n---------------------\n";
print_string "\n Print [Polynomial_variable] variable 0: " in
print_list_poly (convert_poly_variable_0_poly 1);;*)
(* where n = 1 *)
(*
let print_convert_poly_variable_1_poly_color =
let () = print_string "\n---------------------\n";
print_string "\n Print [Polynomial_variable] variable 1: \n" in
print_list_poly (convert_poly_variable_1_poly 1);;*)
(* Polynomial sum *)
(* list p = 3 :: 4 :: nil *)
(*
let define_poly_list_sum =
Polynomial_sum (define_poly_coefficient_3 :: define_poly_coefficient_4 :: []);;
(* [Polynomial_sum] in [poly.v] *)
let poly_sum_poly n = function
| Polynomial_sum l ->
let rec color_poly_sum acc = function
| [] -> Ok acc
| p0 :: l' ->
(match color_poly n p0 with
| Ok p1 -> color_poly_sum (pplus n p1 acc) l'
| Ko e -> Ko e)
in color_poly_sum (pzero n) l
| _ -> Ko TpolyMax;;
(* Convert [poly_sum_poly] into poly of Color type *)
let convert_poly_sum_poly_color n =
match poly_sum_poly n define_poly_list_sum with
| Ok p -> p
| Ko _ -> (pzero 0);;
let print_convert_poly_test_sum_poly_color =
let () = print_string "\n---------------------\n";
print_string "\n Print [Polynomial_sum] where coef = 4 + 3: \n" in
print_list_poly (convert_poly_sum_poly_color 1);;
(* Polynomial multiplication *)
(* list p = 3 :: 4 :: nil *)
let define_poly_list_prod =
Polynomial_product (define_poly_coefficient_3 :: define_poly_coefficient_4 :: []);;
(* [Polynomial_product] in [poly.v] *)
let poly_prod_poly n = function
| Polynomial_product l ->
let rec color_poly_prod acc = function
| [] -> Ok acc
| p0 :: l' ->
(match color_poly n p0 with
| Ok p1 -> color_poly_prod (pmult n p1 acc) l'
| Ko e -> Ko e)
in color_poly_prod (pconst n 1) l
| _ -> Ko TpolyMax;;
(* convert [poly_prod_poly] into poly of Color type *)
let convert_poly_prod_poly n =
match poly_prod_poly n define_poly_list_prod with
| Ok p -> p
| Ko _ -> (pzero 0);; (* when it is error return pzero *)
let print_convert_poly_prod_poly_color =
let () = print_string "\n---------------------\n";
print_string "\n Print [Polynomial_product] where coef = 4 * 3: \n" in
print_list_poly (convert_poly_prod_poly 1);;
(* Test the function [color_poly] in [poly.v] *)
let define_poly = Polynomial_sum
(define_poly_coefficient_3 ::
(Polynomial_product
(define_poly_coefficient_4 :: define_poly_variable_1 :: [])) :: []);;
let convert_color_poly n =
match color_poly n define_poly with
| Ok p -> p
| Ko _ -> (pzero 0);;
let print_color_poly =
let () = print_string "\n---------------------\n";
print_string "\n [color_poly]: \n" in
print_list_poly (convert_color_poly 1);;
(****************************************************************************)
(* Define value for polynomial function for matrix interpretation over
domain natural numbers *)
(* Coefficient *)
let define_coef0 = Coefficient_number (Number_integer 0);;
let define_coef1 = Coefficient_number (Number_integer 1);;
let define_coef2 = Coefficient_number (Number_integer 2);;
(* Vector *)
(* v = 0 :: 1 :: nil *)
let define_coef_vector01 = Polynomial_coefficient
(Coefficient_vector (Vector_vector (define_coef0 :: define_coef1 :: [])));;
(* Matrix *)
(* m = (2 :: 2 :: nil) :: (0 :: 0 :: nil) :: nil *)
let define_matrix_coef2200 = Polynomial_coefficient
(Coefficient_matrix (Matrix_matrix
((define_coef2 :: define_coef2 :: []) ::
(define_coef0:: define_coef0 :: []) :: [])));;
let define_matrix_coef2201 = Polynomial_coefficient
(Coefficient_matrix (Matrix_matrix
((define_coef2 :: define_coef2 :: []) ::
(define_coef1:: define_coef1 :: []) :: [])));;
let matrix_coef2200 = Matrix_matrix
((define_coef2 :: define_coef2 :: []) ::
(define_coef0:: define_coef0 :: []) :: []);;
(* Polynomial *)
(* p (x1) = |0| + |2 2|.x1
|1| |0 0| *)
let define_poly_sum_prod =
Polynomial_sum (define_matrix_coef2200 :: Polynomial_product
(define_matrix_coef2201 :: define_poly_variable_1 :: []) :: []);;
let define_poly_matrix =
Polynomial_sum (Polynomial_product
(define_matrix_coef2200 :: define_poly_variable_1 :: []) :: []);;
(* Test function [color_matrix_function] in [color_matrix_nat.v]; dim
= 2, n = 1 *)
(* Test [color_matrix_function] with poly_sum and poly_prod both coef
vector and matrix. *)
let print_define_color_matrix_function =
match color_matrix_function 2 1 define_poly_sum_prod with
| Ok p -> print_string "\n---------------------\n";
print_string "\n Print [color_matrix_function]: \n";
print_matrixInt p
| Ko _ -> print_string "Error [color_matrix_function]!";;
(* Test [color_matrix_function] alone with poly_sum and coef_matrix *)
let print_define_color_matrix_function2 =
match color_matrix_function 2 1 define_poly_matrix with
| Ok p -> print_string "\n---------------------\n";
print_string "\n Print [color_matrix_function] with matrix : \n";
print_matrixInt p
| Ko _ -> print_string "Error [color_matrix_function] with matrix1!";;
(* Test [color_matrix_function] alone with coef_matrix *)
let print_define_color_matrix_function3 =
match color_matrix_function 2 1 define_matrix_coef2200 with
| Ok p -> print_string "\n---------------------\n";
print_string "\n Print [color_matrix_function] with matrix : \n";
print_matrixInt p
| Ko _ -> print_string "\nError [color_matrix_function] with matrix!";;
open VecUtil;;
open NatUtil;;
open Matrix2;;
open Cpf2color_vector;;
(* Test [bgt_nat] in [type_matrix_naturals] *)
let is_bgt_nat =
match color_matrix 2 matrix_coef2200 with
| Ok m ->
print_string "\n---------------------\n";
print_string "bgt_nat: ";
let bm = bVforall (fun _ -> bgt_nat (get_elem 2 2 m 0 0)0) 1 m in
print_string (string_of_bool bm);
print_string "\n---------------------\n"
| _ -> print_string " Error [is_bgt_nat] ";;
(****************************************************************************)
(* Define value for polynomial function for matrix interpretation over
domain Arctic natural numbers *)
(* Coefficient *)
(* MinusInf *)
let define_coef_minusInf = Coefficient_minusInfinity;;
(* Pos 1 *)
let define_coef_Pos1 = Coefficient_number (Number_integer 1);;
(* Negative *)
let define_coef_negative = Coefficient_number (Number_integer (-1));;
(* Test function [color_coef_arcnat] in [color_matrix_arc_nat.v],
print minusInf *)
let print_color_coef_arcnat_minusInf =
match color_coef_arcnat define_coef_minusInf with
| Ok i -> print_string "\n---------------------\n";
print_string "\n Print [color_coef_arcnat] coefficient MinusInf: ";
print_coqArcInt i
| Ko _ -> print_string "Error [color_coef_arcnat]!";;
let print_color_coef_arcnat_Pos1 =
match color_coef_arcnat define_coef_Pos1 with
| Ok i -> print_string "\n---------------------\n";
print_string "\n Print [color_coef_arcnat] coefficient (Pos 1): ";
print_coqArcInt i; print_newline()
| Ko _ -> print_string "Error [color_coef_arcnat]!\n";;
let print_color_coef_arcnat_negative =
match color_coef_arcnat define_coef_negative with
| Ok i -> print_string "\n---------------------\n";
print_string "\n Print [color_coef_arcnat] coefficient Negative: ";
print_coqArcInt i
| Ko _ -> print_string "\n---------------------\n";
print_string "Error [color_coef_arcnat]!";;
(* Vector *)
(* v = minusInf :: minusInf :: minusInf :: nil *)
let define_coef_vector =
Vector_vector(Coefficient_minusInfinity
:: Coefficient_minusInfinity :: Coefficient_minusInfinity :: []);;
(* v = minusInf *)
let define_vector_minus = Vector_vector (Coefficient_minusInfinity :: []);;
(* Matrix *)
(* m = (1::0::0::nil)::(m :: m :: m:: nil) :: (m :: m :: m::nil) :: nil
| 1 0 0 |
| m m m |
| m m m | *)
let define_coef_list_arc_1_0_0 =
Coefficient_number (Number_integer 1) :: Coefficient_number (Number_integer 0)
:: Coefficient_number (Number_integer 0) :: [];;
let define_coef_list_arc_minus_minus =
Coefficient_minusInfinity :: Coefficient_minusInfinity :: Coefficient_minusInfinity :: [];;
let list_list_matrix = define_coef_list_arc_1_0_0 :: define_coef_list_arc_minus_minus ::
define_coef_list_arc_minus_minus :: [];;
let define_matrix_arc = Matrix_matrix list_list_matrix;;
(* Define matrix with dimension = 1 *)
let define_list_minus = Coefficient_minusInfinity :: [];;
let define_matrix_dim1 = Matrix_matrix (define_list_minus :: []);;
(* Test [color_vector_arcnat] in [color_matrix_arctic_nat.v], dim = 3 *)
let print_color_vector_arcnat =
match color_vector_arcnat 3 define_coef_vector with
| Ok i ->
let () = print_string "\n---------------------\n";
print_string "v = minusInf :: minusInf :: minusInf :: nil\n";
print_string "Print [color_vector_arcnat]: \n" in
print_vec_arc_column i;
print_string "---------------------\n"
| Ko _ -> print_string " Error [color_vector_arcnat]!\n";;
(* Test [color_vector_arcnat] when dim = 1 *)
let print_color_vector_arcnat_dim1 =
match color_vector_arcnat 1 define_vector_minus with
| Ok i ->
let () = print_string "\n---------------------\n";
print_string "v = minusInf :: nil\n";
print_string "Print [color_vector_arcnat] when dim=1: \n" in
print_vec_arc_column i;
print_string "---------------------\n"
| Ko _ -> print_string " Error [color_vector_arcnat]!\n";;
(* Test [color_matrix_arcnat] in [color_matrix_arctic_nat.v], dim = 3 *)
let print_color_matrix_arcnat =
match color_matrix_arcnat 3 define_matrix_arc with
| Ok i ->
let () = print_string "\n---------------------\n";
print_string "\n m = [1::0::0] :: [MinusInf :: MinusInf :: MinusInf]\
:: [MinusInf :: MinusInf :: MinusInf]: \n";
print_string "Print [color_matrix_arcnat]: \n"
in
print_matrix_arc i;
print_string "---------------------\n"
| Ko _ -> print_string " Error [color_matrix_arcnat]!\n";;
(* Test [color_matrix_arcnat] when dim = 1 *)
let print_color_matrix_arcnat_dim1 =
match color_matrix_arcnat 1 define_matrix_dim1 with
| Ok i ->
let () = print_string "\n---------------------\n";
print_string "\n m = (MinusInf :: nil) :: nil \n";
print_string "Print [color_matrix_arcnat] when dim = 1: \n"
in
print_matrix_arc i;
print_string "---------------------\n"
| Ko _ -> print_string " Error [color_matrix_arcnat] when dim = 1!\n";;
(* Define [polynomial] *)
(* p (x1) = | 0 | + |1 m|.x1
| m | |0 m|
*)
(* Vector v = (0, m) *)
let define_vector_0m = Polynomial_coefficient (Coefficient_vector (
Vector_vector (Coefficient_number (Number_integer 0) :: Coefficient_minusInfinity :: [])));;
(* Vector v = (1, m) *)
let define_vector_1m = Polynomial_coefficient (Coefficient_vector (
Vector_vector (Coefficient_number (Number_integer 1) :: Coefficient_minusInfinity :: [])));;
(* Matrix m = (m :: m :: nil) :: (0 :: m :: nil) :: nil) *)
let define_list1 = Coefficient_minusInfinity :: Coefficient_minusInfinity :: [];;
let define_list2 = Coefficient_number (Number_integer 0) :: Coefficient_minusInfinity :: [];;
let define_matrix_1m = Polynomial_coefficient (
(Coefficient_matrix (Matrix_matrix (define_list1 :: define_list2 :: []))));;
(* Matrix m = (m :: m :: nil) :: (0 :: m :: nil) :: nil) *)
let define_list_m1 = Coefficient_minusInfinity :: Coefficient_minusInfinity :: [];;
let define_list_m2 = Coefficient_number (Number_integer 0) :: Coefficient_minusInfinity :: [];;
let define_matrix_2m = Polynomial_coefficient (
(Coefficient_matrix (Matrix_matrix (define_list_m1 :: define_list_m2 :: []))));;
let define_poly_matrix_arcnat = Polynomial_sum (
Polynomial_product (define_vector_0m :: []) ::
Polynomial_product (define_matrix_1m :: define_poly_variable_1 :: []) :: []);;
(* |1| + |m m|. x1
|m| |0 m|
*)
let define_poly_matrix_arcnat2 = Polynomial_sum (
Polynomial_product (define_vector_1m :: []) ::
Polynomial_product (define_matrix_2m :: define_poly_variable_1 :: []) :: []);;
let print_color_matrix_arcnat_function =
match color_matrix_arcnat_function 2 1 define_poly_matrix_arcnat with
| Ok p -> print_string "\n---------------------\n";
print_string "\n Print [color_matrix_arcnat_function]: \n";
print_matrixArcNat p
| Ko _ -> print_string "Error [color_matrix_arcnat_function]!\n";;
(* Test [color_matrix_arcnat_function], dim = 2, n = 1 *)
(*
|m| + |m|.x1 + |3|.x2
*)
let define_vector_m = Polynomial_coefficient (Coefficient_vector (Vector_vector (Coefficient_minusInfinity :: [])));;
let define_matrix_m = Polynomial_coefficient
(Coefficient_matrix (Matrix_matrix ((Coefficient_minusInfinity :: []) :: [])));;
let define_matrix_3 = Polynomial_coefficient
(Coefficient_matrix (Matrix_matrix ((Coefficient_number (Number_integer 3) :: []) :: [])));;
let define_poly_matrix_arcnat_dim1 = Polynomial_sum (
Polynomial_product (define_vector_m :: []) ::
Polynomial_product (define_matrix_3 :: define_poly_variable_1 :: []) :: []);;
(* Polynomial_product (define_matrix_3 :: define_poly_variable_2 :: []) :: []);;*)
let print_color_matrix_arcnat_function_dim1 =
match color_matrix_arcnat_function 1 1 define_poly_matrix_arcnat_dim1 with
| Ok p -> print_string "\n---------------------\n";
print_string "\n Print [color_matrix_arcnat_function] dim 1: \n";
print_matrixArcNat p
| Ko _ -> print_string "Error [color_matrix_arcnat_function] dim 1!\n";;
(* Test [bmint_arc_gt] *)
(* p1(x1) = |1| + |m m|.x1
|m| |0 m|
p2(x1) = |0| + |m m|.x1
|m| |0 m| *)
let print_bmint_arc_gt =
match color_matrix_arcnat_function 2 1 define_poly_matrix_arcnat2,
color_matrix_arcnat_function 2 1 define_poly_matrix_arcnat with
| Ok p1, Ok p2 ->
(match bmint_arc_gt 2 1 p1 p2 with
| true -> print_string "[bmint_arc_gt]: ";
print_string "true"
| false ->
print_string "[bmint_arc_gt]: ";
print_string "false")
| _, _ -> print_string "Error [bmint_arc_gt]!";;
(* Test the condition [is_finite], dim = 3, n = 1 *)
open VecUtil;;
open SemiRing2;;
open Matrix2;;
(* v = minusInf :: minusInf :: minusInf :: nil *)
(* m = (1::0::0::nil)::(m :: m :: m:: nil) :: (m :: m :: m::nil) :: nil
| 1 0 0 |
| m m m |
| m m m | *)
let is_finite_of_vector_and_matrix =
match color_vector_arcnat 3 define_coef_vector,
color_matrix_arcnat 3 define_matrix_arc with
| Ok v, Ok m ->
print_string "\n---------------------\n";
print_string "Is vector and matrix finite: ";
let bm = bVexists (fun _ -> is_finite (get_elem_arcnat 3 3 m 0 0)) 1 m in
let bv = is_finite (coq_Vnth 3 v 0) in
print_string (string_of_bool ((||) bm bv));
print_string "\n---------------------\n"
| _, _ -> print_string " Error [is_finite] vector and matrix";;
(* Test [is_finite] with dim = 1, n = 1, matrix = |-00|, vector = |-00| *)
let is_finite_of_vector_and_matrix_dim1 =
match color_vector_arcnat 1 define_vector_minus,
color_matrix_arcnat 1 define_matrix_dim1 with
| Ok v, Ok m ->
print_string "\n---------------------\n";
print_string "Is vector and matrix finite when dim = 1: ";
let bm = bVexists (fun _ -> is_finite (get_elem_arcnat 1 1 m 0 0)) 1 m in
let bv = is_finite (coq_Vnth 1 v 0) in
print_string (string_of_bool ((||) bm bv));
print_string "\n\n"
| _, _ -> print_string " Error [is_finite] vector and matrix when dim = 1";
print_string "\n---------------------\n";;
(* Test [bgt_arc] in [color_matrix_arctic_nat.v] *)
(* true case *)
let print_bgt_arc =
match bgt_arc (Pos 1) (MinusInf) with
| true -> print_string "Pos 1 >_arc MinusInf: "; print_string "true";
print_newline()
| false -> print_string "Pos 1 >_arc MinusInf: "; print_string "false";
print_newline();;
let print_bgtx2 =
match bgtx (MinusInf) (MinusInf) with
| true -> print_string "MinusInf >> MinusInf: "; print_string "true";
print_newline()
| false -> print_string "MinusInf >> MinusInf: "; print_string "false";
print_newline();;
(* false case *)
let print_bgt_arc1 =
match bgt_arc (MinusInf) (Pos 1) with
| true -> print_string "MinusInf >_arc Pos 1: "; print_string "true";
print_newline()
| false -> print_string "MinusInf >_arc Pos 1: "; print_string "false";
print_newline();;
(* Test [bge_arc] in [color_matrix_arctic_nat.v] *)
let print_bge_arc =
match bge_arc (Pos 1) (MinusInf) with
| true -> print_string "Pos 1 >=_arc MinusInf: "; print_string "true";
print_newline()
| false -> print_string "Pos 1 >=_arc MinusInf: "; print_string "false";
print_newline();;
(* false case *)
let print_bge_arc2 =
match bge_arc (MinusInf) (Pos 1) with
| true -> print_string "MinusInf >=_arc Pos 1: "; print_string "true";
print_newline()
| false -> print_string "MinusInf >=_arc Pos 1: "; print_string "false";
print_newline();;
(* Test [bmint_arc_ge] *)
(****************************************************************************)
(* Define value for polynomial function for matrix interpretation over
domain Arctic integer numbers *)
(* v = -1 :: minusInf :: 1 :: nil *)
let define_coef_vector_arcbz = Vector_vector(
Coefficient_number (Number_integer (-1)) :: Coefficient_minusInfinity ::
Coefficient_number (Number_integer 1) :: []);;
(* m = (0 :: 0 :: -1) :: (m :: 0 :: m) :: (-1 :: -1 :: 0) :: nil
| 0 0 -1 |
| m 0 m |
| -1 -1 0 | *)
let define_list1_arcbz = Coefficient_number (Number_integer 0) ::
Coefficient_number (Number_integer 0) :: Coefficient_number (Number_integer (-1)) :: [];;
let define_list2_arcbz = Coefficient_minusInfinity :: Coefficient_number (Number_integer 0) ::
Coefficient_minusInfinity :: [];;
let define_list3_arcbz = Coefficient_number (Number_integer (-1))
:: Coefficient_number (Number_integer (-1)) :: Coefficient_number (Number_integer 0) :: [];;
let list_list_arcbz = define_list1_arcbz :: define_list2_arcbz :: define_list3_arcbz :: [];;
let define_coef_matrix_arcbz = Matrix_matrix list_list_arcbz;;
let define_coef_vector_true = Vector_vector define_list1_arcbz;;
(* Test [color_coef_arcbz] in [color_matrix_arctic_below_zero.v] *)
let print_color_coef_arcbz =
match color_coef_arcbz define_coef_negative with
| Ok i -> print_string "\n---------------------\n";
print_string "\n Print [color_coef_arcbz] coefficient negative: ";
print_coqArcBZ i
| Ko _ -> print_string "Error [color_coef_arcbz]!";;
(* Test [color_vector_arcbz] *)
let print_color_vector_arcbz =
match color_vector_arcbz 3 define_coef_vector_arcbz with
| Ok i ->
let () = print_string "\n---------------------\n";
print_string "v = -1 :: minusInf :: 1 :: nil\n";
print_string "Print [color_vector_arcbz]: \n" in
print_vec_arcbz_column i;
print_string "---------------------\n"
| Ko _ -> print_string " Error [color_vector_arcbz]!\n";;
(* Test [color_matrix_arcbz] *)
let print_color_matrix_arcbz =
match color_matrix_arcbz 3 define_coef_matrix_arcbz with
| Ok i ->
let () = print_string "\n---------------------\n";
print_string "\n m = [0::0::-1] :: [MinusInf :: 0 :: MinusInf]\
:: [-1 :: -1 :: 0]: \n";
print_string "Print [color_matrix_arcbz]: \n"
in print_matrix_arcbz i;
print_string "---------------------\n"
| Ko _ -> print_string " Error [color_matrix_arcnat]!\n";;
(* p (x1) =
|-1 | + | 0 0 -1 |
| m | | m 0 m |
| 1 | | -1 -1 0 | *)
let poly_vector = Polynomial_coefficient (Coefficient_vector define_coef_vector_arcbz);;
let poly_matrix = Polynomial_coefficient (Coefficient_matrix (
define_coef_matrix_arcbz));;
let define_poly_matrix_arcbz = Polynomial_sum (
Polynomial_product (poly_vector :: []) ::
Polynomial_product ( poly_matrix :: define_poly_variable_1 :: []) :: []);;
(* Test [color_matrix_arcbz_function] *)
let print_color_matrix_arcbz_function =
match color_matrix_arcbz_function 3 1 define_poly_matrix_arcbz with
| Ok p -> print_string "\n---------------------\n";
print_string "\n Print [color_matrix_arcbz_function]: \n";
print_matrixArcBZ p
| Ko _ -> print_string "Error [color_matrix_arcbz_function]!";;
open OrdSemiRing2;;
(* Test [is_above] *)
let is_above_zero_of_vector =
match color_vector_arcbz 3 define_coef_vector_arcbz with
| Ok v ->
print_string "\n---------------------\n";
print_string "Is vector above zero: ";
let is_above = is_above_zero (coq_Vnth 3 v 0) in
print_string (string_of_bool is_above);
print_string "\n---------------------\n"
| _ -> print_string " Error [is_above] vector";;
let is_above_zero_of_vector_true =
match color_vector_arcbz 3 define_coef_vector_true with
| Ok v ->
print_string "\n---------------------\n";
print_string "Is vector above zero: ";
let is_above = is_above_zero (coq_Vnth 3 v 0) in
print_string (string_of_bool is_above);
print_string "\n---------------------\n"
| _ -> print_string " Error [is_above] vector";;
*)
(****************************************************************************)
(* [vector_of_list] in [cpf2color.v] *)
(*
let define_list = 1 :: 0 :: 0 :: 0 :: [];;
let print_length =
print_string "\n- Length of the list: ";
print_int (length define_list); print_newline();;
(* Test the function [vector_of_list] *)
let print_vector_of_list =
match vector_of_list define_list 4 with
| Ok l -> print_string "- Print [vector_of_list]:";
print_vec_int_column l
| _ -> print_string " Error of vector_of_list! \n";;
(* Test the function [int_to_nat] in [cpf2color.v] *)
let print_int_nat i =
match int_to_nat i with
| Ok i ->
let () = print_string "\n - Print [int_to_nat]: \n" in printf "%i " i
| Ko _ -> print_string "error";;
(* Test the function [list_int_to_list_nat]. *)
let define_list2 = 0 :: 0 :: 1 :: 0 :: [];;
let print_list_int_to_nat =
match list_int_to_list_nat define_list2 with
| Ok l -> print_string "- Print [list_int_to_list_nat]: ";
List.iter print_int l
| _ -> print_string " Error of list_int_to_list_nat! \n";;
(* [list_int_to_list_map] testing a list using [map] *)
let list_int_to_list_nat l =
Cpf_util.map int_to_nat l;;
let print_list_int_to_nat' =
match list_int_to_list_nat define_list2 with
| Ok l -> print_string "- Print [list_int_to_list_nat]: ";
List.iter print_int l
| _ -> print_string " Error of list_int_to_list_nat! \n";;
(* TEST: [list_int_to_list_map_rev] by using [map_rev] *)
let list_int_to_list_nat_rev l =
map_rev int_to_nat l;;
let print_list_int_to_nat_rev =
match list_int_to_list_nat_rev define_list2 with
| Ok l -> print_string "- Print [list_int_to_list_nat_rev]: ";
List.iter print_int l
| _ -> print_string " Error of list_int_to_list_nat! \n";;
(* Function testing convert integer number to an ArcticDom. *)
let int_to_arcnat i0 =
(fun f0 fp fn z -> if z=0 then f0 () else if z>0 then fp z else fn (-z))
(fun _ -> (Pos 0))
(fun i1 -> (Pos (Pos.to_nat i1)))
(fun _i1 -> MinusInf)
i0;;
let map_int_to_arcnat l = map int_to_arcnat l;;
let print_int_to_arcnat1 = print_string "print negative: ";
print_coqArcInt (int_to_arcnat (-1)); print_newline();;
let print_int_to_arcnat2 = print_string "print 1:";
print_coqArcInt (int_to_arcnat (1)); print_newline();;
let print_int_to_arcnat3 = print_string "print 0:";
print_coqArcInt (int_to_arcnat 0); print_newline();;
(* Test [vec_of_list] in [VecUtil.v] *)
let print_define_vec_of_list =
print_string "\n- Print vec_of_list\n:";
print_vec_int_column (VecUtil.vec_of_list define_list2);;
(* Test [map] function in [cpf2color.v] *)
let print_map f =
match map f define_list with
| l -> List.iter print_int l;;*)
(* Test [split_list] in [cpf2color.v] *)
let define_list_tuple = (((1, 0), 0), 0) :: (((2, 0), 0), 0) :: [];;
let print_split_list =
print_string "\nPrint [split_list]: ";
List.iter print_int (split_list define_list_tuple); print_newline();;
(***************************************************)
(* Pmult_nat *)
let print_pos_to_nat = print_string " positive to nat: ";
print_int (Pos.to_nat 1); print_newline();;
let print_pos_to_nat_minus = print_string "postive to nat minus: ";
print_int (minus (Pos.to_nat 1) (succ 0)); print_newline();;
let rec iter_op op p a =
(fun f2p1 f2p f1 p ->
if p<=1 then f1 () else if p mod 2 = 0 then f2p (p/2) else f2p1 (p/2))
(fun p0 ->
op a (iter_op op p0 (op a a)))
(fun p0 ->
iter_op op p0 (op a a))
(fun _ ->
a)
p;;
let to_nat x = iter_op plus x (succ 0);; (* succ 0 = 1 *)
let print_my_to_nat = print_string "my to nat: ";
print_int (to_nat (succ 0)); print_newline();;
(*********************************************************)
(* Print xsd list *)
(*********************************************************)
(* TEST [nats_incr_lt] in ListUtil.v *)
(*
open Prf_of_newcpf;;
let nat_lt =
let n = nats_incr_lt 4 in
print_string "print nats_incr_lt of n=4 : ";
List.iter print_int n;;
let p = 1 :: 2 :: 3 :: 4 :: [];;
let print_color_position =
print_string "\n print color_positive 3: \n";
print_int (color_positiveInteger 3);;
let list_position_nat2 p =
let p2 = position p in
if p2 = nats_incr_lt 4 then []
else p2;;
let list_position_nat3 p =
let p2 = position p in
if equiv beq_nat p2 (nats_incr_lt 3) then []
else p2;;
let print_list_position_nat3 =
print_string "Print list_position_nat3: \n";
List.iter print_int (list_position_nat3 p);;
let print_list_position_nat2 =
print_string "\nPrint list_position_nat2: \n";
List.iter print_int (list_position_nat2 p);;
let print_list_position_nat =
let n = list_position_nat p in
print_string "\nprint list position nat: 1 2 3 4: \n";
List.iter print_int n;;
let nat_incr ps n =
if equiv beq_nat (list_position_nat ps)(nats_incr_lt n)
then []
else list_position_nat ps;;