Esempio n. 1
0
        private void DoScrollGrid(PrimesBigInteger amount)
        {
            bool keepColor = true;
            int  counter   = 0;

            for (int i = 0; i < this.Rows; i++)
            {
                for (int j = 0; j < this.Columns; j++)
                {
                    NumberButton btn = GetNumberButton(this.Rows + this.Columns - 2 + counter);
                    if (btn != null)
                    {
                        PrimesBigInteger newVal = btn.BINumber.Add(amount);
                        btn.BINumber = newVal;
                        if (newVal.CompareTo(m_Limit) > 0 || newVal.CompareTo(PrimesBigInteger.One) < 0)
                        {
                            if (m_Limit.CompareTo(PrimesBigInteger.ValueOf(Rows * Columns)) < 0)
                            {
                                return;
                            }
                            ControlHandler.SetButtonVisibility(btn, Visibility.Hidden);
                        }
                        else
                        {
                            // Color the Buttons
                            if (m_ButtonColor != null)
                            {
                                ControlHandler.SetPropertyValue(btn, "Background", m_ButtonColor);
                            }
                            else
                            {
                                if (!keepColor)
                                {
                                    btn.Background = Brushes.White;
                                }
                            }
                            bool isMultipleOfRemovedNumbers = !m_Sieved[btn.BINumber.LongValue];
                            if (
                                isMultipleOfRemovedNumbers ||
                                m_RemovedNumbers.Contains(btn.BINumber))
                            {
                                ControlHandler.SetButtonVisibility(btn, Visibility.Hidden);
                            }
                            else
                            {
                                if (m_MarkedNumbers.ContainsKey(newVal))
                                {
                                    ControlHandler.SetPropertyValue(btn, "Background", m_MarkedNumbers[newVal]);
                                }
                                ControlHandler.SetButtonVisibility(btn, Visibility.Visible);
                            }
                        }
                    }
                    counter++;
                }
            }

            SetButtonStatus();
        }
        private void ExecuteTestSystematic_Log()
        {
            FireEventStartTest();

            while (m_SystematicFrom.CompareTo(m_SystematicTo) <= 0)
            {
                if (!ExecuteLog(m_SystematicFrom))
                {
                    m_SystematicFrom = m_SystematicTo;
                }
                m_SystematicFrom = m_SystematicFrom.Add(PrimesBigInteger.One);
            }

            FireEventStopText();
        }
Esempio n. 3
0
        protected override void DoExecute()
        {
            FireOnStart();
            PrimesBigInteger from = m_From;

            while (from.CompareTo(m_To) <= 0)
            {
                PrimesBigInteger result = PrimesBigInteger.Zero;
                PrimesBigInteger k      = PrimesBigInteger.One;
                while (k.CompareTo(from) <= 0)
                {
                    if (from.Mod(k).Equals(PrimesBigInteger.Zero))
                    {
                        PrimesBigInteger phik = EulerPhi(k);
                        result = result.Add(phik);
                        FireOnMessage(this, from, result.ToString());
                    }
                    k = k.Add(PrimesBigInteger.One);
                }
                FireOnMessage(this, from, result.ToString());
                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Esempio n. 4
0
 public virtual void Execute()
 {
     if (m_From == null)
     {
         throw new ArgumentNullException("from");
     }
     if (m_To == null)
     {
         throw new ArgumentNullException("to");
     }
     if (m_From.CompareTo(m_To) > 0)
     {
         throw new ArgumentException("from must be greater than to", "from");
     }
     StartThread();
 }
Esempio n. 5
0
        protected override void DoExecute()
        {
            FireOnStart();

            PrimesBigInteger from = m_From;

            while (from.CompareTo(m_To) <= 0)
            {
                if (from.IsPrime(20))
                {
                    FireOnMessage(this, from, from.Subtract(PrimesBigInteger.One).ToString("D"));
                }
                else
                {
                    PrimesBigInteger d       = PrimesBigInteger.One;
                    PrimesBigInteger counter = PrimesBigInteger.Zero;

                    while (d.CompareTo(from) < 0)
                    {
                        if (PrimesBigInteger.GCD(d, from).Equals(PrimesBigInteger.One))
                        {
                            counter = counter.Add(PrimesBigInteger.One);
                            FireOnMessage(this, from, counter.ToString("D"));
                        }
                        d = d.Add(PrimesBigInteger.One);
                    }

                    FireOnMessage(this, from, counter.ToString("D"));
                }

                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Esempio n. 6
0
        protected override void DoExecute()
        {
            FireOnStart();

            try
            {
                PrimesBigInteger modulus = m_SecondParameter;

                PrimesBigInteger from = m_From;

                while (from.CompareTo(m_To) <= 0)
                {
                    string msg;
                    try
                    {
                        PrimesBigInteger result = from.ModInverse(modulus);
                        msg = result.ToString("D");
                    }
                    catch (Exception ex)
                    {
                        msg = "-";
                    }
                    FireOnMessage(this, from, msg);
                    from = from.Add(PrimesBigInteger.One);
                }
            }
            catch (Exception ex)
            {
            }

            FireOnStop();
        }
Esempio n. 7
0
        private bool IsPrimitiveRoot(PrimesBigInteger root, PrimesBigInteger prime)
        {
            if (!PrimesBigInteger.GCD(root, prime).Equals(PrimesBigInteger.One))
            {
                return(false);
            }

            PrimesBigInteger primeMinus1 = prime.Subtract(PrimesBigInteger.One);
            PrimesBigInteger k           = PrimesBigInteger.One;

            while (k.CompareTo(primeMinus1) < 0)
            {
                if (m_Jump)
                {
                    return(false);
                }
                if (root.ModPow(k, prime).Equals(PrimesBigInteger.One))
                {
                    return(false);
                }
                k = k.Add(PrimesBigInteger.One);
            }

            return(true);
        }
Esempio n. 8
0
        protected override void DoExecute()
        {
            FireOnStart();

            PrimesBigInteger from = m_From;

            while (from.CompareTo(m_To) <= 0)
            {
                StringBuilder    sbMessage = new StringBuilder("[");
                PrimesBigInteger d         = PrimesBigInteger.One;
                while (d.CompareTo(from) < 0)
                {
                    if (PrimesBigInteger.GCD(d, from).Equals(PrimesBigInteger.One))
                    {
                        if (sbMessage.Length > 1)
                        {
                            sbMessage.Append(", ");
                        }
                        sbMessage.Append(d.ToString());
                        FireOnMessage(this, from, sbMessage.ToString());
                    }
                    d = d.Add(PrimesBigInteger.One);
                }
                sbMessage.Append("]");
                FireOnMessage(this, from, sbMessage.ToString());

                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Esempio n. 9
0
        private bool Witness(PrimesBigInteger a)
        {
            // a mustn't be a multiple of n
            if (a.Mod(m_Value).CompareTo(0) == 0)
            {
                return(false);
            }

            PrimesBigInteger n_1 = m_Value - 1;

            log.Info(string.Format("n-1 = {0} = 2^{1} * {2}", n_1, m_shift, m_d));

            PrimesBigInteger former = a.ModPow(m_d, m_Value);

            log.Info(string.Format(rsc.Primetest.mr_calculating1, a, m_d, m_Value, former));
            if (former.CompareTo(1) == 0)
            {
                log.Info(string.Format(rsc.Primetest.mr_isprime, a, m_Value));
                return(false);
            }

            PrimesBigInteger square = 1;

            for (int i = 1; i <= m_shift; i++)
            {
                square = former.ModPow(2, m_Value);
                log.Info(string.Format(rsc.Primetest.mr_calculating2, a, m_d, 1 << i, m_Value, former, square));
                if (square.CompareTo(1) == 0)
                {
                    bool trivialroot = former.CompareTo(1) == 0 || former.CompareTo(n_1) == 0;
                    if (trivialroot)
                    {
                        log.Info(string.Format(rsc.Primetest.mr_isprime, a, m_Value));
                        return(false);
                    }
                    else
                    {
                        log.Info(string.Format(rsc.Primetest.mr_isnotprime1, former, m_Value));
                        return(true);
                    }
                }
                former = square;
            }

            log.Info(string.Format(rsc.Primetest.mr_isnotprime2, m_Value, a, n_1, m_Value, square));
            return(true);
        }
Esempio n. 10
0
        //private void ComputeRandom()
        //{
        //  PrimesBigInteger i = PrimesBigInteger.One;
        //  while (i.CompareTo(this.NumberOfFormulars) < 0)
        //  {
        //    PrimesBigInteger j = PrimesBigInteger.One;
        //    PrimesBigInteger to = this.NumberOfCalculations;
        //    if (NumberOfCalculations.Equals(PrimesBigInteger.NaN))
        //    {
        //      j = From;
        //      to = To;
        //    }
        //    PrimesBigInteger counter = PrimesBigInteger.Zero;
        //    PrimesBigInteger primesCounter = PrimesBigInteger.Zero;
        //    while(j.CompareTo(to)<=0){
        //      foreach (KeyValuePair<string, Range> kvp in this.Parameters)
        //      {
        //        PrimesBigInteger value = PrimesBigInteger.RandomM(kvp.Value.From.Add(kvp.Value.RangeAmount)).Add(PrimesBigInteger.One);
        //        Function.SetParameter(kvp.Key, value);
        //      }
        //      PrimesBigInteger input = j;
        //      if (!NumberOfCalculations.Equals(PrimesBigInteger.NaN))
        //      {
        //        input = PrimesBigInteger.RandomM(NumberOfCalculations);
        //      }
        //      PrimesBigInteger res = Function.Execute(input);
        //      if(res.IsPrime(10)){
        //        primesCounter = primesCounter.Add(PrimesBigInteger.One);
        //      }
        //      j = j.Add(PrimesBigInteger.One);
        //      counter = counter.Add(PrimesBigInteger.One);
        //    }
        //    if (this.FunctionResult != null) this.FunctionResult(this.Function as IPolynom, primesCounter, counter);
        //    i = i.Add(PrimesBigInteger.One);
        //  }
        //}

        private void ComputeRandom()
        {
            Random r = new Random();

            PrimesBigInteger         i             = PrimesBigInteger.One;
            PrimesBigInteger         j             = null;
            PrimesBigInteger         to            = null;
            PrimesBigInteger         counter       = null;
            PrimesBigInteger         primesCounter = null;
            IList <PrimesBigInteger> m_PrimeList   = new List <PrimesBigInteger>();

            while (i.CompareTo(this.NumberOfFormulars) <= 0)
            {
                j  = PrimesBigInteger.One;
                to = this.NumberOfCalculations;
                if (NumberOfCalculations.Equals(PrimesBigInteger.NaN))
                {
                    j  = From;
                    to = To;
                }
                counter       = PrimesBigInteger.Zero;
                primesCounter = PrimesBigInteger.Zero;
                foreach (KeyValuePair <string, Range> kvp in this.Parameters)
                {
                    PrimesBigInteger mod   = kvp.Value.To.Subtract(kvp.Value.From).Add(PrimesBigInteger.One);
                    PrimesBigInteger value = PrimesBigInteger.ValueOf(r.Next(int.MaxValue)).Mod(mod).Add(kvp.Value.From);//PrimesBigInteger.RandomM(kvp.Value.From.Add(kvp.Value.RangeAmount)).Add(PrimesBigInteger.One);
                    Function.SetParameter(kvp.Key, value);
                }
                while (j.CompareTo(to) <= 0)
                {
                    PrimesBigInteger input = j;
                    if (!NumberOfCalculations.Equals(PrimesBigInteger.NaN))
                    {
                        input = PrimesBigInteger.ValueOf(r.Next(int.MaxValue)).Mod(NumberOfCalculations);//PrimesBigInteger.RandomM(NumberOfCalculations);
                    }
                    PrimesBigInteger res = Function.Execute(input);
                    if (res.CompareTo(PrimesBigInteger.Zero) >= 0 && res.IsPrime(10))
                    {
                        if (!m_PrimeList.Contains(res))
                        {
                            m_PrimeList.Add(res);
                        }
                        primesCounter = primesCounter.Add(PrimesBigInteger.One);
                    }
                    j       = j.Add(PrimesBigInteger.One);
                    counter = counter.Add(PrimesBigInteger.One);
                }
                if (this.FunctionResult != null)
                {
                    this.FunctionResult(this.Function as IPolynom, primesCounter, PrimesBigInteger.ValueOf(m_PrimeList.Count), counter);
                }
                i = i.Add(PrimesBigInteger.One);
            }
        }
Esempio n. 11
0
        private void DoAtomicScroll(PrimesBigInteger amount)
        {
            PrimesBigInteger len      = PrimesBigInteger.ValueOf(m_Buttons.Count - 1);
            PrimesBigInteger newStart = m_Start.Add(amount);

            if (newStart.Add(len).CompareTo(MAX) > 0)
            {
                newStart = MAX.Subtract(len);
            }
            else if (newStart.CompareTo(MIN) < 0)
            {
                newStart = MIN;
            }

            amount  = newStart.Subtract(m_Start);
            m_Start = newStart;
            m_End   = m_Start.Add(len);

            m_ButtonsDict.Clear();

            foreach (NumberButton btn in m_Buttons)
            {
                PrimesBigInteger number = (ControlHandler.GetPropertyValue(btn, "BINumber") as PrimesBigInteger).Add(amount);
                ControlHandler.SetPropertyValue(btn, "BINumber", number);
                m_ButtonsDict.Add(number, btn);
                SetButtonColor(btn);
            }

            if (m_ActualNumber.CompareTo(m_Start) < 0)
            {
                m_ActualNumber = m_Start;
            }
            if (m_ActualNumber.CompareTo(m_End) > 0)
            {
                m_ActualNumber = m_End;
            }
            MarkNumberWithOutThreads(m_ActualNumber);

            SetFromTo();
            SetCountPrimes();
        }
Esempio n. 12
0
 void iscTo_Execute(PrimesBigInteger value)
 {
     if (value.CompareTo(PrimesBigInteger.Two.Add(ButtonScaleMinusOne)) >= 0)
     {
         iscFrom.ResetMessages();
         iscTo.ResetMessages();
         EnableInput();
         PrimesBigInteger diff = value.Subtract(m_Start.Add(ButtonScaleMinusOne));
         DoAtomicScroll(diff);
         MarkNumberWithOutThreads(value);
     }
 }
Esempio n. 13
0
        //public event VoidDelegate Finshed;

        #endregion

        #region Work

        protected override void OnDoWork()
        {
            m_Finished.Reset();
            PrimesBigInteger value = PrimesBigInteger.Two;

            while (value.CompareTo(m_Max) <= 0)
            {
                m_Primes.Add(value);
                value = value.NextProbablePrime();
            }
            m_Finished.Set();
        }
Esempio n. 14
0
 void ircCountPrimes_KeyDown(PrimesBigInteger from, PrimesBigInteger to, PrimesBigInteger second)
 {
     if (to.CompareTo(PrimesBigInteger.ValueOf(10000)) > 0)
     {
         lblInfoPixDontCalc.Visibility = Visibility.Visible;
         cbPiX.IsEnabled = false;
     }
     else
     {
         lblInfoPixDontCalc.Visibility = Visibility.Collapsed;
         cbPiX.IsEnabled = true;
     }
 }
Esempio n. 15
0
        public IList <int> CalculateFactorBase()
        {
            List <int>       result = new List <int>();
            PrimesBigInteger b      = PrimesBigInteger.ValueOf(m_B);
            PrimesBigInteger c      = PrimesBigInteger.Two;

            while (c.CompareTo(b) <= 0)
            {
                result.Add(c.IntValue);
                c = c.NextProbablePrime();
            }
            return(result);
        }
Esempio n. 16
0
        public override ValidationResult Validate(ref PrimesBigInteger bi)
        {
            ValidationResult result = base.Validate(ref bi);

            if (result == ValidationResult.OK)
            {
                if (bi.CompareTo(m_MaxValue) > 0)
                {
                    result = ValidationResult.WARNING;
                }
            }
            return(result);
        }
Esempio n. 17
0
        private void ExecuteStair()
        {
            FunctionExecute fe = m_FunctionExecute;
            double x1 = m_XStart;
            PrimesBigInteger incX = PrimesBigInteger.One;
            PrimesBigInteger inci = PrimesBigInteger.One;
            PrimesBigInteger div = (fe.Range.RangeAmount.CompareTo(PrimesBigInteger.ValueOf(10000)) > 0) ? PrimesBigInteger.Ten : PrimesBigInteger.OneHundred;
            if (fe.Range.RangeAmount.CompareTo(PrimesBigInteger.ValueOf(1000)) > 0 && fe.Function.CanEstimate)
            {
                inci = fe.Range.RangeAmount.Divide(div);
                incX = inci;
            }

            PrimesBigInteger i = m_From;
            while (i.CompareTo(fe.Range.To) <= 0 && !HasTerminateRequest())
            {
                Boolean awokenByTerminate = SuspendIfNeeded();

                if (awokenByTerminate)
                {
                    m_From = i;
                    return;
                }

                double param = i.DoubleValue;

                double formerY = fe.Function.FormerValue;
                double y = fe.Function.Execute(param);

                bool drawstair = !formerY.Equals(y) || formerY.Equals(double.NaN);
                if (formerY.Equals(double.NaN)) formerY = y;
                double x2 = x1 + double.Parse(incX.ToString());
                if (fe.Function.DrawTo.Equals(double.PositiveInfinity) || (x2 <= fe.Function.DrawTo && x2 <= fe.Range.To.DoubleValue))
                {
                    if (drawstair)
                    {
                        x2 -= double.Parse(incX.ToString());
                    }
                    if (!DrawLine(x1, x2, formerY, y, fe.Color, fe.Function)) break;
                    if (drawstair)
                    {
                        x2 += double.Parse(incX.ToString());
                        if (!DrawLine(x1, x2, y, y, fe.Color, fe.Function)) break;
                    }
                }

                x1 = x2;
                i = i.Add(inci);
            }
        }
Esempio n. 18
0
        private void ComputeSystematic()
        {
            Range            rangea  = this.Parameters[0].Value;
            Range            rangeb  = this.Parameters[1].Value;
            Range            rangec  = this.Parameters[2].Value;
            PrimesBigInteger ca      = rangea.From;
            PrimesBigInteger counter = PrimesBigInteger.Zero;

            while (ca.CompareTo(rangea.To) <= 0)
            {
                m_Function.SetParameter("a", ca);
                PrimesBigInteger cb = rangeb.From;
                while (cb.CompareTo(rangeb.To) <= 0)
                {
                    m_Function.SetParameter("b", cb);
                    PrimesBigInteger cc = rangec.From;
                    while (cc.CompareTo(rangec.To) <= 0)
                    {
                        m_Function.SetParameter("c", cc);

                        PrimesBigInteger         from          = From;
                        PrimesBigInteger         primesCounter = PrimesBigInteger.Zero;
                        IList <PrimesBigInteger> m_PrimeList   = new List <PrimesBigInteger>();
                        while (from.CompareTo(To) <= 0)
                        {
                            PrimesBigInteger res = Function.Execute(from);
                            if (res.IsPrime(10))
                            {
                                if (!m_PrimeList.Contains(res))
                                {
                                    m_PrimeList.Add(res);
                                }
                                primesCounter = primesCounter.Add(PrimesBigInteger.One);
                            }
                            counter = counter.Add(PrimesBigInteger.One);
                            from    = from.Add(PrimesBigInteger.One);
                        }
                        if (this.FunctionResult != null)
                        {
                            this.FunctionResult(this.Function as IPolynom, primesCounter, PrimesBigInteger.ValueOf(m_PrimeList.Count), counter);
                        }

                        cc = cc.Add(PrimesBigInteger.One);
                    }
                    cb = cb.Add(PrimesBigInteger.One);
                }
                ca = ca.Add(PrimesBigInteger.One);
            }
        }
Esempio n. 19
0
 public StepResult DoStep(PrimesBigInteger value)
 {
     if (m_Expected.CompareTo(value) == 0)
     {
         m_Numbergrid.RemoveMulipleOf(value);
         m_Expected = m_Expected.NextProbablePrime();
         m_Current  = value;
         if (m_Current.Pow(2).CompareTo(m_MaxValue) >= 0)
         {
             return(StepResult.END);
         }
         return(StepResult.SUCCESS);
     }
     else
     {
         return(StepResult.FAILED);
     }
 }
Esempio n. 20
0
        private void InitButtons()
        {
            btnBack.Visibility    = btnCompleteBack.Visibility = Visibility.Visible;
            btnForward.Visibility = btnCompleteForward.Visibility = Visibility.Visible;

            if (numbergrid.RowDefinitions.Count >= MIN)
            {
                this.numbergrid.Children.Clear();
                DrawGrid();
            }

            PrimesBigInteger counter = 1;

            for (int i = 0; i < this.Rows; i++)
            {
                for (int j = 0; j < this.Columns; j++)
                {
                    NumberButton btn = new NumberButton();
                    btn.NumberButtonStyle = Primes.WpfControls.Components.NumberButtonStyle.Button.ToString();

                    btn.ShowContent = true;
                    btn.Number      = (counter).ToString();
                    btn.Click      += new RoutedEventHandler(NumberButton_Click);
                    Grid.SetColumn(btn, 2 * j);
                    Grid.SetRow(btn, 2 * i);

                    btn.Background = Brushes.White;

                    this.numbergrid.Children.Add(btn);
                    if (counter.CompareTo(this.m_Limit) > 0)
                    {
                        btn.Visibility = Visibility.Hidden;
                    }
                    if (m_RemovedNumbers.Contains(btn.BINumber))
                    {
                        btn.Visibility = Visibility.Hidden;
                    }

                    counter = counter.Add(PrimesBigInteger.ValueOf(1));
                }
            }

            SetButtonStatus();
        }
Esempio n. 21
0
        public void Execute(PrimesBigInteger value)
        {
            tabItemGraphic.IsEnabled = true;
            tcStats.SelectedIndex    = 0;

            this.m_Value = value;
            m_Arrows.Clear();
            ArrowArea.Children.Clear();
            log.Columns = 1;
            log.Clear();
            if (value.CompareTo(PrimesBigInteger.ValueOf(150)) > 0)
            {
                tcStats.SelectedIndex    = 1;
                tabItemGraphic.IsEnabled = false;
                log.Info("Ist die zu prüfende Zahl > 150 kann die Berechnung im Kreis nicht mehr sinnvoll dargestellt werden.");

                switch (KindOfTest)
                {
                case KOD.Single:
                    ExecuteSingle_Log();
                    break;

                case KOD.Systematic:
                    ExecuteSystematic_Log();
                    break;
                }
            }
            else
            {
                CreatePoints();
                switch (KindOfTest)
                {
                case KOD.Single:
                    ExecuteSingle_Graphic();
                    break;

                case KOD.Systematic:
                    ExecuteSystematic_Graphic();
                    break;
                }
            }
        }
Esempio n. 22
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);
        }
Esempio n. 23
0
        private void SetTwinPrimes(PrimesBigInteger value)
        {
            PrimesBigInteger twin1 = value.Subtract(PrimesBigInteger.One);
            PrimesBigInteger twin2 = value.Add(PrimesBigInteger.One);
            PrimesBigInteger tmp   = null;

            if (twin1.IsPrime(20) && twin2.IsPrime(20))
            {
                lblTwinPrimes.Text       = string.Format(Distribution.numberline_insidetwinprime, value, twin1, twin2);
                lblTwinPrimes.Visibility = Visibility.Visible;
            }
            else if (value.IsTwinPrime(ref tmp))
            {
                twin1 = PrimesBigInteger.Min(value, tmp);
                twin2 = PrimesBigInteger.Max(value, tmp);
                if (m_ButtonsDict.ContainsKey(twin1))
                {
                    MarkNumber(m_ButtonsDict[twin1]);
                }
                if (m_ButtonsDict.ContainsKey(twin2))
                {
                    MarkNumber(m_ButtonsDict[twin2]);
                }
                lblTwinPrimes.Text       = string.Format(Distribution.numberline_istwinprime, twin1, twin2);
                lblTwinPrimes.Visibility = Visibility.Visible;
            }

            PrimesBigInteger a    = null;
            PrimesBigInteger b    = null;
            string           text = "";

            twin1.PriorTwinPrime(ref a, ref b);
            if (a.CompareTo(twin1) < 0)
            {
                text = string.Format(Distribution.numberline_priortwinprime, a, b) + " ";
            }
            twin1.Add(PrimesBigInteger.One).NextTwinPrime(ref a, ref b);
            text += string.Format(Distribution.numberline_nexttwinprime, a, b);

            lblTwinPrimes2.Text = text;
        }
Esempio n. 24
0
        private void btnExec_Click(object sender, RoutedEventArgs e)
        {
            PrimesBigInteger n      = GetPrimesCount();
            PrimesBigInteger digits = GetDigits();

            if (digits != null && n != null)
            {
                if (digits.CompareTo(m_MaxDigits) > 0)
                {
                    Info(string.Format(Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.ntimesm_errordigits, m_MaxDigits.ToString()), tbM);
                }
                else
                {
                    if (Execute != null)
                    {
                        Execute(n, digits);
                    }
                    //if (Execute != null) Execute(n, digits.Subtract(PrimesBigInteger.One));
                }
            }
        }
Esempio n. 25
0
        protected override void DoExecute()
        {
            FireOnStart();

            try
            {
                PrimesBigInteger modulus = m_SecondParameter;

                PrimesBigInteger from = m_From;

                while (from.CompareTo(m_To) <= 0)
                {
                    PrimesBigInteger result = PrimesBigInteger.GCD(from, modulus);
                    FireOnMessage(this, from, result.ToString("D"));
                    from = from.Add(PrimesBigInteger.One);
                }
            }
            catch (Exception ex)
            {
            }

            FireOnStop();
        }
Esempio n. 26
0
        protected override void DoExecute()
        {
            FireOnStart();

            for (PrimesBigInteger from = m_From; from.CompareTo(m_To) <= 0; from = from + 1)
            {
                PrimesBigInteger sum = 0;

                for (PrimesBigInteger d = 1; d * 2 <= from; d = d + 1)
                {
                    if (from.Mod(d).Equals(PrimesBigInteger.Zero))
                    {
                        sum = sum + d;
                        FireOnMessage(this, from, sum.ToString());
                    }
                }

                sum = sum + from;
                FireOnMessage(this, from, sum.ToString());
            }

            FireOnStop();
        }
Esempio n. 27
0
        protected override void DoExecute()
        {
            FireOnStart();

            FunctionPiX      pix         = new FunctionPiX();
            PrimesBigInteger from        = m_From;
            PrimesBigInteger _counterTmp = PrimesBigInteger.Two;

            while (_counterTmp.CompareTo(from) <= 0)
            {
                double result = pix.Execute(_counterTmp.DoubleValue);
                FireOnMessage(this, from, StringFormat.FormatDoubleToIntString(result));
                _counterTmp = _counterTmp.Add(PrimesBigInteger.One);
            }

            while (from.CompareTo(m_To) <= 0)
            {
                double result = pix.Execute(from.DoubleValue);
                FireOnMessage(this, from, StringFormat.FormatDoubleToIntString(result));
                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Esempio n. 28
0
        public void RemoveMulipleOf(PrimesBigInteger value)
        {
            DateTime start = DateTime.Now;

            PrimesBigInteger i = value.Multiply(PrimesBigInteger.Two);

            while (i.CompareTo(m_Limit) <= 0)
            {
                m_Sieved[i.LongValue] = false;
                i = i.Add(value);
            }
            //PrimesBigInteger counter = PrimesBigInteger.Two;
            //while (counter.Multiply(value).CompareTo(m_Limit)<=0)
            //{
            //  m_RemovedNumbers.Add(counter.Multiply(value));
            //  counter = counter.Add(PrimesBigInteger.One);
            //}
            m_RemovedMods.Add(value);
            if (value.Pow(2).CompareTo(GetMaxVisibleValue()) <= 0)
            {
                RedrawButtons();
            }
            TimeSpan diff = DateTime.Now - start;
        }
Esempio n. 29
0
        private void DoCalculatePrimitiveRoots()
        {
            try
            {
                DateTime start = DateTime.Now;

                FireOnStart();

                m_Jump = false;

                int numberOfPrimes = 0;

                foreach (var interval in intervals)
                {
                    PrimesBigInteger prime = interval[0];
                    if (!prime.IsPrime(10))
                    {
                        prime = prime.NextProbablePrime();
                    }
                    for (; prime.CompareTo(interval[1]) <= 0; prime = prime.NextProbablePrime())
                    {
                        numberOfPrimes++;

                        int row1 = log.NewLine();
                        int row2 = log.NewLine();

                        log.Info(string.Format(rsc.proot_calculating, prime.ToString()), 0, row1);

                        PrimesBigInteger primeMinus1 = prime.Subtract(PrimesBigInteger.One);
                        PrimesBigInteger numroots    = primeMinus1.Phi();

                        string fmt    = numroots.CompareTo(PrimesBigInteger.One) == 0 ? rsc.proot_resultcalc : rsc.proot_resultscalc;
                        string result = string.Format(fmt, prime.ToString(), numroots.ToString());
                        log.Info(result + ". " + rsc.proot_calculating, 0, row1);

                        PrimesBigInteger primitiveroot = PrimesBigInteger.One;
                        while (primitiveroot.CompareTo(prime) < 0)
                        {
                            if (m_Jump)
                            {
                                break;
                            }
                            if (IsPrimitiveRoot(primitiveroot, prime))
                            {
                                break;
                            }
                            primitiveroot = primitiveroot.Add(PrimesBigInteger.One);
                        }

                        List <PrimesBigInteger> roots = new List <PrimesBigInteger>();

                        PrimesBigInteger i       = PrimesBigInteger.One;
                        bool             skipped = false;

                        while (i.CompareTo(prime) < 0)
                        {
                            lock (m_JumpLockObject)
                            {
                                if (m_Jump)
                                {
                                    m_Jump  = false;
                                    skipped = true;
                                    break;
                                }
                            }
                            if (PrimesBigInteger.GCD(i, primeMinus1).Equals(PrimesBigInteger.One))
                            {
                                roots.Add(primitiveroot.ModPow(i, prime));
                            }
                            i = i.Add(PrimesBigInteger.One);
                        }

                        if (skipped)
                        {
                            log.Info(result + ". " + rsc.proot_skip, 0, row1);
                        }
                        else
                        {
                            log.Info(result + ". " + rsc.proot_printing, 0, row1);
                            roots.Sort(PrimesBigInteger.Compare);
                            //string numbers = string.Join(" ", roots.ToArray().Select(x => x.ToString()));
                            StringBuilder sb = new StringBuilder();
                            foreach (var r in roots)
                            {
                                lock (m_JumpLockObject)
                                {
                                    if (m_Jump)
                                    {
                                        m_Jump  = false;
                                        skipped = true;
                                        break;
                                    }
                                }
                                sb.Append(r.ToString() + " ");
                            }
                            if (skipped)
                            {
                                log.Info(result + ". " + rsc.proot_skip, 0, row1);
                            }
                            else
                            {
                                string numbers = sb.ToString();
                                log.Info(numbers, 0, row2);
                                log.Info(result + ":", 0, row1);
                            }
                        }

                        log.NewLine();
                    }
                }

                if (numberOfPrimes == 0)
                {
                    log.Info(rsc.proot_noprimes);
                }

                TimeSpan diff = DateTime.Now - start;

                StopThread();
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 30
0
        private void Execute(bool doExecute)
        {
            ClearLog();
            intervals.Clear();

            string _input = tbInput.Text;

            if (!string.IsNullOrEmpty(_input))
            {
                string[] input = _input.Trim().Split(',');
                if (input != null && input.Length > 0)
                {
                    foreach (string s in input)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            string[] _inputrange = s.Split(':');
                            if (_inputrange.Length == 1)
                            {
                                PrimesBigInteger ipt = null;
                                validator.Value = s;
                                Primes.WpfControls.Validation.ValidationResult res = validator.Validate(ref ipt);
                                if (res == Primes.WpfControls.Validation.ValidationResult.OK)
                                {
                                    if (ipt.IsPrime(10))
                                    {
                                        intervals.Add(new List <PrimesBigInteger> {
                                            ipt, ipt
                                        });
                                        if (ipt.CompareTo(MAX) > 0)
                                        {
                                            log.Info(string.Format(rsc.proot_warningbignumber, s));
                                        }
                                    }
                                    else
                                    {
                                        log.Info(string.Format(rsc.proot_noprime, s));
                                    }
                                }
                                else
                                {
                                    log.Info(string.Format(rsc.proot_novalidnumber, new object[] { s, MIN.ToString(), MAX.ToString() }));
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(_inputrange[0]) && string.IsNullOrEmpty(_inputrange[1]))
                                {
                                    log.Info(rsc.proot_rangeboth);
                                }
                                else if (string.IsNullOrEmpty(_inputrange[0]))
                                {
                                    log.Info(string.Format(rsc.proot_rangeupper, _inputrange[1]));
                                }
                                else if (string.IsNullOrEmpty(_inputrange[1]))
                                {
                                    log.Info(string.Format(rsc.proot_rangedown, _inputrange[0]));
                                }
                                else
                                {
                                    PrimesBigInteger i1 = IsGmpBigInteger(_inputrange[0]);
                                    PrimesBigInteger i2 = IsGmpBigInteger(_inputrange[1]);
                                    if (i1 != null && i2 != null)
                                    {
                                        if (i1.CompareTo(i2) >= 0)
                                        {
                                            log.Info(string.Format(rsc.proot_wronginterval, s));
                                        }
                                        else
                                        {
                                            intervals.Add(new List <PrimesBigInteger> {
                                                i1, i2
                                            });
                                            if (i2.CompareTo(MAXWARN) > 0)
                                            {
                                                log.Info(string.Format(rsc.proot_warningbiginterval, s));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (doExecute && intervals.Count > 0)
                {
                    StartThread();
                }
            }
            else
            {
                Info(rsc.proot_insert);
            }
        }