Пример #1
0
        private void SetQuadrupletPrimes(PrimesBigInteger value)
        {
            PrimesBigInteger first = null;

            if (IsQuadrupletPrime(value, ref first))
            {
                string text = MarkQuadrupletPrimes(first);
                if (value.Equals(PrimesBigInteger.ValueOf(11)) || value.Equals(PrimesBigInteger.ValueOf(13)))
                {
                    text = MarkQuadrupletPrimes(PrimesBigInteger.Five) + " " + text;
                }
                lblQuadrupletPrimes.Text       = text;
                pnlQuadrupletPrimes.Visibility = Visibility.Visible;
            }
        }
Пример #2
0
        private PrimesBigInteger CalculateFactor(PrimesBigInteger value)
        {
            PrimesBigInteger x = m_StartFX;
            PrimesBigInteger y = m_StartFX;
            PrimesBigInteger d = PrimesBigInteger.One;
            PrimesBigInteger a = m_A;
            int i = 0;

            if (value.Mod(PrimesBigInteger.Two).Equals(PrimesBigInteger.Zero))
            {
                return(PrimesBigInteger.Two);
            }
            do
            {
                x = x.ModPow(PrimesBigInteger.Two, value).Add(a).Mod(value);
                y = y.ModPow(PrimesBigInteger.Two, value).Add(a).Mod(value);
                y = y.ModPow(PrimesBigInteger.Two, value).Add(a).Mod(value);
                d = PrimesBigInteger.GCD(x.Subtract(y), value);
                i++;
                if (y.Equals(x))
                {
                    log.Info("Change Values");
                    a = PrimesBigInteger.ValueOf(new Random().Next());
                    x = y = PrimesBigInteger.ValueOf(new Random().Next());
                    i = 0;
                }
            }while (d.Equals(PrimesBigInteger.One));
            return(d);
        }
Пример #3
0
        private void ActuallNumberButtonArea_MouseMove(object sender, MouseEventArgs e)
        {
            double x   = e.GetPosition(ActuallNumberButtonArea).X - PADDINGLEFT;
            int    div = (int)(x / m_UnitSize + 0.5);

            Canvas.SetLeft(pActualNumber, div * m_UnitSize + PADDINGLEFT - POINTERWIDTH / 2);
            PrimesBigInteger val = null;

            try { val = m_Buttons[div].BINumber; }
            catch { val = m_Start; }
            if (val != null && !val.Equals(m_ActualNumber))
            {
                MarkNumber(val);
            }
        }
Пример #4
0
        private bool ExecuteLog(PrimesBigInteger a)
        {
            PrimesBigInteger result = a.ModPow(m_Value.Subtract(PrimesBigInteger.One), m_Value);

            log.Info(
                string.Format(
                    "Berechne {0}^{1} mod {2} = {3}",
                    new object[] { a.ToString(), m_Value.Subtract(PrimesBigInteger.One), m_Value.ToString(), result.ToString() }));
            ControlHandler.SetPropertyValue(lblA, "Content", a.ToString());
            ControlHandler.SetPropertyValue(lblExp, "Text", m_Value.ToString() + "-1");
            ControlHandler.SetPropertyValue(lblP, "Content", m_Value.ToString());
            ControlHandler.SetPropertyValue(lblCalc, "Text", result.ToString());

            if (result.Equals(PrimesBigInteger.One))
            {
                log.Info(string.Format("{0} hat den Fermattest bestanden und ist mir einer Wahrscheinlichkeit von 50% eine Primzahl", m_Value.ToString()));
            }
            else
            {
                log.Info(string.Format("{0} hat den Fermattest nicht bestanden und ist damit definitiv keine Primzahl. {1} ist Belastungszeuge gegen {2}", new object[] { m_Value.ToString(), a.ToString(), m_Value.ToString() }));
            }

            return(result.Equals(PrimesBigInteger.One));
        }
Пример #5
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));
        }
Пример #6
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;
        }
Пример #7
0
        private PrimesBigInteger EulerPhi(PrimesBigInteger n)
        {
            if (n.Equals(PrimesBigInteger.One))
            {
                return(PrimesBigInteger.One);
            }
            PrimesBigInteger result = PrimesBigInteger.Zero;
            PrimesBigInteger k      = PrimesBigInteger.One;

            while (k.CompareTo(n) <= 0)
            {
                if (PrimesBigInteger.GCD(k, n).Equals(PrimesBigInteger.One))
                {
                    result = result.Add(PrimesBigInteger.One);
                }
                k = k.Add(PrimesBigInteger.One);
            }

            return(result);
        }
Пример #8
0
        private void DoFactorize(object o)
        {
            if (o == null)
            {
                return;
            }

            Dictionary <PrimesBigInteger, long> factors = null;
            PrimesBigInteger value = null;

            if (o.GetType() == typeof(PrimesBigInteger))
            {
                ControlHandler.SetPropertyValue(lblCalcFactorizationInfo, "Text", Distribution.numberline_factorizationcalculating);
                value   = o as PrimesBigInteger;
                factors = value.Factorize();
            }
            else if (o.GetType() == typeof(Dictionary <PrimesBigInteger, long>))
            {
                factors = o as Dictionary <PrimesBigInteger, long>;
                value   = PrimesBigInteger.Refactor(factors);
            }

            if (factors != null)
            {
                String s = value.ToString();
                if (!value.IsPrime(20) && !value.Equals(PrimesBigInteger.One))
                {
                    s += " = " + String.Join(" * ", factors.Keys.Select(i => i + ((factors[i] > 1) ? "^" + factors[i] : "")).ToArray());
                }

                ControlHandler.SetPropertyValue(lblFactors, "Visibility", Visibility.Visible);
                ControlHandler.SetPropertyValue(lblFactors, "Text", s);
            }

            if (FactorizationDone != null)
            {
                FactorizationDone();
            }
        }
Пример #9
0
        private void MarkNumber(PrimesBigInteger value)
        {
            if (m_ActualNumber != null && m_ActualNumber.Equals(value))
            {
                return;
            }

            UnmarkAllNumbers();
            CancelThreads();
            MarkNumberWithOutThreads(value);

            Dictionary <PrimesBigInteger, long> factors = value.Factorize();

            Factorize(factors);
            CalculateGoldbach(value);
            CountPrimes(value);
            m_EulerPhi.Start(value, factors);
            m_Tau.Start(value, factors);
            m_Rho.Start(value, factors);
            m_DivSum.Start(value, factors);

            ControlHandler.SetButtonEnabled(btnCancelAll, true);
        }
Пример #10
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();
            }
        }
        void m_PolynomRangeExecuter_FunctionResult(IPolynom p, PrimesBigInteger primesCount, PrimesBigInteger primesCountReal, PrimesBigInteger counter)
        {
            int row = log.NewLine();

            log.Info(p.ToString(), 0, row);
            PrimesBigInteger percent        = primesCount.Multiply(PrimesBigInteger.ValueOf(100)).Divide(counter);
            PrimesBigInteger percentAbsolut = primesCountReal.Multiply(PrimesBigInteger.ValueOf(100)).Divide(counter);

            /*Most Primes*/
            if (m_MostPrimes == null)
            {
                m_MostPrimes = percent;
                m_ListMostPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom);
            }
            else
            {
                if (m_MostPrimes.Equals(percent))
                {
                    m_ListMostPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom);
                }
                else
                {
                    if (m_MostPrimes.CompareTo(percent) < 0)
                    {
                        m_MostPrimes = percent;
                        m_ListMostPrimes.Clear();
                        m_ListMostPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom);
                    }
                }
            }

            if (m_MostPrimesAbsolut == null)
            {
                m_MostPrimesAbsolut = percentAbsolut;
                m_ListMostPrimesAbsolut.Add((p as SecondDegreePolynom).Clone() as IPolynom);
            }
            else
            {
                if (m_MostPrimesAbsolut.Equals(percentAbsolut))
                {
                    m_ListMostPrimesAbsolut.Add((p as SecondDegreePolynom).Clone() as IPolynom);
                }
                else
                {
                    if (m_MostPrimesAbsolut.CompareTo(percentAbsolut) < 0)
                    {
                        m_MostPrimesAbsolut = percentAbsolut;
                        m_ListMostPrimesAbsolut.Clear();
                        m_ListMostPrimesAbsolut.Add((p as SecondDegreePolynom).Clone() as IPolynom);
                    }
                }
            }

            /*Least Primes*/
            if (m_LeastPrimes == null)
            {
                m_LeastPrimes = percent;
                m_ListLeastPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom);
            }
            else
            {
                if (m_LeastPrimes.Equals(percent))
                {
                    m_ListLeastPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom);
                }
                else
                {
                    if (m_LeastPrimes.CompareTo(percent) > 0)
                    {
                        m_LeastPrimes = percent;
                        m_ListLeastPrimes.Clear();
                        m_ListLeastPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom);
                    }
                }
            }

            m_ResultCounter  = m_ResultCounter.Add(counter);
            m_PrimesCounter  = m_PrimesCounter.Add(primesCount);
            m_PolynomCounter = m_PolynomCounter.Add(PrimesBigInteger.One);
            log.Info(string.Format(Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statGenerated, new object[] { primesCount, percent, primesCountReal }), 1, row);
        }
Пример #12
0
        private void DoExecuteGraphic(PrimesBigInteger a)
        {
            lock (m_RunningLockObject)
            {
                m_Running = true;
            }
            Point            lastPoint = new Point(-1, -1);
            PrimesBigInteger factor    = null;

            ControlHandler.SetPropertyValue(lblA, "Content", a.ToString());
            ControlHandler.SetPropertyValue(lblExp, "Text", m_Value.ToString() + "-1");
            ControlHandler.SetPropertyValue(lblP, "Content", m_Value.ToString());

            ControlHandler.SetPropertyValue(lblCalc, "Text", string.Empty);
            ControlHandler.SetPropertyValue(lblCalc, "Text", a.ModPow(m_Value.Subtract(PrimesBigInteger.One), m_Value).ToString());
            PrimesBigInteger i = PrimesBigInteger.Two;

            PrimesBigInteger result  = null;
            PrimesBigInteger counter = PrimesBigInteger.Zero;

            while (i.CompareTo(m_Value.Subtract(PrimesBigInteger.One)) <= 0)
            {
                Thread.Sleep(100);
                result = a.ModPow(i, m_Value);
                log.Info(
                    string.Format(
                        "Berechne {0}^{1} mod {2} = {3}",
                        new object[] { a.ToString(), i.ToString(), m_Value.ToString(), result.ToString() }));

                if (factor == null)
                {
                    factor = result;
                }
                else
                {
                    factor = factor.Multiply(result);
                }
                //StringBuilder sbText = new StringBuilder();// new StringBuilder(ControlHandler.GetPropertyValue(lblCalc, "Text") as string);
                //sbText.Append(result.ToString());
                //if (i.CompareTo(m_Value.Subtract(PrimesBigInteger.One)) < 0)
                //  sbText.Append(" * ");
                //ControlHandler.SetPropertyValue(lblCalc, "Text", sbText.ToString());

                if (lastPoint.X == -1 && lastPoint.Y == -1)
                {
                    lastPoint = m_Points[result.IntValue];
                }
                else
                {
                    Point newPoint = m_Points[result.IntValue];
                    CreateArrow(counter, lastPoint, newPoint);
                    lastPoint = newPoint;
                }
                i       = i.Add(PrimesBigInteger.One);
                counter = counter.Add(PrimesBigInteger.One);
            }

            if (result != null)
            {
                if (result.Equals(PrimesBigInteger.One))
                {
                    log.Info(
                        string.Format(
                            "Berechne {0}^{1} mod {2} = 1. {3} könnte eine Primzahl sein.",
                            new object[] { a.ToString(), m_Value.Subtract(PrimesBigInteger.One).ToString(), m_Value.ToString(), m_Value.ToString() }));
                }
                else
                {
                    log.Info(
                        string.Format(
                            "Berechne {0}^{1} mod {2} = {3}. {4} ist damit definitiv keine Primzahl.",
                            new object[] { a.ToString(), m_Value.Subtract(PrimesBigInteger.One).ToString(), m_Value.ToString(), result.ToString(), m_Value.ToString() }));
                }
            }

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

            lock (m_RunningLockObject)
            {
                m_Running = false;
            }
        }