Example #1
0
        public Matrix Build(List <Pair> pairs, RationalFactorbase rfb, AlgebraicFactorbase afb, QuadraticCharacters qfb, BigInteger integerRoot, Polynomial polynomial)
        {
            var matrix = new int[rfb.Elements.Count + afb.Elements.Count + qfb.Elements.Count + 1, pairs.Count];

            for (int index = 0; index < pairs.Count; index++)
            {
                var pair     = pairs[index];
                var rational = pair.Item1 + pair.Item2 * integerRoot;
                if (rational < 0)
                {
                    matrix[0, index] = 1;
                    rational         = -rational;
                }
                for (int i = 0; i < rfb.Elements.Count; i++)
                {
                    while (rational % rfb.Elements[i].Item2 == 0)
                    {
                        matrix[i + 1, index]++;
                        rational /= rfb.Elements[i].Item2;
                    }
                    matrix[i + 1, index] %= 2;
                    if (rational == 1)
                    {
                        break;
                    }
                }

                var normCalculator = new FirstDegreeElementsNormCalculator(polynomial, pair.Item2);
                var algebraic      = normCalculator.CalculateNorm(pair.Item1);

                for (int i = 0; i < afb.Elements.Count; i++)
                {
                    var primeIdeal = afb.Elements[i];
                    while (algebraic % primeIdeal.Item2 == 0 && (pair.Item1 + pair.Item2 * primeIdeal.Item1) % primeIdeal.Item2 == 0)
                    {
                        matrix[i + rfb.Elements.Count, index]++;
                        algebraic /= afb.Elements[i].Item2;
                    }
                    matrix[i + rfb.Elements.Count, index] %= 2;
                    if (algebraic == 1 || algebraic == -1)
                    {
                        break;
                    }
                }

                var jacobiSymbol = new JacobiSymbol();

                for (int i = 0; i < qfb.Elements.Count; i++)
                {
                    if (jacobiSymbol.Calculate(pair.Item1 + pair.Item2 * qfb.Elements[i].Item1, qfb.Elements[i].Item2) == -1)
                    {
                        matrix[rfb.Elements.Count + afb.Elements.Count + 1 + i, index] = 1;
                    }
                }
            }


            return(new Matrix(matrix));
        }
Example #2
0
 public SieveOptions(long upperBound, long lowerBound, AlgebraicFactorbase algebraicFactorbase, RationalFactorbase rationalFactorbase, Polynomial polynomial, BigInteger integerRoot)
 {
     UpperBound          = upperBound;
     LowerBound          = lowerBound;
     AlgebraicFactorbase = algebraicFactorbase;
     RationalFactorbase  = rationalFactorbase;
     Polynomial          = polynomial;
     IntegerRoot         = integerRoot;
 }
Example #3
0
        public void SieveMethodTest()
        {
            var algebraicFactorbase = new AlgebraicFactorbase(new List <Pair>()
            {
                new Pair(0, 2),
                new Pair(6, 7),
                new Pair(13, 17),
                new Pair(11, 23),
                new Pair(26, 29),
                new Pair(18, 31),
                new Pair(19, 41),
                new Pair(13, 43),
                new Pair(1, 53),
                new Pair(46, 61),
                new Pair(2, 67),
                new Pair(6, 67),
                new Pair(44, 67),
                new Pair(50, 73),
                new Pair(23, 79),
                new Pair(47, 79),
                new Pair(73, 79),
                new Pair(28, 89),
                new Pair(62, 89),
                new Pair(73, 89),
                new Pair(28, 97),
                new Pair(87, 101),
                new Pair(47, 103)
            });
            var rationalFactorbase = new RationalFactorbase(new List <Pair>()
            {
                new Pair(1, 2),
                new Pair(1, 3),
                new Pair(1, 5),
                new Pair(3, 7),
                new Pair(9, 11),
                new Pair(5, 13),
                new Pair(14, 17),
                new Pair(12, 19),
                new Pair(8, 23),
                new Pair(2, 29),
            });
            var polynomial     = new Polynomial(new BigInteger[] { 8, 29, 15, 1 });
            var root           = 31;
            var options        = new SieveOptions(1000, -1000, algebraicFactorbase, rationalFactorbase, polynomial, root);
            var sieveAlgorithm = new SimpleSieveAlgorithm();
            var result         = sieveAlgorithm.Sieve(40, options);
            var smoothTester   = new SmoothTester();

            foreach (var pair in result)
            {
                Assert.IsTrue(smoothTester.IsSmoothOverRationalFactorbase(pair.Item1, pair.Item2, root, rationalFactorbase));
                Assert.IsTrue(smoothTester.IsSmoothOverAlgebraicFactorbase(pair.Item1, pair.Item2, polynomial, algebraicFactorbase));
            }
        }
Example #4
0
        public bool IsSmoothOverRationalFactorbase(BigInteger a, BigInteger b, BigInteger integerRoot, RationalFactorbase factorbase)
        {
            var element = a + b * integerRoot;

            if (element == 0)
            {
                return(false);
            }
            for (int i = 0; i < factorbase.Elements.Count; i++)
            {
                if (element == 1 || element == -1)
                {
                    return(true);
                }
                var currentPair = factorbase.Elements[i];
                while (element % currentPair.Item2 == 0)
                {
                    element /= currentPair.Item2;
                }
            }
            return(element == 1 || element == -1);
        }