CGAL::Sqrt_extension<NT,ROOT>

In addition, Sqrt_extension has another two default template arguments:
DifferentExtensionComparable = ::CGAL::Tag_false
FilterPredicates = ::CGAL::Tag_false
See below for more details.

Definition

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<NT,ROOT> is RealEmbeddable if NT is RealEmbeddable.

For example, let Integer be some type representing , then Sqrt_extension<Integer,Integer> is able to represent [√root] for some arbitrary Integer root.1 The value of root is set at construction time, or set to zero if it is not specified.

Arithmetic operations among different extensions, say [√a] and [√b], are not supported. The result would be in [√a,√b], which is not representable by Sqrt_extension<Integer,Integer>. The user is responsible to check that arithmetic operations are carried out for elements from the same extensions only. This is not tested by Sqrt_extension<NT,ROOT> for efficiency reasons. A violation of the precondition leads to undefined behavior. Be aware that for efficiency reasons the given 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<NT,ROOT> that lie in different extensions are not interoperable with respect to any arithmetic operations, the full value range of Sqrt_extension<NT,ROOT> 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<NT,ROOT> can be used as if it were a model of an algebraic structure concept, with the following correspondence:

NT Sqrt_extension<NT,ROOT>

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 [√10], the extension of by 10: in [√10] the element 10 has two different factorizations 10 10 and 2 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 CGAL::Lazy_exact_nt<Sqrt_extension>.

In case NT is not RealEmbeddable, DifferentExtensionComparable as well as FilterPredicates have no effect.

Is Model for the Concepts

Assignable
CopyConstructible
DefaultConstructible
EqualityComparable
ImplicitInteroperable with int
ImplicitInteroperable with NT
Fraction if NT is a Fraction
RootOf_2

Creation

Sqrt_extension<NT,ROOT> ext;
Introduces an variable initialized with 0.

Sqrt_extension<NT,ROOT> ext ( Sqrt_extension x);
Copy constructor.

Sqrt_extension<NT,ROOT> ext ( int i);
Introduces an variable initialized with i.

Sqrt_extension<NT,ROOT> ext ( NT x);
Introduces an variable initialized with x.


Sqrt_extension<NT,ROOT> ext ( int a0, int a1, int r);
Constructor from int: ext= a0 +a1 sqrt(r).
Precondition: r 0

Sqrt_extension<NT,ROOT> ext ( NT a0, NT a1, ROOT r);
General constructor: ext= a0 + a1 sqrt(r).
Precondition: r 0

Operations

An object of type Sqrt_extension represent an expression of the form: a0 + a1 * sqrt(root).

NT ext.a0 () const Const access operator for a0
NT ext.a1 () const Const access operator for a1
ROOT ext.root () const Const access operator for root
bool ext.is_extended () const Returns true in case root of ext is not zero.
Note that a1 == 0 does not imply root == 0.

void ext.simplify () Simplifies the representation, in particular 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.

bool ext.is_zero () const returns true if ext represents the value zero.

CGAL::Sign ext.sign () const Determines the sign of ext by (repeated) squaring.
Precondition: Sqrt_extension is RealEmbeddable.

Sqrt_extension ext.abs () const returns the absolute value of ext.
Precondition: Sqrt_extension is RealEmbeddable.

CGAL::Comparison_result
ext.compare ( Sqrt_extension 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.

Sqrt_extension operator+ ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension operator- ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension operator* ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension & ext.operator+= ( Sqrt_extension a)
Precondition: (this->root()==0 or a.root()==0 or this->root() == a.root())
Sqrt_extension & ext.operator-= ( Sqrt_extension a)
Precondition: (this->root()==0 or a.root()==0 or this->root() == a.root())
Sqrt_extension & ext.operator*= ( Sqrt_extension a)
Precondition: (this->root()==0 or a.root()==0 or this->root() == a.root())

In case NT is only an IntegralDomain operator/ implements integral division. In case NT is a Field operator/ implements the field division.

Sqrt_extension operator/ ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
Sqrt_extension & ext.operator/= ( Sqrt_extension a)
Precondition: (this->root()==0 or a.root()==0 or this->root() == a.root())
bool operator== ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
bool operator!= ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())

In case Sqrt_extension is RealEmbeddable:

bool operator< ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
bool operator<= ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
bool operator> ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())
bool operator>= ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 or b.root()==0 or a.root() == b.root())

The stream operations are available as well. They assume that corresponding stream operators for type NT and ROOT exist.

std::ostream& operator<< ( std::ostream& os, ext)
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.

std::istream& operator>> ( std::istream& is, ext)
reads ext from istream is in format EXT[a0,a1,root], the output format in mode CGAL::IO::ASCII

See Also

IntegralDomainWithoutDivision
IntegralDomain
Field
RealEmbeddable
ImplicitInteroperable
Fraction
RootOf_2

CGAL::Tag_true
CGAL::Tag_false


Footnotes

 1  R[a] denotes the extension of a ring R by an element a. See also: http://mathworld.wolfram.com/ExtensionRing.html