-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNiggli.cpp
More file actions
1275 lines (1142 loc) · 43.9 KB
/
Niggli.cpp
File metadata and controls
1275 lines (1142 loc) · 43.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "D7.h"
#include "LRL_Cell.h"
#include "LRL_ToString.h"
#include "MatG6.h"
#include "Niggli.h"
#include "S6.h"
#include "Selling.h"
#include "StoreResults.h"
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <string>
//StoreResults<std::string, G6> g_store(5);
/*
R5
1 0 0 0 0 0
0 1 0 0 0 0
0 1 1 -s 0 0
0 -2s 0 1 0 0
0 0 0 0 1 -s
0 0 0 0 0 1
*/
/* class Niggli
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A class to implement Niggli reduction in the G6 space. Reduce returns a reduced cell
and the matrix that converts the input cell to the reduced cell.
Reduced(void)
== constructor -- nothing to do here
static void Reduce( const G6& vi, MatG6& m, G6& vout, const double delta )
== returns vout as the reduced cell of vi and m, the conversion matrix
static bool NearRed( const G6& gvec, const double delta );
== determines whether gvec is reduced within delta
static bool Near2Red( const G6& gvec, const double delta, G6& vout, double& dist )
== determines whether gvec is reduced within delta, and returns the reduced cell
and how far from reduced
static void Reporter( const std::string& text, const G6& vin, const G6& vout, const MatG6& m )
== prints information about each step in reduction (including standard presentation)
private:
static void MKnorm( const G6& vi, MatG6& m, G6& vout, const double delta )
== internal function to convert vi to standard presentation - the matrix
to implement that change is returned
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
const bool DEBUG_REDUCER(false);
size_t Niggli::m_ReductionCycleCount;
//-----------------------------------------------------------------------------
// Name: g6sign()
// Description: returns the value of the first variable with the sign of the second
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
double g6sign(const double d, const double x)
{
return(x > 0.0 ? d : -d);
}
static void PrintG6(const std::string& text, const G6& v)
{
printf("%s %f %f %f %f %f %f", text.c_str(), v[0], v[1], v[2], v[3], v[4], v[5]);
}
static void PrintMG6_INT(const std::string& text, const MatG6& v)
{
for (int i = 0; i < 6; ++i)
{
printf("%s ", text.c_str());
for (int j = 0; j < 36; j += 6)
{
printf(" %3d", int(v[i + j]));
}
printf("\n");
}
}
//-----------------------------------------------------------------------------
// Name: Reporter()
// Description: prints out the intermediate step values and looks for
// changes in the volume (indication of error)
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void Niggli::Reporter(const std::string& text, const G6& vin, const G6& vout, const MatG6& m)
{
if (!DEBUG_REDUCER) return;
const double volume = LRL_Cell(vout).Volume();
const double previousVolume = LRL_Cell(vin).Volume();
const bool volumeChanged = (fabs(volume - previousVolume) / std::max(volume, previousVolume)) > 1.0E-12;
if (volumeChanged)
{
printf("**************************************************************************************\n");
}
if (text.empty())
{
const int i19191 = 19191;
}
const std::string s1 = LRL_ToString(std::string("vin ") + text.c_str() + " ", vin);
const std::string s2 = LRL_ToString("vout ", vout);
printf("%s\n%s\n", s1.c_str(), s2.c_str());
if (volumeChanged)
{
printf("\nVolume(vout) %f", volume);
printf(" PREVIOUS VOLUME %f\n", previousVolume);
}
else
{
printf("\nVolume %f\n", volume);
}
printf("\n,%s\n", LRL_ToString("m ", m).c_str());
} // end Reporter
//-----------------------------------------------------------------------------
// Name: Niggli()
// Description: constructor
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Niggli::Niggli(void)
{
}
//-----------------------------------------------------------------------------
// Name: Niggli()
// Description: destructor
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Niggli::~Niggli(void)
{
}
void Niggli::MKnormWithoutMatrices(const G6& vi, G6& vout, const double delta) {
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// These are the matrices that can be used to convert a vector to standard
// presentation. They are used in MKnorm. There are NO OTHER POSSIBILITIES.
// The numbering is from Andrews and Bernstein, 1988
const static MatG6 spnull("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 sp1("0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1"); //0,1 3,4
const static MatG6 sp2("1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0"); //1,2 4,5
const static MatG6 sp34a("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1"); // -3,-4
const static MatG6 sp34b("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1"); // -3,-5
const static MatG6 sp34c("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1"); // -4,-5
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const static MatG6 R5_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 -1 0 0 0 -2 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1");
const static MatG6 R5_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 +1 0 0 0 +2 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1");
const static MatG6 R6_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1 0 -1 -2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R6_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 +1 0 0 0 0 1 0 +1 +2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R7_Plus(" 1 0 0 0 0 0 1 1 0 0 0 -1 0 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1 0 -2 0 0 0 0 1");
const static MatG6 R7_Minus(" 1 0 0 0 0 0 1 1 0 0 0 +1 0 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1 0 +2 0 0 0 0 1");
const static MatG6 R8(" 1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 2 0 1 0 1 2 0 0 0 1 1 0 0 0 0 0 1");
const static MatG6 R9_Plus(R5_Plus);
const static MatG6 R9_Minus(R5_Minus);
const static MatG6 R10_Plus(R6_Plus);
const static MatG6 R10_Minus(R6_Minus);
const static MatG6 R11_Plus(R7_Plus);
const static MatG6 R11_Minus(R7_Minus);
const static MatG6 R12("1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 -2 0 -1 0 -1 -2 0 0 0 -1 -1 0 0 0 0 0 1");
bool again = true;
m_ReductionCycleCount = 0;
G6 vin;
vin = vi;
double& g1 = vin[0];
double& g2 = vin[1];
double& g3 = vin[2];
double& g4 = vin[3];
double& g5 = vin[4];
double& g6 = vin[5];
size_t count = 0;
// assure that g1<=g2<=g3
while (again && (count < 5))
{
++count;
again = false;
//std::string sptext;
if ((fabs(vin[0]) > fabs(vin[1]) + delta + 1.e-12 * (vin[0] + vin[1])) ||
(fabs(vin[0] - vin[1]) < 1.e-38 + 1.e-12 * fabs(vin[0] + vin[1])
&& delta<1.0E-12 && fabs(vin[3])>fabs(vin[4]) +
delta + 1.e-12 * (fabs(vin[3]) + fabs(vin[4]))))
{ // SP1 0,1 3,4
//mat = sp1;
std::swap(g1, g2);
std::swap(g4, g5);
again = true;
//sptext = "SP1";
//g_store.Store(sptext, vin);
}
else if ((fabs(vin[1]) > fabs(vin[2]) + delta + 1.e-12 * (vin[1] + vin[2])) ||
(fabs(vin[1] - vin[2]) < 1.e-38 + 1.e-12 * fabs(vin[1] + vin[2])
&& delta<1.0E-12 && fabs(vin[4])>fabs(vin[5]) +
delta + 1.e-12 * (fabs(vin[4]) + fabs(vin[5]))))
{ // SP2 1,2 4,5
//mat = sp2;
std::swap(g2, g3);
std::swap(g5, g6);
again = true;
//sptext = "SP2";
//g_store.Store(sptext, vin);
}
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM input "+sptext+" ", vi));;
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM output "+sptext+" ", vout));;
}
// now we assure (within delta) that the vector is +++ or ---
int bMinusPattern = 0;
int bZeroPattern = 0;
if (g4 < delta + 1.0E-13 * (g2 + g3)) bMinusPattern |= 4;
if (g5 < delta + 1.0E-13 * (g1 + g3)) bMinusPattern |= 2;
if (g6 < delta + 1.0E-13 * (g1 + g2)) bMinusPattern |= 1;
if (fabs(g4) < delta + 1.0E-13 * (g2 + g3)) bZeroPattern |= 4;
if (fabs(g5) < delta + 1.0E-13 * (g1 + g3)) bZeroPattern |= 2;
if (fabs(g6) < delta + 1.0E-13 * (g1 + g2)) bZeroPattern |= 1;
//std::string sptext2("Not_All_+++/---_in_MKnorm");
switch (bMinusPattern)
{
case 0: /* +++ */
{
//mat = spnull;
//sptext2 = "no_mknorm_action_sp1,sp2-0";
//g_store.Store(sptext2, vin);
break;
}
case 1: /* ++- -> --- */
{
//mat = sp34a;
g4 = -g4;
g5 = -g5;
//sptext2 = "SP34a-1";
//g_store.Store(sptext2, vin);
break;
}
case 2: /* +-+ -> --- */
{
//mat = sp34b;
g4 = -g4;
g6 = -g6;
//sptext2 = "SP34b-2";
//g_store.Store(sptext2, vin);
break;
}
case 3: /* +-- -> +++, but +0- -> -0- and +-0 -> --0 and +00 -> -00 */
{
if ((bZeroPattern & 2) == 2) {
//mat = sp34a;
g4 = -g4;
g5 = -g5;
//sptext2 = "SP34a-3";
//g_store.Store(sptext2, vin);
break;
}
else if ((bZeroPattern & 1) == 1) {
//mat = sp34b;
//sptext2 = "SP34b-3";
g4 = -g4;
g6 = -g6;
//g_store.Store(sptext2, vin);
break;
}
else {
//mat = sp34c;
g5 = -g5;
g6 = -g6;
//sptext2 = "SP34c-3";
//g_store.Store(sptext2, vin);
}
break;
}
case 4: /* -++ -> --- */
{
//mat = sp34c;
g5 = -g5;
g6 = -g6;
//sptext2 = "SP34c-4";
//g_store.Store(sptext2, vin);
break;
}
case 5: /* -+- -> +++, but 0+- -> 0-- and -+0 -> --0 and 0+0 -> 0-0 */
{
//mat = sp34b;
//sptext2 = "SP34b-5";
if ((bZeroPattern & 4) == 4) {
//mat = sp34a;
g4 = -g4;
g5 = -g5;
//sptext2 = "SP34a-5";
//g_store.Store(sptext2, vin);
break;
}
else if ((bZeroPattern & 1) == 1) {
//mat = sp34c;
//sptext2 = "SP34c-5a";
g5 = -g5;
g6 = -g6;
//g_store.Store(sptext2, vin);
break;
}
else {
//mat = sp34b;
g4 = -g4;
g6 = -g6;
//sptext2 = "SP34b-5";
//g_store.Store(sptext2, vin);
}
break;
}
case 6: /* --+ - > +++, but 0-+ -> 0-- and -0+ - > -0- and 00+ -> 00- */
{
if ((bZeroPattern & 4) == 4) {
//mat = sp34b;
g4 = -g4;
g6 = -g6;
//sptext2 = "SP34b-5";
////g_store.Store(sptext2, vin);
break;
}
else if ((bZeroPattern & 2) == 2) {
//mat = sp34c;
g5 = -g5;
g6 = -g6;
//sptext2 = "SP34c-5";
//g_store.Store(sptext2, vin);
break;
}
else {
//mat = sp34a;
g4 = -g4;
g5 = -g5;
//sptext2 = "SP34a-6";
//g_store.Store(sptext2, vin);
}
break;
}
case 7:
{
//mat = spnull;
//sptext2 = "no-mknorm_action_sp1,sp2-7";
//g_store.Store(sptext2, vin);
break;
}
}
//vout = mat * vin;
vout = vin;
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM input "+sptext2+" ", vi));;
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM output "+sptext2+" ", vout));;
//std::cout << std::flush;
}
//-----------------------------------------------------------------------------
// Name: MKnorm()
// Description: changes a G6 vector to standard presentation (often called
// normalization in the literature) and returns the standard
// vector and the matrix that changes the input vector to the
// standard one
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void Niggli::MKnorm(const G6& vi, MatG6& m, G6& vout, const double delta) {
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// These are the matrices that can be used to convert a vector to standard
// presentation. They are used in MKnorm. There are NO OTHER POSSIBILITIES.
// The numbering is from Andrews and Bernstein, 1988
const static MatG6 spnull("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 sp1("0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1");
const static MatG6 sp2("1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0");
const static MatG6 sp34a("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1");
const static MatG6 sp34b("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1");
const static MatG6 sp34c("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1");
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const static MatG6 R5_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 -1 0 0 0 -2 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1");
const static MatG6 R5_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 +1 0 0 0 +2 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1");
const static MatG6 R6_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1 0 -1 -2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R6_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 +1 0 0 0 0 1 0 +1 +2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R7_Plus(" 1 0 0 0 0 0 1 1 0 0 0 -1 0 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1 0 -2 0 0 0 0 1");
const static MatG6 R7_Minus(" 1 0 0 0 0 0 1 1 0 0 0 +1 0 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1 0 +2 0 0 0 0 1");
const static MatG6 R8(" 1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 2 0 1 0 1 2 0 0 0 1 1 0 0 0 0 0 1");
const static MatG6 R9_Plus(R5_Plus);
const static MatG6 R9_Minus(R5_Minus);
const static MatG6 R10_Plus(R6_Plus);
const static MatG6 R10_Minus(R6_Minus);
const static MatG6 R11_Plus(R7_Plus);
const static MatG6 R11_Minus(R7_Minus);
//const MatG6 R12(R8);
const static MatG6 R12("1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 -2 0 -1 0 -1 -2 0 0 0 -1 -1 0 0 0 0 0 1");
bool again = true;
int mkCycleCount = 0;
MatG6 mat = MatG6::Eye();
G6 vin;
m = MatG6::Eye();
vin = vi;
// assure that g1<=g2<=g3
while (again && (mkCycleCount <= 5))
{
++mkCycleCount = 0;
again = false;
std::string sptext;
if ((fabs(vin[0]) > fabs(vin[1]) + delta + 1.e-12 * (vin[0] + vin[1])) ||
(fabs(vin[0] - vin[1]) < 1.e-38 + 1.e-12 * fabs(vin[0] + vin[1])
&& delta<1.0E-12 && fabs(vin[3])>fabs(vin[4]) +
delta + 1.e-12 * (fabs(vin[3]) + fabs(vin[4]))))
{ // SP1
mat = sp1;
again = true;
sptext = "SP1";
}
else if ((fabs(vin[1]) > fabs(vin[2]) + delta + 1.e-12 * (vin[1] + vin[2])) ||
(fabs(vin[1] - vin[2]) < 1.e-38 + 1.e-12 * fabs(vin[1] + vin[2])
&& delta<1.0E-12 && fabs(vin[4])>fabs(vin[5]) +
delta + 1.e-12 * (fabs(vin[4]) + fabs(vin[5]))))
{ // SP2
mat = sp2;
again = true;
sptext = "SP2";
}
if (again)
{
// Accumulate the total transformation from the input vector into vout and
// the total transformation itself into matrix m.
const MatG6 mtemp = mat * m;
m = mtemp;
vout = mat * vin;
Reporter(sptext, vin, vout, mat);
vin = vout;
}
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM input "+sptext+" ", vi));;
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM output "+sptext+" ", vout));;
}
// now we assure (within delta) that the vector is +++ or ---
int bMinusPattern = 0;
int bZeroPattern = 0;
if (vin[3] < delta + 1.0E-13 * (vin[1] + vin[2])) bMinusPattern |= 4;
if (vin[4] < delta + 1.0E-13 * (vin[0] + vin[2])) bMinusPattern |= 2;
if (vin[5] < delta + 1.0E-13 * (vin[0] + vin[1])) bMinusPattern |= 1;
if (fabs(vin[3]) < delta + 1.0E-13 * (vin[1] + vin[2])) bZeroPattern |= 4;
if (fabs(vin[4]) < delta + 1.0E-13 * (vin[0] + vin[2])) bZeroPattern |= 2;
if (fabs(vin[5]) < delta + 1.0E-13 * (vin[0] + vin[1])) bZeroPattern |= 1;
std::string sptext2("Not_All_++ + / -- - _in_MKnorm");
switch (bMinusPattern)
{
case 0: /* +++ */
{
mat = spnull;
sptext2 = "no_mknorm_action_sp1,sp2-0";
break;
}
case 1: /* ++- -> --- */
{
mat = sp34a;
sptext2 = "SP34a-1";
break;
}
case 2: /* +-+ -> --- */
{
mat = sp34b;
sptext2 = "SP34b-2";
break;
}
case 3: /* +-- -> +++, but +0- -> -0- and +-0 -> --0 and +00 -> -00 */
{
mat = sp34c;
sptext2 = "SP34c-3";
if ((bZeroPattern & 2) == 2) {
mat = sp34a;
sptext2 = "SP34a-3";
break;
}
if ((bZeroPattern & 1) == 1) {
mat = sp34b;
sptext2 = "SP34b-3";
break;
}
break;
}
case 4: /* -++ -> --- */
{
mat = sp34c;
sptext2 = "SP34c-4";
break;
}
case 5: /* -+- -> +++, but 0+- -> 0-- and -+0 -> --0 and 0+0 -> 0-0 */
{
mat = sp34b;
sptext2 = "SP34b-5";
if ((bZeroPattern & 4) == 4) {
mat = sp34a;
sptext2 = "SP34a-5";
break;
}
if ((bZeroPattern & 1) == 1) {
mat = sp34c;
sptext2 = "SP34c-5";
break;
}
break;
}
case 6: /* --+ - > +++, but 0-+ -> 0-- and -0+ - > -0- and 00+ -> 00- */
{
mat = sp34a;
sptext2 = "SP34a-6";
if ((bZeroPattern & 4) == 4) {
mat = sp34b;
sptext2 = "SP34b-5";
break;
}
if ((bZeroPattern & 2) == 2) {
mat = sp34c;
sptext2 = "SP34c-5";
break;
}
break;
}
case 7:
{
mat = spnull;
sptext2 = "no_mknorm_action_sp1,sp2-7";
break;
}
}
// Accumulate the total transformation from the input vector into vout and
// the total transformation itself into matrix m.
const MatG6 mtemp = mat * m;
m = mtemp;
vout = mat * vin;
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM input "+sptext2+" ", vi));;
// DEBUG_REPORT_STRING(LRL_ToString( " MKNORM output "+sptext2+" ", vout));;
std::cout << std::flush;
Reporter(sptext2, vin, vout, mat);
} // end MKnorm
bool Niggli::Reduce(const G6& vi, G6& vout) {
const bool b = Selling::Reduce(vi, vout);
return ReduceWithoutMatrices(vout, vout, 0.0);
}
bool Niggli::Reduce(const G6& vi, G6& vout, const bool sellingFirst) {
if (IsNiggli(vi)) {
vout = vi;
return true;
}
S6 s6out;
bool b = true;
if (sellingFirst) {
b = Selling::Reduce(S6(vi), s6out);
vout = D7(s6out);
}
else {
vout = vi;
}
if (!b) {
MatG6 m;
const bool bniggli = Niggli::Reduce(vi, m, vout, 0.0);
return bniggli;
}
else if (IsNiggli(vout)) {
return true;
}
else {
MatG6 m;
return Niggli::Reduce(vi, m, vout, 0.0);
}
}
bool Niggli::ReduceWithoutMatrices(const G6& vi, G6& vout, const double delta)
{
if (Niggli::IsNiggli(vi)) {
vout = vi;
return true;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// These are the matrices that can be used to convert a vector to standard
// presentation. They are used in MKnorm. There are NO OTHER POSSIBILITIES.
// The numbering is from Andrews and Bernstein, 1988
const static MatG6 spnull("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 sp1("0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1");
const static MatG6 sp2("1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0");
const static MatG6 sp34a("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1");
const static MatG6 sp34b("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1");
const static MatG6 sp34c("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1");
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const static MatG6 R5_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 -1 0 0 0 -2 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1");
const static MatG6 R5_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 +1 0 0 0 +2 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1");
const static MatG6 R6_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1 0 -1 -2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R6_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 +1 0 0 0 0 1 0 +1 +2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R7_Plus(" 1 0 0 0 0 0 1 1 0 0 0 -1 0 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1 0 -2 0 0 0 0 1");
const static MatG6 R7_Minus(" 1 0 0 0 0 0 1 1 0 0 0 +1 0 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1 0 +2 0 0 0 0 1");
const static MatG6 R8(" 1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 2 0 1 0 1 2 0 0 0 1 1 0 0 0 0 0 1");
const static MatG6 R9_Plus(R5_Plus);
const static MatG6 R9_Minus(R5_Minus);
const static MatG6 R10_Plus(R6_Plus);
const static MatG6 R10_Minus(R6_Minus);
const static MatG6 R11_Plus(R7_Plus);
const static MatG6 R11_Minus(R7_Minus);
//const MatG6 R12(R8);
const static MatG6 R12("1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 -2 0 -1 0 -1 -2 0 0 0 -1 -1 0 0 0 0 0 1");
G6 vin;
size_t reduceCycleCount = 0;
bool again = true;
const bool debug = true;
const int maxCycle = 1000;
vin = vi;
G6 voutPrev(vin);
/* Mapping from Fortran indices:
1 2 3 4 5 6
0 6 12 18 24 30
7 8 9 10 11 12
1 7 13 19 25 31
13 14 15 16 17 18
2 8 14 20 26 32
19 20 21 22 23 24
3 9 15 21 27 33
25 26 27 28 29 30
4 10 16 22 28 34
31 32 33 34 35 36
5 11 17 23 29 35
*/
// Try some number of times to reduce the input vector and accumulate
// the changing vector and total transformation matrix
// The limit on the number of cycles is because (whether because of
// floating point rounding or algorithm issues) there might be a
// case of an infinite loop. The designations R5-R12 are from
double& g1 = vout[0];
double& g2 = vout[1];
double& g3 = vout[2];
double& g4 = vout[3];
double& g5 = vout[4];
double& g6 = vout[5];
// Andrews and Bernstein, 1988
MKnormWithoutMatrices(vin, vout, delta);
while (again && reduceCycleCount < maxCycle)
{
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE start cycle ", ncycle, " ", vin));;
vin = vout;
if (fabs(g4) > fabs(g2) + delta)
{ // R5
//const MatG6 m1 =(vin[3] <= 0.0) ? R5_Minus : R5_Plus;
again = true;
//// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R5-m1\n", m1,"\n"));;
//vout = m1 * vin;
if (g4 <= 0.0) {
g3 = g2 + g3 + g4; // R5_Minus & R9_Minus
g4 = 2 * g2 + g4;
g5 = g5 + g6;
//g_store.Store("R5_Minus", vin);
}
else {
g3 = g2 + g3 - g4; // R5_Plus & R9_Plus
g4 = -2 * g2 + g4;
g5 = g5 - g6;
//g_store.Store("R5_Plus", vin);
}
}
else if (fabs(g5) > fabs(g1) + delta)
{ // R6
//const MatG6 m1 =(vin[4] <= 0.0) ? R6_Minus : R6_Plus;
again = true;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R6-m1\n", m1,"\n"));;
//vout = m1 * vin;
if (g5 <= 0.0) {
g3 = g1 + g3 + g5; // R6_Minus & R10_Minus
g4 = g4 + g6;
g5 = 2 * g1 + g5;
//g_store.Store("R6_Minus", vin);
}
else {
g3 = g1 + g3 - g5; // R6_Plus & R10_Plus
g4 = g4 - g6;
//g_store.Store("R6_Plus", vin);
g5 = -2 * g1 + g5;
}
}
else if (fabs(g6) > fabs(g1) + delta)
{ // R7
//const MatG6 m1 =(vin[5] <= 0.0) ? R7_Minus : R7_Plus;
again = true;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R7-m1\n", m1,"\n"));;
//vout = m1 * vin;
if (g6 <= 0.0) {
g2 = g1 + g2 + g6; // R7_Minus & R11_Minus
g4 = g4 + g5;
g6 = 2 * g1 + g6;
//g_store.Store("R7_Minus", vin);
}
else {
g2 = g1 + g2 - g6; // R7_Plus && R11_Plus
g4 = g4 - g5;
g6 = -2 * g1 + g6;
//g_store.Store("R7_Plus", vin);
}
}
else if (g4 + g5 + g6 + fabs(g1) + fabs(g2) + delta < 0.0)
{ //R8
//const MatG6 m1 = R8;
again = true;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R8-m1\n", m1,"\n"));;
//vout = m1 * vin;
g3 = g1 + g2 + g3 + g4 + g5 + g6; // R8
g4 = 2 * g2 + g4 + g6;
g5 = 2 * g1 + g5 + g6;
//g_store.Store("R8", vin);
}
else if ((fabs(g4 - g2) <= delta && 2.0 * g5 - delta < g6) ||
(fabs(g4 + g2) <= delta && g6 < 0.0))
{ // R9 There is an error in the paper says "2g5<g5" should be "2g5<g6"
//const MatG6 m1 =(vin[3] <= 0.0) ? R9_Minus : R9_Plus;
again = true;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R9-m1\n", m1,"\n"));;
//vout = m1 * vin;
if (g4 <= 0.0) {
g3 = g2 + g3 + g4; // R5_Minus & R9_Minus
g4 = 2 * g2 + g4;
g5 = g5 + g6;
//g_store.Store("R9_Minus", vin);
}
else {
g3 = g2 + g3 - g4; // R5_Plus & R9_Plus
g4 = -2 * g2 + g4;
g5 = g5 - g6;
//g_store.Store("R9_Plus", vin);
}
}
else if ((fabs(g5 - g1) <= delta && 2.0 * g4 - delta < g6) ||
(fabs(g5 + g1) <= delta && g6 < 0.0))
{ //R10 (LAST=15 in ITERATE)
//const MatG6 m1 =(vin[4] <= 0.0) ? R10_Minus : R10_Plus;
again = true;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R10-m\n", m,"\n"));
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R10-m1\n", m1,"\n"));
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R10-m2=m1*m\n", m2,"\n"));
//vout = m1 * vin;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R10-in ", vin));
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R10-out ", vout))
if (g5 <= 0.0) {
g3 = g1 + g3 + g5; // R6_Minus & R10_Minus
g4 = g4 + g6;
g5 = 2 * g1 + g5;
//g_store.Store("R10_Minus", vin);
}
else {
g3 = g1 + g3 - g5; // R6_Plus & R10_Plus
g4 = g4 - g6;
g5 = -2 * g1 + g5;
//g_store.Store("R10_Plus", vin);
}
}
else if ((fabs(g6 - g1) <= delta && 2.0 * g4 - delta < g5) ||
(fabs(g6 + g1) <= delta && g5 < 0.0)) // paper says g6<0, but it seems wrong
{ // R11
//const MatG6 m1 =(vin[5] <= 0.0) ? R11_Minus : R11_Plus;
again = true;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE 1-m1\n", m1,"\n"));;
//vout = m1 * vin;
if (g6 <= 0.0) {
g2 = g1 + g2 + g6; // R7_Minus & R11_Minus
g4 = g4 + g5;
g6 = 2 * g1 + g6;
//g_store.Store("R11_Minus", vin);
}
else {
g2 = g1 + g2 - g6; // R7_Plus && R11_Plus
g4 = g4 - g5;
g6 = -2 * g1 + g6;
//g_store.Store("R11_Plus", vin);
}
}
else if (fabs(g4 + g5 + g6 + fabs(g1) + fabs(g2)) <= delta && (2.0 * (fabs(g1) + g5) + g6 > delta))
{ //R12
//const MatG6 m1 =R12;
again = true;
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE R12-m1\n", m1,"\n"));;
//vout = m1 * vin;
g3 = g1 + g2 + g3 + g4 + g5 + g6; // R12
g4 = -2 * g2 - g4 - g6;
g5 = -2 * g1 - g5 - g6;
//g_store.Store("R12", vin);
}
else
{
again = false;
vout = vin;
}
// probably don't need to do this group of code when again==false !!!!!!!!!!!!!!
if (again) {
MKnormWithoutMatrices(vout, vin, delta);
vout = vin;
}
for (size_t i = 3; i < 6; ++i)
if (std::fabs(vin[i]) < 1.0E-10) vin[i] = 0.0;
if (vin[0] < 0.0 || vin[1] < 0.0 || vin[2] < 0.0) {
// ERROR ERROR ERROR
if (DEBUG_REDUCER) {
fprintf(stderr, " Negative sq, axis %d \n", (int)(reduceCycleCount));
fprintf(stderr, " vin: [%g,%g,%g,%g,%g,%g]\n",
vin[0], vin[1], vin[2], vin[3], vin[4], vin[5]);
fprintf(stderr, " vi: [%g,%g,%g,%g,%g,%g]\n",
vi[0], vi[1], vi[2], vi[3], vi[4], vi[5]);
}
return(false);
}
if (reduceCycleCount == 0) voutPrev = vin;
if (DEBUG_REDUCER)
{
//printf( "%d %f %f %f %f %f %f\n", m_ReductionCycleCount, vout[0], vout[1], vout[2], vout[3], vout[4], vout[5] );
}
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE output ", vi));;
// if (reduceCycleCount > 250) {
// std::cout << std::endl;
// std::cout << "cycle " << reduceCycleCount << std::endl;
// std::cout << "\tvin " << vin << std::endl;
// std::cout << "\tvout " << vout << std::endl;
// }
++reduceCycleCount;
}
bool isNearReduced = Niggli::NearRed(vout, delta);
if (reduceCycleCount >= maxCycle) {
if (isNearReduced) {
std::cout << "THERE IS A REDUCE PROBLEM, m_ReductionCycleCount " << reduceCycleCount << std::endl;
}
}
m_ReductionCycleCount = reduceCycleCount;
return (reduceCycleCount <= maxCycle) || isNearReduced;
}
//-----------------------------------------------------------------------------
// Name: Reduce()
// Description: performs Niggli reduction and returns the standard reduced
// vector and the matrix that changes the input vector to the
// reduced one
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
bool Niggli::Reduce(const G6& vi, MatG6& m, G6& vout, const double delta)
{
if (IsNiggli(vi)) {
vout = vi;
return true;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// These are the matrices that can be used to convert a vector to standard
// presentation. They are used in MKnorm. There are NO OTHER POSSIBILITIES.
// The numbering is from Andrews and Bernstein, 1988
const static MatG6 spnull("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 sp1("0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1");
const static MatG6 sp2("1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0");
const static MatG6 sp34a("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1");
const static MatG6 sp34b("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1");
const static MatG6 sp34c("1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1");
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const static MatG6 R5_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 -1 0 0 0 -2 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1");
const static MatG6 R5_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 +1 0 0 0 +2 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1");
const static MatG6 R6_Plus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1 0 -1 -2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R6_Minus(" 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 +1 0 0 0 0 1 0 +1 +2 0 0 0 1 0 0 0 0 0 0 1");
const static MatG6 R7_Plus(" 1 0 0 0 0 0 1 1 0 0 0 -1 0 0 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 1 0 -2 0 0 0 0 1");
const static MatG6 R7_Minus(" 1 0 0 0 0 0 1 1 0 0 0 +1 0 0 1 0 0 0 0 0 0 1 +1 0 0 0 0 0 1 0 +2 0 0 0 0 1");
const static MatG6 R8(" 1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 2 0 1 0 1 2 0 0 0 1 1 0 0 0 0 0 1");
const static MatG6 R9_Plus(R5_Plus);
const static MatG6 R9_Minus(R5_Minus);
const static MatG6 R10_Plus(R6_Plus);
const static MatG6 R10_Minus(R6_Minus);
const static MatG6 R11_Plus(R7_Plus);
const static MatG6 R11_Minus(R7_Minus);
//const MatG6 R12(R8);
const static MatG6 R12("1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 -2 0 -1 0 -1 -2 0 0 0 -1 -1 0 0 0 0 0 1");
G6 vin;
MatG6 m1;
size_t count = 0;
bool again = true;
const bool debug = true;
const int maxCycle = 260;
m1 = MatG6::Eye();
vin = vi;
G6 voutPrev(vin);
/* Mapping from Fortran indices:
1 2 3 4 5 6
0 6 12 18 24 30
7 8 9 10 11 12
1 7 13 19 25 31
13 14 15 16 17 18
2 8 14 20 26 32
19 20 21 22 23 24
3 9 15 21 27 33
25 26 27 28 29 30
4 10 16 22 28 34
31 32 33 34 35 36
5 11 17 23 29 35
*/
// Try some number of times to reduce the input vector and accumulate
// the changing vector and total transformation matrix
// The limit on the number of cycles is because (whether because of
// floating point rounding or algorithm issues) there might be a
// case of an infinite loop. The designations R5-R12 are from
// Andrews and Bernstein, 1988
MKnorm(vin, m1, vout, delta);
vin = vout;
while (again && count < maxCycle)
{
// DEBUG_REPORT_STRING(LRL_ToString( "REDUCE start m_ReductionCycleCount ", m_ReductionCycleCount, " ", vin));;
m1 = m;
const MatG6 m2temp = m1 * m;
m = m2temp;
m1 = MatG6::Eye();
if (fabs(vin[3]) > fabs(vin[1]) + delta)
{ // R5