Ratio

class mathtools.Ratio(numbers=(1, 1))

Ratio.

Example 1. Ratio of two numbers:

>>> mathtools.Ratio((2, 4))
Ratio((1, 2))

Example 2. Ratio of three numbers:

>>> mathtools.Ratio((2, 4, 2))
Ratio((1, 2, 1))

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.AbjadValueObject.AbjadValueObject" [color=1, group=0, label=AbjadValueObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.AbjadValueObject.AbjadValueObject"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_mathtools { graph [label=mathtools]; "abjad.tools.mathtools.NonreducedRatio.NonreducedRatio" [color=3, group=2, label=NonreducedRatio, shape=box]; "abjad.tools.mathtools.Ratio.Ratio" [color=black, fontcolor=white, group=2, label=<<B>Ratio</B>>, shape=box, style="filled, rounded"]; "abjad.tools.mathtools.NonreducedRatio.NonreducedRatio" -> "abjad.tools.mathtools.Ratio.Ratio"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" -> "abjad.tools.mathtools.NonreducedRatio.NonreducedRatio"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

count(expr) Gets count of expr in ratio.
index(expr) Gets index of expr in ratio.
multipliers Gets multipliers of ratio.
numbers Gets numbers of ratio.
__contains__(expr) Is true when ratio contains expr.
__copy__(\*args) Copies Abjad value object.
__eq__(expr) Is true when expr is a nonreduced ratio with numerator and denominator equal to those of this nonreduced ratio.
__format__([format_specification]) Formats duration.
__getitem__(i) Gets item at i.
__hash__() Hashes non-reduced ratio.
__iter__() Iterates ratio.
__len__() Gets length of ratio.
__ne__(expr) Is true when Abjad object does not equal expr.
__repr__() Gets interpreter representation of Abjad object.
__reversed__() Iterates ratio in reverse.
__str__() Gets string representation of ratio.

Read-only properties

Ratio.multipliers

Gets multipliers of ratio.

Example 1. Ratio of two numbers:

>>> ratio = mathtools.Ratio((2, 4))
>>> ratio.multipliers
(Multiplier(1, 3), Multiplier(2, 3))

Example 2. Ratio of three numbers:

>>> ratio = mathtools.Ratio((2, 4, 2))
>>> ratio.multipliers
(Multiplier(1, 4), Multiplier(1, 2), Multiplier(1, 4))

Returns tuple of multipliers.

Ratio.numbers

Gets numbers of ratio.

Example 1. Ratio of two numbers:

>>> ratio = mathtools.Ratio((2, 4))
>>> ratio.numbers
(1, 2)

Example 2. Ratio of three numbers:

>>> ratio = mathtools.Ratio((2, 4, 2))
>>> ratio.numbers
(1, 2, 1)

Set to tuple of two or more numbers.

Returns tuple of two or more numbers.

Methods

(NonreducedRatio).count(expr)

Gets count of expr in ratio.

Returns integer.

(NonreducedRatio).index(expr)

Gets index of expr in ratio.

Returns integer.

Special methods

(NonreducedRatio).__contains__(expr)

Is true when ratio contains expr. Otherwise false.

Returns true or false.

(AbjadValueObject).__copy__(*args)

Copies Abjad value object.

Returns new Abjad value object.

(NonreducedRatio).__eq__(expr)

Is true when expr is a nonreduced ratio with numerator and denominator equal to those of this nonreduced ratio. Otherwise false.

Returns true or false.

(NonreducedRatio).__format__(format_specification='')

Formats duration.

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

>>> ratio = mathtools.NonreducedRatio((2, 4, 2))
>>> print(format(ratio))
mathtools.NonreducedRatio((2, 4, 2))

Returns string.

Ratio.__getitem__(i)

Gets item at i.

>>> ratio = mathtools.Ratio((2, 4, 2))
>>> ratio[1]
2

Returns integer or tuple.

(NonreducedRatio).__hash__()

Hashes non-reduced ratio.

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

Returns integer.

(NonreducedRatio).__iter__()

Iterates ratio.

Returns generator.

Ratio.__len__()

Gets length of ratio.

>>> ratio = mathtools.Ratio((2, 4, 2))
>>> len(ratio)
3

Returns integer.

(AbjadObject).__ne__(expr)

Is true when Abjad object does not equal expr. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(NonreducedRatio).__reversed__()

Iterates ratio in reverse.

Returns generator.

Ratio.__str__()

Gets string representation of ratio.

Example 1. Ratio of two numbers:

>>> str(mathtools.Ratio((2, 4)))
'1:2'

Example 2. Ratio of three numbers:

>>> str(mathtools.Ratio((2, 4, 2)))
'1:2:1'

Returns string.