This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Arrays

Literals, zeros, indexing, elementwise arithmetic, and passing arrays through functions. Run a cell to see its output beside the expected one.

Elementwise math on an array

Every 1-argument math builtin maps elementwise over an array. No loop.

Viv [1]

Broadcasting an array and a scalar

+, -, *, / broadcast between arrays and scalars, in either order.

Viv [2]

Resetting an array in place with fill

fill(a, v) sets every element. Rebinding (a = zeros(n)) makes a new array, and a caller that passed a in never sees the change; fill changes the array in place.

Viv [3]

Literals and indexing

Comma-separated subscripts, zero-based.

Viv [4]

zeros and indexed stores

zeros allocates rank 1 through 4.

Viv [5]

Elementwise arithmetic

* between arrays is elementwise (the Hadamard product); array times scalar scales.

Viv [6]

len and linspace

len reads the leading dimension.

Viv [7]

Functions take and return arrays

head_tail takes an array and returns a new one.

Viv [8]

Scalars broadcast

A scalar combines elementwise with an array from either side, for every arithmetic operator.

Viv [9]

Matrices combine elementwise too

Viv [10]

Rank 3 and 4 exist

Allocate with zeros; index with one subscript per axis. show prints the flat data for rank 3+.

Viv [11]

linspace endpoints are inclusive

Both endpoints are in the array, as in NumPy. With n = 1 it is the start alone, and with n = 0 it is empty.

Viv [12]

dot is the loop you would write

dot(a, b) is a builtin. The def below is the loop it runs, left to right, and gives the same sum.

Viv [13]

Negative indices count from the end

As in Python: a[-1] is the last element, a[:-1] all but it, A[-1, :] the last row.

Viv [14]

A comprehension builds an array

Its for takes any loop head, and its if keeps the elements it holds for.

Viv [15]

in, and a key for max and sorted

x in a is NumPy's: some element equals x. A key is a def, a builtin or fn(x) -> ....

Viv [16]

norm is the square root of dot

norm(v) is a builtin too, the square root of dot(v, v).

Viv [17]