# Vocabulary/semidot1

>>
<< ` `
Down to: Dyad ` `
Back to: Vocabulary
Thru to: Dictionary

`u;.1 y``u;._1 y``u;.2 y``u;._2 y`SelfIntervals Adverb

Rank Infinity *-- operates on x and y as a whole --*
WHY IS THIS IMPORTANT?

A family of related adverbs, differing only in small details.

We will consider ` u;.1 y ` and ` u;.2 y ` separately.

See this note for the meanings of related phrases ` u;._1 y ` and ` u;._2 y `

**Definition:**
In what follows, an **interval of items** is a sequence of consecutive items of a noun.

**Case: u;.1 y**

This partitions `y` into a sequence of intervals and then applies `u` individually on each interval.
The result of ` u;.1 y ` is the array of results from individual applications of `u`.

An item marking the boundary of an interval is called a ** fret**.
Each interval runs from one fret to the next (or, for the last fret, to the end of the array).

In ` u;.1 y ` the frets are those items of `y` that match the first item of `y`.
In other words, the first item of `y` is used as a delimiter,
and `y` is split into intervals by starting a new interval at every item of `y` that matches the delimiter.

Since the first item of `y` starts the first interval, every item of `y` will be in exactly one interval.

`u` can be any verb.

The following examples use `<`, which boxes each interval, and `+/`, which adds up the numbers in each interval.

<;.1 'a man, a plan, a canal: panama' +---+----+----+----+---+--+-----+--+--+-+ |a m|an, |a pl|an, |a c|an|al: p|an|am|a| +---+----+----+----+---+--+-----+--+--+-+

The first item is (`a`), so every (`a`) starts a new interval.

<;.1 ] 3 1 4 1 5 9 2 6 5 3 5 3 2 3 8 +-----------------+---+---+---+ |3 1 4 1 5 9 2 6 5|3 5|3 2|3 8| +-----------------+---+---+---+

Numbers work too, just as well as bytes.

+/;.1 (3 1 4 1 5 9 2 6 5 3 5 3 2 3 8) NB. () needed to split numeric list 36 8 5 11

Instead of boxing the intervals using `<`, we totaled the numbers.

]a =. _2 ]\ 1 1 1 0 0 1 1 1 2 0 1 1 1 1 2 3 NB. An 8x2 table 1 1 1 0 0 1 1 1 2 0 1 1 1 1 2 3 <;.1 a +---+---+---+---+ |1 1|1 1|1 1|1 1| |1 0|2 0| |2 3| |0 1| | | | +---+---+---+---+

The items of a table are lists (i. e. rows).
A new interval starts with each occurrence of a match with the first item, `1 1`.

**Case u;.2 y**

This is like ` u;.1 y`, except that the frets are those items that match the **last** item of `y`,
and they are used to mark the **end** of an interval:

<;.2 'a man, a plan, a canal: panama' +-+---+----+----+----+---+--+-----+--+--+ |a| ma|n, a| pla|n, a| ca|na|l: pa|na|ma| +-+---+----+----+----+---+--+-----+--+--+ <;.2 (3 1 4 1 5 9 2 6 5 3 5 3 2 3 8) NB. Only one 8, so all one interval +-----------------------------+ |3 1 4 1 5 9 2 6 5 3 5 3 2 3 8| +-----------------------------+

**Note:**
`u;._1 ` and ` u;._2 ` are like ` u;.1 ` and ` u;.2 ` respectively, except that the frets are removed from the intervals before `u` is applied:

<;._1 'a man, a plan, a canal: panama' +--+---+---+---+--+-+----+-+-++ | m|n, | pl|n, | c|n|l: p|n|m|| +--+---+---+---+--+-+----+-+-++ <;._2 'a man, a plan, a canal: panama' ++--+---+---+---+--+-+----+-+-+ || m|n, | pl|n, | c|n|l: p|n|m| ++--+---+---+---+--+-+----+-+-+

Note that when `n` is negative, `u` may be applied to an empty array, if the interval contained only one item.

**Summary of the meaning of**`n`in`u;.n y`**n****Meaning**1 or _1 **First**item is delimiter, interval**starts**with fret2 or _2 **Last**item is delimiter, interval**ends**with fretpositive Fret is **included**in intervalnegative Fret is **deleted**from interval

### Common uses

1. To *cut* a string `y` into a list of boxed substrings at some chosen delimiter, e.g. Space (`' '`)

y=: 'alpha bravo charlie' (<;._1) ' ',y +-----+-----+-------+ |alpha|bravo|charlie| +-----+-----+-------+

Note that we had to add a space at the beginning to make sure we started with the right delimiter,
and that we used the `;._1` form to remove the space from the resulting word.

Compare this with the action of Words (`;:`)
which uses J's rules for recognizing words: much different from looking for spaces:

y=: 'Fine, easy as 1 2 3?' ;: y +----+-+----+--+-----+-+ |Fine|,|easy|as|1 2 3|?| +----+-+----+--+-----+-+ (<;._1) ' ',y +-----+----+--+-+-+--+ |Fine,|easy|as|1|2|3?| +-----+----+--+-+-+--+

But for string contents known to contain no punctuation or number sequences, you might find (`;:`) handier to use.

2. `u;._2` is often used to split a text file into lines, where each line is ended by a linefeed (`LF`)

a =. 1!:1 <'C:\J\bin\profilex.ijs' NB. Read in a text file $a 886 a NB. Display it. It's a list of lines separated by LF NB. profilex.ijs template NB. copy template to profilex and edit as required ... <;._2 a,LF NB. Use LF as delimiter, and split to lines +--------------------------+---------------------------------------- |NB. profilex.ijs template |NB. copy template to profilex and edit... +--------------------------+----------------------------------------

3. The result of ` 0 : 0 ` is like a text file: a list of characters, with lines separated by `LF`.

n =: 0 : 0 NB. Define a multiline noun Line 1 Line 2 ) $n NB. It's a list... 14 <;._2 n NB. ...with LF at the end of each line +------+------+ |Line 1|Line 2| +------+------+

When you need to define a large data array, consider using `0 : 0` to write the lines, and then `u;._2` to process each line.
Common choices of `u` are `<` to create a list of lines, or `".` to execute each line, or `<@;:` to convert each line to a boxed list of words.

]listofnames =: <;._2 (0 : 0) NB. Names read from a file; box each line Alicia Alex Jo Fran ) +------+----+--+----+ |Alicia|Alex|Jo|Fran| +------+----+--+----+ ]name_zip =: ".;._2 (0 : 0) NB. name and zipcode; execute each line 'John Bull' ; 'W1' 'John Q. Public' ; 27607 'Tanaka-san' ; 6038134 ) +--------------+-------+ |John Bull |W1 | +--------------+-------+ |John Q. Public|27607 | +--------------+-------+ |Tanaka-san |6038134| +--------------+-------+ ]colors =: <@;:;._2 (0 : 0) NB. box each list of words red burgundy maroon vermilion green emerald jade blue teal cerulean ) +-------------------------------+--------------------+--------------------+ |+---+--------+------+---------+|+-----+-------+----+|+----+----+--------+| ||red|burgundy|maroon|vermilion|||green|emerald|jade|||blue|teal|cerulean|| |+---+--------+------+---------+|+-----+-------+----+|+----+----+--------+| +-------------------------------+--------------------+--------------------+

### Details

1. Each interval has the same rank as `y`.

2. If `u` is applied to an empty argument
(because the interval contained only the fret, which was deleted before applying `u`), then `u` is applied to `0 $ y`.
This is analogous to execution on a fill-cell.

`0 $ y` is an array with 0 items (each of which has the rank of an item of `y`).

3. `u` may be a cyclic gerund.

### Use These Combinations

Combinations using `;.1-2 y` that have exceptionally good performance are shown in Intervals.

`x u;.1 y``x u;._1 y``x u;.2 y``x u;._2 y`Intervals Adverb

Rank 1 _ *-- operates on lists of x and the entirety of y, with replication of atomic x --*
WHY IS THIS IMPORTANT?

A family of related adverbs, differing only in small details.

Before reading aboutx u;.n ymake sure you understand the operation of u;.n y

We will consider ` x u;.1 y ` and ` x u;.2 y ` separately.

See this note for the meanings of related phrases ` x u;._1 y ` and ` x u;._2 y `

**Definition:**
In what follows, an **interval of items** is a sequence of consecutive items of a noun.

**Case: x u;.1 y**

This partitions `y` into a sequence of intervals and then applies `u` individually on each interval.
The frets of `y`, that is the starting points of intervals, are the items of `y`
corresponding to `1`s in the Boolean list `x`.

The result of ` x u;.1 y ` is the array of results from individual applications of `u`

1 0 1 0 0 <;.1 'abcde' +--+---+ |ab|cde| +--+---+

Items of `y` before the first fret are not part of any interval and are not used:

0 1 0 0 1 <;.1 'abcde' +---+-+ |bcd|e| +---+-+

**Case: x u;.2 y**

This is like ` x u;.1 y `, except that the intervals **end** at frets

1 0 1 0 0 <;.2 'abcde' +-+--+ |a|bc| +-+--+ 0 1 0 0 1 <;.2 'abcde' +--+---+ |ab|cde| +--+---+

**Note:**
` u;._1 ` and ` u;._2 ` are like ` u;.1 ` and ` u;.2 ` respectively,
except that the frets are removed from the intervals before `u` is applied

1 0 1 0 0 <;._1 'abcde' +-+--+ |b|de| +-+--+ 1 0 1 0 0 <;._2 'abcde' ++-+ ||b| ++-+

**Summary of the meaning of**`n`in`x u;.n y`**n****Meaning**1 or _1 Interval **starts**with fret2 or _2 Interval **ends**with fretpositive Fret is **included**in intervalnegative Fret is **deleted**from interval

#### Multidimensional Intervals Using Boxed x

If `x` is a list of boxes, the operation is generalized from intervals of items to subarrays.
Each box of `x` contains the frets for a single axis starting with the first.

Each axis is partitioned using its frets according to the rules of `u;.n`.
`u` is applied to each subarray, and the results are collected

]a =. 4 4 $ 'abcdefghijklmnop' abcd efgh ijkl mnop (1 0 0 1;0 1 0 1) <;.1 a +--+-+ |bc|d| |fg|h| |jk|l| +--+-+ |no|p| +--+-+

An axis corresponding to an empty box in `x`, or an axis beyond the length of `x`,
is taken in full and does not produce an axis of the partitioning.

**Exception: **If the axis of `y` corresponding to the empty box has length 0, the 0-length axis remains in the partitioning.

]a =. (1 0 0;1 0 1) <;.1 i. 3 3 +---+-+ |0 1|2| |3 4|5| |6 7|8| +---+-+ $a 1 2 ]b =. ('';1 0 1) <;.1 i. 3 3 +---+-+ |0 1|2| |3 4|5| |6 7|8| +---+-+ $b 2

The partitioning to create `b` does not have an axis corresponding to the empty box.

### Common Uses

1. `x u;.n y` is a workhorse for acting on intervals of a noun.
To cut text into English sentences (ending with "." and two spaces)

'. ' E. text NB. Find ends-of-sentence 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 ('. ' E. text) <;.2 text +----------------+-------------------+------------+ |I saw Mr. Jones.| Mr. Jones saw me.| We waited.| +----------------+-------------------+------------+

2. To add up intervals of ascending numbers in a list

list =. 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 NB. a list ]ascendingstarts =. 1 , 2 >/\ list NB. places where the list starts an ascending sequence 1 1 0 1 0 0 1 0 1 1 0 0 0 1 0 ascendingstarts <;.1 list NB. The ascending sequences +-+---+-----+---+-+-------+---+ |3|1 4|1 5 9|2 6|5|3 5 8 9|7 9| +-+---+-----+---+-+-------+---+ ascendingstarts +/;.1 list NB. Totals of the ascending sequences 3 5 15 8 5 25 16

3. To split a matrix into block matrix form

(1 0 0 1;1 0 1 0 0) <;.1 i.4 5 +-----+--------+ | 0 1| 2 3 4| | 5 6| 7 8 9| |10 11|12 13 14| +-----+--------+ |15 16|17 18 19| +-----+--------+

### Details

1. Each interval has the same rank as `y`.

2. If `u` is applied to an empty argument (because the interval contained only the fret,
which was deleted before applying `u`), `u` is applied to `0 $ y`.
This is analogous to execution on a fill-cell.

Phrase ` 0 $ y ` is an array with 0 items (each of which has the rank of an item of `y`).

3. If `y` has no intervals (because `x` is all zero), the result is ` 0 $ ,: u 0 $ y` .
This is analogous to execution on a fill-cell.

Phrase ` 0 $ y` is an array with 0 items (each of which has the rank of an item of `y`),
and the final ` 0 $ ,: ` prepends a leading axis of 0 length.

4. `u` may be a cyclic gerund.

5. If `x` is a scalar, it is replicated and used for each item of `y`.

### Oddities

1. If `x` is empty and `y` has items, the result is ` u y` .

2. If `x` is empty and `y` has no items, the result is `0 $ ,: u y` .

3. If `x` is boxed, the same principle applies:
an empty box in `x` means that the corresponding axis is taken in full
and does not produce an axis in the result., except when the axis has length 0.

### Use These Combinations

Combinations using `x ;.1-2 y` that have exceptionally good performance are shown in Intervals.