Exemplo n.º 1
0
        public BigInteger CalculateDeterminant(VectorND[] newVectorNds)
        {
            //Es sind nur quatratische Matrizen erlaubt, daher wird N = M vorausgesetzt
            if (N != M)
            {
                throw new Exception("Non-square matrix!");
            }

            BigInteger[,] basisArray = new BigInteger[N, N];

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    basisArray[i, j] = newVectorNds[i].values[j];
                }
            }

            BigInteger det;

            using (var nativeObject = new NTL_Wrapper())
            {
                det = nativeObject.Determinant(basisArray, N);
            }
            //Absolut, da Gitterdeterminanten immer positiv sind
            return(BigInteger.Abs(det));
        }
Exemplo n.º 2
0
        private static BigInteger ModInverse(BigInteger a, BigInteger mod)
        {
            BigInteger b;

            using (var nativeObject = new NTL_Wrapper())
            {
                b = nativeObject.ModInverse(a % mod, mod);
            }
            return(b);
        }
Exemplo n.º 3
0
        public void LLLReduce()
        {
            ReductionMethod          = ReductionMethods.reduceLLL;
            BigInteger[,] basisArray = new BigInteger[N, M];
            BigInteger[,] transArray = new BigInteger[N, N];
            List <BigInteger[, ]> stepList = new List <BigInteger[, ]>();

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    basisArray[i, j] = Vectors[i].values[j];
                }
            }

            using (var nativeObject = new NTL_Wrapper())
            {
                nativeObject.LLLReduce(basisArray, transArray, stepList, N, M, 0.99);
            }

            ReducedVectors = new VectorND[N];
            for (int i = 0; i < N; i++)
            {
                ReducedVectors[i] = new VectorND(M);
                for (int j = 0; j < M; j++)
                {
                    ReducedVectors[i].values[j] = basisArray[i, j];
                }
            }

            if (M == 2 && N == 2)
            {
                AngleReducedVectors = ReducedVectors[0].AngleBetween(ReducedVectors[1]);
                CalculateDensity();
            }

            UnimodTransVectors = new VectorND[N];
            for (int i = 0; i < N; i++)
            {
                UnimodTransVectors[i] = new VectorND(N);
                for (int j = 0; j < N; j++)
                {
                    UnimodTransVectors[i].values[j] = transArray[i, j];
                }
            }

            ReductionSteps = new List <VectorND[]>();
            foreach (var step in stepList)
            {
                VectorND[] stepVectors = new VectorND[N];
                for (int i = 0; i < N; i++)
                {
                    stepVectors[i] = new VectorND(M);
                    for (int j = 0; j < M; j++)
                    {
                        stepVectors[i].values[j] = step[i, j];
                    }
                }
                ReductionSteps.Add(stepVectors);
            }
        }