Ratio

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.mathtools" { graph [label="abjad.mathtools"]; node [color=1]; "abjad.mathtools.NonreducedRatio.NonreducedRatio" [URL="../api/abjad/mathtools/NonreducedRatio.html#abjad.mathtools.NonreducedRatio.NonreducedRatio", label="Nonreduced\nRatio", target=_top]; "abjad.mathtools.Ratio.Ratio" [URL="../api/abjad/mathtools/Ratio.html#abjad.mathtools.Ratio.Ratio", color=black, fontcolor=white, label=Ratio, target=_top]; "abjad.mathtools.NonreducedRatio.NonreducedRatio" -> "abjad.mathtools.Ratio.Ratio"; } subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=2]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/mathtools/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; "abjad.system.AbjadValueObject.AbjadValueObject" [URL="../api/abjad/mathtools/../system/AbjadValueObject.html#abjad.system.AbjadValueObject.AbjadValueObject", label="Abjad\nValue\nObject", target=_top]; "abjad.system.AbjadObject.AbjadObject" -> "abjad.system.AbjadValueObject.AbjadValueObject"; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_collections.abc" { graph [label="collections.abc"]; node [color=4]; "collections.abc.Collection" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Collection", label=Collection, shape=oval, style=bold, target=_top]; "collections.abc.Container" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Container", label=Container, shape=oval, style=bold, target=_top]; "collections.abc.Iterable" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Iterable", label=Iterable, shape=oval, style=bold, target=_top]; "collections.abc.Reversible" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Reversible", label=Reversible, shape=oval, style=bold, target=_top]; "collections.abc.Sequence" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sequence", label=Sequence, shape=oval, style=bold, target=_top]; "collections.abc.Sized" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sized", label=Sized, shape=oval, style=bold, target=_top]; "collections.abc.Collection" -> "collections.abc.Sequence"; "collections.abc.Container" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Reversible"; "collections.abc.Reversible" -> "collections.abc.Sequence"; "collections.abc.Sized" -> "collections.abc.Collection"; } "abjad.system.AbjadValueObject.AbjadValueObject" -> "abjad.mathtools.NonreducedRatio.NonreducedRatio"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; "builtins.object" -> "collections.abc.Container"; "builtins.object" -> "collections.abc.Iterable"; "builtins.object" -> "collections.abc.Sized"; "collections.abc.Sequence" -> "abjad.mathtools.NonreducedRatio.NonreducedRatio"; }

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

Ratio.

Ratio of two numbers:

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

Ratio of three numbers:

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

Attributes Summary

__eq__ Is true when argument equals ratio.
__getitem__ Gets item or slice identified by argument.
__hash__ Hashes ratio.
__len__ Gets length of ratio.
__str__ Gets string representation of ratio.
multipliers Gets multipliers of ratio.
numbers Gets numbers of ratio.
reciprocal Gets reciprocal.

Special methods

(NonreducedRatio).__contains__(argument)

Is true when ratio contains argument.

Returns true or false.

(AbjadValueObject).__copy__(*arguments)

Copies Abjad value object.

Returns new Abjad value object.

__eq__(argument)

Is true when argument equals ratio.

>>> ratio_1 = abjad.Ratio((1, 2, 1))
>>> ratio_2 = abjad.Ratio((1, 2, 1))
>>> ratio_3 = abjad.Ratio((2, 3, 3))
>>> ratio_1 == ratio_1
True
>>> ratio_1 == ratio_2
True
>>> ratio_1 == ratio_3
False
>>> ratio_2 == ratio_1
True
>>> ratio_2 == ratio_2
True
>>> ratio_2 == ratio_3
False
>>> ratio_3 == ratio_1
False
>>> ratio_3 == ratio_2
False
>>> ratio_3 == ratio_3
True
(NonreducedRatio).__format__(format_specification='')

Formats duration.

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

Returns string.

__getitem__(argument)

Gets item or slice identified by argument.

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

Returns integer or tuple.

__hash__()

Hashes ratio.

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

Returns integer.

(NonreducedRatio).__iter__()

Iterates ratio.

Returns generator.

__len__()

Gets length of ratio.

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

Returns integer.

(NonreducedRatio).__rdiv__(number)

Divides number by ratio.

>>> 1 / abjad.Ratio((1, 1, 3))
[Fraction(1, 5), Fraction(1, 5), Fraction(3, 5)]
>>> abjad.Fraction(1) / abjad.Ratio((1, 1, 3))
[Fraction(1, 5), Fraction(1, 5), Fraction(3, 5)]
>>> 1.0 / abjad.Ratio((1, 1, 3))
[0.2, 0.2, 0.6]

Returns list of fractions or list of floats.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(NonreducedRatio).__reversed__()

Iterates ratio in reverse.

Returns generator.

(NonreducedRatio).__rtruediv__(number)

Divides number by ratio.

>>> 1 / abjad.Ratio((1, 1, 3))
[Fraction(1, 5), Fraction(1, 5), Fraction(3, 5)]
>>> abjad.Fraction(1) / abjad.Ratio((1, 1, 3))
[Fraction(1, 5), Fraction(1, 5), Fraction(3, 5)]
>>> 1.0 / abjad.Ratio((1, 1, 3))
[0.2, 0.2, 0.6]

Returns list of fractions or list of floats.

__str__()

Gets string representation of ratio.

Ratio of two numbers:

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

Ratio of three numbers:

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

Returns string.


Methods

(NonreducedRatio).count(argument)

Gets count of argument in ratio.

Returns integer.

(NonreducedRatio).index(argument)

Gets index of argument in ratio.

Returns integer.


Read-only properties

multipliers

Gets multipliers of ratio.

Ratio of two numbers:

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

Ratio of three numbers:

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

Returns tuple of multipliers.

numbers

Gets numbers of ratio.

Ratio of two numbers:

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

Ratio of three numbers:

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

Set to tuple of two or more numbers.

Returns tuple of two or more numbers.

reciprocal

Gets reciprocal.

Gets reciprocal:

>>> abjad.Ratio((3, 2)).reciprocal
Ratio((2, 3))
>>> abjad.Ratio((3, 2, 7)).reciprocal
Ratio((7, 2, 3))

Returns new ratio.