-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrsp3.scm
13682 lines (11544 loc) · 296 KB
/
grsp3.scm
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
;; =========================================================================
;;
;; grsp3.scm
;;
;; Relational vectors, matrices, files and databases. In general, these
;; functions constitute the basis for other functions found in the grspX.scm
;; files, where X > 3.
;;
;; =========================================================================
;;
;; Copyright (C) 2020 - 2024 Pablo Edronkin (pablo.edronkin at yahoo.com)
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this program. If not, see
;; <https://www.gnu.org/licenses/>.
;;
;; =========================================================================
;;;; General notes:
;;
;; - Read sources for limitations on function parameters.
;; - grsp3 provides some level of matrix algebra functionality for Guile,
;; but in its current version it is not intended to be particulary fast.
;; It does not make use of any additional non-Scheme library like BLAS
;; or Lapack.
;; - As a convention here, m represents rows, n represents columns;
;; variations in this theme include:
;;
;; - lm: lowest row number.
;; - hm: highest row number.
;; - ln: lowest col number.
;; - hn: highest col number.
;; - tm: total number of rows.
;; - tn: total number of columns.
;;
;; - All matrices referred in this file are numeric except wherever
;; specifically stated.
;;
;; Sources:
;;
;; See code of functions used and their respective source files for more
;; credits and references.
;;
;; - [1] Hep.by. (2020). Array Procedures - Guile Reference Manual. [online]
;; Available at:
;; http://www.hep.by/gnu/guile/Array-Procedures.html#Array-Procedures
;; [Accessed 28 Jan. 2020].
;; - [2] En.wikipedia.org. (2020). Numerical linear algebra. [online]
;; Available at: https://en.wikipedia.org/wiki/Numerical_linear_algebra
;; [Accessed 28 Jan. 2020].
;; - [3] En.wikipedia.org. (2020). Matrix theory. [online] Available at:
;; https://en.wikipedia.org/wiki/Category:Matrix_theory
;; [Accessed 28 Jan. 2020].
;; - [4] En.wikipedia.org. (2020). List of matrices. [online] Available at:
;; https://en.wikipedia.org/wiki/List_of_matrices [Accessed 8 Mar. 2020].
;; - [5] Gnu.org. (2020). Random (Guile Reference Manual). [online]
;; Available at:
;; https://www.gnu.org/software/guile/manual/html_node/Random.html
;; [Accessed 26 Jan. 2020].
;; - [6] Es.wikipedia.org. (2020). Factorización LU. [online] Available at:
;; https://es.wikipedia.org/wiki/Factorizaci%C3%B3n_LU
;; [Accessed 28 Jan. 2020].
;; - [7] Gnu.org. (2020). Guile Reference Manual. [online] Available at:
;; https://www.gnu.org/software/guile/manual/guile.html#Arithmetic
;; [Accessed 6 Feb. 2020].
;; - [8] En.wikipedia.org. (2020). Elementary matrix. [online] Available at:
;; https://en.wikipedia.org/wiki/Elementary_matrix#Operations
;; [Accessed 24 Feb. 2020].
;; - [9] En.wikipedia.org. 2020. Determinant. [online] Available at:
;; https://en.wikipedia.org/wiki/Determinant [Accessed 2 August 2020].
;; - [10] En.wikipedia.org. 2020. Leibniz Formula For Determinants.
;; [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Leibniz_formula_for_determinants
;; [Accessed 4 August 2020].
;; - [11] En.wikipedia.org. 2020. Invertible Matrix. [online] Available at:
;; https://en.wikipedia.org/wiki/Invertible_matrix [Accessed 5 August
;; 2020].
;; - [12] En.wikipedia.org. 2020. Permanent (Mathematics). [online]
;; Available at: https://en.wikipedia.org/wiki/Permanent_(mathematics)
;; [Accessed 7 August 2020].
;; - [13] En.wikipedia.org. 2020. Immanant. [online] Available at:
;; https://en.wikipedia.org/wiki/Immanant [Accessed 14 August 2020].
;; - [14] En.wikipedia.org. 2020. Eigendecomposition Of A Matrix. [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix
;; - [15] En.wikipedia.org. 2020. Eigenvalue Algorithm. [online]
;; Available at: https://en.wikipedia.org/wiki/Eigenvalue_algorithm
;; [Accessed 12 August 2020].
;; - [16] En.wikipedia.org. 2021. Relational algebra. [online] Available
;; at: https://en.wikipedia.org/wiki/Relational_algebra [Accessed 16
;; March 2021].
;; - [17] En.wikipedia.org. 2021. Support (mathematics). [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Support_(mathematics)> [Accessed 27
;; March 2021].
;; - [18] Mathispower4u. (2020). LU Decomposition. [online] Available at:
;; https://www.youtube.com/watch?v=UlWcofkUDDU [Accessed 5 Mar. 2020].
;; - [19] En.wikipedia.org. 2021. Genetic algorithm - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Genetic_algorithm
;; [Accessed 13 May 2021].
;; - [20] En.wikipedia.org. 2021. Crossover (genetic algorithm) -
;; Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/Crossover_(genetic_algorithm)
;; [Accessed 13 May 2021].
;; - [21] En.wikipedia.org. 2021. Mutation (genetic algorithm) - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Mutation_(genetic_algorithm)
;; [Accessed 13 May 2021].
;; - [22] En.wikipedia.org. 2021. Selection (genetic algorithm) -
;; Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/Selection_(genetic_algorithm)
;; [Accessed 13 May 2021].
;; - [23] fitness, A., 2015. Accumulated normalized fitness. [online] Stack
;; Overflow. Available at:
;; https://stackoverflow.com/questions/27524241/accumulated-normalized-fitness
;; [Accessed 13 May 2021].
;; - [24] En.wikipedia.org. 2021. Multiset - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Multiset [Accessed 17
;; September 2021].
;; - [25] Gnuplotting.org. 2021. Plotting data « Gnuplotting. [online]
;; Available at: http://www.gnuplotting.org/plotting-data/
;; [Accessed 21 November 2021].
;; - [26] Gnu.org. 2022. Scheduling (Guile Reference Manual). [online]
;; Available at:
;; https://www.gnu.org/software/guile/manual/html_node/Scheduling.html
;; [Accessed 16 May 2022].
;; - [27] En.wikipedia.org. 2022. Pauli matrices - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Pauli_matrices
;; [Accessed 16 May 2022].
;; - [28] En.wikipedia.org. 2022. Gamma matrices - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Gamma_matrices#Dirac_basis
;; [Accessed 16 May 2022].
;; - [29] En.wikipedia.org. 2022. Higher-dimensional gamma matrices -
;; Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/Higher-dimensional_gamma_matrices
;; [Accessed 16 May 2022].
;; - [30] En.wikipedia.org. 2022. Gell-Mann matrices - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Gell-Mann_matrices
;; [Accessed 19 May 2022].
;; - [31] En.wikipedia.org. 2022. Quantum logic gate - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Quantum_logic_gate
;; [Accessed 31 May 2022].
;; - [32] En.wikipedia.org. 2022. Quantum circuit - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Quantum_circuit
;; [Accessed 31 May 2022].
;; - [33] En.wikipedia.org. 2022. Penrose graphical notation - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Penrose_graphical_notation
;; [Accessed 31 May 2022].
;; - [34] En.wikipedia.org. 2022. Categorical quantum mechanics -
;; Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/Categorical_quantum_mechanics
;; [Accessed 31 May 2022].
;; - [35] En.wikipedia.org. 2022. Qutrit - Wikipedia. [online] Available
;; at: https://en.wikipedia.org/wiki/Qutrit#Qutrit_quantum_gates
;; [Accessed 31 May 2022].
;; - [36] En.wikipedia.org. 2022. Tensor product - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Tensor_product
;; [Accessed 31 May 2022].
;; - [37] En.wikipedia.org. 2022. Kronecker product - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Kronecker_product
;; [Accessed 31 May 2022].
;; - [38] Product, T., Borah, M. and Orrick, W., 2022. Tensor product and
;; Kronecker Product. [online] Mathematics Stack Exchange. Available at:
;; https://math.stackexchange.com/questions/203947/tensor-product-and-kronecker-product
;; [Accessed 1 June 2022].
;; - [39] En.wikipedia.org. 2022. List of named matrices - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/List_of_named_matrices [Accessed 6
;; June 2022].
;; - [40] En.wikipedia.org. 2022. Hermitian adjoint - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Hermitian_adjoint
;; [Accessed 9 June 2022].
;; - [41] En.wikipedia.org. 2022. Conjugate transpose - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Conjugate_transpose
;; [Accessed 9 June 2022].
;; - [42] En.wikipedia.org. 2022. Minor (linear algebra) - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Minor_(linear_algebra)
;; [Accessed 9 June 2022].
;; - [43] GeeksforGeeks. 2022. Doolittle Algorithm : LU Decomposition -
;; GeeksforGeeks. [online] Available at:
;; https://www.geeksforgeeks.org/doolittle-algorithm-lu-decomposition/
;; [Accessed 27 June 2022].
;; - [44] En.wikipedia.org. 2022. Crout matrix decomposition - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Crout_matrix_decomposition
;; [Accessed 27 June 2022].
;; - [45] En.wikipedia.org. 2022. Unit vector - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Unit_vector
;; [Accessed 27 June 2022].
;; - [46] En.wikipedia.org. 2022. Dot product - Wikipedia. [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Dot_product [Accessed 27 June 2022].
;; - [47] En.wikipedia.org. 2022. Inner product space - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Inner_product_space
;; [Accessed 27 June 2022].
;; - [48] En.wikipedia.org. 2022. Gram–Schmidt process - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process
;; [Accessed 27 June 2022].
;; - [49] 1980. Algorithms for the QR-Decomposition. [ebook] Zuerich.
;; Gander. Available at:
;; https://people.inf.ethz.ch/gander/papers/qrneu.pdf [Accessed 6 July
;; 2022].
;; - [50] Bindel, 2017. Householder QR. [ebook] Available at:
;; https://www.cs.cornell.edu/~bindel/class/cs6210-f09/lec18.pdf
;; [Accessed 6 July 2022].
;; - [51] People.math.wisc.edu. 2022. qr-4-ls-by-qr. [online] Available at:
;; https://people.math.wisc.edu/~roch/mmids/qr-4-ls-by-qr.html
;; [Accessed 6 July 2022].
;; - [52] En.wikipedia.org. 2022. Wilson matrix - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Wilson_matrix [Accessed
;; 7 July 2022].
;; - [53] En.wikipedia.org. 2022. Cholesky decomposition - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Cholesky_decomposition [Accessed 7
;; July 2022].
;; - [54] Es.wikipedia.org. 2022. Norma matricial - Wikipedia, la
;; enciclopedia libre. [online] Available at:
;; https://es.wikipedia.org/wiki/Norma_matricial [Accessed 10 July 2022].
;; - [55] En.wikipedia.org. 2022. QR algorithm - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/QR_algorithm [Accessed
;; 18 July 2022].
;; - [56] En.wikipedia.org. 2022. List of numerical analysis topics -
;; Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/List_of_numerical_analysis_topics
;; [Accessed 18 July 2022].
;; - [57] En.wikipedia.org. 2022. Matrix splitting - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Matrix_splitting
;; [Accessed 21 July 2022].
;; - [58] En.wikipedia.org. 2022. Gauss–Seidel method - Wikipedia. [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method [Accessed
;; 21 July 2022].
;; - [59] En.wikipedia.org. 2022. Jacobi method - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Jacobi_method [Accessed
;; 21 July 2022].
;; - [60] En.wikipedia.org. 2022. Spectral radius - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Spectral_radius
;; [Accessed 22 July 2022].
;; - [61] En.wikipedia.org. 2022. Rotation matrix - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Rotation_matrix
;; [Accessed 5 October 2022].
;; - [62] Eigenvector and eigenvalue (no date) Math is Fun Advanced.
;; Available at: https://www.mathsisfun.com/algebra/eigenvalue.html
;; (Accessed: January 26, 2023).
;; - [63] Ciobanu, A. (2021) Writing your own Linear Algebra Matrix
;; Library in C, andreinc. Available at:
;; https://www.andreinc.net/2021/01/20/writing-your-own-linear-algebra-matrix-library-in-c#solving-linear-systems-of-equations
;; (Accessed: January 26, 2023).
;; - [64] Forward substitution (no date) Algowiki. Available at:
;; https://algowiki-project.org/en/Forward_substitution
;; (Accessed: January 26, 2023).
;; - [65] Backward substitution (no date) Algowiki. Available at:
;; https://algowiki-project.org/en/Backward_substitution
;; (Accessed: January 26, 2023).
;; - [66] Singular Value Decomposition (SVD) tutorial BE.400 / 7.548
;; (no date) Singular value decomposition (SVD) tutorial. Available at:
;; https://web.mit.edu/be.400/www/SVD/Singular_Value_Decomposition.htm
;; (Accessed: March 13, 2023).
;; - [67] Singular value decomposition (2023) Wikipedia. Wikimedia
;; Foundation. Available at:
;; https://en.wikipedia.org/wiki/Singular_value_decomposition
;; (Accessed: March 16, 2023).
;; - [68] Frobenius inner product (2022) Wikipedia. Wikimedia Foundation.
;; Available at: https://en.wikipedia.org/wiki/Frobenius_inner_product
;; (Accessed: March 16, 2023).
;; - [69] Khatri–rao product (2023) Wikipedia. Wikimedia Foundation.
;; Available at: https://en.wikipedia.org/wiki/Khatri%E2%80%93Rao_product
;; (Accessed: March 17, 2023).
;; - [70] Block matrix (2023) Wikipedia. Wikimedia Foundation. Available
;; at: https://en.wikipedia.org/wiki/Block_matrix (Accessed: March 28,
;; 2023).
;; - [71] https://www.gnu.org/software/guile/manual/html_node/Futures.html
(define-module (grsp grsp3)
#:use-module (grsp grsp0)
#:use-module (grsp grsp1)
#:use-module (grsp grsp2)
#:use-module (grsp grsp4)
#:use-module (grsp grsp11)
#:use-module (ice-9 threads)
#:use-module (ice-9 futures)
#:use-module (ice-9 string-fun)
#:export (grsp-lm
grsp-hm
grsp-ln
grsp-hn
grsp-tm
grsp-tn
grsp-matrix-order
grsp-matrix-esi
grsp-matrix-create
grsp-matrix-create-set
grsp-matrix-create-fix
grsp-matrix-create-dim
grsp-matrix-change
grsp-matrix-find
grsp-matrix-transpose
grsp-matrix-transposer
grsp-matrix-conjugate
grsp-matrix-conjugate-transpose
grsp-matrix-opio
grsp-matrix-opsc
grsp-matrix-opew
grsp-matrix-opewl
grsp-matrix-opfn
grsp-matrix-opmm
grsp-matrix-opmml
grsp-matrix-opmsc
grsp-matrix-cpy
grsp-matrix-subcpy
grsp-matrix-subrep
grsp-matrix-subdcn
grsp-matrix-subdel
grsp-matrix-subexp
grsp-matrix-is-equal
grsp-matrix-is-square
grsp-matrix-is-symmetric
grsp-matrix-is-diagonal
grsp-matrix-is-hermitian
grsp-matrix-is-binary
grsp-matrix-is-nonnegative
grsp-matrix-is-positive
grsp-matrix-row-opar
grsp-matrix-row-opmm
grsp-matrix-row-opsc
grsp-matrix-row-opsw
grsp-matrix-decompose
grsp-matrix-density
grsp-matrix-is-sparse
grsp-matrix-is-symmetric-md
grsp-matrix-total-elements
grsp-matrix-total-element
grsp-matrix-is-hadamard
grsp-matrix-is-markov
grsp-matrix-is-signature
grsp-matrix-is-single-entry
grsp-matrix-identify
grsp-matrix-is-metzler
grsp-l2m
grsp-m2l
grsp-m2v
grsp-dbc2mc
grsp-dbc2mc-csv
grsp-mc2dbc
grsp-mc2dbc-sqlite3
grsp-mc2dbc-hdf5
grsp-mc2dbc-csv
grsp-mc2dbc-gnuplot1
grsp-mc2dbc-gnuplot2
grsp-matrix-interval-mean
grsp-matrix-determinant-lu
grsp-matrix-determinant-qr
grsp-matrix-is-invertible
grsp-eigenval-opio
grsp-matrix-sort
grsp-matrix-minmax
grsp-matrix-trim
grsp-matrix-select
grsp-matrix-row-minmax
grsp-matrix-row-select
grsp-matrix-row-delete
grsp-matrix-row-sort
grsp-matrix-row-invert
grsp-matrix-commit
grsp-matrix-row-selectn
grsp-matrix-col-selectn
grsp-matrix-col-select
grsp-matrix-njoin
grsp-matrix-sjoin
grsp-matrix-ajoin
grsp-matrix-supp
grsp-matrix-row-div
grsp-matrix-row-update
grsp-matrix-te1
grsp-matrix-te2
grsp-matrix-row-append
grsp-matrix-lojoin
grsp-matrix-subrepv
grsp-matrix-subswp
grsp-matrix-col-total-element
grsp-matrix-row-deletev
grsp-matrix-clear
grsp-matrix-clearni
grsp-matrix-row-cartesian
grsp-matrix-col-append
grsp-matrix-col-find-nth
grsp-mn2ll
grsp-matrix-mutation
grsp-matrix-col-mutation
grsp-matrix-col-lmutation
grsp-matrix-crossover
grsp-matrix-crossover-rprnd
grsp-matrix-same-dims
grsp-matrix-fitness-rprnd
grsp-matrix-selectg
grsp-matrix-keyon
grsp-matrix-col-aupdate
grsp-matrix-row-selectc
grsp-matrix-is-empty
grsp-matrix-is-multiset
grsp-matrix-argtype
grsp-matrix-argstru
grsp-matrix-row-subrepal
grsp-matrix-subdell
grsp-matrix-is-samedim
grsp-matrix-is-samediml
grsp-matrix-fill
grsp-matrix-fdif
grsp-matrix-opewc
grsp-matrix-row-opew-mth
grsp-matrix-opew-mth
grsp-mr2l
grsp-l2mr
grsp-matrix-is-traceless
grsp-matrix-movemm
grsp-matrix-movsmm
grsp-matrix-movcrm
grsp-matrix-movtrm
grsp-matrix-ldiagonal
grsp-matrix-minor
grsp-matrix-minor-cofactor
grsp-matrix-cofactor
grsp-matrix-inverse
grsp-matrix-adjugate
grsp-mn2ms
grsp-matrix-spjustify
grsp-matrix-slongest
grsp-ms2s
grsp-matrix-display
grsp-ms2mn
grsp-matrix-tio
grsp-matrix-diagonal-update
grsp-matrix-diagonal-vector
grsp-matrix-row-proj
grsp-matrix-normp
grsp-matrix-normf
grsp-matrix-normm
grsp-eigenval-qr
grsp-eigenvec
grsp-matrix-is-srddominant
grsp-matrix-jacobim
grsp-matrix-sradius
grsp-ms2ts
grsp-mr2ls
grsp-dbc2lls
grsp-matrix-row-prkey
grsp-matrix-strot
grsp-matrix-row-corr
grsp-matrix-correwl
grsp-matrix-wlongest
grsp-matrix-mmt
grsp-matrix-mtm
grsp-matrix-fsubst
grsp-matrix-bsubst
grsp-matrix-compatibility
grsp-matrix-part-create
grsp-matrix-is-filled-with
grsp-matrix-row-selectrn
grsp-matrix-col-selectcn
grsp-matrix-row-subrepf
grsp-matrix-row-subreps
grsp-matrix-ldvl
grsp-matrix-blur
grsp-matrix-col-replacev
grsp-matrix-selectmb
grsp-matrix-row-opscr
grsp-ms2dbc
grsp-dbc2ms
grsp-matrix-split
grsp-matrix-inputev
grsp-matrix-row-inputev
grsp-matrix-rows-inputev
grsp-matrix-rows-addev
grsp-matrix-rows-filled-with
grsp-matrix-displayts
grsp-matrix-subadd
grsp-matrix-displaytn
grsp-matrix-edit
grsp-my2ms
grsp-matrix-displaytm
grsp-matrix-editu
grsp-my2code
grsp-ms2my
grsp-cy2cy
grsp-ms2mb
grsp-matrix-row-select-like
grsp-matrix-sincostan-mth
grsp-matrix-row-number
grsp-matrix-keygen
grsp-matrix-keyapl
grsp-matrix-subdelr
grsp-matrix-row-vol
grsp-ms-get-longest-element
grsp-ms-create-col-headers
grsp-ms-create-row-headers
grsp-ms-pad-elements
grsp-matrix-displaytms
grsp-matrix-row-subrepk
grsp-matrix-row-numk
grsp-matrix-subrepk
grsp-matrix-row-subrepkl
grsp-matrix-row-col-setk
grsp-matrix-find-if-prkey-exists
grsp-matrix-row-subexpk
grsp-matrix-row-insert
grsp-matrix-tf-idf
grsp-matrix-row-insert-ioe
grsp-2l2cm
grsp-l2cm))
;;;; grsp-lm - Short form of (grsp-matrix-esi 1 p_a1).
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices, properties, dimensions, size
;;
;; Parameters:
;;
;; - p_a1: matrix.
;;
;; Notes:
;;
;; - See grsp-matrix-esi.
;;
;; Output:
;;
;; - Numeric, lm value.
;;
(define (grsp-lm p_a1)
(let ((res1 0))
(set! res1 (grsp-matrix-esi 1 p_a1))
res1))
;;;; grsp-hm - Short form of (grsp-matrix-esi 2 p_a1).
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices
;;
;; Parameters:
;;
;; - p_a1: matrix.
;;
;; Notes:
;;
;; - See grsp-matrix-esi.
;;
;; Output:
;;
;; - Numeric, hm value.
;;
(define (grsp-hm p_a1)
(let ((res1 0))
(set! res1 (grsp-matrix-esi 2 p_a1))
res1))
;;;; grsp-ln - Short form of (grsp-matrix-esi 3 p_a1).
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices
;;
;; Parameters:
;;
;; - p_a1: matrix.
;;
;; Notes:
;;
;; - See grsp-matrix-esi.
;;
;; Output:
;;
;; - Numeric, ln value.
;;
(define (grsp-ln p_a1)
(let ((res1 0))
(set! res1 (grsp-matrix-esi 3 p_a1))
res1))
;;;; grsp-hn - Short form of (grsp-matrix-esi 4 p_a1).
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices
;;
;; Parameters:
;;
;; - p_a1: matrix.
;;
;; Notes:
;;
;; - See grsp-matrix-esi.
;;
;; Output:
;;
;; - Numeric, hn value.
;;
(define (grsp-hn p_a1)
(let ((res1 0))
(set! res1 (grsp-matrix-esi 4 p_a1))
res1))
;;;; grsp-tm - Convenience function that returns the total number of rows
;; in p_a1.
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices
;;
;; Parameters:
;;
;; - p_a1: matrix.
;;
;; Notes:
;;
;; - See grsp-matrix-te2.
;;
;; Output:
;;
;; - Numeric, (+ (- hm lm)) value.
;;
(define (grsp-tm p_a1)
(let ((res1 0)
(res2 0))
(set! res2 (grsp-matrix-te2 p_a1))
(set! res1 (array-ref res2 0 0))
res1))
;;;; grsp-tn - Convenience function that returns the total number of cols
;; in p_a1.
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices
;;
;; Parameters:
;;
;; - p_a1: matrix.
;;
;; Notes:
;;
;; - See grsp-matrix-te2.
;;
;; Output:
;;
;; - Numeric, (+ (- hn ln)) value.
;;
(define (grsp-tn p_a1)
(let ((res1 0)
(res2 0))
(set! res2 (grsp-matrix-te2 p_a1))
(set! res1 (array-ref res2 0 1))
res1))
;;;; grsp-matrix-order - Returns the order (* tm tn) of a matrix.
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices, vectors
;;
;; Parameters:
;;
;; - p_a1: matrix.
;;
;; Output:
;;
;; - Numeric.
;;
(define (grsp-matrix-order p_a1)
(let ((res1 (* (grsp-tm p_a1) (grsp-tn p_a1))))
res1))
;;;; grsp-matrix-esi - Extracts shape information from an m x n matrix.
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices, vectors
;;
;; Parameters:
;;
;; - p_e1: number indicating the element value desired.
;;
;; - 1: lm. low boundary for m (rows).
;; - 2: hm. high boundary for m (rows).
;; - 3: ln. low boundary for n (cols).
;; - 4: hn. high boundary for n (cols).
;;
;; - p_m1: m.
;;
;; Sources:
;;
;; - [1][2][3][4].
;;
;; Output:
;;
;; - A number corresponding to the shape element value desired. Returns
;; zero if p_e1 is incorrect.
;;
(define (grsp-matrix-esi p_e1 p_m1)
(let ((res1 0)
(s1 0))
(set! s1 (array-shape p_m1))
(cond ((equal? p_e1 1)
(set! res1 (car (car s1))))
((equal? p_e1 2)
(set! res1 (car (cdr (car s1)))))
((equal? p_e1 3)
(set! res1 (car (car (cdr s1)))))
((equal? p_e1 4)
(set! res1 (car (cdr (car (cdr s1)))))))
res1))
;;;; grsp-matrix-create - Creates an p_m1 x p_n1 matrix and fills it with
;; element value p_s1.
;;
;; Keywords:
;;
;; - functions, algebra, matrix, matrices, vectors
;;
;; Parameters:
;;
;; - p_s1: matrix type.
;;
;; - "#I": Identity matrix.
;; - "#AI": Anti Identity matrix (anti diagonal).
;; - "#Q": Quincunx matrix.
;; - "#Test1": Test matrix 1 (LU decomposable)[1].
;; - "#Test2": Test matrix 2 (LU decomposable)[2].
;; - "#Ladder": Ladder matrix.
;; - "#Arrow": Arrowhead matrix.
;; - "#Hilbert": Hilbert matrix.
;; - "#Lehmer": Lehmer matrix.
;; - "#Pascal": Pascal matrix.
;; - "#Ex2SVD": 4 x 2 matrix example for SVD, see [66].
;; - "#Ex1SVD": 4 X 5 matrix example for SVD, see [67].
;; - "#CH": 0-1 checkerboard pattern matrix.
;; - "#CHR": 0-1 checkerboard pattern matrix, randomized.
;; - "#+IJ": matrix containing the sum of i and j values.
;; - "#-IJ": matrix containing the substraction of i and j values.
;; - "#+IJ": matrix containing the product of i and j values.
;; - "#-IJ": matrix containing the quotient of i and j values.
;; - "#US": upper shift matrix.
;; - "#LS": lower shift matrix.
;; - "#UT": upper triangular matrix, with value 1 in non-zero elements.
;; - "#LT": lower triangular matrix, with value 1 in non-zero elements.
;; - "#rprnd": pseduo random values, normal distribution, sd = 0.15.
;; - "#zrow": zebra row.
;; - "#zcol": zebra col.
;; - "#n0[-m:+m]": matrix of (2m +1 ) rows and n cols, with first column
;; element -m and last row, first col element reaching m.
;;
;; - p_m1: rows, positive integer.
;; - p_n1: cols, positive integer.
;;
;; Examples:
;;
;; - example3.scm, example5.scm.
;;
;; Notes:
;;
;; - See grsp0.grsp-s2dbc, grsp0.grsp-dbc2s, grsp0.grsp-random-state-set.
;;
;; Output:
;;
;; - Matrix.
;;
;; Sources:
;;
;; - [1][2][18][31].
;;
(define (grsp-matrix-create p_s1 p_m1 p_n1)
(let ((res1 0)
(t1 "n")
(s1 0)
(i1 0)
(j1 0)
(m1 p_m1)
(m3 p_m1)
(n1 p_n1)
(p0 0)
(p1 0)
(p2 0)
(p3 0))
(cond ((eq? (grsp-eiget m1 0) #t)
(cond ((eq? (grsp-eiget n1 0) #t)
;; For an identity matrix, first set all elements to 0.
(cond ((equal? p_s1 "#I")
(set! s1 0))
((equal? p_s1 "#AI")
(set! s1 0))
((equal? p_s1 "#Q")
(set! s1 1)
(set! m1 2)
(set! n1 2))
((equal? p_s1 "#Test1")
(set! s1 0)
(set! m1 3)
(set! n1 3))
((equal? p_s1 "#Test2")
(set! s1 0)
(set! m1 3)
(set! n1 3))
((equal? p_s1 "#Ladder")
(set! s1 1))
((equal? p_s1 "#Arrow")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#Hilbert")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#Lehmer")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#Pascal")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#Ex2SVD")
(set! s1 0))
((equal? p_s1 "#Ex1SVD")
(set! s1 0))
((equal? p_s1 "#Fibonacci")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#CH")
(set! s1 0))
((equal? p_s1 "#CHR")
(set! s1 0))
((equal? p_s1 "#+IJ")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#-IJ")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#*IJ")
(set! s1 1)
(set! n1 m1))
((equal? p_s1 "#/IJ")
(set! s1 1)
(set! n1 m1))
((equal? p_s1 "#US")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#LS")
(set! s1 0)
(set! n1 m1))
((equal? p_s1 "#rprnd")
(set! s1 0))
((equal? p_s1 "#zrow")
(set! s1 0))
((equal? p_s1 "#zcol")
(set! s1 0))
((equal? p_s1 "#n0[-m:+m]")
(set! s1 0)
(set! m1 (+ 1 (* m1 2))))
(else (set! s1 p_s1)))
;; Build the matrix.
(set! res1 (make-array s1 m1 n1))
;; Once the matrix has been created, depending on the
;; type of matrix, modify its values.
(cond ((equal? p_s1 "#I")
(while (< i1 m1)
(set! j1 0)
(while (< j1 n1)
(cond ((eq? i1 j1)
(array-set! res1 1 i1 j1)))
(set! j1 (+ j1 1)))
(set! i1 (+ i1 1))))
((equal? p_s1 "#Test1")
(set! res1 (grsp-l2mr res1 (list 1 4 -3) 0 0))
(set! res1 (grsp-l2mr res1 (list -2 8 5) 1 0))
(set! res1 (grsp-l2mr res1 (list 3 4 7) 2 0)))
((equal? p_s1 "#Test2")
(set! res1 (grsp-l2mr res1 (list 2 4 -4) 0 0))
(set! res1 (grsp-l2mr res1 (list 1 -4 3) 1 0))
(set! res1 (grsp-l2mr res1 (list -6 -9 5) 2 0)))
((equal? p_s1 "#Ladder")
(while (< i1 m1)
(set! j1 0)
(while (< j1 n1)
(array-set! res1 s1 i1 j1)
(set! s1 (+ s1 1))
(set! j1 (+ j1 1)))
(set! i1 (+ i1 1))))
((equal? p_s1 "#Arrow")
(set! res1 (grsp-matrix-create "#I" m1 n1))
(grsp-matrix-row-opsc "#+" res1 0 1)
(set! res1 (grsp-matrix-transpose res1))
(grsp-matrix-row-opsc "#+" res1 0 1)
(set! res1 (grsp-matrix-transpose res1))
(set! res1 (grsp-matrix-transpose res1))
(array-set! res1 1 0 0))
((equal? p_s1 "#AI")
(set! i1 (- m1 1))
(while (>= i1 0)
(set! j1 (- n1 1))
(while (>= j1 0)
(cond ((equal? (+ i1 j1) (- m1 1))
(array-set! res1 1 i1 j1)))
(set! j1 (- j1 1)))
(set! i1 (- i1 1))))
((equal? p_s1 "#Hilbert")
(while (< i1 m1)
(set! j1 0)
(while (< j1 n1)
(array-set! res1
(/ 1
(- (+ (+ i1 1) (+ j1 1))
1))
i1
j1)
(set! j1 (+ j1 1)))
(set! i1 (+ i1 1))))
((equal? p_s1 "#Lehmer")
(while (< i1 m1)
(set! j1 0)
(while (< j1 n1)
(array-set! res1 (/ (min (+ i1 1)
(+ j1 1))
(max (+ i1 1)
(+ j1 1)))
i1 j1)
(set! j1 (+ j1 1)))
(set! i1 (+ i1 1))))
((equal? p_s1 "#Pascal")
(while (< i1 m1)
(set! j1 0)
(while (< j1 n1)
(array-set! res1
(grsp-biconr (+ i1 j1)