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 GCD when input is Gaussian Integer #97

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Changes from all 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
36 changes: 28 additions & 8 deletions benchmarks/polys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sympy import symbols, prod, prem, rem, degree, LC, subresultants, gcd
from sympy import symbols, prod, prem, rem, degree, LC, subresultants, gcd, I, ZZ_I
from sympy.polys import QQ, Poly


Expand All @@ -23,14 +23,15 @@ class _GCDExample:
"""A benchmark example with two polynomials and their gcd."""

def __init__(self, n):
f, g, d, syms = self.make_poly(n)
f, g, d, syms, domain = self.make_poly(n)
self.f = f
self.g = g
self.d = d
self.x = syms[0]
self.y = syms[1:]
self.syms = syms
self.ring = QQ[syms]
self.domain = domain
self.ring = domain[syms]

def to_expr(self, expr):
return expr
Expand Down Expand Up @@ -79,7 +80,7 @@ def make_poly(self, n):
d = (1 + x + sum(y[:n])) ** 2
f = d * (-2 + x - sum(y[:n])) ** 2
g = d * (2 + x + sum(y[:n])) ** 2
return f, g, d, syms
return f, g, d, syms, QQ


class _SparseGCDHighDegree(_GCDExample):
Expand Down Expand Up @@ -110,7 +111,7 @@ def make_poly(self, n):
d = 1 + x ** (n + 1) + sum([y[i] ** (n + 1) for i in range(n)])
f = d * (-2 + x ** (n + 1) + sum([y[i] ** (n + 1) for i in range(n)]))
g = d * (2 + x ** (n + 1) + sum([y[i] ** (n + 1) for i in range(n)]))
return f, g, d, syms
return f, g, d, syms, QQ


class _QuadraticNonMonicGCD(_GCDExample):
Expand Down Expand Up @@ -141,7 +142,7 @@ def make_poly(self, n):
d = 1 + x ** 2 * y[0] ** 2 + sum([y[i] ** 2 for i in range(1, n)])
f = d * (-1 + x ** 2 - y[0] ** 2 + sum([y[i] ** 2 for i in range(1, n)]))
g = d * (2 + x * y[0] + sum(y[1:n])) ** 2
return f, g, d, syms
return f, g, d, syms, QQ


class _SparseNonMonicQuadratic(_GCDExample):
Expand Down Expand Up @@ -172,9 +173,23 @@ def make_poly(self, n):
d = -1 + x * prod(y[:n])
f = d * (3 + x * prod(y[:n]))
g = d * (-3 + x * prod(y[:n]))
return f, g, d, syms
return f, g, d, syms, QQ


class _GaussianInteger(_GCDExample):
"""An example of Polynomial using Gaussian Integer"""

def make_poly(self, n):
x, y1, y2, y3, y4, y5 = syms = symbols("x y1 y2 y3 y4 y5")

d = (-x + I*y1)*n

f = (-I*x**n - 2*y1*y3 - I*(-y2 + n) - I*(y4 + y5))*d

g = (-I*x**(n + 1) - 2*y1*(y3 + n) - I*(-y2 + n + 1) - I*(y4 + y5))*d

return f, g, d, syms, ZZ_I

class _TimeOP:
"""
Benchmarks comparing Poly implementations of a given operation.
Expand Down Expand Up @@ -341,4 +356,9 @@ class TimeGCD_QuadraticNonMonicGCD(_TimeGCD):

class TimeGCD_SparseNonMonicQuadratic(_TimeGCD):
GCDExampleCLS = _SparseNonMonicQuadratic
params = [(1, 3, 5), ('expr', 'dense', 'sparse')]
params = [(1, 3, 5), ('expr', 'dense', 'sparse')]


class TimeGCD_GaussInt( _TimeGCD):
GCDExampleCLS = _GaussianInteger
params = [(1, 2, 3), ('expr', 'dense', 'sparse')]