예제 #1
0
 public void Combine(CountDictionary dictionary)
 {
     foreach (var kvp in dictionary)
     {
         AddSafe(kvp.Key, kvp.Value);
     }
 }
예제 #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));
            }
        }
예제 #3
0
파일: Relation.cs 프로젝트: be4/GNFS
 public Relation()
 {
     IsPersisted            = false;
     RationalFactorization  = new CountDictionary();
     AlgebraicFactorization = new CountDictionary();
 }
예제 #4
0
파일: Relation.cs 프로젝트: 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);
                }
            }
        }