public Operand Simplify(char c) { if (Simplifying.Contains(c)) { Simplifying.Clear(); System.Diagnostics.Debug.WriteLine("Warning: circular dependency detected, " + c + " depends on itself"); } else if (Knowns.ContainsKey(c)) { HasExactForm = true; if (n == Numbers.Decimal) { return(os.Simplify(Knowns[c])); } } else { Unknowns.Add(c); if (Subsitutions != null && Subsitutions.ContainsKey(c) && Subsitutions[c] != null) { Simplifying.Add(c); Operand ans = os.Simplify(Subsitutions[c]); if (Simplifying.Count != 0) { Simplifying.Remove(c); return(ans); } } } return(new Term(c)); }
public Operand Simplify(TrigFunction tf) { Operand o = null; double constant; bool skip = tf.Operands[0].IsConstant(out constant); if (!skip) { o = Format.Simplify(tf.Operands[0]); } if (skip || o.IsConstant(out constant)) { double temp = System.Math.Round(tf.Operation(constant, Units), 14); ValidateAnswer(temp); HasTrig = true; return(temp); } else { return(new Term(new TrigFunction(tf.Name, o, tf.Operation))); } }
public Operand Simplify(Term t) { Print.Log("simplifying " + t); Term b = new Term(1); b.coefficient[0] = t.coefficient[0]; b.coefficient[1] = t.coefficient[1]; Operand ans = b; foreach (Pair pair in t.members.KeyValuePairs()) { Operand o = Simplify(pair.Key as dynamic); o.Exponentiate(os.Simplify(pair.Value)); ans.Multiply(o); } Term a = ans.TermForm; bool wholeCoefficients = a.coefficient[0].IsInt() && a.coefficient[1].IsInt(); if (wholeCoefficients && a.coefficient[1] != 1) { hasExactForm = true; } //Simplify fractions if (numbers == Numbers.Decimal || !wholeCoefficients) { double d = a.coefficient[1]; a.coefficient[1] = 1; a.Numerator = a.coefficient[0] / d; } Print.Log("simplified " + t + " to " + ans); return(ans); }
public Operand Simplify(Function f) { double[] inputs = new double[f.Operands.Length]; for (int i = 0; f.Operands[i].IsConstant(out inputs[i]) || Format.Simplify(f.Operands[i]).IsConstant(out inputs[i]); i++) { if (i == inputs.Length - 1) { return(f.Operation(inputs)); } } return(new Term(new Function(f.Name, f.Operands))); }