mirror of https://github.com/CGAL/cgal
added functor Inverse + global function to AF (with respect to multiplication)
This commit is contained in:
parent
85c841ef30
commit
b39ede765c
|
|
@ -68,7 +68,9 @@ Algebraic_foundations/doc_tex/Algebraic_foundations/interoperability.tex -text
|
|||
Algebraic_foundations/doc_tex/Algebraic_foundations/real_embeddable.tex -text
|
||||
Algebraic_foundations/doc_tex/Algebraic_foundations/real_number_types.tex -text
|
||||
Algebraic_foundations/doc_tex/Algebraic_foundations_ref/AlgebraicStructureTraits_Divides.tex -text
|
||||
Algebraic_foundations/doc_tex/Algebraic_foundations_ref/AlgebraicStructureTraits_Inverse.tex -text
|
||||
Algebraic_foundations/doc_tex/Algebraic_foundations_ref/Fraction.tex -text
|
||||
Algebraic_foundations/doc_tex/Algebraic_foundations_ref/inverse.tex -text
|
||||
Algebraic_foundations/examples/Algebraic_foundations/algebraic_structure_dispatch.cpp -text
|
||||
Algebraic_foundations/examples/Algebraic_foundations/fraction_traits.cpp -text
|
||||
Algebraic_foundations/examples/Algebraic_foundations/implicit_interoperable_dispatch.cpp -text
|
||||
|
|
|
|||
|
|
@ -132,6 +132,11 @@ A model of \ccc{AlgebraicStructureTraits::DivMod}.\\
|
|||
Required by the concept \ccc{EuclideanRing}.
|
||||
}
|
||||
|
||||
\ccNestedType{Inverse}{
|
||||
A model of \ccc{AlgebraicStructureTraits::Inverse}.\\
|
||||
Required by the concept \ccc{Field}.
|
||||
}
|
||||
|
||||
\ccNestedType{Sqrt}{
|
||||
A model of \ccc{AlgebraicStructureTraits::Sqrt}.\\
|
||||
Required by the concept \ccc{FieldWithSqrt}.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
\begin{ccRefFunctionObjectConcept}{AlgebraicStructureTraits::Inverse}
|
||||
|
||||
\ccDefinition
|
||||
|
||||
\ccc{AdaptableUnaryFunction} providing the inverse element with
|
||||
respect to multiplication of a \ccc{Field}.
|
||||
|
||||
\ccRefines
|
||||
|
||||
\ccc{AdaptableUnaryFunction}
|
||||
|
||||
\ccTypes
|
||||
\ccNestedType{result_type}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Type}.}
|
||||
\ccNestedType{argument_type}
|
||||
{ Is \ccc{AlgebraicStructureTraits::Type}.}
|
||||
|
||||
\ccOperations
|
||||
\ccThree{xxxxxxxxxxx}{xxxxxxxxxxx}{}
|
||||
\ccCreationVariable{inverse}
|
||||
\ccMethod{result_type operator()(argument_type x) const;}
|
||||
{ returns the inverse element of $x$ with respect to multiplication.
|
||||
\ccPrecond $x \neq 0$
|
||||
}
|
||||
|
||||
%\ccHasModels
|
||||
|
||||
\ccSeeAlso
|
||||
|
||||
\ccRefIdfierPage{AlgebraicStructureTraits}
|
||||
|
||||
\end{ccRefFunctionObjectConcept}
|
||||
|
|
@ -12,8 +12,9 @@ operators / and /=.
|
|||
|
||||
Moreover, \ccc{CGAL::Algebraic_structure_traits< Field >} is a model of
|
||||
\ccc{AlgebraicStructureTraits} providing:\\
|
||||
- \ccc{CGAL::Algebraic_structure_traits< Field >::Algebraic_type} derived
|
||||
from \ccc{Field_tag} \\
|
||||
- \ccc{CGAL::Algebraic_structure_traits< Field >::Algebraic_type} derived from \ccc{Field_tag} \\
|
||||
- \ccc{CGAL::Algebraic_structure_traits< FieldWithSqrt >::Inverse}\\
|
||||
|
||||
|
||||
\ccRefines
|
||||
\ccc{IntegralDomain}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
\ccRefConceptPage{AlgebraicStructureTraits::DivMod}\\
|
||||
\ccRefConceptPage{AlgebraicStructureTraits::Div}\\
|
||||
\ccRefConceptPage{AlgebraicStructureTraits::Mod}\\
|
||||
\ccRefConceptPage{AlgebraicStructureTraits::Inverse}\\
|
||||
\ccRefConceptPage{AlgebraicStructureTraits::Sqrt}\\
|
||||
\ccRefConceptPage{AlgebraicStructureTraits::IsSquare}\\
|
||||
\ccRefConceptPage{AlgebraicStructureTraits::KthRoot}\\
|
||||
|
|
@ -61,6 +62,7 @@
|
|||
\ccRefIdfierPage{CGAL::div_mod}\\
|
||||
\ccRefIdfierPage{CGAL::div}\\
|
||||
\ccRefIdfierPage{CGAL::mod}\\
|
||||
\ccRefIdfierPage{CGAL::inverse}\\
|
||||
\ccRefIdfierPage{CGAL::sqrt}\\
|
||||
\ccRefIdfierPage{CGAL::kth_root}\\
|
||||
\ccRefIdfierPage{CGAL::root_of}\\
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
\begin{ccRefFunction}{inverse}
|
||||
|
||||
\ccDefinition
|
||||
|
||||
The function \ccRefName\ returns the inverse element with respect to multiplication.
|
||||
|
||||
The function is guaranteed to be well defined in case the argument type
|
||||
is a model of the \ccc{Field} concept.
|
||||
|
||||
\ccInclude{CGAL/number_utils.h}
|
||||
|
||||
\ccFunction{template <class NT> NT inverse(const NT& x);}
|
||||
{\ccPrecond $x \neq 0$}
|
||||
|
||||
|
||||
|
||||
\ccSeeAlso
|
||||
|
||||
\ccRefConceptPage{Field}\\
|
||||
\ccRefConceptPage{AlgebraicStructureTraits::Inverse}\\
|
||||
|
||||
\end{ccRefFunction}
|
||||
|
|
@ -35,6 +35,7 @@
|
|||
\input{Algebraic_foundations_ref/AlgebraicStructureTraits_DivMod.tex}
|
||||
\input{Algebraic_foundations_ref/AlgebraicStructureTraits_Div.tex}
|
||||
\input{Algebraic_foundations_ref/AlgebraicStructureTraits_Mod.tex}
|
||||
\input{Algebraic_foundations_ref/AlgebraicStructureTraits_Inverse.tex}
|
||||
\input{Algebraic_foundations_ref/AlgebraicStructureTraits_Sqrt.tex}
|
||||
\input{Algebraic_foundations_ref/AlgebraicStructureTraits_KthRoot.tex}
|
||||
\input{Algebraic_foundations_ref/AlgebraicStructureTraits_RootOf.tex}
|
||||
|
|
@ -63,6 +64,7 @@
|
|||
\input{Algebraic_foundations_ref/div_mod.tex}
|
||||
\input{Algebraic_foundations_ref/div.tex}
|
||||
\input{Algebraic_foundations_ref/mod.tex}
|
||||
\input{Algebraic_foundations_ref/inverse.tex}
|
||||
\input{Algebraic_foundations_ref/sqrt.tex}
|
||||
\input{Algebraic_foundations_ref/kth_root.tex}
|
||||
\input{Algebraic_foundations_ref/root_of.tex}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ class Algebraic_structure_traits {
|
|||
typedef Null_functor Kth_root;
|
||||
typedef Null_functor Root_of;
|
||||
typedef Null_functor Divides;
|
||||
typedef Null_functor Inverse;
|
||||
};
|
||||
|
||||
// The algebraic structure traits base class
|
||||
|
|
@ -462,6 +463,17 @@ class Algebraic_structure_traits_base< Type_, Field_tag >
|
|||
}
|
||||
CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR( Type )
|
||||
};
|
||||
|
||||
// maps to \c 1/x by default.
|
||||
class Inverse
|
||||
: public std::unary_function< Type, Type > {
|
||||
public:
|
||||
Type operator()( const Type& x ) const {
|
||||
static const Type& one = Type(1);
|
||||
return one/x;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Default implementation of Divides functor for Field:
|
||||
// returns always true
|
||||
|
|
|
|||
|
|
@ -358,6 +358,11 @@ void test_algebraic_structure_intern( const CGAL::Field_tag& ) {
|
|||
assert(!ie || tmp == AS(5)/AS(2));
|
||||
assert(CGAL_NTS divides(AS(5),AS(2),tmp));
|
||||
assert(!ie || tmp == AS(2)/AS(5));
|
||||
|
||||
typename AST::Inverse inverse;
|
||||
assert(AS(1)/AS(2) == inverse(AS(2)));
|
||||
assert(AS(1)/AS(2) == CGAL::inverse(AS(2)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,16 @@ square( const AS& x ) {
|
|||
typename Algebraic_structure_traits< AS >::Square square;
|
||||
return square( x );
|
||||
}
|
||||
|
||||
|
||||
template< class AS >
|
||||
inline
|
||||
typename Algebraic_structure_traits< AS >::Inverse::result_type
|
||||
inverse( const AS& x ) {
|
||||
typename Algebraic_structure_traits< AS >::Inverse inverse;
|
||||
return inverse( x );
|
||||
}
|
||||
|
||||
template< class AS >
|
||||
inline
|
||||
typename Algebraic_structure_traits<AS>::Is_one::result_type
|
||||
|
|
|
|||
Loading…
Reference in New Issue