/** * Calculates the Sturm chain to a given polynomial * * @param function * the polynomial function * @return the Sturm chain of <code>function</code> as array */ public static Polynomial[] calculateSturm(Polynomial function) { LinkedList <Polynomial> sturm = new LinkedList <Polynomial>(); // add the original function and its derivation sturm.AddFirst(function); sturm.AddFirst(function.diff()); // iteratively perform polynomial divison while (sturm.First.Value.degree() > 0) { sturm.AddFirst(sturm.First.Next.Value.mod(sturm.First.Value).multiply(-1)); } // convert the list to an array for efficiency purposes Polynomial[] result = new Polynomial4[sturm.Count]; int i = 0; foreach (Polynomial poly in sturm) { result[i] = poly; i++; } return(result); }
// Actually a degree4-result is sufficient (and we want to make our users // benefit from this fact, so we define a Polynomial4-mod-method)... public Polynomial4 mod(Polynomial4 other) { return(new Polynomial4(mod(toArray(), degree(), other.toArray(), other .degree()))); }