+ return lcmcoeff(e, _num1());
+}
+
+/** Bring polynomial from Q[X] to Z[X] by multiplying in the previously
+ * determined LCM of the coefficient's denominators.
+ *
+ * @param e multivariate polynomial (need not be expanded)
+ * @param lcm LCM to multiply in */
+
+static ex multiply_lcm(const ex &e, const numeric &lcm)
+{
+ if (is_ex_exactly_of_type(e, mul)) {
+ ex c = _ex1();
+ numeric lcm_accum = _num1();
+ for (unsigned i=0; i<e.nops(); i++) {
+ numeric op_lcm = lcmcoeff(e.op(i), _num1());
+ c *= multiply_lcm(e.op(i), op_lcm);
+ lcm_accum *= op_lcm;
+ }
+ c *= lcm / lcm_accum;
+ return c;
+ } else if (is_ex_exactly_of_type(e, add)) {
+ ex c = _ex0();
+ for (unsigned i=0; i<e.nops(); i++)
+ c += multiply_lcm(e.op(i), lcm);
+ return c;
+ } else if (is_ex_exactly_of_type(e, power)) {
+ return pow(multiply_lcm(e.op(0), lcm.power(ex_to_numeric(e.op(1)).inverse())), e.op(1));
+ } else
+ return e * lcm;