diff --git a/.gitattributes b/.gitattributes index f8a72e6b758..d89d207cabd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1762,6 +1762,7 @@ Number_types/include/CGAL/Sqrt_extension/Algebraic_extension_traits.h -text Number_types/include/CGAL/Sqrt_extension/Algebraic_structure_traits.h -text Number_types/include/CGAL/Sqrt_extension/Coercion_traits.h -text Number_types/include/CGAL/Sqrt_extension/Fraction_traits.h -text +Number_types/include/CGAL/Sqrt_extension/Modular_traits.h -text Number_types/include/CGAL/Sqrt_extension/Real_embeddable_traits.h -text Number_types/include/CGAL/Sqrt_extension/Scalar_factor_traits.h -text Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h -text diff --git a/Modular_arithmetic/include/CGAL/Modular_traits.h b/Modular_arithmetic/include/CGAL/Modular_traits.h index 9ff297f3a52..43ee5a634db 100644 --- a/Modular_arithmetic/include/CGAL/Modular_traits.h +++ b/Modular_arithmetic/include/CGAL/Modular_traits.h @@ -5,17 +5,8 @@ #include #include -#include #include -#ifdef CGAL_USE_LEDA -#include -#endif// CGAL_USE_LEDA - -#ifdef CGAL_USE_CORE -#include -#endif// CGAL_USE_CORE - namespace CGAL { @@ -26,7 +17,7 @@ namespace CGAL { for unsupported types. Note that this support is optional. \see CGAL_Modular_traits_spec for supported types. */ - + template class Modular_traits{ public: @@ -88,153 +79,6 @@ public: }; }; -#ifdef CGAL_USE_LEDA -// TODO: mv to leda_integer.h -template<> -class Modular_traits< ::leda::integer > { - typedef Modular MOD; - public: - typedef ::leda::integer NT; - typedef ::CGAL::Tag_true Is_modularizable; - typedef MOD Modular_NT; - - struct Modular_image{ - Modular_NT operator()(const NT& a){ - return Modular_NT ((a%NT(MOD::get_current_prime())).to_long()); - } - }; - struct Modular_image_inv{ - NT operator()(const Modular& x){ - return NT(x.get_value()); - } - }; -}; -#endif // CGAL_USE_LEDA - -#ifdef CGAL_USE_CORE -// --------------------------------- -// TODO: mv to CORE_BigInt.h - -/*! \ingroup NiX_Modular_traits_spec - * \brief a model of concept ModularTraits, - * specialization of NiX::Modular_traits. - */ -template<> -class Modular_traits< ::CORE::BigInt > { - typedef Modular MOD; - public: - typedef ::CORE::BigInt NT; - typedef CGAL::Tag_true Is_modularizable; - typedef MOD Modular_NT; - - struct Modular_image{ - Modular_NT operator()(const NT& a){ - NT tmp = a % NT(MOD::get_current_prime()); -// TODO: reactivate this assertion -// it fails with core_v1.6x_20040329 -// NiX_assert(tmp.isInt()); - int mi(tmp.longValue()); - if (mi < 0) mi += MOD::get_current_prime(); - return Modular_NT(mi); - } - }; - struct Modular_image_inv{ - NT operator()(const Modular& x){ - return NT(x.get_value()); - } - }; -}; -#endif // CGAL_USE_CORE - - -//-------------------------------- -// TODO : mv to Sqrt_extension.h - -template< class COEFF, class ROOT> -class Modular_traits< Sqrt_extension > { - -private: - typedef Sqrt_extension EXT; - typedef Modular_traits MT_COEFF; - typedef Modular_traits MT_ROOT; - typedef typename MT_COEFF::Modular_NT Modular_NT_coeff; - typedef typename MT_ROOT::Modular_NT Modular_NT_root; -public: - typedef Sqrt_extension NT; - typedef typename MT_COEFF::Is_modularizable Is_modularizable; - typedef Sqrt_extension Modular_NT; - - struct Modular_image{ - Modular_NT operator()(const EXT& a){ - typename MT_ROOT::Modular_image mod_image_root; - typename MT_COEFF::Modular_image mod_image_coeff; - Modular_NT_root root_mod = mod_image_root(a.root()); - if(root_mod != Modular_NT_root(0)){ - return Modular_NT(mod_image_coeff(a.a0()), - mod_image_coeff(a.a1()), - root_mod); - }else{ - return Modular_NT(mod_image_coeff(a.a0())); - } - } - }; - - struct Modular_image_inv{ - NT operator()(const Modular_NT& a){ - typename MT_ROOT::Modular_image_inv mod_image_inv_root; - typename MT_COEFF::Modular_image_inv mod_image_inv_coeff; - - if(a.is_extended()){ - return NT( - mod_image_inv_coeff(a.a0()), - mod_image_inv_coeff(a.a1()), - mod_image_inv_root(a.root())); - }else{ - return NT(mod_image_inv_coeff(a.a0())); - } - } - }; -}; - -//template < typename Coeffcient > class Polynomial; -/*! \ingroup NiX_Polynomial - * \ingroup NiX_Modular_traits_spec - * \brief Specialization of Modular_traits for NiX::Polynomial. - * - * NiX::Modular_traits::Modular_image maps the coefficients of a polynomial - * to their Modular_image and returns the resulting polynomial. - */ -/*template< class COEFF > -class Modular_traits< Polynomial > { - -private: - typedef Modular_traits Mtr; -public: - typedef Polynomial NT; - typedef Modular_traits Self; - typedef typename Mtr::Is_modularizable Is_modularizable; - typedef Polynomial Modular_NT; - - struct Modular_image{ - Modular_NT operator()(const NT& p){ - std::vector V; - typename Mtr::Modular_image modular_image; - for(int i=0; i<=p.degree();i++) - V.push_back(modular_image(p[i])); - return Modular_NT(V.begin(),V.end()); - } - }; - struct Modular_image_inv{ - NT operator()(const Modular_NT& p){ - std::vector V; - typename Mtr::Modular_image_inv modular_image_inv; - for(int i=0; i<=p.degree();i++) - V.push_back(modular_image_inv(p[i])); - return NT(V.begin(),V.end()); - } - }; -};*/ - // TODO: put this into Modular_arithmetic/src/ int primes[64] = { 67089287,67089299,67089329,67089377,67089461,67089469,67089479,67089511, diff --git a/Number_types/include/CGAL/CORE_BigInt.h b/Number_types/include/CGAL/CORE_BigInt.h index ddea0fdf10e..0e057bcc856 100644 --- a/Number_types/include/CGAL/CORE_BigInt.h +++ b/Number_types/include/CGAL/CORE_BigInt.h @@ -25,6 +25,9 @@ #include #include +#include +#include + CGAL_BEGIN_NAMESPACE // @@ -129,6 +132,37 @@ template <> class Real_embeddable_traits< CORE::BigInt > }; }; +/*! \ingroup NiX_Modular_traits_spec + * \brief a model of concept ModularTraits, + * specialization of NiX::Modular_traits. + */ +template<> +class Modular_traits< ::CORE::BigInt > { + typedef Modular MOD; + public: + typedef ::CORE::BigInt NT; + typedef CGAL::Tag_true Is_modularizable; + typedef MOD Modular_NT; + + struct Modular_image{ + Modular_NT operator()(const NT& a){ + NT tmp = a % NT(MOD::get_current_prime()); +// TODO: reactivate this assertion +// it fails with core_v1.6x_20040329 +// NiX_assert(tmp.isInt()); + int mi(tmp.longValue()); + if (mi < 0) mi += MOD::get_current_prime(); + return Modular_NT(mi); + } + }; + struct Modular_image_inv{ + NT operator()(const Modular& x){ + return NT(x.get_value()); + } + }; +}; + + template<> struct Needs_parens_as_product{ bool operator()(const CORE::BigInt& x){ diff --git a/Number_types/include/CGAL/CORE_BigRat.h b/Number_types/include/CGAL/CORE_BigRat.h index c5a7d48ab1e..d1a9872ab8a 100644 --- a/Number_types/include/CGAL/CORE_BigRat.h +++ b/Number_types/include/CGAL/CORE_BigRat.h @@ -26,6 +26,9 @@ #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()) @@ -152,6 +155,29 @@ 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::Modular Modular_NT; + struct Modular_image{ + Modular_NT operator()(const NT& rat){ + MT_int::Modular_image int_mod; + Modular_NT num = int_mod(CGAL_CORE_NUMERATOR(rat)); + Modular_NT den = int_mod(CGAL_CORE_DENOMINATOR(rat)); + return num/den; + } + }; +}; + + template class Output_rep< ::CORE::BigRat, F> { const ::CORE::BigRat& t; diff --git a/Number_types/include/CGAL/Sqrt_extension.h b/Number_types/include/CGAL/Sqrt_extension.h index 290be85e0af..50aa353b512 100644 --- a/Number_types/include/CGAL/Sqrt_extension.h +++ b/Number_types/include/CGAL/Sqrt_extension.h @@ -57,6 +57,7 @@ factorization property. #include #include #include +#include #include #endif // CGAL_SQRT_EXTENSION_H diff --git a/Number_types/include/CGAL/Sqrt_extension/Modular_traits.h b/Number_types/include/CGAL/Sqrt_extension/Modular_traits.h new file mode 100644 index 00000000000..fc72d60af1b --- /dev/null +++ b/Number_types/include/CGAL/Sqrt_extension/Modular_traits.h @@ -0,0 +1,83 @@ +// Copyright (c) 2006-2007 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL: $ +// $Id: $ +// +// +// Author(s) : Michael Hemmer + + +#ifndef CGAL_SQRT_EXTENSION_MODULAR_TRAITS_H +#define CGAL_SQRT_EXTENSION_MODULAR_TRAITS_H + +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + +/////////// MODULAR_TRAITS BEGIN + +template< class COEFF, class ROOT> +class Modular_traits< Sqrt_extension > { + +private: + typedef Sqrt_extension EXT; + typedef Modular_traits MT_COEFF; + typedef Modular_traits MT_ROOT; + typedef typename MT_COEFF::Modular_NT Modular_NT_coeff; + typedef typename MT_ROOT::Modular_NT Modular_NT_root; +public: + typedef Sqrt_extension NT; + typedef typename MT_COEFF::Is_modularizable Is_modularizable; + typedef Sqrt_extension Modular_NT; + + struct Modular_image{ + Modular_NT operator()(const EXT& a){ + typename MT_ROOT::Modular_image mod_image_root; + typename MT_COEFF::Modular_image mod_image_coeff; + Modular_NT_root root_mod = mod_image_root(a.root()); + if(root_mod != Modular_NT_root(0)){ + return Modular_NT(mod_image_coeff(a.a0()), + mod_image_coeff(a.a1()), + root_mod); + }else{ + return Modular_NT(mod_image_coeff(a.a0())); + } + } + }; + + struct Modular_image_inv{ + NT operator()(const Modular_NT& a){ + typename MT_ROOT::Modular_image_inv mod_image_inv_root; + typename MT_COEFF::Modular_image_inv mod_image_inv_coeff; + + if(a.is_extended()){ + return NT( + mod_image_inv_coeff(a.a0()), + mod_image_inv_coeff(a.a1()), + mod_image_inv_root(a.root())); + }else{ + return NT(mod_image_inv_coeff(a.a0())); + } + } + }; +}; + +/////////// MODULAR_TRAITS END + +CGAL_END_NAMESPACE + +#endif diff --git a/Number_types/include/CGAL/leda_integer.h b/Number_types/include/CGAL/leda_integer.h index b0fe4ab32d1..4631b06ec36 100644 --- a/Number_types/include/CGAL/leda_integer.h +++ b/Number_types/include/CGAL/leda_integer.h @@ -40,6 +40,9 @@ #include // for To_interval #endif +#include +#include + CGAL_BEGIN_NAMESPACE template <> class Algebraic_structure_traits< leda_integer > @@ -170,6 +173,26 @@ template <> class Real_embeddable_traits< leda_integer > }; }; +template<> +class Modular_traits< ::leda::integer > { + typedef Modular MOD; + public: + typedef ::leda::integer NT; + typedef ::CGAL::Tag_true Is_modularizable; + typedef MOD Modular_NT; + + struct Modular_image{ + Modular_NT operator()(const NT& a){ + return Modular_NT ((a%NT(MOD::get_current_prime())).to_long()); + } + }; + struct Modular_image_inv{ + NT operator()(const Modular& x){ + return NT(x.get_value()); + } + }; +}; + // // Needs_parens_as_product // diff --git a/Number_types/include/CGAL/leda_rational.h b/Number_types/include/CGAL/leda_rational.h index ee83042eb60..1c2def22bb8 100644 --- a/Number_types/include/CGAL/leda_rational.h +++ b/Number_types/include/CGAL/leda_rational.h @@ -29,6 +29,9 @@ #include #include +#include +#include + #include #include @@ -197,6 +200,27 @@ 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::Modular Modular_NT; + + struct Modular_image{ + Modular_NT operator()(const NT& rat){ + MT_int::Modular_image int_mod; + Modular_NT num = int_mod(rat.numerator()); + Modular_NT den = int_mod(rat.denominator()); + return num/den; + } + }; +}; + + template class Output_rep< leda_rational, F> { const leda_rational& t;