mathtools.fragment

abjad.tools.mathtools.fragment(n, cell)

Fragment scalar n into cell fragments such that sum(cell) <= n.

abjad> mathtools.fragment(1, [Rational(1, 2), Rational(1, 4)])
[Rational(1, 2), Rational(1, 4), Rational(1, 4)]
abjad> mathtools.fragment(Rational(1,2), [Rational(1, 6), Rational(1, 10)])
[Rational(1, 6), Rational(1, 10), Rational(7, 30)]

Raise TypeError on nonnumeric n:

abjad> mathtools.fragment('foo', [Rational(1, 2), Rational(1, 4)])
TypeError

Raise ValueError when sum(cell) is not less than or equal to n:

abjad> mathtools.fragment(1, [Rational(3, 4), Rational(3, 4)]) 
ValueError

Todo

Generalize and rename this function.

Previous topic

mathtools.factors

Next topic

mathtools.greatest_multiple_less_equal

This Page