brain
tamnd's digital brain — notes, problems, research
42734 notes
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.
An infinite number of people (numbered 1, 2, 3, etc.) are lined up to get a room at Hilbert's newest infinite hotel.
Consider a directed graph made from an orthogonal lattice of Htimes W nodes.
Let f5(n) be the largest integer x for which 5^x divides n.
Consider a wire of length 1 unit between two posts.
A line segment of length 2n-3 is randomly split into n segments of integer length (n ge 3).
Let y0, y1, y2, dots be a sequence of random unsigned 32-bit integers (i.e.
Alice and Bob have enjoyed playing Nim every day.
A bracelet is made by connecting at least three numbered beads in a circle.
Let n be a positive integer.
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for examp
In the following equation x, y, and n are positive integers.
A sequence of rooted trees Tn is constructed such that Tn has n nodes numbered 1 to n.
Two positive numbers A and B are said to be connected (denoted by "A leftrightarrow B") if one of these conditions holds
The four right-angled triangles with sides (9,12,15), (12,16,20), (5,12,13) and (12,35,37) all have one of the shorter s
Having three black objects B and one white object W they can be grouped in 7 ways like this: | | | | | | | | |--------|-
Jack has three plates in front of him.
Let G(a, b) be the smallest non-negative integer n for which operatorname{mathbf{gcd}}Greatest common divisor(n^3 + b, (
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
A positive integer is called heptaphobic if it is not divisible by seven and no number divisible by seven can be produce
2^{15} = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
A permutation is an ordered arrangement of objects.
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, b
A unit fraction contains 1 in the numerator.
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns.
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,
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once.
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
In the United Kingdom the currency is made up of pound (£) and pence (p).
Given a prime p and a positive integer n lt p, let R(p, n) be the multiplicative order of p modulo n!.
Given the representation of a continued fraction alpha is a real number with continued fraction representation: alpha =
Euler discovered the remarkable quadratic formula: n^2 + n + 41 It turns out that the formula will produce 40 primes for
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
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number.
An irrational decimal fraction is created by concatenating the positive integers: It can be seen that the 12th digit of
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
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,
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
Given a set E of positive integers, an element x of E is called an element divisor (elevisor) of E if x divides another
A band of pirates has come into a hoard of treasure, and must decide how to distribute it amongst themselves.
Given a natural number q, let p = 2^q - 1 be the q-th Mersenne number.
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
In the 20 times 20 grid below, four numbers along a diagonal line have been marked in red.
The Fibonacci sequence is defined by the recurrence relation: Fn = F{n - 1} + F{n - 2}, where F1 = 1 and F2 = 1.
The nth term of the sequence of triangle numbers is given by, tn = frac12n(n+1); so the first ten triangle numbers are:
n! means n times (n - 1) times cdots times 3 times 2 times 1.
If p is the perimeter of a right angle triangle with integral length sides, a, b, c, there are exactly three solutions f
The sequence of triangle numbers is generated by adding the natural numbers.
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
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
You are given the following information, but you may prefer to do some research for yourself.
We use xoplus y for the bitwise XOR of x and y.
The first two consecutive numbers to have two distinct prime factors are: The first three consecutive numbers to have th
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: As 1 = 1^4 is
Left and Right play a game with a word consisting of L's and R's, alternating turns.
Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2.
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
The series, 1^1 + 2^2 + 3^3 + cdots + 10^{10} = 10405071317.
The total number of prime factors of n, counted with multiplicity, is denoted Omega(n).
The number 3797 has an interesting property.
Two players play a game using a deck of 2n cards: n red and n black.
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a s
de Bruijn has a digital combination lock with k buttons numbered 0 to k-1 where k le 10.
The prime 41, can be written as the sum of six consecutive primes: This is the longest sum of consecutive primes that ad
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
In the classical game of Nim two players take turns removing stones from piles.
Given two unequal positive integers a and b, we define a self-describing sequence consisting of alternating runs of as a
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly
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: | | | | | | |------------|-----|---
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.
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.
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.
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.
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.
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.
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.
Testing strategy: differential testing against vm3, BG corpus, fuzzing, sanitiser matrix (ASan/UBSan/TSan/MSan/LeakSan), property tests, reproducibility check, 16 phased CI gates.
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.
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.
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.
One paragraph each, Phase 1 vs Phase 2.
Gatekeeper, notarytool, SmartScreen, Authenticode, and the real cost of shipping a desktop binary.
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).
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 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…
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.
The two competing approaches to debugging Wasm, and why DWARF won inside Chrome.
Fat Mach-O wrapping arm64 + x86_64, the lipo tool, and the end of x86_64 support.
The Apple object/executable format: macOS, iOS, iPadOS, tvOS, watchOS, visionOS.
Microsoft's native debug format, the sidecar PDB file, and the pain of producing one on Linux.
The Windows executable and object format.
Python-syntax systems language built on MLIR, with both AOT and JIT pipelines, on the path to 1.0 in H1 2026.