Beispiel #1
0
        public static Pow[] GetNarrowPowers(this Rational r, Rational[] narrows = null)
        {
            if (narrows == null)
            {
                narrows = NarrowUtils.GetDefault(r.GetInvolvedPowerCount());
            }
            int len = r.GetInvolvedPowerCount();

            if (len > narrows.Length)
            {
                return(null);
            }
            Pow[] res = new Pow[len];
            r = r.Clone();
            for (int i = len - 1; i >= 0; --i)
            {
                Pow e = r.GetPrimePower(i);
                res[i] = e;
                if (e != 0)
                {
                    r /= narrows[i].Power(e);
                }
            }
            return(res);
        }
Beispiel #2
0
 public static string FormatNarrowPowers(this Rational r, Rational[] narrows = null)
 {
     if (narrows == null)
     {
         narrows = NarrowUtils.GetDefault(r.GetInvolvedPowerCount());
     }
     Pow[] pows = GetNarrowPowers(r, narrows);
     if (pows == null)
     {
         return(null);              //!!! where invalid narrowPrimes from?
     }
     return(Powers.ToString(pows, "|}"));
 }
Beispiel #3
0
        public void UpdateNarrows(Rational[] userNarrows = null)
        {
            _narrows = new Rational[_involvedPrimeCount];
            _error   = null;

            // set default narrows
            foreach (Rational item in _items)
            {
                Rational narrow = NarrowUtils.MakeNarrow(item, _baseItem);
                SetNarrow(narrow);
            }

            // set custom user narrows
            if (userNarrows != null)
            {
                var invalidNarrows = new List <Rational>();
                foreach (Rational narrow in userNarrows)
                {
                    if (narrow.IsDefault())
                    {
                        continue;
                    }
                    if (!IsInRange(narrow))
                    {
                        invalidNarrows.Add(narrow);
                    }
                    else
                    {
                        SetNarrow(narrow);
                    }
                }
                if (invalidNarrows.Count > 0)
                {
                    _error = "Narrows out of subgroup: " + String.Join(", ", invalidNarrows);
                }
            }

            // !!! he we should check if resulting narrows can solve each generated rational;
            //   currently we add all missing narrows (even if it's out of subgroup) instead.

            /*
             * for (int i = 0; i < _narrows.Length; ++i) {
             *  if (_narrows[i].IsDefault()) {
             *      _narrows[i] = NarrowUtils.MakeNarrow(Rational.Prime(i), _baseItem); // default narrow prime
             *  }
             * }
             */
#if DEBUG
            Debug.WriteLine("Narrows set: " + Rational.FormatRationals(_narrows));
#endif
        }
Beispiel #4
0
        private bool SetNarrow(Rational n)
        {
            // make high prime positive
            n = NarrowUtils.ValidateNarrow(n);
            if (n.IsDefault())
            {
                return(false);
            }
            // set narrow to the array - by high prime index
            int h = n.GetHighPrimeIndex();

            if (0 <= h && h < _narrows.Length)
            {
                _narrows[h] = n;
                return(true);
            }
            return(false);
        }