\documentclass[11pt]{article} \usepackage{common} \begin{document} \notehead{0302}{Dependent type theory: the minimum for reading Mathlib statements}{Pi types, \texttt{Prop} versus \texttt{Type}, decidability, and ten miniF2F statements decoded binder by binder. Companion notebook: \texttt{notebooks/\allowbreak 0302-dependent-types.ipynb}.} \begin{problem} \question{What must we be able to read in a Lean statement to know what the reward actually measures?} Note 0301 showed that the kernel certifies $v:T$ for the type $T$ \emph{as written}. Whether the reward measures what we want therefore depends on reading $T$ correctly: which variables are bound, which symbols are hypotheses, what \texttt{/}, \texttt{-}, \texttt{$\uparrow$} and \texttt{$\forall n\le9$} really mean, and whether Lean can \emph{evaluate} the statement or only prove it. This note gives the smallest dependent-type vocabulary needed to read a statement such as those of miniF2F \cite{minif2f} and to see which hazards are in the statement and not in the proof. \end{problem} \stepcounter{section}% the problem box counts as section 1: keeps every \S and notebook cross-reference stable \section{Notation} \begin{center}\small \begin{tabular}{@{}lP{10.3cm}@{}}\toprule Symbol & Meaning\\\midrule $\Pi x{:}A.\,B(x)$ & dependent function type (Lean: \texttt{(x : A) $\to$ B x}, \texttt{$\forall$ x : A, B x})\\ $A\to B$ & $\Pi x{:}A.\,B$ with $x\notin\FV(B)$ (non-dependent)\\ $\Sort\,u$ & universe at level $u\in\{0,1,2,\dots\}$; $\Prop=\Sort\,0$, $\Type\,n=\Sort(n{+}1)$, $\Type=\Sort\,1$\\ $\imax(u,v)$ & $0$ if $v=0$, else $\max(u,v)$\\ $P:\Prop$ & a proposition; a term $h:P$ is a proof of it (0301)\\ \texttt{Decidable}\,$P$ & a \emph{datum} (\texttt{isTrue h} or \texttt{isFalse h}) deciding $P:\Prop$; \texttt{decide}\,$P:\bool$\\ $\uparrow$ & an inserted coercion (e.g.\ $\N\to\R$)\\ $a\mathbin{-}b$ on $\N$ & truncated subtraction $\max(a-b,0)$; $a\mathbin{/}b$ on $\N$: floor; on $\Z$: Euclidean (\S3.4)\\\bottomrule \end{tabular} \end{center} \section{Derivation} \subsection{From $A\to B$ to $\Pi x{:}A.\,B(x)$} In 0301 a proof of $A\to B$ is a function from proofs of $A$ to proofs of $B$. For $\forall x{:}X.\,P(x)$ the \emph{type} of the result depends on the argument: a proof of $P(3)$ and a proof of $P(4)$ are proofs of different propositions. A function whose result type depends on its argument has type $\Pi x{:}X.\,P(x)$. Rules (with $\Gamma$ as in 0301): \begin{gather*} \frac{\Gamma\vdash A:\Sort\,u\quad\Gamma,x{:}A\vdash B:\Sort\,v}{\Gamma\vdash\Pi x{:}A.\,B:\Sort\,\imax(u,v)}\ (\Pi\text{F})\qquad \frac{\Gamma,x{:}A\vdash t:B}{\Gamma\vdash\lambda x{:}A.\,t:\Pi x{:}A.\,B}\ (\Pi\text{I})\\[4pt] \frac{\Gamma\vdash f:\Pi x{:}A.\,B\quad\Gamma\vdash a:A}{\Gamma\vdash f\,a:B[x{:=}a]}\ (\Pi\text{E}) \end{gather*} with $(\lambda x.t)\,a\rightsquigarrow t[x{:=}a]$. Setting $x\notin\FV(B)$ recovers 0301's rules, so $\to$ is a special case. This is precisely rule \texttt{t-all} of the formalised kernel (Lean4Lean \S2.2: $\Gamma\vdash(\forall x{:}\alpha.\beta):U_{\imax(\ell_1,\ell_2)}$) \cite{lean4lean}. \subsection{Universes and why $\imax$ is the right rule} Every type lives in a sort, and $\Sort\,u:\Sort(u{+}1)$ (Lean4Lean \S2.1: ``the type of \texttt{sort u} is \texttt{sort (succ u)}''). What should $\Pi x{:}A.\,B$ live in? Two constraints. \begin{enumerate}[nosep] \item \emph{Predicativity of data}: if $A:\Sort\,u$ and $B:\Sort\,v$ with $v>0$, the function type must be at least as large as both (a smaller universe would let a type contain a type that quantifies over it; this is the design constraint behind Girard's paradox, which we do not re-derive). The least choice is $\max(u,v)$. \item \emph{Impredicativity of propositions}: for a statement $\forall x{:}A.\,P(x)$ with $P(x):\Prop$ we want the result to be a $\Prop$ \emph{even if $A$ is huge} (e.g.\ $A=\Prop$ itself: $\forall p{:}\Prop,\ p\to p$). Otherwise ``for all sets $S$, \dots'' would be a $\Type$, not a proposition, and could not be an argument of $\land$, $\to$ or a hypothesis. \end{enumerate} Combining the two gives exactly $\imax(u,v)=0$ if $v=0$ else $\max(u,v)$. Consistency of the impredicative bottom universe together with proof irrelevance is the classical Calculus-of-Constructions result \cite{mathlib20} \S2. \emph{Worked checks (notebook cell 1; the kernel agrees on all ten).} $\forall n{:}\N,\ n=n$: $u=1$ ($\N:\Type$), $v=0$, so $\imax=0$: a $\Prop$. $(\alpha{:}\Type)\to\alpha\to\alpha$: $\Type:\Type\,1=\Sort\,2$ so $u=2$, $v=1$, so $\Sort\,2=\Type\,1$. $\forall p{:}\Prop,\ p\to p$: $u=1$, $v=0$, so a $\Prop$ (impredicative). \subsection{A theorem statement is a Pi telescope; hypotheses are non-dependent binders} \[\texttt{theorem}\ c\ (x_1{:}A_1)\cdots(x_n{:}A_n)\ (h_1{:}H_1)\cdots(h_m{:}H_m)\ :\ G\] \[\text{means}\qquad c:\ \Pi x_1{:}A_1\cdots\Pi x_n{:}A_n.\ H_1\to\cdots\to H_m\to G.\] A proof is $\lambda x_1\dots x_n\,h_1\dots h_m.\,t$ with $t:G$; the tactic \texttt{intro} is $\Pi$I. The $h_i$ are \emph{non-dependent} binders (their names are not free in later types) so \texttt{\#check} prints them as arrows, with names dropped: \begin{lstlisting} mathd_algebra_478 : ∀ (b h v : ℝ), 0 < b ∧ 0 < h ∧ 0 < v → v = 1 / 3 * (b * h) → b = 30 → h = 13 / 2 → v = 65 \end{lstlisting} Binder-predicate notation $\forall n\le 9,\ Q$ is sugar for $\forall n,\ n\le9\to Q$ (so it has \emph{two} binders: $n$ and an anonymous proof). The sort of the whole statement is $\imax$ of the pieces, hence $\Prop$ (the notebook's \texttt{\#sort\_of} reports \texttt{sort=Prop} for all ten). \subsection{Elaboration: what the symbols mean} The elaborator inserts information the surface text does not show. Four rules cover almost every surprise. \paragraph{(a) Numerals and unification.} A literal \texttt{2} is \texttt{OfNat ?$\alpha$ 2}; $?\alpha$ is fixed by unification with the surrounding term, and defaults to $\N$ if nothing constrains it. In \texttt{v = 1/3 * (b * h)} with $v{:}\R$, the \texttt{1/3} is real, $=1/3$; had it been elaborated in $\N$ it would be $0$. \emph{Elaboration order matters}: \texttt{$\forall$ n < 40, Nat.Prime (n*n+n+41)} fails to find a \texttt{Decidable} instance (notebook; our diagnosis of the cause is that $n{:}?\alpha$ is still a metavariable when synthesis is attempted, the observed fact is the failure), while \texttt{$\forall$ n < (40:$\N$), \dots} succeeds. \paragraph{(b) Coercions.} A $\uparrow$ is inserted when a term of type $A$ is used where $B$ is expected (\texttt{aime\_1983\_p1}: $x,y,z,w:\N$ but \texttt{Real.log} needs $\R$). $\uparrow(a-b)\ne\uparrow a-\uparrow b$ in general because $-$ is evaluated \emph{before} casting. \paragraph{(c) Truncated subtraction on $\N$.} \texttt{Nat.sub} is defined by $n-0=n$, $n-(m{+}1)=\mathrm{pred}(n-m)$ with $\mathrm{pred}\,0=0$. Then $5-7=\mathrm{pred}(\mathrm{pred}(5-5))=\mathrm{pred}(\mathrm{pred}\,0)=0$. \begin{lemma}\label{lem:tsub} For $a,b\in\N$: $(a-b)+b=\max(a,b)$.\end{lemma} \emph{Proof.} If $b\le a$ write $a=d+b$; induction on $b$ gives $a-b=d$, so $(a-b)+b=a=\max(a,b)$. If $a true | isFalse \_ => false}$.\end{definition} \begin{lemma}[\texttt{of\_decide\_eq\_true}]\label{lem:dec} $\texttt{decide}\ p=\texttt{true}\to p$.\end{lemma} \emph{Proof.} Case on the instance. If \texttt{isTrue h}, then $p$ holds by $h$. If \texttt{isFalse h}, then $\texttt{decide}\,p=\texttt{false}$, and \texttt{false = true} is absurd (\texttt{Bool.noConfusion}). $\square$\\ So \texttt{by decide} elaborates to \texttt{of\_decide\_eq\_true (Eq.refl true)}: the kernel checks $\texttt{decide}\,p\equiv\texttt{true}$ \emph{by evaluation} (notebook: \texttt{\#print two\_plus\_two}). Closure: $\wedge,\vee,\neg,\to$ preserve decidability (combine the two data); a \emph{bounded} quantifier $\forall n0$ (a \emph{finite} sum: the infinite one equals $1$ and would give only $\ge0$). 200 random $(k,a)$: $|(A,B)|\ge2^{1-k}$ always; residual $3.7\times10^{-15}$.\\ \texttt{mathd\_\-algebra\_\-209} & $\forall(\sigma{:}\R\simeq\R),\ \sigma.\mathrm{invFun}\,2=10\to\sigma.\mathrm{invFun}\,10=1\to\sigma.\mathrm{invFun}\,1=2\to\sigma.\mathrm{toFun}(\sigma.\mathrm{toFun}\,10)=1$ & \texttt{$\sigma$.2} is the structure field \texttt{invFun} (informal $\sigma^{-1}$). \texttt{Equiv} bundles two functions \emph{and} two proofs; proof irrelevance makes equal functions give equal \texttt{Equiv}. Permutation $\{10{\mapsto}2,1{\mapsto}10,2{\mapsto}1\}$ checked.\\ \texttt{mathd\_\-numbertheory\_\-1124} & $\forall n\le9,\ 18\mid374\cdot10+n\to n=4$ & Binder-predicate sugar (binders: $n$, $n\le9$, hypothesis). \texttt{$\mid$} is $\exists c,\ \cdots=18c$ (decidable via \texttt{mod}); the statement is a bounded $\forall$, hence decidable; only $n=4$ works.\\ \texttt{imo\_\-1983\_\-p6} & $\forall(a\,b\,c{:}\R),\ 00\end{cases}$; so every $\forall$-statement is a $\Prop$.\\ \textbf{R2.} $\texttt{theorem}\,c\,(\vec x{:}\vec A)(\vec h{:}\vec H):G$ is the type $\Pi\vec x{:}\vec A.\,\vec H\to G$; hypotheses are non-dependent binders.\\ \textbf{R3.} $\texttt{decide}\,p=\texttt{true}\Rightarrow p$ (Lemma~\ref{lem:dec}); bounded quantifiers decidable, $\forall n{:}\N$ and $=_\R$ not.\\ \textbf{R4.} $(a-b)+b=\max(a,b)$ on $\N$; $\Z$-division is Euclidean ($a=bq+r$, $0\le r<|b|$); $x/0=0$ on $\R$. \end{result} \paragraph{Numerical verification (notebook 0302, all cells executed).} \begin{center}\small\begin{tabular}{@{}P{7.4cm}P{2.8cm}P{4.4cm}@{}}\toprule Identity & agreement & max abs error\\\midrule R1: $\imax$ rule vs the kernel's sort of 10 Pi types & 10/10 & 0 (exact)\\ R3: Python brute force vs Lean \texttt{decide} on 12 bounded statements & 12/12 & 0\\ R4: Lean \texttt{\#eval} vs Python model of $\N$/$\Z$ on 8 expressions; Lean $7/(-2)=-3$ and $(-7)/2=-4$ vs floor & 8/8; Python \texttt{//} differs on $7/(-2)$ as predicted & 0\\ Ten miniF2F statements: hypotheses satisfiable, conclusion verified & 10/10 & exact for 8; $0$ (aime, fp64), $3.7\times10^{-15}$ (imo\_1969\_p2), $E/a^4\ge6.6\times10^{-8}$ (imo\_1983\_p6)\\ Kernel/Lean elaboration of all ten, sort $=\Prop$ & 10/10 & ---\\ R4: \texttt{a - b + b = max a b} (Python on $61^2$ pairs; Lean proof); Euclidean law and $a/0=0$ on $\Z$ (1464-point grid, Lean); $x/0=0$ on $\R$ (Lean proof) & all & 0\\\bottomrule\end{tabular}\end{center} \section{What breaks} \begin{center}\small\begin{tabular}{@{}P{3.2cm}P{6.2cm}P{5.2cm}@{}}\toprule Failure & Mechanism & Assumption violated\\\midrule Wrong default type & \texttt{1/3} elaborated in $\N$ is $0$; a statement ``true'' for the wrong reason & the author's numeral type equals the elaborator's (check \texttt{pp.numericTypes})\\ Truncated \texttt{-} / floor \texttt{/} & $\N$ arithmetic silently differs from $\Z$/$\R$ (Lemma~\ref{lem:tsub}) & informal ``$a-b$'' is real subtraction\\ Total division $x/0=0$ & dropping \texttt{x $\ne$ 0} can make a false statement true or a true one false & the informal statement excludes division by 0\\ Vacuous hypotheses & contradictory hypotheses make any conclusion provable (0305); $0\le w$ on $\N$ is harmless but shows how informal ``positive'' can degrade & hypotheses are satisfiable; check by witness\\ \texttt{autoImplicit} & a typo \texttt{xx} becomes a fresh universally quantified variable: \texttt{@t\_typo : $\forall$ \{xx : $\N$\} (x : $\N$), x+1 > xx} (notebook); with it off, \texttt{unknown identifier} & every free identifier is intended; the benchmark audit recommends disabling \texttt{autoImplicit} \cite{faults26}\\ Over-/under-statement & statements simplified, solution given away, or unprovable: miniF2F has formal/informal mismatches in over half of 488 problems and 16 unprovable statements \cite{minif2frev} & formal $\approx$ informal\\ Using \texttt{decide} on large closed props & kernel evaluation is slow/exhausts recursion; statement with $\R$ has no instance & statement is small and over a decidable fragment\\\bottomrule\end{tabular}\end{center} \nextnote{0303 specifies \emph{code}, not mathematics: pre/postconditions as Pi/implication types, verification conditions, loop invariants, and a verified linear search in Lean~4.} \begin{small} \begin{thebibliography}{99} \bibitem{lean4lean} M.~Carneiro, \emph{Lean4Lean}, arXiv:2403.14064, \S2.1 (universe levels, \texttt{imax a b = if b = 0 then 0 else max a b}), \S2.2 (rule \texttt{t-all}). \bibitem{mathlib20} The mathlib Community, \emph{The Lean Mathematical Library}, arXiv:1910.09336, \S2 (CIC; impredicative, proof-irrelevant \texttt{Prop}; universe hierarchy), \S4.2 (the \texttt{decidable} class; $\mathrm{decidable}\ p\simeq\Sigma b,\mathrm{reflect}\ b\ p$; classical instances via choice). Lean~3 text; the logic is shared. \bibitem{minif2f} K.~Zheng, J.~M.~Han, S.~Polu, \emph{miniF2F: a cross-system benchmark for formal Olympiad-level mathematics}, arXiv:2109.00110 (488 problems, 244 valid / 244 test). \emph{Not fetched; only the problem count, confirmed in \cite{minif2frev}, is used.} \bibitem{minif2frev} M.~Ospanov, F.~Farnia, R.~Yousefzadeh, \emph{miniF2F-Lean Revisited}, arXiv:2511.03108, \S2.1--2.2 (informal and formal statement errors); the ``Unprovable statements'' paragraph, inside \S2.2, reports 16 unprovable problems across the test and validation sets; abstract: formal/informal discrepancies for more than half of the problems. \bibitem{faults26} P.~S.~Ammanamanchi, S.~Bhat, S.~Biderman, \emph{Faults in Our Formal Benchmarking}, arXiv:2606.29493: taxonomy of dataset defects; release standards (disable \texttt{autoImplicit}). \bibitem{cc88} T.~Coquand, G.~Huet, ``The calculus of constructions'' (1988); J.-Y.~Girard (1972) for the paradox that forces the predicativity constraint. \emph{Not on arXiv; not fetched; cited for the named results; the $\imax$ rule is derived above from the two constraints and checked against the kernel.} \end{thebibliography} \end{small} \end{document}