includefile(include/header)

COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::PrimeFactors)(3bobcat)(_CurYrs_)
            (libbobcat-dev__CurVers_)(Prime Factorization)

manpagename(FBB::PrimeFactors)(Performs the prime-number factorization of
            (BigInt) values)

manpagesynopsis()
    bf(#include <bobcat/primefactors>)nl()
    Linking option: tt(-lbobcat) 

manpagedescription()

    Integral values fall into two categories: prime numbers, whose only
integral divisors are their own values and 1, and composite numbers, which
also have at least one other (prime number) integral divisor. All composite
integral values can be factorized as the product of prime numbers. E.g., 6 can
be factorized as 2 * 3; 8 can be factorized as 2 * 2 * 2. Finding these prime
factors is called the prime number factorization, or `prime
factorization'. When factorizing a value its prime factors may sometimes
repeatedly be used as integral divisors: 8 is factorized as tt(pow(2, 3)), and
36 is factorized as
        verb(
    36 = pow(2, 2) * pow(3, 2)
        )

    The class bf(FBB::PrimeFactors) performs prime number factorizations of
tt(FBB::BigInt) values. When factorizing a value prime numbers up to
tt(sqrt(value)) must be available, as prime numbers up to tt(sqrt(value)) may
be factors of tt(value). Currently tt(PrimeFactors) uses the sieve of
Eratosthenes to find these prime numbers. To find the next prime number beyond
tt(lastPrime), the sieve of Eratosthenes must be used repeatedly for
tt(lastPrime += 2) until tt(lastPrime) is prime. Once determined, prime
numbers can of course be used directly to determine the next prime number or
to factorize an integral value. To accellerate prime number factorization and
Eratosthenes's sieve bf(PrimeFactors) saves all its computed prime numbers in
either a tt(std::vector) or in a file. Once determined, these prime numbers
may again be used when factorizing the next integral value.

    After factorizing an integral value its prime number factors and
associated powers are made available in a vector of
(tt(PrimeFactors::PrimePower)) structs, containing the value's sorted prime
factors and associated powers.

includefile(include/namespace)

manpagesection(INHERITS FROM)
    -

manpagesection(TYPEDEFS AND ENUMS)

    itemization(
    itb(struct PrimePower) contains two fields:
        verb(
    struct PrimePower
    {
        BigInt prime;
        size_t power;
    };
        )
        Here, tt(power) represents the number of times tt(prime) can be used
as an integral divisor of the value that was factorized by bf(PrimeFactors).

    itb(Factors) is a synonym for tt(std::vector<PrimePower)
    )

manpagesection(CONSTRUCTORS)
    itemization(
    itb(PrimeFactors(BigIntVector &primes))
        Prime numbers that were determined while factorizing values are
collected in the tt(BigIntVector) that is passed as argument to this
constructor. 

    Initially the tt(BigIntVector) passed as argument may be empty or may
contain at least two primes (which must be, respectively, 2 and 3). The prime
numbers in tt(primes) must be sorted. The constructor does not verify whether
the prime numbers are actually sorted, but if the tt(BigIntVector) contains
primes it em(does) check whether the first two prime numbers are indeed 2 and
3. An tt(FBB::Exception) is thrown if this condition is not met.

    While numbers are being factorized, new prime numbers may be added to
tt(primes), and tt(primes) can be reused by othher tt(PrimeFactors) objects.

    itb(PrimeFactors(std::string const &name = "~/.primes", size_t blockSize =
1000))
        Prime numbers that are determined while factorizing values are
collected on a stream whose name is passed as argument to this constructor. By
default tt(~/.primes) is used. If tt(name) starts with `tt(~/)', then this
string is replaced by the user's home directory. 

    Primes are read from the named stream in blocks of at most tt(blockSize),
and new primes are flushed to this stream once tt(blockSize) new primes have
been generated or when the bf(PrimeFactors) object (i.e., the last
bf(PrimeFactors) object sharing the stream) ceases to exist.

    If the stream does not yet exist it is created by bf(PrimeFactors). The
stream may either be empty, or it must contain sorted and white-space
delimited prime numbers (inserted as hexadecimal tt(BigInt) values). The first
two primes on this file must be, respectively, 2 and 3. The constructor does
not verify whether the prime numbers are actually sorted, but if the stream
contains primes it em(does) check whether the first two prime numbers are
indeed 2 and 3. An tt(FBB::Exception) is thrown if this condition is not met.

    While numbers are being factorized, new prime numbers may be added to the
stream, and the stream can be reused by other tt(PrimeFactors) objects.
    )

    Copy and move constructors (and assignment operators) are available.

    bf(FBB::PrimeFactor) objects created using the copy constructor or
receiving their values using the copy assignment operator share the prime
numbers storage device (the tt(BigIntVector) or the stream containing the
primes) with their source objects.

manpagesection(MEMBER FUNCTION)

    itemization(
    itb(Factors const &factorize(BigInt const &value))
        The prime factors of tt(value) are determined and returned in the
tt(PrimeFactors::Factors) vectors. While the prime factors of tt(value) are
determined new prime numbers may be added to the tt(BigIntVector) or to the
stream that is passed to the bf(PrimeFactors) object. The elements of
tt(PrimeFactors::Factors) are sorted by their prime numbers. The first element
contains the value's smallest prime number factor.
    )

manpagesection(EXAMPLE)
    
        verbinclude(../../primefactors/driver/driver.cc)

    If this program is run with argument 1950 it produces the following
output: 
        verb(
    Using /tmp/primes:
    2**1 3**1 5**2 13**1 
    Using BigIntVector:
    2**1 3**1 5**2 13**1 
    Collected primes: 2 3 5 7 11 13 
        )

manpagefiles()
    em(bobcat/primefactors) - defines the class interface

manpageseealso()
    bf(bobcat)(7), bf(bigint)(3bobcat)

manpagebugs()
    None Reported.

includefile(include/trailer)
