From a08cb228e753c462696e67519aefcc749763d7bb Mon Sep 17 00:00:00 2001 From: Ben <16917183+bencrts@users.noreply.github.com> Date: Wed, 8 May 2024 11:44:34 +0100 Subject: [PATCH 1/3] fix issue 110 --- estimator/lwe_dual.py | 1 + estimator/reduction.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/estimator/lwe_dual.py b/estimator/lwe_dual.py index bf8a0e5..107d121 100644 --- a/estimator/lwe_dual.py +++ b/estimator/lwe_dual.py @@ -591,6 +591,7 @@ def cost( k_fft, p, ) + rho, T_sample, _, beta_sieve = red_cost_model.short_vectors( beta, N=N, d=k_lat + m, sieve_dim=beta_sieve ) diff --git a/estimator/reduction.py b/estimator/reduction.py index cbdac59..1800cba 100644 --- a/estimator/reduction.py +++ b/estimator/reduction.py @@ -390,6 +390,11 @@ def _short_vectors_sieve(self, beta, d, N=None, B=None, preprocess=True, sieve_d self.delta(sieve_dim) ** (sieve_dim - 1) * self.delta(beta) ** (1 - sieve_dim) ) + #arbitrary choice + if c > 2**1000: + c = oo + return (rho, oo, oo, sieve_dim) + return ( rho, ceil(c) * self(beta, d), @@ -883,7 +888,7 @@ def short_vectors(self, beta, d, N=None, preprocess=True, B=None, C=5.46, sieve_ rho = sqrt(4 / 3.0) * RR( self.delta(sieve_dim) ** (sieve_dim - 1) * self.delta(beta) ** (1 - sieve_dim) ) - + if N == 1: if preprocess: return 1.0, self(beta, d, B=B), 1, beta @@ -892,8 +897,16 @@ def short_vectors(self, beta, d, N=None, preprocess=True, B=None, C=5.46, sieve_ elif N is None: N = floor(2 ** (0.2075 * sieve_dim)) # pick something - c = N / floor(2 ** (0.2075 * sieve_dim)) - sieve_cost = C * 2 ** (self.NN_AGPS[self.nn]["a"] * sieve_dim + self.NN_AGPS[self.nn]["b"]) + c0 = RR(N) + c1 = RR(2 ** (0.2075 * sieve_dim)) + c = c0 / floor(c1) + sieve_cost = C * 2 ** RR((self.NN_AGPS[self.nn]["a"] * sieve_dim + self.NN_AGPS[self.nn]["b"])) + + #arbitrary choice + if c > 2**1000: + c = oo + return(rho, oo, oo, sieve_dim) + return ( rho, ceil(c) * (self(beta, d) + sieve_cost), From 969828f9e5ce4d7f1a92fd1b69a39883bba28bad Mon Sep 17 00:00:00 2001 From: Ben <16917183+bencrts@users.noreply.github.com> Date: Wed, 8 May 2024 11:47:15 +0100 Subject: [PATCH 2/3] fix flake8 in the CI --- estimator/reduction.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/estimator/reduction.py b/estimator/reduction.py index 1800cba..55b7524 100644 --- a/estimator/reduction.py +++ b/estimator/reduction.py @@ -390,7 +390,7 @@ def _short_vectors_sieve(self, beta, d, N=None, B=None, preprocess=True, sieve_d self.delta(sieve_dim) ** (sieve_dim - 1) * self.delta(beta) ** (1 - sieve_dim) ) - #arbitrary choice + # arbitrary choice if c > 2**1000: c = oo return (rho, oo, oo, sieve_dim) @@ -888,7 +888,7 @@ def short_vectors(self, beta, d, N=None, preprocess=True, B=None, C=5.46, sieve_ rho = sqrt(4 / 3.0) * RR( self.delta(sieve_dim) ** (sieve_dim - 1) * self.delta(beta) ** (1 - sieve_dim) ) - + if N == 1: if preprocess: return 1.0, self(beta, d, B=B), 1, beta @@ -902,10 +902,15 @@ def short_vectors(self, beta, d, N=None, preprocess=True, B=None, C=5.46, sieve_ c = c0 / floor(c1) sieve_cost = C * 2 ** RR((self.NN_AGPS[self.nn]["a"] * sieve_dim + self.NN_AGPS[self.nn]["b"])) - #arbitrary choice + # arbitrary choice if c > 2**1000: - c = oo - return(rho, oo, oo, sieve_dim) + # set c = oo + return ( + rho, + oo, + oo, + sieve_dim, + ) return ( rho, From 56111bc0e07b2919c76f97235a544aa2d91d75f0 Mon Sep 17 00:00:00 2001 From: Ben <16917183+bencrts@users.noreply.github.com> Date: Wed, 8 May 2024 12:18:23 +0100 Subject: [PATCH 3/3] be consistent with return statements --- estimator/reduction.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/estimator/reduction.py b/estimator/reduction.py index 55b7524..583122b 100644 --- a/estimator/reduction.py +++ b/estimator/reduction.py @@ -392,8 +392,13 @@ def _short_vectors_sieve(self, beta, d, N=None, B=None, preprocess=True, sieve_d # arbitrary choice if c > 2**1000: - c = oo - return (rho, oo, oo, sieve_dim) + # set c = oo + return ( + rho, + oo, + oo, + sieve_dim, + ) return ( rho,