CGAL::Sqrt_extension<NT,ROOT>

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 [sqrt(root)] for some arbitrary value root. The value of root is set at construction time, or left open if root is not specified.

Note that 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.

It is not possible to interoperate two values from two different extensions [sqrt(a)] and [sqrt(b)], since the result is in [sqrt(a),sqrt(b)], which is not representable by Sqrt_extension<Integer,Integer>.


begin of advanced section  advanced  begin of advanced section
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 an UniqueFactorizationDomain or EuclideanRing is just an IntegralDomain, since the extension in general destroys the unique factorization property, e.g.,

10 = sqrt(10) · sqrt(10) = 2 · 5 over [sqrt(10)]

Note that the user is responsible for checking that the elements of Sqrt_extension<NT,ROOT> that are manipulated are actually in a same extension field. If different extension fields are mixed together, the code may crash at runtime!

In the same way Sqrt_extension can be used as if it were a model of RealEmbeddable if NT is model of RealEmbeddable. Comparisons of two values from different extension via operators is not allowed. However, the member function compare provides this comparison.

end of advanced section  advanced  end of advanced section

Is Model for the Concepts

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

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);
Constructor from int.


Sqrt_extension<NT,ROOT> ext ( NT x);
Constructor from type NT.


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


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

Operations

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

bool ext.is_extended () Returns true in case root of ext is not zero.
Note that a1 == 0 does not imply root == 0.

NT ext.a0 () Const access operator for a0
NT ext.a1 () Const access operator for a1
ROOT ext.root () Const access operator for root
void ext.simplify () Propagates the simplify command to members of ext.
see also: AlgebraicStructureTraits::Simplify.

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

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

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

Sqrt_extension ext.compare ( Sqrt_extension y, bool in_same_extension = false)
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 || b.root()==0 || a.root() == b.root())
Sqrt_extension operator- ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 || b.root()==0 || a.root() == b.root())
Sqrt_extension operator* ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 || b.root()==0 || a.root() == b.root())
Sqrt_extension & ext.operator+= ( Sqrt_extension a)
Precondition: (this->root()==0 || a.root()==0 || this->root() == a.root())
Sqrt_extension & ext.operator-= ( Sqrt_extension a)
Precondition: (this->root()==0 || a.root()==0 || this->root() == a.root())
Sqrt_extension & ext.operator*= ( Sqrt_extension a)
Precondition: (this->root()==0 || a.root()==0 || this->root() == a.root())

In case NT is an IntegralDomain operator/ implements integral division.

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

In case Sqrt_extension is RealEmbeddable:

bool operator< ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 || b.root()==0 || a.root() == b.root())
bool operator<= ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 || b.root()==0 || a.root() == b.root())
bool operator> ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 || b.root()==0 || a.root() == b.root())
bool operator>= ( Sqrt_extension a, Sqrt_extension b)
Precondition: (a.root()==0 || b.root()==0 || 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