nzmath.factor.util

FactoringMethod

Base class of factoring methods.
All methods defined in factor.methods are implemented as derived classes of this class. The main method factor is the only method user will call. Other methods continue_factor, find and generate are explained for a writer of a new factoring method.

Constructor

FactoringMethod()

Create an instance.

Methods

factor(number [, **options])

Factor the given positive integer number.

The default returned type is a list of tuples. Each tuple has a factor and its valuation, and the product is equal to the given number. It looks like:
[(p1, e1), ..., (pn, en)].

An option 'return_type' is for the returned type, whose value can be:

  1. 'list' for default type described above.
  2. 'tracker' for FactoringInteger.

An option 'need_sort' is boolean: True to sort the result. This should be specified with return_type='list'.

continue_factor(tracker [, **options])

Continue factoring and return the result of factorization.

The argument tracker should be an instance of FactoringInteger.

The default returned type is FactoringInteger, but if 'return_type' is specified as 'list' then it returns list of tuples (prime, index).
The primes are judged by a function specified in 'primeq' optional argument, default to nzmath.prime.primeq.

find(target [, **options])

Find a factor from the target number.

This method must be overridden, or factor method should be overridden not to call this method.

generate(target [, **options])

Generate prime factors of the target number with their valuations. The method may terminate with yielding (1, 1) to indicate the factorization is incomplete.

This method must be overridden, or factor method should be overridden not to call this method.
(new in 0.90.0)