Values and your first syllables

This page starts from plain values and ends with operators that take a setting. You will learn:

  • how to write numbers, labels and arrays;
  • what rank and axis mean;
  • how a syllable's three parts give its meaning, by changing one part at a time;
  • how to give an operator a parameter, such as a threshold or a window size.

Type each example into the box on the home page as you go. Change it and run it again.

Values

A value on its own evaluates to itself.

42
⇒ 42Try it

Garo has whole numbers (Int), decimals (Float), true and false (Bool), and labels. A label is written with a backquote in front, like `east. Garo calls a label a symbol, or Sym. It is for category names: regions, statuses, product codes.

`east
⇒ `eastTry it

Arithmetic uses the math signs +, -, × and ÷. Dividing two whole numbers gives a decimal.

7 ÷ 2
⇒ 3.5Try it

Arrays

An array is a list of values of one type, in square brackets.

[1, 2, 3] × 10
⇒ [10, 20, 30]Try it

The × 10 applied to every element. That is the habit of an array language: an operation on an array works on all of it. Two arrays of the same length combine element by element:

[1, 2, 3] + [10, 20, 30]
⇒ [11, 22, 33]Try it

A comparison works the same way, and gives a Bool for each element:

[3, 8, 1, 9] > 5
⇒ [false, true, false, true]Try it

An array of arrays is a matrix, as long as every inner array has the same length. Garo calls each inner array a row.

[[1, 2, 3], [4, 5, 6]]
⇒ [[1, 2, 3], [4, 5, 6]]Try it

Two words come up all the time:

  • The rank of an array is how many levels of brackets it has. A single number has rank 0, a list has rank 1, and a matrix has rank 2.
  • An axis is one direction you can move through an array. A matrix has two. The first axis runs down, from row to row. The last axis runs across, along each row.

In NumPy terms, the first axis is axis=0 and the last axis is axis=-1.

Your first syllable

닫 [3, 1, 4, 1, 5]
⇒ 14Try it

닫 is the sum. Its three parts:

  • ㄷ, the family: reduce. A reduce collapses many values into one.
  • ㅏ, the flow: along the last axis. On a list, that is the whole list.
  • ㄷ, the final: additive. It finishes by adding.

A syllable is written before the data it works on, with a space between them.

Change the final

Keep the family and the flow, and swap the last letter. Each final is a direction, and the family decides what that direction means. For a reduce:

SyllableFinalResult
닫ㄷ additivethe sum
달ㄹ multiplicativethe product
닥ㄱ toward greaterthe largest
단ㄴ toward lesserthe smallest
담ㅁ cardinalitythe count
당ㅇ balancedthe mean
당 [3, 1, 4, 1, 5]
⇒ 2.8Try it
담 [3, 1, 4, 1, 5]
⇒ 5Try it

The mean of whole numbers is a decimal, so 당 gives 2.8, while the count stays a whole number.

Change the family

Now keep the flow and the final, and swap the first letter. ㄹ is the scan family. A scan is a running reduce: it keeps the result at every step instead of only the last one.

랃 [3, 1, 4, 1, 5]
⇒ [3, 4, 8, 9, 14]Try it

랃 is the running total, NumPy's np.cumsum. The finals mean the same as before, so 락 is the running maximum:

락 [3, 1, 4, 1, 5]
⇒ [3, 3, 4, 4, 5]Try it

ㅅ is the order family. With the final ㄴ (lesser first) it sorts ascending, and with ㄱ (greater first) it sorts descending:

산 [3, 1, 4, 1, 5]
⇒ [1, 1, 3, 4, 5]Try it
삭 [3, 1, 4, 1, 5]
⇒ [5, 4, 3, 1, 1]Try it

Change the flow

On a matrix the flow starts to matter. ㅏ runs along each row, so 닫 gives one sum per row:

닫 [[1, 2, 3], [4, 5, 6]]
⇒ [6, 15]Try it

ㅓ runs along the first axis, down each column. 덛 gives the column sums:

덛 [[1, 2, 3], [4, 5, 6]]
⇒ [5, 7, 9]Try it

ㅡ treats the whole array as one flat run of values. 듣 adds up everything:

듣 [[1, 2, 3], [4, 5, 6]]
⇒ 21Try it

In NumPy these are a.sum(axis=1), a.sum(axis=0) and a.sum(). The same flows work for every family. Sorting within each row is 산, and within each column is 선:

선 [[3, 9], [1, 7], [2, 8]]
⇒ [[1, 7], [2, 8], [3, 9]]Try it

The flow is the most regular part of Garo. ㅏ always means along the last axis, whatever the family.

Parameters

Some operators need a setting before they can run. 긱 is the map family (ㄱ: do something to each element), the flow ㅣ (each element on its own), and the final ㄱ (toward greater). It means "the larger of each element and p". You give p right after the syllable:

긱 0 [-2, 3, -1, 5]
⇒ [0, 3, 0, 5]Try it

That is the ReLU from neural networks: negative numbers become 0. In NumPy it is np.maximum(x, 0). A parameter is a value the operator needs. It comes after the syllable and before the data.

The same final means the same direction in other families. 닉 is the select family (ㄴ: keep some elements), and 닉 p keeps the elements greater than p:

닉 2 [1, 5, 2, 8]
⇒ [5, 8]Try it

님 keeps the first p elements, like SQL's LIMIT. Its final is ㅁ, cardinality, which is about counts. A parameter that is a plain number may be glued straight onto the syllable:

님3 [5, 6, 7, 8, 9]
⇒ [5, 6, 7]Try it

The local family, ㅎ, works on sliding windows. Its parameter is the window's width. 항 is local, along rows, balanced: a moving average.

항 3 [1, 2, 3, 4, 5, 6]
⇒ [`none, `none, 2.0, 3.0, 4.0, 5.0]Try it

The first two positions have no full window of 3 behind them, so Garo gives no value there. It prints that as `none, which means absent. The last tutorial page explains absence.

What you have learned

  • An operator is one syllable: a family, a flow and an optional final.
  • Change one part to get a neighboring operator.
  • Some operators take a parameter, written after the syllable.

Next, words and the pipe puts several operators together.