### Manual Installation: Install Suggested Python Packages Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Optionally install suggested Python packages from suggestions.txt. ```bash (fpylll) pip install -r suggestions.txt ``` -------------------------------- ### Manual Installation: Build and Install Python Extension Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Configure pkg-config path, build the Python extension, and install the package. ```bash (fpylll) export PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig:$PKG_CONFIG_PATH" (fpylll) python setup.py build (fpylll) pip install . ``` -------------------------------- ### Manual Installation: Install Dependencies Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Install fplll dependencies using the provided script within the activated virtual environment. ```bash (fpylll) ./install-dependencies.sh $VIRTUAL_ENV ``` -------------------------------- ### Manual Installation: Install Python Packages Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Install required Python packages from requirements.txt. ```bash (fpylll) pip install -r requirements.txt ``` -------------------------------- ### Build and Install fpylll Source: https://github.com/fplll/fpylll/blob/master/README.rst Commands to build and install the fpylll package using setup.py and pip. ```bash $ (fpylll) python setup.py build $ (fpylll) pip install . ``` -------------------------------- ### Manual Installation: Install Suggested Python Packages Source: https://github.com/fplll/fpylll/blob/master/README.rst Shell command to install optional suggested Python packages for fpylll using pip. ```bash $ (fpylll) pip install -r suggestions.txt ``` -------------------------------- ### Sagemath Manual Update: Install Suggested Python Packages Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Optionally install suggested Python packages from suggestions.txt using pip3. ```bash (sage-sh) pip3 install -r suggestions.txt ``` -------------------------------- ### Automatic Installation Script Source: https://github.com/fplll/fpylll/blob/master/README.rst Shell commands to bootstrap and activate the fpylll environment for automatic installation. ```bash $ ./bootstrap.sh $ source ./activate ``` -------------------------------- ### Manual Installation: Create and Activate Virtual Environment Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Create a new virtual environment named 'env' and activate it for manual installation. ```bash virtualenv env ln -s ./env/bin/activate ./ source ./activate ``` -------------------------------- ### Print q-ary Matrix Example Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Prints an example of a q-ary matrix generated with specific parameters. Useful for visualizing the output of `randomize`. ```python print(D) ``` -------------------------------- ### Build and Install fpylll in SageMath Source: https://github.com/fplll/fpylll/blob/master/README.rst Commands to build and install the fpylll package using setup.py and pip3 within the SageMath environment. ```bash $ (sage-sh) python3 setup.py build $ (sage-sh) pip3 install . $ (sage-sh) exit ``` -------------------------------- ### Automatic Installation Script Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Execute the bootstrap script for automatic installation and activate the environment. ```bash ./bootstrap.sh source ./activate ``` -------------------------------- ### Manual Installation: Install fplll Dependencies Source: https://github.com/fplll/fpylll/blob/master/README.rst Shell command to install fplll dependencies within an active virtual environment. ```bash $ (fpylll) ./install-dependencies.sh $VIRTUAL_ENV ``` -------------------------------- ### Sagemath Manual Update: Build and Install Python Extension Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Configure pkg-config path, build the Python extension, and install using pip3. ```bash (sage-sh) export PKG_CONFIG_PATH="$SAGE_LOCAL/lib/pkgconfig:$PKG_CONFIG_PATH" (sage-sh) python3 setup.py build (sage-sh) pip3 install . (sage-sh) exit ``` -------------------------------- ### Sagemath Manual Update: Install Python Packages Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Install required Python packages from requirements.txt using pip3. ```bash (sage-sh) pip3 install -r requirements.txt ``` -------------------------------- ### Install fplll dependencies Source: https://github.com/fplll/fpylll/blob/master/README.rst Installs fplll dependencies using a provided script within the SageMath environment. ```bash $ (sage-sh) ./install-dependencies.sh $SAGE_LOCAL ``` -------------------------------- ### Manual Installation: Install Python Requirements Source: https://github.com/fplll/fpylll/blob/master/README.rst Shell command to install the required Python packages for fpylll using pip. ```bash $ (fpylll) pip install -r requirements.txt ``` -------------------------------- ### Install suggested Python packages Source: https://github.com/fplll/fpylll/blob/master/README.rst Installs optional suggested Python packages for fpylll using pip3. ```bash $ (sage-sh) pip3 install -r suggestions.txt ``` -------------------------------- ### Start IPython session Source: https://github.com/fplll/fpylll/blob/master/README.rst Command to start an IPython session within the activated fpylll virtual environment. ```bash $ (fpylll) ipython ``` -------------------------------- ### Manual Installation: Create Virtual Environment Source: https://github.com/fplll/fpylll/blob/master/README.rst Shell commands to create and activate a Python virtual environment for manual installation of fpylll. ```bash $ virtualenv env $ ln -s ./env/bin/activate ./ $ source ./activate ``` -------------------------------- ### Sagemath Manual Update: Install Dependencies Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Install fplll dependencies using the provided script, targeting Sagemath's local directory. ```bash (sage-sh) ./install-dependencies.sh $SAGE_LOCAL ``` -------------------------------- ### Verify fpylll installation in SageMath Source: https://github.com/fplll/fpylll/blob/master/README.rst Commands to verify the fpylll installation by importing it in SageMath and printing its version. ```bash $ sage sage: import fpylll sage: print(fpylll.__version__) ``` -------------------------------- ### Install fpylll requirements Source: https://github.com/fplll/fpylll/blob/master/README.rst Installs the required Python packages for fpylll using pip3. ```bash $ (sage-sh) pip3 install -r requirements.txt ``` -------------------------------- ### Sagemath Manual Update: Verify Installation Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Verify the fpylll upgrade by importing it in Sage and printing its version. ```bash sage sage: import fpylll sage: print(fpylll.__version__) ``` -------------------------------- ### Start Python Interpreter Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Launch the IPython interpreter within the activated virtual environment. ```bash (fpylll) ipython ``` -------------------------------- ### Manual Installation: Set Library Path Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Set the LD_LIBRARY_PATH to allow Python to find fplll and its dependencies. ```bash (fpylll) export LD_LIBRARY_PATH="$VIRTUAL_ENV/lib" ``` -------------------------------- ### Compile fplll with Debugging Source: https://github.com/fplll/fpylll/wiki/Debugging Clean the build, configure fplll with debugging flags and no static linking, then install. This prepares the underlying C++ library for debugging. ```bash make clean CXXFLAGS="-O0 -ggdb -DDEBUG" ./configure --prefix=$VIRTUAL_ENV --disable-static make -j4 install ``` -------------------------------- ### Compile fpylll with Debugging Source: https://github.com/fplll/fpylll/wiki/Debugging Remove the existing build directory and install fpylll with the same debugging flags used for fplll. This ensures that Python extensions are compiled with debug symbols. ```bash rm -r build CXXFLAGS="-O0 -ggdb -DDEBUG" python setup.py install ``` -------------------------------- ### Example Usage: Counting Points for Radius 2 Source: https://github.com/fplll/fpylll/blob/master/docs/example-gauss-circle-problem.md Demonstrates how to use the `gauss` function to find the number of lattice points for a radius of 2. It prints the count and the list of points. ```python g = gauss(2, 2, 100) len(g) g ``` -------------------------------- ### Detailed CVP Enumeration Execution Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Illustrates the underlying execution steps for CVP enumeration, including GSO matrix setup, enumeration object creation, and vector transformation. ```default >>> from fpylll.fplll.gso import MatGSO >>> from fpylll.fplll.enumeration import Enumeration >>> M = MatGSO(A) >>> _ = M.update_gso() >>> E = Enumeration(M) >>> _, v2 = E.enumerate(0, A.nrows, 5, 40, M.from_canonical(t))[0] >>> v3 = IntegerMatrix.from_iterable(1, A.nrows, map(lambda x: int(x), v2)) >>> v1 = v3*A >>> print(v1) [ 1 2 3 4 ] ``` -------------------------------- ### BKZ Lattice Reduction (No Pruning) Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Applies BKZ reduction to a matrix with a specified block size. Requires the BKZ module and parameters. This example does not use pruning. ```python from fpylll import BKZ block_size = 3 FPLLL.set_random_seed(1337) A.randomize("qary", bits=10, k=3) A_bkz = BKZ.reduction(A, BKZ.Param(block_size)) print(A_bkz) ``` -------------------------------- ### Example Usage: Estimating Points for Radius 80 Source: https://github.com/fplll/fpylll/blob/master/docs/example-gauss-circle-problem.md Calculates the estimated number of lattice points for a radius of 80 using the `gauss` function with an appropriate `nr` value derived from the theoretical bound. ```python from math import pi, ceil, sqrt R = 80 nr = ceil(pi*R**2 + 2*sqrt(2)*pi*R) len(gauss(R,2,nr)) ``` -------------------------------- ### Get GSO Coefficients Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Retrieves the inner product r_{i,j} and the coefficient mu_{i,j} from the GSO matrix. These are fundamental values in lattice theory. ```python i = 3; j = 2; print(M.get_r(i,j)) print(M.get_mu(i,j)) ``` -------------------------------- ### Compute Determinant from GSO Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Calculates the root determinant and log determinant of a matrix using its GSO representation. Specify the start and stop rows for the calculation. ```python start_row = 0 stop_row = -1 root_det_A = M.get_root_det(start_row, stop_row) log_det_A = M.get_log_det(start_row, stop_row) print(root_det_A) # root_det_A = det(A)^(1/n) doctest: +ELLIPSIS print(log_det_A) # log_det_A = exp(det(A)) in base e doctest: +ELLIPSIS ``` -------------------------------- ### Babai's Nearest Plane Algorithm Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Applies Babai's Nearest Plane algorithm to find a vector close to the target vector using a given basis. Requires GSO tool setup. ```pycon >>> FPLLL.set_random_seed(1337) >>> A = LLL.reduction(IntegerMatrix.random(5, "qary", bits=10, k=3)) >>> M = GSO.Mat(A) >>> _ = M.update_gso() >>> w = M.babai([1, 17, -3, -75, 102]) >>> A.multiply_left(w) (-6, 12, -19, -71, 98) ``` -------------------------------- ### Solving Closest Vector Problem (CVP) Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Finds the closest vector to a target vector in a lattice generated by a given matrix using enumeration. Requires CVP class and matrix setup. ```default >>> from fpylll import CVP >>> A = IntegerMatrix.from_matrix([[1,2,3,4],[30,4,4,5],[1,-2,3,4]]) >>> t = (1, 2, 5, 5) >>> v0 = CVP.closest_vector(A, t) >>> v0 (1, 2, 3, 4) ``` -------------------------------- ### Linting fpylll Source Code with Flake8 Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Checks the fpylll source code for style guide violations using flake8. This command enforces line length and complexity limits on the src directory. ```bash (fpylll) flake8 --max-line-length=120 --max-complexity=16 --ignore=E22,E241 src ``` -------------------------------- ### ValueError: Float type 'dd' unknown Source: https://github.com/fplll/fpylll/wiki/Float-Type-unknown This exception indicates that FPLLL was compiled without libqd support. To resolve this, install libqd and rebuild FPLLL and FPyLLL, or use an alternative floating-point type like 'mpfr'. ```python ValueError: Float type 'dd' unknown ``` -------------------------------- ### Activate SageMath virtual environment Source: https://github.com/fplll/fpylll/blob/master/README.rst Command to activate the SageMath virtual environment for manual updates. ```bash $ sage -sh ``` -------------------------------- ### Sagemath Manual Update: Activate Sage-sh Virtualenv Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Activate the sage-sh virtual environment for updating fpylll within Sagemath. ```bash sage -sh ``` -------------------------------- ### Set PKG_CONFIG_PATH for fpylll build in SageMath Source: https://github.com/fplll/fpylll/blob/master/README.rst Configures the PKG_CONFIG_PATH environment variable for building fpylll within the SageMath environment. ```bash $ (sage-sh) export PKG_CONFIG_PATH="$SAGE_LOCAL/lib/pkgconfig:$PKG_CONFIG_PATH" ``` -------------------------------- ### Lattice Matrix Operations with fpylll Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Demonstrates creating a random integer matrix, performing GSO updates, and applying LLL reduction. Shows how norms and mu values change after reduction. ```python >>> from fpylll import * >>> A = IntegerMatrix(50, 50) >>> A.randomize("ntrulike", bits=50, q=127) >>> A[0].norm() 3564748886669202.5 >>> M = GSO.Mat(A) >>> M.update_gso() >>> M.get_mu(1,0) 0.815748944429783 >>> L = LLL.Reduction(M) >>> L() >>> M.get_mu(1,0) 0.41812865497076024 >>> A[0].norm() 24.06241883103193 ``` -------------------------------- ### Activate Virtual Environment Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Reactivate the virtual environment using the activate script. ```bash source ./activate ``` -------------------------------- ### Constructing the Lattice Basis for Diophantine Equations Source: https://github.com/fplll/fpylll/blob/master/docs/example-linear-diophantine-equations.md This snippet initializes the IntegerMatrix and populates the basis vectors for the lattice used to solve a linear Diophantine equation. It sets up the matrix structure required for the LLL reduction. ```pycon >>> from fpylll import IntegerMatrix, LLL >>> N1 = 100 >>> N2 = 10000 >>> a = [1124, 1799, 1151, 1979, 1799, 1625, 1077, 1666, 1438, 1739] >>> a0 = 22833 >>> n = len(a) >>> M = IntegerMatrix(n+1, n+2) >>> for i in range(len(a)): ... M[i, -1] = a[i]*N2 ... M[i, i] = 1 ... ``` -------------------------------- ### Activate fpylll virtual environment Source: https://github.com/fplll/fpylll/blob/master/README.rst Command to activate the fpylll virtual environment. ```bash $ source ./activate ``` -------------------------------- ### BKZ Lattice Reduction (With Pruning) Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Performs BKZ reduction using default pruning strategies. Requires importing BKZ and defining block size and strategy parameters. ```python from fpylll import BKZ param = BKZ.Param(block_size = block_size, strategies = BKZ.DEFAULT_STRATEGY) bkz_reduced = BKZ.reduction(A, param) ``` -------------------------------- ### Vector Conversion with GSO Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Demonstrates converting a vector to and from the canonical basis using the GSO matrix. This involves updating the GSO and using `to_canonical` and `from_canonical` methods. ```python A = IntegerMatrix.from_matrix([[1,2,3,4],[30,4,4,5],[1,-2,3,4],[0,0,1,0]]) M = GSO.Mat(A) _ = M.update_gso() v = (1,2,5,5) v_from_canonical = M.from_canonical(v) print(v_from_canonical) v_back_to_canonical = tuple([int(round(v_)) for v_ in M.to_canonical(v_from_canonical)]) print(v_back_to_canonical) # the dimension of the GS-matrix : print(M.d) ``` -------------------------------- ### BKZ Reduction with Default Strategy Source: https://github.com/fplll/fpylll/blob/master/docs/example-custom-pruning.md Computes the BKZ reduction of the same matrix using fpylll's default strategy for comparison. This is generally faster than the custom linear pruning. ```python >>> param = BKZ.Param(block_size=10, strategies=BKZ.DEFAULT_STRATEGY) >>> bkz_reduced_2 = BKZ.reduction(A, param) ``` -------------------------------- ### Completing the Lattice Basis and Applying LLL Reduction Source: https://github.com/fplll/fpylll/blob/master/docs/example-linear-diophantine-equations.md This snippet completes the construction of the lattice basis matrix by setting the last row and then applies the LLL reduction algorithm to the matrix. The output `L` represents the LLL-reduced basis. ```pycon >>> M[-1, -2] = N1 >>> M[-1, -1] = -a0 * N2 >>> L = LLL.reduction(M); print(L) ``` -------------------------------- ### BKZ Reduction with Custom Linear Pruning Source: https://github.com/fplll/fpylll/blob/master/docs/example-custom-pruning.md Computes the BKZ reduction of a large matrix using the custom linear pruning strategy defined previously. Requires importing IntegerMatrix, BKZ, and FPLLL. ```python >>> from fpylll import IntegerMatrix, BKZ, FPLLL >>> A = IntegerMatrix(70, 71) >>> FPLLL.set_random_seed(2013) >>> A.randomize("intrel", bits=100) >>> bkz_reduced = BKZ.reduction(A, LP) ``` -------------------------------- ### Instantiate Linear Pruning Strategy Source: https://github.com/fplll/fpylll/blob/master/docs/example-custom-pruning.md Instantiates the custom linear pruning strategy with a block size of 10 and a level of 6. ```python >>> LP = linear_pruning_strategy(10, 6) ``` -------------------------------- ### Running fpylll Tests Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Executes all tests for the fpylll library using py.test. Ensure the fpylll environment is activated. ```bash (fpylll) PY_IGNORE_IMPORTMISMATCH=1 py.test ``` -------------------------------- ### Create Matrix from List Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Initializes an IntegerMatrix from a list of lists. This is a common way to define matrices programmatically. ```python A = IntegerMatrix.from_matrix([[1,2,3,4],[30,4,4,5],[1,-2,3,4],[0,0,1,0]]) ``` -------------------------------- ### Initialize GSO Matrix Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Initializes the Gram-Schmidt orthogonalization (GSO) matrix from an IntegerMatrix. Requires the GSO module. ```python from fpylll import GSO A = IntegerMatrix.from_matrix([[1,2,3,4],[30,4,4,5],[1,-2,3,4],[0,0,1,0]]) M = GSO.Mat(A) ``` -------------------------------- ### LD_LIBRARY_HACK for activate script Source: https://github.com/fplll/fpylll/blob/master/README.rst Appends the virtual environment's lib directory to LD_LIBRARY_PATH when activating the environment. ```bash ### LD_LIBRARY_HACK _OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_LIBRARY_PATH="$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH ### END_LD_LIBRARY_HACK ``` -------------------------------- ### Compare Reduction Results Source: https://github.com/fplll/fpylll/blob/master/docs/example-custom-pruning.md Compares the results of BKZ reduction using the custom linear pruning strategy and the default strategy to verify their equivalence or differences. ```python >>> bkz_reduced == bkz_reduced_2 True ``` -------------------------------- ### Print Integer Matrix Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Displays the contents of an IntegerMatrix object. This is useful for verifying matrix generation. ```python print(A) ``` -------------------------------- ### PKG_CONFIG_HACK for activate script Source: https://github.com/fplll/fpylll/blob/master/README.rst Appends the virtual environment's pkgconfig directory to PKG_CONFIG_PATH when activating the environment. ```bash ### PKG_CONFIG_HACK _OLD_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig:$PKG_CONFIG_PATH" export PKG_CONFIG_PATH ### END_PKG_CONFIG_HACK ``` -------------------------------- ### Define and Enumerate Lattice Points for Gauss Circle Problem Source: https://github.com/fplll/fpylll/blob/master/docs/example-gauss-circle-problem.md This function computes lattice points within a specified radius using fpylll's enumeration. It defines a lattice, initializes the GSO, and then enumerates solutions up to a given squared radius. The function returns a list of points, including the origin and their negative counterparts. ```python from fpylll.fplll.gso import MatGSO from fpylll.fplll.integer_matrix import IntegerMatrix from fpylll import FPLLL, Enumeration, EvaluatorStrategy FPLLL.set_random_seed(1337) def gauss(radius, dim, nr): A = IntegerMatrix.identity(dim) #define the latttice Z^dim M = MatGSO(A) _ = M.update_gso() enum = Enumeration(M, nr_solutions = nr) e1 = enum.enumerate(0, dim, radius**2, 0) return [tuple(dim*[0])] + [v for d,v in e1] + [tuple([-x for x in v]) for d,v in e1] ``` -------------------------------- ### Generate Various Matrix Types Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Generates different types of matrices including uniform, ntrulike, ntrulike2, and qary. Requires FPLLL and copy imports. Set a random seed before generation. ```python from fpylll import FPLLL from copy import copy b = 10 p = 521 # prime FPLLL.set_random_seed(1337) A = IntegerMatrix(6,6) B = copy(A) C = copy(A) D = copy(A) A.randomize("uniform", bits=b) B.randomize("ntrulike", bits=b, q=p) C.randomize("ntrulike2", bits=b, q=p) D.randomize("qary", bits=b, k=3) ``` -------------------------------- ### Set PKG_CONFIG_PATH for fpylll Source: https://github.com/fplll/fpylll/blob/master/README.rst Configures the PKG_CONFIG_PATH environment variable to include the pkgconfig directory within the virtual environment for fpylll. ```bash $ (fpylll) export PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig:$PKG_CONFIG_PATH" ``` -------------------------------- ### Generate Random Knapsack-Type Matrix Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Creates a random knapsack-type matrix of the form [a | I_n]. Ensure FPLLL is imported and a random seed is set. ```python from fpylll import IntegerMatrix, FPLLL FPLLL.set_random_seed(1337) A = IntegerMatrix(9, 10) A.randomize("intrel", bits=10) ``` -------------------------------- ### Run Valgrind with Suppressions Source: https://github.com/fplll/fpylll/wiki/Debugging Execute your Python script under Valgrind, applying the custom suppression file. This command will report memory errors and leaks, filtered by the provided suppressions. ```bash valgrind --suppressions=valgrind-python.supp python test.py ``` -------------------------------- ### Extracting and Verifying the Small Solution Source: https://github.com/fplll/fpylll/blob/master/docs/example-linear-diophantine-equations.md After LLL reduction, this snippet extracts the submatrix corresponding to the original variables and calculates the norm of the last row, which represents a small solution to the Diophantine equation. ```default >>> L.submatrix(0, 0, n, n)[-1].norm() 5.099019513... ``` -------------------------------- ### Finding the Shortest Vector using SVP Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Computes the shortest vector of a lattice generated by the rows of a matrix using the `shortest_vector` method from the SVP class. The first row of the resulting matrix is the shortest vector. ```default >>> from fpylll import SVP >>> SVP.shortest_vector(A) (-3, 0, 21, -15, -23) >>> print(A[0]) (-3, 0, 21, -15, -23) >>> A[0].norm() 34.698703... ``` -------------------------------- ### Debug Python with GDB Source: https://github.com/fplll/fpylll/wiki/Debugging Launch the GDB debugger with Python as the target executable. This allows you to set breakpoints and inspect the state of your Python script during execution. ```bash gdb --args python test.py ``` -------------------------------- ### LLL Lattice Reduction Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Performs LLL reduction on an IntegerMatrix. Requires the LLL module and setting a random seed. The original matrix is preserved. ```python from fpylll import LLL FPLLL.set_random_seed(1337) A.randomize("qary", bits=10, k=3) A_original = copy(A) A_lll = LLL.reduction(A) print(A_lll) ``` -------------------------------- ### Restore PKG_CONFIG_PATH in deactivate script Source: https://github.com/fplll/fpylll/blob/master/README.rst Restores the original PKG_CONFIG_PATH when deactivating the virtual environment. ```bash ### PKG_CONFIG_HACK if ! [ -z ${_OLD_PKG_CONFIG_PATH+x} ] ; then PKG_CONFIG_PATH="$_OLD_PKG_CONFIG_PATH" export PKG_CONFIG_PATH unset _OLD_PKG_CONFIG_PATH fi ### END_PKG_CONFIG_HACK ``` -------------------------------- ### Patch Activate Script for LD_LIBRARY_HACK Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Add LD_LIBRARY_HACK to the activate script to automatically set LD_LIBRARY_PATH. ```bash ### LD_LIBRARY_HACK _OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_LIBRARY_PATH="$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH ### END_LD_LIBRARY_HACK ### PKG_CONFIG_HACK _OLD_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig:$PKG_CONFIG_PATH" export PKG_CONFIG_PATH ### END_PKG_CONFIG_HACK ``` -------------------------------- ### Set LD_LIBRARY_PATH for fpylll Source: https://github.com/fplll/fpylll/blob/master/README.rst Exports the LD_LIBRARY_PATH environment variable to include the lib directory of the virtual environment, allowing Python to find fplll libraries. ```bash $ (fpylll) export LD_LIBRARY_PATH="$VIRTUAL_ENV/lib" ``` -------------------------------- ### Define Custom Linear Pruning Strategy Source: https://github.com/fplll/fpylll/blob/master/docs/example-custom-pruning.md This function defines a custom linear pruning strategy for BKZ reduction. It raises ValueErrors for invalid block_size or level inputs and constructs a BKZ.Param object with the specified linear pruning parameters. ```python >>> def linear_pruning_strategy(block_size, level): ... if level > block_size - 1: ... raise ValueError ... if block_size < 5: ... raise ValueError ... from fpylll import BKZ ... from fpylll.fplll.pruner import PruningParams ... from fpylll.fplll.bkz_param import Strategy ... preprocessing = 3 ... strategies1 = [Strategy(i) for i in range(6)] ... for b in range(6, block_size+1): ... if block_size == b: ... pr = PruningParams.LinearPruningParams(block_size, level) ... s = Strategy(b, [preprocessing], [pr]) ... else: ... s = Strategy(b, [preprocessing]) ... strategies1.append(s) ... param = BKZ.Param(block_size = block_size, strategies = strategies1) ... return param ``` -------------------------------- ### Calculate Number of Points for Gauss Circle Problem (N_R) Source: https://github.com/fplll/fpylll/blob/master/docs/example-gauss-circle-problem.md This function calculates N_R, the number of integer lattice points (x, y) such that x^2 + y^2 <= R^2. It leverages the enumeration function to find points and then computes N_R as 2 times the number of non-zero points plus one for the origin. ```python # computation of N_R from fpylll.fplll.gso import MatGSO from fpylll.fplll.integer_matrix import IntegerMatrix from fpylll import Enumeration, EvaluatorStrategy from math import pi, ceil, sqrt def n(radius): dim = 2 nr = ceil(pi*radius**2 + 2*sqrt(2)*pi*radius) A = IntegerMatrix.identity(dim) M = MatGSO(A) _ = M.update_gso() enum = Enumeration(M,nr_solutions = nr) e1 = enum.enumerate(0, dim, radius**2, 0) return 2*len(e1)+1 ``` -------------------------------- ### Parallel LLL Reduction using Multiprocessing Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Performs LLL reduction on multiple IntegerMatrix objects in parallel using Python's multiprocessing Pool. This approach bypasses the GIL for true parallelism. ```python from fpylll import IntegerMatrix, LLL from multiprocessing import Pool d, workers, tasks = 30, 4, 128 def run_it(p, f, A, prefix=""): """Print status during parallel execution.""" import sys r = [] for i, retval in enumerate(p.imap_unordered(f, A, 1)): r.append(retval) sys.stderr.write('\r{0} done: {1:.2%}'.format(prefix, float(i)/len(A))) sys.stderr.flush() sys.stderr.write('\r{0} done {1:.2%}\n'.format(prefix, float(i+1)/len(A))) return r A = [IntegerMatrix.random(d, "uniform", bits=30) for _ in range(tasks)] A = run_it(Pool(workers), LLL.reduction, A) ``` -------------------------------- ### Restore LD_LIBRARY_PATH in deactivate script Source: https://github.com/fplll/fpylll/blob/master/README.rst Restores the original LD_LIBRARY_PATH when deactivating the virtual environment. ```bash ### LD_LIBRARY_HACK if ! [ -z ${_OLD_LD_LIBRARY_PATH+x} ] ; then LD_LIBRARY_PATH="$_OLD_LD_LIBRARY_PATH" export LD_LIBRARY_PATH unset _OLD_LD_LIBRARY_PATH fi ### END_LD_LIBRARY_HACK ``` -------------------------------- ### Check if Matrix is LLL-Reduced Source: https://github.com/fplll/fpylll/blob/master/docs/tutorial.md Tests whether a given matrix satisfies the conditions for LLL reduction. Useful for verifying the output of reduction algorithms. ```python print(LLL.is_reduced(A_original)) # a uniform matrix is usually not LLL-reduced print(LLL.is_reduced(A_lll)) ``` -------------------------------- ### Valgrind Suppressions for Python Memory Management Source: https://github.com/fplll/fpylll/wiki/Debugging Custom Valgrind suppression rules for `PyObject_Free` and `PyObject_Realloc`. These rules help filter out known memory-related issues originating from Python's memory allocators, reducing noise during Valgrind analysis. ```text { ADDRESS_IN_RANGE/Invalid read of size 4 Memcheck:Addr4 fun:PyObject_Free } { ADDRESS_IN_RANGE/Invalid read of size 4 Memcheck:Value4 fun:PyObject_Free } { ADDRESS_IN_RANGE/Invalid read of size 8 Memcheck:Addr8 fun:PyObject_Free } { ADDRESS_IN_RANGE/Invalid read of size 8 Memcheck:Value8 fun:PyObject_Free } { ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value Memcheck:Cond fun:PyObject_Free } { ADDRESS_IN_RANGE/Invalid read of size 4 Memcheck:Addr4 fun:PyObject_Realloc } { ADDRESS_IN_RANGE/Invalid read of size 4 Memcheck:Value4 fun:PyObject_Realloc } { ADDRESS_IN_RANGE/Invalid read of size 8 Memcheck:Addr8 fun:PyObject_Realloc } { ADDRESS_IN_RANGE/Invalid read of size 8 Memcheck:Value8 fun:PyObject_Realloc } { ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value Memcheck:Cond fun:PyObject_Realloc } ``` -------------------------------- ### fpylll Citation Information Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Provides the BibTeX entry for citing the fpylll library in academic work. Includes author, title, version, year, and URL. ```default @unpublished{fpylll, author = {The {FPLLL} development team}, title = {{fpylll}, a {Python} wrapper for the {fplll} lattice reduction library, {Version}: 0.6.4}, year = 2025, note = {Available at \url{https://github.com/fplll/fpylll}}, url = {https://github.com/fplll/fpylll} } ``` -------------------------------- ### Patch Deactivate Script for LD_LIBRARY_HACK Source: https://github.com/fplll/fpylll/blob/master/docs/index.md Add LD_LIBRARY_HACK to the deactivate function in the activate script to restore original LD_LIBRARY_PATH. ```bash ### LD_LIBRARY_HACK if ! [ -z ${_OLD_LD_LIBRARY_PATH+x} ] ; then LD_LIBRARY_PATH="$_OLD_LD_LIBRARY_PATH" export LD_LIBRARY_PATH unset _OLD_LD_LIBRARY_PATH fi ### END_LD_LIBRARY_HACK ### PKG_CONFIG_HACK if ! [ -z ${_OLD_PKG_CONFIG_PATH+x} ] ; then PKG_CONFIG_PATH="$_OLD_PKG_CONFIG_PATH" export PKG_CONFIG_PATH unset _OLD_PKG_CONFIG_PATH fi ### END_PKG_CONFIG_HACK ``` -------------------------------- ### Setting Precision for MPFR Float Type Source: https://github.com/fplll/fpylll/wiki/Float-Type-unknown When using the 'mpfr' floating-point type, set the desired precision. 'dd' typically uses 106 bits of precision. ```python FPLLL.set_precision(106) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.