partition_integer_into_halves

mathtools.partition_integer_into_halves(n, bigger=Left, even='allowed')

Writes positive integer n as the pair t = (left, right) such that n == left + right.

When n is odd the greater part of t corresponds to the value of bigger:

>>> mathtools.partition_integer_into_halves(7, bigger=Left)
(4, 3)
>>> mathtools.partition_integer_into_halves(7, bigger=Right)
(3, 4)

Likewise when n is even and even = 'disallowed':

>>> mathtools.partition_integer_into_halves(
...     8,
...     bigger=Left,
...     even='disallowed',
...     )
(5, 3)
>>> mathtools.partition_integer_into_halves(
...     8,
...     bigger=Right,
...     even='disallowed',
...     )
(3, 5)

But when n is even and even = 'allowed' then left == right and bigger is ignored:

>>> mathtools.partition_integer_into_halves(8)
(4, 4)
>>> mathtools.partition_integer_into_halves(8, bigger=Left)
(4, 4)
>>> mathtools.partition_integer_into_halves(8, bigger=Right)
(4, 4)

When n is 0 returns (0, 0):

>>> mathtools.partition_integer_into_halves(0)
(0, 0)

When n is 0 and even = 'disallowed' raises partition error.

Raises type error on noninteger n.

Raises value error on negative n.

Returns pair of positive integers.