brain
tamnd's digital brain — notes, problems, research
43815 notes
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly
The number 3797 has an interesting property.
Consider all integer combinations of a^b for 2 le a le 5 and 2 le b le 5: If they are then placed in numerical order, wi
Euler discovered the remarkable quadratic formula: n^2 + n + 41 It turns out that the formula will produce 40 primes for
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order,
A unit fraction contains 1 in the numerator.
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
Given a prime p and a positive integer n lt p, let R(p, n) be the multiplicative order of p modulo n!.
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Take the number 192 and multiply it by each of 1, 2, and 3: By concatenating each product we get the 1 to 9 pandigital,
Starting in the top left corner of a 2 times 2 grid, and only being able to move to the right and down, there are exactl
You are given the following information, but you may prefer to do some research for yourself.
2^{15} = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: | | | | | | |------------|-----|---
The following iterative sequence is defined for the set of positive integers: - n to n/2 (n is even) - n to 3n + 1 (n is
A band of pirates has come into a hoard of treasure, and must decide how to distribute it amongst themselves.
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 lette
An irrational decimal fraction is created by concatenating the positive integers: It can be seen that the 12th digit of
The first two consecutive numbers to have two distinct prime factors are: The first three consecutive numbers to have th
Given two unequal positive integers a and b, we define a self-describing sequence consisting of alternating runs of as a
A sequence (an){n ge 0} starts with a0 = 3 and for each n ge 0, - if an is a triangle numberA triangle number is a numbe
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
Given a natural number q, let p = 2^q - 1 be the q-th Mersenne number.
Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2.
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, th
We use xoplus y for the bitwise XOR of x and y.
A permutation is an ordered arrangement of objects.
Given the representation of a continued fraction alpha is a real number with continued fraction representation: alpha =
The nth term of the sequence of triangle numbers is given by, tn = frac12n(n+1); so the first ten triangle numbers are:
de Bruijn has a digital combination lock with k buttons numbered 0 to k-1 where k le 10.
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a s
Given a set E of positive integers, an element x of E is called an element divisor (elevisor) of E if x divides another
In the 20 times 20 grid below, four numbers along a diagonal line have been marked in red.
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once.
If p is the perimeter of a right angle triangle with integral length sides, a, b, c, there are exactly three solutions f
In the classical game of Nim two players take turns removing stones from piles.
In the United Kingdom the currency is made up of pound (£) and pence (p).
Left and Right play a game with a word consisting of L's and R's, alternating turns.
n! means n times (n - 1) times cdots times 3 times 2 times 1.
Two players play a game using a deck of 2n cards: n red and n black.
Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns.
The Fibonacci sequence is defined by the recurrence relation: Fn = F{n - 1} + F{n - 2}, where F1 = 1 and F2 = 1.
A positive integer is called heptaphobic if it is not divisible by seven and no number divisible by seven can be produce
The prime 41, can be written as the sum of six consecutive primes: This is the longest sum of consecutive primes that ad
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: As 1 = 1^4 is
The series, 1^1 + 2^2 + 3^3 + cdots + 10^{10} = 10405071317.
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number.
The sequence of triangle numbers is generated by adding the natural numbers.
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22
The total number of prime factors of n, counted with multiplicity, is denoted Omega(n).
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, b
The C target itself: C23 features used, compiler matrix (clang, gcc, msvc, zig cc, cosmocc, tcc), tier-1/2/3 architectures and OSes, ABI per arch, libc matrix, sanitisers, reproducibility, hardening, style guide for emitted C.
Build pipeline: `mochi build` command surface, output layout, amalgamated runtime, cross-compilation via bundled zig cc, APE via cosmocc, WASM via wasi-sdk, content-addressed caching, reproducibility.
Lowering the Mochi query DSL (LINQ-style from/where/select/join/group by/order/limit/union/intersect/except) to C with arena allocation, operator fusion, and load/save adapters.
Lowering Mochi `stream<T>`, stream definitions, `on`-handlers, agent records, and `intent` methods, plus the M:N work-stealing scheduler over minicoro fibers that runs them.
Risks (semantic, build, supply chain, performance, ergonomic), explicit alternatives considered (LLVM IR, WASM, Rust, JIT, C++, Zig), kill switches that demote the transpiler back to optional, comparable industrial precedent.
Every Mochi construct the MEP-45 codegen must lower: value core, function core, collection core, ADT core, query DSL, stream/agent core, logic, AI/FFI, tests, modules, error model, concurrency semantics.
Survey of transpilers and AOT compilers that emit C or behave like a C-target system: Nim, Crystal, Vala, OCaml, Roc, Koka, MLton, Cosmopolitan, zig cc, Cython, ATS, Soufflé. Twelve distilled lessons.
The five guiding principles behind the Mochi-to-C transpiler (spec-first, boring C, no ABI surprises, portability over performance, verifiable output), plus the runtime shape and a sample C output.
Inventory of the third-party and home-grown components the C runtime can stand on: GC (BDWGC, MMTk, Perceus), allocator (mimalloc, scudo), coroutines (minicoro), I/O (libuv, libxev), strings, hash tables, JSON/YAML/CSV, HTTP, LLM, FFI.
Codegen pipeline, why a C IR, name mangling rules, type-lowering table, value representation with `mochi_value` boxed type, expression lowering, statement lowering, for-loop lowering, try/catch via setjmp, Maranget pattern matching, modules, amalgamation.
Testing strategy: differential testing against vm3, BG corpus, fuzzing, sanitiser matrix (ASan/UBSan/TSan/MSan/LeakSan), property tests, reproducibility check, 16 phased CI gates.
Type-system lowering details: generics/monomorphisation, records, sum types with niche optimisation, closures with fat pointer, strings with SSO, lists, maps with Swiss-table, sets, time/duration, error values with built-in code table.
Gatekeeper, notarytool, SmartScreen, Authenticode, and the real cost of shipping a desktop binary.
One paragraph each, Phase 1 vs Phase 2.
One-paragraph recommendation, plus reasoning, for which naive-emission technique Mochi MEP-42 should adopt as the first cut.
Statically linked, position-independent, ASLR-friendly, and no dynamic loader required.
A conceptual essay on where Mochi MEP-42 should sit on the curve from "compile slowly, run fast" (LLVM -O3) through "compile and run at medium speed" (Cranelift, B3) to "compile instantly, run okay" (copy-and-patch, Sparkplug).
The published material a Mochi engineer should keep open while implementing MEP-42 phase 1. Cooper/Torczon 3rd ed for the canonical theory, Nystrom for a hands-on bytecode compiler walkthrough, Appel for the verified-compiler-curious, plus 2024-2026 course materials covering…
Fat Mach-O wrapping arm64 + x86_64, the lipo tool, and the end of x86_64 support.
The "honorable mentions" beyond LLVM/Cranelift/MIR/QBE.
What it takes to write a valid ELF/Mach-O/COFF from a backend's raw bytes.
Comparison table and Phase 1 / Phase 2 recommendation for Mochi's native code-generation backend.
Cross-cutting patterns from twelve production AOT pipelines, with a recommendation for which one Mochi should learn from most.
The two competing approaches to debugging Wasm, and why DWARF won inside Chrome.
The .wasm container, plus the component model binary and WAT text format.
Microsoft's native debug format, the sidecar PDB file, and the pain of producing one on Linux.
Meta's typed Python subset that can be AOT-aware, the Cinder JIT, and CPython 3.13+'s experimental copy-and-patch JIT.
The universal Unix object/executable format: Linux, *BSD, Solaris, Haiku, embedded.
Single-page roll-up of every (target ISA x OS) combination Mochi MEP-42 could ship, with status and engineering complexity recommendations.
A single binary that is simultaneously a valid ELF, Mach-O, PE, and BSD a.out.
Apple's Swift in two modes: full LLVM-driven AOT for app platforms, and a stripped Embedded Swift mode for microcontrollers and freestanding binaries.
Python-syntax systems language built on MLIR, with both AOT and JIT pipelines, on the path to 1.0 in H1 2026.
The Windows executable and object format.
The Glasgow Haskell Compiler's native code generator: hand-written, x86_64 / aarch64 / risc-v, alongside an LLVM alternative.
The most actively researched mid-tier compiler backend of the 2020s. ISLE for instruction selection, proof-carrying code for Wasm-sandbox memory accesses, and VeriISLE for verified instruction-lowering rules.
The Apple object/executable format: macOS, iOS, iPadOS, tvOS, watchOS, visionOS.
The cross-platform binary debug format, its current standard, and where the next version is going.
"How small can a useful native backend be?"
The lowest-cognitive-load path: emit C, let GCC/Clang do the rest.
Recent foundational work from POPL and its co-located CPP (Certified Programs and Proofs) workshop on verified compilation, secure calling conventions, and packet-filter codegen.
The Triton dialect (OpenAI, GPU codegen), the IREE dialect (Google, ML compiler), Mojo's MLIR-based KGEN compiler, and the broader trend of language frontends as MLIR dialects. The "if we wanted to be ambitious" backend story for Mochi.
Multi-Level IR, dialect framework, the foundation under Mojo, IREE, and OpenXLA.
"Mochi → Wasm → wasmtime compile → native": skip the backend, use the wasm ecosystem.
Direct syscalls on Linux, why this is impossible on macOS, and the APE alternative.
Recent work from the flagship PL conference on lightweight backends, baseline JIT design, superoptimization for stack bytecode, and library composition that sidesteps heavyweight compilation.
Static, GC-by-default systems language that emits C (or C++, JavaScript, LLVM) and inherits the host toolchain's optimiser.
A 14k-LOC SSA compiler backend by Quentin Carbonneaux that targets x86-64, arm64, and riscv64 from a textual SSA IR. The "70% of LLVM in 10% of the code" pitch. The natural fallback if writing our own emitter feels too risky.