Learn R Programming

kStatistics (version 2.0)

mkT: Scomposition of a vector of non-negative integers

Description

Given a vector v of non-negative integers, the routine finds all the lists (v1, ..., vn) of non-negative integer vectors, with the same lenght of v and such that v=v1+...+vn.

Usage

mkT(v = c(), n = 0)

Arguments

v

vector of integers

n

integer, number of addends

Value

list

the list of n vectors (v1, ..., vn)

Warning

The vector of the first parameter must be not empty and must contain all non-negative values. The second parameter must be a positive integer.

Details

From an input vector v of non-negative integers, the routine generates all the lists of n vectors (v1, ..., vn) of non-negative integers, including the zero vector, having the same lenght of v and such that their sum gives v. Note that two lists are different if they contain the same vectors but permutated.

References

Di Nardo E., Guarino G., Senato D. (2011) A new algorithm for computing the multivariate Faa di Bruno's formula. Appl. Math. Comp. 217, 6286--6295. (download from http://arxiv.org/abs/1012.6008)

See Also

mkmSet, MFB

Examples

Run this code
# NOT RUN {
# Return the scompositions of the vector (1,1) in 2 vectors of 2 non-negative integers such that 
# their sum is (1,1), that is
# ([1,1],[0,0]) - ([0,0],[1,1]) - ([1,0],[0,1]) - ([0,1],[1,0])
mkT(c(1,1),2)

# Return the scompositions of the vector (1,0,1) in 2 vectors of 3 non-negative integers such that 
# their sum gives (1,0,1), that is
# ([1,0,1],[0,0,0]) - ([0,0,0],[1,0,1]) - ([1,0,0],[0,0,1]) - ([0,0,1],[1,0,0]).
# Note that the second value in each resulting vector is always zero.
mkT(c(1,0,1),2)

# Return the scompositions of the vector (1,1,1) in 3 vectors of 3 non-negative integers such that 
# their sum gives (1,1,1). The result is in a compact form expression.
for (m in mkT(c(1,1,1),3)) {for (n in m) cat(n," - "); cat("\n"); }

# }

Run the code above in your browser using DataLab