-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ijs
2355 lines (2265 loc) · 92.9 KB
/
test.ijs
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
NB. Test
NB.
NB. drvevx Dyads to compute the normalization error of
NB. eigenvectors produced by nonsymmetric eigenvalue
NB. problem solver
NB. drgev Adv. to make dyad to compute the relative
NB. backward error of eigenvectors produced by
NB. generalized nonsymmetric eigenvalue problem
NB. solver
NB. xxt01 Actors to compute the relative backward error
NB. for the matrix reconstructed from gexxf,tzxxf
NB. output
NB. t02x Modifiers to make dyad to compute the relative
NB. backward error for the solution(s) computed
NB. xxt02 Dyads to compute the relative backward error for
NB. the matrix reconstructed partially from ungxx
NB. output
NB. t03 Dyad to compute the relative backward error for
NB. the matrix times its inverse reconstructed
NB. xxt03 Actors to compute the relative backward error
NB. for the matrix [partial] multiplication by
NB. unmxxxx
NB. t04x Actors to compute the relative forward error for
NB. the solution(s) computed
NB. xxt11 Dyads to compute the relative backward error for
NB. the unitary (orthogonal) matrix reconstructed
NB. from gexpf gepxf output
NB. qrt14 Checks whether X is in the row space of op(A)
NB. qrt16x Adv. to make dyad to compute the residual for a
NB. solution(s) computed of an overdetermined or
NB. underdetermined system involving a matrix of
NB. full rank, or its [conjugate-]transpose
NB. qrt171 Adv. to make dyad to compute the ratio for
NB. zero-residual problem
NB. t211 Dyad to compute the relative backward error of
NB. eigenvectors produced by symmetric eigenvalue
NB. problem solver
NB. t22x Dyads to compute the error of eigenvectors
NB. produced by nonsymmetric eigenvalue problem
NB. solver
NB. t511x Dyads to compute the error of generalized Schur
NB. form produced by hgexxsxx
NB. t513x Monads to compute the error of Schur vectors
NB. produced by hgexxsxx
NB. t52xx Dyads to compute the error of Schur vectors
NB. produced by tgevcxxx
NB. chk1mv Adv. to make dyad to compute the relative
NB. backward error for the basic matrix-vector
NB. operation with general matrix
NB. chk1mm Adv. to make dyad to compute the relative
NB. backward error for the basic matrix-matrix
NB. operation with general matrices
NB. chk2mv Adv. to make dyad to compute the relative
NB. backward error for the basic hermitian
NB. (symmetric) matrix-vector operation
NB. chk2mm Adv. to make dyad to compute the relative
NB. backward error for the basic hermitian
NB. (symmetric) matrix-matrix operation
NB. chk3mv Adv. to make dyad to compute the relative
NB. backward error for the basic matrix-vector
NB. operation with triangular matrix
NB. chk3mm Adv. to make dyad to compute the relative
NB. backward error for the basic matrix-matrix
NB. operation with triangular matrix
NB. chk3sv Adv. to make dyad to compute the relative
NB. backward error for the basic equation solver
NB. with triangular matrix
NB. chk3sm Adv. to make dyad to compute the relative
NB. backward error for the basic matrix equation
NB. solver with triangular matrix
NB. chk4r Adv. to make dyad to compute the relative
NB. backward error for the basic rank 1 operation
NB. with general matrix
NB. chk4rk Conj. to make dyad to compute the relative
NB. backward error for the basic hermitian
NB. (symmetric) rank k operation
NB. chk5r Conj. to make dyad to compute the relative
NB. backward error for the basic hermitian
NB. (symmetric) rank 1 operation
NB. chk5r2k Conj. to make dyad to compute the relative
NB. backward error for the basic hermitian
NB. (symmetric) rank 2k operation
NB. chk6r2 Conj. to make dyad to compute the relative
NB. backward error for the basic hermitian
NB. (symmetric) rank 2 operation
NB.
NB. Copyright 2010,2011,2013,2017,2018,2020,2021,2023,2024,
NB. 2025 Igor Zhuravlov
NB.
NB. This file is part of mt
NB.
NB. mt is free software: you can redistribute it and/or
NB. modify it under the terms of the GNU Lesser General
NB. Public License as published by the Free Software
NB. Foundation, either version 3 of the License, or (at your
NB. option) any later version.
NB.
NB. mt is distributed in the hope that it will be useful, but
NB. WITHOUT ANY WARRANTY; without even the implied warranty
NB. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
NB. See the GNU Lesser General Public License for more
NB. details.
NB.
NB. You should have received a copy of the GNU Lesser General
NB. Public License along with mt. If not, see
NB. <http://www.gnu.org/licenses/>.
NB. =========================================================
NB. Configuration
coclass 'mt'
NB. =========================================================
NB. Local definitions
NB. ---------------------------------------------------------
NB. drvev
NB.
NB. Description:
NB. Monad to compute the normalization error of
NB. eigenvectors produced by nonsymmetric eigenvalue
NB. problem solver
NB.
NB. Syntax:
NB. nerrV=. drvev V
NB. where
NB. V - n×n-matrix, either left or right eigenvectors
NB. nerrV ≥ 0, the normalization error
NB. n ≥ 0, the size of V
NB.
NB. Formula:
NB. err := max(errL,errR)
NB. vrmax[j] := max(|Re(V[i,j])|)
NB. i | Im(V[i,j]) == 0
NB.
NB. vmax[j] := max(|V[:,j]|)
NB. i
NB.
NB. if ∃ j | vrmax[j] / vmax[j] < 1 - 2 * FP_PREC then
NB. errV := 1 / FP_PREC
NB. else
NB. errV := max(min(| ||V[:,j]||_E - 1 | , 1) / FP_PREC)
NB. j
NB. endif
NB. where
NB. V - either L or R
NB. errV - either errL or errR
NB.
NB. Notes:
NB. - models LAPACK's xDRVEV
drvev=: (% FP_PREC)"_`(>./@(FP_PREC %~ 1 ([ <. |@:-) normsc))@.((1 _2 p. FP_PREC) *./@:<: (%~&(>./@:|) ({."1 (* 0 = *) {:"1)@:+.))
NB. ---------------------------------------------------------
NB. cberrAfact
NB.
NB. Description:
NB. Conj. to make dyad to compute the relative backward
NB. error of matrix factorization
NB.
NB. Syntax:
NB. berr=. (A ; normA) (normx cberrAfact mul) factors
NB. where
NB. normx - monad to compute matrix norm; is called as:
NB. normM=. normx M
NB. mul - monad to compute Aapprox; is called as:
NB. Aapprox=. mul factors
NB. A - n×n-matrix to decompose
NB. normA ≥ 0, the norm of A
NB. factors - any noun, boxed factors of Aapprox
NB. Aapprox - the same shape as A, approximate A
NB. berr ≥ 0, the relative backward error
NB. n ≥ 0, the size of A and Aapprox
NB.
NB. Formula:
NB. n := size(A)
NB. ||A|| := max(normx(A) , FP_SFMIN)
NB. ||F|| := normx(A - Aapprox)
NB. if ||A|| > ||F|| then
NB. berr := (||F|| / ||A||) / (FP_PREC * n)
NB. elseif 1 > ||A|| then
NB. berr := (min(||F|| , n * ||A||) / ||A||) / (FP_PREC * n)
NB. else
NB. berr := min(||F|| / ||A|| , n) / (FP_PREC * n)
NB. endif
NB.
NB. Notes:
NB. - models LAPACK's xGET51(1), xGET51(2) and 1st check in
NB. DSYT21(1) and ZHET21(1) when normx is norm1
cberrAfact=: 2 : '(u@((- 0&{::)~ v) ((% {:) <. 0 { ])`((<. */) % 1 { ])@.(1 ([ > {) ])`(% {:)@.(< {:) #@(0 {:: [) , FP_SFMIN >. 1 {:: [) % (FP_PREC * #@(0 {:: [))'
NB. ---------------------------------------------------------
NB. aberrU
NB.
NB. Description:
NB. Adv. to make monad to compute the relative backward
NB. error of unitary (orthogonal) matrix
NB.
NB. Syntax:
NB. berrU=. (compI aberrU) Uapprox
NB. where
NB. compI - monad to compute Iapprox; is called as:
NB. Iapprox=. compI Uapprox
NB. Uapprox - n×n-matrix, approximate unitary (orthogonal)
NB. Iapprox - n×n-matrix, approximate identity matrix
NB. berrU ≥ 0, the relative backward error for Uapprox
NB. n ≥ 0, the size of A, Uapprox and Iapprox
NB.
NB. Formula:
NB. n := size(Uapprox)
NB. berrU := min(||Iapprox - I||_1 , n) / (FP_PREC * n)
NB.
NB. Notes:
NB. - models LAPACK's 2nd check in DSYT21(1) and ZHET21(1)
aberrU=: 1 : 'norm1@(<: upddiag)@u (<. % FP_PREC * ]) #'
NB. =========================================================
NB. Interface
NB. ---------------------------------------------------------
NB. drvevl
NB. drvevr
NB.
NB. Description:
NB. Dyads to compute the normalization error of
NB. eigenvectors produced by nonsymmetric eigenvalue
NB. problem solver
NB.
NB. Syntax:
NB. errL=. trash drgevl (trash ; L ; trash)
NB. errR=. trash drgevr (trash ; trash ; R )
NB. where
NB. L - n×n-matrix, columns with left eigenvectors
NB. R - n×n-matrix, columns with right eigenvectors
NB. errL ≥ 0, float, scalar, error for L
NB. errR ≥ 0, float, scalar, error for R
drvevl=: drvev@(1 {:: ])
drvevr=: drvev@(2 {:: ])
NB. ---------------------------------------------------------
NB. drgev
NB.
NB. Description:
NB. Adv. to make dyad to compute the relative backward
NB. error of eigenvectors produced by generalized
NB. nonsymmetric eigenvalue problem solver
NB.
NB. Syntax:
NB. vberr=. mmul`vmul`norma`normb drgev
NB. where
NB. mmul - dyad to multiply matrices; is called as:
NB. M3=. M1 mmul M2
NB. vmul - dyad to multiply matrix by diagonal matrix
NB. represented as vector; is called as:
NB. M2=. v1 vmul M1
NB. norma - monad to compute norm of matrix; is called
NB. as:
NB. normM=. norma M1
NB. normb - monad to compute norms of matrix rows
NB. (columns); is called as:
NB. v2=. normb M1
NB. vberr - dyad to compute berr; is called as:
NB. berr=. (AB ; normAB) vberr (e1e2 ; V)
NB. AB - 2×n×n-brick, matrix pair (A,B) to
NB. eigen-decompose
NB. e1e2 - 2×n-matrix, laminated vectors of
NB. generalized eigenvalues α and β
NB. V - either L or R
NB. M1,M2,M3 - n×n-matrix
NB. v1,v2 - n-vector
NB. L - n×n-matrix, columns with left eigenvectors
NB. R - n×n-matrix, columns with right eigenvectors
NB. berr ≥ 0, float, scalar, backward error
NB. normAB -:normA , normB
NB. normA ≥ 0, float, scalar, the norm of matrix A
NB. normB ≥ 0, float, scalar, the norm of matrix B
NB.
NB. Formula:
NB. n := size(A)
NB. berr := max(berr0,berr1)
NB. - for ggevlxx:
NB. ||L|| := max(||L||_inf , FP_PREC)
NB. ||R|| := max(||R||_inf , FP_PREC)
NB. - for L:
NB. berr0 := (||(C2 * (C1 * E2)) * L * A - (C2 * (C1 * E2)) * L * B||_1 / ||L||) / FP_PREC
NB. berr1 := normit(normitc(L) - 1) / (FP_PREC * n)
NB. - for R:
NB. berr0 := (||A * R^H * ((E2 * С1) * С2) - B * R^H * ((E1 * С1) * С2)||_1 / ||R||) / FP_PREC
NB. berr1 := normit(normitc(R) - 1) / (FP_PREC * n)
NB. - for L and R:
NB. berr0 := max(berr0(ggevlvx),berr0(ggevlxv))
NB. berr1 := max(berr1(ggevlvx),berr1(ggevlxv))
NB. - for ggevuxx:
NB. ||L|| := max(||L||_1 , FP_PREC)
NB. ||R|| := max(||R||_1 , FP_PREC)
NB. - for L:
NB. berr0 := (||(C2 * (C1 * E2)) * L^H * A - (C2 * (C1 * E2)) * L^H * B||_1 / ||L||) / FP_PREC
NB. berr1 := normit(normitc(L) - 1) / (FP_PREC * n)
NB. - for R:
NB. berr0 := (||A * R * ((E2 * С1) * С2) - B * R * ((E1 * С1) * С2)||_1 / ||R||) / FP_PREC
NB. berr1 := normit(normitc(R) - 1) / (FP_PREC * n)
NB. - for L and R:
NB. berr0 := max(berr0(ggevuvx),berr0(ggevuxv))
NB. berr1 := max(berr1(ggevuvx),berr1(ggevuxv))
NB. C1 := (diag(coeff1))^_1
NB. C2 := (diag(coeff2))^_1
NB. coeff1(i) := if(sorim(α(i)) > (1/FP_SFMIN) / ||B||
NB. or sorim(β(i)) > (1/FP_SFMIN) / ||A||
NB. or max(sorim(α(i)),sorim(β(i))) < 1)
NB. then max(max(sorim(α(i)),sorim(β(i))),FP_SFMIN)
NB. else 1
NB. coeff2(i) := max(sorim(α(i))*||B||,sorim(β(i))*||A||, FP_SFMIN)
NB. ||A|| := max(||A||_1 , FP_SFMIN)
NB. ||B|| := max(||B||_1 , FP_SFMIN)
NB. where
NB. v(i) - i-th element of vector v
NB.
NB. Application:
NB. - to compute berr for L from ggevlvx:
NB. NB. berr=. AB vberrlL (e1e2 ; L)
NB. vberrlL=: mp_mt_~ "2` * `normi_mt_`normitr_mt_ drgev_mt_
NB. - to compute berr for R from ggevlxv:
NB. NB. berr=. AB vberrlR (e1e2 ; R)
NB. vberrlR=: (mp_mt_ ct_mt_)"2`(*"1)`normi_mt_`normitr_mt_ drgev_mt_
NB. - to compute berr for L from ggevuvx:
NB. NB. berr=. AB vberruL (e1e2 ; L)
NB. vberruL=: (mp_mt_~ ct_mt_)"2` * `norm1_mt_`normitc_mt_ drgev_mt_
NB. - to compute berr for R from ggevuxv:
NB. NB. berr=. AB vberruR (e1e2 ; R)
NB. vberruR=: mp_mt_ "2`(*"1)`norm1_mt_`normitc_mt_ drgev_mt_
NB.
NB. Notes:
NB. - models LAPACK's xDRGEV and xGET52
drgev=: 1 : 0
'`mmul vmul norma normb'=. m
'e1e2 V'=. y
n=. # V
if. 0 = n do. 0 return. end.
banorm=. |. FP_SFMIN >. 1 {:: x NB. 2-vector, float
alfbetmax=. (% FP_SFMIN) % 1 >. banorm NB. 2-vector, float
abs1ab=. sorim"1 e1e2 NB. 2×n-matrix, float
abmax=. (>./) abs1ab NB. n-vector, float
cond=. (+./) (abs1ab > alfbetmax) , 1 > abmax NB. n-vector, boolean
e1e2=. e1e2 (%"1) cond} 1 ,: FP_SFMIN >. abmax NB. 2×n-matrix
abcoeff=. (|. e1e2) (%"1) (>./) FP_SFMIN , abs1ab * banorm NB. 2×n-matrix
Err=. -/ abcoeff vmul (0 {:: x) mmul V NB. n×n-matrix
errnrm=. (norma Err) % FP_PREC >. norma V NB. scalar, float
result1=. errnrm % FP_PREC NB. scalar, float
enrmer=. normir <: normb V NB. scalar, float
result2=. enrmer % FP_PREC * n NB. scalar, float
result1 >. result2 NB. scalar, float
)
NB. ---------------------------------------------------------
NB. get01
NB.
NB. Description:
NB. Conj. to make dyad to compute the relative backward
NB. error for the general matrix reconstructed from
NB. gexxxxxxx output
NB.
NB. Syntax:
NB. berrG=. (G ; normG) (normx get01 getSize) Gapprox
NB. where
NB. normx - monad to compute matrix norm; is called as:
NB. normM=. normx M
NB. getSize - monad to get size of G; is called as:
NB. size=. getSize G
NB. G - m×n-matrix, general
NB. Gapprox - the same shape as G, the approximate G
NB. normG ≥ 0, the norm of G
NB. size ∈ {m,n}, the size of G
NB. berrG ≥ 0, the relative backward error for Gapprox
NB. m ≥ 0, rows in G
NB. n ≥ 0, columns in G
NB.
NB. Formula:
NB. (m,n) := shape(G)
NB. if 0 = m or 0 = n then
NB. berrG := 0
NB. elseif 0 = ||G|| and 0 < ||G - Gapprox|| then
NB. berrG := 1 / FP_EPS
NB. else
NB. berrG := ((||G - Gapprox|| / size) / ||G||) / FP_EPS
NB. endif
NB. where
NB. for getrflu1p : Gapprox := L * U1 * P, size := m, ||matrix|| := ||matrix||_inf
NB. for getrfpl1u and gesvxxx and xGETRF: Gapprox := P * L1 * U, size := n, ||matrix|| := ||matrix||_1
NB. for getrfpu1l : Gapprox := P * U1 * L, size := n, ||matrix|| := ||matrix||_1
NB. for getrful1p : Gapprox := U * L1 * P, size := m, ||matrix|| := ||matrix||_inf
NB.
NB. Notes:
NB. - models LAPACK's xGET01
get01=: 2 : '((FP_EPS , v@]) %~/@,@,.`(%@FP_EPS)@.(</@:*@]) (1 {:: [) , u@(- 0&{::)~)`0:@.(0 e. $@])'
NB. ---------------------------------------------------------
NB. het01
NB.
NB. Description:
NB. Dyad to compute the relative backward error for the
NB. matrix reconstructed from hexxxxx, poxxxxx and ptxxxxx
NB. output
NB.
NB. Syntax:
NB. berrH=. (H ; normH) het01 Happrox
NB. where
NB. H - n×n-matrix, the Hermitian (symmetric),
NB. possibly positive definite, and possibly
NB. tridiagonal
NB. normH ≥ 0, the norm of H
NB. Happrox - the same shape as H, the approximate H
NB. berrH ≥ 0, the relative backward error for Happrox
NB. n ≥ 0, the size of H
NB.
NB. Formula:
NB. n := size(H)
NB. if 0 = n then
NB. berrH := 0
NB. elseif 0 = ||H||_1 and 0 < ||H - Happrox||_1 or ∃ i | 0 ≠ Im(Happrox(i,i)) then
NB. berrH := 1 / FP_EPS
NB. else
NB. berrH := ((||H - Happrox||_1 / n) / ||H||_1) / FP_EPS
NB. endif
NB. where
NB. for hetrfpl and hesvxxx: Happrox := P * L1 * T * L1^H * P^H
NB. for hetrfpu and : Happrox := P * U1 * T * U1^H * P^H
NB. for potrfl and posvxxx: Happrox := L * L^H
NB. for potrfu : Happrox := U * U^H
NB. for pttrfl and ptsvxxx: Happrox := L1 * D * L1^H
NB. for pttrfu : Happrox := U1 * D * U1^H
NB.
NB. Notes:
NB. - models:
NB. - LAPACK's DSYT01_AA, ZHET01_AA and xPTT01 with the
NB. following differences:
NB. - ∞-norm is used instead of 1-norm
NB. - since diag(Happrox) may contain complex values,
NB. then an additional check for (0 = Im(Happrox(i,i)))
NB. is needed as same as in ZHET01 and ZPOT01
NB. - LAPACK's xPOT01 with the following differences:
NB. - ∞-norm is used instead of 1-norm
NB. - a condition (0 < ||H - Happrox||_1) is checked, too
NB. as in other xxxT01
het01=: ((FP_EPS , #@]) %~/@,@,.`(%@FP_EPS)@.(</@:*@]) (1 {:: [) , normi@(- 0&{::)~)`(%@FP_EPS)@.(0 +./@:~: 11 o. diag@])`0:@.(0 = #@])
NB. ---------------------------------------------------------
NB. hst01
NB.
NB. Description:
NB. Adv. to make dyad to compute the relative backward
NB. error for the Hessenberg matrix reconstructed from
NB. gehrdx output
NB.
NB. Syntax:
NB. berrS=. (S ; normS) (normx hst01) Sapprox
NB. where
NB. normx - monad to compute matrix norm; is called as:
NB. normM=. normx M
NB. S - n×n-matrix, the lower or upper Hessenberg
NB. Sapprox - the same shape as S, the approximate S
NB. normS ≥ 0, the norm of S
NB. berrS ≥ 0, the relative backward error for Sapprox
NB. n ≥ 0, the size of S
NB.
NB. Formula:
NB. n := size(S)
NB. ||S|| := max(normx(S) , FP_SFMIN)
NB. if 0 = n then
NB. berrS := 0
NB. else
NB. berrS := (min(||S - Sapprox|| , ||S||) / max((FP_SFMIN * n) / FP_PREC , ||S|| * FP_PREC)) / n
NB. endif
NB. where
NB. for gehrdl: Sapprox := Q^H * H * Q , ||matrix|| := ||matrix||_inf
NB. for gehrdu: Sapprox := Q * H * Q^H, ||matrix|| := ||matrix||_1
NB.
NB. Notes:
NB. - models LAPACK's xHST01 when normx is norm1
hst01=: 1 : '%~/@(#@] ([ , (((>. FP_PREC %~ FP_SFMIN&*)~ FP_PREC&*) {.) , 1 { ]) u@(- 0&{::)~ (] , <.) FP_SFMIN >. 1 {:: [)`0:@.(0 = #@])'
NB. ---------------------------------------------------------
NB. lqt01
NB. qlt01
NB. qrt01
NB. rqt01
NB.
NB. Description:
NB. Dyads to compute the relative backward error for the
NB. matrix reconstructed from gexqf geqxf output
NB.
NB. Syntax:
NB. berrA=. (A ; normA) lqt01 (Lapprox ; Qapprox)
NB. berrA=. (A ; normA) qlt01 (Qapprox ; Lapprox)
NB. berrA=. (A ; normA) qrt01 (Qapprox ; Rapprox)
NB. berrA=. (A ; normA) rqt01 (Rapprox ; Qapprox)
NB. where
NB. A - m×n-matrix
NB. normA ≥ 0, the norm of A
NB. xapprox - approximate factors of A
NB. berrA ≥ 0, the relative backward error of
NB. Q-factorization
NB. m ≥ 0, rows in A
NB. n ≥ 0, columns in A
NB.
NB. Formula:
NB. (m,n) := shape(A)
NB. berrA := max(berr0,berr1)
NB. if 0 < ||A||_1 then
NB. berr0 := ((||F1||_1 / max(1, size)) / ||A||_1) / FP_EPS
NB. else
NB. berr0 := 0
NB. endif
NB. berr1 := (||F2||_1 / max(1, size)) / FP_EPS
NB. where
NB. for gelqf: F1 := L - A * Q^H, F2 := Q * Q^H - I, size := n
NB. for geqlf: F1 := L - Q^H * A, F2 := Q^H * Q - I, size := m
NB. for geqrf: F1 := R - Q^H * A, F2 := Q^H * Q - I, size := m
NB. for gerqf: F1 := R - A * Q^H, F2 := Q * Q^H - I, size := n
NB.
NB. Notes:
NB. - lqt01 models LAPACK's xLQT01
NB. - qlt01 models LAPACK's xQLT01
NB. - qrt01 models LAPACK's xQRT01
NB. - rqt01 models LAPACK's xRQT01
lqt01=: (FP_EPS %~ (1 {:: [) %~ (norm1 % 1 >. c)@(((mp~ 0&{::)~ ct@(1&{::)) - 0 {:: ]))`0:@.(0 = 1 {:: [) >. (FP_EPS %~ (1 >. c) %~ norm1@(<: upddiag)@(mp ct))@(1 {:: ])
qlt01=: (FP_EPS %~ (1 {:: [) %~ (norm1 % 1 >. #)@(((mp 0&{::)~ ct@(0&{::)) - 1 {:: ]))`0:@.(0 = 1 {:: [) >. (FP_EPS %~ (1 >. #) %~ norm1@(<: upddiag)@(mp~ ct))@(0 {:: ])
qrt01=: qlt01
rqt01=: lqt01
NB. ---------------------------------------------------------
NB. lpt01
NB. plt01
NB. prt01
NB. rpt01
NB.
NB. Description:
NB. Dyads to compute the relative backward error for the
NB. matrix reconstructed from gexpf gepxf output
NB.
NB. Syntax:
NB. berrA=. (A ; normA) lpt01 (ip ; LQf)
NB. berrA=. (A ; normA) plt01 (ip ; QfL)
NB. berrA=. (A ; normA) prt01 (ip ; QfR)
NB. berrA=. (A ; normA) rpt01 (ip ; RQf)
NB. where
NB. A - m×n-matrix
NB. normA ≥ 0, the norm of A
NB. ip - inversed permutation of rows or columns of A
NB. xQf,Qfx - Q-factorization of A
NB. berrA ≥ 0, the relative backward error for matrix A
NB. permuted
NB. m ≥ 0, rows in A
NB. n ≥ 0, columns in A
NB.
NB. Formula:
NB. (m,n) := shape(A)
NB. if 0 = m or 0 = n then
NB. berrA := 0
NB. else
NB. berrA := ||F|| / (FP_EPS * max(m,n))
NB. if 0 < ||A|| then
NB. berrA := berrA / ||A||
NB. endif
NB. endif
NB. where
NB. for gelpf: F := P * A - L * Q, ||matrix|| := ||matrix||_inf
NB. for geplf: F := A * P - Q * L, ||matrix|| := ||matrix||_1
NB. for geprf: F := A * P - Q * R, ||matrix|| := ||matrix||_1
NB. for gerpf: F := P * A - R * Q, ||matrix|| := ||matrix||_inf
NB.
NB. Notes:
NB. - prt01 models LAPACK's xQPT01
lpt01=: ((1 {:: [) %~^:(0 < [) C. ~&(0&{::) (normi % FP_EPS * >./@$)@:- (unmlqrn trlpick @:(}:"1))@(1 {:: ]))`0:@.(0 e. $@(0 {:: [))
plt01=: ((1 {:: [) %~^:(0 < [) C."1~&(0&{::) (norm1 % FP_EPS * >./@$)@:- (unmqlln (trlpick~ -~/@$)@ }. )@(1 {:: ]))`0:@.(0 e. $@(0 {:: [))
prt01=: ((1 {:: [) %~^:(0 < [) C."1~&(0&{::) (norm1 % FP_EPS * >./@$)@:- (unmqrln trupick @ }: )@(1 {:: ]))`0:@.(0 e. $@(0 {:: [))
rpt01=: ((1 {:: [) %~^:(0 < [) C. ~&(0&{::) (normi % FP_EPS * >./@$)@:- (unmrqrn (trupick~ -~/@$)@:(}."1))@(1 {:: ]))`0:@.(0 e. $@(0 {:: [))
NB. ---------------------------------------------------------
NB. lzt01
NB. zlt01
NB. zrt01
NB. rzt01
NB.
NB. Description:
NB. Dyads to compute the relative backward error for the
NB. matrix reconstructed from tzxxf output
NB.
NB. Syntax:
NB. berrA=. (A ; normA) lzt01 LZf
NB. berrA=. (A ; normA) zlt01 ZfL
NB. berrA=. (A ; normA) zrt01 ZfR
NB. berrA=. (A ; normA) rzt01 RZf
NB. where
NB. A - m×n-matrix
NB. normA ≥ 0, the norm of A
NB. xZf,Zfx - Z-factorization of trapezoidal part of A
NB. berrA ≥ 0, the relative backward error for xZf, Zfx
NB. m ≥ 0, rows in A
NB. n ≥ 0, columns in A
NB.
NB. Formula:
NB. (m,n) := shape(A)
NB. berrA := max(berr0,berr1)
NB. if 0 = m or 0 = n then
NB. berrA := 0
NB. else
NB. if 0 < ||A|| then
NB. berr0 := (||F1|| / (FP_EPS * size)) / ||A||
NB. else
NB. berr0 := ||F1|| / (FP_EPS * size)
NB. endif
NB. berr1 := ||F2|| / (FP_EPS * size)
NB. endif
NB. where
NB. for tzlzf: F1 := A - L * Z, F2 := Z * Z^H - I, size := n, ||matrix|| := ||matrix||_1
NB. for tzzlf: F1 := A - Z * L, F2 := Z^H * Z - I, size := m, ||matrix|| := ||matrix||_inf
NB. for tzzrf: F1 := A - Z * R, F2 := Z^H * Z - I, size := m, ||matrix|| := ||matrix||_inf
NB. for tzrzf: F1 := A - R * Z, F2 := Z * Z^H - I, size := n, ||matrix|| := ||matrix||_1
NB.
NB. Notes:
NB. - rzt01 models LAPACK's xRZT01 and xRZT02
NB. - shortened geometry is used:
NB. - L (R) is square triangular min(m,n)×min(m,n)-matrix
NB. - Z is m×n-matrix
lzt01=: ((1 {:: [) %~^:(0 < [) (norm1 % FP_EPS * 1 >. c)@((- (trlpick~ -~/@$)@(0&{::))~ (unmlzrn ((1 - c) {."1 ({."1~ -@#)))))`0:@.(0 e. $@]) >. (norm1 % FP_EPS * 1 >. c)@((<: upddiag)~ 0 >. -~/@$)@(unmlzrc unglz)`0:@.(0 e. $)@]
zlt01=: ((1 {:: [) %~^:(0 < [) (normi % FP_EPS * 1 >. #)@((- trlpick @(0&{::))~ (unmzlln ((1 -~ #) {. ({. ~ c)))))`0:@.(0 e. $@]) >. (normi % FP_EPS * 1 >. #)@( <: upddiag )@(unmzllc ungzl)`0:@.(0 e. $)@]
zrt01=: ((1 {:: [) %~^:(0 < [) (normi % FP_EPS * 1 >. #)@((- (trupick~ -~/@$)@(0&{::))~ (unmzrln ((1 - #) {. ({. ~ -@c)))))`0:@.(0 e. $@]) >. (normi % FP_EPS * 1 >. #)@((<: upddiag)~ 0 <. -~/@$)@(unmzrlc ungzr)`0:@.(0 e. $)@]
rzt01=: ((1 {:: [) %~^:(0 < [) (norm1 % FP_EPS * 1 >. c)@((- trupick @(0&{::))~ (unmrzrn ((1 -~ c) {."1 ({."1~ #)))))`0:@.(0 e. $@]) >. (norm1 % FP_EPS * 1 >. c)@( <: upddiag )@(unmrzrc ungrz)`0:@.(0 e. $)@]
NB. ---------------------------------------------------------
NB. unt01
NB.
NB. Description:
NB. Conj. to make monad to compute the relative backward
NB. error for the matrix reconstructed from gehrdx output
NB.
NB. Syntax:
NB. berrU=. (normx unt01 compI) Uapprox
NB. where
NB. normx - monad to compute matrix norm; is called as:
NB. normM=. normx M
NB. compI - monad to compute Iapprox; is called as:
NB. Iapprox=. compI Uapprox
NB. Uapprox - m×n-matrix, approximate unitary (orthogonal)
NB. Iapprox - m×m- or n×n-matrix, approximate identity
NB. matrix
NB. normU ≥ 0, the norm of U
NB. berrU ≥ 0, the relative backward error for Uapprox
NB. m ≥ 0, rows in Uapprox
NB. n ≥ 0, columns in Uapprox
NB.
NB. Formula:
NB. (m,n) := shape(Uapprox)
NB. if 0 = m or 0 = n then
NB. berrU := 0
NB. else
NB. berrU := (||Iapprox - I|| / max(m , n)) / FP_PREC
NB. endif
NB. where
NB. for gehrdl: Iapprox := Q * Q^H, ||matrix|| := ||matrix||_inf
NB. for gehrdu: Iapprox := Q^H * Q , ||matrix|| := ||matrix||_1
NB.
NB. Notes:
NB. - models LAPACK's DORT01, ZUNT01 when normx is norm1
unt01=: 2 : '%~/@(FP_PREC , >./@$ , u@(<: upddiag)@v)`0:@.(0 e. $@])'
NB. ---------------------------------------------------------
NB. t02m (dyadic conj.)
NB. t02v (dyadic adv.)
NB.
NB. Description:
NB. Modifiers to make dyad to compute the relative backward
NB. error for the solution(s) computed
NB.
NB. Syntax:
NB. vberrX=. calcB t02m norm1tx
NB. vberrx=. calcb t02v
NB. where
NB. calcB - dyad to compute Bapprox; is called as:
NB. Bapprox=. Xapprox calcB A
NB. calcb - dyad to compute bapprox; is called as:
NB. bapprox=. xapprox calcb A
NB. norm1tx - monad to compute column-wise or row-wise
NB. vector 1-taxicab-norm for list of vectors; is
NB. called as:
NB. normVectors=. norm1tx vectors
NB. vberrX - dyad to compute the relative backward error
NB. for solutions computed; is called as:
NB. berrX=. (A ; B ; X ; trash ; normA) vberrX Xapprox
NB. vberrx - dyad to compute the relative backward error
NB. for the solution computed; is called as:
NB. berrX=. (A ; b ; x ; trash ; normA) vberrx xapprox
NB. A - n×n-matrix of linear system to solve
NB. B - n×nrhs-matrix or nrhs×n-matrix, exact RHS
NB. b - n-vector, the exact RHS
NB. Bapprox - the same shape as B, approximate RHS:
NB. Bapprox := op(A) * Xapprox or
NB. Bapprox := Xapprox * op(A)
NB. bapprox - n-vector, the approximate RHS:
NB. bapprox := op(A) * xapprox or
NB. bapprox := xapprox * op(A)
NB. X - the same shape as B, exact solutions of
NB. matrix equation:
NB. op(A) * X = B or
NB. X * op(A) = B
NB. x - n-vector, the exact solution of equation:
NB. op(A) * x = b or
NB. x * op(A) = b
NB. Xapprox - the same shape as B, approximate solutions
NB. xapprox - n-vector, the approximate solution
NB. normA ≥ 0, the norm of op(A)
NB. berrX ≥ 0, the relative backward error
NB. n ≥ 0, the order of system
NB. nrhs ≥ 0, the number of RHS
NB.
NB. Formula:
NB. (n,nrhs) := shape(B)
NB. foreach i-th computed solution Xapprox from nrhs solutions do
NB. if 0 = n or 0 = nrhs then
NB. berrX[i] := 0
NB. elseif 0 = ||op(A)|| or 0 = ||Xapprox|| then
NB. berrX[i] := 1 / FP_EPS
NB. else
NB. berrX[i] := ((||B - Bapprox|| / ||op(A)||) / ||Xapprox||) / FP_EPS
NB. endif
NB. endfor
NB. berrX := max(berrX[i])
NB. where
NB. ||vector|| := norm1t(vector)
NB. ||matrix|| := ||matrix||_1 when A is at left of X or either A^T or A^H is from right of X
NB. := ||matrix||_inf when A is at right of X or either A^T or A^H is from left of X
NB. Bapprox := op(A) * Xapprox for (op(A) * X = B) equation
NB. := Xapprox * op(A) for (X * op(A) = B) equation
NB.
NB. Notes:
NB. - models LAPACK's xTRT02, xGET02, xGTT02, xPOT02, xPTT02
t02m=: 2 : 'max@((FP_EPS , 4 {:: [) %~/@,@,.`(%@FP_EPS)@.(0 ([ = {) ])"1 ] ,.&v (u 0&{::)~ - 1 {:: [)`(%@FP_EPS)@.(0 = 4 {:: [)`0:@.(0 e. $@])'
t02v=: 1 : ' ((FP_EPS , 4 {:: [) %~/@,@,.`(%@FP_EPS)@.(0 ([ = {) ]) ] , &norm1tc (u 0&{::)~ - 1 {:: [)`(%@FP_EPS)@.(0 = 4 {:: [)`0:@.(0 = #@])'
NB. ---------------------------------------------------------
NB. lqt02
NB. qlt02
NB. qrt02
NB. rqt02
NB.
NB. Description:
NB. Dyads to compute the relative backward error for the
NB. matrix reconstructed partially from ungxq,ungqx output
NB.
NB. Syntax:
NB. berrQ=. (A ; normA ; LQf ; k) lqt02 Qapprox
NB. berrQ=. (A ; normA ; QfL ; k) qlt02 Qapprox
NB. berrQ=. (A ; normA ; QfR ; k) qrt02 Qapprox
NB. berrQ=. (A ; normA ; RQf ; k) rqt02 Qapprox
NB. where
NB. A - m×n-matrix
NB. normA ≥ 0, the norm of A
NB. xQf,Qfx - Q-factorization of A
NB. k ∈ [0,min(m,n)], an amount of elementary
NB. reflectors taken to form Qapprox
NB. Qapprox - m×n-matrix, approximate unitary (orthogonal),
NB. which is defined as the product of k
NB. elementary reflectors
NB. berrQ ≥ 0, the relative backward error for Qapprox
NB. m ≥ 0, rows in A
NB. n ≥ 0, columns in A
NB.
NB. Formula:
NB. (m,n) := shape(A)
NB. berrQ := max(berr0,berr1)
NB. if 0 < ||A||_1 then
NB. berr0 := ((||F1||_1 / max(1, size)) / ||A||_1) / FP_EPS
NB. else
NB. berr0 := 0
NB. endif
NB. berr1 := (||F2||_1 / max(1, size)) / FP_EPS
NB. where
NB. k ∈ {0, 1, min(m,n)/2, min(m,n)}
NB. for unglq: F1 := L(0 :k-1,0 :m-1) - A(0 :k-1,0:n-1) * Qapprox ^H, F2 := Qapprox * Qapprox^H - I, size := n, Qapprox := H(k-1)' * ... * H(0 )'
NB. for ungql: F1 := L(0 :n-1,n-k:n-1) - Qapprox ^H * A(0:m-1,n-k:n-1) , F2 := Qapprox^H * Qapprox - I, size := m, Qapprox := H(k-1) * ... * H(0 )
NB. for ungqr: F1 := R(0 :n-1,0 :k-1) - Qapprox ^H * A(0:m-1,0 :k-1) , F2 := Qapprox^H * Qapprox - I, size := m, Qapprox := H(0 ) * ... * H(k-1)
NB. for ungrq: F1 := R(m-k:m-1,0 :m-1) - A(m-k:m-1,0:n-1) * Qapprox ^H, F2 := Qapprox * Qapprox^H - I, size := n, Qapprox := H(0 )' * ... * H(k-1)'
NB.
NB. Notes:
NB. - m≤n for LQ and RQ, m≥n for QL and QR
NB. - lqt02 models LAPACK's xLQT02
NB. - qlt02 models LAPACK's xQLT02
NB. - qrt02 models LAPACK's xQRT02
NB. - rqt02 models LAPACK's xRQT02
lqt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. c@(0 {:: [)) , norm1@(( 3&{:: {. trl @ (2&{::))@[ - ((mp~ 3&{:: {. 0&{:: )~ ct)))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. c@(0&{::))~ norm1@(<: upddiag)@(mp ct))
qlt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. #@(0 {:: [)) , norm1@((-@(3&{::) {."1 (trl~ -~/@$)@ (2&{::))@[ - ((mp -@(3&{::) {."1 (0&{::))~ ct)))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. #@(0&{::))~ norm1@(<: upddiag)@(mp~ ct))
qrt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. #@(0 {:: [)) , norm1@(( 3&{:: {."1 tru @ (2&{::))@[ - ((mp 3&{:: {."1 (0&{::))~ ct)))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. #@(0&{::))~ norm1@(<: upddiag)@(mp~ ct))
rqt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. c@(0 {:: [)) , norm1@((-@(3&{::) {. (tru~ -~/@$)@ (2&{::))@[ - ((mp~ -@(3&{::) {. 0&{:: )~ ct)))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. c@(0&{::))~ norm1@(<: upddiag)@(mp ct))
NB. ---------------------------------------------------------
NB. lzt02
NB. zlt02
NB. zrt02
NB. rzt02
NB.
NB. Description:
NB. Dyads to compute the relative backward error for the
NB. matrix reconstructed partially from ungxz,ungzx output
NB.
NB. Syntax:
NB. berrZ=. (A ; normA ; LZf ; k) lzt02 Zapprox
NB. berrZ=. (A ; normA ; ZfL ; k) zlt02 Zapprox
NB. berrZ=. (A ; normA ; ZfR ; k) zrt02 Zapprox
NB. berrZ=. (A ; normA ; RZf ; k) rzt02 Zapprox
NB. where
NB. A - m×n-matrix
NB. normA ≥ 0, the norm of A
NB. xZf,Zfx - Z-factorization of trapezoidal part of A
NB. k ∈ [0,min(m,n)], an amount of elementary
NB. reflectors taken to form Zapprox
NB. Zapprox - m×n-matrix, approximate unitary (orthogonal),
NB. which is defined as the product of k
NB. elementary reflectors
NB. berrZ ≥ 0, the relative backward error for Zapprox
NB. m ≥ 0, rows in A
NB. n ≥ 0, columns in A
NB.
NB. Formula:
NB. (m,n) := shape(A)
NB. berrZ := max(berr0,berr1)
NB. if 0 < ||A||_1 then
NB. berr0 := ((||F1||_1 / max(1, size)) / ||A||_1) / FP_EPS
NB. else
NB. berr0 := 0
NB. endif
NB. berr1 := (||F2||_1 / max(1, size)) / FP_EPS
NB. where
NB. k ∈ {0, 1, min(m,n)/2, min(m,n)}
NB. for unglz: F1 := A(m-k-1:m-1,n-k-1:n-1) - L(m-k-1:m-1,m-k-1:m-1) * Zapprox(m-k-1:m-1,n-k-1:n-1), F2 := Zapprox * Zapprox^H - I, size := n, Zapprox := H(k-1)' * ... * H(0 )'
NB. for ungzl: F1 := A(0 :k-1,0 :k-1) - L(0 :k-1,0 :k-1) *~ Zapprox(0 :k-1,0 :k-1), F2 := Zapprox^H * Zapprox - I, size := m, Zapprox := H(k-1) * ... * H(0 )
NB. for ungzr: F1 := A(m-k-1:m-1,n-k-1:n-1) - R(n-k-1:n-1,n-k-1:n-1) *~ Zapprox(m-k-1:m-1,n-k-1:n-1), F2 := Zapprox^H * Zapprox - I, size := m, Zapprox := H(0 ) * ... * H(k-1)
NB. for ungrz: F1 := A(0 :k-1,0 :k-1) - R(0 :k-1,0 :k-1) * Zapprox(0 :k-1,0 :k-1), F2 := Zapprox * Zapprox^H - I, size := n, Zapprox := H(0 )' * ... * H(k-1)'
NB.
NB. Notes:
NB. - m≤n for LZ and RZ, m≥n for ZL and ZR
NB. - shortened geometry is used:
NB. - L (R) is square triangular min(m,n)×min(m,n)-matrix
NB. - Z is m×n-matrix
lzt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. c@(0 {:: [)) , norm1@(((0 {:: [) trlpick@({.~ 2 # -@#) ]) - (2 {:: [) (({.~ 2 # -@#) mp ({."1~ -@#)@]) ]))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. c@(0&{::))~ norm1@(<: upddiag)@(mp ct))
zlt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. #@(0 {:: [)) , norm1@(((0 {:: [) trlpick@({.~ 2 # c) ]) - (2 {:: [) (({.~ 2 # c) mp~ ({. ~ c)@]) ]))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. #@(0&{::))~ norm1@(<: upddiag)@(mp~ ct))
zrt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. #@(0 {:: [)) , norm1@(((0 {:: [) trupick@({.~ 2 # -@c) ]) - (2 {:: [) (({.~ 2 # -@c) mp~ ({. ~ -@c)@]) ]))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. #@(0&{::))~ norm1@(<: upddiag)@(mp~ ct))
rzt02=: %~/@(FP_EPS , (1 {:: [) , (1 >. c@(0 {:: [)) , norm1@(((0 {:: [) trupick@({.~ 2 # #) ]) - (2 {:: [) (({.~ 2 # #) mp ({."1~ #)@]) ]))`0:@.(0 = 1 {:: [) >. FP_EPS %~ ((% 1 >. c@(0&{::))~ norm1@(<: upddiag)@(mp ct))
NB. ---------------------------------------------------------
NB. t03
NB.
NB. Description:
NB. Dyad to compute the relative backward error for the
NB. matrix times its inverse reconstructed
NB.
NB. Syntax:
NB. berriA=. (A ; rcondA ; normA) t03 iAapprox
NB. where
NB. A - n×n-matrix, general or triangular or
NB. Hermitian (symmetric), possibly positive
NB. definite, possibly tridiagonal
NB. rcondA ≥ 0, the reciprocal of the condition number of
NB. A
NB. normA ≥ 0, the norm of A
NB. iAapprox - n×n-matrix, the approximate of A inverse
NB. berriA ≥ 0, the relative backward error for iAapprox
NB. n ≥ 0, the size of A and iAapprox
NB.
NB. Formula:
NB. n := size(A)
NB. if 0 = n then
NB. berriA := 0
NB. elseif 0 = ||A||_1 or 0 = ||A^_1||_1 then
NB. berriA := 1 / FP_EPS
NB. else
NB. berriA := ((||A * A^_1 - I||_1 * rcond(A)) / n) / FP_EPS
NB. endif
NB. where
NB. for trtril : A := L , rcond(A) := trlcon1 (L)
NB. for trtril1 : A := L1 , rcond(A) := trl1con1(L1)
NB. for trtriu : A := U , rcond(A) := trucon1 (U)
NB. for trtriu1 : A := U1 , rcond(A) := tru1con1(U1)
NB. for getrilu1p: A := L * U1 * P , rcond(A) := gecon1 (A)
NB. for getripl1u: A := P * L1 * U , rcond(A) := gecon1 (A)
NB. for getripu1l: A := P * U1 * L , rcond(A) := gecon1 (A)
NB. for getriul1p: A := U * L1 * P , rcond(A) := gecon1 (A)
NB. for hetripl : A := P * L1 * T * L1^H * P^H, rcond(A) := hecon1 (A)
NB. for hetripu : A := P * U1 * T * U1^H * P^H, rcond(A) := hecon1 (A)
NB. for potril : A := L * L^H , rcond(A) := pocon1 (A)
NB. for potriu : A := U * U^H , rcond(A) := pocon1 (A)
NB. for pttril : A := L1 * D * L1^H , rcond(A) := ptcon1 (A)
NB. for pttriu : A := U1 * D * U1^H , rcond(A) := ptcon1 (A)
NB.
NB. Notes:
NB. - models LAPACK's xTRT01, xGET03, xPOT03
t03=: %~/@(FP_EPS , #@] , norm1@(<: upddiag)@(mp~ 0&{::)~ * 1 {:: [)`(%@FP_EPS)@.(0 e. ((, 2&{::)~ norm1))`0:@.(0 = #@])
NB. ---------------------------------------------------------
NB. lqt03
NB. qlt03
NB. qrt03
NB. rqt03
NB.
NB. Description:
NB. Adv. to make dyad to compute the relative backward
NB. error for the matrix partial multiplication by unmxxxx
NB.
NB. Syntax:
NB. berrP=. (C ; normC ; LQf ; k) (compP lqt03) Papprox
NB. berrP=. (C ; normC ; QfL ; k) (compP qlt03) Papprox
NB. berrP=. (C ; normC ; QfR ; k) (compP qrt03) Papprox
NB. berrP=. (C ; normC ; RQf ; k) (compP rqt03) Papprox
NB. where
NB. compP - dyad to compute P; is called as:
NB. P=. C compP Q
NB. C - m×n-matrix when (C * op(Q)), or n×m-matrix
NB. when (op(Q) * C)
NB. normC ≥ 0, the norm of C
NB. xQf,Qfx - matrix to extract Q in factorized form
NB. k ∈ [0,min(m,n)], an amount of elementary
NB. reflectors taken to form Q
NB. Papprox - m×n-matrix or n×m-matrix, approximate P
NB. berrP ≥ 0, the relative backward error for P
NB. Q - n×n-matrix, unitary (orthogonal), which is
NB. defined as the product of k elementary
NB. reflectors of order n
NB. op(Q) = Q for unmxxxn or op(Q) = Q^H for unmxxxc
NB. P - m×n-matrix (C * op(Q)), or n×m-matrix
NB. (op(Q) * C), the matrix inner product
NB. m ≥ 0, rows or columns in C
NB. n ≥ 0, columns or rows in C
NB.
NB. Formula:
NB. n := size(Q)
NB. m := columns(C) if side='L' or rows(C) if side='R'
NB. if 0 < ||C||_1 then
NB. berrP := ||F1||_1 / (max(1, n) * ||C||_1 * FP_EPS)
NB. else
NB. berrP := ||F1||_1 / (max(1, n) * FP_EPS)
NB. endif
NB. where
NB. k ∈ {0, 1, min(m,n)/2, min(m,n)}
NB. F1 := Papprox - C compP Q(k)
NB. for unmlqxx: Q(k) := H(k-1)' * ... * H(0 )'
NB. for unmqlxx: Q(k) := H(k-1) * ... * H(0 )
NB. for unmqrxx: Q(k) := H(0 ) * ... * H(k-1)
NB. for unmrqxx: Q(k) := H(0 )' * ... * H(k-1)'
NB.
NB. Notes:
NB. - m≤n for LQ and RQ, m≥n for QL and QR
NB. - xxt03 models corresp. LAPACK's xxxT03 with the
NB. following difference: only a sole test is performed,
NB. either (Q * C), (Q^H * C), (C * Q) or (C * Q^H)
NB. - lqt03 models LAPACK's xLQT03
NB. - qlt03 models LAPACK's xQLT03
NB. - qrt03 models LAPACK's xQRT03
NB. - rqt03 models LAPACK's xRQT03
NB.
NB. Application:
NB. - implement LAPACK's xLQT03:
NB. result1=. ( C ; (norm1 C) ; LQf ; k) ((mp~ ] ) lqt03) Papprox
NB. result2=. ((|: C) ; (normi C) ; LQf ; k) ((mp ] ) lqt03) Papprox
NB. result3=. ( C ; (norm1 C) ; LQf ; k) ((mp~ ct) lqt03) Papprox
NB. result4=. ((|: C) ; (normi C) ; LQf ; k) ((mp ct) lqt03) Papprox
NB. result=. result1 , result2 , result3 , result4
NB. - implement LAPACK's xQLT03:
NB. result1=. ( C ; (norm1 C) ; QfL ; k) ((mp~ ] ) qlt03) Papprox
NB. result2=. ((|: C) ; (normi C) ; QfL ; k) ((mp ] ) qlt03) Papprox
NB. result3=. ( C ; (norm1 C) ; QfL ; k) ((mp~ ct) qlt03) Papprox
NB. result4=. ((|: C) ; (normi C) ; QfL ; k) ((mp ct) qlt03) Papprox
NB. result=. result1 , result2 , result3 , result4
NB. - implement LAPACK's xQRT03:
NB. result1=. ( C ; (norm1 C) ; QfR ; k) ((mp~ ] ) qrt03) Papprox
NB. result2=. ((|: C) ; (normi C) ; QfR ; k) ((mp ] ) qrt03) Papprox
NB. result3=. ( C ; (norm1 C) ; QfR ; k) ((mp~ ct) qrt03) Papprox
NB. result4=. ((|: C) ; (normi C) ; QfR ; k) ((mp ct) qrt03) Papprox
NB. result=. result1 , result2 , result3 , result4
NB. - implement LAPACK's xRQT03:
NB. result1=. ( C ; (norm1 C) ; RQf ; k) ((mp~ ] ) rqt03) Papprox
NB. result2=. ((|: C) ; (normi C) ; RQf ; k) ((mp ] ) rqt03) Papprox
NB. result3=. ( C ; (norm1 C) ; RQf ; k) ((mp~ ct) rqt03) Papprox
NB. result4=. ((|: C) ; (normi C) ; RQf ; k) ((mp ct) rqt03) Papprox
NB. result=. result1 , result2 , result3 , result4
lqt03=: 1 : 'norm1@(- 0&{:: u 3&{:: (<:@c@] unglq {. ) 2&{:: )~ % FP_EPS * 1:^:(0&=)@(1 {:: [) * 1 >. <:@c@(2 {:: [)'