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.
42Garo 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.
`eastArithmetic uses the math signs +, -, × and ÷. Dividing two whole numbers gives a decimal.
7 ÷ 2Arrays
An array is a list of values of one type, in square brackets.
[1, 2, 3] × 10The × 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]A comparison works the same way, and gives a Bool for each element:
[3, 8, 1, 9] > 5An 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]]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]닫 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:
| Syllable | Final | Result |
|---|---|---|
| 닫 | ㄷ additive | the sum |
| 달 | ㄹ multiplicative | the product |
| 닥 | ㄱ toward greater | the largest |
| 단 | ㄴ toward lesser | the smallest |
| 담 | ㅁ cardinality | the count |
| 당 | ㅇ balanced | the mean |
당 [3, 1, 4, 1, 5]담 [3, 1, 4, 1, 5]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]랃 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]ㅅ is the order family. With the final ㄴ (lesser first) it sorts ascending, and with ㄱ (greater first) it sorts descending:
산 [3, 1, 4, 1, 5]삭 [3, 1, 4, 1, 5]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]]ㅓ runs along the first axis, down each column. 덛 gives the column sums:
덛 [[1, 2, 3], [4, 5, 6]]ㅡ treats the whole array as one flat run of values. 듣 adds up everything:
듣 [[1, 2, 3], [4, 5, 6]]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]]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]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]님 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]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]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.