diff --git a/Modular_arithmetic/doc_tex/Modular_arithmetic_ref/Modularizable.tex b/Modular_arithmetic/doc_tex/Modular_arithmetic_ref/Modularizable.tex index b7e9fa01b0b..2eaea753394 100644 --- a/Modular_arithmetic/doc_tex/Modular_arithmetic_ref/Modularizable.tex +++ b/Modular_arithmetic/doc_tex/Modular_arithmetic_ref/Modularizable.tex @@ -5,28 +5,35 @@ An algebraic structure is called \ccRefName, if there is a suitable mapping into an algebraic structure which is based on the type \ccc{CGAL::Residue}. For scalar types, e.g. Integers, this mapping is just the canonical homomorphism -into the type \ccc{CGAL::Residue}. For compound types, e.g. Polynomials, +into the type \ccc{CGAL::Residue} with respect to the current prime. +For compound types, e.g. Polynomials, the mapping is applied to the coefficients of the compound type. The mapping is provided via \ccc{CGAL::Modular_traits}, being a model of \ccc{ModularTraits}. +Note that types representing rationals, or types which do have some notion +of denominator, are not \ccc{Modularizable}. +This is due to the fact that the denominator may be zero modulo the prime, +which can not be represented. + +%\ccRefIdfierPage{CORE::BigRat}\\ +%\ccRefIdfierPage{CGAL::Gmpq}\\ +%\ccRefIdfierPage{leda::rational}\\ +%\ccRefIdfierPage{mpq_class}\\ +%\ccRefIdfierPage{CGAL::Quotient}\\ + \ccHasModels \ccRefIdfierPage{int}\\ \ccRefIdfierPage{long}\\ \ccRefIdfierPage{CORE::BigInt}\\ -\ccRefIdfierPage{CORE::BigRat}\\ \ccRefIdfierPage{CGAL::Gmpz}\\ -\ccRefIdfierPage{CGAL::Gmpq}\\ \ccRefIdfierPage{leda::integer}\\ -\ccRefIdfierPage{leda::rational}\\ \ccRefIdfierPage{mpz_class}\\ -\ccRefIdfierPage{mpq_class}\\ -\ccRefIdfierPage{CGAL::Quotient}, depends on template argument.\\ \ccRefIdfierPage{CGAL::Lazy_exact_nt}, depends on template argument.\\ -\ccRefIdfierPage{CGAL::Sqrt_extension}, depends on template arguments.\\ +\ccRefIdfierPage{CGAL::Sqrt_extension}, depends on template arguments.\\ \ccRefIdfierPage{CGAL::Polynomial}, depends on template argument.\\ \ccSeeAlso diff --git a/Modular_arithmetic/test/Modular_arithmetic/Modular_traits.cpp b/Modular_arithmetic/test/Modular_arithmetic/Modular_traits.cpp index 16c5622e306..726892696e8 100644 --- a/Modular_arithmetic/test/Modular_arithmetic/Modular_traits.cpp +++ b/Modular_arithmetic/test/Modular_arithmetic/Modular_traits.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include //#include @@ -23,14 +22,11 @@ #ifdef CGAL_USE_CORE #include -#include #endif // CGAL_USE_CORE #ifdef CGAL_USE_GMP #include -#include #include -#include #endif // CGAL_USE_GMP @@ -80,28 +76,20 @@ int main() #ifdef CGAL_USE_LEDA test_modular_traits(); - test_modular_traits(); test_modular_traits >(); - test_modular_traits >(); - test_modular_traits >(); test_modular_traits >(); test_modular_traits >(); #endif #ifdef CGAL_USE_CORE test_modular_traits(); - test_modular_traits(); test_modular_traits >(); - test_modular_traits >(); - test_modular_traits >(); test_modular_traits >(); test_modular_traits >(); #endif #ifdef CGAL_USE_GMP test_modular_traits(); - test_modular_traits(); test_modular_traits< mpz_class >(); - test_modular_traits< mpq_class >(); #endif // test Sqrt_extension @@ -115,15 +103,6 @@ int main() assert( !CGAL::Modular_traits > ::Is_modularizable::value); - - // test Quotient - test_modular_traits >(); - assert( - !CGAL::Modular_traits > - ::Is_modularizable::value); - assert( - !CGAL::Modular_traits > > - ::Is_modularizable::value); // test_modular_traits(); diff --git a/Number_types/include/CGAL/CORE_BigRat.h b/Number_types/include/CGAL/CORE_BigRat.h index d51a49620b4..0dd1e92f277 100644 --- a/Number_types/include/CGAL/CORE_BigRat.h +++ b/Number_types/include/CGAL/CORE_BigRat.h @@ -26,9 +26,6 @@ #include #include // used for To_interval-functor -#include -#include - //#if defined(CGAL_CORE_BIGRAT_NUMER_DENOM_ARE_MEMBERS) // #define CGAL_CORE_NUMERATOR(X) ((X).numerator()) // #define CGAL_CORE_DENOMINATOR(X) ((X).denominator()) @@ -154,34 +151,6 @@ public: }; }; -/*! \ingroup NiX_Modular_traits_spec - * \brief a model of concept ModularTraits, - * specialization of NiX::Modular_traits. - */ -template<> -class Modular_traits< ::CORE::BigRat > { - typedef ::CORE::BigInt Integer; - typedef Modular_traits MT_int; -public: - typedef ::CORE::BigRat NT; - typedef ::CGAL::Tag_true Is_modularizable; - typedef CGAL::Residue Residue_type; - struct Modular_image{ - Residue_type operator()(const NT& rat){ - MT_int::Modular_image int_mod; - Residue_type num = int_mod(CGAL_CORE_NUMERATOR(rat)); - Residue_type den = int_mod(CGAL_CORE_DENOMINATOR(rat)); - return num/den; - } - }; - struct Modular_image_representative{ - NT operator()(const Residue_type& x){ - return NT(x.get_value()); - } - }; -}; - - template class Output_rep< ::CORE::BigRat, F> { const ::CORE::BigRat& t; diff --git a/Number_types/include/CGAL/Gmpq.h b/Number_types/include/CGAL/Gmpq.h index a2de7d96e61..34486fa7097 100644 --- a/Number_types/include/CGAL/Gmpq.h +++ b/Number_types/include/CGAL/Gmpq.h @@ -24,7 +24,6 @@ #include #include #include -#include CGAL_BEGIN_NAMESPACE @@ -133,33 +132,6 @@ public: }; }; -/*! \ingroup NiX_Modular_traits_spec - * \brief a model of concept ModularTraits, - * specialization of NiX::Modular_traits. - */ -template<> -class Modular_traits< Gmpq > { -public: - typedef Gmpq NT; - typedef CGAL::Tag_true Is_modularizable; - typedef Residue Residue_type; - - struct Modular_image{ - Residue_type operator()(const NT& a){ - Gmpz num(a.numerator() % Residue::get_current_prime() ); - Gmpz den(a.denominator() % Residue::get_current_prime() ); - Residue num_m (CGAL::Residue(int(mpz_get_si(num.mpz())))); - Residue den_m (CGAL::Residue(int(mpz_get_si(den.mpz())))); - return num_m / den_m; - } - }; - struct Modular_image_representative{ - NT operator()(const Residue_type& x){ - return NT(x.get_value()); - } - }; -}; - CGAL_END_NAMESPACE //since types are included by Gmp_coercion_traits.h: diff --git a/Number_types/include/CGAL/Quotient.h b/Number_types/include/CGAL/Quotient.h index 225c8a8fc30..89c572d0716 100644 --- a/Number_types/include/CGAL/Quotient.h +++ b/Number_types/include/CGAL/Quotient.h @@ -42,7 +42,6 @@ #include #include -#include CGAL_BEGIN_NAMESPACE @@ -869,61 +868,6 @@ public: }; }; -//fwd -class Residue; - -namespace CGALi{ - -template -struct Quotient_modular_traits_base{ - typedef Quotient NT; - typedef ::CGAL::Tag_false Is_modularizable; - typedef ::CGAL::Null_functor Residue_type; - typedef ::CGAL::Null_functor Modular_image; - typedef ::CGAL::Null_functor Modular_image_representative; -}; - -template -class Quotient_modular_traits_base{ -public: - typedef Quotient NT; - typedef CGAL::Tag_true Is_modularizable; - typedef Residue Residue_type; - - struct Modular_image{ - Residue_type operator()(const NT& a){ - typedef CGAL::Modular_traits MT_RT; - typename MT_RT::Modular_image modular_image; - typename MT_RT::Residue_type num(modular_image(a.numerator())); - typename MT_RT::Residue_type den(modular_image(a.denominator())); - return num / den; - } - }; - struct Modular_image_representative{ - NT operator()(const Residue_type& x){ - return NT(x.get_value()); - } - }; -}; - -template -struct Quotient_is_modularizable{ -private: - typedef typename Modular_traits::Residue_type Residue_type; - typedef Algebraic_structure_traits AST; - typedef typename AST::Algebraic_category Algebraic_category; - typedef CGAL::is_same_or_derived Is_field; -public: - typedef CGAL::Boolean_tag Type; -}; - -} // namespace CGALi - -template -class Modular_traits > - :public CGALi::Quotient_modular_traits_base - ::Type>{}; - CGAL_END_NAMESPACE #endif // CGAL_QUOTIENT_H diff --git a/Number_types/include/CGAL/leda_rational.h b/Number_types/include/CGAL/leda_rational.h index 8995065d31e..9321f9a05fe 100644 --- a/Number_types/include/CGAL/leda_rational.h +++ b/Number_types/include/CGAL/leda_rational.h @@ -31,9 +31,6 @@ #include #include -#include -#include - #include #include @@ -202,32 +199,6 @@ public: }; }; -// Modular_traits -template<> -class Modular_traits< ::leda::rational > { - typedef ::leda::integer Integer; - typedef CGAL::Modular_traits MT_int; -public: - typedef ::leda::rational NT; - typedef ::CGAL::Tag_true Is_modularizable; - typedef CGAL::Residue Residue_type; - - struct Modular_image{ - Residue_type operator()(const NT& rat){ - MT_int::Modular_image int_mod; - Residue_type num = int_mod(rat.numerator()); - Residue_type den = int_mod(rat.denominator()); - return num/den; - } - }; - struct Modular_image_representative{ - NT operator()(const Residue_type& x){ - return NT(x.get_value()); - } - }; -}; - - template class Output_rep< leda_rational, F> { const leda_rational& t; diff --git a/Number_types/include/CGAL/mpq_class.h b/Number_types/include/CGAL/mpq_class.h index 6a9bf26e03f..6e80aa7ca52 100644 --- a/Number_types/include/CGAL/mpq_class.h +++ b/Number_types/include/CGAL/mpq_class.h @@ -284,31 +284,6 @@ public: }; }; -template<> -class Modular_traits< mpq_class > { -public: - typedef mpq_class NT; - typedef CGAL::Tag_true Is_modularizable; - typedef Residue Residue_type; - - struct Modular_image{ - Residue_type operator()(const mpq_class& a){ - typedef Fraction_traits FT; - mpz_class num, den; - FT::Decompose()(a,num,den); - mpz_class prime(Residue::get_current_prime()); - CGAL::Residue num_m(int(mpz_get_si(CGAL::mod(num,prime).get_mpz_t()))); - CGAL::Residue den_m(int(mpz_get_si(CGAL::mod(den,prime).get_mpz_t()))); - return num_m/den_m; - } - }; - struct Modular_image_representative{ - NT operator()(const Residue_type& x){ - return NT(x.get_value()); - } - }; -}; - CGAL_END_NAMESPACE #undef CGAL_CHECK_GMP_EXPR