Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > strings and nets > horizontalJoin
next | previous | forward | backward | up | index | toc

horizontalJoin -- join nets or strings horizontally

Synopsis

Description

If the list L contains only strings, then horizontalJoin acts like the command concatenate.

i1 : L = {"some", "strings", "to", "join"}

o1 = {some, strings, to, join}

o1 : List
i2 : horizontalJoin L

o2 = somestringstojoin
i3 : concatenate L

o3 = somestringstojoin
i4 : demark(" ", L) --to insert spaces when concatenating strings

o4 = some strings to join

Unlike concatenate, horizontalJoin can also be used on Nets.

i5 : M = for i from 1 to 10 list if isPrime i then netList{toString i, toString i^2}

        +-+  +-+    +--+    +--+
o5 = {, |2|, |3|, , |5 |, , |7 |, , , }
        +-+  +-+    +--+    +--+
        |4|  |9|    |25|    |49|
        +-+  +-+    +--+    +--+

o5 : List
i6 : horizontalJoin M

     +-++-++--++--+
o6 = |2||3||5 ||7 |
     +-++-++--++--+
     |4||9||25||49|
     +-++-++--++--+

As the previous example shows, null arguments are allowed and ignored.

Nets and strings can be mixed in the input list. In this case, a string is interpreted as a net of height one, with baseline below the string. The operator Net ^ ZZ can be used to lower or raise the baseline of a string or net.

i7 : R = QQ[x];
i8 : N1 = for i from 1 to 5 list if isPrime i then netList{x^i, i*x, i:x, i} else toString i

         +------+  +---------+     +---------------+
         | 2    |  | 3       |     | 5             |
o8 = {1, |x     |, |x        |, 4, |x              |}
         +------+  +---------+     +---------------+
         |2x    |  |3x       |     |5x             |
         +------+  +---------+     +---------------+
         |(x, x)|  |(x, x, x)|     |(x, x, x, x, x)|
         +------+  +---------+     +---------------+
         |2     |  |3        |     |5              |
         +------+  +---------+     +---------------+

o8 : List
i9 : horizontalJoin N1

      +------++---------+ +---------------+
      | 2    || 3       | | 5             |
o9 = 1|x     ||x        |4|x              |
      +------++---------+ +---------------+
      |2x    ||3x       | |5x             |
      +------++---------+ +---------------+
      |(x, x)||(x, x, x)| |(x, x, x, x, x)|
      +------++---------+ +---------------+
      |2     ||3        | |5              |
      +------++---------+ +---------------+
i10 : N2 = for i from 1 to 5 list if isPrime i then netList{x^i, i*x, i:x, i} else (toString i)^-6

          +------+  +---------+     +---------------+
          | 2    |  | 3       |     | 5             |
o10 = { , |x     |, |x        |,  , |x              |}
          +------+  +---------+     +---------------+
          |2x    |  |3x       |     |5x             |
          +------+  +---------+     +---------------+
          |(x, x)|  |(x, x, x)|     |(x, x, x, x, x)|
          +------+  +---------+     +---------------+
       1  |2     |  |3        |  4  |5              |
          +------+  +---------+     +---------------+

o10 : List
i11 : horizontalJoin N2

       +------++---------+ +---------------+
       | 2    || 3       | | 5             |
o11 =  |x     ||x        | |x              |
       +------++---------+ +---------------+
       |2x    ||3x       | |5x             |
       +------++---------+ +---------------+
       |(x, x)||(x, x, x)| |(x, x, x, x, x)|
       +------++---------+ +---------------+
      1|2     ||3        |4|5              |
       +------++---------+ +---------------+

In the next example, we use horizontalJoin to concatenate the display of two random integer matrices. The matrices are converted to nets first with the command net.

i12 : A = net matrix apply(3, i -> apply(3, j -> random(10)))

o12 = | 8 1 3 |
      | 7 8 3 |
      | 3 7 8 |
i13 : B = net matrix apply(3, i -> apply(3, j -> random(10)))

o13 = | 8 5 7 |
      | 8 5 2 |
      | 3 6 3 |
i14 : horizontalJoin(A,B)

o14 = | 8 1 3 || 8 5 7 |
      | 7 8 3 || 8 5 2 |
      | 3 7 8 || 3 6 3 |

Nested sequences in the input are automatically spliced. For instance, in the next example the input is interpreted as \{A, B, A, B, A\}.

i15 : horizontalJoin {(A, B), (A, B, (A))}

o15 = | 8 1 3 || 8 5 7 || 8 1 3 || 8 5 7 || 8 1 3 |
      | 7 8 3 || 8 5 2 || 7 8 3 || 8 5 2 || 7 8 3 |
      | 3 7 8 || 3 6 3 || 3 7 8 || 3 6 3 || 3 7 8 |

However, the command horizontalJoin \{\{A, B\}, \{A, B, \{A\}\}\} will throw an error, because nested lists are not automatically flattened.

Caveat

This command will work with no arguments, or all null arguments. The net returned has zero height and zero depth, which might be unexpected.

See also

Ways to use horizontalJoin :

For the programmer

The object horizontalJoin is a compiled function.