{{ message }}

Instantly share code, notes, and snippets.

Last active Feb 26, 2018

# Use outer products to create matrices

The outer product quick `þ` can be attached to dyads and causes the dyad to act on each pair of elements in its left and right arguments. It is shorthand for `€Ð€`. For example if we had the code `[1,2]+€Ð€[0,10]` we could shorten it to `[1,2]+þ[0,10]` and they would both yield `[[1,2],[11,12]]`. I will refer to a dyad with `þ` applied (such as `+þ`) as an outer product dyad.

When an integer is one of the arguments of an outer product dyad, Jelly takes the range of that number first then uses the result as the argument. Knowing this, the above example can be further shortened to `2+þ[0,10]`. This is true for both the left and right arguments of an outer product dyad.

Some outer product dyads when acting monadically on an integer yield certain integer matrices that can be useful in golfing (especially ASCII art challenges) but would take many bytes to otherwise construct. For example `=þ` when applied to an integer `n` yields an `n×n` identity matrix. Try `=þ` online!

Below is a table of outer product dyads and the type of matrices they yield when acting monadically on an integer. There are dyads I haven't included in the table like `&`, `|`, `%`, `w`, `ẇ` and `ḍ` that also produce integer matrices but their patterns are not as simple and they would be useful in fewer situations. Try `wþ` online!

`=`, `⁼`, `i` or `ċ` Identity matrix. `1 0 0`
`0 1 0`
`0 0 1`
`>` Elements above diagonal are `1`, all other elements are `0`. `0 1 1`
`0 0 1`
`0 0 0`
`<` Elements below diagonal are `1`, all other elements are `0`. `0 0 0`
`1 0 0`
`1 1 0`
`n` or `⁻` Diagonal elements are `0`, off diagonal elements are `1`. `0 1 1`
`1 0 1`
`1 1 0`
`a`, `ị`, `ṛ` or `ȧ` Row index of each element. `1 1 1`
`2 2 2`
`3 3 3`
`o`, `ḷ` or `ȯ` Column index of each element. `1 2 3`
`1 2 3`
`1 2 3`
`_` Main diagonal is `0`, upper diagonals are `1`, `2`..., lower diagonals are `-1`, `-2`... `0 1 2`
`-1 0 1`
`-2-1 0`
`_@` Main diagonal is `0`, upper diagonals are `-1`, `-2`, etc., lower diagonals are `1`, `2`, etc. The only dyad in this table that doesn't have a one byte alternative that results in a transposed matrix is `_`. `0 -1-2`
`1 0 -1`
`2 1 0`
`ạ` Main diagonal is `0`, upper and lower diagonals are `1`, `2`, `3`... `0 1 2`
`1 0 1`
`2 1 0`
`+` Row index plus column index. `2 3 4`
`3 4 5`
`4 5 6`
`«` Minimum of row and column indices. `1 1 1`
`1 2 2`
`1 2 3`
`»` Maximum of row and column indices. `1 2 3`
`2 2 3`
`3 3 3`