// IHarmonicity public double GetDistance(Rational r) { double d = 0.0; int[] pows = r.GetPrimePowers(); for (int i = 0; i < pows.Length; ++i) { int e = pows[i]; int p = Utils.GetPrime(i); d += e * e * Math.Pow(p, _exp); } return(d); }
public override double GetDistance(Rational r) { double d = 0.0; int[] pows = r.GetPrimePowers(); for (int i = 0; i < pows.Length; ++i) { int e = pows[i]; if (e != 0) { int p = Utils.GetPrime(i); d += Math.Abs(e) * 2.0 * (p - 1) * (p - 1) / p; } } return(d); }
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 override double GetDistance(Rational r) { double d = 1.0; int[] pows = r.GetPrimePowers(); for (int i = 0; i < pows.Length; ++i) { int e = pows[i]; if (e != 0) { int p = Utils.GetPrime(i); d += (double)Math.Abs(e) // * Math.Exp(-e * 0.0001) // make a bit non-commutative to fix the order (avoiding blinking on count increase) - seems needed only if use "overage" in GridDrawer.GenerateItems // / (p-1); -- backward.. * (p - 1); } } return(d); }
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); }
public static int[] FindCoordinates(Rational[] basis, Rational vector, int vectorLength) { int basisSize = basis.Length; // get prime powers int[][] b = new int[basisSize][]; for (int i = 0; i < basisSize; ++i) { b[i] = basis[i].GetPrimePowers(); } int[] v = vector.GetPrimePowers(); // Matrix matrix = new Matrix(b, v, vectorLength); int[] coordinates = matrix.FindCoordinates(); #if DEBUG // check result if (coordinates != null) { Rational r = Rational.One; for (int i = 0; i < coordinates.Length; ++i) { r *= basis[i].Power(coordinates[i]); } if (!r.Equals(vector)) { throw new Exception( String.Format("FindCoordinates failed: {0} != {1}", r, vector) ); } } #endif return(coordinates); }