Skip to content

Instantly share code, notes, and snippets.

@cswiercz
Created February 23, 2018 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cswiercz/a975f80f9d09cb224960fd6bd15abd86 to your computer and use it in GitHub Desktop.
Save cswiercz/a975f80f9d09cb224960fd6bd15abd86 to your computer and use it in GitHub Desktop.
mnuk_conditions() Fraction Field Timing Test
# coding: utf-8
# In[1]:
R = QQbar['x,y']
x,y = R.gens()
g1 = x^4 + x^2*y^2 + (-2)*x^2*y - x*y^2 + y^2
g2 = -x^7 + 2*x^3*y + y^3
g = g1
d = g.total_degree()
#
# construct generalized adjoint polynomial
#
cvars = ['c_%d_%d'%(i,j) for i in range(d-2) for j in range(d-2)]
vars = list(R.variable_names()) + cvars
C = PolynomialRing(QQbar, cvars)
S = PolynomialRing(C, [x,y])
T = PolynomialRing(QQbar, vars)
c = S.base_ring().gens()
x,y = S(x),S(y)
P = sum(c[j+(d-2)*i] * x**i * y**j
for i in range(d-2) for j in range(d-2)
if i+j <= d-3)
#
# construct intergral basis element
#
b = (x^2*y - x*y + y)/x^2
print(g)
print(P)
print(b)
# In[2]:
generic_adjoint = P
R = g.parent()
S = generic_adjoint.parent()
B = S.base_ring()
c = B.gens()
T = QQbar[R.variable_names() + B.variable_names()]
print(S)
print(B)
print(T)
# In[3]:
B = PolynomialRing(QQbar, [R.variable_names()[0]] + list(B.variable_names()))
print(B)
# In[4]:
def method1():
Q = B.fraction_field()[R.variable_names()[1]]
u, v = map(Q, R.gens())
numer = b.numerator()
denom = b.denominator()
expr = numer(u,v) * generic_adjoint(u,v)
modulus = g(u,v)
r_reduced_mod_g = expr % modulus
return r_reduced_mod_g
def method2():
Q = B[R.variable_names()[1]]
u, v = map(Q, R.gens())
numer = b.numerator()
denom = b.denominator()
expr = numer(u,v) * generic_adjoint(u,v)
modulus = g(u,v)
r_reduced_mod_g = expr.change_ring(B.fraction_field()) % modulus
return r_reduced_mod_g
timeit('method1()')
timeit('method2()')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment