Exemplo n.º 1
0
        private void TrialDivision()
        {
            m_Height = 0;
            PrimesBigInteger divisor = PrimesBigInteger.Two;

            FireOnActualDivisorChanged(divisor);
            PrimesBigInteger  value = new PrimesBigInteger(this.m_Root.Value);
            GmpFactorTreeNode node  = this.m_Root;

            while (!value.IsProbablePrime(10))
            {
                //int counter = 0;
                while (value.Mod(divisor).CompareTo(PrimesBigInteger.Zero) != 0)
                {
                    divisor = divisor.NextProbablePrime();
                    FireOnActualDivisorChanged(divisor);
                    //counter++;
                    //if (counter == 1000000)
                    //{
                    //  if (OnCanceled != null) OnCanceled("Nach 100.000 Versuchen wurde kein weiterer Faktor gefunden, das Verfahren wird abgebrochen.");
                    //  CancelFactorize();
                    //}
                }
                value       = value.Divide(divisor);
                m_Remainder = value;
                GmpFactorTreeNode primeNodeTmp = new GmpFactorTreeNode(divisor);
                primeNodeTmp.IsPrime = true;
                node.AddChild(primeNodeTmp);
                node         = node.AddChild(new GmpFactorTreeNode(value));
                node.IsPrime = value.IsProbablePrime(20);
                m_Height++;
                AddFactor(divisor);
            }
            m_Remainder = null;

            node.IsPrime = true;
            AddFactor(node.Value);
            if (OnStop != null)
            {
                OnStop();
            }
        }
Exemplo n.º 2
0
        private void SetButtonColor(NumberButton btn)
        {
            PrimesBigInteger number = ControlHandler.GetPropertyValue(btn, "BINumber") as PrimesBigInteger;

            if (number.IsProbablePrime(10))
            {
                ControlHandler.SetPropertyValue(btn, "Background", Brushes.LightBlue);
            }
            else
            {
                ControlHandler.SetPropertyValue(btn, "Background", Brushes.Black);
            }
        }
Exemplo n.º 3
0
        private void DoFactorize(PrimesBigInteger value)
        {
            /*
             *        if (N.compareTo(ONE) == 0) return;
             * if (N.isProbablePrime(20)) { System.out.println(N); return; }
             * BigInteger divisor = rho(N);
             * factor(divisor);
             * factor(N.divide(divisor));
             */
            if (value.Equals(PrimesBigInteger.One))
            {
                return;
            }
            if (value.IsProbablePrime(10))
            {
                if (!m_Factors.ContainsKey(value))
                {
                    m_Factors.Add(value, PrimesBigInteger.Zero);
                }
                PrimesBigInteger tmp = m_Factors[value];
                m_Factors[value] = tmp.Add(PrimesBigInteger.One);

                if (FoundFactor != null)
                {
                    FoundFactor(m_Factors.GetEnumerator());
                }
                log.Info(value.ToString());
                return;
            }
            else
            {
                if (!m_FactorsTmp.ContainsKey(value))
                {
                    m_FactorsTmp.Add(value, 0);
                }
                m_FactorsTmp[value]++;
                if (m_FactorsTmp[value] > 3)
                {
                    log.Info(value.ToString() + " Zu oft");
                    m_A = PrimesBigInteger.RandomM(value).Add(PrimesBigInteger.Two);
                    m_FactorsTmp.Remove(value);
                }
            }
            PrimesBigInteger div = CalculateFactor(value);

            DoFactorize(div);
            DoFactorize(value.Divide(div));
        }
Exemplo n.º 4
0
        private void SetInfoActualNumber(PrimesBigInteger value)
        {
            setActualNumberText(value);
            string info = string.Empty;

            if (value.IsProbablePrime(10))
            {
                lblActualNumber.Foreground = Brushes.Red;
                info = Distribution.numberline_isprime;
            }
            else
            {
                lblActualNumber.Foreground = Brushes.Black;
            }
            lblActualNumberInfo.Text = info;
        }
Exemplo n.º 5
0
        private void SetSextupletPrimes(PrimesBigInteger value)
        {
            if (!value.IsProbablePrime(10))
            {
                return;
            }

            PrimesBigInteger first = null;

            if (value.Equals(PrimesBigInteger.Seven))
            {
                first = PrimesBigInteger.ValueOf(11);                                        // 7 is the only prime that doesn't match the pattern, so handle this case separately
            }
            else if (!IsQuadrupletPrime(value, ref first) && !IsQuadrupletPrime(value.Add(PrimesBigInteger.Four), ref first) && !IsQuadrupletPrime(value.Subtract(PrimesBigInteger.Four), ref first))
            {
                return;
            }

            first = first.Subtract(PrimesBigInteger.Four);
            if (!first.IsPrime(10))
            {
                return;
            }
            if (!first.Add(PrimesBigInteger.ValueOf(16)).IsPrime(10))
            {
                return;
            }

            List <int> diffs = new List <int> {
                0, 4, 6, 10, 12, 16
            };
            List <PrimesBigInteger> l = new List <PrimesBigInteger>();

            foreach (var d in diffs)
            {
                PrimesBigInteger p = first.Add(PrimesBigInteger.ValueOf(d));
                l.Add(p);
                if (m_ButtonsDict.ContainsKey(p))
                {
                    MarkNumber(m_ButtonsDict[p]);
                }
            }

            lblSixTupletPrimes.Text       = string.Format(Distribution.numberline_issixtupletprime, l[0], l[1], l[2], l[3], l[4], l[5]);
            pnlSixTupletPrimes.Visibility = Visibility.Visible;
        }
Exemplo n.º 6
0
        private void DoCalculateGoldbach(object o)
        {
            if (o == null || o.GetType() != typeof(PrimesBigInteger))
            {
                return;
            }

            PrimesBigInteger value = o as PrimesBigInteger;

            if (value.Mod(PrimesBigInteger.Two).Equals(PrimesBigInteger.One)) // value is odd
            {
                ControlHandler.SetPropertyValue(lblGoldbachInfoCalc, "Text", string.Format(Distribution.numberline_isodd, value));
                ControlHandler.SetPropertyValue(gbGoldbach, "Visibility", Visibility.Collapsed);
            }
            else if (value.Equals(PrimesBigInteger.Two))  // value = 2
            {
                ControlHandler.SetPropertyValue(lblGoldbachInfoCalc, "Text", Distribution.numberline_istwo);
                ControlHandler.SetPropertyValue(gbGoldbach, "Visibility", Visibility.Collapsed);
            }
            else // value is even and not prime
            {
                int counter  = 0;
                int maxlines = 1000;

                if (!value.IsProbablePrime(10))
                {
                    long x    = value.LongValue;
                    int  i    = 0;
                    long sum1 = PrimeNumbers.primes[i];
                    while (sum1 <= x / 2)
                    {
                        long sum2 = x - sum1;
                        if (BigIntegerHelper.IsProbablePrime(sum2))
                        //if (PrimeNumbers.isprime.Contains(sum2))
                        {
                            counter++;

                            if (counter < maxlines)
                            {
                                logGoldbach.Info(string.Format("{0} + {1}   ", sum1, sum2));
                            }
                            else if (counter == maxlines)
                            {
                                logGoldbach.Info(string.Format(Distribution.numberline_goldbachmaxlines, maxlines));
                            }

                            if (counter % 50 == 0)
                            {
                                string fmt = (counter == 1) ? Distribution.numberline_goldbachfoundsum : Distribution.numberline_goldbachfoundsums;
                                ControlHandler.SetPropertyValue(lblGoldbachInfoCalc, "Text", string.Format(fmt, counter, value));
                            }
                        }
                        sum1 = (++i < PrimeNumbers.primes.Length) ? PrimeNumbers.primes[i] : (long)BigIntegerHelper.NextProbablePrime(sum1 + 1);
                    }

                    string fmt1 = (counter == 1) ? Distribution.numberline_goldbachfoundsum : Distribution.numberline_goldbachfoundsums;
                    ControlHandler.SetPropertyValue(lblGoldbachInfoCalc, "Text", string.Format(fmt1, counter, value));
                    ControlHandler.SetPropertyValue(gbGoldbach, "Visibility", goldbachIsOpen ? Visibility.Visible : Visibility.Collapsed);
                }
            }

            if (GoldbachDone != null)
            {
                GoldbachDone();
            }
        }