1.. _example-custom-pruning: 2 3.. role:: math(raw) 4 :format: html latex 5.. 6 7.. role:: raw-latex(raw) 8 :format: latex 9.. 10 11:orphan: 12 13Linear Pruning 14============== 15 16If we want to use pruning we can use the default pruning of fplll or to use our custom pruning. For instance, say that for some reason we want to use linear pruning. Then, we shall define the new linear pruning strategy as follows. 17 18:: 19 20 >>> def linear_pruning_strategy(block_size, level): 21 ... if level > block_size - 1: 22 ... raise ValueError 23 ... if block_size < 5: 24 ... raise ValueError 25 ... from fpylll import BKZ 26 ... from fpylll.fplll.pruner import PruningParams 27 ... from fpylll.fplll.bkz_param import Strategy 28 ... preprocessing = 3 29 ... strategies1 = [Strategy(i) for i in range(6)] 30 ... for b in range(6, block_size+1): 31 ... if block_size == b: 32 ... pr = PruningParams.LinearPruningParams(block_size, level) 33 ... s = Strategy(b, [preprocessing], [pr]) 34 ... else: 35 ... s = Strategy(b, [preprocessing]) 36 ... strategies1.append(s) 37 ... param = BKZ.Param(block_size = block_size, strategies = strategies1) 38 ... return param 39 40So, now we can define a new strategy that uses linear pruning 41 42:: 43 44 >>> LP = linear_pruning_strategy(10, 6) 45 46Now, we shall compute the BKZ reduction of a large matrix using linear pruning. 47 48:: 49 50 >>> from fpylll import IntegerMatrix, BKZ, FPLLL 51 >>> A = IntegerMatrix(70, 71) 52 >>> FPLLL.set_random_seed(2013) 53 >>> A.randomize("intrel", bits=100) 54 >>> bkz_reduced = BKZ.reduction(A, LP) 55 56Now, ``bkz_reduced`` is the BKZ reduced matrix of **A** using linear pruning with blocksize 10 and level 6. If we want to use the default strategy of fplll (which is faster than the previous linear pruning strategy) we use ``BKZ.DEFAULT_STRATEGY``, 57 58:: 59 60 >>> param = BKZ.Param(block_size=10, strategies=BKZ.DEFAULT_STRATEGY) 61 >>> bkz_reduced_2 = BKZ.reduction(A, param) 62 63and 64 65:: 66 67 >>> bkz_reduced == bkz_reduced_2 68 True 69