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

Complex numbers

A complex number type: the `i` suffix on a number makes it imaginary, arithmetic mixes complex and real values, and every engine (the interpreter, C and wasm) computes the complex functions with the same formulas, so they print the same digits. Run a cell to see its output beside the expected one.

Imaginary literals and arithmetic

2.5i is an imaginary literal (a bare identifier i is still a variable — only digits take the suffix). +, -, *, / work between complex and real values; reals promote.

Viv [1]

re, im, conj, abs

abs of a complex number is its modulus; z times its conjugate is exactly |z| squared.

Viv [2]

Euler's identity, computed

exp, log, sqrt, sin, cos, tan all work on complex arguments. e^{i pi} comes out as -1 with an imaginary part of 1.2e-16, which is sin of the double nearest pi. sqrt takes the half-angle formulas, so the square root of -1 is exactly i.

Viv [3]

A rotation is a complex multiply

Multiplying by e^{i theta} rotates the plane by theta. A function that takes and returns complex values needs no annotations; the compiler infers the types.

Viv [4]