Division

class durationtools.Division

Division.

Example 1. Division with duration, start offset and payload:

>>> division = durationtools.Division(
...     (3, 8),
...     payload=rhythmmakertools.NoteRhythmMaker(),
...     start_offset=Offset((5, 4)),
...     )
>>> print(format(division))
durationtools.Division(
    (3, 8),
    payload=rhythmmakertools.NoteRhythmMaker(),
    start_offset=durationtools.Offset(5, 4),
    )

Example 2. Division with duration and start offset:

>>> division = durationtools.Division(
...     (3, 8),
...     start_offset=Offset((5, 4)),
...     )
>>> print(format(division))
durationtools.Division(
    (3, 8),
    start_offset=durationtools.Offset(5, 4),
    )

Example 3. Division with duration:

>>> division = durationtools.Division((3, 8))
>>> print(format(division))
durationtools.Division(
    (3, 8)
    )

Example 4. Initializes from other division:

>>> division = durationtools.Division(
...     (3, 8),
...     payload=rhythmmakertools.NoteRhythmMaker(),
...     start_offset=Offset((5, 4)),
...     )
>>> new_division = durationtools.Division(division)
>>> print(format(new_division))
durationtools.Division(
    (3, 8),
    payload=rhythmmakertools.NoteRhythmMaker(),
    start_offset=durationtools.Offset(5, 4),
    )

Example 5. Initializes from nonreduced fraction:

>>> fraction = mathtools.NonreducedFraction((6, 4))
>>> division = durationtools.Division(
...     fraction,
...     payload=rhythmmakertools.NoteRhythmMaker(),
...     start_offset=Offset((5, 4)),
...     )
>>> new_division = durationtools.Division(division)
>>> print(format(new_division))
durationtools.Division(
    (6, 4),
    payload=rhythmmakertools.NoteRhythmMaker(),
    start_offset=durationtools.Offset(5, 4),
    )

Example 6. Empty initialization:

>>> division = durationtools.Division()
>>> print(format(division))
durationtools.Division(
    (0, 1)
    )

Example 7. Makes divisions from durations:

>>> durations = 10 * [Duration(1, 8)]
>>> start_offsets = mathtools.cumulative_sums(durations)[:-1]
>>> divisions = []
>>> for duration, start_offset in zip(durations, start_offsets):
...     division = durationtools.Division(
...         duration,
...         start_offset=start_offset,
...         )
...     divisions.append(division)
>>> divisions = Sequence(divisions)
>>> for division in divisions:
...     print(division)
Division((1, 8), start_offset=Offset(0, 1))
Division((1, 8), start_offset=Offset(1, 8))
Division((1, 8), start_offset=Offset(1, 4))
Division((1, 8), start_offset=Offset(3, 8))
Division((1, 8), start_offset=Offset(1, 2))
Division((1, 8), start_offset=Offset(5, 8))
Division((1, 8), start_offset=Offset(3, 4))
Division((1, 8), start_offset=Offset(7, 8))
Division((1, 8), start_offset=Offset(1, 1))
Division((1, 8), start_offset=Offset(9, 8))

Partitions divisions into thirds:

>>> ratio = mathtools.Ratio((1, 1, 1))
>>> parts = divisions.partition_by_ratio_of_lengths(ratio)

Gets middle third:

>>> for division in parts[1]:
...     division
Division((1, 8), start_offset=Offset(3, 8))
Division((1, 8), start_offset=Offset(1, 2))
Division((1, 8), start_offset=Offset(5, 8))
Division((1, 8), start_offset=Offset(3, 4))

Gets start offset of middle third:

>>> parts[1][0].start_offset
Offset(3, 8)

Example 8. Makes divisions from durations:

>>> durations = 10 * [Duration(1, 8)]
>>> start_offsets = mathtools.cumulative_sums(durations)[:-1]
>>> divisions = []
>>> for duration, start_offset in zip(durations, start_offsets):
...     division = durationtools.Division(
...         duration,
...         start_offset=start_offset,
...         )
...     divisions.append(division)
>>> divisions = Sequence(divisions)
>>> for division in divisions:
...     print(division)
Division((1, 8), start_offset=Offset(0, 1))
Division((1, 8), start_offset=Offset(1, 8))
Division((1, 8), start_offset=Offset(1, 4))
Division((1, 8), start_offset=Offset(3, 8))
Division((1, 8), start_offset=Offset(1, 2))
Division((1, 8), start_offset=Offset(5, 8))
Division((1, 8), start_offset=Offset(3, 4))
Division((1, 8), start_offset=Offset(7, 8))
Division((1, 8), start_offset=Offset(1, 1))
Division((1, 8), start_offset=Offset(9, 8))

Splits divisions every five sixteenths:

>>> parts = divisions.split([Fraction(5, 16)], cyclic=True)
>>> for i, part in enumerate(parts):
...     message = 'part {}'.format(i)
...     print(message)
...     for division in part:
...         print('\t' + str(division))
part 0
    Division((1, 8), start_offset=Offset(0, 1))
    Division((1, 8), start_offset=Offset(1, 8))
    Division((1, 16), start_offset=Offset(1, 4))
part 1
    Division((1, 16), start_offset=Offset(5, 16))
    Division((1, 8), start_offset=Offset(3, 8))
    Division((1, 8), start_offset=Offset(1, 2))
part 2
    Division((1, 8), start_offset=Offset(5, 8))
    Division((1, 8), start_offset=Offset(3, 4))
    Division((1, 16), start_offset=Offset(7, 8))
part 3
    Division((1, 16), start_offset=Offset(15, 16))
    Division((1, 8), start_offset=Offset(1, 1))
    Division((1, 8), start_offset=Offset(9, 8))

Gets start offset of first division of last part:

>>> parts[-1][0].start_offset
Offset(15, 16)

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_durationtools { graph [label=durationtools]; "abjad.tools.durationtools.Division.Division" [color=black, fontcolor=white, group=2, label=<<B>Division</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_mathtools { graph [label=mathtools]; "abjad.tools.mathtools.NonreducedFraction.NonreducedFraction" [color=5, group=4, label=NonreducedFraction, shape=box]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } subgraph cluster_fractions { graph [label=fractions]; "fractions.Fraction" [color=4, group=3, label=Fraction, shape=box]; } subgraph cluster_numbers { graph [label=numbers]; "numbers.Complex" [color=6, group=5, label=Complex, shape=oval, style=bold]; "numbers.Number" [color=6, group=5, label=Number, shape=box]; "numbers.Rational" [color=6, group=5, label=Rational, shape=oval, style=bold]; "numbers.Real" [color=6, group=5, label=Real, shape=oval, style=bold]; "numbers.Complex" -> "numbers.Real"; "numbers.Number" -> "numbers.Complex"; "numbers.Real" -> "numbers.Rational"; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.mathtools.NonreducedFraction.NonreducedFraction"; "abjad.tools.mathtools.NonreducedFraction.NonreducedFraction" -> "abjad.tools.durationtools.Division.Division"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; "builtins.object" -> "numbers.Number"; "fractions.Fraction" -> "abjad.tools.mathtools.NonreducedFraction.NonreducedFraction"; "numbers.Rational" -> "fractions.Fraction"; }

Attribute summary

conjugate() Conjugate is a no-op for Reals.
denominator Denominator of nonreduced fraction.
duration Gets duration of division.
from_decimal(dec) Converts a finite Decimal instance to a rational number, exactly.
from_float(f) Converts a finite float to a rational number, exactly.
imag Nonreduced fractions have no imaginary part.
limit_denominator([max_denominator]) Closest Fraction to self with denominator at most max_denominator.
multiply_with_cross_cancelation(multiplier) Multiplies nonreduced fraction by expr with cross-cancelation.
multiply_with_numerator_preservation(multiplier) Multiplies nonreduced fraction by multiplier with numerator preservation where possible.
multiply_without_reducing(expr) Multiplies nonreduced fraction by expr without reducing.
numerator Numerator of nonreduced fraction.
pair Read only pair of nonreduced fraction numerator and denominator.
payload Gets payload of division.
real Nonreduced fractions are their own real component.
reduce() Reduces nonreduced fraction.
start_offset Gets start offset of division.
stop_offset Gets stop offset of division.
with_denominator(denominator) Returns new nonreduced fraction with integer denominator.
with_multiple_of_denominator(denominator) Returns new nonreduced fraction with multiple of integer denominator.
__abs__() Absolute value of nonreduced fraction.
__add__(expr) Adds expr to division.
__bool__(a) a != 0
__ceil__(a) Will be math.ceil(a) in 3.0.
__complex__() complex(self) == complex(float(self), 0)
__copy__(\*args) Copies division.
__deepcopy__(\*args) Deep copies division.
__div__(expr) Divides nonreduced fraction by expr.
__divmod__(other) divmod(self, other): The pair (self // other, self % other).
__eq__(expr) Is true when expr equals nonreduced fraction.
__float__() float(self) = self.numerator / self.denominator
__floor__(a) Will be math.floor(a) in 3.0.
__floordiv__(a, b) a // b
__format__([format_specification]) Formats nonreduced fraction.
__ge__(expr) Is true when nonreduced fraction is greater than or equal to expr.
__gt__(expr) Is true when nonreduced fraction is greater than expr.
__hash__() Hashes nonreduced fraction.
__le__(expr) Is true when nonreduced fraction is less than or equal to expr.
__lt__(expr) Is true when nonreduced fraction is less than expr.
__mod__(a, b) a % b
__mul__(expr) Multiplies nonreduced fraction by expr.
__ne__(expr) Is true when expr does not equal nonreduced fraction.
__neg__() Negates nonreduced fraction.
__new__(class_[, argument, payload, ...])
__pos__(a) +a: Coerces a subclass instance to Fraction
__pow__(expr) Raises nonreduced fraction to expr.
__radd__(expr) Adds nonreduced fraction to expr.
__rdiv__(expr) Divides expr by nonreduced fraction.
__rdivmod__(other) divmod(other, self): The pair (self // other, self % other).
__repr__() Gets interpreter representation of nonreduced fraction.
__rfloordiv__(b, a) a // b
__rmod__(b, a) a % b
__rmul__(expr) Multiplies expr by nonreduced fraction.
__round__([ndigits]) Will be round(self, ndigits) in 3.0.
__rpow__(b, a) a ** b
__rsub__(expr) Subtracts nonreduced fraction from expr.
__rtruediv__(expr) Divides expr by nonreduced fraction.
__str__() Gets string representation of division.
__sub__(expr) Subtracts expr from division.
__truediv__(expr) Divides nonreduced fraction in Python 3.
__trunc__(a) trunc(a)

Read-only properties

(NonreducedFraction).denominator

Denominator of nonreduced fraction.

>>> fraction = mathtools.NonreducedFraction(-6, 3)
>>> fraction.denominator
3

Returns positive integer.

Division.duration

Gets duration of division.

Example 1. Gets duration:

>>> division = durationtools.Division((3, 8))
>>> division.duration
Duration(3, 8)

Example 2. Gets duration:

>>> division = durationtools.Division((6, 4))
>>> division.duration
Duration(3, 2)

Returns duration.

(NonreducedFraction).imag

Nonreduced fractions have no imaginary part.

>>> fraction.imag
0

Returns zero.

(NonreducedFraction).numerator

Numerator of nonreduced fraction.

>>> fraction = mathtools.NonreducedFraction(-6, 3)
>>> fraction.numerator
-6

Returns integer.

(NonreducedFraction).pair

Read only pair of nonreduced fraction numerator and denominator.

>>> fraction = mathtools.NonreducedFraction(-6, 3)
>>> fraction.pair
(-6, 3)

Returns integer pair.

Division.payload

Gets payload of division.

Example 1. Division with payload:

>>> division = durationtools.Division(
...     (3, 8),
...     payload=rhythmmakertools.NoteRhythmMaker(),
...     start_offset=Offset((5, 4)),
...     )
>>> division.payload
NoteRhythmMaker()

Example 2. Division without duration:

>>> division = durationtools.Division(
...     (3, 8),
...     start_offset=Offset((5, 4)),
...     )
>>> division.payload is None
True

Set to object or none.

Defaults to none.

Returns object or none.

(NonreducedFraction).real

Nonreduced fractions are their own real component.

>>> fraction.real
NonreducedFraction(-6, 3)

Returns nonreduced fraction.

Division.start_offset

Gets start offset of division.

Example 1. Division with start offset:

>>> division = durationtools.Division(
...     (3, 8),
...     start_offset=Offset((5, 4)),
...     )
>>> division.start_offset
Offset(5, 4)

Example 2. Division without start offset:

>>> division = durationtools.Division((3, 8))
>>> division.start_offset is None
True

Set to offset or none.

Defaults to none.

Returns offset or none.

Division.stop_offset

Gets stop offset of division.

Example 1. Division with start offset:

>>> division = durationtools.Division(
...     (3, 8),
...     start_offset=Offset((5, 4)),
...     )
>>> division.stop_offset
Offset(13, 8)

Example 2. Division without start offset:

>>> division = durationtools.Division((3, 8))
>>> division.stop_offset is None
True

Returns none when start offset is none.

Returns offset or none.

Methods

(Real).conjugate()

Conjugate is a no-op for Reals.

(Fraction).limit_denominator(max_denominator=1000000)

Closest Fraction to self with denominator at most max_denominator.

>>> Fraction('3.141592653589793').limit_denominator(10)
Fraction(22, 7)
>>> Fraction('3.141592653589793').limit_denominator(100)
Fraction(311, 99)
>>> Fraction(4321, 8765).limit_denominator(10000)
Fraction(4321, 8765)
(NonreducedFraction).multiply_with_cross_cancelation(multiplier)

Multiplies nonreduced fraction by expr with cross-cancelation.

>>> fraction = mathtools.NonreducedFraction(4, 8)
>>> fraction.multiply_with_cross_cancelation((2, 3))
NonreducedFraction(4, 12)
>>> fraction.multiply_with_cross_cancelation((4, 1))
NonreducedFraction(4, 2)
>>> fraction.multiply_with_cross_cancelation((3, 5))
NonreducedFraction(12, 40)
>>> fraction.multiply_with_cross_cancelation((6, 5))
NonreducedFraction(12, 20)
>>> fraction = mathtools.NonreducedFraction(5, 6)
>>> fraction.multiply_with_cross_cancelation((6, 5))
NonreducedFraction(1, 1)

Returns nonreduced fraction.

(NonreducedFraction).multiply_with_numerator_preservation(multiplier)

Multiplies nonreduced fraction by multiplier with numerator preservation where possible.

>>> fraction = mathtools.NonreducedFraction(9, 16)
>>> fraction.multiply_with_numerator_preservation((2, 3))
NonreducedFraction(9, 24)
>>> fraction.multiply_with_numerator_preservation((1, 2))
NonreducedFraction(9, 32)
>>> fraction.multiply_with_numerator_preservation((5, 6))
NonreducedFraction(45, 96)
>>> fraction = mathtools.NonreducedFraction(3, 8)
>>> fraction.multiply_with_numerator_preservation((2, 3))
NonreducedFraction(3, 12)

Returns nonreduced fraction.

(NonreducedFraction).multiply_without_reducing(expr)

Multiplies nonreduced fraction by expr without reducing.

>>> fraction = mathtools.NonreducedFraction(3, 8)
>>> fraction.multiply_without_reducing((3, 3))
NonreducedFraction(9, 24)
>>> fraction = mathtools.NonreducedFraction(4, 8)
>>> fraction.multiply_without_reducing((4, 5))
NonreducedFraction(16, 40)
>>> fraction.multiply_without_reducing((3, 4))
NonreducedFraction(12, 32)

Returns nonreduced fraction.

(NonreducedFraction).reduce()

Reduces nonreduced fraction.

>>> fraction = mathtools.NonreducedFraction(-6, 3)
>>> fraction.reduce()
Fraction(-2, 1)

Returns fraction.

(NonreducedFraction).with_denominator(denominator)

Returns new nonreduced fraction with integer denominator.

>>> mathtools.NonreducedFraction(3, 6).with_denominator(12)
NonreducedFraction(6, 12)

Returns nonreduced fraction.

(NonreducedFraction).with_multiple_of_denominator(denominator)

Returns new nonreduced fraction with multiple of integer denominator.

>>> fraction = mathtools.NonreducedFraction(3, 6)
>>> fraction.with_multiple_of_denominator(5)
NonreducedFraction(5, 10)

Returns nonreduced fraction.

Class & static methods

(Fraction).from_decimal(dec)

Converts a finite Decimal instance to a rational number, exactly.

(Fraction).from_float(f)

Converts a finite float to a rational number, exactly.

Beware that Fraction.from_float(0.3) != Fraction(3, 10).

Special methods

(NonreducedFraction).__abs__()

Absolute value of nonreduced fraction.

>>> abs(mathtools.NonreducedFraction(-3, 3))
NonreducedFraction(3, 3)

Returns nonreduced fraction.

Division.__add__(expr)

Adds expr to division.

Example 1. No start offsets:

>>> division_1 = durationtools.Division((2, 4))
>>> division_2 = durationtools.Division((4, 4))
>>> division_1 + division_2
Division((6, 4))

Example 2. One start offset:

>>> division_1 = durationtools.Division(
...     (2, 4),
...     start_offset=Offset(1),
...     )
>>> division_2 = durationtools.Division((4, 4))
>>> division_1 + division_2
Division((6, 4), start_offset=Offset(1, 1))

Example 3. Contiguous start offsets:

>>> division_1 = durationtools.Division(
...     (2, 4),
...     start_offset=Offset(1),
...     )
>>> division_2 = durationtools.Division(
...     (4, 4),
...     start_offset=Offset((3, 2)),
...     )
>>> division_1 + division_2
Division((6, 4), start_offset=Offset(1, 1))

Example 4. Noncontiguous start offsets:

>>> division_1 = durationtools.Division(
...     (2, 4),
...     start_offset=Offset(1),
...     )
>>> division_2 = durationtools.Division(
...     (4, 4),
...     start_offset=Offset(10),
...     )
>>> division_1 + division_2
Division((40, 4), start_offset=Offset(1, 1))

Example 5. Identical start offsets:

>>> division_1 = durationtools.Division(
...     (2, 4),
...     start_offset=Offset(1),
...     )
>>> division_2 = durationtools.Division(
...     (4, 4),
...     start_offset=Offset(1),
...     )
>>> division_1 + division_2
Division((4, 4), start_offset=Offset(1, 1))

Example 6. Overlapping start offsets:

>>> division_1 = durationtools.Division(
...     (2, 4),
...     start_offset=Offset(1),
...     )
>>> division_2 = durationtools.Division(
...     (4, 4),
...     start_offset=Offset((5, 4)),
...     )
>>> division_1 + division_2
Division((5, 4), start_offset=Offset(1, 1))

Returns new division.

(Fraction).__bool__(a)

a != 0

(Fraction).__ceil__(a)

Will be math.ceil(a) in 3.0.

(Real).__complex__()

complex(self) == complex(float(self), 0)

Division.__copy__(*args)

Copies division.

Returns new division.

Division.__deepcopy__(*args)

Deep copies division.

Returns new division.

(NonreducedFraction).__div__(expr)

Divides nonreduced fraction by expr.

>>> mathtools.NonreducedFraction(3, 3) / 1
NonreducedFraction(3, 3)

Returns nonreduced fraction.

(Real).__divmod__(other)

divmod(self, other): The pair (self // other, self % other).

Sometimes this can be computed faster than the pair of operations.

(NonreducedFraction).__eq__(expr)

Is true when expr equals nonreduced fraction.

>>> mathtools.NonreducedFraction(3, 3) == 1
True

Returns true or false.

(Rational).__float__()

float(self) = self.numerator / self.denominator

It’s important that this conversion use the integer’s “true” division rather than casting one side to float before dividing so that ratios of huge integers convert without overflowing.

(Fraction).__floor__(a)

Will be math.floor(a) in 3.0.

(Fraction).__floordiv__(a, b)

a // b

(NonreducedFraction).__format__(format_specification='')

Formats nonreduced fraction.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

>>> fraction = mathtools.NonreducedFraction(-6, 3)
>>> print(format(fraction))
mathtools.NonreducedFraction(-6, 3)

Returns string.

(NonreducedFraction).__ge__(expr)

Is true when nonreduced fraction is greater than or equal to expr.

>>> mathtools.NonreducedFraction(3, 3) >= 1
True

Returns true or false.

(NonreducedFraction).__gt__(expr)

Is true when nonreduced fraction is greater than expr.

>>> mathtools.NonreducedFraction(3, 3) > 1
False

Returns true or false.

(NonreducedFraction).__hash__()

Hashes nonreduced fraction.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(NonreducedFraction).__le__(expr)

Is true when nonreduced fraction is less than or equal to expr.

>>> mathtools.NonreducedFraction(3, 3) <= 1
True

Returns true or false.

(NonreducedFraction).__lt__(expr)

Is true when nonreduced fraction is less than expr.

>>> mathtools.NonreducedFraction(3, 3) < 1
False

Returns true or false.

(Fraction).__mod__(a, b)

a % b

(NonreducedFraction).__mul__(expr)

Multiplies nonreduced fraction by expr.

>>> mathtools.NonreducedFraction(3, 3) * 3
NonreducedFraction(9, 3)

Returns nonreduced fraction.

(NonreducedFraction).__ne__(expr)

Is true when expr does not equal nonreduced fraction.

>>> mathtools.NonreducedFraction(3, 3) != 'foo'
True

Returns true or false.

(NonreducedFraction).__neg__()

Negates nonreduced fraction.

>>> -mathtools.NonreducedFraction(3, 3)
NonreducedFraction(-3, 3)

Returns nonreduced fraction.

static Division.__new__(class_, argument=None, payload=None, start_offset=None)
(Fraction).__pos__(a)

+a: Coerces a subclass instance to Fraction

(NonreducedFraction).__pow__(expr)

Raises nonreduced fraction to expr.

>>> mathtools.NonreducedFraction(3, 6) ** -1
NonreducedFraction(6, 3)

Returns nonreduced fraction.

(NonreducedFraction).__radd__(expr)

Adds nonreduced fraction to expr.

>>> 1 + mathtools.NonreducedFraction(3, 3)
NonreducedFraction(6, 3)

Returns nonreduced fraction.

(NonreducedFraction).__rdiv__(expr)

Divides expr by nonreduced fraction.

>>> 1 / mathtools.NonreducedFraction(3, 3)
NonreducedFraction(3, 3)

Returns nonreduced fraction.

(Real).__rdivmod__(other)

divmod(other, self): The pair (self // other, self % other).

Sometimes this can be computed faster than the pair of operations.

(NonreducedFraction).__repr__()

Gets interpreter representation of nonreduced fraction.

>>> mathtools.NonreducedFraction(3, 6)
NonreducedFraction(3, 6)

Returns string.

(Fraction).__rfloordiv__(b, a)

a // b

(Fraction).__rmod__(b, a)

a % b

(NonreducedFraction).__rmul__(expr)

Multiplies expr by nonreduced fraction.

>>> 3 * mathtools.NonreducedFraction(3, 3)
NonreducedFraction(9, 3)

Returns nonreduced fraction.

(Fraction).__round__(ndigits=None)

Will be round(self, ndigits) in 3.0.

Rounds half toward even.

(Fraction).__rpow__(b, a)

a ** b

(NonreducedFraction).__rsub__(expr)

Subtracts nonreduced fraction from expr.

>>> 1 - mathtools.NonreducedFraction(3, 3)
NonreducedFraction(0, 3)

Returns nonreduced fraction.

(NonreducedFraction).__rtruediv__(expr)

Divides expr by nonreduced fraction.

>>> 1 / mathtools.NonreducedFraction(3, 3)
NonreducedFraction(3, 3)

Returns nonreduced fraction.

Division.__str__()

Gets string representation of division.

Returns string.

Division.__sub__(expr)

Subtracts expr from division.

Example 1. No timespans:

>>> division_1 = durationtools.Division((6, 2))
>>> division_2 = durationtools.Division((4, 2))
>>> division_1 - division_2
Division((2, 2))
>>> division_2 - division_1
Division((-2, 2))

Example 2. Overlapping timespans that start at the same time:

>>> division_1 = durationtools.Division(
...     (4, 1),
...     start_offset=Offset(10),
...     )
>>> division_2 = durationtools.Division(
...     (2, 1),
...     start_offset=Offset(10),
...     )
>>> division_1 - division_2
Division((2, 1), start_offset=Offset(12, 1))
>>> division_2 - division_1
Division((-2, 1), start_offset=Offset(12, 1))

Example 3. Overlapping timespans that start at different times:

>>> division_1 = durationtools.Division(
...     (4, 1),
...     start_offset=Offset(10),
...     )
>>> division_2 = durationtools.Division(
...     (4, 1),
...     start_offset=Offset(12),
...     )
>>> division_1 - division_2
Division((2, 1), start_offset=Offset(10, 1))
>>> division_2 - division_1
Division((2, 1), start_offset=Offset(14, 1))

Example 4. Nonoverlapping timespans:

>>> division_1 = durationtools.Division(
...     (6, 2),
...     start_offset=Offset(0),
...     )
>>> division_2 = durationtools.Division(
...     (4, 2),
...     start_offset=Offset(20),
...     )
>>> division_1 - division_2
Division((6, 2), start_offset=Offset(0, 1))
>>> division_2 - division_1
Division((4, 2), start_offset=Offset(20, 1))

Exceptions. Raises exception when one division has a start offset and the other does not:

>>> division_1 = durationtools.Division(
...     (6, 4),
...     start_offset=Offset(5),
...     )
>>> division_2 = durationtools.Division((2, 4))
>>> division_1 - division_2
Traceback (most recent call last):
...
Exception: both divisions must have (or not have) start offsets.
>>> division_2 - division_1
Traceback (most recent call last):
...
Exception: both divisions must have (or not have) start offsets.

Uses timespan arithmetic when both divisions have a start offset.

Returns new division.

(NonreducedFraction).__truediv__(expr)

Divides nonreduced fraction in Python 3.

Returns nonreduced fraction.

(Fraction).__trunc__(a)

trunc(a)