Macaulay2 » Documentation
Packages » Macaulay2Doc :: mingle
next | previous | forward | backward | up | index | toc

mingle -- mingle elements of several lists

Synopsis

Description

The output list M takes the first element of each Li, i=1,...,n, followed by the second element of Li, i=1,...,n, and so forth.

i1 : mingle {{a1, a2, a3}, {b1, b2, b3}, {c1, c2, c3}}

o1 = {a1, b1, c1, a2, b2, c2, a3, b3, c3}

o1 : List

The lists can have different lengths. After a list is exhausted, it will be silently ignored.

i2 : mingle {{a1, a2, a3, a4}, {b1, b2}, {c1}}

o2 = {a1, b1, c1, a2, b2, a3, a4}

o2 : List

To transpose a nested list (thinking of it as a matrix), try using mingle with pack.

i3 : pack(3, mingle ((a1, a2, a3), (b1, b2, b3), (c1, c2, c3)))

o3 = {{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}}

o3 : List

Notice from the previous example that mingle accepts sequences and other types of BasicLists as input, but the output will always be a List.

Further examples:

i4 : concatenate mingle( {"a","b","c"} , {",",","} )

o4 = a,b,c
i5 : netList pack(3, mingle( (0..5), apply(6, i -> i^2), apply(6, i -> i^3)))

     +-+--+---+
o5 = |0|0 |0  |
     +-+--+---+
     |1|1 |1  |
     +-+--+---+
     |2|4 |8  |
     +-+--+---+
     |3|9 |27 |
     +-+--+---+
     |4|16|64 |
     +-+--+---+
     |5|25|125|
     +-+--+---+

See also

Ways to use mingle :

For the programmer

The object mingle is a compiled function.