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

Compare

Python and Viv, side by side

39 small programs, each written twice, once in Python and once in Viv. The two versions use the same algorithm, print the same output, and are cut into the same regions, so a page can show them line against line. The notes on each page list the differences in syntax to look for.

A script, study/compare/check.sh, runs every pair: the Python with CPython and NumPy, the Viv in the interpreter, compiled to C and compiled to wasm. It fails unless the outputs match. Where a pair's output differs, its notes name the lines and why, and the rest of the output must still match. Each page also shows what py2viv, the translator from numeric Python, makes of the Python, or its reason for refusing it.

Basics

Printing and formatting, variables and arithmetic, conditionals, loops, functions.

  1. Printing and formatting same output
  2. Arithmetic and conditionals output differs
  3. Loops same output
  4. Functions same output

Strings

Split, join, format, and text processed character by character.

  1. String basics same output
  2. Word count same output
  3. Palindromes same output
  4. Caesar cipher same output
  5. Numbers from text same output

Lists and growable arrays

Building a list as you go, filtering, sorting, slicing.

  1. Growing a list same output
  2. Sorting same output
  3. Slices, copies and aliases output differs

Dicts and maps

Counting with string keys and number keys.

  1. Word frequency same output
  2. Counting with number keys same output

Records, classes and tuples

Dataclasses against records; several results and unpacking.

  1. Records and dataclasses same output
  2. Tuples and unpacking same output
  3. A class with state same output

Recursion

Factorial, memoized Fibonacci, the Tower of Hanoi, merge sort, quicksort.

  1. Factorial same output
  2. Fibonacci with a memo same output
  3. Tower of Hanoi same output
  4. Merge sort same output
  5. Quicksort in place same output

Files

Writing text and reading it back line by line.

  1. Reading and writing text files same output

Numerics

Root finding, quadrature, ODEs, iterative and direct linear algebra: NumPy against Viv's arrays.

  1. Newton's method same output
  2. Bisection same output
  3. Simpson's rule same output
  4. Runge-Kutta 4 on an oscillator same output
  5. Euler against the exact solution same output
  6. Jacobi iteration same output
  7. Power iteration same output
  8. LU factorization and solve same output
  9. Matrix operations same output

Random numbers

A seeded generator whose draws match NumPy's.

  1. Seeded random numbers same output

Gradients

A gradient derived by hand in Python against Viv's grad.

  1. Gradients by hand and by grad same output

Plotting

Matplotlib against Viv's figure records.

  1. A line plot output differs

A small GPT

A transformer trained with a hand-written backward pass: NumPy classes, then PyTorch, against lib/gpt.

  1. A small GPT in NumPy and in Viv same output
  2. The same GPT in PyTorch, against Viv same output

Errors

Exceptions against checked results and stop.

  1. Exceptions against checked results same output

Tests

Test functions and asserts against Viv's test blocks.

  1. Tests same output

The differences to learn first

Where the outputs differ