public override string ToString() { var result = new List <string>(); if (!Coefficient.Equals(NumberDecimal.One)) { result.Add(Coefficient.ToString()); } result.AddRange(Variables.Select(a => a.ToString())); result.AddRange(Others.Select(a => "(" + a.ToString() + ")")); return(string.Join("*", result)); }
public TermExpression(IValue coefficient, VariablePowExpression[] variablePows, VariableExpression[] variables, params IExpression[] others) { Coefficient = coefficient ?? new NumberDecimal(1, 0); if (Coefficient.Equals(NumberDecimal.Zero)) { return; } var variablesR = TermExpression.Multiply(variablePows, variables?.Select(a => (VariablePowExpression)a))?.ToList(); var othersR = new List <IExpression>(); if (others != null) { var result = new TermExpression(others); Coefficient = Coefficient.Multiply(result.Coefficient); variablesR.AddRange(result.Variables); othersR.AddRange(result.Others); } Variables = Unify(variablesR); Others = othersR.ToArray(); }