コード例 #1
0
        // Returns per-row errors
        public static string[] GetErrors(Tempered[] ts, Subgroup subgroup)
        {
            if (ts == null)
            {
                return(null);
            }

            string[] errors = new string[ts.Length];

            Rational[] indep     = new Rational[ts.Length]; // independent intervals
            int        indepSize = 0;

            for (int i = 0; i < ts.Length; ++i)
            {
                Rational r     = ts[i].rational;
                string   error = null;
                if (r.IsDefault())
                {
                    error = "Invalid rational";
                }
                else if (r.Equals(Rational.One))
                {
                    error = "1/1 can't be tempered";
                }
                else if (!subgroup.IsInRange(r))
                {
                    error = "Out of JI range";
                }
                else
                {
                    if (indepSize > 0)
                    {
                        var m      = new Vectors.Matrix(indep, -1, indepSize, makeDiagonal: true);
                        var coords = m.FindRationalCoordinates(r);
                        if (coords != null)
                        {
                            error = "";
                            for (int j = 0; j < coords.Length; ++j)
                            {
                                if (coords[j].sign != 0)
                                {
                                    error += String.Format(" * {0}^{1}", indep[j].FormatFraction(), coords[j].FormatFraction());
                                }
                            }
                            if (error.Length != 0)
                            {
                                error = "Dependend: " + error.Substring(2);
                            }
                        }
                    }
                    indep[indepSize++] = r;
                }
                errors[i] = error;
            }

            return(errors);
        }
コード例 #2
0
        // Filters out invalid and dependent vectors
        public static Tempered[] Validate(Tempered[] ts, Subgroup subgroup)
        {
            if (ts == null)
            {
                return(null);
            }

            var result = new List <Tempered>();

            Rational[] indep     = new Rational[ts.Length]; // independent intervals
            int        indepSize = 0;

            for (int i = 0; i < ts.Length; ++i)
            {
                Rational r = ts[i].rational;
                if (r.IsDefault())
                {
                    continue;
                }
                // skip if out of subgroup
                if (!subgroup.IsInRange(r))
                {
                    continue;
                }
                // skip if dependend
                if (indepSize > 0)
                {
                    var m = new Matrix(indep, -1, indepSize, makeDiagonal: true);
                    if (m.FindCoordinates(r) != null)
                    {
                        continue;
                    }
                }
                indep[indepSize++] = r;
                //
                result.Add(ts[i]);
            }

            return(result.Count == 0 ? null : result.ToArray());
        }