Examples

hello.mul

The hello program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.

Source

examples/compare/hello.mul is stored in the compact layout, as AI agents write it: a space only between two words, no other whitespace. The page lays it out for reading; the Compact button shows the stored text, and Copy always copies it.

module compare.hello pub fn main()->i32 io{print("Hello, world!")return 0}

Verified IR

What mul ir prints after the verifier has accepted the program.

module compare.hello

fn @main() -> i32 io {
b0:
  %0 = const.string "Hello, world!"
  print %0
  %1 = const.i32 0
  return %1
}

Run

Output and exit code of the program in MUL (interpreter and Cranelift), Go, PHP, C and Rust, from examples/compare/evidence/hello/run.txt. The value main returns is the exit code.

$ mul run examples/compare/hello.mul
Hello, world!
exit code 0

$ mul run --backend cranelift examples/compare/hello.mul
Hello, world!
exit code 0

$ go build -o hello examples/compare/hello.go && ./hello
Hello, world!
exit code 0

$ php examples/compare/hello.php
Hello, world!
exit code 0

$ cc -o hello examples/compare/hello.c && ./hello
Hello, world!
exit code 0

$ rustc --edition 2021 -O -o hello examples/compare/hello.rs && ./hello
Hello, world!
exit code 0

Tokens

Token count of each file, MUL as the base: first the offline estimate of mul tokens, then the same files counted with the real BPE vocabularies (--tokenizer-cmd). The estimate applies fixed rules fitted to the pilot study (design document, chapter 23) instead of a learned vocabulary of merges, so it is a few percent off on each file; quote the BPE numbers.

$ mul tokens examples/compare/hello.mul --compare examples/compare/hello.go examples/compare/hello.php examples/compare/hello.c examples/compare/hello.rs
tokenizer: estimate
note: offline estimate, not a real tokenizer (about 5% per file on GPT-style BPE); use --tokenizer-cmd for exact counts
file                        layout        tokens      diff         %
examples/compare/hello.mul  compact           22      base
examples/compare/hello.go   as written        22        +0     +0.0%
examples/compare/hello.php  as written        15        -7    -31.8%
examples/compare/hello.c    as written        25        +3    +13.6%
examples/compare/hello.rs   as written        14        -8    -36.4%
$ mul tokens examples/compare/hello.mul --compare examples/compare/hello.go examples/compare/hello.php examples/compare/hello.c examples/compare/hello.rs --tokenizer-cmd "python3 research/token-sample/count.py cl100k_base"
tokenizer: cl100k_base
file                        layout        tokens      diff         %
examples/compare/hello.mul  compact           22      base
examples/compare/hello.go   as written        19        -3    -13.6%
examples/compare/hello.php  as written        15        -7    -31.8%
examples/compare/hello.c    as written        23        +1     +4.5%
examples/compare/hello.rs   as written        12       -10    -45.5%
$ mul tokens examples/compare/hello.mul --compare examples/compare/hello.go examples/compare/hello.php examples/compare/hello.c examples/compare/hello.rs --tokenizer-cmd "python3 research/token-sample/count.py o200k_base"
tokenizer: o200k_base
file                        layout        tokens      diff         %
examples/compare/hello.mul  compact           22      base
examples/compare/hello.go   as written        19        -3    -13.6%
examples/compare/hello.php  as written        15        -7    -31.8%
examples/compare/hello.c    as written        23        +1     +4.5%
examples/compare/hello.rs   as written        12       -10    -45.5%

The same program in other languages

make compare checks that each of them prints the same output and exits with the same code.

Go

examples/compare/hello.go

package main

import "fmt"

func main() {
	fmt.Println("Hello, world!")
}

PHP

examples/compare/hello.php

<?php

echo "Hello, world!\n";
exit(0);

C

examples/compare/hello.c

#include <stdio.h>

int main(void) {
    puts("Hello, world!");
    return 0;
}

Rust

examples/compare/hello.rs

fn main() {
    println!("Hello, world!");
}