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

Stencils and PDE steps

A finite-difference stencil is arithmetic on shifted copies of an array, and an implicit time step is a tridiagonal solve. These are the pieces the PDE solvers are built from. Run a cell to see its output beside the expected one.

A periodic second difference

roll(u, k) moves element i to i + k, wrapping around, so roll(u, 1)[i] is u[i - 1]. The second difference of i squared is exactly 2; the two ends show the wrap.

Viv [1]

roll along one axis of a grid

A third argument picks the axis: 0 shifts rows, 1 shifts along each row. A five-point Laplacian is four of these.

Viv [2]

A tridiagonal solve

tridiag_solve(sub, diag, super, rhs) is the Thomas algorithm, O(n). Here the matrix is the 1-D Laplacian (-1, 2, -1), and the right-hand side is chosen so the answer is all ones. sub[0] and super[n-1] are never read.

Viv [3]

One implicit heat step

Backward Euler for u_t = u_xx with dt / h^2 = 1: solve (I - r D2) u_new = u_old. The spike spreads symmetrically, and no time step is too large for it.

Viv [4]

The max-norm error

max and min of ONE array reduce it to its largest or smallest entry. With two arguments they stay elementwise.

Viv [5]

An array to a power

pow(a, s) raises every entry to the same scalar power.

Viv [6]

Negating an array

Unary minus works on arrays, real or complex.

Viv [7]