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); }
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, "|}")); }
public int[] FindCoordinates(Rational vector) { int len = vector.GetInvolvedPowerCount(); if (len > height) { return(null); } //if (width < basisSize + len) throw new Exception(""); int[] pows = vector.GetPrimePowers(); int[] v = new int[height]; Array.Copy(pows, 0, v, 0, len); // int[] result = new int[basisSize]; for (int row = 0; row < height; ++row) { // int col = leadCols[row]; int lead = col == -1 ? 0 : m[col, ro[row]]; // int b = 0; for (int i = 0; i < height; ++i) { b += v[i] * m[basisSize + i, ro[row]]; } // if (lead == 0) { if (b != 0) { return(null); } } else { if (b % lead != 0) { return(null); // non-integer coordinate } result[col] = b / lead; } } return(result); }
public RationalX[] FindRationalCoordinates(Rational vector) { //!!! seems fails if vector == 1/1 int len = vector.GetInvolvedPowerCount(); if (len > height) { return(null); } //if (width < basisSize + len) throw new Exception(""); int[] pows = vector.GetPrimePowers(); int[] v = new int[height]; Array.Copy(pows, 0, v, 0, len); // RationalX[] result = new RationalX[basisSize]; for (int row = 0; row < height; ++row) { // int col = leadCols[row]; int lead = col == -1 ? 0 : m[col, ro[row]]; // int b = 0; for (int i = 0; i < height; ++i) { b += v[i] * m[basisSize + i, ro[row]]; } // if (lead == 0) { if (b != 0) { return(null); // no solution } } else { result[col] = new RationalX(b, lead); } } return(result); }