Module Tally
[hide private]
[frames] | no frames]

Module Tally

source code

Arithmetic support for "zero-agnostic" numbers.

Example use:

# simple addition test
a = Tally(["19"])
b = Tally(["1"])
c = a + b
print c.possibilities() # set([110,20])

# simple multiplication test
a = Tally(10)
c = a * 3
print c.possibilities() # set([120, 210, 30, 1110])


Classes [hide private]
  TallyNum
A single "zero agnostic" number, as represented in khipu.
  Tally
A set of "zero-agnostic" numbers which could represent the sum of several cords in a khipu.
Functions [hide private]
 
_addFast(a, b, limit=None, cache=None)
Add two zero-agnostic values, specially treating the least-significant digit (whose position is fixed).
source code
 
_addSlow(a, b, limit=None, cache=None)
Add two TallyNum objects, specially treating the least-significant digit (whose position is fixed).
source code
 
main() source code
 
profile() source code
 
psyco() source code
Function Details [hide private]

_addFast(a, b, limit=None, cache=None)

source code 
Add two zero-agnostic values, specially treating the least-significant digit (whose position is fixed). This is 'fast' addition: carries are reduced immediately, which means addition is not commutative as the results may (conservatively) include extra values. For example, 18+(51+52) will (incorrectly) include '31' as a possibility, since 51+52=103=13.

_addSlow(a, b, limit=None, cache=None)

source code 
Add two TallyNum objects, specially treating the least-significant digit (whose position is fixed). This is 'slow' addition: carries are preserved and digits are not reduced, which guarantees commutativity but requires special care during comparison.