public Expression Factor() { // Check if there is a simple factor of x. if (this[0].EqualsZero()) { return(Product.New(variable, new Polynomial(Coefficients.Where(i => i.Key != 0).ToDictionary(i => i.Key - 1, i => i.Value), variable).Factor()).Evaluate()); } DefaultDictionary <Expression, int> factors = new DefaultDictionary <Expression, int>(0); switch (Degree) { //case 2: // Expression a = this[2]; // Expression b = this[1]; // Expression c = this[0]; // // D = b^2 - 4*a*c // Expression D = Add.New(Multiply.New(b, b), Multiply.New(-4, a, c)); // factors[Binary.Divide(Add.New(Unary.Negate(b), Call.Sqrt(D)), Multiply.New(2, a))] += 1; // factors[Binary.Divide(Add.New(Unary.Negate(b), Call.Sqrt(D)), Multiply.New(2, a))] += 1; // break; default: return(this); } // Assemble expression from factors. //return Multiply.New(factors.Select(i => Power.New(Binary.Subtract(x, i.Key), i.Value))); }