Пример #1
0
 /// <summary>
 /// Multiplies this <see cref="POS"/> by <paramref name="expression"/>
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public IExpression Multiply(IExpression expression)
 {
     // If the other expression as a POS
     if (expression is POS product)
     {
         // Check if the powers match
         return(new POS(Power == product.Power?
                        // If so, just concat lists of factors
                        Factors.Concat(product.Factors) :
                        // Otherwise invert the second expression
                        Factors.Concat(product.Factors.Select((x) => x.Reciprocal())), Power));
     }
     // If it's not simply create a new POS based on it and multiply it by the current instance
     else
     {
         return(Multiply(new POS(expression)));
     }
 }