Class Tally
source code
A set of "zero-agnostic" numbers which could represent the sum
of several cords in a khipu.
"Zero-agnostic" means that all zeros in the number except for the
one in the units place (if any) have been elided. The limit
argument to the constructor constrains the length of the numbers
contained in a Tally resulting from arithmetic operations, in
order to more efficiently model likely khipu sums (where the
maximum # of knots on a cord, and thus decimal places, can be
estimated).
If the fast argument is true, Tally will represent the
zero-agnostic numbers as unadorned integers, which is likely to be
faster. As a trade off, it can't carefully track the carry digit
in intermediate results, with the result that addition on Tally
objects will not be commutative, and the Tally objects may
contain some arithmetic possibilities that can't actually occur.
For example, (18+51)+52 will differ from 18+(51+52): the latter
incorrectly contains the zero-agnostic sum "31" as a possibility (since
51+52=103=13). However, I believe that fast Tallys will contain a
superset of the actual possibilities; in any case pass False
as the fast
argument for more precise results (and slower operation).
|
limit
The maximum number of digits allowed in a Tally component.
|
|
fast
If True , trade accuracy for speed.
|
Add a Tally to a Tally. Since Tallys are sets of zero-agnostic
integers, we return the cartesian product of adding all the possible
numbers in each Tally.
|
Multiply a Tally by a nonnegative integer (via addition). Note
that the 'num' multiplicand argument here is not a zero-agnostic
integer: it is a plain ol' normal everyday actual integer.
|