package misc;

public class Differentiator {
	static public PolyFunction differentiate(PolyFunction f) {
		PolyFunction a = new PolyFunction();
		
		for (int i = 0, size = f.getMaxGrade(); i <= size; i++) {
			if (!f.hasKoeff(i)) {
				continue;
			}
			if (i == 0) {
				// x^0 => 0
				continue;
			}
			a.setKoeff(i-1, i * f.getKoeff(i));
		}
		
		return a;
	}
}

@@ -8,16 +8,45 @@
  misc;%0A%0A
+import java.util.Map.Entry;%0A%0A
 public c
@@ -180,113 +180,65 @@
 or (
-int i = 0, size = f.getMaxGrade(); i %3C= size; i++) %7B%0A%09%09%09if (!f.hasKoeff(i)) %7B%0A%09%09%09%09continue;%0A%09%09%09%7D%0A%09%09%09if (i
+Entry%3CInteger, Double%3E entry : f) %7B%0A%09%09%09if (entry.getKey()
  == 
@@ -295,29 +295,58 @@
 eff(
-i-1, i * f.getKoeff(i
+entry.getKey()-1, entry.getKey() * entry.getValue(
 ));%0A

use iteration in differentiator