Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = {}

def br(x):
    r = 1-1/x
    for t,s in mysubs.items():
        if r.subs({t:s})==0:            # assume that this happens only in denominators
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew2():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='degrevlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]

    global mysubs
    mysubs = dict( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(mysubs)
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx)
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = {}

def br(x):
    r = 1-1/x
    for t,s in mysubs.items():
        if r.subs({t:s})==0:            # assume that this happens only in denominators
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew2():
measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='degrevlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]

    global mysubs
    mysubs = dict( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(mysubs)
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx)
dx
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = {}

def br(x):
    r = 1-1/x
    for t,s in mysubs.items():
        if r.subs({t:s})==0:            # assume that this happens only in denominators
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='degrevlex')
order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]

    global mysubs
    mysubs = dict( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(mysubs)
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = {}

def br(x):
    r = 1-1/x
    for t,s in mysubs.items():
mysubs:
        if r.subs({t:s})==0:            # assume that this happens only in denominators
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
order='degrevlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]

    global mysubs
    mysubs = dict( list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(mysubs)
).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = {}

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        if r.subs({t:s})==0:            # assume that this happens only in denominators
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='degrevlex')
order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = {}

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        if r.subs({t:s})==0:     # assume that this happens only in denominators
the denominator of chi
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = {}
[]

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        if r.subs({t:s})==0:    # assume that this happens only in the denominator of chi
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    rho.reverse()

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = []
poles = set()

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        if r.subs({t:s})==0:    # assume that this happens only in the denominator of chi
            assert t not in poles    # to make sure each pole is processed only ones
            poles.add(t)
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    rho.reverse()

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden
    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = []
poles = set()

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        if r.subs({t:s})==0:    # assume that this happens only in the denominator of chi
            assert t not in poles    # to make sure each pole is processed only ones
            poles.add(t)
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    rho.reverse()

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden

    assert poles == set(X)      # checking that there was one pole for each variable X[i]

    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = []
poles = set()

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        if r.subs({t:s})==0:    # assume that this happens only in the denominator of chi
            assert t not in poles    # to make sure each pole is processed only ones
once
            poles.add(t)
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    rho.reverse()

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden

    assert poles == set(X)      # checking that there was one pole for each variable X[i]

    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = []
poles = set()

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        if r.subs({t:s})==0:    # assume that this happens only in the denominator of chi
            assert t not in poles    # to make sure each pole is processed only once
            poles.add(t)
while r.subs({t:s})==0:
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    rho.reverse()

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum / chiden

    assert poles == set(X)      # checking that there was one pole for each variable X[i]

    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = []

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        while r.subs({t:s})==0:
            r = r.derivative(t)
        r = r.subs({t:s})
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    F = R.fraction_field()
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    rho.reverse()

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = chinum F(chinum) / chiden
F(chiden)

    return chi.factor()

You can try to perform substitution and cancellation of simple poles directly in your br function, which significantly speed up things:

mysubs = []

def br(x):
    r = 1-1/x
    for t,s in mysubs:
        m = 0
        while r.subs({t:s})==0:
            r = r.derivative(t)
            m += 1
        r = r.subs({t:s})
r.subs({t:s}) / factorial(m)
    return r

def measNew():
    k = 3
    R = PolynomialRing(ZZ, ['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'], order='invlex')
    F = R.fraction_field()
    R.inject_variables()
    K = 1 + q2 + q2^2 + q3 + q4
    X = R.gens()[:k]
    rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.monomials()]
    rho.reverse()

    global mysubs
    mysubs = list( zip(X,rho) )

    chix = prod( br(X[j]) for j in range(k) )
    chim = prod( br(X[j]/m) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) 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(j+1,k) ) for j in range (k) )
    dx = prod( X[j] for j in range(k) ).subs(dict(mysubs))
    chinum = chim * chiup * chiups
    chiden = chix * chido * chidos * dx
    chi = F(chinum) / F(chiden)

    return chi.factor()