Macaulay2 Engine
Loading...
Searching...
No Matches
aring-translate.hpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
3#ifndef _aring_translate_hpp_
4#define _aring_translate_hpp_
5
43
45// Contains functions which are "ring translational" //
47
48#include "aring-RR.hpp"
49#include "aring-CC.hpp"
50#include "aring-RRR.hpp"
51#include "aring-CCC.hpp"
52#include "aring-RRi.hpp"
53#include "aring-CCi.hpp"
54#include "aring-zz-gmp.hpp"
55#include "aring-zzp.hpp"
56#include "aring-zzp-ffpack.hpp"
57#include "aring-qq.hpp"
58#include "aring-m2-gf.hpp"
59#include "aring-tower.hpp"
60
61// include flint headers last to avoid #1674
62#include "aring-zz-flint.hpp"
63#include "aring-zzp-flint.hpp"
65#include "aring-gf-flint.hpp"
66
67namespace M2 {
68template <typename RT>
69bool get_from_BigReal(const RT& R, typename RT::ElementType& a, gmp_RR b)
70{
71 (void) R;
72 (void) a;
73 (void) b;
74 return false;
75}
76
77template <typename RT>
78bool get_from_Interval(const RT& R, typename RT::ElementType& a, gmp_RRi b)
79{
80 (void) R;
81 (void) a;
82 (void) b;
83 return false;
84}
85
86template <typename RT>
87bool get_from_ComplexInterval(const RT& R, typename RT::ElementType & a, gmp_CCi b)
88{
89 return false;
90}
91
92template <typename RT>
93bool get_from_BigComplex(const RT& R, typename RT::ElementType& a, gmp_CC b)
94{
95 (void) R;
96 (void) a;
97 (void) b;
98 return false;
99}
100template <typename RT>
101bool get_from_double(const RT& R, typename RT::ElementType& a, double b)
102{
103 (void) R;
104 (void) a;
105 (void) b;
106 return false;
107}
108template <typename RT>
109bool get_from_complex_double(const RT& R,
110 typename RT::ElementType& a,
111 double re,
112 double im)
113{
114 (void) R;
115 (void) a;
116 (void) re;
117 (void) im;
118 return false;
119}
120
121inline bool get_from_BigReal(const ARingRR& R,
123 gmp_RR b)
124{
125 return R.set_from_BigReal(a, b);
126}
127
128inline bool get_from_BigReal(const ARingRRR& R,
130 gmp_RR b)
131{
132 return R.set_from_BigReal(a, b);
133}
134
135inline bool get_from_BigReal(const ARingRRi& R,
137 gmp_RR b)
138{
139 return R.set_from_BigReal(a, b);
140}
141
142inline bool get_from_BigReal(const ARingCC& R,
144 gmp_RR b)
145{
146 return R.set_from_BigReal(a, b);
147}
148
149inline bool get_from_BigReal(const ARingCCC& R,
151 gmp_RR b)
152{
153 return R.set_from_BigReal(a, b);
154}
155
156inline bool get_from_BigComplex(const ARingCCC& R,
158 gmp_CC b)
159{
160 return R.set_from_BigComplex(a, b);
161}
162
163inline bool get_from_BigComplex(const ARingCC& R,
165 gmp_CC b)
166{
167 return R.set_from_BigComplex(a, b);
168}
169
170inline bool get_from_double(const ARingRRR& R,
172 double b)
173{
174 return R.set_from_double(a, b);
175}
176
177inline bool get_from_double(const ARingRRi& R,
179 double b)
180{
181 return R.set_from_double(a, b);
182}
183
184inline bool get_from_Interval(const ARingRRi& R,
186 gmp_RRi b)
187{
188 return R.set_from_Interval(a, b);
189}
190
193 gmp_CCi b)
194{
195 R.set(a, b);
196 return true;
197}
198
199inline bool get_from_double(const ARingCCi& R,
201 double b)
202{
203 return R.set_from_double(a, b);
204}
205
206inline bool get_from_Interval(const ARingCCi& R,
208 gmp_RRi b)
209{
210 return R.set_from_Interval(a, b);
211}
212
213inline bool get_from_BigComplex(const ARingCCi& R,
215 gmp_CC b)
216{
217 return R.set_from_BigComplex(a, b);
218}
219
220inline bool get_from_BigReal(const ARingCCi& R,
222 gmp_RR b)
223{
224 return R.set_from_BigReal(a, b);
225}
226
227inline bool get_from_double(const ARingRR& R, ARingRR::ElementType& a, double b)
228{
229 return R.set_from_double(a, b);
230}
231
232inline bool get_from_double(const ARingCCC& R,
234 double b)
235{
236 return R.set_from_double(a, b);
237}
238
239inline bool get_from_double(const ARingCC& R, ARingCC::ElementType& a, double b)
240{
241 return R.set_from_double(a, b);
242}
243
246 double re,
247 double im)
248{
249 return R.set_from_complex_double(a, re, im);
250}
251
252inline bool get_from_complex_double(const ARingCC& R,
254 double re,
255 double im)
256{
257 return R.set_from_complex_double(a, re, im);
258}
259
262 double re,
263 double im)
264{
265 return R.set_from_complex_double(a, re, im);
266}
267
268// Promote an element of one ring to another.
269// Given a "natural and canonical" map R --> S (depends on the context)
270// and an element fR of R, set result_fS to be the image of fR under this map.
271// Return true if this was done, else return false.
272template <typename RingR, typename RingS>
273bool mypromote(const RingR& R,
274 const RingS& S,
275 const typename RingR::ElementType& fR,
276 typename RingS::ElementType& result_fS)
277{
278 (void) R;
279 (void) S;
280 (void) fR;
281 (void) result_fS;
282 return false;
283}
284template <typename RingR, typename RingS>
285bool mylift(const RingR& R,
286 const RingS& S,
287 typename RingR::ElementType& result_gR,
288 const typename RingS::ElementType& gS)
289{
290 (void) R;
291 (void) S;
292 (void) result_gR;
293 (void) gS;
294 return false;
295}
296
298inline bool mypromote(const ARingQQ& R,
299 const ARingRR& S,
300 const ARingQQ::ElementType& fR,
302{
303 (void) R;
304 return S.set_from_mpq(fS, &fR);
305}
306inline bool mypromote(const ARingQQ& R,
307 const ARingRRR& S,
308 const ARingQQ::ElementType& fR,
310{
311 (void) R;
312 return S.set_from_mpq(fS, &fR);
313}
314inline bool mypromote(const ARingQQ& R,
315 const ARingRRi& S,
316 const ARingQQ::ElementType& fR,
318{
319 (void) R;
320 return S.set_from_mpq(fS, &fR);
321}
322inline bool mypromote(const ARingQQ& R,
323 const ARingCC& S,
324 const ARingQQ::ElementType& fR,
326{
327 (void) R;
328 return S.set_from_mpq(fS, &fR);
329}
330inline bool mypromote(const ARingQQ& R,
331 const ARingCCC& S,
332 const ARingQQ::ElementType& fR,
334{
335 (void) R;
336 return S.set_from_mpq(fS, &fR);
337}
338
339inline bool mypromote(const ARingRR& R,
340 const ARingRR& S,
341 const ARingRR::ElementType& fR,
343{
344 (void) R;
345 S.set_from_double(fS, fR);
346 return true;
347}
348inline bool mypromote(const ARingRR& R,
349 const ARingRRR& S,
350 const ARingRR::ElementType& fR,
352{
353 (void) R;
354 S.set_from_double(fS, fR);
355 return true;
356}
357inline bool mypromote(const ARingRR& R,
358 const ARingCC& S,
359 const ARingRR::ElementType& fR,
361{
362 (void) R;
363 S.set_from_doubles(fS, fR, 0);
364 return true;
365}
366inline bool mypromote(const ARingRR& R,
367 const ARingCCC& S,
368 const ARingRR::ElementType& fR,
370{
371 (void) R;
372 S.set_from_doubles(fS, fR, 0);
373 return true;
374}
375
376inline bool mypromote(const ARingRRR& R,
377 const ARingRRR& S,
378 const ARingRRR::ElementType& fR,
380{
381 (void) R;
382 S.set(fS, fR);
383 return true;
384}
385inline bool mypromote(const ARingRRR& R,
386 const ARingRR& S,
387 const ARingRRR::ElementType& fR,
389{
390 (void) R;
391 auto fR1 = const_cast<ARingRRR::ElementType&>(fR);
392 S.set_from_BigReal(fS, &fR1);
393 return true;
394}
395
396inline bool mypromote(const ARingRRR& R,
397 const ARingCCC& S,
398 const ARingRRR::ElementType& fR,
400{
401 (void) R;
402 S.set_from_RRR(fS, fR);
403 return true;
404}
405inline bool mypromote(const ARingRRR& R,
406 const ARingCC& S,
407 const ARingRRR::ElementType& fR,
409{
410 (void) R;
411 auto fR1 = const_cast<ARingRRR::ElementType&>(fR);
412 S.set_from_BigReal(fS, &fR1);
413 return true;
414}
415
416inline bool mypromote(const ARingRRi& R,
417 const ARingRRi& S,
418 const ARingRRi::ElementType& fR,
420{
421 (void) R;
422 S.set(fS, fR);
423 return true;
424}
425inline bool mypromote(const ARingRR& R,
426 const ARingRRi& S,
427 const ARingRR::ElementType& fR,
429{
430 (void) R;
431 S.set_from_double(fS, fR);
432 return true;
433}
434inline bool mypromote(const ARingRRR& R,
435 const ARingRRi& S,
436 const ARingRRR::ElementType& fR,
438{
439 (void) R;
440 S.set_from_BigReal(fS, &fR);
441 return true;
442}
443
444inline bool mypromote(const ARingCC& R,
445 const ARingCC& S,
446 const ARingCC::ElementType& fR,
448{
449 (void) R;
450 S.set(fS, fR);
451 return true;
452}
453inline bool mypromote(const ARingCC& R,
454 const ARingCCC& S,
455 const ARingCC::ElementType& fR,
457{
458 (void) R;
459 S.set_from_complex_double(fS, fR.re, fR.im);
460 return true;
461}
462
463inline bool mypromote(const ARingCCC& R,
464 const ARingCC& S,
465 const ARingCCC::ElementType& fR,
467{
468 (void) R;
469 auto fR1 = const_cast<ARingCCC::ElementType&>(fR);
470 S.set_from_BigReals(fS, &fR1.re, &fR1.im);
471 return true;
472}
473inline bool mypromote(const ARingCCC& R,
474 const ARingCCC& S,
475 const ARingCCC::ElementType& fR,
477{
478 (void) R;
479 S.set(fS, fR);
480 return true;
481}
482
483inline bool mypromote(const ARingCCi& R,
484 const ARingCCi& S,
485 const ARingCCi::ElementType& fR,
487{
488 S.set(fS, fR);
489 return true;
490}
491inline bool mypromote(const ARingRR& R,
492 const ARingCCi& S,
493 const ARingRR::ElementType& fR,
495{
496 S.set_from_double(fS, fR);
497 return true;
498}
499
500inline bool mypromote(const ARingRRi& R,
501 const ARingCCi& S,
502 const ARingRRi::ElementType& fR,
504{
505 S.set_from_Interval(fS, &fR);
506 return true;
507}
508
509inline bool mypromote(const ARingRRR& R,
510 const ARingCCi& S,
511 const ARingRRR::ElementType& fR,
513{
514 S.set_from_BigReal(fS, &fR);
515 return true;
516}
517inline bool mypromote(const ARingCC& R,
518 const ARingCCi& S,
519 const ARingCC::ElementType& fR,
521{
522 S.set_from_complex_double(fS, fR.re, fR.im);
523 return true;
524}
525inline bool mypromote(const ARingCCC& R,
526 const ARingCCi& S,
527 const ARingCCC::ElementType& fR,
529{
530 S.set_from_BigComplex(fS, &fR);
531 return true;
532}
533
535inline bool mylift(const ARingRRR& R,
536 const ARingRR& S,
537 ARingRRR::ElementType& result_gR,
538 const ARingRR::ElementType& gS)
539{
540 (void) S;
541 R.set_from_double(result_gR, gS);
542 return true;
543}
544inline bool mylift(const ARingRRR& R,
545 const ARingRRR& S,
546 ARingRRR::ElementType& result_gR,
547 const ARingRRR::ElementType& gS)
548{
549 (void) S;
550 R.set(result_gR, gS);
551 return true;
552}
553inline bool mylift(const ARingRRR& R,
554 const ARingCCC& S,
555 ARingRRR::ElementType& result_gR,
556 const ARingCCC::ElementType& gS)
557{
558 R.set(result_gR, S.realPartReference(gS));
559 return (R.is_zero(S.imaginaryPartReference(gS)));
560}
561inline bool mylift(const ARingRRR& R,
562 const ARingCC& S,
563 ARingRRR::ElementType& result_gR,
564 const ARingCC::ElementType& gS)
565{
566 (void) S;
567 R.set_from_double(result_gR, gS.re);
568 return gS.im == 0;
569}
570
571inline bool mylift(const ARingRR& R,
572 const ARingRR& S,
573 ARingRR::ElementType& result_gR,
574 const ARingRR::ElementType& gS)
575{
576 (void) S;
577 R.set_from_double(result_gR, gS);
578 return true;
579}
580inline bool mylift(const ARingRR& R,
581 const ARingRRR& S,
582 ARingRR::ElementType& result_gR,
583 const ARingRRR::ElementType& gS)
584{
585 (void) S;
586 auto gS1 = const_cast<ARingRRR::ElementType&>(gS);
587 R.set_from_BigReal(result_gR, &gS1);
588 return true;
589}
590inline bool mylift(const ARingRR& R,
591 const ARingCCC& S,
592 ARingRR::ElementType& result_gR,
593 const ARingCCC::ElementType& gS)
594{
595 auto gS1 = const_cast<ARingRRR::ElementType&>(S.realPartReference(gS));
596 R.set_from_BigReal(result_gR, &gS1);
597 return (S.real_ring().is_zero(S.imaginaryPartReference(gS)));
598}
599inline bool mylift(const ARingRR& R,
600 const ARingCC& S,
601 ARingRR::ElementType& result_gR,
602 const ARingCC::ElementType& gS)
603{
604 (void) S;
605 R.set_from_double(result_gR, gS.re);
606 return gS.im == 0;
607}
608
609inline bool mylift(const ARingCCC& R,
610 const ARingCCC& S,
611 ARingCCC::ElementType& result_gR,
612 const ARingCCC::ElementType& gS)
613{
614 (void) S;
615 R.set(result_gR, gS);
616 return true;
617}
618inline bool mylift(const ARingCCC& R,
619 const ARingCC& S,
620 ARingCCC::ElementType& result_gR,
621 const ARingCC::ElementType& gS)
622{
623 (void) S;
624 R.set_from_complex_double(result_gR, gS.re, gS.im);
625 return true;
626}
627inline bool mylift(const ARingCC& R,
628 const ARingCCC& S,
629 ARingCC::ElementType& result_gR,
630 const ARingCCC::ElementType& gS)
631{
632 (void) S;
633 auto gS1 = const_cast<ARingCCC::ElementType&>(gS);
634 R.set_from_BigReals(result_gR, &gS1.re, &gS1.im);
635 return true;
636}
637inline bool mylift(const ARingCC& R,
638 const ARingCC& S,
639 ARingCC::ElementType& result_gR,
640 const ARingCC::ElementType& gS)
641{
642 (void) S;
643 R.set(result_gR, gS);
644 return true;
645}
646
648
649inline bool mylift(const ARingRR& R,
650 const ARingRRi& S,
651 ARingRR::ElementType& result_gR,
652 const ARingRRi::ElementType& gS)
653{
655 ARingRRR::Element gT(T);
656 auto gS1 = const_cast<ARingRRi::ElementType&>(gS);
657 S.midpoint(gT,gS1);
658 bool liftstep = mylift(R,T,result_gR,gT);
659 S.diameter(gT,gS1);
660 return liftstep && T.is_zero(gT);
661}
662
663inline bool mylift(const ARingRRR& R,
664 const ARingRRi& S,
665 ARingRRR::ElementType& result_gR,
666 const ARingRRi::ElementType& gS)
667{
669 ARingRRR::Element gT(T);
670 auto gS1 = const_cast<ARingRRi::ElementType&>(gS);
671 S.midpoint(gT,gS1);
672 bool liftstep = mylift(R,T,result_gR,gT);
673 S.diameter(gT,gS1);
674 return liftstep && T.is_zero(gT);
675}
676
677inline bool mylift(const ARingQQ& R,
678 const ARingRRi& S,
679 ARingQQ::ElementType& result_gR,
680 const ARingRRi::ElementType& gS)
681{
683 ARingRRR::Element gT(T);
684 auto gS1 = const_cast<ARingRRi::ElementType&>(gS);
685 S.midpoint(gT,gS1);
686 bool liftstep = mylift(R,T,result_gR,gT);
687 S.diameter(gT,gS1);
688 return liftstep && T.is_zero(gT);
689}
690
691// ZZ/p --> ZZ/p. 9 versions NONE OF THESE.
692// instead:
693// (1) lift to ZZ (int version?)
694// (2) promote to the version of ZZ/p.
695
696// ZZ/p --> GF(p^n)
697
698// GF(p^m) --> GF(p^n), where m|n, also switch GF type.
699
700// The following are all essentially from_BigRational
701// QQ --> RR
702// QQ --> RRR
703// QQ --> CC
704// QQ --> CCC
705
706// really, there are:
707// RR --> RRR (from double)
708// RR --> CC (imag part = 0)
709// CC --> CCC (from doubles)
710// RRR --> RRR (change precision)
711// RRR --> CCC (imag part = 0)
712// CCC --> CCC (change precision)
713
714// RRR --> RR Use lift.
715// CCC --> CC Use lift.
716
717// RRR --> RR (truncate)
718// RR --> RRR (make new precision)
719// RRR --> RRR (change precision)
720// RR --> CC (imag part = 0)
721// RRR --> CC (RRR --> RR, and imag part = 0)
722// CCC --> CC (truncate)
723// RR --> CCC
724// RRR --> CCC
725// CC --> CCC
726// CCC --> CCC
727
728}; // namespace M2
729
730#endif
731
732// Local Variables:
733// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
734// indent-tabs-mode: nil
735// End:
M2::ARingCC — machine-precision complex numbers (pair of doubles).
M2::ARingCCC — arbitrary-precision complex numbers (pair of MPFR floats).
M2::ARingCCi — certified complex intervals as Cartesian rectangles of MPFI intervals.
M2::ARingRR — machine-precision real numbers (IEEE 754 double).
M2::ARingRRR — arbitrary-precision real numbers backed by MPFR.
M2::ARingRRi — certified real intervals [a, b] with MPFR endpoints, MPFI arithmetic.
M2::ARingGFFlintBig — arbitrary-degree GF(p^k) via FLINT fq_nmod.
M2::ARingGFFlint — small GF(p^k) via FLINT Zech-logarithm tables.
M2::ARingGFM2 — native engine Galois field, no FLINT dependency.
Tiny dispatcher header that picks the default ARingQQ from among the QQ aring implementations.
M2::ARingTower — iterated finite-field extension tower for very large GF(p^k).
M2::ARingZZ — FLINT-backed arbitrary-precision integers with small-value inlining.
M2::ARingZZGMP — aring integer ring backed straight by GMP mpz_t.
M2::ARingZZpFFPACK — Z/p via FFLAS-FFPACK's Givaro::Modular<double> field.
M2::ARingZZpFlint — Z/p via FLINT's nmod_t precomputed-reciprocal reduction.
M2::ARingZZp — portable Z/p for small primes via log / exp tables.
void set(ElementType &result, const ElementType &a) const
Definition aring-CC.hpp:157
bool set_from_mpq(ElementType &result, mpq_srcptr a) const
Definition aring-CC.hpp:189
elem ElementType
Definition aring-CC.hpp:81
void set_from_doubles(ElementType &result, double re, double im) const
Definition aring-CC.hpp:455
bool set_from_BigReals(ElementType &result, gmp_RR re, gmp_RR im) const
Definition aring-CC.hpp:202
bool set_from_BigComplex(ElementType &result, gmp_CC a) const
Definition aring-CC.hpp:208
bool set_from_double(ElementType &result, double a) const
Definition aring-CC.hpp:214
bool set_from_complex_double(ElementType &result, double re, double im) const
Definition aring-CC.hpp:220
bool set_from_BigReal(ElementType &result, gmp_RR a) const
Definition aring-CC.hpp:196
bool set_from_BigReal(ElementType &result, gmp_RR a) const
bool set_from_complex_double(ElementType &result, double re, double im) const
const RealRingType & real_ring() const
Definition aring-CCC.hpp:91
bool set_from_RRR(ElementType &result, const ARingRRR::ElementType &a) const
bool set_from_mpq(ElementType &result, mpq_srcptr a) const
bool set_from_double(ElementType &result, double a) const
const ARingRRR::ElementType & realPartReference(const ElementType &a) const
void set_from_doubles(ElementType &result, double re, double im) const
const ARingRRR::ElementType & imaginaryPartReference(const ElementType &a) const
bool set_from_BigComplex(ElementType &result, gmp_CC a) const
void set(ElementType &result, const ElementType &a) const
aring-style adapter for arbitrary-precision complex numbers, stored as (MPFR, MPFR) pairs.
Definition aring-CCC.hpp:71
aring-style adapter for double-precision complex numbers, stored as (double, double) pairs.
Definition aring-CC.hpp:72
void set(ElementType &result, const ElementType &a) const
bool set_from_BigComplex(ElementType &result, gmp_CC a) const
bool set_from_complex_double(ElementType &result, double re, double im) const
bool set_from_double(ElementType &result, double a) const
bool set_from_BigReal(ElementType &result, gmp_RR a) const
bool set_from_Interval(ElementType &result, gmp_RRi a) const
aring-style adapter for arbitrary-precision complex intervals, stored as (MPFI, MPFI) pairs.
Definition aring-CCi.hpp:74
__mpq_struct ElementType
bool set_from_mpq(ElementType &result, mpq_srcptr a) const
Definition aring-RR.hpp:150
elem ElementType
Definition aring-RR.hpp:68
bool set_from_BigReal(ElementType &result, gmp_RR a) const
Definition aring-RR.hpp:156
bool set_from_double(ElementType &result, double a) const
Definition aring-RR.hpp:161
aring-style adapter for double-precision real numbers.
Definition aring-RR.hpp:62
bool set_from_BigReal(ElementType &result, gmp_RR a) const
bool is_zero(const ElementType &f) const
Definition aring-RRR.hpp:96
void set(ElementType &result, const ElementType &a) const
bool set_from_double(ElementType &result, double a) const
bool set_from_mpq(ElementType &result, mpq_srcptr a) const
aring-style adapter for arbitrary-precision real numbers, backed by MPFR.
Definition aring-RRR.hpp:70
void midpoint(ARingRRR::ElementType &a, const ElementType &b) const
bool set_from_Interval(ElementType &result, gmp_RRi a) const
void set(ElementType &result, const ElementType &a) const
void diameter(ARingRRR::ElementType &a, const ElementType &b) const
unsigned long get_precision() const
Definition aring-RRi.hpp:81
bool set_from_mpq(ElementType &result, mpq_srcptr a) const
bool set_from_double(ElementType &result, double a) const
bool set_from_BigReal(ElementType &result, gmp_RR a) const
aring-style adapter for arbitrary-precision real intervals, backed by MPFI.
Definition aring-RRi.hpp:69
mpfr_srcptr gmp_RR
Definition m2-types.h:148
struct gmp_CC_struct * gmp_CC
Definition m2-types.h:156
mpfi_srcptr gmp_RRi
Definition m2-types.h:153
struct gmp_CCi_struct * gmp_CCi
Definition m2-types.h:162
bool get_from_Interval(const RT &R, typename RT::ElementType &a, gmp_RRi b)
ARingQQGMP ARingQQ
Definition aring-qq.hpp:38
bool mypromote(const RingR &R, const RingS &S, const typename RingR::ElementType &fR, typename RingS::ElementType &result_fS)
bool get_from_BigComplex(const RT &R, typename RT::ElementType &a, gmp_CC b)
bool get_from_complex_double(const RT &R, typename RT::ElementType &a, double re, double im)
bool get_from_double(const RT &R, typename RT::ElementType &a, double b)
bool get_from_ComplexInterval(const RT &R, typename RT::ElementType &a, gmp_CCi b)
bool get_from_BigReal(const RT &R, typename RT::ElementType &a, gmp_RR b)
bool mylift(const RingR &R, const RingS &S, typename RingR::ElementType &result_gR, const typename RingS::ElementType &gS)
Definition aring-CC.cpp:3
#define T
Definition table.c:13