Skip to content

Commit

Permalink
Merge pull request #89 from fplll/bkz2_get_pruning
Browse files Browse the repository at this point in the history
Bkz2 get pruning
  • Loading branch information
malb committed Aug 1, 2017
2 parents 7fba772 + 7abfeae commit 1f4ca8a
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/fpylll/algorithms/bkz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fpylll import BKZ, Enumeration, EnumerationError
from fpylll.algorithms.bkz import BKZReduction as BKZBase
from fpylll.algorithms.bkz_stats import dummy_tracer
from fpylll.util import adjust_radius_to_gh_bound
from fpylll.util import gaussian_heuristic


class BKZReduction(BKZBase):
Expand All @@ -17,13 +17,16 @@ def __init__(self, A):
"""
BKZBase.__init__(self, A)

def get_pruning(self, kappa, block_size, param, tracer=dummy_tracer):
strategy = param.strategies[block_size]
def get_pruning(self, kappa, block_size, params, tracer=dummy_tracer):
strategy = params.strategies[block_size]
radius = self.M.get_r(kappa, kappa) * self.lll_obj.delta
r = [self.M.get_r(i, i) for i in range(kappa, kappa+block_size)]
gh_radius = gaussian_heuristic(r)

radius, re = self.M.get_r_exp(kappa, kappa)
root_det = self.M.get_root_det(kappa, kappa + block_size)
gh_radius, ge = adjust_radius_to_gh_bound(radius, re, block_size, root_det, 1.0)
return strategy.get_pruning(radius * 2**re, gh_radius * 2**ge)
if (params.flags & BKZ.GH_BND and block_size > 30):
radius = min(radius, gh_radius * params.gh_factor)

return radius, strategy.get_pruning(radius, gh_radius)

def randomize_block(self, min_row, max_row, tracer=dummy_tracer, density=0):
"""Randomize basis between from ``min_row`` and ``max_row`` (exclusive)
Expand All @@ -32,8 +35,6 @@ def randomize_block(self, min_row, max_row, tracer=dummy_tracer, density=0):
2. apply lower triangular matrix with coefficients in -1,0,1
3. LLL reduce result
:param min_row: start in this row
:param max_row: stop at this row (exclusive)
:param tracer: object for maintaining statistics
Expand Down Expand Up @@ -96,22 +97,16 @@ def svp_reduction(self, kappa, block_size, params, tracer=dummy_tracer):
with tracer.context("reduction"):
self.svp_preprocessing(kappa, block_size, params, tracer=tracer)

radius, expo = self.M.get_r_exp(kappa, kappa)
radius *= self.lll_obj.delta

if params.flags & BKZ.GH_BND and block_size > 30:
root_det = self.M.get_root_det(kappa, kappa + block_size)
radius, expo = adjust_radius_to_gh_bound(radius, expo, block_size, root_det, params.gh_factor)

pruning = self.get_pruning(kappa, block_size, params, tracer)
with tracer.context("pruner"):
radius, pruning = self.get_pruning(kappa, block_size, params, tracer)

try:
enum_obj = Enumeration(self.M)
with tracer.context("enumeration",
enum_obj=enum_obj,
probability=pruning.expectation,
full=block_size==params.block_size):
solution, max_dist = enum_obj.enumerate(kappa, kappa + block_size, radius, expo,
solution, max_dist = enum_obj.enumerate(kappa, kappa + block_size, radius, 0,
pruning=pruning.coefficients)[0]
with tracer.context("postprocessing"):
self.svp_postprocessing(kappa, block_size, solution, tracer=tracer)
Expand Down

0 comments on commit 1f4ca8a

Please sign in to comment.