- // Los nombres M, D y H los puso Rosita en clase, cambiar si se les
- // ocurren algunos mejores!
- // m = u1*v1
- // d = u2*v2
- // h = (u1+v1)*(u2+v2) = u1*u2+u1*v2+u2*v1+u2*v2
- num_type m = karastuba(u12.second, v12.second);
- num_type d = karastuba(u12.first, v12.first);
- num_type h = karastuba(u12.second + v12.second,
- u12.first + v12.first);
-
- // H-D-M = u1*u2+u1*v2+u2*v1+u2*v2 - u2*v2 - u1*v1 = u1*v2+u2*v1
- // u1*v1 << base^N + u1*v2+u2*v1 << base^N/2 + u2*v2
- num_type res;
- res = (m << chunk_size) + ((h - d - m) << (chunk_size / 2) ) + h;
+ /*
+ std::cout << "u:" << u12.first << " - " << u12.second << "\n";
+ std::cout << "v:" << v12.first << " - " << v12.second << "\n";
+ */
+
+ /* Aca esta la gracia de toda la cuestion:
+ * m = u1*v1
+ * d = u2*v2
+ * h = (u1+u2)*(v1+v2) = u1*u2+u1*v2+u2*v1+u2*v2
+ *
+ * h - d - m = u1*v2+u2*v1
+ * u1*v1 << base^N + u1*v2+u2*v1 << base^(N/2) + u2*v2
+ * m << base^N + (h - d - m) << base^(N/2) + d
+ */
+ num_type m = karatsuba(u12.first, v12.first);
+ num_type d = karatsuba(u12.second, v12.second);
+
+ num_type sumfst = u12.first + u12.second;
+ num_type sumsnd = v12.first + v12.second;
+ num_type h = karatsuba(sumfst, sumsnd);
+
+ /*
+ fflush(stdout); fflush(stderr);
+ std::cout << "m: " << m << "\n";
+ std::cout << "d: " << d << "\n";
+ std::cout << "h: " << h << "\n";
+ fflush(stdout); fflush(stderr);
+ */
+
+ num_type res, tmp;
+
+ /* tmp = h - d - m */
+ normalize_length(h, d);
+ tmp = h - d;
+ normalize_length(tmp, m);
+ /*
+ std::cout << "t: " << tmp << "\n";
+ std::cout << "m: " << m << "\n";
+ */
+ tmp = tmp - m;
+ //std::cout << "t: " << tmp << "\n";
+
+ /* Resultado final */
+ res = d << chunk_size;
+ res += tmp << (chunk_size / 2);
+ res += m;