Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

fast factorization of ratios of polynomials

I consider polynomials of the form $P=\prod_i (1-1/y_i)$, where each $y_i$ is a Laurent monomial with unit coefficient in variables $x_1,\ldots,x_k, q_1,q_2,q_3,m$.

I'm interested in taking ratios of the form $P_1 / (P_2 \prod_{n=1}^k x_n)$ of such polynoimals, and would like to know what the fastest way is to cancel common factors using sagemath.

An example, where numerator and denominator have already been factored (quickly) by sage:

   (q1*q2*x0 - x1)*(q1*q2*x0 - x2)*(q1*q2*x0 - x3)*(q1*q2*x0 - 1)*(q1*q3*x0 - x1)*(q1*q3*x0 - x2)*(q1*q3*x0 - x3)*(q1*q3*x0 - 1)*(q2*q3*x0 - x1)*(q2*q3*x0 - x2)*(q2*q3*x0 - x3)*(q1*q2*x1 - x0)*(q1*q2*x1 - x2)*(q1*q2*x1 - x3)*(q1*q2*x1 - 1)*(q1*q3*x1 - x0)*(q1*q3*x1 - x2)*(q1*q3*x1 - x3)*(q1*q3*x1 - 1)*(q2*q3*x1 - x0)*(q2*q3*x1 - x2)*(q2*q3*x1 - x3)*(q1*q2*x2 - x0)*(q1*q2*x2 - x1)*(q1*q2*x2 - x3)*(q1*q2*x2 - 1)*(q1*q3*x2 - x0)*(q1*q3*x2 - x1)*(q1*q3*x2 - x3)*(q1*q3*x2 - 1)*(q2*q3*x2 - x0)*(q2*q3*x2 - x1)*(q2*q3*x2 - x3)*(q1*q2*x3 - x0)*(q1*q2*x3 - x1)*(q1*q2*x3 - x2)*(q1*q2*x3 - 1)*(q1*q3*x3 - x0)*(q1*q3*x3 - x1)*(q1*q3*x3 - x2)*(q1*q3*x3 - 1)*(q2*q3*x3 - x0)*(q2*q3*x3 - x1)*(q2*q3*x3 - x2)*(q2*q3 - x0)*(q2*q3 - x1)*(q2*q3 - x2)*(q2*q3 - x3)*(m - x0)*(m - x1)*(m - x2)*(m - x3)*(x0 - x1)^2*(x0 - x2)^2*(x0 - x3)^2*(x1 - x2)^2*(x1 - x3)^2*(x2 - x3)^2/((q1*q2*q3*x0 - x1)*(q1*q2*q3*x0 - x2)*(q1*q2*q3*x0 - x3)*(q1*q2*q3*x0 - 1)*(q1*q2*q3*x1 - x0)*(q1*q2*q3*x1 - x2)*(q1*q2*q3*x1 - x3)*(q1*q2*q3*x1 - 1)*(q1*q2*q3*x2 - x0)*(q1*q2*q3*x2 - x1)*(q1*q2*q3*x2 - x3)*(q1*q2*q3*x2 - 1)*(q1*q2*q3*x3 - x0)*(q1*q2*q3*x3 - x1)*(q1*q2*q3*x3 - x2)*(q1*q2*q3*x3 - 1)*(q1*x0 - x1)*(q1*x0 - x2)*(q1*x0 - x3)*(q1*x0 - 1)*(q2*x0 - x1)*(q2*x0 - x2)*(q2*x0 - x3)*(q3*x0 - x1)*(q3*x0 - x2)*(q3*x0 - x3)*(q1*x1 - x0)*(q1*x1 - x2)*(q1*x1 - x3)*(q1*x1 - 1)*(q2*x1 - x0)*(q2*x1 - x2)*(q2*x1 - x3)*(q3*x1 - x0)*(q3*x1 - x2)*(q3*x1 - x3)*(q1*x2 - x0)*(q1*x2 - x1)*(q1*x2 - x3)*(q1*x2 - 1)*(q2*x2 - x0)*(q2*x2 - x1)*(q2*x2 - x3)*(q3*x2 - x0)*(q3*x2 - x1)*(q3*x2 - x3)*(q1*x3 - x0)*(q1*x3 - x1)*(q1*x3 - x2)*(q1*x3 - 1)*(q2*x3 - x0)*(q2*x3 - x1)*(q2*x3 - x2)*(q3*x3 - x0)*(q3*x3 - x1)*(q3*x3 - x2)*(q2 - x0)*(q2 - x1)*(q2 - x2)*(q2 - x3)*(q3 - x0)*(q3 - x1)*(q3 - x2)*(q3 - x3)*x0*x1*x2*x3)

If I try to factor() this, it takes forever, maybe it's using maxima? ideally, I'd like to use singular.

fast factorization of ratios of polynomials

I consider polynomials of the form $P=\prod_i (1-1/y_i)$, where each $y_i$ is a Laurent monomial with unit coefficient in variables $x_1,\ldots,x_k, q_1,q_2,q_3,m$.

I'm interested in taking ratios of the form $P_1 / (P_2 \prod_{n=1}^k x_n)$ of such polynoimals, polynomials, and would like to know what the fastest way is to cancel common factors using sagemath.

An example, where numerator and denominator have already been factored (quickly) by sage:

   (q1*q2*x0 - x1)*(q1*q2*x0 - x2)*(q1*q2*x0 - x3)*(q1*q2*x0 - 1)*(q1*q3*x0 - x1)*(q1*q3*x0 - x2)*(q1*q3*x0 - x3)*(q1*q3*x0 - 1)*(q2*q3*x0 - x1)*(q2*q3*x0 - x2)*(q2*q3*x0 - x3)*(q1*q2*x1 - x0)*(q1*q2*x1 - x2)*(q1*q2*x1 - x3)*(q1*q2*x1 - 1)*(q1*q3*x1 - x0)*(q1*q3*x1 - x2)*(q1*q3*x1 - x3)*(q1*q3*x1 - 1)*(q2*q3*x1 - x0)*(q2*q3*x1 - x2)*(q2*q3*x1 - x3)*(q1*q2*x2 - x0)*(q1*q2*x2 - x1)*(q1*q2*x2 - x3)*(q1*q2*x2 - 1)*(q1*q3*x2 - x0)*(q1*q3*x2 - x1)*(q1*q3*x2 - x3)*(q1*q3*x2 - 1)*(q2*q3*x2 - x0)*(q2*q3*x2 - x1)*(q2*q3*x2 - x3)*(q1*q2*x3 - x0)*(q1*q2*x3 - x1)*(q1*q2*x3 - x2)*(q1*q2*x3 - 1)*(q1*q3*x3 - x0)*(q1*q3*x3 - x1)*(q1*q3*x3 - x2)*(q1*q3*x3 - 1)*(q2*q3*x3 - x0)*(q2*q3*x3 - x1)*(q2*q3*x3 - x2)*(q2*q3 - x0)*(q2*q3 - x1)*(q2*q3 - x2)*(q2*q3 - x3)*(m - x0)*(m - x1)*(m - x2)*(m - x3)*(x0 - x1)^2*(x0 - x2)^2*(x0 - x3)^2*(x1 - x2)^2*(x1 - x3)^2*(x2 - x3)^2/((q1*q2*q3*x0 - x1)*(q1*q2*q3*x0 - x2)*(q1*q2*q3*x0 - x3)*(q1*q2*q3*x0 - 1)*(q1*q2*q3*x1 - x0)*(q1*q2*q3*x1 - x2)*(q1*q2*q3*x1 - x3)*(q1*q2*q3*x1 - 1)*(q1*q2*q3*x2 - x0)*(q1*q2*q3*x2 - x1)*(q1*q2*q3*x2 - x3)*(q1*q2*q3*x2 - 1)*(q1*q2*q3*x3 - x0)*(q1*q2*q3*x3 - x1)*(q1*q2*q3*x3 - x2)*(q1*q2*q3*x3 - 1)*(q1*x0 - x1)*(q1*x0 - x2)*(q1*x0 - x3)*(q1*x0 - 1)*(q2*x0 - x1)*(q2*x0 - x2)*(q2*x0 - x3)*(q3*x0 - x1)*(q3*x0 - x2)*(q3*x0 - x3)*(q1*x1 - x0)*(q1*x1 - x2)*(q1*x1 - x3)*(q1*x1 - 1)*(q2*x1 - x0)*(q2*x1 - x2)*(q2*x1 - x3)*(q3*x1 - x0)*(q3*x1 - x2)*(q3*x1 - x3)*(q1*x2 - x0)*(q1*x2 - x1)*(q1*x2 - x3)*(q1*x2 - 1)*(q2*x2 - x0)*(q2*x2 - x1)*(q2*x2 - x3)*(q3*x2 - x0)*(q3*x2 - x1)*(q3*x2 - x3)*(q1*x3 - x0)*(q1*x3 - x1)*(q1*x3 - x2)*(q1*x3 - 1)*(q2*x3 - x0)*(q2*x3 - x1)*(q2*x3 - x2)*(q3*x3 - x0)*(q3*x3 - x1)*(q3*x3 - x2)*(q2 - x0)*(q2 - x1)*(q2 - x2)*(q2 - x3)*(q3 - x0)*(q3 - x1)*(q3 - x2)*(q3 - x3)*x0*x1*x2*x3)

If I try to factor() this, it takes forever, maybe it's using maxima? ideally, I'd like to use singular.

fast factorization of ratios of polynomials

I consider polynomials of the form $P=\prod_i (1-1/y_i)$, where each $y_i$ is a Laurent monomial with unit coefficient in variables $x_1,\ldots,x_k, q_1,q_2,q_3,m$.

I'm interested in taking ratios of the form $P_1 / (P_2 \prod_{n=1}^k x_n)$ of such polynomials, and would like to know what the fastest way is to cancel common factors using sagemath.

An example, where numerator and denominator have already been factored (quickly) by sage:Let me write an explicit code example:

   (q1*q2*x0 - x1)*(q1*q2*x0 - x2)*(q1*q2*x0 - x3)*(q1*q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1*q2*q3*x3 - 1)*(q1*x0 - x1)*(q1*x0 - x2)*(q1*x0 - x3)*(q1*x0 - 1)*(q2*x0 - x1)*(q2*x0 - x2)*(q2*x0 - x3)*(q3*x0 - x1)*(q3*x0 - x2)*(q3*x0 - x3)*(q1*x1 - x0)*(q1*x1 - x2)*(q1*x1 - x3)*(q1*x1 - 1)*(q2*x1 - x0)*(q2*x1 - x2)*(q2*x1 - x3)*(q3*x1 - x0)*(q3*x1 - x2)*(q3*x1 - x3)*(q1*x2 - x0)*(q1*x2 - x1)*(q1*x2 - x3)*(q1*x2 - 1)*(q2*x2 - x0)*(q2*x2 - x1)*(q2*x2 - x3)*(q3*x2 - x0)*(q3*x2 - x1)*(q3*x2 - x3)*(q1*x3 - x0)*(q1*x3 - x1)*(q1*x3 - x2)*(q1*x3 - 1)*(q2*x3 - x0)*(q2*x3 - x1)*(q2*x3 - x2)*(q3*x3 - x0)*(q3*x3 - x1)*(q3*x3 - x2)*(q2 - x0)*(q2 - x1)*(q2 - x2)*(q2 - x3)*(q3 - x0)*(q3 - x1)*(q3 - x2)*(q3 - x3)*x0*x1*x2*x3)
def br(x):
    return 1-1/x

q1,q2,q3,m = var('q1,q2,q3,m')

def mex(q1,q2,q3,m):
    q4 = var('q4')
    N.<q1,q2,q3,q4> = PolynomialRing(ZZ, 4, order='neglex')
    k = 3
    K = 1 + q1 + q2
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    X = [var("x%d" % i) for i in range(k)]
    chim = prod([ br(X[j]/m) for j in range(k)])
    chix = prod([ br(X[j]) for j in range(k)])
    chiup = prod([ prod([ br(q1*q2*X[i]/X[j])*br(q1*q3*X[i]/X[j])*br(q2*q3*X[i]/X[j])*(br(X[i]/X[j]))^2 for i in range(k) if i > j]) for j in range(k)])
    chiups = prod([ prod([ br(X[i]/(X[j]*q1*q2))*br(X[i]/(X[j]*q1*q3))*br(X[i]/(X[j]*q2*q3)) for i in range(k) if i > j]) for j in range(k)])
    chido = prod([ prod([ br(q1*X[i]/X[j])*br(q2*X[i]/X[j])*br(q3*X[i]/X[j])*br(q1*q2*q3*X[i]/X[j]) for i in range(k) if i > j]) for j in range (k)])
    chidos = prod([ prod([ br(X[i]/(X[j]*q1))*br(X[i]/(X[j]*q2))*br(X[i]/(X[j]*q3))*br(X[i]/(X[j]*q1*q2*q3)) for i in range(k) if i > j]) for j in range (k)])
    dx = prod([ X[j] for j in range(k)])
    chinum = (chim*chiup*chiups).factor()
    chiden = (chix*chido*chidos*dx).factor()
    chi = chinum/chiden
    return chi.factor()

If instead of chi.factor(), I try return chi it is very fast. I suspect there's a better way (perhaps using singular), to factor() this, it takes forever, maybe it's using maxima? ideally, I'd like to use singular.factorize chi.

fast factorization of ratios of polynomials

I consider polynomials of the form $P=\prod_i (1-1/y_i)$, where each $y_i$ is a Laurent monomial with unit coefficient in variables $x_1,\ldots,x_k, q_1,q_2,q_3,m$.

I'm interested in taking ratios of the form $P_1 / (P_2 \prod_{n=1}^k x_n)$ of such polynomials, and would like to know what the fastest way is to cancel common factors using sagemath.

Let me write an explicit code example:

def br(x):
    return 1-1/x

q1,q2,q3,m = var('q1,q2,q3,m')

def mex(q1,q2,q3,m):
    q4 = var('q4')
    N.<q1,q2,q3,q4> = PolynomialRing(ZZ, 4, order='neglex')
    k = 3
    K = 1 + q1 + q2
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    X = [var("x%d" % i) for i in range(k)]
    chim = prod([ br(X[j]/m) for j in range(k)])
    chix = prod([ br(X[j]) for j in range(k)])
    chiup = prod([ prod([ br(q1*q2*X[i]/X[j])*br(q1*q3*X[i]/X[j])*br(q2*q3*X[i]/X[j])*(br(X[i]/X[j]))^2 for i in range(k) if i > j]) for j in range(k)])
    chiups = prod([ prod([ br(X[i]/(X[j]*q1*q2))*br(X[i]/(X[j]*q1*q3))*br(X[i]/(X[j]*q2*q3)) for i in range(k) if i > j]) for j in range(k)])
    chido = prod([ prod([ br(q1*X[i]/X[j])*br(q2*X[i]/X[j])*br(q3*X[i]/X[j])*br(q1*q2*q3*X[i]/X[j]) for i in range(k) if i > j]) for j in range (k)])
    chidos = prod([ prod([ br(X[i]/(X[j]*q1))*br(X[i]/(X[j]*q2))*br(X[i]/(X[j]*q3))*br(X[i]/(X[j]*q1*q2*q3)) for i in range(k) if i > j]) for j in range (k)])
    dx = prod([ X[j] for j in range(k)])
    chinum = (chim*chiup*chiups).factor()
    chiden = (chix*chido*chidos*dx).factor()
    chi = chinum/chiden
    return chi.factor()

If instead of chi.factor(), I return chi it is very fast. I suspect there's a better way (perhaps using singular), to factorize chi.

fast factorization of ratios of polynomials

I consider polynomials of the form $P=\prod_i (1-1/y_i)$, where each $y_i$ is a Laurent monomial with unit coefficient in variables $x_1,\ldots,x_k, q_1,q_2,q_3,m$.

I'm interested in taking ratios of the form $P_1 / (P_2 \prod_{n=1}^k x_n)$ of such polynomials, and would like to know what the fastest way is to cancel common factors using sagemath.

Let me write an explicit code example:

def br(x):
    return 1-1/x

q1,q2,q3,m = var('q1,q2,q3,m')

def mex(q1,q2,q3,m):
    q4 = var('q4')
    N.<q1,q2,q3,q4> = PolynomialRing(ZZ, 4, order='neglex')
    k = 3
    K = 1 + q1 + q2
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    X = [var("x%d" % i) for i in range(k)]
    chim = prod([ br(X[j]/m) for j in range(k)])
    chix = prod([ br(X[j]) for j in range(k)])
    chiup = prod([ prod([ br(q1*q2*X[i]/X[j])*br(q1*q3*X[i]/X[j])*br(q2*q3*X[i]/X[j])*(br(X[i]/X[j]))^2 for i in range(k) if i > j]) for j in range(k)])
    chiups = prod([ prod([ br(X[i]/(X[j]*q1*q2))*br(X[i]/(X[j]*q1*q3))*br(X[i]/(X[j]*q2*q3)) for i in range(k) if i > j]) for j in range(k)])
    chido = prod([ prod([ br(q1*X[i]/X[j])*br(q2*X[i]/X[j])*br(q3*X[i]/X[j])*br(q1*q2*q3*X[i]/X[j]) for i in range(k) if i > j]) for j in range (k)])
    chidos = prod([ prod([ br(X[i]/(X[j]*q1))*br(X[i]/(X[j]*q2))*br(X[i]/(X[j]*q3))*br(X[i]/(X[j]*q1*q2*q3)) for i in range(k) if i > j]) for j in range (k)])
    dx = prod([ X[j] for j in range(k)])
    chinum = (chim*chiup*chiups).factor()
(chim*chiup*chiups)
    chiden = (chix*chido*chidos*dx).factor()
(chix*chido*chidos*dx)
    chi = chinum/chiden
    # return chi.factor()
    for xi,rhoi in zip(X,rho):
         chi = (chi*(xi-rhoi)).factor().subs({xi: rhoi})
    return chi

If instead of chi.factor(), This currently works in the symbolic ring, but gets slow as soon as k,K grow a bit. I return chi was hoping that using singular (Laurent polyn ring, e.g.) would make it is very fast. I suspect there's a better way (perhaps using singular), to factorize chi.faster, but cannot make it such that everything happens there yet.

fast factorization of ratios of polynomials

I consider polynomials of the form $P=\prod_i (1-1/y_i)$, where each $y_i$ is a Laurent monomial with unit coefficient in variables $x_1,\ldots,x_k, q_1,q_2,q_3,m$.

I'm interested in taking ratios of the form $P_1 / (P_2 \prod_{n=1}^k x_n)$ of such polynomials, and would like to know what the fastest way is to cancel common factors using sagemath.

The final goal is to take residues at simple poles, so factorizations will happen.

Let me write an explicit a full code example:

def br(x):
    return 1-1/x

q1,q2,q3,m = var('q1,q2,q3,m')

def mex(q1,q2,q3,m):
    q4 = var('q4')
    N.<q1,q2,q3,q4> = PolynomialRing(ZZ, 4, order='neglex')
    k = 3
    K = 1 + q1 + q2
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    X = [var("x%d" % i) for i in range(k)]
    chim = prod([ br(X[j]/m) for j in range(k)])
    chix = prod([ br(X[j]) for j in range(k)])
    chiup = prod([ prod([ br(q1*q2*X[i]/X[j])*br(q1*q3*X[i]/X[j])*br(q2*q3*X[i]/X[j])*(br(X[i]/X[j]))^2 for i in range(k) if i > j]) for j in range(k)])
    chiups = prod([ prod([ br(X[i]/(X[j]*q1*q2))*br(X[i]/(X[j]*q1*q3))*br(X[i]/(X[j]*q2*q3)) for i in range(k) if i > j]) for j in range(k)])
    chido = prod([ prod([ br(q1*X[i]/X[j])*br(q2*X[i]/X[j])*br(q3*X[i]/X[j])*br(q1*q2*q3*X[i]/X[j]) for i in range(k) if i > j]) for j in range (k)])
    chidos = prod([ prod([ br(X[i]/(X[j]*q1))*br(X[i]/(X[j]*q2))*br(X[i]/(X[j]*q3))*br(X[i]/(X[j]*q1*q2*q3)) for i in range(k) if i > j]) for j in range (k)])
    dx = prod([ X[j] for j in range(k)])
    chinum = (chim*chiup*chiups)
    chiden = (chix*chido*chidos*dx)
    chi = chinum/chiden
    # return chi.factor()
    for xi,rhoi in zip(X,rho):
         chi = (chi*(xi-rhoi)).factor().subs({xi: rhoi})
    return chi

This currently works in the symbolic ring, but gets slow as soon as k,K grow a bit. I was hoping that using singular (Laurent polyn ring, e.g.) would make it faster, but cannot make it such that everything happens there yet.