Esempio n. 1
0
        //private void Scroll(int factor)
        //{
        //  DateTime start = DateTime.Now;

        //  foreach (Rectangle nb in m_Buttons)
        //  {
        //    PrimesBigInteger c = nb.Tag as PrimesBigInteger;
        //    c = c.Add(PrimesBigInteger.ValueOf(this.Columns * factor));
        //    if (c.IsPrime(10))
        //    {
        //      nb.Fill = Brushes.Red;
        //    }
        //    else
        //    {
        //      nb.Fill = Brushes.White;
        //    }

        //    nb.Tag = c;
        //    (nb.ToolTip as ToolTip).Content = c.ToString();
        //  }
        //  TimeSpan diff = DateTime.Now - start;
        //  Debug.WriteLine(string.Format("Scroll: Std={0}, Min={1}, sek={2}, MS={3}", new object[] { diff.Hours, diff.Minutes, diff.Seconds, diff.Milliseconds }));
        //}

        private void Scroll(int factor)
        {
            //DateTime start = DateTime.Now;
            PrimesBigInteger sa = PrimesBigInteger.ValueOf(this.Columns * factor);

            m_start = PrimesBigInteger.Max(m_start.Add(sa), PrimesBigInteger.One);
            DrawButtons();
            //TimeSpan diff = DateTime.Now - start;
            //Debug.WriteLine(string.Format("Scroll: Std={0}, Min={1}, sek={2}, MS={3}", new object[] { diff.Hours, diff.Minutes, diff.Seconds, diff.Milliseconds }));
        }
        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)
            {
                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. 4
0
        /// <summary>
        /// Calculates binary expressions and pushes the result into the operands stack
        /// </summary>
        /// <param name="op">Binary operator</param>
        /// <param name="operand1">First operand</param>
        /// <param name="operand2">Second operand</param>
        private void Calculate(string op, PrimesBigInteger operand1, PrimesBigInteger operand2)
        {
            PrimesBigInteger res = PrimesBigInteger.Zero;

            try
            {
                switch (op)
                {
                case Token.Add: res = operand1.Add(operand2); break;

                case Token.Subtract: res = operand1.Subtract(operand2); break;

                case Token.Multiply: res = operand1.Multiply(operand2); break;

                case Token.Divide: res = operand1.Divide(operand2); break;

                case Token.Mod: res = operand1.Mod(operand2); break;

                case Token.Power: res = operand1.Pow(operand2.IntValue); break;

                case Token.Log: res = PrimesBigInteger.Zero; break;

                case Token.Root: res = PrimesBigInteger.Zero; break;
                }

                operands.Push(PostProcess(res));
            }
            catch (Exception e)
            {
                ThrowException(e.Message);
            }
        }
Esempio n. 5
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. 6
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. 7
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. 8
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. 9
0
        private void DrawButtons()
        {
            double x1 = 0;
            double x2 = 8;

            if (m_Buttons.Count > 0)
            {
                x1 = (double)ControlHandler.ExecuteMethod(PaintArea, "GetLeft", new object[] { m_Buttons[0] });
                x2 = (double)ControlHandler.ExecuteMethod(PaintArea, "GetLeft", new object[] { m_Buttons[1] });
            }

            UIElementCollection children = ControlHandler.GetPropertyValue(PaintArea, "Children") as UIElementCollection;

            ControlHandler.ExecuteMethod(children, "Clear");
            m_Buttons.Clear();
            m_ButtonsDict.Clear();

            double width = (double)ControlHandler.GetPropertyValue(LineArea, "ActualWidth");
            double len   = width - (PADDINGLEFT + PADDINGRIGHT);

            if (len < 0)
            {
                len = 100;
            }
            m_UnitSize = len / (m_ButtonScale - 1);

            ControlHandler.ExecuteMethod(LineArea, "SetLeft", new object[] { numberline, PADDINGLEFT });
            ControlHandler.SetPropertyValue(numberline, "Width", len);

            double y = (double)ControlHandler.ExecuteMethod(LineArea, "GetTop", new object[] { numberline }) + numberline.Height / 2;

            int buttonsize = Math.Max(3, Math.Min(20, (int)(len / m_ButtonScale)));

            for (int i = 0; i < m_ButtonScale; i++)
            {
                double x = i * m_UnitSize + PADDINGLEFT;
                DrawNumberButton(m_Start.Add(PrimesBigInteger.ValueOf(i)), x, y, buttonsize, buttonsize);
            }

            if (m_Buttons != null && m_Buttons.Count > 0)
            {
                NumberButton nb = m_Buttons[m_Buttons.Count - 1];
                Canvas.SetLeft(pToNumber, Canvas.GetLeft(nb) - 6);
                lblCountPoints.Text = m_Buttons.Count.ToString();
                SetEdgeButtonColor();
            }
        }
Esempio n. 10
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;
        }
Esempio n. 11
0
        protected override void DoExecute()
        {
            FireOnStart();

            ControlHandler.SetPropertyValue(m_tbCalcInfo, "Visibility", Visibility.Visible);
            StringBuilder sb = new StringBuilder();

            var factors = (m_Factors != null) ? m_Factors : m_Value.Factorize();

            Dictionary <PrimesBigInteger, long> f    = new Dictionary <PrimesBigInteger, long>();
            List <PrimesBigInteger>             keys = factors.Keys.ToList();

            foreach (var key in keys)
            {
                f[key] = 0;
            }

            Dictionary <PrimesBigInteger, PrimesBigInteger> result = new Dictionary <PrimesBigInteger, PrimesBigInteger>();
            PrimesBigInteger sum = PrimesBigInteger.Zero;

            int i;

            do
            {
                PrimesBigInteger phi = PrimesBigInteger.Phi(f);
                result[PrimesBigInteger.Refactor(f)] = phi;
                sum = sum.Add(phi);
                for (i = keys.Count - 1; i >= 0; i--)
                {
                    f[keys[i]]++;
                    if (f[keys[i]] <= factors[keys[i]])
                    {
                        break;
                    }
                }
                for (int j = i + 1; j < keys.Count; j++)
                {
                    f[keys[j]] = 0;
                }
            }while (i >= 0);

            SetCalcInfo(string.Format(Primes.Resources.lang.WpfControls.Distribution.Distribution.numberline_eulerphisuminfo, m_Value, sum));

            List <PrimesBigInteger> philist = result.Keys.Select(k => k).ToList();

            philist.Sort(PrimesBigInteger.Compare);
            foreach (var k in philist)
            {
                m_Log.Info(string.Format(Primes.Resources.lang.WpfControls.Distribution.Distribution.numberline_eulerphisumlog, k, result[k]));
            }

            String s = String.Join(" + ", philist.Select(k => String.Format("φ({0})", k)));

            m_Log.Info(s + " = " + sum);

            FireOnStop();
        }
Esempio n. 12
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. 13
0
        private void btnForward_Click(object sender, RoutedEventArgs e)
        {
            PrimesBigInteger rows   = PrimesBigInteger.ValueOf(this.Rows);
            PrimesBigInteger amount = rows;

            if (sender == btnCompleteForward)
            {
                amount =
                    m_Limit.Subtract((numbergrid.Children[this.Rows + this.Columns - 2 + (this.Columns * this.Rows) - 1] as NumberButton).BINumber);
                amount = amount.Add(rows.Subtract(amount.Mod(rows)));
            }

            ScrollGrid(amount, false);
        }
Esempio n. 14
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. 15
0
 void m_Step4_FoundFactor(object o)
 {
     if (o != null && o.GetType() == typeof(PrimesBigInteger))
     {
         PrimesBigInteger value = o as PrimesBigInteger;
         if (!m_Factors.ContainsKey(value))
         {
             m_Factors.Add(value, PrimesBigInteger.Zero);
         }
         PrimesBigInteger tmp = m_Factors[value];
         m_Factors[value] = tmp.Add(PrimesBigInteger.One);
     }
     FireFoundFactorEvent(m_Factors.GetEnumerator());
 }
Esempio n. 16
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. 17
0
        public NumberlineControl()
        {
            InitializeComponent();

            m_Buttons     = new List <NumberButton>();
            markedNumbers = new List <NumberButton>();
            m_ButtonsDict = new Dictionary <PrimesBigInteger, NumberButton>();

            m_ButtonScale = 45.0;
            m_Start       = MIN;
            m_End         = m_Start.Add(PrimesBigInteger.ValueOf((long)m_ButtonScale - 1));

            iscTo.Execute       += new ExecuteSingleDelegate(iscTo_Execute);
            iscTo.KeyDown       += new ExecuteSingleDelegate(iscTo_Execute);
            iscFrom.Execute     += new ExecuteSingleDelegate(iscFrom_Execute);
            iscFrom.KeyDown     += new ExecuteSingleDelegate(iscFrom_Execute);
            iscFrom.OnInfoError += new MessageDelegate(iscFrom_OnInfoError);
            iscFrom.NoMargin     = true;
            iscTo.NoMargin       = true;

            iscFrom.SetBorderBrush(Brushes.Blue);
            iscTo.SetBorderBrush(Brushes.Violet);

            iscTo.OnInfoError           += new MessageDelegate(iscFrom_OnInfoError);
            iscTo.KeyDownNoValidation   += new MessageDelegate(iscTo_KeyDownNoValidation);
            iscFrom.KeyDownNoValidation += new MessageDelegate(iscTo_KeyDownNoValidation);
            IValidator <PrimesBigInteger>     validatefrom      = new BigIntegerMinValueValidator(null, MIN);
            InputValidator <PrimesBigInteger> inputvalidatefrom = new InputValidator <PrimesBigInteger>();

            inputvalidatefrom.DefaultValue = "2";
            inputvalidatefrom.Validator    = validatefrom;
            iscFrom.AddInputValidator(InputSingleControl.Free, inputvalidatefrom);
            SetInputValidator();

            this.FactorizationDone += new VoidDelegate(NumberlineControl_FactorizationDone);
            this.GoldbachDone      += new VoidDelegate(NumberlineControl_GoldbachDone);

            m_EulerPhi         = new EulerPhi(logEulerPhi, lblCalcEulerPhiInfo);
            m_EulerPhi.OnStop += new VoidDelegate(m_EulerPhi_OnStop);

            m_Tau         = new Tau(logTau, lblCalcTauInfo);
            m_Tau.OnStop += new VoidDelegate(m_Tau_OnStop);

            m_Rho         = new Rho(logRho, lblCalcRhoInfo);
            m_Rho.OnStop += new VoidDelegate(m_Rho_OnStop);

            m_DivSum         = new EulerPhiSum(logDivSum, lblCalcDividerSum);
            m_DivSum.OnStop += new VoidDelegate(m_DivSum_OnStop);
        }
Esempio n. 18
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));
        }
Esempio n. 19
0
        public PrimitivRootControl()
        {
            InitializeComponent();
            this.OnStart    += new VoidDelegate(PrimitivRootControl_OnStart);
            this.OnStop     += new VoidDelegate(PrimitivRootControl_OnStop);
            validator        = new BigIntegerMinValueMaxValueValidator(null, MIN, MAX);
            log.OverrideText = true;
            int mersenneexp = mersenneseed[new Random().Next(mersenneseed.Length - 1)];

            tbInput.Text  = PrimesBigInteger.Random(2).Add(PrimesBigInteger.Three).NextProbablePrime().ToString();
            tbInput.Text += ", 2^" + mersenneexp + "-1";
            PrimesBigInteger rangeval = PrimesBigInteger.Random(2).Add(PrimesBigInteger.Three);

            tbInput.Text += ", " + rangeval.ToString() + ":" + rangeval.Add(PrimesBigInteger.Ten).ToString();

            rndGenerate      = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
            m_JumpLockObject = new object();
        }
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
        private string MarkQuadrupletPrimes(PrimesBigInteger first)
        {
            List <int> diffs = new List <int> {
                0, 2, 6, 8
            };
            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]);
                }
            }

            return(string.Format(Distribution.numberline_isquadtrupletprime, l[0], l[1], l[2], l[3]));
        }
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 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. 25
0
 protected virtual void DoExecute()
 {
     if (Start != null)
     {
         Start();
     }
     while (m_From.CompareTo(m_To) <= 0)
     {
         PrimesBigInteger result = m_Function.Execute(m_From);
         if (FunctionResult != null)
         {
             FunctionResult(result, m_From);
         }
         m_From = m_From.Add(PrimesBigInteger.One);
     }
     if (Stop != null)
     {
         Stop();
     }
     Cancel();
 }
Esempio n. 26
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. 27
0
        protected override void DoExecute()
        {
            FireOnStart();

            ControlHandler.SetPropertyValue(m_tbCalcInfo, "Visibility", Visibility.Visible);

            List <PrimesBigInteger> divisors = (m_Factors != null) ? PrimesBigInteger.Divisors(m_Factors) : m_Value.Divisors();

            divisors.Sort(PrimesBigInteger.Compare);

            PrimesBigInteger sum = PrimesBigInteger.Zero;

            foreach (var d in divisors)
            {
                sum = sum.Add(d);
            }

            String s = String.Join(" + ", divisors.Select(i => i.ToString()).ToArray());

            m_Log.Info(s + " = " + sum);
            SetCalcInfo(string.Format(Primes.Resources.lang.WpfControls.Distribution.Distribution.numberline_rhoinfo, m_Value, sum));

            FireOnStop();
        }
Esempio n. 28
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. 29
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. 30
0
 void iscFrom_Execute(PrimesBigInteger value)
 {
     EnableInput();
     iscTo_Execute(value.Add(ButtonScaleMinusOne));
     MarkNumberWithOutThreads(m_Start);
 }