<commit_before>#ifndef FPLLL_PRUNER_H
#define FPLLL_PRUNER_H

/* Copyright (C) 2015-2016 <NAME>, <NAME>.

   This file is part of fplll. fplll is free software: you
   can redistribute it and/or modify it under the terms of the GNU Lesser
   General Public License as published by the Free Software Foundation,
   either version 2.1 of the License, or (at your option) any later version.

   fplll is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTAbILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with fplll. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
#include "gso.h"
#include "bkz_param.h"
#include <array>

FPLLL_BEGIN_NAMESPACE

/**
   This file provides an implementation of the numerically optimized pruning
   strategy of [GNR10].

   Many details for implementation follows from the thesis [Chen13] Some
   simplifications have been made, for example we restrict ourselves to ``even
   vector bounds'' i.e., the bound at indices 2i and 2i+1 are kept equal, as to
   allow volume estimation by pure integration (see [GNR10,Chen13])

   The current descent method use gradients, but alternative algorithms
   (Nelder-Mead) May be added soon.

   naming conventions:

   - b is for bound (squared)

   - ipv is for inverse partial volumes (NOT squared)

   - r is for gram schmidt length (squared). Automatically renormalized to avoid
   overflowing partial volumes

   - p is for polynomial

   inside this code, b,pv,and R are in reversed order as to conform with the
   algorithm desciption of [Chen13] reversing the order is handled by the load
   and save methods.

   - n is for the dimension of the basis to prune

   - d is for degrees of polynomials. md is for max_degree

   - d is floor(n/2 at most). Odd n are dealt with by ignoring the first component
*/

#define PRUNER_MAX_PREC 1000
#define PRUNER_MAX_D 1023
#define PRUNER_MAX_N 2047

#define PRUNER_METHOD_GRADIENT 0    // Gradient Only
#define PRUNER_METHOD_NM 1          // NealderMead Only
#define PRUNER_METHOD_HYBRID 2      // Gradient followed by NelderMead



/**
   @brief prune function, hiding the Pruner class

   @param pr store pruning coefficients here
   @param probability store success probability here
   @param enumeration_radius target enumeration radius
   @param preproc_cost cost of preprocessing
   @param target_probability overall target success probability
   @param m GSO matrix
   @param method for the descent (gradient, NM, both)
   @param start_row start enumeration here
   @param end_row stop enumeration here
*/

template <class FT, class GSO_ZT, class GSO_FT>
void prune(/*output*/ vector<double> &pr, double &probability,
           /*inputs*/ const double enumeration_radius, const double preproc_cost,
           const double target_probability, const MatGSO<GSO_ZT, GSO_FT> &m, 
           const int descent_method = PRUNER_METHOD_GRADIENT, int start_row = 0, int end_row = 0);


/**
   @brief prune function, hiding the Pruner class

   @param pruning store pruning structure
   @param probability store success probability here
   @param enumeration_radius target enumeration radius
   @param preproc_cost cost of preprocessing
   @param target_probability overall target success probability
   @param m GSO matrix
   @param method for the descent (gradient, NM, both)
   @param start_row start enumeration here
   @param end_row stop enumeration here

   @return Pruning object.
*/

template <class FT, class GSO_ZT, class GSO_FT>
Pruning prune(/*inputs*/ const double enumeration_radius, const double preproc_cost,
           const double target_probability, MatGSO<GSO_ZT, GSO_FT> &m, 
           const int descent_method = PRUNER_METHOD_GRADIENT, int start_row = 0, int end_row = 0);

/**
   @brief prune function averaging over several bases

   @param probability store success probability here
   @param enumeration_radius target enumeration radius
   @param preproc_cost cost of preprocessing
   @param target_probability overall target success probability
   @param m GSO matrices
   @param start_row start enumeration here
   @param end_row stop enumeration here
   @return Pruning object.
*/

template <class FT, class GSO_ZT, class GSO_FT>
Pruning prune(/*inputs*/ const double enumeration_radius, const double preproc_cost,
              const double target_probability, vector<MatGSO<GSO_ZT, GSO_FT> > &m,
              const int descent_method = PRUNER_METHOD_GRADIENT, int start_row = 0, int end_row = 0);

/**
   @brief svp_probability function, hiding the Pruner class

   @param pruning
   @return pruning probability
*/


template <class FT>
double svp_probability(const Pruning &pruning);

template <class FT><commit_msg>enum for PRUNER_METHOD, and default set to PRUNER_METHOD_HYBRID<commit_after>#ifndef FPLLL_PRUNER_H
#define FPLLL_PRUNER_H

/* Copyright (C) 2015-2016 <NAME>, <NAME>.

   This file is part of fplll. fplll is free software: you
   can redistribute it and/or modify it under the terms of the GNU Lesser
   General Public License as published by the Free Software Foundation,
   either version 2.1 of the License, or (at your option) any later version.

   fplll is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTAbILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with fplll. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
#include "gso.h"
#include "bkz_param.h"
#include <array>

FPLLL_BEGIN_NAMESPACE

/**
   This file provides an implementation of the numerically optimized pruning
   strategy of [GNR10].

   Many details for implementation follows from the thesis [Chen13] Some
   simplifications have been made, for example we restrict ourselves to ``even
   vector bounds'' i.e., the bound at indices 2i and 2i+1 are kept equal, as to
   allow volume estimation by pure integration (see [GNR10,Chen13])

   The current descent method use gradients, but alternative algorithms
   (Nelder-Mead) May be added soon.

   naming conventions:

   - b is for bound (squared)

   - ipv is for inverse partial volumes (NOT squared)

   - r is for gram schmidt length (squared). Automatically renormalized to avoid
   overflowing partial volumes

   - p is for polynomial

   inside this code, b,pv,and R are in reversed order as to conform with the
   algorithm desciption of [Chen13] reversing the order is handled by the load
   and save methods.

   - n is for the dimension of the basis to prune

   - d is for degrees of polynomials. md is for max_degree

   - d is floor(n/2 at most). Odd n are dealt with by ignoring the first component
*/

#define PRUNER_MAX_PREC 1000
#define PRUNER_MAX_D 1023
#define PRUNER_MAX_N 2047

enum PRUNER_METHOD { PRUNER_METHOD_GRADIENT, PRUNER_METHOD_NM, PRUNER_METHOD_HYBRID };

/**
   @brief prune function, hiding the Pruner class

   @param pr store pruning coefficients here
   @param probability store success probability here
   @param enumeration_radius target enumeration radius
   @param preproc_cost cost of preprocessing
   @param target_probability overall target success probability
   @param m GSO matrix
   @param method for the descent (gradient, NM, both)
   @param start_row start enumeration here
   @param end_row stop enumeration here
*/

template <class FT, class GSO_ZT, class GSO_FT>
void prune(/*output*/ vector<double> &pr, double &probability,
           /*inputs*/ const double enumeration_radius, const double preproc_cost,
           const double target_probability, const MatGSO<GSO_ZT, GSO_FT> &m, 
           const int descent_method = PRUNER_METHOD_HYBRID, int start_row = 0, int end_row = 0);


/**
   @brief prune function, hiding the Pruner class

   @param pruning store pruning structure
   @param probability store success probability here
   @param enumeration_radius target enumeration radius
   @param preproc_cost cost of preprocessing
   @param target_probability overall target success probability
   @param m GSO matrix
   @param method for the descent (gradient, NM, both)
   @param start_row start enumeration here
   @param end_row stop enumeration here

   @return Pruning object.
*/

template <class FT, class GSO_ZT, class GSO_FT>
Pruning prune(/*inputs*/ const double enumeration_radius, const double preproc_cost,
           const double target_probability, MatGSO<GSO_ZT, GSO_FT> &m, 
           const int descent_method = PRUNER_METHOD_HYBRID, int start_row = 0, int end_row = 0);

/**
   @brief prune function averaging over several bases

   @param probability store success probability here
   @param enumeration_radius target enumeration radius
   @param preproc_cost cost of preprocessing
   @param target_probability overall target success probability
   @param m GSO matrices
   @param start_row start enumeration here
   @param end_row stop enumeration here
   @return Pruning object.
*/

template <class FT, class GSO_ZT, class GSO_FT>
Pruning prune(/*inputs*/ const double enumeration_radius, const double preproc_cost,
              const double target_probability, vector<MatGSO<GSO_ZT, GSO_FT> > &m,
              const int descent_method = PRUNER_METHOD_HYBRID, int start_row = 0, int end_row = 0);

/**
   @brief svp_probability function, hiding the Pruner class

   @param pruning
   @return pruning probability
*/


template <class FT>
double svp_probability(const Pruning &pruning);

template <class FT>
{'fraction_non_alphanumeric': 0.05793089305854609, 'fraction_numerical': 0.008920332205475239, 'mean_word_length': 3.833498513379584, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6149460', 'n_tokens_mistral': 2927, 'n_tokens_neox': 2729, 'n_words': 1194}