Esempio n. 1
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. 2
0
        private void DoFactorize(object o)
        {
            if (o == null)
            {
                return;
            }

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

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

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

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

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