public Rational GetNarrowParent(Rational r) { int lastLevel = r.GetHighPrimeIndex(); if (lastLevel >= _involvedPrimeCount) { return(default(Rational)); } if (lastLevel <= _basePrimeIndex) { return(default(Rational)); // We don't draw lines between base intervals (e.g. 1/2 - 1 - 2 - 4). } // Rational step = _narrows[lastLevel]; // last level step if (step.IsDefault()) { return(default(Rational)); //!!! exception ? } int lastPower = r.GetPrimePower(lastLevel); // last level coordinate if (lastPower > 0) { return(r / step); } else { return(r * step); } }
private void UpdateRange() { _baseItem = default(Rational); _basePrimeIndex = 0; _involvedPrimeCount = 0; // int maxIndex = 0; int minIndex = int.MaxValue; // foreach (Rational r in _items) { int i = r.GetHighPrimeIndex(); if (maxIndex < i) { maxIndex = i; } if (minIndex > i) { minIndex = i; _baseItem = r; } } // _involvedPrimeCount = maxIndex + 1; _basePrimeIndex = _baseItem.GetHighPrimeIndex(); }
public static Rational MakeNarrow(Rational r, Rational b) { if (r.GetHighPrimeIndex() == b.GetHighPrimeIndex()) { return(r); // can't narrow on same prime level } double r_ = r.ToDouble(); double b_ = b.ToDouble(); double l = Math.Log(r_, b_); // e.g. 1.58 for {3, 2} Pow e = (Pow)(l + 0.25); // something between Floor and Round r /= b.Power(e); return(r); }
public static Rational ValidateNarrow(Rational n) { if (n.IsDefault()) { return(n); // invalid } int h = n.GetHighPrimeIndex(); if (h == -1) { return(default(Rational)); // "1" can't be a narrow } if (n.GetPrimePower(h) < 0) // max prime should be in nominator { n = Rational.One / n; } return(n); }
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); }
public static Rational MakeNarrow(Rational r, int basePrimeIndex) { if (r.GetHighPrimeIndex() <= basePrimeIndex) { return(r); // can't narrow } r = ValidateNarrow(r); // double rr = r.ToDouble(); if (rr < 1.0) { return(r); // e.g. for 5/6 - doubtful !!! } int b = Utils.GetPrime(basePrimeIndex); // base prime: 2, 3,.. double l = Math.Log(rr - 1.0, b); Pow e = (Pow)Math.Round(l); Long d = Utils.Pow(b, e); r /= d; return(r); }