-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheq.ijs
1064 lines (1014 loc) · 42.8 KB
/
eq.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. Eigenvalues and Schur form
NB.
NB. hgexxe Eigenvalues of pair of structured matrices
NB. hgexxs Eigenvalues and the Schur form of pair of
NB. structured matrices
NB.
NB. testhgeq Test hgexxxxx by square matrices
NB. testeq Adv. to make verb to test hgexxxxx by matrices
NB. of generator and shape given
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. laqr1
NB.
NB. Description:
NB. 1st column of (H-s1*I)*(H-s2*I)
NB.
NB. Syntax:
NB. vK=. (s1,s2) laqr1 H
NB. where
NB. H - 2×2-matrix or 3×3-matrix
NB.
NB. Notes:
NB. - implements LAPACK's xLAQR1
NB.
NB. TODO:
NB. - tacit
laqr1=: 4 : 0
's1 s2'=. x
((-&s1 upddiag ]) (mp (% norm1t)) ((-&s2 updl 0) ({."1) ])) y
)
NB. ---------------------------------------------------------
NB. hgexxeo
NB.
NB. Description:
NB. Compute generalized eigenvalues of hs-segment
NB.
NB. Syntax:
NB. 'HTupd signbc'=. hs hgexxeo H ,: T
NB. where
NB. hs - 2-vector of integers (h,s) 'head' and 'size',
NB. defines eigenvalues range
NB. H - n×n-matrix, either HSL or HSU inside the
NB. submatrix H[h:h+s-1,h:h+s-1], and L or U
NB. outside
NB. T - n×n-matrix, either L or U
NB. HTupd -:Hupd ,: Tupd
NB. Hupd - H with hs-segment of diagonal replaced by
NB. alpha (see hgexx)
NB. Tupd - T with hs-segment of diagonal replaced by
NB. beta (see hgexx)
NB. signbc - s-vector, scaling factors to form Q,Z later
hgexxeo=: 4 : 0
'Hd Td'=. (0 , x) diag"2 y
absb=. | Td
'signbc Td'=. (,:~ FP_SFMIN < absb)} 1 0 2 |: (1 ,: + * Td) ,: 0 ,: absb
((((Hd * signbc) ,: Td) (;"1) 0 , x) setdiag"1 2 y) ; signbc
)
NB. ---------------------------------------------------------
NB. hgezqso
NB. hgeqzso
NB.
NB. Description:
NB. Compute generalized eigenvalues of hs-segment and
NB. reduce corresponding rows (hgezqso) or columns
NB. (hgeqzso) to generalized Schur form
NB.
NB. Syntax:
NB. 'HTupd signbc'=. hs hgexxso H ,: T
NB. where
NB. hs - 2-vector of integers (h,s) 'head' and 'size',
NB. defines eigenvalues range
NB. H - n×n-matrix, either lower (hgezqso) or upper
NB. (hgeqzso) Hessenberg inside the submatrix
NB. H[h:h+s-1,h:h+s-1], and lower (hgezqso) or
NB. upper (hgeqzso) triangular outside
NB. T - n×n-matrix, either lower (hgezqso) or upper
NB. (hgeqzso) triangular
NB. HTupd -:Hupd ,: Tupd
NB. Hupd - H with rows (hgezqso) or columns (hgeqzso)
NB. from hs-segment transformed to Shur form
NB. Tupd - T with rows (hgezqso) or columns (hgeqzso)
NB. from hs-segment transformed to Shur form
NB. signbc - s-vector, scaling factors to form Q,Z later
hgezqso=: 4 : 0
liso=. liso4dhs x
'y signbc'=. x hgexxeo y
subHT=. liso ({"2) y
((((,:~) liso >/ (i. c y))} subHT ,: subHT (*"2) signbc) liso}"2 y) ; signbc
)
hgeqzso=: 4 : 0
liso=. liso4dhs x
'y signbc'=. x hgexxeo y
subHT=. liso ({"1) y
((((,:~) (i. c y) </ liso)} subHT ,: subHT (*"1) signbc) liso}"1 y) ; signbc
)
NB. ---------------------------------------------------------
NB. hgezq
NB. hgeqz
NB.
NB. Description:
NB. Adv. to make dyad to find eigenvalues of either lower
NB. (hgezq) or upper (hgeqz) Hessenberg-triangular pair
NB. (H,T) and, optionally, to reduce this pair to
NB. generalized Schur form
NB.
NB. Syntax:
NB. 'HTupd dQ1 dZ1'=. hs (hgexxxo`init`reset`step hgexx) HT
NB. where
NB. hgexxxo - monad to compute generalized eigenvalues of
NB. hs-segment and, optionally, to reduce
NB. corresponding columns to generalized Schur
NB. form, is either hgezqso (hgezq only), hgeqzso
NB. (hgeqz only) or hgexxeo, is called as:
NB. 'HTupd signbc'=. hgexxxo hs ; HT
NB. init - dyad to initialize counters, is called as:
NB. 'ifrstm ilastm'=. (h , ilast) init (0 , n-1)
NB. reset - dyad to reset counters optionally, is called
NB. as:
NB. 'ifrstm ilastm'=. (h , ilast) reset (ifrstm , ilastm)
NB. step - monad to change counter optionally, is
NB. called as:
NB. ifrstm=. ifirst step ifrstm
NB.
NB. Notes:
NB. - refer to hgeqzxxxx below for parameters description
NB. - non-converged eigenvalues are set to NaN
hgezq=: 1 : 0
:
'`hgezqxo init reset step'=. m
e=. +/ 'h s'=. x
dQ1=. dZ1=. ((0 4 $ 0))
abnorm=. (0 2 ,. ,.~ x) norms"2;.0 y
'atol btol'=. abtol=. FP_SFMIN >. FP_PREC * abnorm
'ascale bscale'=. abscale=. % FP_SFMIN >. abnorm
'y signbc'=. ((c y) (] , -) e) hgezqxo y NB. process eigenvalues (columns) h+s:n-1
dZ1=. dZ1 , 4 ({."1) signbc ,. (c y) liso4th e
NB. Eigenvalues h+s:n-1 have been found.
NB. Initialize dynamic indices
ilast=. <: e
'ifrstm ilastm'=. (h , ilast) init (0 , <: c y)
NB. ifrstm - the column of the last
NB. splitting column to the left
NB. of the column ilast, this is
NB. always at least h
iiter=. 0 NB. counts iterations since the last
NB. eigenvalue was found, to tell when to
NB. use an extraordinary shift
eshift=. 0
maxit=. 30 * s NB. the maximum number of ZQ sweep allowed
jiter=. 0
NB. Main ZQ iteration loop
NB. Row operations modify columns ifrstm:*
NB. Column operations modify rows *:ilastm
while. jiter < maxit do.
goto60=. 1 NB. set default branching
NB. split the matrix if possible, by two tests:
NB. 1. H[j-1,j]=0 OR j=h
NB. 2. T[j,j]=0
if. ilast ~: h do.
if. atol < sorim (< 0 , ilast - 1 0) { y do.
if. btol < | (< 1 , ,~ ilast) { y do.
NB. general case: j < ilast
j=. <: ilast
while. j >: h do.
NB. test 1: H[j-1,j]=0 OR j=h
if. j = h do.
ilazro=. 1
elseif. atol >: sorim (< 0 , j - 1 0) { y do.
y=. 0 (< 0 , j - 1 0)} y
ilazro=. 1
else.
ilazro=. 0
end.
NB. test 2: T[j,j]=0
if. btol > | (< 1 , ,~ j) { y do.
y=. 0 (< 1 , ,~ j)} y
NB. test 2a: check for 2 consecutive small
NB. superdiagonals in H
ilazr2=. 0
if. -. ilazro do.
'Hj1j Hjj1 Hjj'=. sorim (< 0 ,. ((_1 0,0 1,:0 0)) + j) { y
if. 0 >: (Hj1j , Hjj) mp (ascale * (Hjj1 , -atol)) do.
ilazr2=. 1
end.
end.
NB. If both tests (1 & 2) pass, i.e., the
NB. leading diagonal element of T in the block
NB. is zero, then split a 1x1 block off at the
NB. left, i.e. at the j-th row/column. The
NB. leading diagonal element of the remainder
NB. can also be zero, so this may have to be
NB. done repeatedly.
if. ilazro +. ilazr2 do.
jch=. j
liso=. (>: ilastm) liso4th j
while. jch < ilast do.
'y cs'=. rot rotga y ; (< 0 ; liso ; (jch + 0 1)) ; 0
liso=. }. liso
y=. cs&rot&.((< 1 ; liso ; (jch + 0 1))&{) y
dZ1=. dZ1 , (+ cs) , jch + 0 1
if. ilazr2 do.
y=. *&({. cs)&.((< 0 , jch - 1 0)&{) y
ilazr2=. 0
end.
if. btol <: sorim (< 1 , jch + 1 1) { y do.
if. ilast > >: jch do.
ifirst=. >: jch
goto60=. 0
end.
goto_l60.
end.
y=. 0 (< 1 , jch + 1 1)} y
jch=. >: jch
end.
else.
NB. Only test 2 passed - chase the zero to
NB. T[ilast,ilast], then process as in the
NB. case T[ilast,ilast]=0
jch=. j
lisor=. (>: ilastm) liso4th <: j
lisoc=. (2 + j) liso4th ifrstm
while. jch < ilast do.
'y cs'=. rot rotga y ; (< 1 ; (2 }. lisor) ; (jch + 0 1)) ; 0
y=. cs&rot&.((< 0 ; lisor ; (jch + 0 1))&{) y
dZ1=. dZ1 , (+ cs) , jch + 0 1
'y cs'=. rot&.|: rotga y ; (< 0 ; (jch - 0 1) ; lisoc) ; ((< < a: ; _1))
y=. cs&(rot&.|:)&.((< 1 ; (jch - 0 1) ; (_2 }. lisoc))&{) y
dQ1=. dQ1 , cs , jch - 0 1
lisor=. }. lisor
lisoc=. lisoc , 2 + jch
jch=. >: jch
end.
end.
goto_l50.
elseif. ilazro do.
ifirst=. j
goto60=. 0
goto_l60.
end.
j=. <: j
end.
NB. drop-through is impossible
((_. ; '') setdiag"2 y) ; ,~ a: NB. set all eigenvalues to NaN
return.
else.
y=. 0 (< 1 , ,~ ilast)} y
end.
label_l50.
NB. T[ilast,ilast]=0 - clear H[ilast-1,ilast] to
NB. split off a 1x1 block
liso=. (>: ilast) liso4th ifrstm
'y cs'=. rot&.|: rotga y ; (< 0 ; (ilast - 0 1) ; liso) ; ((< < a: ; _1))
y=. cs&(rot&.|:)&.((< 1 ; (ilast - 0 1) ; (}: liso))&{) y
dQ1=. dQ1 , cs , ilast - 0 1
else.
y=. 0 (< 0 , ilast - 1 0)} y
end.
end.
label_l60.
if. goto60 do.
NB. H[ilast-1,ilast]=0 - standartize B, set alpha and
NB. beta
'y signbc'=. (ilast , 1) hgezqxo y NB. process ilast-th eigenvalue (column)
dQ1=. dQ1 , 4 ({."1) signbc ,. ilast
NB. goto next block - exit if finished
ilast=. <: ilast
if. ilast < h do.
NB. normal exit
'y signbc'=. (0 , 0 >. <: h) hgezqxo y NB. process eigenvalues (columns) 0:h-1
dQ1=. dQ1 , 4 ({."1) signbc ,. i. 0 >. <: h
y ; dQ1 ; dZ1
return.
end.
NB. reset counters
iiter=. 0
eshift=. 0
'ifrstm ilastm'=. (h , ilast) reset (ifrstm , ilastm)
else.
NB. ZQ step
NB. This iteration only involves rows/columns
NB. ifirst:ilast. We assume ifirst<ilast, and that the
NB. diagonal of B is non-zero
iiter=. >: iiter
ifrstm=. ifirst step ifrstm
NB. Compute the shift.
NB. At this point, ifirst<ilast, and the diagonal
NB. elements of T[ifirst:ilast,ifirst:ilast] are larger
NB. than btol in magnitude
if. 10 | iiter do.
NB. The Wilkinson shift, i.e., the eigenvalues of the
NB. bottom-right 2x2 block of T^_1*H which is nearest
NB. to the bottom-right element.
NB. We factor T as D*L, where L is unit lower
NB. triangular, and compute L^_1*(D^_1*H)
'L21 DA11 DA12 DA21 DA22'=. %/ ((6 0 1 2 3 ,: 7 4 4 7 7)) ({,) abscale * ((< a: ; ;~ ilast - 1 0) { y)
IBA22=. DA22 - L21 * DA12
t1=. -: DA11 + IBA22
rtdisc=. %: (t1 , DA21 , -DA11) mp (t1 , DA12 , DA22)
temp=. +/!.0 */ +. rtdisc , t1 - IBA22
shift=. t1 - temp negneg rtdisc
else.
NB. Exceptional shift. Chosen for no paticularly good
NB. reason
eshift=. eshift + + %/ abscale * (;/ 0 1 ,. ((0 _1 ,: _1 _1)) + ilast) { y
shift=. eshift
end.
NB. now check for two consecutive small subdiagonals
HTd=. (0 1 (,"0 1) ilast (] , -) ifirst) diag"1 2/ y
ctemp=. (- (shift&*))/ abscale * {. HTd
temp=. (sorim }."1 ctemp) ,: ascale * sorim ((< 1 ; 0 ; <<0)) { HTd
tempr=. >./ temp
temp=. temp %"1 ((0 , 1 - FP_EPS) I. tempr)} 1 , tempr ,: 1
'istart ctemp'=. (+&ifirst , {&ctemp) (ilast - ifirst) | >: (>:/ temp * atol ,: sorim ((< 1 ; 0 ; <<_1)) { HTd) i: 1
NB. do an implicit-shift ZQ sweep
NB. initial Z
cs=. lartg ctemp , ascale * (< 0 , istart + 0 1) { y
NB. sweep
j=. istart
lisor=. (>: ilastm) liso4th j
lisoc=. (j + 2) liso4th ifrstm
while. j < ilast do.
liso=. j + 0 1
NB. is a first iteration?
if. j = istart do.
y=. cs&rot"2&.((< a: ; lisor ; liso)&{) y
else.
'y cs'=. rot rotga y ; (< 0 ; lisor ; liso) ; 0
lisor=. }. lisor
y=. cs&rot&.((< 1 ; lisor ; liso)&{) y
end.
dZ1=. dZ1 , (+ cs) , liso
liso=. j + 1 0
'y cs'=. rot&.|: rotga y ; (< 1 ; liso ; lisoc) ; ((< < a: ; _1))
NB. isn't a last iteration?
if. j < <: ilast do.
lisoc=. lisoc , j + 2
end.
y=. cs&(rot&.|:)&.((< 0 ; liso ; lisoc)&{) y
dQ1=. dQ1 , cs , liso
j=. >: j
end.
end.
jiter=. >: jiter
end.
NB. drop-through means non-convergence, set incorrect eigenvalues 0:ilast to NaN
((_. ; 0 0 , >: ilast) setdiag"2 y) ; dQ1 ; dZ1
)
hgeqz=: 1 : 0
:
'`hgeqzxo init reset step'=. m
e=. +/ 'h s'=. x
dQ1=. dZ1=. ((0 4 $ 0))
abnorm=. (0 2 ,. ,.~ x) norms"2;.0 y
'atol btol'=. abtol=. FP_SFMIN >. FP_PREC * abnorm
'ascale bscale'=. abscale=. % FP_SFMIN >. abnorm
'y signbc'=. ((c y) (] , -) e) hgeqzxo y NB. process eigenvalues (columns) h+s:n-1
dZ1=. dZ1 , 4 ({."1) signbc ,. (c y) liso4th e
NB. Eigenvalues h+s:n-1 have been found.
NB. Initialize dynamic indices
ilast=. <: e
'ifrstm ilastm'=. (h , ilast) init (0 , <: c y)
NB. ifrstm - the row of the last splitting
NB. row above row ilast, this is
NB. always at least h
iiter=. 0 NB. counts iterations since the last
NB. eigenvalue was found, to tell when to
NB. use an extraordinary shift
eshift=. 0
maxit=. 30 * s NB. the maximum number of QZ sweep allowed
jiter=. 0
NB. Main QZ iteration loop
NB. Column operations modify rows ifrstm:*
NB. Row operations modify columns *:ilastm
while. jiter < maxit do.
goto60=. 1 NB. set default branching
NB. split the matrix if possible, by to tests:
NB. 1. H[j,j-1]=0 OR j=h
NB. 2. T[j,j]=0
if. ilast ~: h do.
if. atol < sorim (< 0 , ilast - 0 1) { y do.
if. btol < | (< 1 , ,~ ilast) { y do.
NB. general case: j < ilast
j=. <: ilast
while. j >: h do.
NB. test 1: H[j,j-1]=0 OR j=h
if. j = h do.
ilazro=. 1
elseif. atol >: sorim (< 0 , j - 0 1) { y do.
y=. 0 (< 0 , j - 0 1)} y
ilazro=. 1
else.
ilazro=. 0
end.
NB. test 2: T[j,j]=0
if. btol > | (< 1 , ,~ j) { y do.
y=. 0 (< 1 , ,~ j)} y
NB. test 2a: check for 2 consecutive small
NB. subdiagonals in H
ilazr2=. 0
if. -. ilazro do.
'Hjj1 Hj1j Hjj'=. sorim (< 0 ,. ((0 _1,1 0,:0 0)) + j) { y
if. 0 >: (Hjj1 , Hjj) mp (ascale * (Hj1j , -atol)) do.
ilazr2=. 1
end.
end.
NB. If both tests (1 & 2) pass, i.e., the
NB. leading diagonal element of T in the block
NB. is zero, then split a 1x1 block off at the
NB. top, i.e. at the j-th row/column. The
NB. leading diagonal element of the remainder
NB. can also be zero, so this may have to be
NB. done repeatedly.
if. ilazro +. ilazr2 do.
jch=. j
liso=. (>: ilastm) liso4th j
while. jch < ilast do.
'y cs'=. rot&.|: rotga y ; (< 0 ; (jch + 0 1) ; liso) ; ((< < a: ; 0))
liso=. }. liso
y=. cs&(rot&.|:)&.((< 1 ; (jch + 0 1) ; liso)&{) y
dQ1=. dQ1 , (+ cs) , jch + 0 1
if. ilazr2 do.
y=. *&({. cs)&.((< 0 , jch - 0 1)&{) y
ilazr2=. 0
end.
if. btol <: sorim (< 1 , jch + 1 1) { y do.
if. ilast > >: jch do.
ifirst=. >: jch
goto60=. 0
end.
goto_u60.
end.
y=. 0 (< 1 , jch + 1 1)} y
jch=. >: jch
end.
else.
NB. Only test 2 passed - chase the zero to
NB. T[ilast,ilast], then process as in the
NB. case T[ilast,ilast]=0
jch=. j
lisoc=. (>: ilastm) liso4th <: j
lisor=. (2 + j) liso4th ifrstm
while. jch < ilast do.
'y cs'=. rot&.|: rotga y ; (< 1 ; (jch + 0 1) ; (2 }. lisoc)) ; ((< < a: ; 0))
y=. cs&(rot&.|:)&.((< 0 ; (jch + 0 1) ; lisoc)&{) y
dQ1=. dQ1 , (+ cs) , jch + 0 1
'y cs'=. rot rotga y ; (< 0 ; lisor ; (jch - 0 1)) ; _1
y=. cs&rot&.((< 1 ; (_2 }. lisor) ; (jch - 0 1))&{) y
dZ1=. dZ1 , cs , jch - 0 1
lisoc=. }. lisoc
lisor=. lisor , 2 + jch
jch=. >: jch
end.
end.
goto_u50.
elseif. ilazro do.
ifirst=. j
goto60=. 0
goto_u60.
end.
j=. <: j
end.
NB. drop-through is impossible
(((_. ; '')) setdiag"2 y) ; ((,~ a:)) NB. set all eigenvalues to NaN
return.
else.
y=. 0 (< 1 , ,~ ilast)} y
end.
label_u50.
NB. T[ilast,ilast]=0 - clear H[ilast,ilast-1] to
NB. split off a 1x1 block
liso=. (>: ilast) liso4th ifrstm
'y cs'=. rot rotga y ; (< 0 ; liso ; (ilast - 0 1)) ; _1
y=. cs&rot&.((< 1 ; (}: liso) ; (ilast - 0 1))&{) y
dZ1=. dZ1 , cs , ilast - 0 1
else.
y=. 0 (< 0 , ilast - 0 1)} y
end.
end.
label_u60.
if. goto60 do.
NB. H[ilast,ilast-1]=0 - standartize B, set alpha and
NB. beta
'y signbc'=. (ilast , 1) hgeqzxo y NB. process ilast-th eigenvalue (column)
dZ1=. dZ1 , 4 ({."1) signbc ,. ilast
NB. goto next block - exit if finished
ilast=. <: ilast
if. ilast < h do.
NB. normal exit
'y signbc'=. (0 , 0 >. <: h) hgeqzxo y NB. process eigenvalues (columns) 0:h-1
dZ1=. dZ1 , 4 ({."1) signbc ,. i. 0 >. <: h
y ; dQ1 ; dZ1
return.
end.
NB. reset counters
iiter=. 0
eshift=. 0
'ifrstm ilastm'=. (h , ilast) reset (ifrstm , ilastm)
else.
NB. QZ step
NB. This iteration only involves rows/columns
NB. ifirst:ilast. We assume ifirst<ilast, and that the
NB. diagonal of B is non-zero
iiter=. >: iiter
ifrstm=. ifirst step ifrstm
NB. Compute the shift.
NB. At this point, ifirst<ilast, and the diagonal
NB. elements of T[ifirst:ilast,ifirst:ilast] are larger
NB. than btol in magnitude
if. 10 | iiter do.
NB. The Wilkinson shift, i.e., the eigenvalues of the
NB. bottom-right 2x2 block of H*T^_1 which is nearest
NB. to the bottom-right element.
NB. We factor T as U*D, where U is unit upper
NB. triangular, and compute (H*D^_1)*U^_1
'U12 AD11 AD21 AD12 AD22'=. %/ ((5 0 2 1 3 ,: 7 4 4 7 7)) ({,) abscale * ((< a: ; ;~ ilast - 1 0) { y)
ABI22=. AD22 - U12 * AD21
t1=. -: AD11 + ABI22
rtdisc=. %: (t1 , AD12 , -AD11) mp (t1 , AD21 , AD22)
temp=. (+/!.0) */ +. rtdisc , t1 - ABI22
shift=. t1 - temp negneg rtdisc
else.
NB. Exceptional shift. Chosen for no paticularly good
NB. reason
eshift=. eshift + + %/ abscale * (;/ 0 1 ,. ((_1 0 ,: _1 _1)) + ilast) { y
shift=. eshift
end.
NB. now check for two consecutive small subdiagonals
HTd=. (0 _1 (,"0 1) ilast (] , -) ifirst) diag"1 2/ y
ctemp=. (- (shift&*))/ abscale * {. HTd
temp=. (sorim }."1 ctemp) ,: ascale * sorim ((< 1 ; 0 ; <<0)) { HTd
tempr=. (>./) temp
temp=. temp %"1 ((0 , 1 - FP_EPS) I. tempr)} 1 , tempr ,: 1
'istart ctemp'=. (+&ifirst , {&ctemp) (ilast - ifirst) | >: (>:/ temp * atol ,: sorim ((< 1 ; 0 ; <<_1)) { HTd) i: 1
NB. do an implicit-shift QZ sweep
NB. initial Q
cs=. lartg ctemp , ascale * (< 0 , istart + 1 0) { y
NB. sweep
j=. istart
lisoc=. (>: ilastm) liso4th j
lisor=. (j + 2) liso4th ifrstm
while. j < ilast do.
liso=. j + 0 1
NB. is a first iteration?
if. j = istart do.
y=. cs&(rot&.|:)"2&.((< a: ; liso ; lisoc)&{) y
else.
'y cs'=. rot&.|: rotga y ; (< 0 ; liso ; lisoc) ; ((< < a: ; 0))
lisoc=. }. lisoc
y=. cs&(rot&.|:)&.((< 1 ; liso ; lisoc)&{) y
end.
dQ1=. dQ1 , (+ cs) , liso
liso=. j + 1 0
'y cs'=. rot rotga y ; (< 1 ; lisor ; liso) ; _1
NB. isn't a last iteration?
if. j < <: ilast do.
lisor=. lisor , j + 2
end.
y=. cs&rot&.((< 0 ; lisor ; liso)&{) y
dZ1=. dZ1 , cs , liso
j=. >: j
end.
end.
jiter=. >: jiter
end.
NB. drop-through means non-convergence, set incorrect eigenvalues 0:ilast to NaN
((_. ; 0 0 , >: ilast) setdiag"2 y) ; dQ1 ; dZ1
)
NB. ---------------------------------------------------------
NB. hgezqe
NB. hgezqs
NB. hgeqze
NB. hgeqzs
NB.
NB. Description:
NB. Shortcuts, see hgeqzxxxx
NB.
NB. Syntax:
NB. 'HTupd dQ1 dZ1'=. hs hgexxx HT
hgezqe=: hgexxeo`[`(2 1&{@,`[@.((<{:)~{.))`[ hgezq
hgezqs=: hgezqso`]`] `] hgezq
hgeqze=: hgexxeo`[`(2 1&{@,`[@.((<{:)~{.))`[ hgeqz
hgeqzs=: hgeqzso`]`] `] hgeqz
NB. =========================================================
NB. Interface
NB. ---------------------------------------------------------
NB. hgezqenn
NB. hgezqenv
NB. hgezqevn
NB. hgezqevv
NB. hgezqsnn
NB. hgezqsnv
NB. hgezqsvn
NB. hgezqsvv
NB.
NB. Description:
NB. Compute eigenvalues (hgezqxxx) and reduce to
NB. generalized Schur form (hgezqsxx):
NB. dQ1^H * S * dZ1 = H
NB. dQ1^H * P * dZ1 = T
NB. the generalized lower Hessenberg form (H,T) using
NB. single-shift ZQ method. Matrix pairs of this type are
NB. produced by the reduction to generalized lower
NB. Hessenberg form of a matrix pair (A,B):
NB. Q1^H * H * Z1 = A
NB. Q1^H * T * Z1 = B
NB. as computed by gghrdlxx. The unitary (orthogonal)
NB. matrices dQ1 and dZ1 may either be formed explicitly,
NB. or they may be postmultiplied by input matrices Q1 and
NB. Z1, so that:
NB. (dQ1*Q1)^H * S * (dZ1*Z1) = Q1^H * H * Z1
NB. (dQ1*Q1)^H * P * (dZ1*Z1) = Q1^H * T * Z1
NB. To avoid overflow, eigenvalues of the matrix pair (H,T)
NB. (equivalently, of (A,B)) are computed as a pair of
NB. values. Each i-th eigenvector (row) from L and R has a
NB. corresponding eigenvalue represented as a pair of i-th
NB. elements from vectors e1 and e2:
NB. E1=. diagmat e1=. diag S
NB. E2=. diagmat e2=. diag P
NB. If E2 is nonsingular then:
NB. E=. diagmat e1%e2
NB. is a diagonal matrix of eigenvalues, and GNEP can be
NB. expressed as:
NB. L * A = E * L * B
NB. A * R^H = B * R^H * E
NB. and if E1 is nonsingular then:
NB. E=. diagmat e2%e1
NB. is a diagonal matrix of eigenvalues, and GNEP can be
NB. expressed as:
NB. E * L * A = L * B
NB. A * R^H * E = B * R^H * E
NB.
NB. Syntax:
NB. e1e2=. hs hgezqenn H ,: T
NB. 'e1e2 Z2'=. hs hgezqenv H , T ,: Z1
NB. 'e1e2 Q2'=. hs hgezqevn H , T ,: Q1
NB. 'e1e2 Q2Z2'=. hs hgezqevv H , T , Q1 ,: Z1
NB. 'S P'=. hs hgezqsnn H ,: T
NB. 'S P Z2'=. hs hgezqsnv H , T ,: Z1
NB. 'S P Q2'=. hs hgezqsvn H , T ,: Q1
NB. 'S P Q2 Z2'=. hs hgezqsvv H , T , Q1 ,: Z1
NB. where
NB. hs - 2-vector of integers (h,s) 'head' and 'size',
NB. defines submatrices H11 and T11 position in H
NB. and T, respectively, see ggballp and gehrdl
NB. H - n×n-matrix, the lower Hessenberg inside the
NB. submatrix H[h:h+s-1,h:h+s-1], and lower
NB. triangular outside
NB. T - n×n-matrix, the lower triangular
NB. e1e2 - 2×n-matrix of eigenvalues e1 and e2:
NB. e1e2 -: e1 ,: e2
NB. Q1 - n×n-matrix, the unitary (orthogonal)
NB. Q2 - n×n-matrix, the unitary (orthogonal), the left
NB. Schur vectors of (H,T) pair if Q1=I, and of
NB. (A,B) pair otherwise
NB. Z1 - n×n-matrix, the unitary (orthogonal)
NB. Z2 - n×n-matrix, the unitary (orthogonal), the right
NB. Schur vectors of (H,T) pair if Z1=I, and of
NB. (A,B) pair otherwise
NB. Q2Z2 -:Q2 ,: Z2
NB. S - n×n-matrix, the lower triangular
NB. P - n×n-matrix, the lower triangular
NB.
NB. Notes:
NB. - non-converged eigenvalues are set to NaN
NB.
NB. Assertions (with appropriate comparison tolerance):
NB. e1e2 -: diag"2 (S ,: P)
NB. Q2 -: dQ1 mp Q1
NB. Z2 -: dZ1 mp Z1
NB. (H ,: T) -: dQ1 (mp~ ct)~"2 (S ,: P) mp"2 dZ1
NB. (C ,: D) -: Q2 (mp~ ct)~"2 (S ,: P) mp"2 Z2
NB. I -: Q2^H * Q2
NB. I -: Z2^H * Z2
NB. where
NB. C - n×n-matrix, general
NB. D - n×n-matrix, general
NB. n=. # C
NB. hs=. 0 , n
NB. I=. idmat n
NB. 'B Z0'=. (trl@:(}:"1) ,: unglq)@gelqf D
NB. A=. C (mp ct) Z0
NB. 'H T Q1 Z1'=. hs gghrdlvv A , B , I ,: Z0
NB. e1e2=. hs hgezqenn H ,: T
NB. 'S P Q2 Z2'=. hs hgezqsvv H , T , Q1 ,: Z1
NB. 'S P dQ1 dZ1'=. hs hgezqsvv H , T , ,:~ I
NB.
NB. Application:
NB. - detect case of non-convergence (0=converged,
NB. 1=non-converged), any of:
NB. isnan < e1e2
NB. isnan < S,:P NB. too expensive, use the next
NB. isnan < diag"2 S,:P
hgezqenn=: diag"2@(0 {:: hgezqe )
hgezqenv=: (2 { ]) ((diag"2@(0 {:: ])) ; (rotscll 2&{:: )) (hgezqe 2&{.)
hgezqevn=: (2 { ]) ((diag"2@(0 {:: ])) ; (rotscll 1&{:: )) (hgezqe 2&{.)
hgezqevv=: (2 }. ]) ((diag"2@(0 {:: ])) ; (rotscll"2&.:> }.)) (hgezqe 2&{.)
hgezqsnn=: 0 {:: hgezqs
hgezqsnv=: (2 { ]) (( 0 {:: ] ) , (rotscll 2&{:: )) (hgezqs 2&{.)
hgezqsvn=: (2 { ]) (( 0 {:: ] ) , (rotscll 1&{:: )) (hgezqs 2&{.)
hgezqsvv=: (2 }. ]) (( 0 {:: ] ) , (rotscll"2&: > }.)) (hgezqs 2&{.)
NB. ---------------------------------------------------------
NB. hgeqzenn
NB. hgeqzenv
NB. hgeqzevn
NB. hgeqzevv
NB. hgeqzsnn
NB. hgeqzsnv
NB. hgeqzsvn
NB. hgeqzsvv
NB.
NB. Description:
NB. Compute eigenvalues (hgeqzxxx) and reduce to
NB. generalized Schur form (hgeqzsxx):
NB. dQ1 * S * dZ1^H = H
NB. dQ1 * P * dZ1^H = T
NB. the generalized upper Hessenberg form (H,T) using
NB. single-shift QZ method. Matrix pairs of this type are
NB. produced by the reduction to generalized upper
NB. Hessenberg form of a matrix pair (A,B):
NB. Q1 * H * Z1^H = A
NB. Q1 * T * Z1^H = B
NB. as computed by gghrduxx. The unitary (orthogonal)
NB. matrices dQ1 and dZ1 may either be formed explicitly,
NB. or they may be premultiplied by input matrices Q1 and
NB. Z1, so that:
NB. (Q1*dQ1) * S * (Z1*dZ1)^H = Q1 * H * Z1^H
NB. (Q1*dQ1) * P * (Z1*dZ1)^H = Q1 * T * Z1^H
NB. To avoid overflow, eigenvalues of the matrix pair (H,T)
NB. (equivalently, of (A,B)) are computed as a pair of
NB. values. Each i-th eigenvector (column) from L and R has
NB. a corresponding eigenvalue represented as a pair of
NB. i-th elements from vectors e1 and e2:
NB. E1=. diagmat e1=. diag S
NB. E2=. diagmat e2=. diag P
NB. If E2 is nonsingular then:
NB. E=. diagmat e1%e2
NB. is a diagonal matrix of eigenvalues, and GNEP can be
NB. expressed as:
NB. L^H * A = E * L^H * B
NB. A * R = B * R * E
NB. and if E1 is nonsingular then:
NB. E=. diagmat e2%e1
NB. is a diagonal matrix of eigenvalues, and GNEP can be
NB. expressed as:
NB. E * L^H * A = L^H * B
NB. A * R * E = B * R * E
NB.
NB. Syntax:
NB. e1e2=. hs hgeqzenn H ,: T
NB. 'e1e2 Z2'=. hs hgeqzenv H , T ,: Z1
NB. 'e1e2 Q2'=. hs hgeqzevn H , T ,: Q1
NB. 'e1e2 Q2Z2'=. hs hgeqzevv H , T , Q1 ,: Z1
NB. 'S P'=. hs hgeqzsnn H ,: T
NB. 'S P Z2'=. hs hgeqzsnv H , T ,: Z1
NB. 'S P Q2'=. hs hgeqzsvn H , T ,: Q1
NB. 'S P Q2 Z2'=. hs hgeqzsvv H , T , Q1 ,: Z1
NB. where
NB. hs - 2-vector of integers (h,s) 'head' and 'size',
NB. defines submatrices H11 and T11 position in H
NB. and T, respectively, see ggbalup and gehrdu
NB. H - n×n-matrix, the upper Hessenberg inside the
NB. submatrix H[h:h+s-1,h:h+s-1], and upper
NB. triangular outside
NB. T - n×n-matrix, the upper triangular
NB. e1e2 - 2×n-matrix of eigenvalues e1 and e2:
NB. e1e2 -: e1 ,: e2
NB. Q1 - n×n-matrix, the unitary (orthogonal)
NB. Q2 - n×n-matrix, the unitary (orthogonal), the left
NB. Schur vectors of (H,T) pair if Q1=I, and of
NB. (A,B) pair otherwise
NB. Z1 - n×n-matrix, the unitary (orthogonal)
NB. Z2 - n×n-matrix, the unitary (orthogonal), the right
NB. Schur vectors of (H,T) pair if Z1=I, and of
NB. (A,B) pair otherwise
NB. Q2Z2 -:Q2 ,: Z2
NB. S - n×n-matrix, the upper triangular
NB. P - n×n-matrix, the upper triangular
NB.
NB. Notes:
NB. - non-converged eigenvalues are set to NaN
NB. - hgeqzenn models LAPACK's xHGEQZ('E','N','N')
NB. - hgeqzenv models LAPACK's xHGEQZ('E','N','V')
NB. - hgeqzevn models LAPACK's xHGEQZ('E','V','N')
NB. - hgeqzevv models LAPACK's xHGEQZ('E','V','V')
NB. - hgeqzsnn models LAPACK's xHGEQZ('S','N','N')
NB. - hgeqzsnv models LAPACK's xHGEQZ('S','N','V')
NB. - hgeqzsvn models LAPACK's xHGEQZ('S','V','N')
NB. - hgeqzsvv models LAPACK's xHGEQZ('S','V','V')
NB.
NB. Assertions (with appropriate comparison tolerance):
NB. e1e2 -: diag"2 (S ,: P)
NB. Q2 -: Q1 mp dQ1
NB. Z2 -: Z1 mp dZ1
NB. (H ,: T) -: dQ1 mp"2 (S ,: P) (mp ct)"2 dZ1
NB. (C ,: D) -: Q2 mp"2 (S ,: P) (mp ct)"2 Z2
NB. I -: Q2 * Q2^H
NB. I -: Z2 * Z2^H
NB. where
NB. C - n×n-matrix, general
NB. D - n×n-matrix, general
NB. n=. # C
NB. hs=. 0 , n
NB. I=. idmat n
NB. 'Q0 B'=. (ungqr ,: tru@}:)@geqrf D
NB. A=. Q0 (mp~ ct)~ C
NB. 'H T Q1 Z1'=. hs gghrduvv A , B , Q0 ,: I
NB. e1e2=. hs hgeqzenn H ,: T
NB. 'S P Q2 Z2'=. hs hgeqzsvv H , T , Q1 ,: Z1
NB. 'S P dQ1 dZ1'=. hs hgeqzsvv H , T , ,:~ I
NB.
NB. Application:
NB. - models LAPACK's xHGEQZ('E','N','I'):
NB. NB. 'e1e2 dZ1'=. hs hgeqzeni H ,: T
NB. hgeqzeni=: hgeqzenv (, idmat@c)
NB. - models LAPACK's xHGEQZ('E','I','N'):
NB. NB. 'e1e2 dQ1'=. hs hgeqzein H ,: T
NB. hgeqzein=: hgeqzevn (, idmat@c)
NB. - models LAPACK's xHGEQZ('E','I','I'):
NB. NB. 'e1e2 dQ1dZ1'=. hs hgeqzeii H ,: T
NB. hgeqzeii=: hgeqzevv (,~^:2~ idmat@c)
NB. - models LAPACK's xHGEQZ('E','I','V'):
NB. NB. 'e1e2 dQ1Z2'=. hs hgeqzeiv H , T ,: Z1
NB. hgeqzeiv=: hgeqzevv (1&A.@, idmat@c)
NB. - models LAPACK's xHGEQZ('E','V','I'):
NB. NB. 'e1e2 Q2dZ1'=. hs hgeqzevi H , T ,: Q1
NB. hgeqzevi=: hgeqzevv (, idmat@c)
NB. - models LAPACK's xHGEQZ('S','N','I'):
NB. NB. 'S P dZ1'=. hs hgeqzsni H ,: T
NB. hgeqzsni=: hgeqzsnv (, idmat@c)
NB. - models LAPACK's xHGEQZ('S','I','N'):
NB. NB. 'S P dQ1'=. hs hgeqzsin H ,: T
NB. hgeqzsin=: hgeqzsvn (, idmat@c)
NB. - models LAPACK's xHGEQZ('S','I','I'):
NB. NB. 'S P dQ1 dZ1'=. hs hgeqzsii H ,: T
NB. hgeqzsii=: hgeqzsvv (,~^:2~ idmat@c)
NB. - models LAPACK's xHGEQZ('S','I','V'):
NB. NB. 'S P dQ1 Z2'=. hs hgeqzsiv H , T ,: Z1
NB. hgeqzsiv=: hgeqzsvv (1&A.@, idmat@c)
NB. - models LAPACK's xHGEQZ('S','V','I'):
NB. NB. 'S P Q2 dZ1'=. hs hgeqzsvi H , T ,: Q1
NB. hgeqzsvi=: hgeqzsvv (, idmat@c)
NB. - detect case of non-convergence (0=converged,
NB. 1=non-converged), any of:
NB. isnan < e1e2
NB. isnan < S,:P NB. too expensive, use the next
NB. isnan < diag"2 S,:P
NB.
NB. References:
NB. [1] C. B. Moler, G. W. Stewart. An Algorithm for
NB. Generalized Matrix Eigenvalue Problems. SIAM J.
NB. Numer. Anal., 10(1973), pp. 241-256.
hgeqzenn=: diag"2@(0 {:: hgeqze )
hgeqzenv=: (2 { ]) ((diag"2@(0 {:: ])) ; (rotsclu 2&{:: )) (hgeqze 2&{.)
hgeqzevn=: (2 { ]) ((diag"2@(0 {:: ])) ; (rotsclu 1&{:: )) (hgeqze 2&{.)
hgeqzevv=: (2 }. ]) ((diag"2@(0 {:: ])) ; (rotsclu"2&.:> }.)) (hgeqze 2&{.)
hgeqzsnn=: 0 {:: hgeqzs
hgeqzsnv=: (2 { ]) (( 0 {:: ] ) , (rotsclu 2&{:: )) (hgeqzs 2&{.)
hgeqzsvn=: (2 { ]) (( 0 {:: ] ) , (rotsclu 1&{:: )) (hgeqzs 2&{.)
hgeqzsvv=: (2 }. ]) (( 0 {:: ] ) , (rotsclu"2&: > }.)) (hgeqzs 2&{.)
NB. =========================================================
NB. Test suite
NB. ---------------------------------------------------------
NB. testhgeq
NB.
NB. Description:
NB. Test:
NB. - xHGEQZ (math/lapack2 addon)
NB. - hgexxxxx (math/mt addon)
NB. by pair of square matrices
NB.
NB. Syntax:
NB. log=. testhgeq AB
NB. where
NB. AB - 2×n×n-brick
NB. log - 6-vector of boxes, test log
testhgeq=: 3 : 0
_1 cocreate < 'mttmp'
load_mttmp_ 'math/mt/external/lapack2/hgeqz'
n=. c y
hs=. 0 , n
I=. idmat n
'Hl Tl'=. HTl=. hs gghrdlnn (((mp ct@unglq) ,: trlpick@(_1 }."1 ])) gelqf)/ y
'Hu Tu'=. HTu=. hs gghrdunn (((mp~ ct@ungqr) ,: trupick@(_1 }. ])) geqrf)/ y
rcondl=. (geconi Hl) <. trlconi Tl
rcondu=. (gecon1 Hu) <. trucon1 Tu
normsl=. ;/ normi"2 HTl
normsu=. ;/ norm1"2 HTu
argslapack=. normsu , ;/ HTu , ,:~ I NB. arguments for xHGEQZ t511u t513u
argsmtl=. normsl , < HTl NB. arguments for hgezqxnn t511l t513l
argsmtvl=. normsl , < HTl , I NB. arguments for hgezqxnv hgezqxvn t511l t513l
argsmtvvl=. normsl , < HTl , ,:~ I NB. arguments for hgezqxvv t511l t513l
argsmtu=. normsu , < HTu NB. arguments for hgeqzxnn t511u t513u
argsmtvu=. normsu , < HTu , I NB. arguments for hgeqzxnv hgeqzxvn t511u t513u
argsmtvvu=. normsu , < HTu , ,:~ I NB. arguments for hgeqzxvv t511u t513u
t511u1=: (t511u"1~ ( 2 0 ,: 3 1)&{ )~ (0 4 5 ,: 1 4 5)&{
t511l2=: (t511l"1~ (((2 ; 0)&{::) ; 0&{::) ,: (2 ; 1)&{:: ; 1 &{::)~ <"2@((0 2 3 ,: 1 2 3)&{)
t511u2=: (t511u"1~ (((2 ; 0)&{::) ; 0&{::) ,: (2 ; 1)&{:: ; 1 &{::)~ <"2@((0 2 3 ,: 1 2 3)&{)
t513u4=: t513u@(4 {:: ])
t513u5=: t513u@(5 {:: ])
t513u45=: (4 {:: ]) >.&t513u 5 {:: ]
t513l1=: t513l@(1 {:: ])
t513u1=: t513u@(1 {:: ])
t513l2=: t513l@(2 { ])
t513u2=: t513u@(2 { ])
t513l01=: ((1;0) {:: ]) >.&t513l (1;1) {:: ]
t513u01=: ((1;0) {:: ]) >.&t513u (1;1) {:: ]
t513l23=: (2 { ]) >.&t513l 3 { ]
t513u23=: (2 { ]) >.&t513u 3 { ]
log=. ('''enn''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`nan )) argslapack
log=. log lcat ('''eni''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u5 ))) argslapack
log=. log lcat ('''env''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u5 ))) argslapack
log=. log lcat ('''ein''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u4 ))) argslapack
log=. log lcat ('''eii''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u45))) argslapack
log=. log lcat ('''eiv''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u45))) argslapack
log=. log lcat ('''evn''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u4 ))) argslapack
log=. log lcat ('''evi''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u45))) argslapack
log=. log lcat ('''evv''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u45))) argslapack
log=. log lcat ('''snn''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`nan )) argslapack
log=. log lcat ('''sni''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u5 ))) argslapack
log=. log lcat ('''snv''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u5 ))) argslapack
log=. log lcat ('''sin''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u4 ))) argslapack
log=. log lcat ('''sii''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`(t511u1 >./@, t513u45))) argslapack
log=. log lcat ('''siv''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`(t511u1 >./@, t513u45))) argslapack
log=. log lcat ('''svn''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u4 ))) argslapack
log=. log lcat ('''svi''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`(t511u1 >./@, t513u45))) argslapack
log=. log lcat ('''svv''&dhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`(t511u1 >./@, t513u45))) argslapack
log=. log lcat ('''enn''&zhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`nan )) argslapack
log=. log lcat ('''eni''&zhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u5 ))) argslapack
log=. log lcat ('''env''&zhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u5 ))) argslapack
log=. log lcat ('''ein''&zhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u4 ))) argslapack
log=. log lcat ('''eii''&zhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u45))) argslapack
log=. log lcat ('''eiv''&zhgeqz_mttmp_' tmonad ((0 1}~ 1 ; #@(2&{::)) `]`(rcondu"_)`nan`( t513u45))) argslapack