Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks for pseudo remainder method #89

Merged
merged 19 commits into from
Jul 14, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 102 additions & 4 deletions benchmarks/polys.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,115 @@
import sympy
from sympy import symbols, prod
from sympy.polys import ZZ, Poly


class TimePolyManyGens:
"""Time using a Poly with many generators"""

params = [1, 10, 100, 500]

def setup(self, n):
self.xs = sympy.symbols('x:{}'.format(n))
self.xs = symbols('x:{}'.format(n))
self.x = self.xs[n // 2]
self.px = sympy.Poly(self.x, self.xs)
self.px = Poly(self.x, self.xs)

def time_create_poly(self, n):
sympy.Poly(self.x, self.xs)
Poly(self.x, self.xs)

def time_is_linear(self, n):
self.px.is_linear


class TimePolyprem:
1e9abhi1e10 marked this conversation as resolved.
Show resolved Hide resolved
"""Benchmark for the prem method"""

params = [(1,), (5,), (10,), (15,)]

def setup(self, size):
self.x, self.y, self.y1, self.y2, self.y3, self.y4, self.y5, self.y6, self.y7, self.y8, self.y9, self.y10 = symbols("x, y, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10")
self.y = [self.y1, self.y2, self.y3, self.y4, self.y5, self.y6, self.y7, self.y8, self.y9, self.y10]
1e9abhi1e10 marked this conversation as resolved.
Show resolved Hide resolved
self.values = {}
self.size = size
self.generate_poly_case1()
self.generate_poly_case2()
self.generate_poly_case3()
self.generate_poly_case4()

def generate_poly_case1(self):
# Linearly dense quartic inputs with quadratic GCDs.
n = self.size
D = (1 + self.x + sum(self.y[:n])) ** 2
self.f = D * (-2 + self.x - sum(self.y[:n])) ** 2
self.g = D * (2 + self.x + sum(self.y[:n])) ** 2
1e9abhi1e10 marked this conversation as resolved.
Show resolved Hide resolved

def time_prem_case1(self):
self.values['prem_case1'] = prem(self.f, self.g, self.x)

def time_Polyprem_case1(self):
n = self.size
fp, gp = Poly(self.f, self.x, *(self.y)[:n]), Poly(self.g, self.x, *(self.y)[:n])
self.values['Polyprem_case1'] = fp.prem(gp)

def time_PolyElement_prem_case1(self):
self.R = ZZ[self.x, self.y1, self.y2, self.y3, self.y4, self.y5, self.y6, self.y7, self.y8, self.y9, self.y10]
fpe, gpe = self.R.from_sympy(self.f), self.R.from_sympy(self.g)
self.values['PolyElement_prem_case1'] = fpe.prem(gpe)
1e9abhi1e10 marked this conversation as resolved.
Show resolved Hide resolved

def generate_poly_case2(self):
# Sparse GCD and inputs where degree are proportional to the number of variables.
n = self.size
D = 1 + self.x ** (n + 1) + sum([self.y[i] ** (n + 1) for i in range(n)])
self.f = D * (-2 + self.x ** (n + 1) + sum([self.y[i] ** (n + 1) for i in range(n)]))
self.g = D * (2 + self.x ** (n + 1) + sum([self.y[i] ** (n + 1) for i in range(n)]))

def time_prem_case2(self):
self.values['prem_case2'] = prem(self.f, self.g, self.x)

def time_Polyprem_case2(self):
n = self.size
fp, gp = Poly(self.f, self.x, *(self.y)[:n]), Poly(self.g, self.x, *(self.y)[:n])
self.values['Polyprem_case2'] = fp.prem(gp)

def time_PolyElement_prem_case2(self):
self.R = ZZ[self.x, self.y1, self.y2, self.y3, self.y4, self.y5, self.y6, self.y7, self.y8, self.y9, self.y10]
fpe, gpe = self.R.from_sympy(self.f), self.R.from_sympy(self.g)
self.values['PolyElement_prem_case2'] = fpe.prem(gpe)

def generate_poly_case3(self):
# Quadratic non-monic GCD, F and G have other quadratic factors.
n = self.size
D = 1 + self.x**2 * self.y[0]**2 + sum([self.y[i]**2 for i in range(1, n)])
self.f = D * (-1 + self.x**2 - self.y[0]**2 + sum([self.y[i]**2 for i in range(1, n)]))
self.g = D * (2 + self.x * self.y[0] + sum(self.y[1:n]))**2

def time_prem_case3(self):
self.values['prem_case3'] = prem(self.f, self.g, self.x)

def time_Polyprem_case3(self):
n = self.size
fp, gp = Poly(self.f, self.x, *(self.y)[:n]), Poly(self.g, self.x, *(self.y)[:n])
self.values['Polyprem_case3'] = fp.prem(gp)

def time_PolyElement_prem_case3(self):
self.R = ZZ[self.x, self.y1, self.y2, self.y3, self.y4, self.y5, self.y6, self.y7, self.y8, self.y9, self.y10]
fpe, gpe = self.R.from_sympy(self.f), self.R.from_sympy(self.g)
self.values['PolyElement_prem_case3'] = fpe.prem(gpe)

def generate_poly_case4(self):
# Sparse non-monic quadratic inputs with linear GCDs.
n = self.size
D = -1 + self.x * prod(self.y[:n])
self.f = D * (3 + self.x * prod(self.y[:n]))
self.g = D * (-3 + self.x * prod(self.y[:n]))

def time_prem_case4(self):
self.values['prem_case4'] = prem(self.f, self.g, self.x)

def time_Polyprem_case4(self):
n = self.size
fp, gp = Poly(self.f, self.x, *(self.y)[:n]), Poly(self.g, self.x, *(self.y)[:n])
self.values['Polyprem_case4'] = fp.prem(gp)
1e9abhi1e10 marked this conversation as resolved.
Show resolved Hide resolved

def time_PolyElement_prem_case4(self):
self.R = ZZ[self.x, self.y1, self.y2, self.y3, self.y4, self.y5, self.y6, self.y7, self.y8, self.y9, self.y10]
fpe, gpe = self.R.from_sympy(self.f), self.R.from_sympy(self.g)
self.values['PolyElement_prem_case4'] = fpe.prem(gpe)