diff --git a/M2/Macaulay2/e/basic-rings/aring-GF-flint-big.hpp b/M2/Macaulay2/e/basic-rings/aring-GF-flint-big.hpp index 7a4a95a904d..77ebdd41840 100644 --- a/M2/Macaulay2/e/basic-rings/aring-GF-flint-big.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-GF-flint-big.hpp @@ -226,13 +226,6 @@ class ARingGFFlintBig : public RingInterface return true; } - bool set_from_BigReal(ElementType& result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - void negate(ElementType& result, const ElementType& a) const { fq_nmod_neg(&result, &a, mContext); diff --git a/M2/Macaulay2/e/basic-rings/aring-GF-flint.hpp b/M2/Macaulay2/e/basic-rings/aring-GF-flint.hpp index 4dc400099f9..081dd902075 100644 --- a/M2/Macaulay2/e/basic-rings/aring-GF-flint.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-GF-flint.hpp @@ -207,13 +207,6 @@ class ARingGFFlint : public RingInterface return true; } - bool set_from_BigReal(ElementType& result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - void negate(ElementType& result, const ElementType& a) const { fq_zech_neg(&result, &a, mContext); diff --git a/M2/Macaulay2/e/basic-rings/aring-QQ-flint.hpp b/M2/Macaulay2/e/basic-rings/aring-QQ-flint.hpp index 8a86241b3ed..d39be513537 100644 --- a/M2/Macaulay2/e/basic-rings/aring-QQ-flint.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-QQ-flint.hpp @@ -116,13 +116,6 @@ class ARingQQFlint : public SimpleARing return true; } - bool set_from_BigReal(ElementType& result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - void set_var(ElementType& result, int v) const { (void) v; diff --git a/M2/Macaulay2/e/basic-rings/aring-ZZ-flint.hpp b/M2/Macaulay2/e/basic-rings/aring-ZZ-flint.hpp index 36849a01dca..1e64612232a 100644 --- a/M2/Macaulay2/e/basic-rings/aring-ZZ-flint.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-ZZ-flint.hpp @@ -111,13 +111,6 @@ void set_from_mpz(ElementType& result, mpz_srcptr a) const return false; } - bool set_from_BigReal(ElementType& result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - void set_var(ElementType& result, int v) const { (void) v; diff --git a/M2/Macaulay2/e/basic-rings/aring-ZZp-ffpack.hpp b/M2/Macaulay2/e/basic-rings/aring-ZZp-ffpack.hpp index 435480bac5f..a608f5b9da4 100644 --- a/M2/Macaulay2/e/basic-rings/aring-ZZp-ffpack.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-ZZp-ffpack.hpp @@ -160,13 +160,6 @@ class ARingZZpFFPACK : public SimpleARing bool set_from_mpq(ElementType &result, mpq_srcptr a) const; - bool set_from_BigReal(ElementType &result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - ElementType computeGenerator() const; void set_var(ElementType &result, int v) const diff --git a/M2/Macaulay2/e/basic-rings/aring-ZZp-flint.hpp b/M2/Macaulay2/e/basic-rings/aring-ZZp-flint.hpp index 44a2278a7f4..3f8097fa1f0 100644 --- a/M2/Macaulay2/e/basic-rings/aring-ZZp-flint.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-ZZp-flint.hpp @@ -119,13 +119,6 @@ class ARingZZpFlint : public SimpleARing return true; } - bool set_from_BigReal(ElementType &result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - // arithmetic void negate(ElementType &result, ElementType a) const { diff --git a/M2/Macaulay2/e/basic-rings/aring-ZZp.hpp b/M2/Macaulay2/e/basic-rings/aring-ZZp.hpp index 014b1f89f98..177acba081d 100644 --- a/M2/Macaulay2/e/basic-rings/aring-ZZp.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-ZZp.hpp @@ -141,13 +141,6 @@ class ARingZZp : public SimpleARing return true; } - bool set_from_BigReal(elem &result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - // arithmetic void negate(elem &result, elem a) const { diff --git a/M2/Macaulay2/e/basic-rings/aring-m2-GF.hpp b/M2/Macaulay2/e/basic-rings/aring-m2-GF.hpp index ece986c1b50..f5a1726e4ea 100644 --- a/M2/Macaulay2/e/basic-rings/aring-m2-GF.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-m2-GF.hpp @@ -186,13 +186,6 @@ class ARingGFM2 : public SimpleARing return true; } - bool set_from_BigReal(elem &result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - void negate(elem &result, elem a) const { if (a != 0) diff --git a/M2/Macaulay2/e/basic-rings/aring-tower.hpp b/M2/Macaulay2/e/basic-rings/aring-tower.hpp index d9215f8519c..61bdc119502 100644 --- a/M2/Macaulay2/e/basic-rings/aring-tower.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-tower.hpp @@ -227,13 +227,6 @@ class ARingTower : public RingInterface return false; } // TODO: write this - bool set_from_BigReal(elem &result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } - // arithmetic void negate(elem &result, elem a) const { diff --git a/M2/Macaulay2/e/basic-rings/aring-translate.hpp b/M2/Macaulay2/e/basic-rings/aring-translate.hpp index c46bcf9e575..718787389d1 100644 --- a/M2/Macaulay2/e/basic-rings/aring-translate.hpp +++ b/M2/Macaulay2/e/basic-rings/aring-translate.hpp @@ -3,6 +3,9 @@ #ifndef M2_BASIC_RINGS_ARING_TRANSLATE_HPP_ #define M2_BASIC_RINGS_ARING_TRANSLATE_HPP_ +#include +#include + /////////////////////////////////////////////////////// // Contains functions which are "ring translational" // /////////////////////////////////////////////////////// @@ -27,211 +30,136 @@ #include "basic-rings/aring-GF-flint.hpp" namespace M2 { -template -bool get_from_BigReal(const RT& R, typename RT::ElementType& a, gmp_RR b) -{ - (void) R; - (void) a; - (void) b; - return false; -} -template -bool get_from_Interval(const RT& R, typename RT::ElementType& a, gmp_RRi b) -{ - (void) R; - (void) a; - (void) b; - return false; -} +namespace detail { -template -bool get_from_ComplexInterval(const RT& R, typename RT::ElementType & a, gmp_CCi b) -{ - return false; -} +template +inline constexpr bool has_set_from_mpq = false; template -bool get_from_BigComplex(const RT& R, typename RT::ElementType& a, gmp_CC b) -{ - (void) R; - (void) a; - (void) b; - return false; -} -template -bool get_from_double(const RT& R, typename RT::ElementType& a, double b) -{ - (void) R; - (void) a; - (void) b; - return false; -} -template -bool get_from_complex_double(const RT& R, - typename RT::ElementType& a, - double re, - double im) -{ - (void) R; - (void) a; - (void) re; - (void) im; - return false; -} +inline constexpr bool has_set_from_mpq< + RT, + std::void_t().set_from_mpq( + std::declval(), + std::declval()))>> = true; -inline bool get_from_BigReal(const ARingQQ& R, - ARingQQ::ElementType& a, - gmp_RR b) -{ - return R.set_from_BigReal(a, b); -} +template +inline constexpr bool has_set_from_double = false; -inline bool get_from_BigReal(const ARingRR& R, - ARingRR::ElementType& a, - gmp_RR b) -{ - return R.set_from_BigReal(a, b); -} +template +inline constexpr bool has_set_from_double< + RT, + std::void_t().set_from_double( + std::declval(), std::declval()))>> = + true; -inline bool get_from_BigReal(const ARingRRR& R, - ARingRRR::ElementType& a, - gmp_RR b) -{ - return R.set_from_BigReal(a, b); -} - -inline bool get_from_BigReal(const ARingRRi& R, - ARingRRi::ElementType& a, - gmp_RR b) -{ - return R.set_from_BigReal(a, b); -} +template +inline constexpr bool has_set_from_BigReal = false; -inline bool get_from_BigReal(const ARingCC& R, - ARingCC::ElementType& a, - gmp_RR b) -{ - return R.set_from_BigReal(a, b); -} +template +inline constexpr bool has_set_from_BigReal< + RT, + std::void_t().set_from_BigReal( + std::declval(), std::declval()))>> = + true; -inline bool get_from_BigReal(const ARingCCC& R, - ARingCCC::ElementType& a, - gmp_RR b) -{ - return R.set_from_BigReal(a, b); -} +template +inline constexpr bool has_set_from_Interval = false; -inline bool get_from_BigComplex(const ARingCCC& R, - ARingCCC::ElementType& a, - gmp_CC b) -{ - return R.set_from_BigComplex(a, b); -} +template +inline constexpr bool has_set_from_Interval< + RT, + std::void_t().set_from_Interval( + std::declval(), std::declval()))>> = + true; -inline bool get_from_BigComplex(const ARingCC& R, - ARingCC::ElementType& a, - gmp_CC b) -{ - return R.set_from_BigComplex(a, b); -} +template +inline constexpr bool has_set_from_complex_double = false; -inline bool get_from_double(const ARingRRR& R, - ARingRRR::ElementType& a, - double b) -{ - return R.set_from_double(a, b); -} - -inline bool get_from_double(const ARingRRi& R, - ARingRRi::ElementType& a, - double b) -{ - return R.set_from_double(a, b); -} - -inline bool get_from_Interval(const ARingRRi& R, - ARingRRi::ElementType& a, - gmp_RRi b) -{ - return R.set_from_Interval(a, b); -} - -inline bool get_from_ComplexInterval(const ARingCCi& R, - ARingCCi::ElementType& a, - gmp_CCi b) -{ - R.set(a, b); - return true; -} +template +inline constexpr bool has_set_from_complex_double< + RT, + std::void_t().set_from_complex_double( + std::declval(), + std::declval(), + std::declval()))>> = true; -inline bool get_from_double(const ARingCCi& R, - ARingCCi::ElementType& a, - double b) -{ - return R.set_from_double(a, b); -} +template +inline constexpr bool has_set_from_BigComplex = false; -inline bool get_from_Interval(const ARingCCi& R, - ARingCCi::ElementType& a, - gmp_RRi b) -{ - return R.set_from_Interval(a, b); -} +template +inline constexpr bool has_set_from_BigComplex< + RT, + std::void_t().set_from_BigComplex( + std::declval(), std::declval()))>> = + true; -inline bool get_from_BigComplex(const ARingCCi& R, - ARingCCi::ElementType& a, - gmp_CC b) -{ - return R.set_from_BigComplex(a, b); -} +template +inline constexpr bool has_set_from_ComplexInterval = false; -inline bool get_from_BigReal(const ARingCCi& R, - ARingCCi::ElementType& a, - gmp_RR b) -{ - return R.set_from_BigReal(a, b); -} +template +inline constexpr bool has_set_from_ComplexInterval< + RT, + std::void_t().set_from_ComplexInterval( + std::declval(), std::declval()))>> = + true; +} // namespace detail -inline bool get_from_double(const ARingRR& R, ARingRR::ElementType& a, double b) +template +bool get_from_double(const RT& R, typename RT::ElementType& a, double b) { - return R.set_from_double(a, b); + if constexpr (detail::has_set_from_double) + return R.set_from_double(a, b); + else + return false; } -inline bool get_from_double(const ARingCCC& R, - ARingCCC::ElementType& a, - double b) +template +bool get_from_BigReal(const RT& R, typename RT::ElementType& a, gmp_RR b) { - return R.set_from_double(a, b); + if constexpr (detail::has_set_from_BigReal) + return R.set_from_BigReal(a, b); + else + return false; } -inline bool get_from_double(const ARingCC& R, ARingCC::ElementType& a, double b) +template +bool get_from_Interval(const RT& R, typename RT::ElementType& a, gmp_RRi b) { - return R.set_from_double(a, b); + if constexpr (detail::has_set_from_Interval) + return R.set_from_Interval(a, b); + else + return false; } -inline bool get_from_complex_double(const ARingCCC& R, - ARingCCC::ElementType& a, - double re, - double im) +template +bool get_from_complex_double(const RT& R, + typename RT::ElementType& a, + double re, + double im) { - return R.set_from_complex_double(a, re, im); + if constexpr (detail::has_set_from_complex_double) + return R.set_from_complex_double(a, re, im); + else + return false; } -inline bool get_from_complex_double(const ARingCC& R, - ARingCC::ElementType& a, - double re, - double im) +template +bool get_from_BigComplex(const RT& R, typename RT::ElementType& a, gmp_CC b) { - return R.set_from_complex_double(a, re, im); + if constexpr (detail::has_set_from_BigComplex) + return R.set_from_BigComplex(a, b); + else + return false; } -inline bool get_from_complex_double(const ARingCCi& R, - ARingCCi::ElementType& a, - double re, - double im) +template +bool get_from_ComplexInterval(const RT& R, typename RT::ElementType & a, gmp_CCi b) { - return R.set_from_complex_double(a, re, im); + if constexpr (detail::has_set_from_ComplexInterval) + return R.set_from_ComplexInterval(a, b); + else + return false; } // Promote an element of one ring to another. @@ -264,56 +192,30 @@ bool mylift(const RingR& R, } ///////////////////////////////////////////////////// -inline bool mypromote(const ARingQQ& R, - const ARingRR& S, - const ARingQQ::ElementType& fR, - ARingRR::ElementType& fS) -{ - (void) R; - return S.set_from_mpq(fS, &fR); -} -inline bool mypromote(const ARingQQ& R, - const ARingRRR& S, - const ARingQQ::ElementType& fR, - ARingRRR::ElementType& fS) -{ - (void) R; - return S.set_from_mpq(fS, &fR); -} -inline bool mypromote(const ARingQQ& R, - const ARingRRi& S, - const ARingQQ::ElementType& fR, - ARingRRi::ElementType& fS) -{ - (void) R; - return S.set_from_mpq(fS, &fR); -} -inline bool mypromote(const ARingQQ& R, - const ARingCC& S, - const ARingQQ::ElementType& fR, - ARingCC::ElementType& fS) -{ - (void) R; - return S.set_from_mpq(fS, &fR); -} -inline bool mypromote(const ARingQQ& R, - const ARingCCC& S, - const ARingQQ::ElementType& fR, - ARingCCC::ElementType& fS) +template +bool mypromote(const ARingQQ& R, + const RingS& S, + const ARingQQ::ElementType& fR, + typename RingS::ElementType& fS) { (void) R; - return S.set_from_mpq(fS, &fR); + if constexpr (detail::has_set_from_mpq) + return S.set_from_mpq(fS, &fR); + else + return false; } ///////////////////////////////////////////////////// -inline bool mypromote(const ARingRR& R, - const ARingRR& S, - const ARingRR::ElementType& fR, - ARingRR::ElementType& fS) +template +bool mypromote(const Ring& R, + const Ring& S, + const typename Ring::ElementType& fR, + typename Ring::ElementType& fS) { (void) R; - S.set_from_double(fS, fR); + S.set(fS, fR); return true; } +///////////////////////////////////////////////////// inline bool mypromote(const ARingRR& R, const ARingRRR& S, const ARingRR::ElementType& fR, @@ -342,15 +244,6 @@ inline bool mypromote(const ARingRR& R, return true; } ///////////////////////////////////////////////////// -inline bool mypromote(const ARingRRR& R, - const ARingRRR& S, - const ARingRRR::ElementType& fR, - ARingRRR::ElementType& fS) -{ - (void) R; - S.set(fS, fR); - return true; -} inline bool mypromote(const ARingRRR& R, const ARingRR& S, const ARingRRR::ElementType& fR, @@ -382,15 +275,6 @@ inline bool mypromote(const ARingRRR& R, return true; } ///////////////////////////////////////////////////// -inline bool mypromote(const ARingRRi& R, - const ARingRRi& S, - const ARingRRi::ElementType& fR, - ARingRRi::ElementType& fS) -{ - (void) R; - S.set(fS, fR); - return true; -} inline bool mypromote(const ARingRR& R, const ARingRRi& S, const ARingRR::ElementType& fR, @@ -410,15 +294,6 @@ inline bool mypromote(const ARingRRR& R, return true; } ///////////////////////////////////////////////////// -inline bool mypromote(const ARingCC& R, - const ARingCC& S, - const ARingCC::ElementType& fR, - ARingCC::ElementType& fS) -{ - (void) R; - S.set(fS, fR); - return true; -} inline bool mypromote(const ARingCC& R, const ARingCCC& S, const ARingCC::ElementType& fR, @@ -439,24 +314,7 @@ inline bool mypromote(const ARingCCC& R, S.set_from_BigReals(fS, &fR1.re, &fR1.im); return true; } -inline bool mypromote(const ARingCCC& R, - const ARingCCC& S, - const ARingCCC::ElementType& fR, - ARingCCC::ElementType& fS) -{ - (void) R; - S.set(fS, fR); - return true; -} ///////////////////////////////////////////////////// -inline bool mypromote(const ARingCCi& R, - const ARingCCi& S, - const ARingCCi::ElementType& fR, - ARingCCi::ElementType& fS) -{ - S.set(fS, fR); - return true; -} inline bool mypromote(const ARingRR& R, const ARingCCi& S, const ARingRR::ElementType& fR, @@ -615,24 +473,11 @@ inline bool mylift(const ARingCC& R, ///////////////////////////////////////////////////// -inline bool mylift(const ARingRR& R, - const ARingRRi& S, - ARingRR::ElementType& result_gR, - const ARingRRi::ElementType& gS) -{ - ARingRRR T(S.get_precision()); - ARingRRR::Element gT(T); - auto gS1 = const_cast(gS); - S.midpoint(gT,gS1); - bool liftstep = mylift(R,T,result_gR,gT); - S.diameter(gT,gS1); - return liftstep && T.is_zero(gT); -} - -inline bool mylift(const ARingRRR& R, - const ARingRRi& S, - ARingRRR::ElementType& result_gR, - const ARingRRi::ElementType& gS) +template +bool mylift(const RingR& R, + const ARingRRi& S, + typename RingR::ElementType& result_gR, + const ARingRRi::ElementType& gS) { ARingRRR T(S.get_precision()); ARingRRR::Element gT(T); @@ -661,20 +506,6 @@ inline bool mylift(const ARingQQ& R, return R.set_from_BigReal(fR, &fS); } -inline bool mylift(const ARingQQ& R, - const ARingRRi& S, - ARingQQ::ElementType& result_gR, - const ARingRRi::ElementType& gS) -{ - ARingRRR T(S.get_precision()); - ARingRRR::Element gT(T); - auto gS1 = const_cast(gS); - S.midpoint(gT,gS1); - bool liftstep = mylift(R,T,result_gR,gT); - S.diameter(gT,gS1); - return liftstep && T.is_zero(gT); -} - // ZZ/p --> ZZ/p. 9 versions NONE OF THESE. // instead: // (1) lift to ZZ (int version?) diff --git a/M2/Macaulay2/e/basic-rings/aring.hpp b/M2/Macaulay2/e/basic-rings/aring.hpp index 266901fc5df..0f7483bbbef 100644 --- a/M2/Macaulay2/e/basic-rings/aring.hpp +++ b/M2/Macaulay2/e/basic-rings/aring.hpp @@ -249,12 +249,6 @@ class DummyRing : public SimpleARing (void) a; return false; } - bool set_from_BigReal(elem &result, gmp_RR a) const - { - (void) result; - (void) a; - return false; - } void set_var(elem &result, int v) const { (void) v; diff --git a/M2/Macaulay2/tests/normal/subst7.m2 b/M2/Macaulay2/tests/normal/subst7.m2 index 67ca89f47e3..594a7c177ab 100644 --- a/M2/Macaulay2/tests/normal/subst7.m2 +++ b/M2/Macaulay2/tests/normal/subst7.m2 @@ -5,12 +5,12 @@ assert try (substitute(v_1,RR);false) else true -- used to crash (<= 1.9.2) assert try (substitute(v_{1},RR);false) else true -- used to crash (<= 1.9.2) assert(ring lift(v_{1},RR_53) === RR_53) --- issue 473: -assert try (sub(matrix{{1.0}},QQ);false) else true -- used to crash (<= 1.9.2) +-- issue 473: +assert( sub(matrix{{1.0}}, QQ) == matrix(QQ, 1) ) -- used to crash (<= 1.9.2) f = map(QQ,RR_53) -assert try (f (matrix{{1.0}}); false) else true -- used to crash (<= 1.9.2) +assert (f (matrix{{1.0}}) == matrix(QQ, 1) ) -- used to crash (<= 1.9.2) C = matrix {{1_CC}} assert(ring lift(C,RR) === RR_53) -- works