/usr/include/FLINT/mpz_poly.h is in libflint-dev 1.011-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | /*============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===============================================================================*/
/******************************************************************************
mpz_poly.h: Polynomials over Z, implemented as an array of mpz_t's
Copyright (C) 2007, William Hart and David Harvey
******************************************************************************/
#ifndef MPZ_POLY_H
#define MPZ_POLY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
#include "memory-manager.h"
#include "fmpz_poly.h"
typedef struct
{
mpz_t* coeffs;
unsigned long alloc;
unsigned long length;
} mpz_poly_struct;
// mpz_poly_t allows reference-like semantics for mpz_poly_struct:
typedef mpz_poly_struct mpz_poly_t[1];
// for some functions it's convenient to trick the compiler into letting us
// swap input argument pointers; we use mpz_poly_p for this
typedef mpz_poly_struct* mpz_poly_p;
#define SWAP_MPZ_POLY_PTRS(x, y) \
do { \
mpz_poly_p zzz_ptr = (x); \
(x) = (y); \
(y) = zzz_ptr; \
} while (0);
// ------------------------------------------------------
// Initialisation and memory management
void mpz_poly_init(mpz_poly_t poly);
void mpz_poly_clear(mpz_poly_t poly);
void mpz_poly_init2(mpz_poly_t poly, unsigned long alloc);
void mpz_poly_init3(mpz_poly_t poly, unsigned long alloc, unsigned long bits);
void mpz_poly_realloc(mpz_poly_t poly, unsigned long alloc);
// _bits_ only applies to newly allocated coefficients, not existing ones...
void mpz_poly_realloc2(mpz_poly_t poly, unsigned long alloc,
unsigned long bits);
// this non-inlined version REQUIRES that alloc > poly->alloc
void __mpz_poly_ensure_alloc(mpz_poly_t poly, unsigned long alloc);
// this is arranged so that the initial comparison (very frequent) is inlined,
// but the actual allocation (infrequent) is not
static inline
void mpz_poly_ensure_alloc(mpz_poly_t poly, unsigned long alloc)
{
if (alloc > poly->alloc)
__mpz_poly_ensure_alloc(poly, alloc);
}
// ------------------------------------------------------
// Setting/retrieving coefficients
static inline
mpz_t* mpz_poly_coeff_ptr(mpz_poly_t poly, unsigned long n)
{
if (n >= poly->length)
return NULL;
return &poly->coeffs[n];
}
static inline
void mpz_poly_get_coeff(mpz_t c, mpz_poly_t poly, unsigned long n)
{
if (n >= poly->length)
mpz_set_ui(c, 0);
else
mpz_set(c, poly->coeffs[n]);
}
static inline
unsigned long mpz_poly_get_coeff_ui(mpz_poly_t poly, unsigned long n)
{
if (n >= poly->length)
return 0;
return mpz_get_ui(poly->coeffs[n]);
}
static inline
long mpz_poly_get_coeff_si(mpz_poly_t poly, unsigned long n)
{
if (n >= poly->length)
return 0;
return mpz_get_si(poly->coeffs[n]);
}
void mpz_poly_set_coeff(mpz_poly_t poly, unsigned long n, mpz_t c);
void mpz_poly_set_coeff_ui(mpz_poly_t poly, unsigned long n, unsigned long c);
void mpz_poly_set_coeff_si(mpz_poly_t poly, unsigned long n, long c);
static inline
mpz_t* _mpz_poly_get_coeff_ptr(mpz_poly_t poly, unsigned long n)
{
return poly->coeffs + n;
}
static inline
void _mpz_poly_get_coeff(mpz_t c, mpz_poly_t poly, unsigned long n)
{
mpz_set(c, poly->coeffs[n]);
}
static inline
unsigned long _mpz_poly_get_coeff_ui(mpz_poly_t poly, unsigned long n)
{
return mpz_get_ui(poly->coeffs[n]);
}
static inline
long _mpz_poly_get_coeff_si(mpz_poly_t poly, unsigned long n)
{
return mpz_get_si(poly->coeffs[n]);
}
static inline
void _mpz_poly_set_coeff(mpz_poly_t poly, unsigned long n, mpz_t c)
{
mpz_set(poly->coeffs[n], c);
}
static inline
void _mpz_poly_set_coeff_ui(mpz_poly_t poly, unsigned long n, unsigned long c)
{
mpz_set_ui(poly->coeffs[n], c);
}
static inline
void _mpz_poly_set_coeff_si(mpz_poly_t poly, unsigned long n, long c)
{
mpz_set_si(poly->coeffs[n], c);
}
// ------------------------------------------------------
// String conversions and I/O
int mpz_poly_from_string(mpz_poly_t poly, const char* s);
char* mpz_poly_to_string(mpz_poly_t poly);
void mpz_poly_print(mpz_poly_t poly);
void mpz_poly_fprint(mpz_poly_t poly, FILE* f);
int mpz_poly_read(mpz_poly_t poly);
int mpz_poly_fread(mpz_poly_t poly, FILE* f);
char* mpz_poly_to_string_pretty(mpz_poly_t poly, const char * x);
void mpz_poly_fprint_pretty(mpz_poly_t poly, FILE* f, const char * x);
void mpz_poly_print_pretty(mpz_poly_t poly, const char * x);
// ------------------------------------------------------
// Length and degree
void mpz_poly_normalise(mpz_poly_t poly);
int mpz_poly_normalised(mpz_poly_t poly);
void mpz_poly_pad(mpz_poly_t poly, unsigned long length);
void mpz_poly_truncate(mpz_poly_t res, mpz_poly_t poly, unsigned long length);
static inline
unsigned long mpz_poly_length(mpz_poly_t poly)
{
return poly->length;
}
static inline
long mpz_poly_degree(mpz_poly_t poly)
{
return (long) poly->length - 1;
}
// ------------------------------------------------------
// Assignment
void mpz_poly_set(mpz_poly_t res, mpz_poly_t poly);
static inline
void mpz_poly_zero(mpz_poly_t poly)
{
poly->length = 0;
}
static inline
void mpz_poly_swap(mpz_poly_t poly1, mpz_poly_t poly2)
{
mpz_t* temp1;
unsigned long temp2;
temp1 = poly2->coeffs;
poly2->coeffs = poly1->coeffs;
poly1->coeffs = temp1;
temp2 = poly1->alloc;
poly1->alloc = poly2->alloc;
poly2->alloc = temp2;
temp2 = poly1->length;
poly1->length = poly2->length;
poly2->length = temp2;
}
// ------------------------------------------------------
// Conversions
void mpz_poly_to_fmpz_poly(fmpz_poly_t res, mpz_poly_t poly);
void fmpz_poly_to_mpz_poly(mpz_poly_t res, const fmpz_poly_t poly);
// ------------------------------------------------------
// Comparison
int mpz_poly_equal(mpz_poly_t poly1, mpz_poly_t poly2);
// ------------------------------------------------------
// Addition/subtraction
void mpz_poly_add(mpz_poly_t res, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_sub(mpz_poly_t res, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_neg(mpz_poly_t res, mpz_poly_t poly);
// ------------------------------------------------------
// Shifting
void mpz_poly_lshift(mpz_poly_t res, mpz_poly_t poly, unsigned long k);
void mpz_poly_rshift(mpz_poly_t res, mpz_poly_t poly, unsigned long k);
static inline
void mpz_poly_shift(mpz_poly_t res, mpz_poly_t poly, long k)
{
if (k >= 0)
mpz_poly_lshift(res, poly, k);
else
mpz_poly_rshift(res, poly, -k);
}
//-------------------------------------------------------
// Norms
void mpz_poly_2norm(mpz_t norm, mpz_poly_t poly);
// ------------------------------------------------------
// Scalar multiplication and division
void mpz_poly_scalar_mul(mpz_poly_t res, mpz_poly_t poly, mpz_t c);
void mpz_poly_scalar_mul_ui(mpz_poly_t res, mpz_poly_t poly, unsigned long c);
void mpz_poly_scalar_mul_si(mpz_poly_t res, mpz_poly_t poly, long c);
void mpz_poly_scalar_div(mpz_poly_t res, mpz_poly_t poly, mpz_t c);
void mpz_poly_scalar_div_ui(mpz_poly_t res, mpz_poly_t poly, unsigned long c);
void mpz_poly_scalar_div_si(mpz_poly_t res, mpz_poly_t poly, long c);
void mpz_poly_scalar_div_exact(mpz_poly_t res, mpz_poly_t poly, mpz_t c);
void mpz_poly_scalar_div_exact_ui(mpz_poly_t res, mpz_poly_t poly,
unsigned long c);
void mpz_poly_scalar_div_exact_si(mpz_poly_t res, mpz_poly_t poly, long c);
void mpz_poly_scalar_mod(mpz_poly_t res, mpz_poly_t poly, mpz_t c);
void mpz_poly_scalar_mod_ui(mpz_poly_t res, mpz_poly_t poly, unsigned long c);
// ------------------------------------------------------
// Polynomial multiplication
void mpz_poly_mul(mpz_poly_t res, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_mul_naive(mpz_poly_t res, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_mul_karatsuba(mpz_poly_t res, mpz_poly_t poly1,
mpz_poly_t poly2);
void mpz_poly_mul_SS(mpz_poly_t res, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_mul_naive_KS(mpz_poly_t res, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_sqr(mpz_poly_t res, mpz_poly_t poly);
void mpz_poly_sqr_naive(mpz_poly_t res, mpz_poly_t poly);
void mpz_poly_sqr_SS(mpz_poly_t res, mpz_poly_t poly);
void mpz_poly_sqr_karatsuba(mpz_poly_t res, mpz_poly_t poly);
void mpz_poly_sqr_naive_KS(mpz_poly_t res, mpz_poly_t poly);
// exported for profiling...
unsigned long _mpz_poly_mul_karatsuba_crossover(unsigned long limbs);
// ------------------------------------------------------
// Polynomial division
void mpz_poly_monic_inverse(mpz_poly_t res, mpz_poly_t poly, unsigned long k);
void mpz_poly_pseudo_inverse(mpz_poly_t res, mpz_poly_t poly, unsigned long k);
void mpz_poly_monic_div(mpz_poly_t quot, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_pseudo_div(mpz_poly_t quot, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_monic_rem(mpz_poly_t rem, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_pseudo_rem(mpz_poly_t rem, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_monic_div_rem(mpz_poly_t quot, mpz_poly_t rem,
mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_pseudo_div_rem(mpz_poly_t quot, mpz_poly_t rem,
mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_monic_inverse_naive(mpz_poly_t res, mpz_poly_t poly,
unsigned long k);
void mpz_poly_pseudo_inverse_naive(mpz_poly_t res, mpz_poly_t poly,
unsigned long k);
void mpz_poly_monic_div_naive(mpz_poly_t quot, mpz_poly_t poly1,
mpz_poly_t poly2);
void mpz_poly_pseudo_div_naive(mpz_poly_t quot, mpz_poly_t poly1,
mpz_poly_t poly2);
void mpz_poly_monic_rem_naive(mpz_poly_t rem, mpz_poly_t poly1,
mpz_poly_t poly2);
void mpz_poly_pseudo_rem_naive(mpz_poly_t rem, mpz_poly_t poly1,
mpz_poly_t poly2);
void mpz_poly_monic_div_rem_naive(mpz_poly_t quot, mpz_poly_t rem,
mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_pseudo_div_rem_naive(mpz_poly_t quot, mpz_poly_t rem,
mpz_poly_t poly1, mpz_poly_t poly2);
// ------------------------------------------------------
// GCD and extended GCD
void mpz_poly_content(mpz_t x, mpz_poly_t poly);
unsigned long mpz_poly_content_ui(mpz_poly_t poly);
void mpz_poly_gcd(mpz_poly_t res, mpz_poly_t poly1, mpz_poly_t poly2);
void mpz_poly_xgcd(mpz_poly_t res, mpz_poly_t a, mpz_poly_t b,
mpz_poly_t poly1, mpz_poly_t poly2);
// ------------------------------------------------------
// Miscellaneous
unsigned long mpz_poly_max_limbs(mpz_poly_t poly);
unsigned long mpz_poly_max_bits(mpz_poly_t poly);
unsigned long mpz_poly_product_max_limbs(mpz_poly_t poly1, mpz_poly_t poly2);
unsigned long mpz_poly_product_max_bits(mpz_poly_t poly1, mpz_poly_t poly2);
// ------------------------------------------------------
// Exported for testing only
void _mpz_poly_mul_kara_recursive(mpz_t* out,
mpz_t* in1, unsigned long len1, mpz_t* in2, unsigned long len2,
mpz_t* scratch, unsigned long skip, unsigned long crossover);
// *************** end of file
#ifdef __cplusplus
}
#endif
#endif
|