forked from flintlib/flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmpz_poly.h
1013 lines (691 loc) · 35.9 KB
/
fmpz_poly.h
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=============================================================================
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
=============================================================================*/
/******************************************************************************
Copyright (C) 2006, 2007, 2008, 2009, 2010 William Hart
Copyright (C) 2009, 2011 Andy Novocin
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#ifndef FMPZ_POLY_H
#define FMPZ_POLY_H
#undef ulong /* interferes with system includes */
#include <stdio.h>
#define ulong unsigned long
#include <mpir.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "nmod_poly.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Type definitions *********************************************************/
typedef struct
{
fmpz * coeffs;
long alloc;
long length;
} fmpz_poly_struct;
typedef fmpz_poly_struct fmpz_poly_t[1];
typedef struct {
fmpz c;
fmpz_poly_struct *p;
long *exp;
long num;
long alloc;
} fmpz_poly_factor_struct;
typedef fmpz_poly_factor_struct fmpz_poly_factor_t[1];
/* Memory management ********************************************************/
void fmpz_poly_init(fmpz_poly_t poly);
void fmpz_poly_init2(fmpz_poly_t poly, long alloc);
void fmpz_poly_realloc(fmpz_poly_t poly, long alloc);
void fmpz_poly_fit_length(fmpz_poly_t poly, long len);
void fmpz_poly_clear(fmpz_poly_t poly);
void _fmpz_poly_normalise(fmpz_poly_t poly);
static __inline__
void _fmpz_poly_set_length(fmpz_poly_t poly, long newlen)
{
if (poly->length > newlen)
{
long i;
for (i = newlen; i < poly->length; i++)
_fmpz_demote(poly->coeffs + i);
}
poly->length = newlen;
}
/* Polynomial parameters ***************************************************/
static __inline__
long fmpz_poly_length(const fmpz_poly_t poly)
{
return poly->length;
}
static __inline__
long fmpz_poly_degree(const fmpz_poly_t poly)
{
return poly->length - 1;
}
/* Assignment and basic manipulation ***************************************/
void fmpz_poly_set(fmpz_poly_t poly1, const fmpz_poly_t poly2);
void fmpz_poly_set_ui(fmpz_poly_t poly, ulong c);
void fmpz_poly_set_si(fmpz_poly_t poly, long c);
void fmpz_poly_set_fmpz(fmpz_poly_t poly, const fmpz_t c);
void fmpz_poly_set_mpz(fmpz_poly_t poly, const mpz_t c);
int _fmpz_poly_set_str(fmpz * poly, const char * str);
int fmpz_poly_set_str(fmpz_poly_t poly, const char * str);
char * _fmpz_poly_get_str(const fmpz * poly, long len);
char * fmpz_poly_get_str(const fmpz_poly_t poly);
char * _fmpz_poly_get_str_pretty(const fmpz * poly, long len, const char * x);
char * fmpz_poly_get_str_pretty(const fmpz_poly_t poly, const char * x);
static __inline__
void fmpz_poly_zero(fmpz_poly_t poly)
{
_fmpz_poly_set_length(poly, 0);
}
static __inline__
void fmpz_poly_one(fmpz_poly_t poly)
{
fmpz_poly_set_ui(poly, 1UL);
}
void fmpz_poly_zero_coeffs(fmpz_poly_t poly, long i, long j);
void fmpz_poly_swap(fmpz_poly_t poly1, fmpz_poly_t poly2);
void _fmpz_poly_reverse(fmpz * res, const fmpz * poly, long len, long n);
void fmpz_poly_reverse(fmpz_poly_t res, const fmpz_poly_t poly, long n);
static __inline__
void fmpz_poly_truncate(fmpz_poly_t poly, long newlen)
{
if (poly->length > newlen)
{
long i;
for (i = newlen; i < poly->length; i++)
_fmpz_demote(poly->coeffs + i);
poly->length = newlen;
_fmpz_poly_normalise(poly);
}
}
/* Randomisation ***********************************************************/
void fmpz_poly_randtest(fmpz_poly_t f, flint_rand_t state,
long len, mp_bitcnt_t bits);
void fmpz_poly_randtest_unsigned(fmpz_poly_t f, flint_rand_t state,
long len, mp_bitcnt_t bits);
void fmpz_poly_randtest_not_zero(fmpz_poly_t f, flint_rand_t state,
long len, mp_bitcnt_t bits);
/* Getting and setting coefficients ****************************************/
long fmpz_poly_get_coeff_si(const fmpz_poly_t poly, long n);
void fmpz_poly_set_coeff_si(fmpz_poly_t poly, long n, long x);
ulong fmpz_poly_get_coeff_ui(const fmpz_poly_t poly, long n);
void fmpz_poly_set_coeff_ui(fmpz_poly_t poly, long n, ulong x);
void fmpz_poly_set_coeff_fmpz(fmpz_poly_t poly, long n, const fmpz_t x);
void fmpz_poly_get_coeff_fmpz(fmpz_t x, const fmpz_poly_t poly, long n);
#define fmpz_poly_get_coeff_ptr(poly, n) \
((n) < (poly)->length ? (poly)->coeffs + (n) : NULL)
#define fmpz_poly_lead(poly) \
((poly)->length ? (poly)->coeffs + (poly)->length - 1 : NULL)
/* Comparison **************************************************************/
int fmpz_poly_equal(const fmpz_poly_t poly1, const fmpz_poly_t poly2);
#define fmpz_poly_is_zero(poly) \
((poly)->length == 0)
static __inline__
int fmpz_poly_is_one(const fmpz_poly_t op)
{
return (op->length) == 1 && (*(op->coeffs) == 1L);
}
static __inline__
int fmpz_poly_is_unit(const fmpz_poly_t op)
{
return (op->length == 1) && (*(op->coeffs) == 1L || *(op->coeffs) == -1L);
}
/* Addition and subtraction ************************************************/
void _fmpz_poly_add(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_add(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
void _fmpz_poly_sub(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_sub(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
void fmpz_poly_neg(fmpz_poly_t res, const fmpz_poly_t poly);
/* Scalar multiplication and division **************************************/
void fmpz_poly_scalar_mul_ui(fmpz_poly_t poly1,
const fmpz_poly_t poly2, ulong x);
void fmpz_poly_scalar_mul_si(fmpz_poly_t poly1,
const fmpz_poly_t poly2, long x);
void fmpz_poly_scalar_mul_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x);
void fmpz_poly_scalar_addmul_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x);
void _fmpz_poly_scalar_submul_fmpz(fmpz * poly1,
const fmpz * poly2, long len2, const fmpz_t x);
void fmpz_poly_scalar_submul_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x);
void fmpz_poly_scalar_fdiv_ui(fmpz_poly_t poly1,
const fmpz_poly_t poly2, ulong x);
void fmpz_poly_scalar_fdiv_si(fmpz_poly_t poly1,
const fmpz_poly_t poly2, long x);
void fmpz_poly_scalar_fdiv_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x);
void fmpz_poly_scalar_tdiv_ui(fmpz_poly_t poly1,
const fmpz_poly_t poly2, ulong x);
void fmpz_poly_scalar_tdiv_si(fmpz_poly_t poly1,
const fmpz_poly_t poly2, long x);
void fmpz_poly_scalar_tdiv_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x);
void fmpz_poly_scalar_divexact_ui(fmpz_poly_t poly1,
const fmpz_poly_t poly2, ulong x);
void fmpz_poly_scalar_divexact_si(fmpz_poly_t poly1,
const fmpz_poly_t poly2, long x);
void fmpz_poly_scalar_divexact_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x);
static __inline__
void fmpz_poly_scalar_mod_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x)
{
if (poly2->length == 0)
{
fmpz_poly_zero(poly1);
}
else
{
fmpz_poly_fit_length(poly1, poly2->length);
_fmpz_vec_scalar_mod_fmpz(poly1->coeffs, poly2->coeffs, poly2->length, x);
_fmpz_poly_set_length(poly1, poly2->length);
_fmpz_poly_normalise(poly1);
}
}
static __inline__
void fmpz_poly_scalar_smod_fmpz(fmpz_poly_t poly1,
const fmpz_poly_t poly2, const fmpz_t x)
{
if (poly2->length == 0)
{
fmpz_poly_zero(poly1);
}
else
{
fmpz_poly_fit_length(poly1, poly2->length);
_fmpz_vec_scalar_smod_fmpz(poly1->coeffs, poly2->coeffs, poly2->length, x);
_fmpz_poly_set_length(poly1, poly2->length);
_fmpz_poly_normalise(poly1);
}
}
/* Bit packing *************************************************************/
void _fmpz_poly_bit_pack(mp_ptr arr, const fmpz * poly,
long len, mp_bitcnt_t bit_size, int negate);
int _fmpz_poly_bit_unpack(fmpz * poly, long len,
mp_srcptr arr, mp_bitcnt_t bit_size, int negate);
void _fmpz_poly_bit_unpack_unsigned(fmpz * poly, long len,
mp_srcptr arr, mp_bitcnt_t bit_size);
void fmpz_poly_bit_pack(fmpz_t f, const fmpz_poly_t poly,
mp_bitcnt_t bit_size);
void fmpz_poly_bit_unpack(fmpz_poly_t poly, const fmpz_t f,
mp_bitcnt_t bit_size);
void fmpz_poly_bit_unpack_unsigned(fmpz_poly_t poly, const fmpz_t f,
mp_bitcnt_t bit_size);
/* Multiplication **********************************************************/
void _fmpz_poly_mul_classical(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_mul_classical(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void _fmpz_poly_mullow_classical(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2, long n);
void fmpz_poly_mullow_classical(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2, long n);
void _fmpz_poly_mulhigh_classical(fmpz * res, const fmpz * poly1,
long len1, const fmpz * poly2, long len2, long start);
void fmpz_poly_mulhigh_classical(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long start);
void _fmpz_poly_mulmid_classical(fmpz * res, const fmpz * poly1,
long len1, const fmpz * poly2, long len2);
void fmpz_poly_mulmid_classical(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void fmpz_poly_mul_karatsuba(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void _fmpz_poly_mul_karatsuba(fmpz * res, const fmpz * poly1,
long len1, const fmpz * poly2, long len2);
void _fmpz_poly_mullow_karatsuba_n(fmpz * res, const fmpz * poly1,
const fmpz * poly2, long n);
void fmpz_poly_mullow_karatsuba_n(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long n);
void _fmpz_poly_mulhigh_karatsuba_n(fmpz * res, const fmpz * poly1,
const fmpz * poly2, long len);
void fmpz_poly_mulhigh_karatsuba_n(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long length);
void _fmpz_poly_mul_KS(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_mul_KS(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void _fmpz_poly_mullow_KS(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2, long n);
void fmpz_poly_mullow_KS(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2, long n);
void _fmpz_poly_mul_SS(fmpz * output, const fmpz * input1, long length1,
const fmpz * input2, long length2);
void fmpz_poly_mul_SS(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void _fmpz_poly_mullow_SS(fmpz * output, const fmpz * input1, long length1,
const fmpz * input2, long length2, long n);
void fmpz_poly_mullow_SS(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long n);
void _fmpz_poly_mul(fmpz * res, const fmpz * poly1,
long len1, const fmpz * poly2, long len2);
void fmpz_poly_mul(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void _fmpz_poly_mullow(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2, long n);
void fmpz_poly_mullow(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long n);
void fmpz_poly_mulhigh_n(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long n);
/* Squaring ******************************************************************/
void _fmpz_poly_sqr_KS(fmpz * rop, const fmpz * op, long len);
void fmpz_poly_sqr_KS(fmpz_poly_t rop, const fmpz_poly_t op);
void fmpz_poly_sqr_karatsuba(fmpz_poly_t rop, const fmpz_poly_t op);
void _fmpz_poly_sqr_karatsuba(fmpz * rop, const fmpz * op, long len);
void _fmpz_poly_sqr_classical(fmpz * rop, const fmpz * op, long len);
void fmpz_poly_sqr_classical(fmpz_poly_t rop, const fmpz_poly_t op);
void _fmpz_poly_sqr(fmpz * rop, const fmpz * op, long len);
void fmpz_poly_sqr(fmpz_poly_t rop, const fmpz_poly_t op);
void _fmpz_poly_sqrlow_KS(fmpz * res, const fmpz * poly, long len, long n);
void fmpz_poly_sqrlow_KS(fmpz_poly_t res, const fmpz_poly_t poly, long n);
void _fmpz_poly_sqrlow_karatsuba_n(fmpz * res, const fmpz * poly, long n);
void fmpz_poly_sqrlow_karatsuba_n(fmpz_poly_t res, const fmpz_poly_t poly, long n);
void _fmpz_poly_sqrlow_classical(fmpz * res, const fmpz * poly, long len, long n);
void fmpz_poly_sqrlow_classical(fmpz_poly_t res, const fmpz_poly_t poly, long n);
void _fmpz_poly_sqrlow(fmpz * res, const fmpz * poly, long len, long n);
void fmpz_poly_sqrlow(fmpz_poly_t res, const fmpz_poly_t poly, long n);
/* Powering ****************************************************************/
void _fmpz_poly_pow_multinomial(fmpz * res, const fmpz * poly, long len, ulong e);
void fmpz_poly_pow_multinomial(fmpz_poly_t res, const fmpz_poly_t poly, ulong e);
void _fmpz_poly_pow_binomial(fmpz * res, const fmpz * poly, ulong e);
void fmpz_poly_pow_binomial(fmpz_poly_t res, const fmpz_poly_t poly, ulong e);
void _fmpz_poly_pow_binexp(fmpz * res, const fmpz * poly, long len, ulong e);
void fmpz_poly_pow_binexp(fmpz_poly_t res, const fmpz_poly_t poly, ulong e);
void _fmpz_poly_pow_addchains(fmpz * res, const fmpz * poly, long len, const int * a, int n);
void fmpz_poly_pow_addchains(fmpz_poly_t res, const fmpz_poly_t poly, ulong e);
void _fmpz_poly_pow_small(fmpz * res, const fmpz * poly, long len, ulong e);
void _fmpz_poly_pow(fmpz * res, const fmpz * poly, long len, ulong e);
void fmpz_poly_pow(fmpz_poly_t res, const fmpz_poly_t poly, ulong e);
void _fmpz_poly_pow_trunc(fmpz * res, const fmpz * poly, ulong e, long n);
void
fmpz_poly_pow_trunc(fmpz_poly_t res, const fmpz_poly_t poly, ulong e, long n);
/* Shifting ****************************************************************/
void _fmpz_poly_shift_left(fmpz * res, const fmpz * poly, long len, long n);
void _fmpz_poly_shift_right(fmpz * res, const fmpz * poly, long len, long n);
void fmpz_poly_shift_left(fmpz_poly_t res, const fmpz_poly_t poly, long n);
void fmpz_poly_shift_right(fmpz_poly_t res, const fmpz_poly_t poly, long n);
/* Norms *******************************************************************/
void _fmpz_poly_2norm(fmpz_t res, const fmpz * poly, long len);
void fmpz_poly_2norm(fmpz_t res, const fmpz_poly_t poly);
mp_bitcnt_t _fmpz_poly_2norm_normalised_bits(const fmpz * poly, long len);
static __inline__
ulong fmpz_poly_max_limbs(const fmpz_poly_t poly)
{
return _fmpz_vec_max_limbs(poly->coeffs, poly->length);
}
static __inline__
long fmpz_poly_max_bits(const fmpz_poly_t poly)
{
return _fmpz_vec_max_bits(poly->coeffs, poly->length);
}
static __inline__ void
fmpz_poly_height(fmpz_t res, const fmpz_poly_t poly)
{
_fmpz_vec_height(res, poly->coeffs, poly->length);
}
/* Greatest common divisor *************************************************/
void _fmpz_poly_gcd_subresultant(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_gcd_subresultant(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
int _fmpz_poly_gcd_heuristic(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
int fmpz_poly_gcd_heuristic(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void _fmpz_poly_gcd_modular(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_gcd_modular(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
void _fmpz_poly_gcd(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_gcd(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
void _fmpz_poly_lcm(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_lcm(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
void _fmpz_poly_resultant(fmpz_t res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_resultant(fmpz_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
void _fmpz_poly_xgcd_modular(fmpz_t r, fmpz * s, fmpz * t,
const fmpz * poly1, long len1, const fmpz * poly2, long len2);
void fmpz_poly_xgcd_modular(fmpz_t r, fmpz_poly_t s, fmpz_poly_t t,
const fmpz_poly_t poly1, const fmpz_poly_t poly2);
static __inline__
void _fmpz_poly_xgcd(fmpz_t r, fmpz * s, fmpz * t,
const fmpz * poly1, long len1, const fmpz * poly2, long len2)
{
_fmpz_poly_xgcd_modular(r, s, t, poly1, len1, poly2, len2);
}
static __inline__
void fmpz_poly_xgcd(fmpz_t r, fmpz_poly_t s, fmpz_poly_t t,
const fmpz_poly_t poly1, const fmpz_poly_t poly2)
{
fmpz_poly_xgcd_modular(r, s, t, poly1, poly2);
}
/* Gaussian content ********************************************************/
void _fmpz_poly_content(fmpz_t res, const fmpz * poly, long len);
void fmpz_poly_content(fmpz_t res, const fmpz_poly_t poly);
void _fmpz_poly_primitive_part(fmpz * res, const fmpz * poly, long len);
void fmpz_poly_primitive_part(fmpz_poly_t res, const fmpz_poly_t poly);
/* Euclidean division ******************************************************/
void _fmpz_poly_divrem_basecase(fmpz * Q, fmpz * R, const fmpz * A,
long lenA, const fmpz * B, long lenB);
void fmpz_poly_divrem_basecase(fmpz_poly_t Q, fmpz_poly_t R,
const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_divrem_divconquer_recursive(fmpz * Q, fmpz * BQ, fmpz * W,
const fmpz * A, const fmpz * B, long lenB);
void _fmpz_poly_divrem_divconquer(fmpz * Q, fmpz * R,
const fmpz * A, long lenA, const fmpz * B, long lenB);
void fmpz_poly_divrem_divconquer(fmpz_poly_t Q, fmpz_poly_t R,
const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_divrem(fmpz * Q, fmpz * R, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_divrem(fmpz_poly_t Q, fmpz_poly_t R, const fmpz_poly_t A,
const fmpz_poly_t B);
void _fmpz_poly_div_basecase(fmpz * Q, fmpz * R, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_div_basecase(fmpz_poly_t Q,
const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_divremlow_divconquer_recursive(fmpz * Q, fmpz * QB,
const fmpz * A, const fmpz * B, long lenB);
void _fmpz_poly_div_divconquer_recursive(fmpz * Q, fmpz * temp,
const fmpz * A, const fmpz * B, long lenB);
void _fmpz_poly_div_divconquer(fmpz * Q, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_div_divconquer(fmpz_poly_t Q,
const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_div(fmpz * Q, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_div(fmpz_poly_t Q, const fmpz_poly_t A,
const fmpz_poly_t B);
void _fmpz_poly_rem_basecase(fmpz * Q, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_rem_basecase(fmpz_poly_t R,
const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_rem(fmpz * R, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_rem(fmpz_poly_t R, const fmpz_poly_t A, const fmpz_poly_t B);
void
fmpz_poly_div_root(fmpz_poly_t Q, const fmpz_poly_t A, const fmpz_t c);
void
_fmpz_poly_div_root(fmpz * Q, const fmpz * A, long len, const fmpz_t c);
/* Power series division ***************************************************/
void _fmpz_poly_inv_series_newton(fmpz * Qinv, const fmpz * Q, long n);
void fmpz_poly_inv_series_newton(fmpz_poly_t Qinv, const fmpz_poly_t Q, long n);
static __inline__ void
_fmpz_poly_inv_series(fmpz * Qinv, const fmpz * Q, long n)
{
_fmpz_poly_inv_series_newton(Qinv, Q, n);
}
static __inline__ void
fmpz_poly_inv_series(fmpz_poly_t Qinv, const fmpz_poly_t Q, long n)
{
fmpz_poly_inv_series_newton(Qinv, Q, n);
}
void _fmpz_poly_div_series(fmpz * Q, const fmpz * A, const fmpz * B, long n);
void fmpz_poly_div_series(fmpz_poly_t Q, const fmpz_poly_t A,
const fmpz_poly_t B, long n);
/* Divisibility testing ***************************************************/
int _fmpz_poly_divides(fmpz * q, const fmpz * a,
long len1, const fmpz * b, long len2);
int fmpz_poly_divides(fmpz_poly_t q, const fmpz_poly_t a, const fmpz_poly_t b);
/* Pseudo division *********************************************************/
void _fmpz_poly_pseudo_divrem_basecase(fmpz * Q, fmpz * R, ulong * d,
const fmpz * A, long A_len, const fmpz * B, long B_len);
void fmpz_poly_pseudo_divrem_basecase(fmpz_poly_t Q, fmpz_poly_t R,
ulong * d, const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_pseudo_divrem_divconquer(fmpz * Q, fmpz * R, ulong * d,
const fmpz * A, long lenA, const fmpz * B, long lenB);
void fmpz_poly_pseudo_divrem_divconquer(fmpz_poly_t Q, fmpz_poly_t R,
ulong * d, const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_pseudo_divrem_cohen(fmpz * Q, fmpz * R, const fmpz * A,
long lenA, const fmpz * B, long lenB);
void fmpz_poly_pseudo_divrem_cohen(fmpz_poly_t Q, fmpz_poly_t R,
const fmpz_poly_t A, const fmpz_poly_t B);
void _fmpz_poly_pseudo_rem_cohen(fmpz * R, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_pseudo_rem_cohen(fmpz_poly_t R, const fmpz_poly_t A,
const fmpz_poly_t B);
static __inline__
void _fmpz_poly_pseudo_divrem(fmpz * Q, fmpz * R, ulong * d,
const fmpz * A, long A_len, const fmpz * B, long B_len)
{
_fmpz_poly_pseudo_divrem_basecase(Q, R, d, A, A_len, B, B_len);
}
static __inline__
void fmpz_poly_pseudo_divrem(fmpz_poly_t Q, fmpz_poly_t R,
ulong * d, const fmpz_poly_t A, const fmpz_poly_t B)
{
fmpz_poly_pseudo_divrem_basecase(Q, R, d, A, B);
}
void _fmpz_poly_pseudo_div(fmpz * Q, ulong * d, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_pseudo_div(fmpz_poly_t Q, ulong * d, const fmpz_poly_t A,
const fmpz_poly_t B);
void _fmpz_poly_pseudo_rem(fmpz * R, ulong * d, const fmpz * A, long lenA,
const fmpz * B, long lenB);
void fmpz_poly_pseudo_rem(fmpz_poly_t R, ulong * d, const fmpz_poly_t A,
const fmpz_poly_t B);
/* Derivative **************************************************************/
void _fmpz_poly_derivative(fmpz * rpoly, const fmpz * poly, long len);
void fmpz_poly_derivative(fmpz_poly_t res, const fmpz_poly_t poly);
/* Evaluation **************************************************************/
void
_fmpz_poly_evaluate_divconquer_fmpz(fmpz_t res, const fmpz * poly, long len,
const fmpz_t a);
void fmpz_poly_evaluate_divconquer_fmpz(fmpz_t res, const fmpz_poly_t poly,
const fmpz_t a);
void _fmpz_poly_evaluate_horner_fmpz(fmpz_t res, const fmpz * f, long len,
const fmpz_t a);
void fmpz_poly_evaluate_horner_fmpz(fmpz_t res, const fmpz_poly_t f,
const fmpz_t a);
void _fmpz_poly_evaluate_fmpz(fmpz_t res, const fmpz * f, long len, const fmpz_t a);
void fmpz_poly_evaluate_fmpz(fmpz_t res, const fmpz_poly_t f, const fmpz_t a);
void _fmpz_poly_evaluate_horner_mpq(fmpz_t rnum, fmpz_t rden,
const fmpz * f, long len,
const fmpz_t anum, const fmpz_t aden);
void fmpz_poly_evaluate_horner_mpq(mpq_t res, const fmpz_poly_t f,
const mpq_t a);
void _fmpz_poly_evaluate_mpq(fmpz_t rnum, fmpz_t rden,
const fmpz * f, long len,
const fmpz_t anum, const fmpz_t aden);
void fmpz_poly_evaluate_mpq(mpq_t res, const fmpz_poly_t f, const mpq_t a);
mp_limb_t _fmpz_poly_evaluate_mod(const fmpz * poly, long len, mp_limb_t a,
mp_limb_t n, mp_limb_t ninv);
mp_limb_t fmpz_poly_evaluate_mod(const fmpz_poly_t poly, mp_limb_t a,
mp_limb_t n);
void
_fmpz_poly_evaluate_divconquer(fmpz * res, const fmpz * poly, long len,
const fmpz_t x);
void
fmpz_poly_evaluate_divconquer(fmpz_t res,
const fmpz_poly_t poly, const fmpz_t x);
/* Composition *************************************************************/
void _fmpz_poly_compose_horner(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_compose_horner(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
void _fmpz_poly_compose_divconquer(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_compose_divconquer(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
void _fmpz_poly_compose(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2);
void fmpz_poly_compose(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_poly_t poly2);
/* Power series composition and compositional inverse **********************/
void
_fmpz_poly_compose_series_brent_kung(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2, long n);
void
fmpz_poly_compose_series_brent_kung(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long n);
void
_fmpz_poly_compose_series_horner(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2, long n);
void
fmpz_poly_compose_series_horner(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long n);
void
_fmpz_poly_compose_series(fmpz * res, const fmpz * poly1, long len1,
const fmpz * poly2, long len2, long n);
void
fmpz_poly_compose_series(fmpz_poly_t res,
const fmpz_poly_t poly1, const fmpz_poly_t poly2, long n);
void
_fmpz_poly_revert_series_lagrange(fmpz * Qinv, const fmpz * Q, long n);
void
fmpz_poly_revert_series_lagrange(fmpz_poly_t Qinv, const fmpz_poly_t Q, long n);
void
_fmpz_poly_revert_series_lagrange_fast(fmpz * Qinv, const fmpz * Q, long n);
void
fmpz_poly_revert_series_lagrange_fast(fmpz_poly_t Qinv,
const fmpz_poly_t Q, long n);
void
_fmpz_poly_revert_series_newton(fmpz * Qinv, const fmpz * Q, long n);
void
fmpz_poly_revert_series_newton(fmpz_poly_t Qinv, const fmpz_poly_t Q, long n);
void
_fmpz_poly_revert_series(fmpz * Qinv, const fmpz * Q, long n);
void
fmpz_poly_revert_series(fmpz_poly_t Qinv, const fmpz_poly_t Q, long n);
/* Signature ***************************************************************/
void _fmpz_poly_signature(long * r1, long * r2, fmpz * poly, long len);
void fmpz_poly_signature(long * r1, long * r2, fmpz_poly_t poly);
/* Input and output ********************************************************/
int fmpz_poly_fprint(FILE * file, const fmpz_poly_t poly);
int _fmpz_poly_fprint_pretty(FILE * file,
const fmpz * poly, long len, const char * x);
int fmpz_poly_fprint_pretty(FILE * file,
const fmpz_poly_t poly, const char * x);
static __inline__
int fmpz_poly_print(const fmpz_poly_t poly)
{
return fmpz_poly_fprint(stdout, poly);
}
static __inline__
int fmpz_poly_print_pretty(const fmpz_poly_t poly, const char * x)
{
return fmpz_poly_fprint_pretty(stdout, poly, x);
}
int fmpz_poly_fread(FILE * file, fmpz_poly_t poly);
int fmpz_poly_fread_pretty(FILE *file, fmpz_poly_t poly, char **x);
static __inline__
int fmpz_poly_read(fmpz_poly_t poly)
{
return fmpz_poly_fread(stdin, poly);
}
static __inline__
int fmpz_poly_read_pretty(fmpz_poly_t poly, char **x)
{
return fmpz_poly_fread_pretty(stdin, poly, x);
}
static __inline__
void fmpz_poly_debug(const fmpz_poly_t poly)
{
printf("(alloc = %ld, length = %ld, vec = ", poly->alloc, poly->length);
if (poly->coeffs)
{
printf("{");
_fmpz_vec_print(poly->coeffs, poly->alloc);
printf("}");
}
else
{
printf("NULL");
}
printf(")");
fflush(stdout);
}
/* CRT ********************************************************************/
void fmpz_poly_get_nmod_poly(nmod_poly_t res, const fmpz_poly_t poly);
void fmpz_poly_set_nmod_poly(fmpz_poly_t res, const nmod_poly_t poly);
void fmpz_poly_set_nmod_poly_unsigned(fmpz_poly_t res, const nmod_poly_t poly);
void
_fmpz_poly_CRT_ui_precomp(fmpz * res, const fmpz * poly1, long len1,
const fmpz_t m1, mp_srcptr poly2, long len2, mp_limb_t m2,
mp_limb_t m2inv, fmpz_t m1m2, mp_limb_t c, int sign);
void _fmpz_poly_CRT_ui(fmpz * res, const fmpz * poly1, long len1,
const fmpz_t m1, mp_srcptr poly2, long len2, mp_limb_t m2,
mp_limb_t m2inv, int sign);
void fmpz_poly_CRT_ui(fmpz_poly_t res, const fmpz_poly_t poly1,
const fmpz_t m1, const nmod_poly_t poly2,
int sign);
/* Products *****************************************************************/
void _fmpz_poly_product_roots_fmpz_vec(fmpz * poly,
const fmpz * xs, long n);
void fmpz_poly_product_roots_fmpz_vec(fmpz_poly_t poly,
const fmpz * xs, long n);
/* Multipoint evaluation and interpolation *********************************/
void
fmpz_poly_evaluate_fmpz_vec(fmpz * res, const fmpz_poly_t f,
const fmpz * a, long n);
void
fmpz_poly_interpolate_fmpz_vec(fmpz_poly_t poly,
const fmpz * xs, const fmpz * ys, long n);
/* Hensel lifting ************************************************************/
void fmpz_poly_hensel_build_tree(long * link, fmpz_poly_t *v, fmpz_poly_t *w,
const nmod_poly_factor_t fac);
void fmpz_poly_hensel_lift(fmpz_poly_t Gout, fmpz_poly_t Hout,
fmpz_poly_t Aout, fmpz_poly_t Bout,
const fmpz_poly_t f,
const fmpz_poly_t g, const fmpz_poly_t h,
const fmpz_poly_t a, const fmpz_poly_t b,
const fmpz_t p, const fmpz_t p1);
void _fmpz_poly_hensel_lift_without_inverse(fmpz *G, fmpz *H,
const fmpz *f, long lenF,
const fmpz *g, long lenG, const fmpz *h, long lenH,
const fmpz *a, long lenA, const fmpz *b, long lenB,
const fmpz_t p, const fmpz_t p1);
void fmpz_poly_hensel_lift_without_inverse(fmpz_poly_t Gout, fmpz_poly_t Hout,
const fmpz_poly_t f, const fmpz_poly_t g, const fmpz_poly_t h,
const fmpz_poly_t a, const fmpz_poly_t b,
const fmpz_t p, const fmpz_t p1);
void _fmpz_poly_hensel_lift_only_inverse(fmpz *A, fmpz *B,
const fmpz *G, long lenG, const fmpz *H, long lenH,
const fmpz *a, long lenA, const fmpz *b, long lenB,
const fmpz_t p, const fmpz_t p1);
void fmpz_poly_hensel_lift_only_inverse(fmpz_poly_t Aout, fmpz_poly_t Bout,
const fmpz_poly_t G, const fmpz_poly_t H,
const fmpz_poly_t a, const fmpz_poly_t b,
const fmpz_t p, const fmpz_t p1);
void fmpz_poly_hensel_lift_tree_recursive(long *link,
fmpz_poly_t *v, fmpz_poly_t *w, fmpz_poly_t f, long j, long inv,
const fmpz_t p0, const fmpz_t p1);
void fmpz_poly_hensel_lift_tree(long *link, fmpz_poly_t *v, fmpz_poly_t *w,
fmpz_poly_t f, long r, const fmpz_t p, long e0, long e1, long inv);
long _fmpz_poly_hensel_start_lift(fmpz_poly_factor_t lifted_fac, long *link,
fmpz_poly_t *v, fmpz_poly_t *w, const fmpz_poly_t f,
const nmod_poly_factor_t local_fac, long target_exp);
long _fmpz_poly_hensel_continue_lift(fmpz_poly_factor_t lifted_fac,