WikiLean

Wikifunctions formalization

Giving Wikifunctions' executable functions the formal specification they lack — borrowed from Mathlib.

How these are verified — the deployed code, proved equal to its Mathlib spec.

WikiLean joins each Wikidata mathematics concept to two things: an Mathlib formalization, and a Wikifunctions executable function (via the wikifunctionswiki sitelink on the shared Wikidata item). The Wikidata QID is the join key. So for a function Wikifunctions can run but cannot prove anything about, the matching Mathlib declaration becomes the formal spec it was missing.

Of the 1,904 Wikifunctions currently linked to Wikidata, 25 fall in WikiLean's addressable set. For each we pin a computable oracle (the Mathlib decl or composed expression that produces the ground-truth value), grade whether that oracle is actually faithful to what the Wikifunction computes, and write a Lean spec stating its defining properties.

1,904WF ↔ Wikidata
25addressable
14/25faithful
15composite-provable
9oracle-testable
1spec-only
The Lean spec corpus (all 25 blocks) builds green against Mathlib — zero sorry, no axiom cheats. Every verdict is independently confirmed.

The 25 addressable functions

Grouped by verification tier. Each row links the Wikifunctions function (ZID), its Wikidata item (QID), and the Mathlib oracle pinned as ground truth. Hover a faithfulness chip for the reviewer's note.

composite-provable — computable/decidable ℕ or ℤ oracle — conformance is provable in-kernel with decide.
oracle-testable — computable oracle as differential-test ground truth: exact ℚ/ℤ arithmetic, plus Float (IEEE-754 binary64) oracles for float64 functions.
spec-only — noncomputable real oracle only (e.g. arbitrary-precision Gamma) — specifies exact-ℝ behavior.

composite-provable 15

computable/decidable ℕ or ℤ oracle — conformance is provable in-kernel with decide

Function Wikidata Mathlib oracle Computability Faithfulness
Z12427is primeQ49008decide (Nat.Prime n) -- via instance Nat.decidablePrimedecidablefaithful
Z13521addQ32043Nat.add (equivalently the `(· + ·)` / HAdd.hAdd on ℕ)computable (ℕ/ℤ)wrong target
Z13612greatest common divisorQ131752Nat.gcdcomputable (ℕ/ℤ)wrong target
Z13660least common multipleQ102761Nat.lcmcomputable (ℕ/ℤ)wrong target
Z13667factorialQ120976Nat.factorialcomputable (ℕ/ℤ)faithful
Z13701are coprimeQ104752Nat.Coprime (i.e. decide (Nat.Coprime m n)); definitionally Nat.gcd m n = 1decidablefaithful
Z13822modular inverseQ2741788fun (a n : ℕ) => ((a : ZMod n)⁻¹).val -- ⁻¹ is ZMod.inv; .val is the canonical residuecomputable (ℕ/ℤ)faithful
Z13835nth Fibonacci numberQ23835349Nat.fibcomputable (ℕ/ℤ)faithful
Z13955Euler totientQ190026Nat.totientcomputable (ℕ/ℤ)faithful
Z14933is perfect numberQ170043decide (Nat.Perfect n)decidablefaithful
Z15483nth r-simplex numberQ331350Nat.choose (n + r - 1) r -- equivalently Nat.multichoose n r (Nat.multichoose_eq)computable (ℕ/ℤ)wrong target
Z15849Kronecker deltaQ192826fun (i j : ℕ) => (if i = j then 1 else 0 : ℕ) -- equivalently (1 : Matrix ℕ ℕ ℕ) i j, characterized by Matrix.one_applycomputable (ℕ/ℤ)faithful
Z18194powersetQ205170Finset.powersetcomputable (ℕ/ℤ)repr. mismatch
Z20000Bayes' theoremQ182505fun (pBA pA pB : ℚ) => pBA * pA / pBcomputable (ℕ/ℤ)repr. mismatch
Z28925is Pythagorean tripleQ208225decide (a * a + b * b = c * c) -- equiv to PythagoreanTriple over ℤ; for the Mathlib decl use: decide (PythagoreanTriple (a:ℤ) b c)decidablefaithful

oracle-testable 9

computable oracle as differential-test ground truth: exact ℚ/ℤ arithmetic, plus Float (IEEE-754 binary64) oracles for float64 functions

Function Wikidata Mathlib oracle Computability Faithfulness
Z10862multiply numeric stringsQ40276HMul.hMul (or Nat.mul / Int.mul); for the decimal "full stop" format, Rat multiplication (· * ·) on ℚcomputable (ℕ/ℤ)wrong target
Z12665exponentiationQ33456(· ^ ·) on Float · ideal: Real.rpowfloat64faithful
Z13341linear interpolationQ2266329(1 - t)·a + t·b on Float · ideal: AffineMap.lineMapfloat64faithful
Z21003natural logarithmQ204037Float.log · ideal: Real.logfloat64faithful
Z21005log base 10Q966582Float.log x / Float.log 10 · ideal: Real.logb 10float64faithful
Z21917complex conjugate (integer pair)Q381040fun p : ℤ × ℤ => (p.1, -p.2) -- integer-pair conjugation; corresponds to starRingEnd ℂ via conj_re/conj_im (Complex.star z = ⟨z.re, -z.im⟩)computable (ℕ/ℤ)repr. mismatch
Z30840arithmetic meanQ19033fun (l : List ℕ) => ((l.map (Nat.cast : ℕ → ℚ)).sum) / (l.length : ℚ)computable (ℕ/ℤ)wrong target
Z31173Euler characteristicQ852973(fun (V E F : ℕ) => (V : ℤ) - (E : ℤ) + (F : ℤ)) -- elementary V - E + F; no dedicated Mathlib decl existscomputable (ℕ/ℤ)wrong target
Z35278Shannon entropyQ204570∑ negMulLog over Float (bits) · ideal: Real.negMulLogfloat64faithful

spec-only 1

noncomputable real oracle only (e.g. arbitrary-precision Gamma) — specifies exact-ℝ behavior

Function Wikidata Mathlib oracle Computability Faithfulness
Z16483gamma functionQ190573Real.Gammanoncomputable ℝrepr. mismatch

What the cross-check found

Pinning a Mathlib oracle doubles as an audit of WikiLean's own AI-generated tags. As originally mapped, only 9 of 25 were faithful for spec purposes: a recurring failure was a tag pointing at a typeclass (the abstract algebraic structure, e.g. GCDMonoid, AddCommMonoid) rather than the computable operation (Nat.gcd, Nat.add). A typeclass can never serve as a value oracle. Each such case was corrected to a concrete computable oracle, lifting the corpus to 14/25 faithful.

The remaining non-faithful rows are honest representation mismatches (right concept, wrong encoding — e.g. a Gaussian-integer pair vs Mathlib's , or a noncomputable Set.powerset vs the enumerable Finset.powerset), kept visible rather than papered over.

Done: a verified composite-evaluator proof-of-concept — a small deep embedding of the Wikifunctions composition language whose evaluator proves Z13701's composite implementation equals(gcd(a, b), 1) equal to Mathlib's Nat.Coprime (zero sorry; axioms = propext). Next: generalize the evaluator to the remaining composite functions, and a differential-testing harness that runs these oracles against the live Wikifunctions evaluator API.