Ejemplo n.º 1
0
        /// <summary>
        /// Calculates unary expressions and pushes the result into the operands stack
        /// </summary>
        /// <param name="op">Unary operator</param>
        /// <param name="operand">Operand</param>
        private void Calculate(string op, PrimesBigInteger operand)
        {
            PrimesBigInteger res = PrimesBigInteger.One;

            try
            {
                switch (op)
                {
                case Token.UnaryMinus: res = operand.Multiply(PrimesBigInteger.NegativeOne); break;

                //case Token.Abs:        res = Math.Abs(operand); break;
                //case Token.ACosine:    res = Math.Acos(operand); break;
                //case Token.ASine:      res = Math.Asin(operand); break;
                //case Token.ATangent:   res = Math.Atan(operand); break;
                //case Token.Cosine:     res = Math.Cos(operand); break;
                //case Token.Ln:         res = Math.Log(operand); break;
                //case Token.Log10:      res = Math.Log10(operand); break;
                //case Token.Sine:       res = Math.Sin(operand); break;
                case Token.Sqrt: res = operand.SquareRoot(); break;
                    //case Token.Tangent:    res = Math.Tan(operand); break;
                    //case Token.Exp:        res = Math.Exp(operand); break;
                    //case Token.Factorial:  for (int i = 2; i <= (int)operand; res *= i++) ;
                    //break;
                }

                operands.Push(PostProcess(res));
            }
            catch (Exception e)
            {
                ThrowException(e.Message);
            }
        }
Ejemplo n.º 2
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.Multiply(PrimesBigInteger.Two).CompareTo(from) <= 0)
                {
                    if (from.Mod(d).Equals(PrimesBigInteger.Zero))
                    {
                        if (sbMessage.Length > 1)
                        {
                            sbMessage.Append(", ");
                        }
                        sbMessage.Append(d.ToString());

                        FireOnMessage(this, from, sbMessage.ToString());
                    }
                    d = d.Add(PrimesBigInteger.One);
                }
                sbMessage.Append(", " + from.ToString() + "]");
                FireOnMessage(this, from, sbMessage.ToString());
                from = from.Add(PrimesBigInteger.One);
            }

            FireOnStop();
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public virtual PrimesBigInteger Execute(PrimesBigInteger input)
        {
            PrimesBigInteger a = (m_list[A] as PolynomFactor).Value;
            PrimesBigInteger b = (m_list[B] as PolynomFactor).Value;
            PrimesBigInteger c = (m_list[C] as PolynomFactor).Value;

            return((input.Pow(2).Multiply(a).Add(b.Multiply(input))).Add(c));
        }
Ejemplo n.º 5
0
        protected override void DoExecute()
        {
            FireOnStart();

            try
            {
                PrimesBigInteger modulus = m_SecondParameter;

                PrimesBigInteger from = m_From;

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

            FireOnStop();
        }
Ejemplo n.º 6
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;
        }
        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);
        }
Ejemplo n.º 8
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;
            }
        }