Repository navigation
A quantifier's facts are read inside its body - #1500
Merged
Merged
Conversation
forall p in PP : forall k in ZZ : (0 < k and k < p) implies p divides binomial(p, k) was left as written: the claim needs p prime and 0 < k < p, and only the quantifiers around it say so. A quantifier whose body has a rule that reads facts now decides it with them in scope: that its name is in its set and, while a claim is simplified, the conjuncts of its hypothesis. The rule for p divides binomial(p, k) reads them (Nat.Prime.dvd_choose_self). The bound name is renamed first, to a name no other expression has, and every fact is about a renamed name, so nothing that read a fact is reachable from outside the decision, through a node's own cache or a structural one. Steps recorded under a renamed name are written back under the given one. Part of #1409. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1409.
This implements Prob 8.9.24 for every prime, as agreed on #1409.
forall p in PP : forall k in ZZ : (0 < k and k < p) implies p divides binomial(p, k)is nowTrue. It was left as written, because the claim needspprime and0 < k < p, and only the quantifiers around it say so.How the facts reach the rule
A quantifier hands its facts down while it decides its body. It establishes that its name is in the set it ranges over, and, while a claim is simplified, the conjuncts of its hypothesis.
forall x in S : H implies C, the conjuncts ofHare in scope whileCis simplified, and never whileHis.existsandexists!, each conjunct is simplified with the ones before it in scope.pis prime in either order of the two quantifiers. A curried hypothesis,0 < k implies (k < p implies ...), works too.The rule for
p divides binomial(p, k)reads them throughQuantifierFacts.PrimeDividesItsBinomial.Why nothing leaks
The bound name is renamed first, to a name no other expression has, taken from a process-wide counter. Every fact is about a renamed name. A node that caches its simplification can only have read a fact if it mentions a renamed name, and every such node is built during this decision. So nothing reachable from outside the decision can hold a verdict that depended on the facts, including through a cache keyed on structure. For the same reason, a conjunct of the hypothesis that mentions only free names is not put in scope.
WhatTheQuantifiersEstablishDoesNotLeaveThemshares one claim node between a statement and the caller. The statement isTrue, and afterwards the claim on its own is stillp divides binomial(p, k)underEvaled,InnerSimplifiedandSimplify().A substitution stops at a binder, so an inner quantifier that binds
pagain isn't renamed through, and the outer facts don't reach it:forall p in PP : forall p in ZZ+ : ...isFalse. The renaming happens only where a rule in the body reads facts. Every other statement is decided as before, under its own names.What the rule needs
It needs
pprime,kwhole,k > 0andp - k > 0. Positivity is read off the comparisons and memberships in scope, up to a constant:k <= p - 1boundsp - kbelow by 1, and a prime is at least 2. So over the primesp divides binomial(p, 1)isTrue, andp divides binomial(p, 2)isFalse(a counterexample atp = 2). Without primality, or without either bound onk, the statement isFalse. For a realkit stays unevaluated.Proof recording
Steps recorded under a renamed name are written back under the given one. When the facts reduce a body to
True, the statement is recorded as written, so the proof reads:Nat.Prime.dvd_choose_self (hp : p.Prime) (hk : k ≠ 0) (hkp : k < p) : p ∣ choose p kis inMathlib/Data/Nat/Choose/Dvd.lean.Measured
The unit suite passes on net10.0: 12738 passed, 14 skipped, none failed, out of 12752, of which 14 are new.
The allocation gate passes on all 19 gated benchmarks.
Fermat's little theorem is next, derived from this rule through the binomial theorem as the book does.
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura