Package sympycore :: Package arithmetic
[hide private]
[frames] | no frames]

Package arithmetic

source code

Low-level arithmetics support.

Arithmetic package provides:



Submodules [hide private]

Classes [hide private]
  Complex
Represents complex number.
  Float
Represents floating-point numbers.
  FractionTuple
Represents a fraction.
  Infinity
Base class for directional infinities.
Functions [hide private]
 
gcd(*args)
Calculate the greatest common divisor (GCD) of the arguments.
source code
call graph 
 
lcm(*args)
Calculate the least common multiple (LCM) of the arguments.
source code
call graph 
 
multinomial_coefficients(m, n, _tuple=<type 'tuple'>, _zip=<built-in function zip>)
Return a dictionary containing pairs {(k1,k2,..,km) : C_kn} where C_kn are multinomial coefficients such that n=k1+k2+..+km.
source code
call graph 
Function Details [hide private]

multinomial_coefficients(m, n, _tuple=<type 'tuple'>, _zip=<built-in function zip>)

source code 
call graph 

Return a dictionary containing pairs {(k1,k2,..,km) : C_kn} where C_kn are multinomial coefficients such that n=k1+k2+..+km.

For example:

>>> print multinomial_coefficients(2,5)
{(3, 2): 10, (1, 4): 5, (2, 3): 10, (5, 0): 1, (0, 5): 1, (4, 1): 5}

The algorithm is based on the following result:

Consider a polynomial and it's m-th exponent:

P(x) = sum_{i=0}^m p_i x^k
P(x)^n = sum_{k=0}^{m n} a(n,k) x^k

The coefficients a(n,k) can be computed using the J.C.P. Miller Pure Recurrence [see D.E.Knuth, Seminumerical Algorithms, The art of Computer Programming v.2, Addison Wesley, Reading, 1981;]:

a(n,k) = 1/(k p_0) sum_{i=1}^m p_i ((n+1)i-k) a(n,k-i),

where a(n,0) = p_0^n.