private PolynomialTerm( double coefficient, ReadOnlyArray <IndeterminateExpression> indeterminates, string?signature, IndeterminateExpression greatestPowerExpression) { bool anyIndeterminates = indeterminates.Length > 0; bool hasSignature = signature != null; if (coefficient.NumericEquals(0) && anyIndeterminates) { throw new ArgumentException(nameof(indeterminates)); } _coefficient = coefficient; _indeterminates = indeterminates; if (anyIndeterminates == hasSignature) { _indeterminatesSignature = signature ?? string.Empty; GreatestPowerIndeterminate = greatestPowerExpression; } else { _indeterminatesSignature = anyIndeterminates ? string.Join(string.Empty, indeterminates.AsList()) : string.Empty; GreatestPowerIndeterminate = anyIndeterminates ? FindGreatestPowerIndeterminate(indeterminates.AsList()) : default; } }
public static IFinitaryOperation <double> GetOperation( this IndeterminateExpression operation, params PolynomialTerm[] variables) { return(new PolynomialFinitaryOperation( variables: variables, valueCalculation: x => operation.Value(x))); }
public static PolynomialTerm Cos(PolynomialTerm name) { if (name.IsConstant) { return(NumberMath.RoundedCos((double)name)); } else { return(IndeterminateExpression.Cos((char)name)); } }
private static IndeterminateExpression FindGreatestPowerIndeterminate(IEnumerable <IndeterminateExpression> indeterminates) { IndeterminateExpression greatestPower = default; foreach (var kv in indeterminates) { if (kv.Power > greatestPower.Power) { greatestPower = kv; } } return(greatestPower); }
private PolynomialTerm(IndeterminateExpression term) { _coefficient = 1; if (term.IsOne) { _indeterminates = default; _indeterminatesSignature = string.Empty; GreatestPowerIndeterminate = default; } else { _indeterminates = new[] { term }; _indeterminatesSignature = _indeterminates.AsList().Single().ToString(); GreatestPowerIndeterminate = term; } }
// * public static PolynomialTerm operator *(PolynomialTerm a, PolynomialTerm b) { double coefficient = a._coefficient * b._coefficient; if (coefficient.NumericEquals(0)) { return(0); } else if (a.IsConstant) { return(new PolynomialTerm(coefficient, b)); } else if (b.IsConstant) { return(new PolynomialTerm(coefficient, a)); } else { return(new PolynomialTerm( coefficient: coefficient, indeterminates: IndeterminateExpression.Multiply(a._indeterminates.AsList(), b._indeterminates.AsList()))); } }