mirror of https://github.com/CGAL/cgal
Moved Modular_traits specializations out of Modular_arithmetic package to the respective Number_types.
This commit is contained in:
parent
631654aa84
commit
c1aadfd606
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -5,17 +5,8 @@
|
|||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Modular.h>
|
||||
#include <CGAL/Sqrt_extension.h>
|
||||
#include <vector>
|
||||
|
||||
#ifdef CGAL_USE_LEDA
|
||||
#include <CGAL/leda_integer.h>
|
||||
#endif// CGAL_USE_LEDA
|
||||
|
||||
#ifdef CGAL_USE_CORE
|
||||
#include <CGAL/CORE_BigInt.h>
|
||||
#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 NT_>
|
||||
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<COEFF,ROOT> > {
|
||||
|
||||
private:
|
||||
typedef Sqrt_extension<COEFF,ROOT> EXT;
|
||||
typedef Modular_traits<COEFF> MT_COEFF;
|
||||
typedef Modular_traits<ROOT> MT_ROOT;
|
||||
typedef typename MT_COEFF::Modular_NT Modular_NT_coeff;
|
||||
typedef typename MT_ROOT::Modular_NT Modular_NT_root;
|
||||
public:
|
||||
typedef Sqrt_extension<COEFF, ROOT > NT;
|
||||
typedef typename MT_COEFF::Is_modularizable Is_modularizable;
|
||||
typedef Sqrt_extension<Modular_NT_coeff, Modular_NT_root> 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<COEFF> > {
|
||||
|
||||
private:
|
||||
typedef Modular_traits<COEFF> Mtr;
|
||||
public:
|
||||
typedef Polynomial<COEFF> NT;
|
||||
typedef Modular_traits<NT> Self;
|
||||
typedef typename Mtr::Is_modularizable Is_modularizable;
|
||||
typedef Polynomial<typename Mtr::Modular_NT> Modular_NT;
|
||||
|
||||
struct Modular_image{
|
||||
Modular_NT operator()(const NT& p){
|
||||
std::vector<typename Mtr::Modular_NT> 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<COEFF> 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,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@
|
|||
#include <CGAL/number_type_basic.h>
|
||||
#include <CGAL/CORE_coercion_traits.h>
|
||||
|
||||
#include <CGAL/Modular.h>
|
||||
#include <CGAL/Modular_traits.h>
|
||||
|
||||
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<CORE::BigInt>{
|
||||
bool operator()(const CORE::BigInt& x){
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@
|
|||
#include <CGAL/CORE_coercion_traits.h>
|
||||
#include <CGAL/CORE_Expr.h> // used for To_interval-functor
|
||||
|
||||
#include <CGAL/Modular.h>
|
||||
#include <CGAL/Modular_traits.h>
|
||||
|
||||
//#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<Integer> 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 F>
|
||||
class Output_rep< ::CORE::BigRat, F> {
|
||||
const ::CORE::BigRat& t;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ factorization property.
|
|||
#include <CGAL/Sqrt_extension/Real_embeddable_traits.h>
|
||||
#include <CGAL/Sqrt_extension/Fraction_traits.h>
|
||||
#include <CGAL/Sqrt_extension/Coercion_traits.h>
|
||||
#include <CGAL/Sqrt_extension/Modular_traits.h>
|
||||
#include <CGAL/Sqrt_extension/io.h>
|
||||
|
||||
#endif // CGAL_SQRT_EXTENSION_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 <hemmer@mpi-inf.mpg.de>
|
||||
|
||||
|
||||
#ifndef CGAL_SQRT_EXTENSION_MODULAR_TRAITS_H
|
||||
#define CGAL_SQRT_EXTENSION_MODULAR_TRAITS_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Modular.h>
|
||||
#include <CGAL/Modular_traits.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
/////////// MODULAR_TRAITS BEGIN
|
||||
|
||||
template< class COEFF, class ROOT>
|
||||
class Modular_traits< Sqrt_extension<COEFF,ROOT> > {
|
||||
|
||||
private:
|
||||
typedef Sqrt_extension<COEFF,ROOT> EXT;
|
||||
typedef Modular_traits<COEFF> MT_COEFF;
|
||||
typedef Modular_traits<ROOT> MT_ROOT;
|
||||
typedef typename MT_COEFF::Modular_NT Modular_NT_coeff;
|
||||
typedef typename MT_ROOT::Modular_NT Modular_NT_root;
|
||||
public:
|
||||
typedef Sqrt_extension<COEFF, ROOT > NT;
|
||||
typedef typename MT_COEFF::Is_modularizable Is_modularizable;
|
||||
typedef Sqrt_extension<Modular_NT_coeff, Modular_NT_root> 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
|
||||
|
|
@ -40,6 +40,9 @@
|
|||
#include <LEDA/numbers/bigfloat.h>// for To_interval
|
||||
#endif
|
||||
|
||||
#include <CGAL/Modular.h>
|
||||
#include <CGAL/Modular_traits.h>
|
||||
|
||||
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
|
||||
//
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@
|
|||
#include <CGAL/leda_coercion_traits.h>
|
||||
#include <CGAL/Interval_nt.h>
|
||||
|
||||
#include <CGAL/Modular.h>
|
||||
#include <CGAL/Modular_traits.h>
|
||||
|
||||
#include <CGAL/Needs_parens_as_product.h>
|
||||
|
||||
#include <utility>
|
||||
|
|
@ -197,6 +200,27 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
// Modular_traits
|
||||
template<>
|
||||
class Modular_traits< ::leda::rational > {
|
||||
typedef ::leda::integer Integer;
|
||||
typedef CGAL::Modular_traits<Integer> 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 F>
|
||||
class Output_rep< leda_rational, F> {
|
||||
const leda_rational& t;
|
||||
|
|
|
|||
Loading…
Reference in New Issue