oILAB
Loading...
Searching...
No Matches
IntegerLattice.h
Go to the documentation of this file.
1/* This file is part of gbLAB.
2 *
3 * gbLAB is distributed without any warranty under the MIT License.
4 */
5
6
7#ifndef gbLAB_IntegerLattice_h_
8#define gbLAB_IntegerLattice_h_
9
10#include <DiophantineSolver.h>
11
12namespace gbLAB
13{
18 template <int dim>
20 {
21 using IntScalarType = long long int;
22 using VectorDimI = Eigen::Matrix<IntScalarType,dim,1>;
23 using MatrixDimI = Eigen::Matrix<IntScalarType,dim,dim>;
24 public:
27 {}
28
29 static Eigen::Matrix<IntScalarType,dim-1,dim>
30 perpendicularDirections(const Eigen::Vector<IntScalarType,dim>& in)
31 {
32 Eigen::Matrix<IntScalarType,dim-1,dim> out= Eigen::Matrix<IntScalarType,dim-1,dim>::Zero();
33
34 int firstNonZero= 0;
35 for (int ind= 0; ind<dim; ind++)
36 {
37 if (in(ind) != 0)
38 {
39 firstNonZero = ind;
40 break;
41 }
42 else
43 {
44 out(ind,ind)= 1;
45 }
46 }
47
48 if (firstNonZero==dim-1) return out;
49
50 out(firstNonZero,firstNonZero)= -in(firstNonZero+1)/IntegerMath<IntScalarType>::gcd(in(firstNonZero),in(firstNonZero+1));
51 out(firstNonZero,firstNonZero+1)= in(firstNonZero)/IntegerMath<IntScalarType>::gcd(in(firstNonZero),in(firstNonZero+1));
52
53 for (int ind= firstNonZero+2; ind<dim; ind++)
54 {
55 if (in(ind)==0)
56 {
57 out.row(ind-1)= Eigen::Vector<IntScalarType, dim>::Zero(dim);
58 out(ind-1,ind)= 1;
59 continue;
60 }
61 Eigen::Vector<IntScalarType,3> truncated_in;
62 truncated_in << in(ind-2), in(ind-1), in(ind);
63 //truncated_in= truncated_in/IntegerMath<IntScalarType>::gcd(truncated_in);
64
65 IntScalarType x,y;
67 truncated_in(1),
68 -truncated_in(2)*IntegerMath<IntScalarType>::gcd(truncated_in(0),truncated_in(1)),x,y);
69
70 out(ind-1,ind)= IntegerMath<IntScalarType>::gcd(truncated_in(0),truncated_in(1));
71 out(ind-1,ind-2)= x;
72 out(ind-1,ind-1)= y;
73
74 out.row(ind-1)= out.row(ind-1)/IntegerMath<IntScalarType>::gcd(out.row(ind-1));
75 }
76 return out;
77 }
78 };
79}
80#endif
static void solveDiophantine2vars(IntScalarType a, IntScalarType b, IntScalarType c, IntScalarType &x, IntScalarType &y)
const MatrixDimI latticeBasis
Eigen::Matrix< IntScalarType, dim, 1 > VectorDimI
static Eigen::Matrix< IntScalarType, dim-1, dim > perpendicularDirections(const Eigen::Vector< IntScalarType, dim > &in)
long long int IntScalarType
Eigen::Matrix< IntScalarType, dim, dim > MatrixDimI
static IntScalarType gcd(const IntScalarType &a, const IntScalarType &b)
Definition IntegerMath.h:33