DGtal
0.6.devel
|
#include <SternBrocot.h>
Public Types | |
typedef TInteger | Integer |
typedef TQuotient | Quotient |
typedef SternBrocot< TInteger, TQuotient > | SternBrocotTree |
typedef SternBrocotTree::Fraction | Self |
typedef NumberTraits< Integer > ::UnsignedVersion | UnsignedInteger |
typedef std::pair< Quotient, Quotient > | Value |
typedef std::vector< Quotient > | CFracSequence |
typedef InputIteratorWithRankOnSequence < CFracSequence, Quotient > | ConstIterator |
typedef Value | value_type |
typedef ConstIterator | const_iterator |
typedef const value_type & | const_reference |
Public Member Functions | |
Fraction (Integer aP, Integer aQ, Fraction ancestor=SternBrocotTree::zeroOverOne()) | |
Fraction (Node *sb_node=0) | |
Fraction (const Self &other) | |
Self & | operator= (const Self &other) |
bool | null () const |
Integer | p () const |
Integer | q () const |
Quotient | u () const |
Quotient | k () const |
Fraction | left () const |
Fraction | right () const |
bool | even () const |
bool | odd () const |
Fraction | father () const |
Fraction | father (Quotient m) const |
Fraction | previousPartial () const |
Fraction | inverse () const |
Fraction | partial (Quotient kp) const |
Fraction | reduced (Quotient i) const |
void | push_back (const std::pair< Quotient, Quotient > "ient) |
void | pushBack (const std::pair< Quotient, Quotient > "ient) |
void | getSplit (Fraction &f1, Fraction &f2) const |
void | getSplitBerstel (Fraction &f1, Quotient &nb1, Fraction &f2, Quotient &nb2) const |
void | getCFrac (std::vector< Quotient > "ients) const |
bool | equals (Integer p1, Integer q1) const |
bool | lessThan (Integer p1, Integer q1) const |
bool | moreThan (Integer p1, Integer q1) const |
bool | operator== (const Fraction &other) const |
bool | operator!= (const Fraction &other) const |
bool | operator< (const Fraction &other) const |
bool | operator> (const Fraction &other) const |
void | selfDisplay (std::ostream &out) const |
ConstIterator | begin () const |
ConstIterator | end () const |
Private Attributes | |
Node * | myNode |
This fraction is a model of CPositiveIrreducibleFraction.
It represents a positive irreducible fraction, i.e. some p/q qith gcd(p,q)=1. It is an inner class of SternBrocot. This representation of a fraction is simply a pointer to the corresponding node in this tree.
Definition at line 151 of file SternBrocot.h.
typedef std::vector<Quotient> DGtal::SternBrocot< TInteger, TQuotient >::Fraction::CFracSequence |
Definition at line 159 of file SternBrocot.h.
typedef ConstIterator DGtal::SternBrocot< TInteger, TQuotient >::Fraction::const_iterator |
Definition at line 164 of file SternBrocot.h.
typedef const value_type& DGtal::SternBrocot< TInteger, TQuotient >::Fraction::const_reference |
Definition at line 165 of file SternBrocot.h.
typedef InputIteratorWithRankOnSequence<CFracSequence,Quotient> DGtal::SternBrocot< TInteger, TQuotient >::Fraction::ConstIterator |
Definition at line 160 of file SternBrocot.h.
typedef TInteger DGtal::SternBrocot< TInteger, TQuotient >::Fraction::Integer |
Definition at line 153 of file SternBrocot.h.
typedef TQuotient DGtal::SternBrocot< TInteger, TQuotient >::Fraction::Quotient |
Definition at line 154 of file SternBrocot.h.
typedef SternBrocotTree::Fraction DGtal::SternBrocot< TInteger, TQuotient >::Fraction::Self |
Definition at line 156 of file SternBrocot.h.
typedef SternBrocot<TInteger,TQuotient> DGtal::SternBrocot< TInteger, TQuotient >::Fraction::SternBrocotTree |
Definition at line 155 of file SternBrocot.h.
typedef NumberTraits<Integer>::UnsignedVersion DGtal::SternBrocot< TInteger, TQuotient >::Fraction::UnsignedInteger |
Definition at line 157 of file SternBrocot.h.
typedef std::pair<Quotient, Quotient> DGtal::SternBrocot< TInteger, TQuotient >::Fraction::Value |
Definition at line 158 of file SternBrocot.h.
typedef Value DGtal::SternBrocot< TInteger, TQuotient >::Fraction::value_type |
Definition at line 163 of file SternBrocot.h.
|
inline |
Any fraction p/q. Complexity is in \( \sum_i u_i \), where u_i are the partial quotients of p/q.
aP | the numerator (>=0) |
aQ | the denominator (>=0) |
ancestor | (optional) any ancestor of aP/aQ in the tree (for speed-up). |
NB: Complexity is bounded by \( 2 \sum_i u_i \), where u_i are the partial quotients of aP/aQ.
Definition at line 70 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::operator=().
|
inline |
Default constructor.
sb_node | the associated node (or 0 for null fraction). |
Definition at line 78 of file SternBrocot.ih.
|
inline |
Copy constructor.
other | the object to clone. |
Definition at line 86 of file SternBrocot.ih.
|
inline |
Definition at line 483 of file SternBrocot.ih.
|
inline |
Definition at line 494 of file SternBrocot.ih.
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 155 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::fraction().
|
inline |
Definition at line 266 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left().
|
inline |
Definition at line 284 of file SternBrocot.ih.
|
inline |
m | a quotient between 1 and uk-1. |
Definition at line 293 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantRight, and DGtal::SternBrocot< TInteger, TQuotient >::Node::u.
|
inline |
quotients | (returns) the coefficients of the continued fraction of 'this'. |
Definition at line 460 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantRight, DGtal::SternBrocot< TInteger, TQuotient >::Node::k, and DGtal::SternBrocot< TInteger, TQuotient >::Node::u.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::display().
|
inline |
Splitting formula, O(1) time complexity. This fraction should not be 0/1 or 1/0. NB: 'this' = [f1] [f2].
f1 | (returns) the left part of the split. |
f2 | (returns) the right part of the split. |
Definition at line 427 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantRight, and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::myNode.
|
inline |
Berstel splitting formula, O(1) time complexity. This fraction should not be 0/1 or 1/0. NB: 'this' = nb1*[f1] nb2*[f2]. Also, if 'this->k' is even then nb1=1, otherwise nb2=1.
f1 | (returns) the left part of the split (left pattern). |
nb1 | (returns) the number of repetition of the left pattern |
f2 | (returns) the right part of the split (right pattern). |
nb2 | (returns) the number of repetition of the right pattern |
Definition at line 437 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantRight, and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::myNode.
|
inline |
Definition at line 326 of file SternBrocot.ih.
|
inline |
Definition at line 145 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::display(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left().
|
inline |
Definition at line 220 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantRight, DGtal::SternBrocot< TInteger, TQuotient >::Node::descendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::descendantRight, DGtal::SternBrocot< TInteger, TQuotient >::Fraction::even(), DGtal::SternBrocot< TInteger, TQuotient >::instance(), DGtal::SternBrocot< TInteger, TQuotient >::Node::inverse, DGtal::SternBrocot< TInteger, TQuotient >::Fraction::k(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::myNode, DGtal::SternBrocot< TInteger, TQuotient >::nbFractions, DGtal::SternBrocot< TInteger, TQuotient >::Node::p, DGtal::SternBrocot< TInteger, TQuotient >::Fraction::p(), DGtal::SternBrocot< TInteger, TQuotient >::Node::q, DGtal::SternBrocot< TInteger, TQuotient >::Fraction::q(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::u().
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::fraction(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::pushBack(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::right().
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 164 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::fraction().
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 174 of file SternBrocot.ih.
|
inline |
Definition at line 108 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::display().
|
inline |
Definition at line 275 of file SternBrocot.ih.
|
inline |
other | any fraction. |
Definition at line 193 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::myNode.
|
inline |
other | any fraction. |
Definition at line 202 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::p(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::q().
|
inline |
Assignment
other | the object to clone. |
Definition at line 95 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::myNode.
|
inline |
other | any fraction. |
Definition at line 184 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::myNode.
|
inline |
other | any fraction. |
Definition at line 211 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::p(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::q().
|
inline |
Definition at line 117 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::display(), DGtal::SternBrocot< TInteger, TQuotient >::fraction(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::operator<(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::operator>().
|
inline |
|
inline |
Definition at line 314 of file SternBrocot.ih.
|
inline |
Modifies this fraction \form#77 to obtain the fraction \form#147. The depth of the quotient must be given, since continued fractions have two writings
\([u_0,...,u_k]\) and \([u_0,...,u_k - 1, 1]\).
Useful to create output iterators, for instance with @code typedef ... Fraction; Fraction f; std::back_insert_iterator<Fraction> itout = std::back_inserter( f ); @endcode @param quotient the pair \form#76.
Definition at line 364 of file SternBrocot.ih.
|
inline |
Modifies this fraction \form#77 to obtain the fraction \form#147. The depth of the quotient must be given, since continued fractions have two writings
\([u_0,...,u_k]\) and \([u_0,...,u_k - 1, 1]\).
See push_back for creating output iterators. @param quotient the pair \form#76.
Definition at line 373 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left(), DGtal::SternBrocot< TInteger, TQuotient >::oneOverZero(), DGtal::SternBrocot< TInteger, TQuotient >::operator=(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::right(), and DGtal::SternBrocot< TInteger, TQuotient >::zeroOverOne().
|
inline |
Definition at line 126 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::display(), DGtal::SternBrocot< TInteger, TQuotient >::fraction(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::operator<(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::operator>().
|
inline |
i | a positive integer smaller or equal to k()+2. |
Definition at line 345 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantRight, and DGtal::SternBrocot< TInteger, TQuotient >::Node::k.
|
inline |
Definition at line 251 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left().
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::fraction(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::pushBack().
|
inline |
Writes/Displays the fraction on an output stream.
out | the output stream where the object is written. |
Definition at line 504 of file SternBrocot.ih.
|
inline |
Definition at line 135 of file SternBrocot.ih.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::display(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left().
|
private |
Definition at line 168 of file SternBrocot.h.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::Fraction::getSplit(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::getSplitBerstel(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::operator!=(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::operator=(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::operator==().