CGAL 5.4.2 - Number Types
|
#include <CGAL/Sqrt_extension.h>
An instance of this class represents an extension of the type NT
by one square root of the type ROOT
.
NT
is required to be constructible from ROOT
.
NT
is required to be an IntegralDomainWithoutDivision
.
Sqrt_extension
is RealEmbeddable
if NT is RealEmbeddable
.
For example, let Integer
be some type representing \( \Z\), then Sqrt_extension<Integer,Integer>
is able to represent \( \Z[\sqrt{\mathrm{root}}]\) for some arbitrary Integer \(\mathrm{root}\). \( R[a]\) denotes the extension of a ring \( R\) by an element \( a\). See also: http://mathworld.wolfram.com/ExtensionRing.html
The value of \(\mathrm{root}\) is set at construction time, or set to zero if it is not specified.
Arithmetic operations among different extensions, say \( \Z[\sqrt{a}]\) and \( \Z[\sqrt{b}]\), are not supported. The result would be in \( \Z[\sqrt{a},\sqrt{b}]\), which is not representable by Sqrt_extension<Integer,Integer>
.
This is not tested by Sqrt_extension
for efficiency reasons. A violation of the precondition leads to undefined behavior. Be aware that for efficiency reasons the given \(\mathrm{root}\) is stored as it is given to the constructor. In particular, an extension by a square root of a square is considered as an extension.
Since elements of Sqrt_extension
that lie in different extensions are not interoperable with respect to any arithmetic operations, the full value range of Sqrt_extension
does not represent an algebraic structure. However, each subset of the value range that represents the extension of NT by a particular square root is a valid algebraic structure, since this subset is closed under all provided arithmetic operations. From there, Sqrt_extension
can be used as if it were a model of an algebraic structure concept, with the following correspondence:
NT | Sqrt_extension |
IntegralDomainWithoutDivision | IntegralDomainWithoutDivision |
IntegralDomain | IntegralDomain |
UniqueFactorizationDomain | IntegralDomain |
EuclideanRing | IntegralDomain |
Field | Field |
The extension of a UniqueFactorizationDomain
or EuclideanRing
is just an IntegralDomain
, since the extension in general destroys the unique factorization property. For instance consider \( \Z[\sqrt{10}]\), the extension of \( \Z\) by \( \sqrt{10}\): in \( \Z[\sqrt{10}]\) the element 10 has two different factorizations \( \sqrt{10} \cdot \sqrt{10}\) and \( 2 \cdot 5\). In particular, the factorization is not unique.
If NT
is a model of RealEmbeddable
the type Sqrt_extension
is also considered as RealEmbeddable
. However, by default it is not allowed to compare values from different extensions for efficiency reasons. In case such a comparison becomes necessary, use the member function compare with the according Boolean flag. If such a comparison is a very frequent case, override the default of DifferentExtensionComparable
by giving CGAL::Tag_true
as third template parameter. This effects the behavior of compare functions as well as the compare operators.
The fourth template argument, FilterPredicates
, triggers an internal filter that may speed up comparisons and sign computations. In case FilterPredicates
is set to CGAL::Tag_true
the type first computes a double interval containing the represented number and tries to perform the comparison or sign computation using this interval. Once computed, this interval is stored by the corresponding Sqrt_extension
object for further usage. Note that this internal filter is switched off by default, since it may conflict with other filtering methods, such as Lazy_exact_nt<Sqrt_extension>
.
In case NT
is not RealEmbeddable
, DifferentExtensionComparable
as well as FilterPredicates
have no effect.
ImplicitInteroperable
with int
ImplicitInteroperable
with NT
Related Functions | |
(Note that these are not member functions.) | |
Sqrt_extension | operator+ (const Sqrt_extension &a, const Sqrt_extension &b) |
Sqrt_extension | operator- (const Sqrt_extension &a, const Sqrt_extension &b) |
Sqrt_extension | operator* (const Sqrt_extension &a, const Sqrt_extension &b) |
Sqrt_extension | operator/ (const Sqrt_extension &a, const Sqrt_extension &b) |
bool | operator== (const Sqrt_extension &a, const Sqrt_extension &b) |
bool | operator!= (const Sqrt_extension &a, const Sqrt_extension &b) |
bool | operator< (const Sqrt_extension &a, const Sqrt_extension &b) |
bool | operator<= (const Sqrt_extension &a, const Sqrt_extension &b) |
bool | operator> (const Sqrt_extension &a, const Sqrt_extension &b) |
bool | operator>= (const Sqrt_extension &a, const Sqrt_extension &b) |
std::ostream & | operator<< (std::ostream &os, const Sqrt_extension< NT, ROOT > &ext) |
writes ext to ostream os . More... | |
std::istream & | operator>> (std::istream &is, const Sqrt_extension< NT, ROOT > &ext) |
reads ext from istream is in format EXT[a0,a1,root] , the output format in mode CGAL::IO::ASCII More... | |
Creation | |
Sqrt_extension () | |
Introduces a variable ext initialized with 0. | |
Sqrt_extension (const Sqrt_extension &x) | |
Copy constructor. | |
Sqrt_extension (const int &i) | |
Introduces a variable ext initialized with \( i\). | |
Sqrt_extension (const NT &x) | |
Introduces a variable ext initialized with \( x\). | |
template<class NTX > | |
Sqrt_extension (const NTX &x) | |
Introduces a variable ext initialized with \( x\). More... | |
Sqrt_extension (int a0, int a1, int r) | |
Constructor from int: ext \( = a0 +a1 \cdot sqrt(r)\). More... | |
Sqrt_extension (NT a0, NT a1, ROOT r) | |
General constructor: ext \( = a0 + a1 \cdot sqrt(r)\). More... | |
Operations | |
An object of type | |
const NT & | a0 () const |
Const access operator for a0. | |
const NT & | a1 () const |
Const access operator for a1. | |
const ROOT & | root () const |
Const access operator for root. | |
bool | is_extended () const |
Returns true in case root of ext is not zero. More... | |
void | simplify () |
Simplifies the representation, in particular \(\mathrm{root}\) is set to zero if \( a1\) is zero, that is, ext becomes not extended. More... | |
bool | is_zero () const |
returns true if ext represents the value zero. | |
CGAL::Sign | sign () const |
Determines the sign of ext by (repeated) squaring. More... | |
Sqrt_extension | abs () const |
returns the absolute value of ext . More... | |
CGAL::Comparison_result | compare (const Sqrt_extension &y, bool in_same_extension=!DifferentExtensionComparable::value) const |
Compares ext with y. More... | |
Sqrt_extension & | operator+= (const Sqrt_extension &a) |
Sqrt_extension & | operator-= (const Sqrt_extension &a) |
Sqrt_extension & | operator*= (const Sqrt_extension &a) |
Sqrt_extension & | operator/= (const Sqrt_extension &a) |
|
explicit |
Introduces a variable ext
initialized with \( x\).
CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::Sqrt_extension | ( | int | a0, |
int | a1, | ||
int | r | ||
) |
Constructor from int: ext
\( = a0 +a1 \cdot sqrt(r)\).
CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::Sqrt_extension | ( | NT | a0, |
NT | a1, | ||
ROOT | r | ||
) |
General constructor: ext
\( = a0 + a1 \cdot sqrt(r)\).
Sqrt_extension CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::abs | ( | ) | const |
returns the absolute value of ext
.
Sqrt_extension
is RealEmbeddable
. CGAL::Comparison_result CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::compare | ( | const Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates > & | y, |
bool | in_same_extension = !DifferentExtensionComparable::value |
||
) | const |
Compares ext
with y.
The optional bool in_same_extension
indicates whether ext
and \( y\) are in the same extension of NT.
bool CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::is_extended | ( | ) | const |
Returns true in case root of ext
is not zero.
Note that \( a1 == 0 \) does not imply \( \mathrm{root} == 0\).
Sqrt_extension& CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::operator*= | ( | const Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates > & | a | ) |
Sqrt_extension& CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::operator+= | ( | const Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates > & | a | ) |
Sqrt_extension& CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::operator-= | ( | const Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates > & | a | ) |
Sqrt_extension& CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::operator/= | ( | const Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates > & | a | ) |
In case NT
is only an IntegralDomain
operator/ implements integral division. In case NT
is a Field
operator/ implements the field division.
CGAL::Sign CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::sign | ( | ) | const |
Determines the sign of ext
by (repeated) squaring.
Sqrt_extension
is RealEmbeddable
. void CGAL::Sqrt_extension< NT, ROOT, DifferentExtensionComparable, FilterPredicates >::simplify | ( | ) |
Simplifies the representation, in particular \(\mathrm{root}\) is set to zero if \( a1\) is zero, that is, ext
becomes not extended.
Moreover, it propagates the simplify command to members of ext
. see also: AlgebraicStructureTraits::Simplify
.
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
In case NT
is only an IntegralDomain
operator/ implements integral division. In case NT
is a Field
operator/ implements the field division.
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension
is RealEmbeddable
.
|
related |
writes ext
to ostream os
.
The format depends on the CGAL::IO::MODE
of os
.
In case the mode is CGAL::IO::ASCII
the format is EXT[a0,a1,root]
.
In case the mode is CGAL::IO::PRETTY
the format is human readable.
operator>>
must be defined for ROOT
and NT
.
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension
is RealEmbeddable
.
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension
is RealEmbeddable
.
|
related |
(a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension
is RealEmbeddable
.
|
related |
reads ext
from istream is
in format EXT[a0,a1,root]
, the output format in mode CGAL::IO::ASCII
operator<<
must be defined exist for ROOT
and NT
.