The functions in the NumTheoryQQ
file are predominantly basic
operations from number theory which involve rational numbers (rather
than just integers). Please recall that computational number theory is
not the primary remit of CoCoALib, so do not expect to find a
complete collection of operations here -- you would do better to
look at Victor Shoup's NTL (Number Theory Library), or PARI/GP,
or some other specialized library/system.
Several of these functions give errors if they are handed unsuitable values:
unless otherwise indicated below the error is of type ERR::BadArg
.
The main functions available are:
ContFracIter(q)
constructs a new continued fraction iterator object
IsEnded(CFIter)
true iff the iterator has moved past the last "partial quotient"
*CFIter
gives the current "partial quotient"
++CFIter
move to next "partial quotient"
CFApproximantsIter(q)
construct a new continued fraction approximant iterator
IsEnded(CFAIter)
true iff the iterator has moved past the last "partial quotient"
*CFAIter
give the current continued fraction aproximant
++CFAIter
move to next approximant
It is all pretty simple. The only tricky part is that the "end" of
the ContFracIter
is represented by both myFrac
and myQuot
being
zero. This means that a newly created iterator for zero is already ended.
CFApproximantsIter
delegates most of the work to ContFracIter
.
How should these iterators be printed out?
ContFracIter
could be rather more efficient for rationals having
very large numerator and denominator. One way would be to compute with
num and den divided by the same large factor (probably a power of 2),
and taking care to monitor how accurate these "scaled" num and den are.
I'll wait until there is a real need before implementing (as I expect
it will turn out a bit messy).
CFApproximantsIter::operator
should be made more efficient.