public Polynomial(IEnumerable <Summand> summands) { if (summands == null) { throw new ArgumentNullException(nameof(summands)); } foreach (var summand in summands) { Summands.Add(summand); } }
/// <summary> /// Adds the <paramref name="expression"/> to this <see cref="SOP"/> /// </summary> /// <param name="expression"></param> /// <returns></returns> public IExpression Add(IExpression expression) { // If the other expression is an SOP if (expression is SOP sum) { // Check if the signs match return(new SOP(Sign == sum.Sign ? // If so, just concat lists of summands Summands.Concat(sum.Summands) : // Otherwise negate the second expression Summands.Concat(sum.Summands.Select((x) => x.Negation())), Sign)); } // If it's not simply create a new SOP based on it and add it to the current instance else { return(Add(new SOP(expression))); } }