Ejemplo n.º 1
0
 public void Combine(CountDictionary dictionary)
 {
     foreach (var kvp in dictionary)
     {
         AddSafe(kvp.Key, kvp.Value);
     }
 }
Ejemplo n.º 2
0
        public override string ToString()
        {
            if (Relations.FreeRelations.Any())
            {
                StringBuilder result = new StringBuilder();

                List <Relation> relations = Relations.FreeRelations.First();

                result.AppendLine(FormatRelations(relations));

                BigInteger algebraic = relations.Select(rel => rel.AlgebraicNorm).Product();
                BigInteger rational  = relations.Select(rel => rel.RationalNorm).Product();

                bool isAlgebraicSquare = algebraic.IsSquare();
                bool isRationalSquare  = rational.IsSquare();

                CountDictionary algCountDict = new CountDictionary();
                foreach (var rel in relations)
                {
                    algCountDict.Combine(rel.AlgebraicFactorization);
                }

                result.AppendLine("---");
                result.AppendLine($"Rational  ∏(a+mb): IsSquare? {isRationalSquare} : {rational}");
                result.AppendLine($"Algebraic ∏ƒ(a/b): IsSquare? {isAlgebraicSquare} : {algebraic}");
                result.AppendLine();
                result.AppendLine($"Algebraic factorization (as prime ideals): {algCountDict.FormatStringAsFactorization()}");
                result.AppendLine();

                result.AppendLine();
                result.AppendLine("");
                result.AppendLine(string.Join(Environment.NewLine,
                                              relations.Select(rel =>
                {
                    BigInteger f = _gnfs.CurrentPolynomial.Evaluate((BigInteger)rel.A);
                    if (rel.B == 0)
                    {
                        return("");
                    }
                    return($"ƒ({rel.A}) ≡ {f} ≡ {(f % rel.B)} (mod {rel.B})");
                }
                                                               )));
                result.AppendLine();



                return(result.ToString());
            }
            else
            {
                return(FormatRelations(Relations.SmoothRelations));
            }
        }
Ejemplo n.º 3
0
Archivo: Relation.cs Proyecto: be4/GNFS
 public Relation()
 {
     IsPersisted            = false;
     RationalFactorization  = new CountDictionary();
     AlgebraicFactorization = new CountDictionary();
 }
Ejemplo n.º 4
0
Archivo: Relation.cs Proyecto: be4/GNFS
        private static void Sieve(IEnumerable <BigInteger> primeFactors, ref BigInteger quotientValue, CountDictionary dictionary)
        {
            if (quotientValue.Sign == -1 || primeFactors.Any(f => f.Sign == -1))
            {
                throw new Exception("There shouldn't be any negative values either in the quotient or the factors");
            }

            foreach (BigInteger factor in primeFactors)
            {
                if (quotientValue == 0 || quotientValue == 1)
                {
                    return;
                }

                if ((factor * factor) > quotientValue)
                {
                    if (primeFactors.Contains(quotientValue))
                    {
                        dictionary.Add(quotientValue);
                        quotientValue = 1;
                    }
                    return;
                }

                while (quotientValue != 1 && quotientValue % factor == 0)
                {
                    quotientValue = BigInteger.Divide(quotientValue, factor);
                    dictionary.Add(factor);
                }
            }
        }