This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
nf_elem.h
780 lines (623 loc) · 24.2 KB
/
nf_elem.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
/*=============================================================================
This file is part of Antic.
Antic is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
=============================================================================*/
/******************************************************************************
Copyright (C) 2013 William Hart
******************************************************************************/
#ifndef NF_ELEM_H
#define NF_ELEM_H
#ifdef NF_ELEM_INLINES_C
#define NF_ELEM_INLINE ANTIC_DLL
#else
#define NF_ELEM_INLINE static __inline__
#endif
#include "gmp.h"
#include "flint/flint.h"
#include "flint/fmpq_poly.h"
#include "flint/fmpq_mat.h"
#include "flint/fmpz_mat.h"
#include "flint/fmpz_mod_poly.h"
#include "nf.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct /* element of a linear number field */
{
fmpz_t num;
fmpz_t den;
} lnf_elem_struct;
typedef lnf_elem_struct lnf_elem_t[1];
typedef struct /* element of a quadratic number field */
{
fmpz num[3]; /* extra coeff for delayed reduction */
fmpz_t den;
} qnf_elem_struct;
typedef qnf_elem_struct qnf_elem_t[1];
typedef union /* element in a number field (specified by an nf_t) */
{
fmpq_poly_t elem; /* general case */
lnf_elem_t lelem; /* linear number field */
qnf_elem_t qelem; /* quadratic number field */
} nf_elem_struct;
typedef nf_elem_struct nf_elem_t[1];
#define NF_ELEM_NUMREF(xxx) fmpq_poly_numref((xxx)->elem)
#define NF_ELEM_DENREF(xxx) fmpq_poly_denref((xxx)->elem)
#define LNF_ELEM_NUMREF(xxx) ((xxx)->lelem->num)
#define LNF_ELEM_DENREF(xxx) ((xxx)->lelem->den)
#define QNF_ELEM_NUMREF(xxx) ((xxx)->qelem->num)
#define QNF_ELEM_DENREF(xxx) ((xxx)->qelem->den)
#define NF_ELEM(xxx) (xxx)->elem
#define LNF_ELEM(xxx) (xxx)->lelem
#define QNF_ELEM(xxx) (xxx)->qelem
/******************************************************************************
Initialisation
******************************************************************************/
ANTIC_DLL void nf_elem_init(nf_elem_t a, const nf_t nf);
ANTIC_DLL void nf_elem_clear(nf_elem_t a, const nf_t nf);
ANTIC_DLL void nf_elem_randtest(nf_elem_t a, flint_rand_t state,
mp_bitcnt_t bits, const nf_t nf);
ANTIC_DLL void nf_elem_randtest_not_zero(nf_elem_t a, flint_rand_t state,
mp_bitcnt_t bits, const nf_t nf);
NF_ELEM_INLINE
void nf_elem_canonicalise(nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR) {
_fmpq_canonicalise(LNF_ELEM_NUMREF(a), LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
_fmpq_poly_canonicalise(QNF_ELEM_NUMREF(a), QNF_ELEM_DENREF(a), 3);
else
fmpq_poly_canonicalise(NF_ELEM(a));
}
ANTIC_DLL void _nf_elem_reduce(nf_elem_t a, const nf_t nf);
ANTIC_DLL void nf_elem_reduce(nf_elem_t a, const nf_t nf);
ANTIC_DLL int _nf_elem_invertible_check(nf_elem_t a, const nf_t nf);
/******************************************************************************
Comparison
******************************************************************************/
ANTIC_DLL int _nf_elem_equal(const nf_elem_t a, const nf_elem_t b, const nf_t nf);
ANTIC_DLL int nf_elem_equal(const nf_elem_t a, const nf_elem_t b, const nf_t nf);
NF_ELEM_INLINE
int nf_elem_is_zero(const nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
return fmpz_is_zero(LNF_ELEM_NUMREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
const fmpz * const anum = QNF_ELEM_NUMREF(a);
return fmpz_is_zero(anum) && fmpz_is_zero(anum + 1);
} else
return fmpq_poly_is_zero(a->elem);
}
NF_ELEM_INLINE
int nf_elem_is_one(const nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
return fmpz_is_one(LNF_ELEM_NUMREF(a)) && fmpz_is_one(LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
const fmpz * const anum = QNF_ELEM_NUMREF(a);
return fmpz_is_one(anum) && fmpz_is_zero(anum + 1)
&& fmpz_is_one(QNF_ELEM_DENREF(a));
} else
return fmpq_poly_is_one(a->elem);
}
ANTIC_DLL int nf_elem_is_gen(const nf_elem_t a, const nf_t nf);
NF_ELEM_INLINE
int nf_elem_is_integer(const nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
return fmpz_is_one(LNF_ELEM_DENREF(a));
else if (nf->flag & NF_QUADRATIC)
return fmpz_is_zero(QNF_ELEM_NUMREF(a) + 1) &&
fmpz_is_one(QNF_ELEM_DENREF(a));
else
return NF_ELEM(a)->length <= 1 && fmpz_is_one(NF_ELEM_DENREF(a));
}
NF_ELEM_INLINE
int nf_elem_is_rational(const nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR) return 1;
else if (nf->flag & NF_QUADRATIC)
return fmpz_is_zero(QNF_ELEM_NUMREF(a) + 1);
else
return NF_ELEM(a)->length <= 1;
}
NF_ELEM_INLINE
int nf_elem_equal_si(const nf_elem_t a, const slong b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
return fmpz_is_one(LNF_ELEM_DENREF(a)) &&
fmpz_equal_si(LNF_ELEM_NUMREF(a), b);
else if (nf->flag & NF_QUADRATIC)
return fmpz_is_zero(QNF_ELEM_NUMREF(a) + 1) &&
fmpz_is_one(QNF_ELEM_DENREF(a)) &&
fmpz_equal_si(QNF_ELEM_NUMREF(a), b);
else
{
if (b == 0) return fmpq_poly_is_zero(NF_ELEM(a));
else return NF_ELEM(a)->length == 1 &&
fmpz_is_one(NF_ELEM_DENREF(a)) &&
fmpz_equal_si(NF_ELEM_NUMREF(a), b);
}
}
NF_ELEM_INLINE
int nf_elem_equal_ui(const nf_elem_t a, const ulong b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
return fmpz_is_one(LNF_ELEM_DENREF(a)) &&
fmpz_equal_ui(LNF_ELEM_NUMREF(a), b);
else if (nf->flag & NF_QUADRATIC)
return fmpz_is_zero(QNF_ELEM_NUMREF(a) + 1) &&
fmpz_is_one(QNF_ELEM_DENREF(a)) &&
fmpz_equal_ui(QNF_ELEM_NUMREF(a), b);
else
{
if (b == 0) return fmpq_poly_is_zero(NF_ELEM(a));
else return NF_ELEM(a)->length == 1 &&
fmpz_is_one(NF_ELEM_DENREF(a)) &&
fmpz_equal_ui(NF_ELEM_NUMREF(a), b);
}
}
NF_ELEM_INLINE
int nf_elem_equal_fmpz(const nf_elem_t a, const fmpz_t b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
return fmpz_is_one(LNF_ELEM_DENREF(a)) && fmpz_equal(LNF_ELEM_NUMREF(a), b);
else if (nf->flag & NF_QUADRATIC)
return fmpz_is_zero(QNF_ELEM_NUMREF(a) + 1) &&
fmpz_is_one(QNF_ELEM_DENREF(a)) &&
fmpz_equal(QNF_ELEM_NUMREF(a), b);
else
{
if (NF_ELEM(a)->length == 0)
return fmpz_is_zero(b);
else if (NF_ELEM(a)->length == 1)
return fmpz_is_one(NF_ELEM_DENREF(a)) &&
fmpz_equal(NF_ELEM_NUMREF(a), b);
else
return 0;
}
}
NF_ELEM_INLINE
int nf_elem_equal_fmpq(const nf_elem_t a, const fmpq_t b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
return fmpz_equal(LNF_ELEM_NUMREF(a), fmpq_numref(b)) &&
fmpz_equal(LNF_ELEM_DENREF(a), fmpq_denref(b));
else if (nf->flag & NF_QUADRATIC)
return fmpz_is_zero(QNF_ELEM_NUMREF(a) + 1) &&
fmpz_equal(QNF_ELEM_NUMREF(a), fmpq_numref(b)) &&
fmpz_equal(QNF_ELEM_DENREF(a), fmpq_denref(b)) ;
else
{
if (NF_ELEM(a)->length == 0)
return fmpq_is_zero(b);
else if (NF_ELEM(a)->length == 1)
return fmpz_equal(NF_ELEM_NUMREF(a), fmpq_numref(b)) &&
fmpz_equal(NF_ELEM_DENREF(a), fmpq_denref(b));
else
return 0;
}
}
/******************************************************************************
I/O
******************************************************************************/
ANTIC_DLL void nf_elem_print_pretty(const nf_elem_t a,
const nf_t nf, const char * var);
ANTIC_DLL char * nf_elem_get_str_pretty(const nf_elem_t a,
const char * var, const nf_t nf);
/******************************************************************************
Element creation
******************************************************************************/
NF_ELEM_INLINE
void nf_elem_zero(nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_zero(LNF_ELEM_NUMREF(a));
fmpz_one(LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz_zero(anum);
fmpz_zero(anum + 1);
fmpz_one(QNF_ELEM_DENREF(a));
} else
fmpq_poly_zero(NF_ELEM(a));
}
NF_ELEM_INLINE
void nf_elem_one(nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_one(LNF_ELEM_NUMREF(a));
fmpz_one(LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz_one(anum);
fmpz_zero(anum + 1);
fmpz_one(QNF_ELEM_DENREF(a));
} else
fmpq_poly_one(NF_ELEM(a));
}
NF_ELEM_INLINE
void nf_elem_gen(nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_neg(LNF_ELEM_NUMREF(a), nf->pol->coeffs);
fmpz_set(LNF_ELEM_DENREF(a), nf->pol->coeffs + 1);
_fmpq_canonicalise(LNF_ELEM_NUMREF(a), LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz_one(anum + 1);
fmpz_zero(anum);
fmpz_one(QNF_ELEM_DENREF(a));
} else
{
fmpq_poly_zero(NF_ELEM(a));
fmpq_poly_set_coeff_ui(NF_ELEM(a), 1, 1);
}
}
NF_ELEM_INLINE
void nf_elem_set_si(nf_elem_t a, slong c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_set_si(LNF_ELEM_NUMREF(a), c);
fmpz_one(LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz_set_si(anum, c);
fmpz_zero(anum + 1);
fmpz_one(QNF_ELEM_DENREF(a));
} else
fmpq_poly_set_si(NF_ELEM(a), c);
}
NF_ELEM_INLINE
void nf_elem_set_ui(nf_elem_t a, ulong c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_set_ui(LNF_ELEM_NUMREF(a), c);
fmpz_one(LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz_set_ui(anum, c);
fmpz_zero(anum + 1);
fmpz_one(QNF_ELEM_DENREF(a));
} else
fmpq_poly_set_ui(NF_ELEM(a), c);
}
NF_ELEM_INLINE
void nf_elem_set_fmpz(nf_elem_t a, const fmpz_t c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_set(LNF_ELEM_NUMREF(a), c);
fmpz_one(LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz_set(anum, c);
fmpz_zero(anum + 1);
fmpz_one(QNF_ELEM_DENREF(a));
} else
fmpq_poly_set_fmpz(NF_ELEM(a), c);
}
NF_ELEM_INLINE
void nf_elem_set_fmpq(nf_elem_t a, const fmpq_t c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_set(LNF_ELEM_NUMREF(a), fmpq_numref(c));
fmpz_set(LNF_ELEM_DENREF(a), fmpq_denref(c));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz_set(anum, fmpq_numref(c));
fmpz_zero(anum + 1);
fmpz_set(QNF_ELEM_DENREF(a), fmpq_denref(c));
} else
fmpq_poly_set_fmpq(NF_ELEM(a), c);
}
ANTIC_DLL void nf_elem_set_fmpq_poly(nf_elem_t a, const fmpq_poly_t pol, const nf_t nf);
/******************************************************************************
Conversion
******************************************************************************/
ANTIC_DLL
void nf_elem_set_fmpz_mat_row(nf_elem_t b, const fmpz_mat_t M,
const slong i, fmpz_t den, const nf_t nf);
ANTIC_DLL
void nf_elem_get_fmpz_mat_row(fmpz_mat_t M, const slong i, fmpz_t den,
const nf_elem_t b, const nf_t nf);
FLINT_DLL
void nf_elem_get_fmpq_poly(fmpq_poly_t pol, const nf_elem_t a, const nf_t nf);
ANTIC_DLL
void _nf_elem_get_nmod_poly(nmod_poly_t pol, const nf_elem_t a, const nf_t nf);
ANTIC_DLL
void nf_elem_get_nmod_poly_den(nmod_poly_t pol,
const nf_elem_t a, const nf_t nf, int den);
ANTIC_DLL
void nf_elem_get_nmod_poly(nmod_poly_t pol, const nf_elem_t a, const nf_t nf);
#if __FLINT_RELEASE >= 20700
ANTIC_DLL
void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol,
const nf_elem_t a, const nf_t nf, const fmpz_mod_ctx_t ctx);
ANTIC_DLL
void nf_elem_get_fmpz_mod_poly_den(fmpz_mod_poly_t pol,
const nf_elem_t a, const nf_t nf, int den, const fmpz_mod_ctx_t ctx);
ANTIC_DLL
void nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol,
const nf_elem_t a, const nf_t nf, const fmpz_mod_ctx_t ctx);
#else
ANTIC_DLL
void _nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf);
ANTIC_DLL
void nf_elem_get_fmpz_mod_poly_den(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf, int den);
ANTIC_DLL
void nf_elem_get_fmpz_mod_poly(fmpz_mod_poly_t pol, const nf_elem_t a, const nf_t nf);
#endif
/******************************************************************************
Basic manipulation
******************************************************************************/
NF_ELEM_INLINE
void nf_elem_get_den(fmpz_t d, const nf_elem_t b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_set(d, LNF_ELEM_DENREF(b));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz_set(d, QNF_ELEM_DENREF(b));
} else
{
fmpz_set(d, NF_ELEM_DENREF(b));
}
}
NF_ELEM_INLINE
void nf_elem_set_den(nf_elem_t b, fmpz_t d, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_set(LNF_ELEM_DENREF(b), d);
} else if (nf->flag & NF_QUADRATIC)
{
fmpz_set(QNF_ELEM_DENREF(b), d);
} else
{
fmpz_set(NF_ELEM_DENREF(b), d);
}
}
ANTIC_DLL
void nf_elem_get_coeff_fmpq(fmpq_t a, const nf_elem_t b, slong i, const nf_t nf);
ANTIC_DLL
void nf_elem_get_coeff_fmpz(fmpz_t a, const nf_elem_t b, slong i, const nf_t nf);
NF_ELEM_INLINE
int nf_elem_den_is_one(const nf_elem_t a, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
return fmpz_is_one(LNF_ELEM_DENREF(a));
} else if (nf->flag & NF_QUADRATIC)
{
return fmpz_is_one(QNF_ELEM_DENREF(a));
} else
{
return fmpz_is_one(NF_ELEM_DENREF(a));
}
}
ANTIC_DLL
void _nf_elem_set_coeff_num_fmpz(nf_elem_t a, slong i, const fmpz_t b, const nf_t nf);
/******************************************************************************
Arithmetic
******************************************************************************/
NF_ELEM_INLINE
void nf_elem_set(nf_elem_t a, const nf_elem_t b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_set(LNF_ELEM_NUMREF(a), LNF_ELEM_NUMREF(b));
fmpz_set(LNF_ELEM_DENREF(a), LNF_ELEM_DENREF(b));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
const fmpz * const bnum = QNF_ELEM_NUMREF(b);
fmpz_set(anum, bnum);
fmpz_set(anum + 1, bnum + 1);
fmpz_set(QNF_ELEM_DENREF(a), QNF_ELEM_DENREF(b));
} else
fmpq_poly_set(NF_ELEM(a), NF_ELEM(b));
}
NF_ELEM_INLINE
void nf_elem_neg(nf_elem_t a, const nf_elem_t b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_neg(LNF_ELEM_NUMREF(a), LNF_ELEM_NUMREF(b));
fmpz_set(LNF_ELEM_DENREF(a), LNF_ELEM_DENREF(b));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
const fmpz * const bnum = QNF_ELEM_NUMREF(b);
fmpz_neg(anum, bnum);
fmpz_neg(anum + 1, bnum + 1);
fmpz_set(QNF_ELEM_DENREF(a), QNF_ELEM_DENREF(b));
} else
fmpq_poly_neg(NF_ELEM(a), NF_ELEM(b));
}
NF_ELEM_INLINE
void nf_elem_swap(nf_elem_t a, nf_elem_t b, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
{
fmpz_swap(LNF_ELEM_NUMREF(a), LNF_ELEM_NUMREF(b));
fmpz_swap(LNF_ELEM_DENREF(a), LNF_ELEM_DENREF(b));
} else if (nf->flag & NF_QUADRATIC)
{
fmpz * const anum = QNF_ELEM_NUMREF(a);
fmpz * const bnum = QNF_ELEM_NUMREF(b);
fmpz_swap(anum, bnum);
fmpz_swap(anum + 1, bnum + 1);
fmpz_swap(anum + 2, bnum + 2);
fmpz_swap(QNF_ELEM_DENREF(a), QNF_ELEM_DENREF(b));
} else
fmpq_poly_swap(NF_ELEM(a), NF_ELEM(b));
}
ANTIC_DLL void nf_elem_add_si(nf_elem_t a,
const nf_elem_t b, slong c, const nf_t nf);
ANTIC_DLL void nf_elem_add_fmpz(nf_elem_t a,
const nf_elem_t b, const fmpz_t c, const nf_t nf);
ANTIC_DLL void nf_elem_add_fmpq(nf_elem_t a,
const nf_elem_t b, const fmpq_t c, const nf_t nf);
ANTIC_DLL void nf_elem_sub_si(nf_elem_t a,
const nf_elem_t b, slong c, const nf_t nf);
ANTIC_DLL void nf_elem_sub_fmpz(nf_elem_t a,
const nf_elem_t b, const fmpz_t c, const nf_t nf);
ANTIC_DLL void nf_elem_sub_fmpq(nf_elem_t a,
const nf_elem_t b, const fmpq_t c, const nf_t nf);
ANTIC_DLL void nf_elem_si_sub(nf_elem_t a,
slong c, const nf_elem_t b, const nf_t nf);
ANTIC_DLL void nf_elem_fmpz_sub(nf_elem_t a,
const fmpz_t c, const nf_elem_t b, const nf_t nf);
ANTIC_DLL void nf_elem_fmpq_sub(nf_elem_t a,
const fmpq_t c, const nf_elem_t b, const nf_t nf);
ANTIC_DLL void nf_elem_scalar_mul_si(nf_elem_t a, const nf_elem_t b,
slong c, const nf_t nf);
ANTIC_DLL void nf_elem_scalar_mul_fmpz(nf_elem_t a, const nf_elem_t b,
const fmpz_t c, const nf_t nf);
ANTIC_DLL void nf_elem_scalar_mul_fmpq(nf_elem_t a, const nf_elem_t b,
const fmpq_t c, const nf_t nf);
ANTIC_DLL void nf_elem_scalar_div_si(nf_elem_t a, const nf_elem_t b,
slong c, const nf_t nf);
ANTIC_DLL void nf_elem_scalar_div_fmpz(nf_elem_t a, const nf_elem_t b,
const fmpz_t c, const nf_t nf);
ANTIC_DLL void nf_elem_scalar_div_fmpq(nf_elem_t a, const nf_elem_t b,
const fmpq_t c, const nf_t nf);
ANTIC_DLL void _nf_elem_add_lf(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf, int can);
ANTIC_DLL void _nf_elem_sub_lf(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf, int can);
ANTIC_DLL void _nf_elem_add_qf(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf, int can);
ANTIC_DLL void _nf_elem_sub_qf(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf, int can);
ANTIC_DLL void nf_elem_add_qf(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf);
ANTIC_DLL void nf_elem_sub_qf(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf);
NF_ELEM_INLINE
void _nf_elem_add(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
_nf_elem_add_lf(a, b, c, nf, 0);
else if (nf->flag & NF_QUADRATIC)
_nf_elem_add_qf(a, b, c, nf, 0);
else
fmpq_poly_add_can(NF_ELEM(a), NF_ELEM(b), NF_ELEM(c), 0);
}
NF_ELEM_INLINE
void _nf_elem_sub(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
_nf_elem_sub_lf(a, b, c, nf, 0);
else if (nf->flag & NF_QUADRATIC)
_nf_elem_sub_qf(a, b, c, nf, 0);
else
fmpq_poly_sub_can(NF_ELEM(a), NF_ELEM(b), NF_ELEM(c), 0);
}
NF_ELEM_INLINE
void nf_elem_add(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
_nf_elem_add_lf(a, b, c, nf, 1);
else if (nf->flag & NF_QUADRATIC)
nf_elem_add_qf(a, b, c, nf);
else
fmpq_poly_add_can(NF_ELEM(a), NF_ELEM(b), NF_ELEM(c), 1);
}
NF_ELEM_INLINE
void nf_elem_sub(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf)
{
if (nf->flag & NF_LINEAR)
_nf_elem_sub_lf(a, b, c, nf, 1);
else if (nf->flag & NF_QUADRATIC)
nf_elem_sub_qf(a, b, c, nf);
else
fmpq_poly_sub_can(NF_ELEM(a), NF_ELEM(b), NF_ELEM(c), 1);
}
FLINT_DLL void nf_elem_mul_gen(nf_elem_t a, const nf_elem_t b, const nf_t nf);
ANTIC_DLL void _nf_elem_mul(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf);
ANTIC_DLL void nf_elem_mul(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf);
ANTIC_DLL void _nf_elem_mul_red(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf, int red);
ANTIC_DLL void nf_elem_mul_red(nf_elem_t a, const nf_elem_t b,
const nf_elem_t c, const nf_t nf, int red);
ANTIC_DLL void _nf_elem_inv(nf_elem_t a, const nf_elem_t b, const nf_t nf);
ANTIC_DLL void nf_elem_inv(nf_elem_t a, const nf_elem_t b, const nf_t nf);
ANTIC_DLL void _nf_elem_div(nf_elem_t a, const nf_elem_t b, const nf_elem_t c, const nf_t nf);
ANTIC_DLL void nf_elem_div(nf_elem_t a, const nf_elem_t b, const nf_elem_t c, const nf_t nf);
ANTIC_DLL void _nf_elem_pow(nf_elem_t res, const nf_elem_t b, ulong e, const nf_t nf);
ANTIC_DLL void nf_elem_pow(nf_elem_t res, const nf_elem_t a, ulong e, const nf_t nf);
ANTIC_DLL void _nf_elem_norm(fmpz_t rnum, fmpz_t rden, const nf_elem_t a, const nf_t nf);
ANTIC_DLL void nf_elem_norm(fmpq_t res, const nf_elem_t a, const nf_t nf);
ANTIC_DLL void _nf_elem_norm_div(fmpz_t rnum, fmpz_t rden, const nf_elem_t a,
const nf_t nf, const fmpz_t divisor, slong nbits);
ANTIC_DLL void nf_elem_norm_div(fmpq_t res, const nf_elem_t a, const nf_t nf,
const fmpz_t divisor, slong nbits);
ANTIC_DLL void _nf_elem_trace(fmpz_t rnum, fmpz_t rden, const nf_elem_t a,
const nf_t nf);
ANTIC_DLL void nf_elem_trace(fmpq_t res, const nf_elem_t a, const nf_t nf);
ANTIC_DLL void nf_elem_rep_mat(fmpq_mat_t res, const nf_elem_t a, const nf_t nf);
ANTIC_DLL void nf_elem_rep_mat_fmpz_mat_den(fmpz_mat_t res, fmpz_t den, const nf_elem_t a, const nf_t nf);
/******************************************************************************
Modular reduction
******************************************************************************/
ANTIC_DLL
void _nf_elem_mod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf, int sign);
ANTIC_DLL
void nf_elem_mod_fmpz_den(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf, int den);
ANTIC_DLL
void nf_elem_smod_fmpz_den(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf, int den);
ANTIC_DLL
void nf_elem_mod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf);
ANTIC_DLL
void nf_elem_smod_fmpz(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf);
ANTIC_DLL
void nf_elem_coprime_den(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf);
ANTIC_DLL
void nf_elem_coprime_den_signed(nf_elem_t res, const nf_elem_t a, const fmpz_t mod, const nf_t nf);
#ifdef __cplusplus
}
#endif
/******************************************************************************
Helpers for compatibility with FLINT 2.6
******************************************************************************/
#if __FLINT_RELEASE >= 20700
#define FMPZ_MOD_POLY_FIT_LENGTH(POL, N, CTX) fmpz_mod_poly_fit_length(POL, N, CTX)
#define FMPZ_MOD(F, G, CTX, P) fmpz_mod(F, G, (CTX)->n)
#define FMPZ_MOD_POLY_ZERO(POL, CTX) fmpz_mod_poly_zero(POL, CTX)
#define FMPZ_MOD_POLY_SCALAR_DIV_FMPZ(RES, POL, X, CTX) fmpz_mod_poly_scalar_div_fmpz(RES, POL, X, CTX)
#else
#define FMPZ_MOD_POLY_FIT_LENGTH(POL, N, CTX) fmpz_mod_poly_fit_length(POL, N)
#define FMPZ_MOD(F, G, CTX, P) fmpz_mod(F, G, P)
#define FMPZ_MOD_POLY_ZERO(POL, CTX) fmpz_mod_poly_zero(POL)
#define FMPZ_MOD_POLY_SCALAR_DIV_FMPZ(RES, POL, X, CTX) fmpz_mod_poly_scalar_div_fmpz(RES, POL, X)
#endif
#endif