public static MathObject ExpandProduct(this MathObject r, MathObject s) { if (r is Sum) { var f = (r as Sum).elts[0]; return f.ExpandProduct(s) + (r - f).ExpandProduct(s); } if (s is Sum) return s.ExpandProduct(r); return r * s; }
public static MathObject ExpandProduct(this MathObject r, MathObject s) { while (true) { if (r is Sum) { MathObject f = ((Sum)r).elts[0]; return(f.ExpandProduct(s) + (r - f).ExpandProduct(s)); } if (s is Sum) { var r1 = r; r = s; s = r1; continue; } return(r * s); } }