public static Polynomial operator *(Polynomial polyA, Polynomial polyB) { Polynomial result = new Polynomial(); for (int i = 0; i < polyA.elements.Count; i++) for (int j = 0; j < polyB.elements.Count; j++) result.AddElement(polyA.elements.Keys[i] + polyB.elements.Keys[j], polyA.elements.Values[i]*polyB.elements.Values[j]); return result; }
public static Polynomial operator -(Polynomial polyA, Polynomial polyB) { Polynomial result = new Polynomial(); for (int i = 0; i < polyA.elements.Count; i++) result.AddElement(polyA.elements.Keys[i], polyA.elements.Values[i]); for (int i = 0; i < polyB.elements.Count; i++) { result.AddElement(polyB.elements.Keys[i], -polyB.elements.Values[i]); if (result.elements[polyB.elements.Keys[i]] == 0) // check if afther operation coefficient is 0 result.elements.Remove(polyB.elements.Keys[i]); // for example it's useless to store 0x^5 } return result; }