00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #ifndef FMPQ_POLY_H
00012 #define FMPQ_POLY_H
00013
00014 #ifdef __cplusplus
00015 extern "C" {
00016 #endif
00017
00018 #include <stdio.h>
00019 #include <gmp.h>
00020
00021 #include "fmpz.h"
00022 #include "fmpz_poly.h"
00023
00040 typedef struct
00041 {
00042 fmpz_poly_t num;
00043 fmpz_t den;
00044 } fmpq_poly_struct;
00045
00053 typedef fmpq_poly_struct fmpq_poly_t[1];
00054
00059 typedef fmpq_poly_struct * fmpq_poly_ptr;
00060
00061 void fmpq_poly_canonicalize(fmpq_poly_ptr f, fmpz_t temp);
00062
00064
00066
00068
00069
00077 #define fmpq_poly_numref(op) ((op)->num)
00078
00086 #define fmpq_poly_denref(op) ((op)->den)
00087
00089
00090
00100 static inline
00101 void fmpq_poly_init(fmpq_poly_ptr rop)
00102 {
00103 fmpz_poly_init(rop->num);
00104 rop->den = fmpz_init(1ul);
00105 fmpz_set_ui(rop->den, 1ul);
00106 }
00107
00116 static inline
00117 void fmpq_poly_clear(fmpq_poly_ptr rop)
00118 {
00119 fmpz_poly_clear(rop->num);
00120 fmpz_clear(rop->den);
00121 }
00122
00124
00125
00131 static inline
00132 void fmpq_poly_set(fmpq_poly_ptr rop, const fmpq_poly_ptr op)
00133 {
00134 if (rop != op)
00135 {
00136 fmpz_poly_set(rop->num, op->num);
00137
00138 rop->den = fmpz_realloc(rop->den, fmpz_size(op->den));
00139 fmpz_set(rop->den, op->den);
00140 }
00141 }
00142
00148 static inline
00149 void fmpq_poly_set_si(fmpq_poly_ptr rop, long op)
00150 {
00151 fmpz_poly_zero(rop->num);
00152 fmpz_poly_set_coeff_si(rop->num, 0, op);
00153 fmpz_set_ui(rop->den, 1ul);
00154 }
00155
00161 static inline
00162 void fmpq_poly_set_fmpz(fmpq_poly_ptr rop, const fmpz_t x)
00163 {
00164 fmpz_poly_zero(rop->num);
00165 fmpz_poly_set_coeff_fmpz(rop->num, 0, x);
00166 fmpz_set_ui(rop->den, 1ul);
00167 }
00168
00174 static inline
00175 void fmpq_poly_set_mpz(fmpq_poly_ptr rop, const mpz_t x)
00176 {
00177 fmpz_poly_zero(rop->num);
00178 fmpz_poly_set_coeff_mpz(rop->num, 0, x);
00179 fmpz_set_ui(rop->den, 1ul);
00180 }
00181
00188 static inline
00189 void fmpq_poly_set_mpq(fmpq_poly_ptr rop, const mpq_t x)
00190 {
00191 fmpz_poly_zero(rop->num);
00192 fmpz_poly_set_coeff_mpz(rop->num, 0, mpq_numref(x));
00193 rop->den = fmpz_realloc(rop->den, mpz_size(mpq_denref(x)));
00194 mpz_to_fmpz(rop->den, mpq_denref(x));
00195 }
00196
00204 static inline
00205 void fmpq_poly_swap(fmpq_poly_ptr op1, fmpq_poly_ptr op2)
00206 {
00207 if (op1 != op2)
00208 {
00209 fmpz_t t;
00210 fmpz_poly_swap(op1->num, op2->num);
00211 t = op1->den;
00212 op1->den = op2->den;
00213 op2->den = t;
00214 }
00215 }
00216
00222 static inline
00223 void fmpq_poly_zero(fmpq_poly_ptr rop)
00224 {
00225 fmpz_poly_zero(rop->num);
00226 fmpz_set_ui(rop->den, 1ul);
00227 }
00228
00234 static inline
00235 void fmpq_poly_one(fmpq_poly_ptr rop)
00236 {
00237 fmpz_poly_zero(rop->num);
00238 fmpz_poly_set_coeff_si(rop->num, 0, 1);
00239 fmpz_set_ui(rop->den, 1ul);
00240 }
00241
00242 void fmpq_poly_neg(fmpq_poly_ptr rop, const fmpq_poly_ptr op);
00243 void fmpq_poly_inv(fmpq_poly_ptr rop, const fmpq_poly_ptr op);
00244
00246
00247
00248 void fmpq_poly_get_coeff_mpq(mpq_t rop, const fmpq_poly_ptr op, ulong i);
00249
00250 void fmpq_poly_set_coeff_fmpz(fmpq_poly_ptr rop, ulong i, const fmpz_t x);
00251 void fmpq_poly_set_coeff_mpz(fmpq_poly_ptr rop, ulong i, const mpz_t x);
00252 void fmpq_poly_set_coeff_mpq(fmpq_poly_ptr rop, ulong i, const mpq_t x);
00253 void fmpq_poly_set_coeff_si(fmpq_poly_ptr rop, ulong i, long x);
00254
00256
00257
00264 static inline
00265 int fmpq_poly_is_zero(const fmpq_poly_ptr op)
00266 {
00267 return op->num->length == 0ul;
00268 }
00269
00277 static inline
00278 int fmpq_poly_is_one(const fmpq_poly_ptr op)
00279 {
00280 return (op->num->length == 1ul) && fmpz_is_one(op->num->coeffs)
00281 && fmpz_is_one(op->den);
00282 }
00283
00284 int fmpq_poly_equal(const fmpq_poly_ptr op1, const fmpq_poly_ptr op2);
00285 int fmpq_poly_cmp(const fmpq_poly_ptr left, const fmpq_poly_ptr right);
00286
00288
00289
00296 static inline
00297 ulong fmpq_poly_length(const fmpq_poly_ptr op)
00298 {
00299 return op->num->length;
00300 }
00301
00307 static inline
00308 long fmpq_poly_degree(const fmpq_poly_ptr op)
00309 {
00310 return (long) (op->num->length - 1ul);
00311 }
00312
00314
00315
00316 void fmpq_poly_add(fmpq_poly_ptr rop, const fmpq_poly_ptr op1, const fmpq_poly_ptr op2);
00317 void fmpq_poly_sub(fmpq_poly_ptr rop, const fmpq_poly_ptr op1, const fmpq_poly_ptr op2);
00318
00319 void fmpq_poly_addmul(fmpq_poly_ptr rop, const fmpq_poly_ptr op1, const fmpq_poly_ptr op2);
00320 void fmpq_poly_submul(fmpq_poly_ptr rop, const fmpq_poly_ptr op1, const fmpq_poly_ptr op2);
00321
00323
00324
00325 void fmpq_poly_scalar_mul_si(fmpq_poly_ptr rop, const fmpq_poly_ptr op, long x);
00326 void fmpq_poly_scalar_mul_mpz(fmpq_poly_ptr rop, const fmpq_poly_ptr op, const mpz_t x);
00327 void fmpq_poly_scalar_mul_mpq(fmpq_poly_ptr rop, const fmpq_poly_ptr op, const mpq_t x);
00328
00329 void fmpq_poly_scalar_div_si(fmpq_poly_ptr rop, const fmpq_poly_ptr op, long x);
00330 void fmpq_poly_scalar_div_mpz(fmpq_poly_ptr rop, const fmpq_poly_ptr op, const mpz_t x);
00331 void fmpq_poly_scalar_div_mpq(fmpq_poly_ptr rop, const fmpq_poly_ptr op, const mpq_t x);
00332
00334
00335
00336 void fmpq_poly_mul(fmpq_poly_ptr rop, const fmpq_poly_ptr op1, const fmpq_poly_ptr op2);
00337
00339
00340
00341 void fmpq_poly_floordiv(fmpq_poly_ptr q, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00342 void fmpq_poly_mod(fmpq_poly_ptr r, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00343 void fmpq_poly_divrem(fmpq_poly_ptr q, fmpq_poly_ptr r, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00344
00345 void fmpq_poly_inv_series(fmpq_poly_ptr rop, const fmpq_poly_ptr op, long n);
00346
00347 void fmpq_poly_div_series(fmpq_poly_ptr rop, const fmpq_poly_ptr op1,
00348 const fmpq_poly_ptr op2, long n);
00349
00351
00352
00353 void fmpq_poly_power(fmpq_poly_ptr rop, const fmpq_poly_ptr op, ulong exp);
00354
00356
00357
00358 void fmpq_poly_gcd(fmpq_poly_ptr rop, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00359 void fmpq_poly_xgcd(fmpq_poly_ptr rop, fmpq_poly_ptr s, fmpq_poly_ptr t, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00360 void fmpq_poly_lcm(fmpq_poly_ptr rop, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00361
00363
00364
00365 void fmpq_poly_derivative(fmpq_poly_ptr rop, fmpq_poly_ptr op);
00366
00368
00369
00370 void fmpq_poly_evaluate_mpz(mpq_t rop, fmpq_poly_ptr f, const mpz_t a);
00371 void fmpq_poly_evaluate_mpq(mpq_t rop, fmpq_poly_ptr f, const mpq_t a);
00372
00374
00375
00376 void fmpq_poly_content(mpq_t rop, const fmpq_poly_ptr op);
00377 void fmpq_poly_primitive_part(fmpq_poly_ptr rop, const fmpq_poly_ptr op);
00378 int fmpq_poly_is_monic(const fmpq_poly_ptr op);
00379 void fmpq_poly_monic(fmpq_poly_ptr rop, const fmpq_poly_ptr op);
00380
00382
00383
00384 void fmpq_poly_resultant(mpq_t rop, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00385 void fmpq_poly_discriminant(mpq_t disc, fmpq_poly_t a);
00386
00388
00389
00390 void fmpq_poly_compose(fmpq_poly_ptr rop, const fmpq_poly_ptr a, const fmpq_poly_ptr b);
00391 void fmpq_poly_rescale(fmpq_poly_ptr rop, const fmpq_poly_ptr op, const mpq_t x);
00392
00394
00395
00396 int fmpq_poly_is_squarefree(const fmpq_poly_ptr op);
00397
00399
00400
00401 void fmpq_poly_getslice(fmpq_poly_ptr rop, const fmpq_poly_ptr op, ulong i, ulong j);
00402 void fmpq_poly_left_shift(fmpq_poly_ptr rop, const fmpq_poly_ptr op, ulong n);
00403 void fmpq_poly_right_shift(fmpq_poly_ptr rop, const fmpq_poly_ptr op, ulong n);
00404 void fmpq_poly_truncate(fmpq_poly_ptr rop, const fmpq_poly_ptr op, ulong n);
00405 void fmpq_poly_reverse(fmpq_poly_ptr rop, const fmpq_poly_ptr op, ulong n);
00406
00408
00409
00410 void fmpq_poly_from_list(fmpq_poly_ptr rop, mpq_t *a, ulong n);
00411
00412 int fmpq_poly_from_string(fmpq_poly_ptr rop, const char *s);
00413 char * fmpq_poly_to_string(const fmpq_poly_ptr op);
00414 char * fmpq_poly_to_string_pretty(const fmpq_poly_ptr op, const char *x);
00415 void fmpq_poly_print(const fmpq_poly_ptr op);
00416 void fmpq_poly_print_pretty(const fmpq_poly_ptr op, const char *x);
00417
00418 #ifdef __cplusplus
00419 }
00420 #endif
00421
00422 #endif
00423