Path: blob/master/sage/schemes/hyperelliptic_curves/hypellfrob/recurrences_zn_poly.h
4156 views
/* ============================================================================12recurrences_zn_poly.h: header for recurrences_zn_poly.cpp34This file is part of hypellfrob (version 2.1.1).56Copyright (C) 2007, 2008, David Harvey78This program is free software; you can redistribute it and/or modify9it under the terms of the GNU General Public License as published by10the Free Software Foundation; either version 2 of the License, or11(at your option) any later version.1213This program is distributed in the hope that it will be useful,14but WITHOUT ANY WARRANTY; without even the implied warranty of15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16GNU General Public License for more details.1718You should have received a copy of the GNU General Public License along19with this program; if not, write to the Free Software Foundation, Inc.,2051 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.2122============================================================================ */232425#include <vector>26#include <NTL/ZZ.h>27#include <zn_poly/zn_poly.h>28293031namespace hypellfrob {323334/*35This struct stores precomputed information that can then be used to shift36evaluation values of a polynomial F(x) of degree d.3738Specifically, given the values39F(0), F(b), F(2*b), ..., F(d*b),40the shift() method computes41F(a), F(a + b), F(a + 2*b), ..., F(a + d*b).4243PRECONDITIONS:44d >= 0451, 2, ..., d + 1 are invertible46a + i*b are invertible for -d <= i <= d4748*/49struct Shifter50{51ulong d;5253// input_twist is a vector of length d + 1.54// The i-th entry is \prod_{0 <= j <= d, j != i} (i-j)^(-1).55// todo: this is symmetric, so can make it d/2 + 1, but need to56// deal with even/odd cases separately?57ulong* input_twist;5859// output_twist is a vector of length d + 1.60// The i-th entry is b^(-d) \prod_{0 <= j <= d} (a + (i-j)*b).61ulong* output_twist;6263// precomputed info for performing middle product against a "kernel"64// polynomial of degree 2d. The coefficients of "kernel" are65// (a + k*b)^(-1) for -d <= k <= d.66zn_array_mulmid_precomp1_t kernel_precomp;6768// Scratch space for shift(), length d + 169ulong* scratch;7071// zn_poly modulus object72const zn_mod_struct* mod;7374~Shifter();7576// Constructor (performs various precomputations)77Shifter(ulong d, ulong a, ulong b, const zn_mod_t mod);7879// Shifts evaluation values as described above.80// Assumes both output and input have length d + 1.81void shift(ulong* output, const ulong* input);82};838485/*86Grrr..... I would rather use vector<ulong>, but then strictly speaking87I can't be guaranteed that the data is stored in a simple array format,88so here I go rolling my own....89*/90struct ulong_array91{92ulong* data;9394ulong_array()95{96data = NULL;97}9899ulong_array(ulong amount)100{101data = (ulong*) malloc(sizeof(ulong) * amount);102}103104~ulong_array()105{106if (data)107free(data);108}109110void resize(ulong amount)111{112if (data)113data = (ulong*) realloc(data, sizeof(ulong) * amount);114else115data = (ulong*) malloc(sizeof(ulong) * amount);116}117};118119120121int check_params(ulong k, ulong u, const zn_mod_t mod);122123124125struct LargeEvaluator126{127int r;128ulong k, u, k2, odd;129const std::vector<std::vector<ulong> >& M0;130const std::vector<std::vector<ulong> >& M1;131const zn_mod_t& mod;132Shifter* shifter;133std::vector<ulong_array> scratch;134135LargeEvaluator(int r, ulong k, ulong u,136const std::vector<std::vector<ulong> >& M0,137const std::vector<std::vector<ulong> >& M1,138const zn_mod_t& mod);139140~LargeEvaluator();141142void evaluate(int half, std::vector<ulong_array>& output, ulong offset);143void evaluate_all(std::vector<ulong_array>& output);144};145146147148int zn_poly_interval_products(149std::vector<std::vector<std::vector<ulong> > >& output,150const std::vector<std::vector<ulong> >& M0,151const std::vector<std::vector<ulong> >& M1,152const std::vector<NTL::ZZ>& target, const zn_mod_t& mod);153154155};156157// ----------------------- end of file158159160