Balls in a box

Codex · gpt-6.1-sol

Round 1

Messages

Instructions
Balls protocol v1 — human-in-the-loop scientific workflow.

1. Formulate a Bayesian model yourself. Separate facts supplied by the user from choices or extra assumptions you introduce. Prefer deriving or estimating model parameters from the supplied observations and, when useful, requested experiments. State and justify the model family and observation model needed for that inference. For example, assume and justify a distribution family explicitly, then derive its parameters from the supplied moments, observations or experiment results; do not assume both the family and a complete set of parameter values when those values are what the task requires you to infer. Do not choose convenient parameter values and merely show that they reproduce the observations, presenting that exercise as inference. If the observations do not determine the parameters, expose what remains undetermined and what additional information or assumptions would be needed. Do not silently turn population moments into a fully specified prior.
2. If the information does not determine a unique answer, explain why and give a conditional answer with its assumptions exposed. You may revise the model and conclusion across attempts; preserve the reasons and lineage.
3. Write a substantive Lean proof for the model, observation, Bayesian update and next-draw prediction. A proof of arithmetic for a number calculated elsewhere is insufficient. The human will assess scientific relevance and whether the proof covers the actual inference.
4. Use available tools, including Internet research. Request literature, calculations, experiments or clarification from the operator when useful; a request is optional. Use the request tool below, stop for a real response, and incorporate the response with its source and limitations. Never invent an external response.
5. Run the actual check tool. Read and fix its real errors, retrying without replacing science with a smaller unrelated theorem. Preserve model changes and raw traces.
6. You may introduce additional premises or axioms, but expose them for review. Any sorry or additional axiom is conditional, never an unconditional full pass. Lean correctness does not establish the truth of the premises.
7. Extract definitions, constants, data, assumptions and the exact conclusions. The harness independently compiles and compares the extracted statements and runs a separate kernel check. A failed or unknown check is not success.
8. A human reviews the actual content and may accept or reject it with feedback. If the researcher rejects the assumptions or conclusions, revise your model, assumptions, conclusions and proof in response to the feedback. Never accept your own result or claim human approval.

Human-readability requirements:
- Write the formalization so a human scientist can understand what is assumed and what is concluded, with a concise plain-language translation alongside the relevant Lean statements. Explain the real-world meaning of the model and the reason for each scientific modeling choice.
- Keep the assumptions, scientifically meaningful definitions and final conclusions as small and direct as possible. Avoid redundant definitions, duplicate specializations of the same formula, synonyms, and layers of wrappers that merely rename an expression. Retain a helper definition only when it materially improves clarity or is mathematically necessary.
- Put derivable facts and technical work into intermediate lemmas or proof-local helpers: algebra, normalization, parameter calculations and other consequences should be proved rather than added to the review assumptions. Keep the final conclusion focused on the actual scientific answer.
- Minimizing the review boundary must preserve its meaning: expose every independent modeling choice and every definition needed to interpret the conclusion. Do not hide assumptions in intermediate lemmas, use unproved facts as lemmas, or shorten the conclusion into an unexplained proposition alias.
- Before submission, simplify the public statement and its dependency chain, and give a compact review section separating supplied information, additional assumptions, necessary definitions and proved conclusions. Definitions introduced solely for proof organization should stay inside the proof when possible. Do not optimize for a short file at the cost of a longer or less intelligible assumptions/conclusions packet.

Isolation rule: work only from this task, these instructions, native installed libraries, and the run's own history and supplied responses. Do not seek previous solutions, task-specific proofs, or preset model families, parameter values or expected answers from earlier runs. You may consult general scientific or statistical literature to select and justify a model family. Authentication metadata is mounted only because the native Codex client needs its existing subscription login; it is not scientific evidence. Do not read, print, copy or modify authentication files. Never use paid APIs, API-key fallback, other agents, or external services requiring payment. Stop on subscription quota/authentication errors.

Tools (run in the terminal):
  python /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json
  python /harness/src/vcs_protocol.py tool request --kind literature --question '...'
Kinds are literature, calculation, experiment, clarification. A request stops this cycle; the operator supplies an answer and resumes. Record incorporated response IDs in the candidate. Evidence is user/external supplied and not guaranteed true.

Write /work/candidate.json with this shape (all paths relative to /work):
{"proof_file":"Model.lean", "narrative_file":"report.txt", "conclusions":{"answer":"answer_theorem"}, "user_facts":["..."], "model_choices":["..."], "sources":["..."], "incorporated_inputs":[], "proof_scope":"What the theorems actually establish and what is left to human review"}
List only the final scientific conclusion or conclusions needed to answer the task, with nonempty labels mapped to actual, distinct Lean theorem declarations. A single answer theorem is allowed. Supporting model, update, normalization and other derived facts may be intermediate lemmas; there are no mandatory model/update/prediction conclusion roles. Use plain top-level `theorem name : statement := proof` declarations, with all binders inside `statement`. Imports must be explicit `import Mathlib.…` lines at the start of the file; imports of project/task files are unavailable. The restricted proof language supports definitions, structures, lemmas, axioms and sorry but no executable metaprogramming, custom syntax, namespaces, native_decide, IO or unsafe code. Check feedback gives concrete unsupported syntax errors. Native Mathlib tactics are available. Explain any restriction that prevents a scientifically meaningful formalization; do not pretend a narrower result meets the task.
Task
I have a box that initially contained 50 balls, each either black or white. I drew 10 balls, all of which were black, and did not return them to the box. There are now 40 balls remaining. Other boxes of the same kind also initially contain 50 black and white balls. Across these boxes, the fraction of black balls has a mean of 0.75 and a standard deviation of 0.1. I do not know the original number of black balls in my particular box. Using Bayesian statistics, what is the probability that the next ball drawn from the remaining balls will be black?
assistant
I’ll check the available Lean setup and run history, then distinguish what the supplied moments determine from any additional assumptions needed for a prediction.
shell input
{
  "command": "/usr/bin/bash -lc \"pwd && rg --files -g '\"'!.*'\"' /work | head -60\""
}
shell output · exit 0
/work
/usr/bin/bash: line 1: rg: command not found
shell input
{
  "command": "/usr/bin/bash -lc 'ls -la /work; ls -la /harness; find /work -maxdepth 2 -type f; which lean; which lake'"
}
shell output · exit 1 · failed
total 8
drwxrwxr-x 2 1001 1001 4096 Nov 16 15:30 .
drwxr-xr-x 1 root root 4096 Nov 16 15:30 ..
total 24
drwxr-xr-x 4 root root 4096 Nov 16 15:30 .
drwxr-xr-x 1 root root 4096 Nov 16 15:30 ..
drwxr-xr-x 3 root root 4096 Nov 16 15:30 .lake
-rwxrwxr-x 1 1001 1001  305 Nov 16 12:39 entrypoint.sh
-rw-rw-r-- 1 1001 1001   25 Nov 13 18:58 lean-toolchain
drwxr-xr-x 2 root root 4096 Nov 16 15:30 src
web_search input
{
  "query": "hypergeometric distribution sampling without replacement probability formula N K n",
  "action": {
    "type": "search",
    "query": "hypergeometric distribution sampling without replacement probability formula N K n"
  }
}
web_search output
{
  "results": [
    {
      "type": "text_result",
      "domain": "stats.libretexts.org",
      "ref_id": "turn0search0",
      "snippet": "The hypergeometric distribution is used to calculate probabilities when sampling without replacement. ... You can calculate this probability using the following formula based on the",
      "title": "5.11: Hypergeometric Distribution - Statistics LibreTexts",
      "url": "https://stats.libretexts.org/Bookshelves/Introductory_Statistics/Introductory_Statistics_%28Lane%29/05%3A_Probability/5.11%3A_Hypergeometric_Distribution"
    },
    {
      "type": "text_result",
      "domain": "casrai.org",
      "ref_id": "turn0search1",
      "snippet": "# Hypergeometric Distribution Formula: Definition, Worked Example and Software ... The hypergeometric distribution gives the probability of drawing exactly k items of a particular type",
      "title": "Hypergeometric Distribution Formula and Examples — CASRAI",
      "url": "https://casrai.org/guides/hypergeometric-distribution-formula"
    },
    {
      "type": "text_result",
      "domain": "people.stat.sc.edu",
      "ref_id": "turn0search12",
      "snippet": "# Sampling without replacement: The Hypergeometric Distribution - If we take a sample (without replacement) of size \\(n\\) from a finite collection of \\(N\\) objects",
      "title": "# Sampling without replacement: The Hypergeometric Distribution",
      "url": "https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf"
    },
    {
      "type": "text_result",
      "domain": "www.math.ucla.edu",
      "ref_id": "turn0search13",
      "snippet": "Actually, it is not difficult to write down an exact formula for the probability function of \\(N_n\\) when the sampling is done without replacement. ...",
      "title": "winter99.PDF",
      "url": "https://www.math.ucla.edu/~scp/3c.1.99w/3c.1.w99.pdf"
    },
    {
      "type": "text_result",
      "domain": "www.stat.auckland.ac.nz",
      "ref_id": "turn0search14",
      "snippet": "The hypergeometric distribution is used when we are sampling without replacement from a finite population. ... ii) Probability function ... Boxed formula: \\(f_X(x) = \\mathbb{P}(X",
      "title": "3.4 Hypergeometric distribution: sampling without replacement",
      "url": "https://www.stat.auckland.ac.nz/~fewster/210/notes/2017S2/ch3blank.pdf"
    },
    {
      "type": "text_result",
      "domain": "ndl.ethernet.edu.et",
      "ref_id": "turn0search15",
      "snippet": "Section 3-8/Hypergeometric Distribution ... Note that, in the unusual case that each unit selected is replaced before the next selection, the trials are independent and",
      "title": "Applied Statistics and Probability for Engineers, 6th Edition",
      "url": "https://ndl.ethernet.edu.et/bitstream/123456789/28728/1/Douglas%20C.%20Montgomery%2C_2014.pdf"
    },
    {
      "type": "text_result",
      "domain": "www.cur.ac.rw",
      "ref_id": "turn0search16",
      "snippet": "60 CHAPTER 3 Discrete Random Variables and Probability Distributions ... Gray boxed definition titled “Hypergeometric Distribution” with a formula. ... A sample of size n",
      "title": "Applied Statistics and Probability for Engineers, 7th Edition",
      "url": "https://www.cur.ac.rw/mis/main/library/documents/book_file/digital-695b9c5bc798e2.35384655.pdf"
    },
    {
      "type": "text_result",
      "domain": "www.learnmathclass.com",
      "ref_id": "turn0search2",
      "snippet": "Four letters, two sizes: the hypergeometric's marks run on a case system — capitals for the population, lowercase for the sample — and its pmf",
      "title": "Hypergeometric Distribution: Sampling Without Replacement | Learn Math Class",
      "url": "https://www.learnmathclass.com/probability/distributions/discrete/hypergeometric"
    },
    {
      "type": "text_result",
      "domain": "stats.libretexts.org",
      "ref_id": "turn0search3",
      "snippet": "If the sampling is without replacement, then \\( Y \\) has the hypergeometric distribution with parameters \\( m \\), \\( r \\), and \\( n",
      "title": "11.2: The Binomial Distribution - Statistics LibreTexts",
      "url": "https://stats.libretexts.org/Bookshelves/Probability_Theory/Probability_Mathematical_Statistics_and_Stochastic_Processes_%28Siegrist%29/11%3A_Bernoulli_Trials/11.02%3A_The_Binomial_Distribution"
    },
    {
      "type": "text_result",
      "domain": "stat20.berkeley.edu",
      "ref_id": "turn0search17",
      "snippet": "Hypergeometric distribution ... random sample of size 𝑛from this box. ... What is the probability that we will have exactly 𝑘successes among these 𝑛draws? ...",
      "title": "Probability Distributions",
      "url": "https://stat20.berkeley.edu/spring-2024/3-probability/03-probability-dsns/notes.pdf"
    },
    {
      "type": "text_result",
      "domain": "stat20.berkeley.edu",
      "ref_id": "turn0search4",
      "snippet": "### Hypergeometric distribution ... A simple random sample is a sample drawn without replacement, and on each draw, every ticket is equally likely to be",
      "title": "Probability Distributions – Stat 20",
      "url": "https://stat20.berkeley.edu/spring-2026/3-generalization/03-probability-dsns/notes.html"
    },
    {
      "type": "text_result",
      "domain": "stattrek.org",
      "ref_id": "turn0search5",
      "snippet": "The probability distribution of a hypergeometric random variable is called a hypergeometric distribution. ... * A sample of size n is randomly selected without replacement",
      "title": "Hypergeometric Distribution",
      "url": "https://stattrek.org/probability-distributions/hypergeometric?tutorial=prob"
    },
    {
      "type": "text_result",
      "domain": "probability.app",
      "ref_id": "turn0search6",
      "snippet": "# Hypergeometric distribution You will learn: Compute counts from finite sampling without replacement and check feasible outcomes. ... Hypergeometric PMF Binomial approximation $\\mathrm{Binomial}(K,\\,",
      "title": "Hypergeometric distribution · probability.app",
      "url": "https://probability.app/distributions/hypergeometric"
    },
    {
      "type": "text_result",
      "domain": "atlasofengineering.com",
      "ref_id": "turn0search7",
      "snippet": "A simple random sample without replacement makes every subset of size n equally likely. ... \\displaystyle P(X=k)=\\frac{\\binom Kk\\binom{N-K}{n-k}}{\\binom Nn}. ... Penn State’s probability lesson presen",
      "title": "Hypergeometric Distribution and Sampling Without Replacement | Atlas of Engineering",
      "url": "https://atlasofengineering.com/mathematical-engineering/hypergeometric-distribution-and-sampling-without-replacement/"
    },
    {
      "type": "text_result",
      "domain": "www.pearson.com",
      "ref_id": "turn0search8",
      "snippet": "Image: Mathematical formula for hypergeometric distribution calculating probabilities in sampling without replacement. ... Identify the parameters for the hypergeometric distribution based on the prob",
      "title": "If we sample from a small finite population without replacement, - Triola 14th Edition Ch 5 Problem 5.4.43",
      "url": "https://www.pearson.com/channels/statistics/textbook-solutions/triola-elementary-statistics-14th-edition-9780137366446/ch-5-discrete-probability-distributions/if-we-sample-from-a-small-finite-population-without-replacement-the-binomial-dis"
    },
    {
      "type": "text_result",
      "domain": "www.pearson.com",
      "ref_id": "turn0search9",
      "snippet": "For a population of N items having k successes and failures, the probability of selecting a sample of size that has successes and failures is",
      "title": "Hypergeometric Distribution Binomial experiments require - Larson 8th Edition Ch 4 Problem 4.3.28a",
      "url": "https://www.pearson.com/channels/statistics/textbook-solutions/larson-elementary-statistics-picturing-the-world-8th-edition-9780137493470/ch-4-discrete-probability-distributions/hypergeometric-distribution-binomial-experiments-require-that-any-sampling-be-do"
    },
    {
      "type": "text_result",
      "domain": "snowch.github.io",
      "ref_id": "turn0search10",
      "snippet": "The Hypergeometric distribution models the number of successes in a sample drawn without replacement from a finite population. ... $$P(X=k) = \\frac{\\binom{K}{k} \\binom{N-K}{n-k}}{\\binom{N}{n}}$$P(X=k)",
      "title": "Chapter 7: Common Discrete Distributions - Learn Probability",
      "url": "https://snowch.github.io/learn_probability/chapter-07/"
    },
    {
      "type": "text_result",
      "domain": "lovetocalc.com",
      "ref_id": "turn0search11",
      "snippet": "# Hypergeometric distribution The binomial distribution's sibling for draws without replacement: cards from a deck, numbers from a lottery drum, parts from a small batch.",
      "title": "Hypergeometric Distribution — Drawing without Replacement",
      "url": "https://lovetocalc.com/en/formulas/mathematics/statistics/hypergeometric-distribution/"
    },
    {
      "type": "text_result",
      "domain": "en.wikipedia.org",
      "ref_id": "turn0search18",
      "snippet": "In probability theory and statistics, the hypergeometric distribution is a discrete probability distribution that describes the probability of ${\\displaystyle k}$ successes (random draws for which",
      "title": "Hypergeometric distribution",
      "url": "https://en.wikipedia.org/wiki/Hypergeometric_distribution"
    },
    {
      "type": "text_result",
      "domain": "arxiv.org",
      "ref_id": "turn0academia19",
      "snippet": "Let $n,k$ be positive integers such that $n\\geq k$, and let $H$ be a hypergeometric random variable counting the number of black marbles in a",
      "title": "On lower bounds for hypergeometric tails",
      "url": "https://arxiv.org/abs/2601.09485"
    },
    {
      "type": "text_result",
      "domain": "arxiv.org",
      "ref_id": "turn0academia20",
      "snippet": "We also establish a convex ordering for sampling without replacement from populations of real numbers between zero and one: a population of all zeros or",
      "title": "Exponential bounds for the hypergeometric distribution",
      "url": "https://arxiv.org/abs/1507.08298"
    },
    {
      "type": "text_result",
      "domain": "arxiv.org",
      "ref_id": "turn0academia21",
      "snippet": "We revisit and refine known tail inequalities and confidence bounds for the hypergeometric distribution, i.e., for the setting where we sample without replacement from a",
      "title": "Hypergeometric Distribution Revisited: Tail Inequalities, Confidence Bounds and Sample Sizes",
      "url": "https://arxiv.org/abs/2405.06722"
    }
  ]
}
shell input
{
  "command": "/usr/bin/bash -lc 'ls -la /harness/src; ls /harness/.lake; ls /opt; find / -maxdepth 3 -name lake -o -name lean 2>/dev/null'"
}
shell output · exit 1 · failed
total 68
drwxr-xr-x 2 root root  4096 Nov 16 15:30 .
drwxr-xr-x 4 root root  4096 Nov 16 15:30 ..
-rw-rw-r-- 1 1001 1001 13714 Nov 16 12:55 vcs_extract.py
-rw-rw-r-- 1 1001 1001  7329 Nov 16 12:58 vcs_lean.py
-rw-rw-r-- 1 1001 1001 32775 Nov 16 15:27 vcs_protocol.py
packages
lean
/opt/lean
web_search input
{
  "query": "https://www.stat.auckland.ac.nz/~fewster/210/notes/2017S2/ch3blank.pdf",
  "action": {
    "type": "open_page",
    "url": "https://www.stat.auckland.ac.nz/~fewster/210/notes/2017S2/ch3blank.pdf"
  }
}
web_search output
{
  "results": [
    {
      "type": "text_result",
      "ref_id": "turn1view0",
      "title": "Internal Error"
    }
  ]
}
shell input
{
  "command": "/usr/bin/bash -lc 'cat /harness/src/vcs_lean.py; ls /opt/lean; ls /harness/.lake/packages/mathlib | head'"
}
shell output · exit 0
"""Restricted Lean validation and kernel-environment assumption audit.

Stable VAS_ audit markers preserve compatibility with recorded evidence.
"""
import os
from pathlib import Path
import re

ROOT = Path(__file__).resolve().parents[1]
_TOOLCHAIN = (ROOT / "lean-toolchain").read_text().strip().replace("/", "--").replace(":", "---")
LEAN = os.environ.get("VAS_LEAN") or str(Path(os.environ.get("ELAN_HOME", Path.home() / ".elan")) / "toolchains" / _TOOLCHAIN / "bin/lean")
LEANCHECKER = str(Path(LEAN).with_name("leanchecker"))
ALLOWED_AXIOMS = {"propext", "Classical.choice", "Quot.sound"}
FORBIDDEN = re.compile(
    r"\b(axioms|native_decide|implemented_by|extern|unsafe|opaque|import|"
    r"macro|macro_rules|syntax|elab|notation|infix|infixl|infixr|prefix|postfix|"
    r"run_cmd|run_tac|run_elab|run_meta|initialize|builtin_initialize|instance|attribute|"
    r"partial|private|local|scoped|namespace|section|end|universe|variable|export|IO|System|"
    r"Lean|native|simproc|dsimproc)\b"
    # any word containing elab (by_elab, elab_rules, run_elab: `\belab\b` misses them, `_` is a word character);
    # backtick name literals and quotations are metaprogramming, which a proof body never needs (OT-1861)
    r"|\w*elab\w*|`|#|@\[|\$|«|»")


def strip_comments(source):
    out, i, depth = [], 0, 0
    while i < len(source):
        if source.startswith("/-", i):
            depth += 1
            i += 2
        elif depth and source.startswith("-/", i):
            depth -= 1
            i += 2
        elif depth:
            i += 1
        elif source.startswith("--", i):
            j = source.find("\n", i)
            i = len(source) if j == -1 else j
            out.append("\n")
        else:
            out.append(source[i])
            i += 1
    if depth:
        raise ValueError("Unclosed Lean comment")
    return "".join(out)


def validate(source, required):
    if not isinstance(source, str) or not 0 < len(source.encode()) <= 24000:
        raise ValueError("Lean body must contain at most 24000 UTF-8 bytes")
    code = strip_comments(source)
    if '"' in code:
        raise ValueError("Put prose in comments; executable strings are outside this contract")
    code = re.sub(r"^\s*set_option (maxRecDepth|maxHeartbeats) \d+\s*$", "", code, flags=re.M)
    if re.search(r"\bset_option\b", code):
        raise ValueError("Only maxRecDepth/maxHeartbeats options are available")
    if "VAS_" in code:
        raise ValueError("Names containing VAS_ are reserved for the checker's own report")
    bad = FORBIDDEN.search(code)
    if bad:
        raise ValueError(f"Outside the restricted Lean contract: {bad.group()}")
    if re.search(r"\b(?:def|abbrev|theorem|lemma|structure|inductive|class)\s+[^\s:(]+\.", code):
        raise ValueError("Declare plain top-level names; namespaces are outside this contract")
    theorems = re.findall(r"^\s*(?:theorem|lemma)\s+([A-Za-z_][A-Za-z_0-9']*)", code, re.M)
    missing = [n for n in required if n not in theorems]
    if missing:
        raise ValueError(f"Missing required theorems: {missing}")
    if re.search(r"\baxiom\b(?!\s+[A-Za-z_][A-Za-z_0-9']*\s*[:({\[])", code):
        raise ValueError("Declare an added assumption as `axiom name : statement` at the start of a line")
    return theorems


# Lean itself lists what the proof adds: every axiom declared in the file and every sorry (by its elaborated goal with
# the hypotheses in scope), each marked used when a conclusion theorem reaches it. Read from the checked kernel
# environment, as #print axioms does. Never part of an agent body (run_cmd is outside the contract).
LISTER = """
/-- true if `sorryAx` occurs anywhere other than as the head of an application that states its goal -/
private partial def VAS_unstated : Lean.Expr → Bool
  | e@(.app ..) =>
    let f := e.getAppFn
    (if f.isConstOf ``sorryAx then false else VAS_unstated f) || e.getAppArgs.any VAS_unstated
  | .const n _ => n == ``sorryAx
  | .lam _ t b _ | .forallE _ t b _ => VAS_unstated t || VAS_unstated b
  | .letE _ t v b _ => VAS_unstated t || VAS_unstated v || VAS_unstated b
  | .mdata _ b | .proj _ _ b => VAS_unstated b
  | _ => false

set_option format.width 100000 in
set_option pp.deepTerms true in
set_option pp.proofs true in
set_option pp.maxSteps 100000000 in
open Lean Elab Command Meta in
run_cmd do
  let kenv := (← getEnv).checked.get
  let locals := kenv.constants.map₂.toList
  let localSet : NameSet := locals.foldl (fun s (n, _) => s.insert n) {}
  let exprsOf (ci : ConstantInfo) : Array Expr :=
    #[ci.type] ++ (match ci with
      | .defnInfo v => #[v.value] | .thmInfo v => #[v.value] | .opaqueInfo v => #[v.value] | _ => #[])
  let mut used : NameSet := {}
  let mut todo : List Name := ROOTS
  while !todo.isEmpty do
    let n := todo.head!
    todo := todo.tail!
    if used.contains n then continue
    used := used.insert n
    if let some ci := kenv.find? n then
      for e in exprsOf ci do
        for c in e.getUsedConstants do
          if localSet.contains c && !used.contains c then todo := c :: todo
  for (n, ci) in locals do
    if let .axiomInfo _ := ci then
      logInfo m!"VAS_AXIOM {n} used={used.contains n} : {← liftTermElabM <| ppExpr ci.type} VAS_END"
    -- every declaration kind, type and value: a gap may sit in an axiom's type as well as in a proof
    for e in exprsOf ci do
      -- hasSorry is cached and linear; VAS_unstated walks the term as a tree, exponential on shared proofs
      if e.hasSorry && VAS_unstated e then
        logInfo m!"VAS_GAP {n} used={used.contains n} : (sorry with no stated goal: it can assert anything) VAS_END"
        logInfo m!"VAS_UNSTATED {n} used={used.contains n}"
    if (exprsOf ci).any (·.hasSorry) then
      let seen ← IO.mkRef ({} : Std.HashSet String)
      liftTermElabM do
        for e in exprsOf ci do
          forEachExpr' e fun sub => do
            if sub.isAppOf ``sorryAx && sub.getAppNumArgs ≥ 1 then
              let mut t ← instantiateMVars (sub.getArg! 0)
              if t.isForall && t.bindingDomain!.isConstOf ``Lean.Name then t := t.bindingBody!
              let hyps ← (← getLCtx).foldlM (init := m!"") fun acc d => do
                if d.isImplementationDetail then return acc
                match d.value? with
                | some v => return acc ++ m!"({d.userName} : {← ppExpr d.type} := {← ppExpr v}) "
                | none => return acc ++ m!"({d.userName} : {← ppExpr d.type}) "
              let line ← (m!"VAS_GAP {n} used={used.contains n} : {hyps}⊢ {← ppExpr t} VAS_END").toString
              unless (← seen.get).contains line do
                seen.modify (·.insert line)
                logInfo line
            return true
  logInfo "VAS_LISTED"
"""


def listed(text):
    """Parse the lister's output into added_assumptions entries; None if the lister did not finish."""
    if not re.search(r"^VAS_LISTED\s*$", text, re.M):  # the marker line itself, not a substring of other output
        return None
    out = []
    for kind, name, used, stmt in re.findall(r"VAS_(AXIOM|GAP) (\S+) used=(true|false) : (.*?) VAS_END", text, re.S):
        out.append({"kind": kind.lower(), "in" if kind == "GAP" else "name": name, "used": used == "true",
                    "statement": " ".join(stmt.split())})
    return out
LICENSE
LICENSES
bin
include
lib
share
src
web_search input
{
  "query": "https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf",
  "action": {
    "type": "open_page",
    "url": "https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf"
  }
}
web_search output
{
  "results": [
    {
      "type": "text_result",
      "domain": "people.stat.sc.edu",
      "ref_id": "turn2view0",
      "snippet": "Total lines: 325",
      "url": "https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf"
    }
  ]
}
assistant
The mean and standard deviation constrain the prior on the original black-ball count, but do not specify it. I’ll use the exact likelihood for sampling without replacement and prove that two priors with the supplied moments give different next-draw probabilities. This will establish why the answer is not unique and give the Bayesian formula conditional on a chosen prior.
shell input
{
  "command": "/usr/bin/bash -lc \"ls /harness/.lake/packages; ls /opt/lean/bin; sed -n '1,160p' /harness/src/vcs_protocol.py\""
}
shell output · exit 0
LeanSearchClient
Qq
aesop
batteries
importGraph
mathlib
plausible
proofwidgets
cadical
clang
con-leche
con-ron
lake
ld.lld
lean
lean4lean
leanc
leanchecker
leanchecker-paranoid
leanexport
leanir
leanmake
leantar
llvm-ar
nanoda_bin
"""Versioned, human-gated workflow for agent-written scientific Lean models.

Host control files never enter the scientist container. Container check results are
feedback only: host review always checks its own frozen snapshot independently.
"""
from __future__ import annotations

import hashlib
import json
import os
from pathlib import Path
import re
import shutil
import stat
import subprocess
import sys
import tempfile
import uuid
from datetime import datetime, timezone

import click

ROOT = Path(__file__).resolve().parents[1]
IMAGE = "sha256:c0e8df9380519cf514d5fbb5aeaa7aa5de5f32c50330badcadc05cdabaae5566"
CODEX_VERSION = "codex-cli 0.166.0"
NAME = re.compile(r"[A-Za-z_][A-Za-z_0-9']*")


def digest(path):
    return hashlib.sha256(Path(path).read_bytes()).hexdigest()


def directory_fd(path, create=False):
    """Walk from root without following links, even in an untrusted workspace."""
    path = Path(path).absolute()
    if ".." in path.parts:
        raise ValueError("directory traversal is unsupported")
    fd = os.open("/", os.O_RDONLY | os.O_DIRECTORY)
    try:
        for part in path.parts[1:]:
            if create:
                try:
                    os.mkdir(part, mode=0o700, dir_fd=fd)
                except FileExistsError:
                    pass
            child = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=fd)
            os.close(fd)
            fd = child
        return fd
    except BaseException:
        os.close(fd)
        raise


def ensure_directory(path):
    os.close(directory_fd(path, create=True))


def atomic_write(path, data):
    """Replace the directory entry; never open an existing target or predictable temp."""
    path = Path(path)
    parent = directory_fd(path.parent)
    temp = ".vcs-write-" + uuid.uuid4().hex
    try:
        try:
            existing = os.stat(path.name, dir_fd=parent, follow_symlinks=False)
        except FileNotFoundError:
            existing = None
        if existing is not None and stat.S_ISLNK(existing.st_mode):
            raise ValueError("refusing symlink write destination")
        fd = os.open(temp, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
                     0o600, dir_fd=parent)
        with os.fdopen(fd, "wb") as stream:
            stream.write(data)
        os.replace(temp, path.name, src_dir_fd=parent, dst_dir_fd=parent)
    finally:
        try:
            os.unlink(temp, dir_fd=parent)
        except FileNotFoundError:
            pass
        os.close(parent)


def write_json(path, value):
    atomic_write(path, (json.dumps(value, indent=2) + "\n").encode())


def read_json(path):
    return json.loads(Path(path).read_text())


def stamp():
    return datetime.now(timezone.utc).isoformat()


def inside(base, relative):
    """Reject traversal and symlinks, including intermediate directory links."""
    p = Path(relative)
    if p.is_absolute() or ".." in p.parts:
        raise ValueError("candidate paths must be relative without '..'")
    target = Path(base) / p
    for item in [target, *target.parents]:
        if item == Path(base).parent:
            break
        if item.is_symlink():
            raise ValueError("candidate paths may not contain symlinks")
    if not target.is_file():
        raise ValueError(f"missing candidate file: {relative}")
    return target


def load_candidate(work, manifest):
    manifest = inside(work, str(Path(manifest).relative_to(work)))
    m = read_json(manifest)
    conclusions = m.get("conclusions")
    if not isinstance(conclusions, dict) or not conclusions or not all(
            isinstance(label, str) and label.strip() for label in conclusions):
        raise ValueError("conclusions must be a nonempty mapping of labels to theorem names")
    names = list(conclusions.values())
    if not all(isinstance(n, str) and NAME.fullmatch(n) for n in names) or len(set(names)) != len(names):
        raise ValueError("distinct plain theorem names are required")
    for key in ["user_facts", "model_choices", "sources", "incorporated_inputs"]:
        if not isinstance(m.get(key), list) or not all(isinstance(s, str) for s in m[key]):
            raise ValueError(f"{key} must be a list of strings")
    if not m["user_facts"] or not m["model_choices"] or not isinstance(m.get("proof_scope"), str) or not m["proof_scope"].strip():
        raise ValueError("facts, choices and substantive proof_scope are required")
    return m, inside(work, m["proof_file"]), inside(work, m["narrative_file"])


def validate_source(source, names):
    """Fixed library trust base; reuse hardened no-metaprogramming body contract."""
    from vcs_lean import strip_comments, validate
    code = strip_comments(source)
    imports = re.findall(r"(?m)^import ([A-Za-z0-9_.]+)\s*$", code)
    if not imports or any(not n.startswith("Mathlib.") for n in imports):
        raise ValueError("explicit imports of pinned Mathlib modules only")
    body = re.sub(r"(?m)^import [A-Za-z0-9_.]+\s*$", "", code)
    validate(body, names)
    if re.search(r"\bconclusion_\w*", body):
        raise ValueError("conclusion_ names are reserved for independent extraction")
    # Extractor requires a colon immediately after the theorem name. Fail clearly.
    for n in names:
        if not re.search(r"(?m)^\s*(?:theorem|lemma)\s+" + re.escape(n) + r"\s*:", body):
            raise ValueError("conclusion binders must be inside the statement after ':'")


def verify_candidate(work, manifest, out):
    """Actually compile, audit axioms, recheck kernel and independently extract."""
    from vcs_lean import ALLOWED_AXIOMS, LISTER, listed
    from vcs_extract import run_lean, main as extract
    out = Path(out)
    out.mkdir(parents=True, exist_ok=True)
    result = {"ok": False, "check_complete": False, "reviewable": False, "verdict": "not_proved", "time": stamp()}
    try:
        m, proof, narrative = load_candidate(work, manifest)
        snapshot = out / "submitted.lean"
        snapshot.write_bytes(proof.read_bytes())
        (out / "submitted-report.txt").write_bytes(narrative.read_bytes())
        write_json(out / "submitted-candidate.json", m)
        proof = snapshot
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nimport sympy as s\nfrom math import comb\nfor ks in [(30,40,50),(25,35,45),(30,35,45),(25,37,50),(30,38,45),(32,38,43)]:\n w=s.symbols('w:3'); sol=s.solve([sum(w)-1,sum(p*k for p,k in zip(w,ks))-s.Rational(75,2),sum(p*(k-s.Rational(75,2))**2 for p,k in zip(w,ks))-25],w)\n if min(sol.values())>=0:\n  ps=[sol[x] for x in w]; den=sum(p*comb(k,10) for p,k in zip(ps,ks)); pred=sum(p*comb(k,10)*s.Rational(k-10,40) for p,k in zip(ps,ks))/den\n  print(ks,ps,pred,float(pred))\nPY\""
}
shell output · exit 1 · failed
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sympy'
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom fractions import Fraction as F\nfrom math import comb\nm=F(75,2)\nfor ks in [(30,40,50),(25,35,45),(30,35,45),(25,37,50),(30,38,45),(32,38,43)]:\n ps=[]\n for i,k in enumerate(ks):\n  a,b=[v for j,v in enumerate(ks) if i\"'!=j]\n  ps.append((25+(m-a)*(m-b))/((k-a)*(k-b)))\n if min(ps)>=0:\n  den=sum(p*comb(k,10) for p,k in zip(ps,ks)); pred=sum(p*comb(k,10)*F(k-10,40) for p,k in zip(ps,ks))/den\n  print(ks,ps,pred,float(pred))\nPY\nsed -n '\"'1,65p' /harness/src/vcs_extract.py; ls -la /harness/.lake/packages/mathlib | head -15\""
}
shell output · exit 0
(30, 40, 50) [Fraction(9, 32), Fraction(11, 16), Fraction(1, 32)] 4435250809/5307493622 0.8356582456577091
(25, 35, 45) [Fraction(1, 32), Fraction(11, 16), Fraction(9, 32)] 10053879039/11910436744 0.8441234570230802
(30, 35, 45) [Fraction(1, 12), Fraction(5, 8), Fraction(7, 24)] 9453213/11164432 0.8467258343281593
(25, 37, 50) [Fraction(1, 16), Fraction(175, 208), Fraction(5, 52)] 43113286/46581439 0.9255464606836212
(30, 38, 45) [Fraction(23, 96), Fraction(125, 224), Fraction(17, 84)] 30675364951/37331992534 0.8216910716207421
(32, 38, 43) [Fraction(37, 88), Fraction(7, 40), Fraction(89, 220)] 15410569177/19145987960 0.8048980919237975
"""Extract statement dependencies and conclusions; independently compile and compare."""
import hashlib
import json
import os
from pathlib import Path
import re
import subprocess
import tempfile
import sys

import click

ROOT = Path(__file__).resolve().parents[1]
from vcs_lean import LEAN, LEANCHECKER, LISTER, listed  # noqa: E402

# Display text omits implicit arguments, types and sometimes whole subterms.
# Compare the complete kernel expressions instead. Binder names and metadata do
# not affect meaning; remove them so source positions and fresh binder names do
# not make an otherwise identical extraction fail. All constants, universe
# levels, implicit arguments and binder information remain in the identity.
IDENTITY = """
private partial def VAS_identityExpr : Lean.Expr → Lean.Expr
  | .mdata _ value => VAS_identityExpr value
  | .app fn arg => .app (VAS_identityExpr fn) (VAS_identityExpr arg)
  | .lam _ typ body info => .lam .anonymous (VAS_identityExpr typ) (VAS_identityExpr body) info
  | .forallE _ typ body info => .forallE .anonymous (VAS_identityExpr typ) (VAS_identityExpr body) info
  | .letE _ typ value body flag => .letE .anonymous (VAS_identityExpr typ) (VAS_identityExpr value) (VAS_identityExpr body) flag
  | .proj owner idx value => .proj owner idx (VAS_identityExpr value)
  | value => value

private def VAS_declarationIdentity (ci : Lean.ConstantInfo) : String :=
  let kind := match ci with
    | .axiomInfo _ => "axiom"
    | .defnInfo _ => "definition"
    | .thmInfo _ => "theorem"
    | .opaqueInfo _ => "opaque"
    | .quotInfo _ => "quotient"
    | .inductInfo info => s!"inductive {info.numParams} {info.numIndices} {reprStr info.ctors}"
    | .ctorInfo info => s!"constructor {info.induct} {info.cidx} {info.numParams} {info.numFields}"
    | .recInfo info => s!"recursor {info.numParams} {info.numIndices} {info.numMotives} {info.numMinors}"
  let value := match ci.value? with
    | some body => reprStr (VAS_identityExpr body)
    | none => "no value"
  s!"{kind}|levels={reprStr ci.levelParams}|type={reprStr (VAS_identityExpr ci.type)}|value={value}"
"""

REACH = """
open Lean Elab Command Meta in
run_cmd do
  let kenv := (← getEnv).checked.get
  let localSet : NameSet := kenv.constants.map₂.toList.foldl (fun s (n, _) => s.insert n) {}
  -- statements only: from each conclusion's type, through definitions' types and values
  let mut seen : NameSet := {}
  let mut todo : List Name := []
  for t in TARGETS do
    let some ci := kenv.find? t | throwError m!"no theorem {t}"
    todo := ci.type.getUsedConstants.toList ++ todo
    logInfo m!"VAS_CONCLUSION {t} : {← liftTermElabM <| ppExpr ci.type} VAS_END"
    logInfo m!"VAS_ORIGINAL_IDENTITY {t} : {reprStr (VAS_identityExpr ci.type)} VAS_END"
  while !todo.isEmpty do
    let n := todo.head!
    todo := todo.tail!
    if seen.contains n || !localSet.contains n then continue
    seen := seen.insert n
    let some ci := kenv.find? n | continue
total 12
drwxr-xr-x  3 root root 4096 Nov 16 15:30 .
drwxr-xr-x 10 root root 4096 Nov 16 15:30 ..
drwxr-xr-x  3 root root 4096 Nov 16 15:30 .lake
shell input
{
  "command": "/usr/bin/bash -lc \"sed -n '85,125p' /harness/src/vcs_extract.py; find /harness/.lake/packages/mathlib/.lake -maxdepth 3 -type d | head -12; find /opt/lean -maxdepth 3 -name Mathlib | head\""
}
shell output · exit 0
COMPARE = """
set_option format.width 100000 in
open Lean Elab Command Meta in
run_cmd do
  for n in NAMES do
    let some ci := (← getEnv).find? n | throwError m!"no {n}"
    let some v := ci.value? | throwError m!"no value {n}"
    logInfo m!"VAS_EXTRACTED {n} : {← liftTermElabM <| ppExpr v} VAS_END"
    logInfo m!"VAS_EXTRACTED_IDENTITY {n} : {reprStr (VAS_identityExpr v)} VAS_END"
  for n in DEPENDENCIES do
    let some ci := (← getEnv).find? n | throwError m!"missing extracted dependency {n}"
    logInfo m!"VAS_EXTRACTED_DEPENDENCY_IDENTITY {n} : {VAS_declarationIdentity ci} VAS_END"
"""


def run_lean(path):
    """Lean, then leanchecker on the compiled module (OT-1861): a nonzero status if either fails."""
    libs = sorted((ROOT / ".lake/packages").glob("*/.lake/build/lib/lean"))
    env = dict(os.environ, LEAN_PATH=":".join(map(str, libs)), LEAN_NUM_THREADS="1")
    with tempfile.TemporaryDirectory(prefix="vcs-olean-") as build:
        r = subprocess.run([LEAN, "-j1", f"--root={Path(path).resolve().parent}", "-o", str(Path(build) / "VasExtract.olean"), str(path)], cwd=ROOT,
                           env=env, capture_output=True, text=True, timeout=900)
        if r.returncode != 0:
            return r.returncode, r.stdout + r.stderr
        c = subprocess.run([LEANCHECKER, "VasExtract"], cwd=ROOT, capture_output=True, text=True, timeout=900,
                           env=dict(env, LEAN_PATH=env["LEAN_PATH"] + ":" + build,
                                    PATH=str(Path(LEAN).parent) + ":" + env.get("PATH", "")))
        note = f"\nleanchecker exit {c.returncode}\n{(c.stdout + c.stderr)[-1500:]}\n"
        return (0 if c.returncode == 0 else 10), r.stdout + r.stderr + note


def expression_identities(text, marker):
    """Read complete expression records; duplicate/missing records fail closed."""
    records = re.findall(r"^" + re.escape(marker) + r" (\S+) : (.*?) VAS_END", text, re.M | re.S)
    result = {}
    for name, value in records:
        if name in result:
            raise ValueError(f"duplicate expression identity for {name}")
        result[name] = " ".join(value.split())
    return result

/harness/.lake/packages/mathlib/.lake
/harness/.lake/packages/mathlib/.lake/build
/harness/.lake/packages/mathlib/.lake/build/lib
/harness/.lake/packages/mathlib/.lake/build/lib/lean
shell input
{
  "command": "/usr/bin/bash -lc \"cat > /work/Model.lean <<'EOF'\nimport Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Tactic\n\nset_option maxRecDepth 4096\nset_option maxHeartbeats 4000000\n\n-- k is the original number of black balls. The supplied moments concern k/50.\ndef compatible (p : Fin 51 → ℝ) : Prop :=\n  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧\n  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧\n  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)\"'^2) = 1/100\n\n-- Under uniform draws without replacement, every n-subset is equally likely.\n-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.\ndef likelihood (n : ℕ) (k : Fin 51) : ℝ :=\n  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)\n\n-- Marginal probability of an all-black run of length n.\ndef evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=\n  ∑ k, p k * likelihood n k\n\n-- Bayes conditioning on the observed ten black draws.\ndef posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=\n  p k * likelihood 10 k / evidence p 10\n\n-- Given k and the observation, k-10 black balls remain among forty balls.\n-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.\ndef prediction (p : Fin 51 → ℝ) : ℝ :=\n  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40\n\nlemma observation_step : ∀ k : Fin 51,\n    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by\n  intro k\n  fin_cases k <;> norm_num [likelihood, Nat.choose]\n\nlemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by\n  intros n k\n  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)\n\nlemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by\n  intro k hk\n  fin_cases k <;> norm_num [likelihood, Nat.choose] at *\n\nlemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by\n  intro p hp\n  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=\n    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)\n  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)\n  by_contra h\n  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he\n  have hzero : ∀ k, p k * likelihood 10 k = 0 := by\n    intro k\n    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)\n  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by\n    intro k\n    by_cases hk : 10 ≤ k.val\n    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))\n      simp [pk]\n    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)\n      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)\n  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)\n  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by\n    rw [← Finset.sum_mul, hp.2.1]\n    ring\n  rw [hp.2.2.1, hs] at hb\n  norm_num at hb\n\n-- For every compatible prior, conditioning is well-defined, yields a probability\n-- distribution, satisfies Bayes'\"' update, and gives the next-draw prediction.\ntheorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →\n    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧\n    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧\n    prediction p = evidence p 11 / evidence p 10 := by\n  intro p hp\n  have he := evidence_positive p hp\n  have hn : evidence p 10 ≠ 0 := ne_of_gt he\n  refine ⟨?_, ?_, ?_, ?_⟩\n  · intro k\n    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)\n  · simp only [posterior, ← Finset.sum_div]\n    exact div_self hn\n  · intro k\n    exact div_mul_cancel₀ _ hn\n  · unfold prediction posterior\n    calc\n      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =\n          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by\n            apply Finset.sum_congr rfl\n            intro k _\n            ring\n      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by\n        simp_rw [observation_step]\n        rw [Finset.sum_div]\n      _ = evidence p 11 / evidence p 10 := rfl\nEOF\npython - <<'PY'\nimport os,subprocess,pathlib\nlibs=sorted(pathlib.Path('/harness/.lake/packages').glob('*/.lake/build/lib/lean'))\nenv=dict(os.environ,LEAN_PATH=':'.join(map(str,libs)))\nr=subprocess.run(['/opt/lean/bin/lean','/work/Model.lean'],env=env,capture_output=True,text=True)\npathlib.Path('/work/local-01.log').write_text(r.stdout+r.stderr)\nprint(r.returncode,r.stdout,r.stderr)\nPY\""
}
shell output · exit 0
1 /work/Model.lean:1:0: error: object file '/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic.olean' of module Mathlib.Tactic does not exist
 
shell input
{
  "command": "/usr/bin/bash -lc \"find /harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic -maxdepth 1 -name '*.olean' | head -80; find /harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib -maxdepth 3 -name '*Big*' -o -name '*Choose*'\""
}
shell output · exit 0
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/RenameBVar.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/PPWithUniv.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/TypeCheck.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Eval.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/PNatToNat.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ScopedNS.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ExtendDoc.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ApplyAt.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/TypeStar.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ByCases.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ToDual.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/SudoSetOption.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ContinuousFunctionalCalculus.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/HaveI.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Group.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Rename.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Says.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/BDSimp.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Basify.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Variable.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Change.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/GCongr.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/FailIfNoProgress.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ReduceModChar.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Algebraize.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/SuppressCompilation.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Order.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/MinImports.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Nontriviality.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/DSimpPercent.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/SuccessIfFailWithMsg.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Cases.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Qify.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/LinearCombination.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ProxyType.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Module.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ApplyCongr.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Measurability.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Common.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Eqns.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ExtractGoal.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/GrindAttrs.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ToLevel.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Ring.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ErwQuestion.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/MkIffOfInductiveProp.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/DeclarationNames.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Have.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ToFun.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/OfNat.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Contrapose.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/IntervalCases.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ComputeDegree.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Trace.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/TermCongr.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Spread.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/SimpRw.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/GuardGoalNums.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/CongrExclamation.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Set.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/SetNotationForOrder.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Clean.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Lemma.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Monotonicity.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Finiteness.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/ClearExclamation.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/CasesM.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/FieldSimp.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/FinCases.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormRank.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Zify.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/RSuffices.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Rify.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Hint.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/FastInstance.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Convert.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Assume.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/TFAE.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Peel.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/DFinsupp/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Nat/Choose
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Rat/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Ideal/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/Complex/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Basic/ENNReal/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/GroupTheory/Congruence/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/Choose.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Module/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Polynomial/BigOperators.ir.sig.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Order/BigOperators
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/BigOperators
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra/Star/BigOperators.ir.sig.hash
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\np=Path('/work/Model.lean')\ns=p.read_text().replace('import Mathlib.Tactic\\\\n','import Mathlib.Algebra.Order.BigOperators.Group.Finset\\\\nimport Mathlib.Algebra.BigOperators.Field\\\\nimport Mathlib.Tactic.NormNum\\\\nimport Mathlib.Tactic.FinCases\\\\nimport Mathlib.Tactic.Linarith\\\\nimport Mathlib.Tactic.Ring\\\\nimport Mathlib.Tactic.Positivity\\\\n')\np.write_text(s)\np=Path('/work/compile.py')\np.write_text('''import os, subprocess, pathlib, sys\nlibs=sorted(pathlib.Path('/harness/.lake/packages').glob('*/.lake/build/lib/lean'))\nenv=dict(os.environ,LEAN_PATH=':'.join(map(str,libs)))\nr=subprocess.run(['/opt/lean/bin/lean','/work/Model.lean'],env=env,capture_output=True,text=True)\npathlib.Path('/work/local-'+sys.argv[1]+'.log').write_text(r.stdout+r.stderr)\nprint(r.returncode,r.stdout,r.stderr)\n''')\nPY\npython /work/compile.py 02\""
}
shell input
{
  "command": "/usr/bin/bash -lc \"find /harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic/NormNum -maxdepth 1 -name '*.olean' | sed 's/.*\\\\///'\""
}
shell output · exit 0
DivMod.olean
NatFib.olean
PowMod.olean
Ineq.olean
RealSqrt.olean
IsSquare.olean
LegendreSymbol.olean
Result.olean
NatLog.olean
OfScientific.olean
NatSqrt.olean
Basic.olean
IsCoprime.olean
Irrational.olean
NatFactorial.olean
GCD.olean
Ordinal.olean
Eq.olean
Inv.olean
ModEq.olean
Core.olean
Parity.olean
Pow.olean
Abs.olean
Prime.olean
BigOperators.olean
assistant
The model treats the original count \(K\) as an integer from 0 to 50. Uniform sampling without replacement gives likelihood \(\binom K{10}/\binom{50}{10}\); after those draws, the next-black probability given \(K\) is \((K-10)/40\). I’m formalizing both the update and the ambiguity: two compatible priors give approximately 83.57% and 84.41%.
shell output · exit 0
1 /work/Model.lean:1:0: warning: 
'Mathlib.Data.Real.Basic' has been deprecated: please replace this import by

import Mathlib.Basic.Real.Basic
/work/Model.lean:22:4: error(lean.dependsOnNoncomputable): failed to compile definition, consider marking it as 'noncomputable' because it depends on 'Real.instDivInvMonoid', which is 'noncomputable'
/work/Model.lean:26:4: error(lean.dependsOnNoncomputable): failed to compile definition, consider marking it as 'noncomputable' because it depends on 'likelihood', which is 'noncomputable'
/work/Model.lean:30:4: error(lean.dependsOnNoncomputable): failed to compile definition, consider marking it as 'noncomputable' because it depends on 'Real.instDivInvMonoid', which is 'noncomputable'
/work/Model.lean:35:4: error(lean.dependsOnNoncomputable): failed to compile definition, consider marking it as 'noncomputable' because it depends on 'Real.instDivInvMonoid', which is 'noncomputable'
 
shell input
{
  "command": "/usr/bin/bash -lc 'ps -eo pid,etime,pcpu,args | head -15; ls -l /work'"
}
shell output · exit 0
/usr/bin/bash: line 1: ps: command not found
total 20
-rw-r--r-- 1 1001 1001 4301 Nov 16 15:33 Model.lean
-rw-r--r-- 1 1001 1001  389 Nov 16 15:33 compile.py
-rw-r--r-- 1 1001 1001  157 Nov 16 15:32 local-01.log
-rw-r--r-- 1 1001 1001  931 Nov 16 15:33 local-02.log
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\np=Path('/work/Model.lean')\ns=p.read_text().replace('import Mathlib.Data.Real.Basic','import Mathlib.Basic.Real.Basic')\nfor name in ['likelihood','evidence','posterior','prediction']:\n s=s.replace('def '+name+' ', 'noncomputable def '+name+' ')\np.write_text(s)\nPY\ncat >> /work/Model.lean <<'EOF'\n\n-- Two witnesses, rather than an inferred choice between them: the supplied\n-- population moments do not identify the requested posterior probability.\ntheorem moments_do_not_identify_answer :\n    ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧\n      prediction p = 4435250809/5307493622 ∧\n      prediction q = 10053879039/11910436744 ∧\n      prediction p ≠ prediction q := by\n  let p : Fin 51 → ℝ := fun k =>\n    (if k = 30 then 9/32 else 0) +\n    (if k = 40 then 11/16 else 0) +\n    (if k = 50 then 1/32 else 0)\n  let q : Fin 51 → ℝ := fun k =>\n    (if k = 25 then 1/32 else 0) +\n    (if k = 35 then 11/16 else 0) +\n    (if k = 45 then 9/32 else 0)\n  have sp : ∀ f : Fin 51 → ℝ, (∑ k, p k * f k) =\n      (9/32) * f 30 + (11/16) * f 40 + (1/32) * f 50 := by\n    intro f\n    simp [p, add_mul, ite_mul, Finset.sum_add_distrib]\n  have sq : ∀ f : Fin 51 → ℝ, (∑ k, q k * f k) =\n      (1/32) * f 25 + (11/16) * f 35 + (9/32) * f 45 := by\n    intro f\n    simp [q, add_mul, ite_mul, Finset.sum_add_distrib]\n  have hp : compatible p := by\n    refine ⟨?_, ?_, ?_, ?_⟩\n    · intro k\n      dsimp [p]\n      split_ifs <;> norm_num\n    · have h := sp (fun _ => 1)\n      norm_num at h ⊢\n      exact h\n    · rw [sp]\n      norm_num\n    · rw [sp]\n      norm_num\n  have hq : compatible q := by\n    refine ⟨?_, ?_, ?_, ?_⟩\n    · intro k\n      dsimp [q]\n      split_ifs <;> norm_num\n    · have h := sq (fun _ => 1)\n      norm_num at h ⊢\n      exact h\n    · rw [sq]\n      norm_num\n    · rw [sq]\n      norm_num\n  have ap : prediction p = 4435250809/5307493622 := by\n    rw [(bayesian_answer p hp).2.2.2]\n    unfold evidence\n    rw [sp, sp]\n    norm_num [likelihood, Nat.choose]\n  have aq : prediction q = 10053879039/11910436744 := by\n    rw [(bayesian_answer q hq).2.2.2]\n    unfold evidence\n    rw [sq, sq]\n    norm_num [likelihood, Nat.choose]\n  refine ⟨p, q, hp, hq, ap, aq, ?_⟩\n  rw [ap, aq]\n  norm_num\nEOF\npython /work/compile.py 03\""
}
shell output · exit 0
0  
shell input
{
  "command": "/usr/bin/bash -lc \"cp /work/Model.lean /work/Model-attempt-03.lean; cat > /work/report.txt <<'EOF'\nScientific answer and review packet — cycle 1\n\nThe supplied information does not identify a unique next-black probability.\nFor a specified prior p_k on the ORIGINAL count K, the answer is\n  P(next black | ten black) =\n    [sum_{k=0}\"'^{50} p_k choose(k,10) (k-10)/40]\n      / [sum_{k=0}''^{50} p_k choose(k,10)].\nTerms with k<10 have zero likelihood. Equivalently the answer is\n  [sum p_k choose(k,11)/choose(50,11)]\n    / [sum p_k choose(k,10)/choose(50,10)].\nTwo explicitly compatible priors yield respectively\n  4435250809/5307493622 = approximately 0.8356582457, and\n  10053879039/11910436744 = approximately 0.8441234570.\nThese are conditional examples, not bounds or estimates inferred uniquely from\nmoments. Neither prior is recommended as the true distribution of boxes.\n\nSupplied information\n* The box initially contained 50 balls, each black or white.\n* Ten draws were black, without replacement; 40 balls remain.\n* Across boxes of the same kind, the fraction initially black has mean 0.75\n  and standard deviation 0.1. The count in this box is unknown.\n\nAdditional scientific assumptions\n1. Treat the reported moments as exact population moments, rather than rounded\n   values or noisy estimates. There is no sample size or measurement uncertainty\n   supplied from which to estimate their uncertainty.\n2. Before observing the draws, this particular box is representative of the\n   stated population: p_k is its population distribution of original counts.\n   There is no further selection information about the box.\n3. Each draw selects uniformly among all remaining balls; colors do not change.\n   The fact of ten black draws is the entire observation used for updating.\n   Under this assumption the count of black balls in a sample is hypergeometric.\n4. No parametric shape for the population distribution is imposed. The family\n   is all categorical distributions on integer counts 0,...,50 satisfying the\n   supplied moments. A continuous prior directly on K/50 would not by itself\n   respect this finite grid. A beta distribution or a hierarchical beta-binomial\n   construction would impose additional, scientifically unprovided structure.\n\nNecessary definitions (all in Model.lean)\n* p : Fin 51 -> real numbers represents prior probabilities p_k.\n* compatible p states nonnegativity, sum p_k=1, mean of K/50=3/4 and\n  E[(K/50-3/4)''^2]=1/100. These are direct population moment constraints.\n* likelihood n k = choose(k,n)/choose(50,n) is the conditional probability that\n  all n sampled balls are black. There are choose(50,n) equiprobable n-subsets\n  and choose(k,n) subsets consisting only of black balls. This observation\n  model is assumed from the uniform sampling mechanism, not fitted to the data.\n* evidence p n is sum p_k likelihood(n,k), the marginal probability of that run.\n* posterior p k = p_k likelihood(10,k)/evidence(p,10), Bayes'\"' rule for the\n  observed event. This is finite-event conditioning, with no density approximation.\n* prediction p is the posterior average of (K-10)/40. Formal natural-number\n  subtraction truncates at zero for K<10, which cannot explain the observation.\n\nWhat is inferred, and what is undetermined\nThe population moments imply E[K]=50(3/4)=75/2 and Var(K)=50\"'^2/100=25.\nThey supply normalization and two moment constraints on 51 prior probabilities;\nthey do not determine the prior. The observed ten black draws multiply whatever\nprior is chosen by its exact hypergeometric likelihood. They do not specify a\npopulation prior'\"'s remaining shape. Additional population count frequencies,\na justified generative family, or additional substantive prior information would\nbe needed for a unique numeric answer. Further draws would supply additional\nlikelihood evidence but would still not uniquely determine the population prior.\n\nTo demonstrate the ambiguity construct, explicitly as extra support assumptions:\nA. K in {30,40,50}. The moment equations give weights {9/32,11/16,1/32}.\nB. K in {25,35,45}. The moment equations give weights {1/32,11/16,9/32}.\nThe weights are derived, rather than independently chosen parameters: for a\nthree-point support {a,b,c}, let m=75/2, v=25. Then\n  E[(K-b)(K-c)] = v+(m-b)(m-c) = w_a(a-b)(a-c),\nso w_a=[v+(m-b)(m-c)]/[(a-b)(a-c)], with the other two weights obtained by\npermutation. This uniquely solves the moment equations conditional on that\nsupport. The support choices are witnesses to non-identification, not something\nthe supplied observations identify. The proof verifies their exact moment\nconstraints and distinct Bayesian predictions. There has been no model revision\nfrom a failed numerical guess to a more convenient model.\n\nProved conclusions, with plain-language translations\nbayesian_answer:\n  For EVERY compatible prior, posterior probabilities are nonnegative, sum to\n  one, satisfy posterior(k)*evidence(10)=prior(k)*likelihood(10,k), and the\n  posterior next-black probability is evidence(11)/evidence(10).\n  Its proof derives positive evidence from the supplied mean (if all supported\n  counts were at most 9, the mean fraction could not be 3/4). No positive-evidence\n  premise is added for review. The intermediate observation_step proves the\n  exact depletion identity L_10(k)*(k-10)/40=L_11(k) for all 51 possible counts.\n  Thus the result covers the observation, conditioning and next draw, rather\n  than only numerical arithmetic.\nmoments_do_not_identify_answer:\n  There exist two compatible priors whose predictions are the two exact\n  fractions above and are unequal. The explicit witnesses are local to the\n  proof so that they do not become unnecessary global model assumptions.\n\nFormal scope and limitations\nThe finite probabilistic model is expressed by real-valued mass functions,\nlikelihoods and their sums, not by a separate measure-space construction of\nindividual ball orderings. The hypergeometric formula is the explicit scientific\nobservation-model definition; its link to physical drawing is justified by the\ncounting argument above and is subject to human review. The proof establishes\nBayesian consequences within that model. It cannot establish unbiased physical\ndrawing, population representativeness, or exactness of the supplied moments.\nNo added axioms and no sorry are intended. Standard library logical foundations\nare distinct from scientific assumptions. Compilation, extraction and kernel\nresults must be taken from the actual check feedback, not from this narrative.\nNo human acceptance is claimed.\n\nSources and lineage\nGeneral scientific literature consulted via Internet in this cycle:\nUniversity of South Carolina, STAT 509 Section 3.2 notes, pp. 10-11,\nhttps://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf\nThe notes identify sampling without replacement as hypergeometric and give the\nconditional-count formula. They supply no prior for this problem and no numeric\nanswer. The population data are from the user, not this source. No operator\nrequest was made and no external response ID was incorporated.\nThere were no files or earlier-run history in /work at the start of this cycle.\nLocal compilation traces are retained as local-01.log, local-02.log, etc.\nInitial technical failures were an unavailable umbrella tactic import and\nmissing noncomputable annotations for real division. These required import and\nannotation fixes, with no change to the model, assumptions or scientific claims.\nModel-attempt-03.lean preserves the first complete scientific candidate before\nsubsequent technical fixes, if any. Actual protocol check output is retained by\nthe harness in this run. Human review remains required.\nEOF\npython - <<'PY'\nimport json\nfrom pathlib import Path\nm={\n 'proof_file':'Model.lean','narrative_file':'report.txt',\n 'conclusions':{'conditional_bayesian_prediction':'bayesian_answer','nonidentification':'moments_do_not_identify_answer'},\n 'user_facts':['Initially 50 black-or-white balls; ten drawn were all black without replacement; forty remain.','Across same-kind boxes the original black fraction has mean 0.75 and standard deviation 0.1; original count in this box unknown.'],\n 'model_choices':['Reported moments are treated as exact population moments, not noisy or rounded estimates.','This box is representative of that population before its draws; there is no additional selection information.','Uniform draws without replacement, unchanged colors, and conditioning on the ten-black event alone give likelihood choose(K,n)/choose(50,n).','The prior family is all categorical laws on integer K in 0..50 with the reported moments; no additional shape is inferred. Two three-point support choices are local counterexample witnesses, not asserted population facts.'],\n 'sources':['User task, cycle 1: counts, observation and population moments.','General observation-model reference: University of South Carolina STAT 509 Section 3.2 notes, pp.10-11, https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf (consulted via Internet in this run; no task-specific prior or answer).'],\n 'incorporated_inputs':[],\n 'proof_scope':'Within the explicitly defined finite categorical/hypergeometric model, proves positive observation evidence, normalized nonnegative Bayesian posterior, Bayes update and posterior next-draw expectation equals evidence(11)/evidence(10), for every compatible real-valued prior. Constructs two exact same-moment priors with unequal predictions, proving non-identification. No claim that either witness is the actual prior. Scientific truth of representative sampling, uniform drawing and exact moments remains for human review; no human approval claimed.'}\nPath('/work/candidate.json').write_text(json.dumps(m,indent=2)+'\\\\n')\nPY\""
}
shell output · exit 0
assistant
The Lean file compiles locally. It proves the Bayesian update and prediction for every compatible prior, and constructs two priors with the stated moments and unequal predictions. I’ve written the assumptions and derivation for review; I’ll now run the required checker, including extraction and the separate kernel check.
shell input
{
  "command": "/usr/bin/bash -lc 'python /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json'"
}
shell input
{
  "command": "/usr/bin/bash -lc 'find /work -maxdepth 3 -type f'"
}
shell output · exit 0
/work/report.txt
/work/Model-attempt-03.lean
/work/local-02.log
/work/compile.py
/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted-report.txt
/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted-candidate.json
/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/lean.log
/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.probe.lean
/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted.lean
/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/Checked.lean
/work/Model.lean
/work/local-03.log
/work/candidate.json
/work/local-01.log
shell input
{
  "command": "/usr/bin/bash -lc 'cat /work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/lean.log'"
}
shell output · exit 0
'bayesian_answer' depends on axioms: [propext, Classical.choice, Quot.sound]
'moments_do_not_identify_answer' depends on axioms: [propext, Classical.choice, Quot.sound]
VAS_LISTED

leanchecker exit 0

shell output · exit 1 · failed
{
 "file": "/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted.lean",
 "conclusions": [
  "bayesian_answer",
  "moments_do_not_identify_answer"
 ],
 "lean_exit": 0,
 "ok": false,
 "compiles_alone": true,
 "faithful": {
  "bayesian_answer": true,
  "moments_do_not_identify_answer": false
 },
 "assumption_declarations": [
  "compatible",
  "likelihood",
  "evidence",
  "posterior",
  "prediction"
 ],
 "identity_method": "kernel-expression-repr-v1",
 "conclusion_identities": {
  "bayesian_answer": {
   "original_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585",
   "extracted_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585"
  },
  "moments_do_not_identify_answer": {
   "original_sha256": "3e0711fb331f13a80cd395bdb61eb450ec9d2d000af317f8d11ca45402079b1d",
   "extracted_sha256": "09f7f5f03e05e86fd6e910f9be8e5e88397ae092af95a44df9ffb07c9d830f1e"
  }
 },
 "dependency_faithful": {
  "compatible": true,
  "compatible._proof_1": true,
  "compatible._proof_2": true,
  "compatible._proof_3": true,
  "compatible._proof_4": true,
  "prediction": true,
  "posterior": true,
  "likelihood": true,
  "evidence": true,
  "prediction._proof_1": true
 },
 "dependency_identities": {
  "compatible": {
   "original_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7",
   "extracted_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7"
  },
  "compatible._proof_1": {
   "original_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52",
   "extracted_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52"
  },
  "compatible._proof_2": {
   "original_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1",
   "extracted_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1"
  },
  "compatible._proof_3": {
   "original_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2",
   "extracted_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2"
  },
  "compatible._proof_4": {
   "original_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472",
   "extracted_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472"
  },
  "prediction": {
   "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
   "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
  },
  "posterior": {
   "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
   "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
  },
  "likelihood": {
   "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
   "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
  },
  "evidence": {
   "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
   "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
  },
  "prediction._proof_1": {
   "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
   "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
  }
 },
 "unranged": [],
 "added_assumptions": [],
 "conclusions_as_proved": {
  "bayesian_answer": "\u2200 (p : Fin 51 \u2192 \u211d), compatible p \u2192 (\u2200 (k : Fin 51), 0 \u2264 posterior p k) \u2227 \u2211 k, posterior p k = 1 \u2227 (\u2200 (k : Fin 51), posterior p k * evidence p 10 = p k * likelihood 10 k) \u2227 prediction p = evidence p 11 / evidence p 10",
  "moments_do_not_identify_answer": "\u2203 p q, compatible p \u2227 compatible q \u2227 prediction p = 4435250809 / 5307493622 \u2227 prediction q = 10053879039 / 11910436744 \u2227 prediction p \u2260 prediction q"
 },
 "extracted_file": "/work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.lean",
 "errors": []
}
{
  "ok": false,
  "check_complete": false,
  "reviewable": false,
  "verdict": "not_proved",
  "time": "2026-11-16T15:35:44.565706+00:00",
  "lean_exit": 0,
  "error": "independent extraction failed"
}
assistant
The source proof passed compilation and its kernel check, but the independent extraction failed to reproduce the non-uniqueness theorem exactly. This check is therefore not a success. I’ll inspect the mismatch and adjust the statement’s spelling while preserving the model and scientific claim.
shell input
{
  "command": "/usr/bin/bash -lc 'ls -l /work/checks/d3b2ddd0289f4b9c92d67be787fe45dc; cat /work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.lean; cat /work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.probe.lean | head -55'"
}
shell output · exit 0
total 48
-rw-r--r-- 1 1001 1001 9556 Nov 16 15:35 Checked.lean
-rw-r--r-- 1 1001 1001 3998 Nov 16 15:36 extracted.json
-rw-r--r-- 1 1001 1001 1503 Nov 16 15:36 extracted.lean
-rw-r--r-- 1 1001 1001  201 Nov 16 15:36 lean.log
-rw------- 1 1001 1001 2017 Nov 16 15:35 submitted-candidate.json
-rw-r--r-- 1 1001 1001 7564 Nov 16 15:35 submitted-report.txt
-rw-r--r-- 1 1001 1001 6310 Nov 16 15:35 submitted.lean
-rw------- 1 1001 1001  203 Nov 16 15:36 verdict.json
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40


/-! Conclusions (statements of the proved theorems). -/
def conclusion_bayesian_answer : Prop := ∀ p : Fin 51 → ℝ, compatible p → (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧ (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧ prediction p = evidence p 11 / evidence p 10
def conclusion_moments_do_not_identify_answer : Prop := ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧ prediction p = 4435250809/5307493622 ∧ prediction q = 10053879039/11910436744 ∧ prediction p ≠ prediction q
cat: /work/checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.probe.lean: No such file or directory
shell input
{
  "command": "/usr/bin/bash -lc \"sed -n '125,310p' /harness/src/vcs_extract.py\""
}
shell output · exit 0

def statement_text(lines, start, name):
    """The source of theorem `name`'s statement: from after `name :` to the `:=` that opens its proof."""
    text = "\n".join(lines[start - 1:])
    m = re.match(r"\s*(?:theorem|lemma)\s+" + re.escape(name) + r"\s*:(.*?):=", text, re.S)
    if not m:
        raise ValueError(f"cannot read the statement of {name}")
    return " ".join(m.group(1).split())


@click.command()
@click.argument("lean_file", type=click.Path(exists=True, dir_okay=False))
@click.option("--theorem", "theorems", multiple=True, required=True, help="a conclusion theorem (repeatable)")
@click.option("--out", "out_stem", required=True, help="output stem: writes <out>.lean and <out>.json")
def main(lean_file, theorems, out_stem):
    src = Path(lean_file).read_text()
    lines = src.splitlines()
    out = Path(out_stem)
    probe = out.with_name(out.name + ".probe.lean")
    targets = "[" + ", ".join(f"``{t}" for t in theorems) + "]"
    body = re.sub(r"(?m)^#print axioms.*\n?", "", src)
    # a file written by the current checker already ends with its own LISTER; drop it, the probe appends one
    head = next(ln for ln in LISTER.splitlines() if ln.strip())
    if head in body:
        body = body[:body.index(head)]
    probe.write_text(body + "\nset_option format.width 100000\n" + IDENTITY + REACH.replace("TARGETS", targets)
                     + LISTER.replace("ROOTS", targets))
    status, text = run_lean(probe)
    report = {"file": lean_file, "conclusions": list(theorems), "lean_exit": status}
    if status != 0 or "VAS_REACHED" not in text:
        report |= {"ok": False, "error": "the source did not compile with the extractor",
                   "errors": [ln for ln in text.splitlines() if ": error" in ln][:5]}
        print(json.dumps(report, indent=1))
        sys.exit(1)
    decls = {}
    for name, a, b in re.findall(r"VAS_DECL (\S+) (\d+) (\d+)", text):
        decls[name] = (int(a), int(b))
    unranged = re.findall(r"VAS_UNRANGED (\S+)", text)
    concl = dict(re.findall(r"VAS_CONCLUSION (\S+) : (.*?) VAS_END", text, re.S))
    original_identities = expression_identities(text, "VAS_ORIGINAL_IDENTITY")
    dependency_identities = expression_identities(text, "VAS_DEPENDENCY_IDENTITY")
    added = [a for a in listed(text) or [] if a["used"]]
    # the extracted file: imports, then each assumption's source in file order, inside its namespace. A range
    # inside another one (a structure's fields and constructor) is part of it and is not copied twice.
    imports = [ln for ln in lines if ln.startswith("import ")]
    spans = sorted(set(decls.values()))
    keep = [s for s in spans if not any(o != s and o[0] <= s[0] and s[1] <= o[1] for o in spans)]
    for x, y in zip(keep, keep[1:]):
        if y[0] <= x[1]:
            raise ValueError(f"overlapping declaration ranges {x} and {y}")
    owner = {}
    for name, rng in decls.items():
        if rng in keep and (rng not in owner or len(name) < len(owner[rng])):
            owner[rng] = name
    head = re.compile(r"^\s*(?:@\[[^\]]*\]\s*)?(?:noncomputable\s+|private\s+|protected\s+)*"
                      r"(?:def|theorem|lemma|abbrev|structure|inductive|class|axiom|instance|opaque)\s+([^\s:({\[]+)")
    # top-level `open X` lines of the source go along, in file order, so names resolve as they did there
    opens = [(i + 1, i + 1) for i, ln in enumerate(lines)
             if re.match(r"open\s+[\w.]+(\s+[\w.]+)*\s*$", ln) and not any(a <= i + 1 <= b for a, b in keep)]
    parts, current = [], None
    for rng in sorted(keep + opens):
        a, b = rng
        if rng in opens and rng not in owner:
            if current:
                parts.append(f"end {current}\n")
                current = None
            parts.append(lines[a - 1])
            continue
        name = owner[rng]
        short = next((m.group(1) for ln in lines[a - 1:b] if (m := head.match(ln))), None)
        if short is None or not (name == short or name.endswith("." + short)):
            raise ValueError(f"cannot match the source of {name} at lines {a}-{b}")
        ns = name[: -len(short) - 1] if name != short else ""
        if ns != current:
            if current:
                parts.append(f"end {current}\n")
            if ns:
                parts.append(f"namespace {ns}")
            current = ns
        parts.append("\n".join(lines[a - 1:b]) + "\n")
    if current:
        parts.append(f"end {current}\n")
    starts = {}
    for t in theorems:
        m = re.search(r"(?m)^\s*(?:theorem|lemma)\s+" + re.escape(t) + r"\b", src)
        starts[t] = src[:m.start()].count("\n") + 1 if m else None
    stmts = {t: statement_text(lines, starts[t], t) for t in theorems}
    conclusions = "".join(f"def conclusion_{t} : Prop := {stmts[t]}\n" for t in theorems)
    extracted = ("\n".join(imports) + "\n\n" + "\n".join(parts) + "\n\n"
                 "/-! Conclusions (statements of the proved theorems). -/\n" + conclusions)
    out.with_suffix(".lean").write_text(extracted)
    # step 5: the extracted file compiles alone, and its conclusions are the proved statements
    check = out.with_name(out.name + ".check.lean")
    names = "[" + ", ".join(f"``conclusion_{t}" for t in theorems) + "]"
    dependencies = "[" + ", ".join(f"``{name}" for name in dependency_identities) + "]"
    check.write_text(extracted + IDENTITY + COMPARE.replace("NAMES", names).replace("DEPENDENCIES", dependencies))
    status2, text2 = run_lean(check)
    extracted_identities = expression_identities(text2, "VAS_EXTRACTED_IDENTITY")
    same = {t: bool(original_identities.get(t)) and
            original_identities[t] == extracted_identities.get("conclusion_" + t)
            for t in theorems}
    extracted_dependencies = expression_identities(text2, "VAS_EXTRACTED_DEPENDENCY_IDENTITY")
    dependencies_same = {name: value == extracted_dependencies.get(name)
                         for name, value in dependency_identities.items()}
    identity_hashes = {
        t: {"original_sha256": hashlib.sha256(original_identities[t].encode()).hexdigest()
            if t in original_identities else None,
            "extracted_sha256": hashlib.sha256(extracted_identities["conclusion_" + t].encode()).hexdigest()
            if "conclusion_" + t in extracted_identities else None}
        for t in theorems}
    dependency_hashes = {
        name: {"original_sha256": hashlib.sha256(value.encode()).hexdigest(),
               "extracted_sha256": hashlib.sha256(extracted_dependencies[name].encode()).hexdigest()
               if name in extracted_dependencies else None}
        for name, value in dependency_identities.items()}
    report |= {"ok": status2 == 0 and all(same.values()) and all(dependencies_same.values())
               and set(dependency_identities) == set(extracted_dependencies) and not unranged,
               "compiles_alone": status2 == 0,
               "faithful": same, "assumption_declarations": [owner[r] for r in keep],
               "identity_method": "kernel-expression-repr-v1", "conclusion_identities": identity_hashes,
               "dependency_faithful": dependencies_same, "dependency_identities": dependency_hashes,
               "unranged": unranged, "added_assumptions": added,
               "conclusions_as_proved": {t: " ".join(concl[t].split()) for t in theorems},
               "extracted_file": str(out.with_suffix(".lean")),
               "errors": [ln for ln in text2.splitlines() if ": error" in ln][:5]}
    out.with_suffix(".json").write_text(json.dumps(report, indent=1))
    probe.unlink()
    check.unlink()
    print(json.dumps(report, indent=1))
    sys.exit(0 if report["ok"] else 1)


if __name__ == "__main__":
    main()
shell input
{
  "command": "/usr/bin/bash -lc \"cat > /work/diagnose.py <<'PY'\nimport sys,pathlib\nsys.path.insert(0,'/harness/src')\nimport vcs_extract as v\nroot=pathlib.Path('/work')\nt='moments_do_not_identify_answer'\nfor which,src,tail in [\n ('original',(root/'Model.lean').read_text(),v.REACH.replace('TARGETS','[\"'``'\"'+t+']')),\n ('extracted',(root/'checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.lean').read_text(),v.COMPARE.replace('NAMES','[\"'``conclusion_'\"'+t+']').replace('DEPENDENCIES','[]'))]:\n path=root/('diagnostic-'+which+'.lean')\n path.write_text(src+'\\\\n'+v.IDENTITY+tail)\n status,out=v.run_lean(path)\n (root/('diagnostic-'+which+'.log')).write_text(out)\n print(which,status)\n if which=='original':\n  a=v.expression_identities(out,'VAS_ORIGINAL_IDENTITY')[t]\n else:\n  b=v.expression_identities(out,'VAS_EXTRACTED_IDENTITY')['conclusion_'+t]\nimport difflib\n(root/'identity-diff.txt').write_text('\\\\n'.join(difflib.ndiff(a.split(', '),b.split(', '))))\nprint('original length',len(a),'extracted',len(b))\nprint('\\\\n'.join(x for x in difflib.ndiff(a.split(', '),b.split(', ')) if x.startswith(('- ','+ ','? '))))\nPY\npython /work/diagnose.py\""
}
shell output · exit 0
original 0
extracted 0
original length 8336 extracted 5888
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4435250809))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4435250809))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 4435250808))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 4435250808))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 4435250807))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 4435250807))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 5307493622))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 5307493622))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 5307493621))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 5307493621))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 5307493620))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 5307493620))))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `And []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Eq [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.bvar 0))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4435250809))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4435250809))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_moments_do_not_identify_answer._proof_1 [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 5307493622))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 5307493622))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_moments_do_not_identify_answer._proof_2 [])))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `And []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Eq [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.bvar 0))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 10053879039))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 10053879039))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 10053879038))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 10053879038))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 10053879037))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 10053879037))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 11910436744))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 11910436744))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 11910436743))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 11910436743))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 11910436742))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 11910436742))))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Ne [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.bvar 1))) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.bvar 0))))))) (Lean.BinderInfo.default))) (Lean.BinderInfo.default))
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 10053879039))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 10053879039))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_moments_do_not_identify_answer._proof_3 [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 11910436744))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 11910436744))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_moments_do_not_identify_answer._proof_4 [])))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Ne [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.bvar 1))) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.bvar 0))))))) (Lean.BinderInfo.default))) (Lean.BinderInfo.default))
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\np=Path('/work/Model.lean')\ns=p.read_text()\nfor n in ['4435250809','5307493622','10053879039','11910436744']:\n s=s.replace(n,'(('+n+' : ℕ) : ℝ)')\np.write_text(s)\np=Path('/work/report.txt')\ns=p.read_text()+'''\\\\nActual check lineage, first submission:\\\\nchecks/d3b2ddd0289f4b9c92d67be787fe45dc/verdict.json reports\\\\nnot_proved because independent extraction failed. Compilation and leanchecker\\\\nboth succeeded, with no added axioms or sorry; the first conclusion and every\\\\nmodel definition extracted faithfully. The second conclusion's large real\\\\nnumerals elaborated with inline typeclass proofs in the theorem and generated\\\\nproof constants in the extracted definition. The independent checker compares\\\\nexact expressions, so this was a real extraction failure despite equal\\\\nmathematical meaning. Raw diagnostic-original.log, diagnostic-extracted.log\\\\nand identity-diff.txt record the discrepancy using the harness's own identity\\\\nroutines. The revised source spells the same four large integers as explicit\\\\nnatural-number-to-real casts to avoid that elaboration difference. The values,\\\\nscientific assumptions, theorem content and proof scope are unchanged.\\\\nThe first failure remains a failure; use the subsequent check result to assess\\\\nthe revised candidate.\\\\n'''\np.write_text(s)\nPY\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json\""
}
assistant
The mismatch came from how Lean represented the four large numeric constants in the extracted statement. I’ve rewritten them as explicit natural-number-to-real casts and rerun the checker. The probability values, assumptions, and scientific claim are unchanged; the failed check and diagnostic traces are preserved.
shell output · exit 0
{
 "file": "/work/checks/589b8c8ad6124887b939666f670c9191/submitted.lean",
 "conclusions": [
  "bayesian_answer",
  "moments_do_not_identify_answer"
 ],
 "lean_exit": 0,
 "ok": true,
 "compiles_alone": true,
 "faithful": {
  "bayesian_answer": true,
  "moments_do_not_identify_answer": true
 },
 "assumption_declarations": [
  "compatible",
  "likelihood",
  "evidence",
  "posterior",
  "prediction"
 ],
 "identity_method": "kernel-expression-repr-v1",
 "conclusion_identities": {
  "bayesian_answer": {
   "original_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585",
   "extracted_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585"
  },
  "moments_do_not_identify_answer": {
   "original_sha256": "8b53d298f5f1e2d1b615a9d19d1275c2648305e06659b9780deee0e46f085f1f",
   "extracted_sha256": "8b53d298f5f1e2d1b615a9d19d1275c2648305e06659b9780deee0e46f085f1f"
  }
 },
 "dependency_faithful": {
  "compatible": true,
  "compatible._proof_1": true,
  "compatible._proof_2": true,
  "compatible._proof_3": true,
  "compatible._proof_4": true,
  "prediction": true,
  "posterior": true,
  "likelihood": true,
  "evidence": true,
  "prediction._proof_1": true
 },
 "dependency_identities": {
  "compatible": {
   "original_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7",
   "extracted_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7"
  },
  "compatible._proof_1": {
   "original_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52",
   "extracted_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52"
  },
  "compatible._proof_2": {
   "original_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1",
   "extracted_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1"
  },
  "compatible._proof_3": {
   "original_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2",
   "extracted_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2"
  },
  "compatible._proof_4": {
   "original_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472",
   "extracted_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472"
  },
  "prediction": {
   "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
   "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
  },
  "posterior": {
   "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
   "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
  },
  "likelihood": {
   "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
   "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
  },
  "evidence": {
   "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
   "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
  },
  "prediction._proof_1": {
   "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
   "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
  }
 },
 "unranged": [],
 "added_assumptions": [],
 "conclusions_as_proved": {
  "bayesian_answer": "\u2200 (p : Fin 51 \u2192 \u211d), compatible p \u2192 (\u2200 (k : Fin 51), 0 \u2264 posterior p k) \u2227 \u2211 k, posterior p k = 1 \u2227 (\u2200 (k : Fin 51), posterior p k * evidence p 10 = p k * likelihood 10 k) \u2227 prediction p = evidence p 11 / evidence p 10",
  "moments_do_not_identify_answer": "\u2203 p q, compatible p \u2227 compatible q \u2227 prediction p = \u21914435250809 / \u21915307493622 \u2227 prediction q = \u219110053879039 / \u219111910436744 \u2227 prediction p \u2260 prediction q"
 },
 "extracted_file": "/work/checks/589b8c8ad6124887b939666f670c9191/extracted.lean",
 "errors": []
}
{
  "ok": true,
  "check_complete": true,
  "reviewable": true,
  "verdict": "proved",
  "time": "2026-11-16T15:38:27.280903+00:00",
  "lean_exit": 0,
  "added_assumptions": [],
  "conditional_on": [],
  "extraction": {
    "file": "/work/checks/589b8c8ad6124887b939666f670c9191/submitted.lean",
    "conclusions": [
      "bayesian_answer",
      "moments_do_not_identify_answer"
    ],
    "lean_exit": 0,
    "ok": true,
    "compiles_alone": true,
    "faithful": {
      "bayesian_answer": true,
      "moments_do_not_identify_answer": true
    },
    "assumption_declarations": [
      "compatible",
      "likelihood",
      "evidence",
      "posterior",
      "prediction"
    ],
    "identity_method": "kernel-expression-repr-v1",
    "conclusion_identities": {
      "bayesian_answer": {
        "original_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585",
        "extracted_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585"
      },
      "moments_do_not_identify_answer": {
        "original_sha256": "8b53d298f5f1e2d1b615a9d19d1275c2648305e06659b9780deee0e46f085f1f",
        "extracted_sha256": "8b53d298f5f1e2d1b615a9d19d1275c2648305e06659b9780deee0e46f085f1f"
      }
    },
    "dependency_faithful": {
      "compatible": true,
      "compatible._proof_1": true,
      "compatible._proof_2": true,
      "compatible._proof_3": true,
      "compatible._proof_4": true,
      "prediction": true,
      "posterior": true,
      "likelihood": true,
      "evidence": true,
      "prediction._proof_1": true
    },
    "dependency_identities": {
      "compatible": {
        "original_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7",
        "extracted_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7"
      },
      "compatible._proof_1": {
        "original_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52",
        "extracted_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52"
      },
      "compatible._proof_2": {
        "original_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1",
        "extracted_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1"
      },
      "compatible._proof_3": {
        "original_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2",
        "extracted_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2"
      },
      "compatible._proof_4": {
        "original_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472",
        "extracted_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472"
      },
      "prediction": {
        "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
        "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
      },
      "posterior": {
        "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
        "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
      },
      "likelihood": {
        "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
        "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
      },
      "evidence": {
        "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
        "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
      },
      "prediction._proof_1": {
        "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
        "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
      }
    },
    "unranged": [],
    "added_assumptions": [],
    "conclusions_as_proved": {
      "bayesian_answer": "\u2200 (p : Fin 51 \u2192 \u211d), compatible p \u2192 (\u2200 (k : Fin 51), 0 \u2264 posterior p k) \u2227 \u2211 k, posterior p k = 1 \u2227 (\u2200 (k : Fin 51), posterior p k * evidence p 10 = p k * likelihood 10 k) \u2227 prediction p = evidence p 11 / evidence p 10",
      "moments_do_not_identify_answer": "\u2203 p q, compatible p \u2227 compatible q \u2227 prediction p = \u21914435250809 / \u21915307493622 \u2227 prediction q = \u219110053879039 / \u219111910436744 \u2227 prediction p \u2260 prediction q"
    },
    "extracted_file": "/work/checks/589b8c8ad6124887b939666f670c9191/extracted.lean",
    "errors": []
  },
  "scientific_relevance": "requires human review"
}
assistant
**The supplied moments do not determine a unique probability.**

Assuming your box represents that population and draws are uniform without replacement, let \(p_k\) be the prior probability of initially having \(k\) black balls. Using the [hypergeometric sampling model](https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf), the answer is

\[
\frac{\sum_{k=10}^{50}p_k\binom{k}{10}(k-10)/40}
{\sum_{k=10}^{50}p_k\binom{k}{10}}.
\]

For example, these two priors both have the supplied mean and standard deviation:

| Initial black counts | Respective prior probabilities | Next-black probability |
|---|---|---|
| 30, 40, 50 | 9/32, 11/16, 1/32 | **83.5658%** |
| 25, 35, 45 | 1/32, 11/16, 9/32 | **84.4123%** |

These are conditional examples, not bounds. A unique numeric answer requires further prior information.

The [Lean proof](/work/Model.lean), [scientific report](/work/report.txt), and [manifest](/work/candidate.json) are ready. The revised candidate passed compilation, independent extraction, and kernel checking, with no added axioms or `sorry`. Scientific validity remains for human review; no approval is claimed.

Produced code

attempt-001/Model.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl

-- Two witnesses, rather than an inferred choice between them: the supplied
-- population moments do not identify the requested posterior probability.
theorem moments_do_not_identify_answer :
    ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧
      prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) ∧
      prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) ∧
      prediction p ≠ prediction q := by
  let p : Fin 51 → ℝ := fun k =>
    (if k = 30 then 9/32 else 0) +
    (if k = 40 then 11/16 else 0) +
    (if k = 50 then 1/32 else 0)
  let q : Fin 51 → ℝ := fun k =>
    (if k = 25 then 1/32 else 0) +
    (if k = 35 then 11/16 else 0) +
    (if k = 45 then 9/32 else 0)
  have sp : ∀ f : Fin 51 → ℝ, (∑ k, p k * f k) =
      (9/32) * f 30 + (11/16) * f 40 + (1/32) * f 50 := by
    intro f
    simp [p, add_mul, ite_mul, Finset.sum_add_distrib]
  have sq : ∀ f : Fin 51 → ℝ, (∑ k, q k * f k) =
      (1/32) * f 25 + (11/16) * f 35 + (9/32) * f 45 := by
    intro f
    simp [q, add_mul, ite_mul, Finset.sum_add_distrib]
  have hp : compatible p := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [p]
      split_ifs <;> norm_num
    · have h := sp (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sp]
      norm_num
    · rw [sp]
      norm_num
  have hq : compatible q := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [q]
      split_ifs <;> norm_num
    · have h := sq (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sq]
      norm_num
    · rw [sq]
      norm_num
  have ap : prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) := by
    rw [(bayesian_answer p hp).2.2.2]
    unfold evidence
    rw [sp, sp]
    norm_num [likelihood, Nat.choose]
  have aq : prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) := by
    rw [(bayesian_answer q hq).2.2.2]
    unfold evidence
    rw [sq, sq]
    norm_num [likelihood, Nat.choose]
  refine ⟨p, q, hp, hq, ap, aq, ?_⟩
  rw [ap, aq]
  norm_num
attempt-001/extracted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40


/-! Conclusions (statements of the proved theorems). -/
def conclusion_bayesian_answer : Prop := ∀ p : Fin 51 → ℝ, compatible p → (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧ (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧ prediction p = evidence p 11 / evidence p 10
def conclusion_moments_do_not_identify_answer : Prop := ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧ prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) ∧ prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) ∧ prediction p ≠ prediction q
checks/589b8c8ad6124887b939666f670c9191/submitted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl

-- Two witnesses, rather than an inferred choice between them: the supplied
-- population moments do not identify the requested posterior probability.
theorem moments_do_not_identify_answer :
    ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧
      prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) ∧
      prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) ∧
      prediction p ≠ prediction q := by
  let p : Fin 51 → ℝ := fun k =>
    (if k = 30 then 9/32 else 0) +
    (if k = 40 then 11/16 else 0) +
    (if k = 50 then 1/32 else 0)
  let q : Fin 51 → ℝ := fun k =>
    (if k = 25 then 1/32 else 0) +
    (if k = 35 then 11/16 else 0) +
    (if k = 45 then 9/32 else 0)
  have sp : ∀ f : Fin 51 → ℝ, (∑ k, p k * f k) =
      (9/32) * f 30 + (11/16) * f 40 + (1/32) * f 50 := by
    intro f
    simp [p, add_mul, ite_mul, Finset.sum_add_distrib]
  have sq : ∀ f : Fin 51 → ℝ, (∑ k, q k * f k) =
      (1/32) * f 25 + (11/16) * f 35 + (9/32) * f 45 := by
    intro f
    simp [q, add_mul, ite_mul, Finset.sum_add_distrib]
  have hp : compatible p := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [p]
      split_ifs <;> norm_num
    · have h := sp (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sp]
      norm_num
    · rw [sp]
      norm_num
  have hq : compatible q := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [q]
      split_ifs <;> norm_num
    · have h := sq (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sq]
      norm_num
    · rw [sq]
      norm_num
  have ap : prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) := by
    rw [(bayesian_answer p hp).2.2.2]
    unfold evidence
    rw [sp, sp]
    norm_num [likelihood, Nat.choose]
  have aq : prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) := by
    rw [(bayesian_answer q hq).2.2.2]
    unfold evidence
    rw [sq, sq]
    norm_num [likelihood, Nat.choose]
  refine ⟨p, q, hp, hq, ap, aq, ?_⟩
  rw [ap, aq]
  norm_num
checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl

-- Two witnesses, rather than an inferred choice between them: the supplied
-- population moments do not identify the requested posterior probability.
theorem moments_do_not_identify_answer :
    ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧
      prediction p = 4435250809/5307493622 ∧
      prediction q = 10053879039/11910436744 ∧
      prediction p ≠ prediction q := by
  let p : Fin 51 → ℝ := fun k =>
    (if k = 30 then 9/32 else 0) +
    (if k = 40 then 11/16 else 0) +
    (if k = 50 then 1/32 else 0)
  let q : Fin 51 → ℝ := fun k =>
    (if k = 25 then 1/32 else 0) +
    (if k = 35 then 11/16 else 0) +
    (if k = 45 then 9/32 else 0)
  have sp : ∀ f : Fin 51 → ℝ, (∑ k, p k * f k) =
      (9/32) * f 30 + (11/16) * f 40 + (1/32) * f 50 := by
    intro f
    simp [p, add_mul, ite_mul, Finset.sum_add_distrib]
  have sq : ∀ f : Fin 51 → ℝ, (∑ k, q k * f k) =
      (1/32) * f 25 + (11/16) * f 35 + (9/32) * f 45 := by
    intro f
    simp [q, add_mul, ite_mul, Finset.sum_add_distrib]
  have hp : compatible p := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [p]
      split_ifs <;> norm_num
    · have h := sp (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sp]
      norm_num
    · rw [sp]
      norm_num
  have hq : compatible q := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [q]
      split_ifs <;> norm_num
    · have h := sq (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sq]
      norm_num
    · rw [sq]
      norm_num
  have ap : prediction p = 4435250809/5307493622 := by
    rw [(bayesian_answer p hp).2.2.2]
    unfold evidence
    rw [sp, sp]
    norm_num [likelihood, Nat.choose]
  have aq : prediction q = 10053879039/11910436744 := by
    rw [(bayesian_answer q hq).2.2.2]
    unfold evidence
    rw [sq, sq]
    norm_num [likelihood, Nat.choose]
  refine ⟨p, q, hp, hq, ap, aq, ?_⟩
  rw [ap, aq]
  norm_num

Round 2

Messages

assistant
I’ll review the previous candidate and check feedback, then build a usable conditional prediction with model parameters derived from the supplied moments.
shell input
{
  "command": "/usr/bin/bash -lc 'ls -la /work && rg --files /work /harness | head -80'"
}
shell output · exit 0
total 180
drwxrwxr-x 3 1001 1001  4096 Nov 16 16:02 .
drwxr-xr-x 1 root root  4096 Nov 16 16:02 ..
-rw-r--r-- 1 1001 1001  6310 Nov 16 15:35 Model-attempt-03.lean
-rw-r--r-- 1 1001 1001  6438 Nov 16 15:38 Model.lean
-rw-r--r-- 1 1001 1001  2017 Nov 16 15:35 candidate.json
drwxr-xr-x 4 1001 1001  4096 Nov 16 15:38 checks
-rw-r--r-- 1 1001 1001   389 Nov 16 15:33 compile.py
-rw-r--r-- 1 1001 1001  1038 Nov 16 15:37 diagnose.py
-rw-r--r-- 1 1001 1001  3494 Nov 16 15:37 diagnostic-extracted.lean
-rw-r--r-- 1 1001 1001  9520 Nov 16 15:38 diagnostic-extracted.log
-rw-r--r-- 1 1001 1001  9427 Nov 16 15:37 diagnostic-original.lean
-rw-r--r-- 1 1001 1001 68047 Nov 16 15:37 diagnostic-original.log
-rw------- 1 1001 1001   969 Nov 16 16:02 human-feedback.json
-rw-r--r-- 1 1001 1001 11739 Nov 16 15:38 identity-diff.txt
-rw------- 1 1001 1001  8192 Nov 16 15:40 last-review-packet.json
-rw-r--r-- 1 1001 1001   157 Nov 16 15:32 local-01.log
-rw-r--r-- 1 1001 1001   931 Nov 16 15:33 local-02.log
-rw-r--r-- 1 1001 1001     0 Nov 16 15:34 local-03.log
-rw-r--r-- 1 1001 1001  8606 Nov 16 15:38 report.txt
/usr/bin/bash: line 1: rg: command not found
shell input
{
  "command": "/usr/bin/bash -lc 'cat candidate.json report.txt Model.lean compile.py human-feedback.json; find checks -maxdepth 2 -type f'"
}
shell output · exit 0
{
  "proof_file": "Model.lean",
  "narrative_file": "report.txt",
  "conclusions": {
    "conditional_bayesian_prediction": "bayesian_answer",
    "nonidentification": "moments_do_not_identify_answer"
  },
  "user_facts": [
    "Initially 50 black-or-white balls; ten drawn were all black without replacement; forty remain.",
    "Across same-kind boxes the original black fraction has mean 0.75 and standard deviation 0.1; original count in this box unknown."
  ],
  "model_choices": [
    "Reported moments are treated as exact population moments, not noisy or rounded estimates.",
    "This box is representative of that population before its draws; there is no additional selection information.",
    "Uniform draws without replacement, unchanged colors, and conditioning on the ten-black event alone give likelihood choose(K,n)/choose(50,n).",
    "The prior family is all categorical laws on integer K in 0..50 with the reported moments; no additional shape is inferred. Two three-point support choices are local counterexample witnesses, not asserted population facts."
  ],
  "sources": [
    "User task, cycle 1: counts, observation and population moments.",
    "General observation-model reference: University of South Carolina STAT 509 Section 3.2 notes, pp.10-11, https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf (consulted via Internet in this run; no task-specific prior or answer)."
  ],
  "incorporated_inputs": [],
  "proof_scope": "Within the explicitly defined finite categorical/hypergeometric model, proves positive observation evidence, normalized nonnegative Bayesian posterior, Bayes update and posterior next-draw expectation equals evidence(11)/evidence(10), for every compatible real-valued prior. Constructs two exact same-moment priors with unequal predictions, proving non-identification. No claim that either witness is the actual prior. Scientific truth of representative sampling, uniform drawing and exact moments remains for human review; no human approval claimed."
}
Scientific answer and review packet — cycle 1

The supplied information does not identify a unique next-black probability.
For a specified prior p_k on the ORIGINAL count K, the answer is
  P(next black | ten black) =
    [sum_{k=0}^{50} p_k choose(k,10) (k-10)/40]
      / [sum_{k=0}^{50} p_k choose(k,10)].
Terms with k<10 have zero likelihood. Equivalently the answer is
  [sum p_k choose(k,11)/choose(50,11)]
    / [sum p_k choose(k,10)/choose(50,10)].
Two explicitly compatible priors yield respectively
  4435250809/5307493622 = approximately 0.8356582457, and
  10053879039/11910436744 = approximately 0.8441234570.
These are conditional examples, not bounds or estimates inferred uniquely from
moments. Neither prior is recommended as the true distribution of boxes.

Supplied information
* The box initially contained 50 balls, each black or white.
* Ten draws were black, without replacement; 40 balls remain.
* Across boxes of the same kind, the fraction initially black has mean 0.75
  and standard deviation 0.1. The count in this box is unknown.

Additional scientific assumptions
1. Treat the reported moments as exact population moments, rather than rounded
   values or noisy estimates. There is no sample size or measurement uncertainty
   supplied from which to estimate their uncertainty.
2. Before observing the draws, this particular box is representative of the
   stated population: p_k is its population distribution of original counts.
   There is no further selection information about the box.
3. Each draw selects uniformly among all remaining balls; colors do not change.
   The fact of ten black draws is the entire observation used for updating.
   Under this assumption the count of black balls in a sample is hypergeometric.
4. No parametric shape for the population distribution is imposed. The family
   is all categorical distributions on integer counts 0,...,50 satisfying the
   supplied moments. A continuous prior directly on K/50 would not by itself
   respect this finite grid. A beta distribution or a hierarchical beta-binomial
   construction would impose additional, scientifically unprovided structure.

Necessary definitions (all in Model.lean)
* p : Fin 51 -> real numbers represents prior probabilities p_k.
* compatible p states nonnegativity, sum p_k=1, mean of K/50=3/4 and
  E[(K/50-3/4)^2]=1/100. These are direct population moment constraints.
* likelihood n k = choose(k,n)/choose(50,n) is the conditional probability that
  all n sampled balls are black. There are choose(50,n) equiprobable n-subsets
  and choose(k,n) subsets consisting only of black balls. This observation
  model is assumed from the uniform sampling mechanism, not fitted to the data.
* evidence p n is sum p_k likelihood(n,k), the marginal probability of that run.
* posterior p k = p_k likelihood(10,k)/evidence(p,10), Bayes' rule for the
  observed event. This is finite-event conditioning, with no density approximation.
* prediction p is the posterior average of (K-10)/40. Formal natural-number
  subtraction truncates at zero for K<10, which cannot explain the observation.

What is inferred, and what is undetermined
The population moments imply E[K]=50(3/4)=75/2 and Var(K)=50^2/100=25.
They supply normalization and two moment constraints on 51 prior probabilities;
they do not determine the prior. The observed ten black draws multiply whatever
prior is chosen by its exact hypergeometric likelihood. They do not specify a
population prior's remaining shape. Additional population count frequencies,
a justified generative family, or additional substantive prior information would
be needed for a unique numeric answer. Further draws would supply additional
likelihood evidence but would still not uniquely determine the population prior.

To demonstrate the ambiguity construct, explicitly as extra support assumptions:
A. K in {30,40,50}. The moment equations give weights {9/32,11/16,1/32}.
B. K in {25,35,45}. The moment equations give weights {1/32,11/16,9/32}.
The weights are derived, rather than independently chosen parameters: for a
three-point support {a,b,c}, let m=75/2, v=25. Then
  E[(K-b)(K-c)] = v+(m-b)(m-c) = w_a(a-b)(a-c),
so w_a=[v+(m-b)(m-c)]/[(a-b)(a-c)], with the other two weights obtained by
permutation. This uniquely solves the moment equations conditional on that
support. The support choices are witnesses to non-identification, not something
the supplied observations identify. The proof verifies their exact moment
constraints and distinct Bayesian predictions. There has been no model revision
from a failed numerical guess to a more convenient model.

Proved conclusions, with plain-language translations
bayesian_answer:
  For EVERY compatible prior, posterior probabilities are nonnegative, sum to
  one, satisfy posterior(k)*evidence(10)=prior(k)*likelihood(10,k), and the
  posterior next-black probability is evidence(11)/evidence(10).
  Its proof derives positive evidence from the supplied mean (if all supported
  counts were at most 9, the mean fraction could not be 3/4). No positive-evidence
  premise is added for review. The intermediate observation_step proves the
  exact depletion identity L_10(k)*(k-10)/40=L_11(k) for all 51 possible counts.
  Thus the result covers the observation, conditioning and next draw, rather
  than only numerical arithmetic.
moments_do_not_identify_answer:
  There exist two compatible priors whose predictions are the two exact
  fractions above and are unequal. The explicit witnesses are local to the
  proof so that they do not become unnecessary global model assumptions.

Formal scope and limitations
The finite probabilistic model is expressed by real-valued mass functions,
likelihoods and their sums, not by a separate measure-space construction of
individual ball orderings. The hypergeometric formula is the explicit scientific
observation-model definition; its link to physical drawing is justified by the
counting argument above and is subject to human review. The proof establishes
Bayesian consequences within that model. It cannot establish unbiased physical
drawing, population representativeness, or exactness of the supplied moments.
No added axioms and no sorry are intended. Standard library logical foundations
are distinct from scientific assumptions. Compilation, extraction and kernel
results must be taken from the actual check feedback, not from this narrative.
No human acceptance is claimed.

Sources and lineage
General scientific literature consulted via Internet in this cycle:
University of South Carolina, STAT 509 Section 3.2 notes, pp. 10-11,
https://people.stat.sc.edu/hitchcock/notes509fall11sec32.pdf
The notes identify sampling without replacement as hypergeometric and give the
conditional-count formula. They supply no prior for this problem and no numeric
answer. The population data are from the user, not this source. No operator
request was made and no external response ID was incorporated.
There were no files or earlier-run history in /work at the start of this cycle.
Local compilation traces are retained as local-01.log, local-02.log, etc.
Initial technical failures were an unavailable umbrella tactic import and
missing noncomputable annotations for real division. These required import and
annotation fixes, with no change to the model, assumptions or scientific claims.
Model-attempt-03.lean preserves the first complete scientific candidate before
subsequent technical fixes, if any. Actual protocol check output is retained by
the harness in this run. Human review remains required.

Actual check lineage, first submission:
checks/d3b2ddd0289f4b9c92d67be787fe45dc/verdict.json reports
not_proved because independent extraction failed. Compilation and leanchecker
both succeeded, with no added axioms or sorry; the first conclusion and every
model definition extracted faithfully. The second conclusion's large real
numerals elaborated with inline typeclass proofs in the theorem and generated
proof constants in the extracted definition. The independent checker compares
exact expressions, so this was a real extraction failure despite equal
mathematical meaning. Raw diagnostic-original.log, diagnostic-extracted.log
and identity-diff.txt record the discrepancy using the harness's own identity
routines. The revised source spells the same four large integers as explicit
natural-number-to-real casts to avoid that elaboration difference. The values,
scientific assumptions, theorem content and proof scope are unchanged.
The first failure remains a failure; use the subsequent check result to assess
the revised candidate.
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl

-- Two witnesses, rather than an inferred choice between them: the supplied
-- population moments do not identify the requested posterior probability.
theorem moments_do_not_identify_answer :
    ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧
      prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) ∧
      prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) ∧
      prediction p ≠ prediction q := by
  let p : Fin 51 → ℝ := fun k =>
    (if k = 30 then 9/32 else 0) +
    (if k = 40 then 11/16 else 0) +
    (if k = 50 then 1/32 else 0)
  let q : Fin 51 → ℝ := fun k =>
    (if k = 25 then 1/32 else 0) +
    (if k = 35 then 11/16 else 0) +
    (if k = 45 then 9/32 else 0)
  have sp : ∀ f : Fin 51 → ℝ, (∑ k, p k * f k) =
      (9/32) * f 30 + (11/16) * f 40 + (1/32) * f 50 := by
    intro f
    simp [p, add_mul, ite_mul, Finset.sum_add_distrib]
  have sq : ∀ f : Fin 51 → ℝ, (∑ k, q k * f k) =
      (1/32) * f 25 + (11/16) * f 35 + (9/32) * f 45 := by
    intro f
    simp [q, add_mul, ite_mul, Finset.sum_add_distrib]
  have hp : compatible p := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [p]
      split_ifs <;> norm_num
    · have h := sp (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sp]
      norm_num
    · rw [sp]
      norm_num
  have hq : compatible q := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [q]
      split_ifs <;> norm_num
    · have h := sq (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sq]
      norm_num
    · rw [sq]
      norm_num
  have ap : prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) := by
    rw [(bayesian_answer p hp).2.2.2]
    unfold evidence
    rw [sp, sp]
    norm_num [likelihood, Nat.choose]
  have aq : prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) := by
    rw [(bayesian_answer q hq).2.2.2]
    unfold evidence
    rw [sq, sq]
    norm_num [likelihood, Nat.choose]
  refine ⟨p, q, hp, hq, ap, aq, ?_⟩
  rw [ap, aq]
  norm_num
import os, subprocess, pathlib, sys
libs=sorted(pathlib.Path('/harness/.lake/packages').glob('*/.lake/build/lib/lean'))
env=dict(os.environ,LEAN_PATH=':'.join(map(str,libs)))
r=subprocess.run(['/opt/lean/bin/lean','/work/Model.lean'],env=env,capture_output=True,text=True)
pathlib.Path('/work/local-'+sys.argv[1]+'.log').write_text(r.stdout+r.stderr)
print(r.returncode,r.stdout,r.stderr)
{
  "decision": "reject",
  "binding": "aaa1586e22cc70295f9cebdf6f501d58cc216ce7962e90ee82f202df7d63849c",
  "reason": "Human rejected this candidate: it does not correspond to the intended real-world modeling task and produces no usable predictive example. Multiple possible predictions are acceptable, but proving nonuniqueness is not the intended scientific target. Revise toward a usable Bayesian prediction under an explicitly stated, scientifically justified model or distribution family, deriving its parameters from the supplied moments, observations or requested experiment results. Explain and expose additional assumptions for human review. Do not substitute contrived counterexample priors and a nonidentifiability proof for that predictive task; nonuniqueness may be reported as a limitation. Do not assume both a family and the parameter values that should be inferred.",
  "time": "2026-11-16T16:02:39.113835+00:00",
  "verification_verdict": "proved"
}
checks/589b8c8ad6124887b939666f670c9191/submitted-report.txt
checks/589b8c8ad6124887b939666f670c9191/submitted-candidate.json
checks/589b8c8ad6124887b939666f670c9191/lean.log
checks/589b8c8ad6124887b939666f670c9191/submitted.lean
checks/589b8c8ad6124887b939666f670c9191/extracted.json
checks/589b8c8ad6124887b939666f670c9191/extracted.lean
checks/589b8c8ad6124887b939666f670c9191/verdict.json
checks/589b8c8ad6124887b939666f670c9191/Checked.lean
checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted-report.txt
checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted-candidate.json
checks/d3b2ddd0289f4b9c92d67be787fe45dc/lean.log
checks/d3b2ddd0289f4b9c92d67be787fe45dc/submitted.lean
checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.json
checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.lean
checks/d3b2ddd0289f4b9c92d67be787fe45dc/verdict.json
checks/d3b2ddd0289f4b9c92d67be787fe45dc/Checked.lean
web_search input
{
  "query": "beta binomial distribution mean variance beta prior binomial sampling finite population",
  "action": {
    "type": "search",
    "query": "beta binomial distribution mean variance beta prior binomial sampling finite population"
  }
}
web_search output
{
  "results": [
    {
      "type": "text_result",
      "domain": "faculty.washington.edu",
      "ref_id": "turn0search12",
      "snippet": "The Beta Distribution as a Prior Choice for Binomial θ ... - For the normal distribution the parameters μ and σ² are just the mean",
      "title": "The Beta Distribution as a Prior Choice for Binomial θ",
      "url": "https://faculty.washington.edu/kenrice/sisgbayes/2022-SISG-Probability-Lecture.pdf"
    },
    {
      "type": "text_result",
      "domain": "faculty.washington.edu",
      "ref_id": "turn0search13",
      "snippet": "The Beta Distribution as a Prior Choice for a Binomial θ ... - For the normal distribution the parameters \\(\\mu\\) and \\(\\sigma^2\\) are just the",
      "title": "The Beta Distribution as a Prior Choice for a Binomial θ",
      "url": "https://faculty.washington.edu/kenrice/sisgbayes/2016_SISG_17_3.pdf"
    },
    {
      "type": "text_result",
      "domain": "inla.r-inla-download.org",
      "ref_id": "turn0search14",
      "snippet": "The Beta-binomial distribution arise from a hierarchical model where the probability p is Beta- ... The mean and variance of y are given as ...",
      "title": "Beta-binomial",
      "url": "https://inla.r-inla-download.org/r-inla.org/doc/likelihood/betabinomial.pdf"
    },
    {
      "type": "text_result",
      "domain": "www.stat.tugraz.at",
      "ref_id": "turn0search15",
      "snippet": "The mean and the variance are given by ... A discrete random variable \\(X\\) is said to have a beta-binomial distribution with parameters \\(n \\in",
      "title": "B Probability Calculus and Statistical Inference",
      "url": "https://www.stat.tugraz.at/friedl/FahrmeirKneibLangMarxRegression.pdf"
    },
    {
      "type": "text_result",
      "domain": "faculty.washington.edu",
      "ref_id": "turn0search16",
      "snippet": "# The Beta Distribution as a Prior Choice for a Binomial ... - For the normal distribution the parameters \\(\\mu\\) and \\(\\sigma^2\\) are just the",
      "title": "# The Beta Distribution as a Prior Choice for a Binomial",
      "url": "https://faculty.washington.edu/kenrice/sisgbayes/bsisg3.pdf"
    },
    {
      "type": "text_result",
      "domain": "borowiecki.dev",
      "ref_id": "turn0search17",
      "snippet": "This kind of data is universal in biomedical fields (number of gene mutation sites detected), industrial engineering (number of product defects under fixed sampling) and",
      "title": "A new Bernstein-binomial model for fitting finite discrete data with over-dispersion: Likelihood-based and Bayesian approaches",
      "url": "https://borowiecki.dev/pdf/2610.04964"
    },
    {
      "type": "text_result",
      "domain": "casrai.org",
      "ref_id": "turn0search0",
      "snippet": "The same distribution is the Bayesian posterior predictive for a binomial count under a beta prior, which is why you may meet it in Bayesian",
      "title": "Beta-Binomial Distribution: Formula & Example — CASRAI",
      "url": "https://casrai.org/guides/beta-binomial-distribution"
    },
    {
      "type": "text_result",
      "domain": "www.cs.bgu.ac.il",
      "ref_id": "turn0search1",
      "snippet": "This is convenient because it means the posterior distribution will belong to the same family of functions as the prior, and the Bayesian update procedure",
      "title": "Probability Theory - NLP 2016 - Michael Elhadad",
      "url": "https://www.cs.bgu.ac.il/~elhadad/nlp16/prob.html"
    },
    {
      "type": "text_result",
      "domain": "www.cs.bgu.ac.il",
      "ref_id": "turn0search2",
      "snippet": "If we want to compute a Bayesian estimate of Binomial experiments, we must select a prior for the distribution of the parameter μ. ... This",
      "title": "Probability Theory - NLP 2015 - Michael Elhadad",
      "url": "https://www.cs.bgu.ac.il/~elhadad/nlp15/prob.html"
    },
    {
      "type": "text_result",
      "domain": "cran.r-project.org",
      "ref_id": "turn0search3",
      "snippet": "Must be positive and finite. ... The binomial inference problem is to estimate the population `\\phi` parameter based on the sample data. ... Given a",
      "title": "Help for package DFBA",
      "url": "https://cran.r-project.org/web/packages/DFBA/refman/DFBA.html"
    },
    {
      "type": "text_result",
      "domain": "sunjh22.github.io",
      "ref_id": "turn0search4",
      "snippet": "# 4 Mean, Variance, and Intracluster Correlation ... The concentration \\(a+b\\) controls heterogeneity: larger concentration means smaller \\(\\rho\\) and a tighter distribution of \\(P\\) around",
      "title": "Beta-binomial Distribution – Jiahong Sun",
      "url": "https://sunjh22.github.io/knowledge/statistics/probability-randomness/beta-binomial-distribution.html"
    },
    {
      "type": "text_result",
      "domain": "dickbrus.github.io",
      "ref_id": "turn0search5",
      "snippet": "The same criteria can be used to estimate the proportion of a population or, in case of an infinite population, the areal fraction, satisfying some",
      "title": "Chapter 12 Computing the required sample size | Spatial sampling with R",
      "url": "https://dickbrus.github.io/SpatialSamplingwithR/RequiredSampleSize.html"
    },
    {
      "type": "text_result",
      "domain": "www-users.york.ac.uk",
      "ref_id": "turn0search6",
      "snippet": "It is a weighted average of the prior mean $a/(a+b)$a/(a+b) and the sample proportion $y/n$y/n, and the weights are proportional to the prior sample size",
      "title": "Bayesian Statistics: notes to accompany the lectures",
      "url": "https://www-users.york.ac.uk/~bp787/Bayes_notes.html"
    },
    {
      "type": "text_result",
      "domain": "pmc.ncbi.nlm.nih.gov",
      "ref_id": "turn0search7",
      "snippet": "Prior and posterior distribution for the rate parameter $\\theta $ [Source formula altimg: si1.gif] from the beta-binomial model.",
      "title": "A tutorial on bridge sampling",
      "url": "https://pmc.ncbi.nlm.nih.gov/articles/PMC5699790/"
    },
    {
      "type": "text_result",
      "domain": "kuan-liu.github.io",
      "ref_id": "turn0search8",
      "snippet": "* The beta distribution prior for the binomial is useful for illustrating how the Bayesian approach combines prior information and new data ... * Posterior",
      "title": "Session 3 Introduction to Bayesian inference | HAD5314H - Applied Bayesian Methods in Clinical Epidemiology and Health Care Research",
      "url": "https://kuan-liu.github.io/bayes_bookdown/bayes.html"
    },
    {
      "type": "text_result",
      "domain": "pmc.ncbi.nlm.nih.gov",
      "ref_id": "turn0search9",
      "snippet": "Sample size for estimating a population proportion in fully Bayesian and mixed Bayesian-likelihood approach ... With simple random sampling this reduces to estimating the probability-of-success",
      "title": "Bayesian approach for sample size determination, illustrated with Soil Health Card data of Andhra Pradesh (India)",
      "url": "https://pmc.ncbi.nlm.nih.gov/articles/PMC8607328/"
    },
    {
      "type": "text_result",
      "domain": "bayesball.github.io",
      "ref_id": "turn0search10",
      "snippet": "For future reference, it is useful to know that if \\(p \\sim {\\rm Beta}(a, b)\\), its mean \\(E[p] = \\frac{a}{a+b}\\) and its variance \\(V(p) =",
      "title": "Chapter 7 Learning About a Binomial Probability | Probability and Bayesian Modeling",
      "url": "https://bayesball.github.io/BOOK/proportion"
    },
    {
      "type": "text_result",
      "domain": "vsokolov.org",
      "ref_id": "turn0search11",
      "snippet": "The Beta distribution is frequently used in Bayesian statistics, empirical Bayes methods, and classical statistics to model random variables with values falling inside a finite",
      "title": "3  Bayesian Learning – Bayes, Artificial Intelligence, and Deep Learning",
      "url": "https://vsokolov.org/html/_book/03-bl.html"
    },
    {
      "type": "text_result",
      "domain": "en.wikipedia.org",
      "ref_id": "turn0search18",
      "snippet": "Mean | ${\\displaystyle {\\frac {n\\alpha }{\\alpha +\\beta }}\\!} ... Variance | ${\\displaystyle {\\frac {n\\alpha \\beta (\\alpha +\\beta +n)}{(\\alpha +\\beta )^{2}(\\alpha +\\beta +1)}}\\!} ... In probability",
      "title": "Beta-binomial distribution",
      "url": "https://en.wikipedia.org/wiki/Beta-binomial_distribution"
    },
    {
      "type": "text_result",
      "domain": "en.wikipedia.org",
      "ref_id": "turn0search19",
      "snippet": "Denoting by αPosterior and βPosterior the shape parameters of the posterior beta distribution resulting from applying Bayes' theorem to a binomial likelihood function and a",
      "title": "Beta distribution",
      "url": "https://en.wikipedia.org/wiki/Beta_distribution"
    },
    {
      "type": "text_result",
      "domain": "en.wikipedia.org",
      "ref_id": "turn0search20",
      "snippet": "Binomial distribution ... This estimator is unbiased and uniformly with minimum variance, proven using Lehmann-Scheffé theorem, since it is based on a minimal sufficient and",
      "title": "Binomial distribution",
      "url": "https://en.wikipedia.org/wiki/Binomial_distribution"
    },
    {
      "type": "text_result",
      "domain": "arxiv.org",
      "ref_id": "turn0academia21",
      "snippet": "Title: A new Bernstein-binomial model for fitting finite discrete data with over-dispersion: Likelihood-based and Bayesian approaches ... Although the beta-binomial distribution mitigates this by assi",
      "title": "A new Bernstein-binomial model for fitting finite discrete data with over-dispersion: Likelihood-based and Bayesian approaches",
      "url": "https://arxiv.org/abs/2610.04964"
    },
    {
      "type": "text_result",
      "domain": "en.wikipedia.org",
      "ref_id": "turn0search22",
      "snippet": "Negative binomial distribution ... The cumulative distribution function can be expressed in terms of the regularized incomplete beta function: ${\\displaystyle F(k;r,p)\\equiv \\Pr(X\\leq k)=I_{p}(r,k+1).",
      "title": "Negative binomial distribution",
      "url": "https://en.wikipedia.org/wiki/Negative_binomial_distribution"
    },
    {
      "type": "text_result",
      "domain": "en.wikipedia.org",
      "ref_id": "turn0search23",
      "snippet": "This implies that the conditional expectation and conditional variance of the observed fraction of successes, Y/n, are ... The goal of binomial regression is to",
      "title": "Binomial regression",
      "url": "https://en.wikipedia.org/wiki/Binomial_regression"
    },
    {
      "type": "text_result",
      "domain": "arxiv.org",
      "ref_id": "turn0academia24",
      "snippet": "This paper examines the distribution of order statistics taken from simple-random-sampling without replacement (SRSWOR) from a finite population with values 1,...,N. This distribution is a",
      "title": "The distribution of order statistics under sampling without replacement",
      "url": "https://arxiv.org/abs/2207.00270"
    },
    {
      "type": "text_result",
      "domain": "en.wikipedia.org",
      "ref_id": "turn0search25",
      "snippet": "* Given certain conditions, the sum (hence the average) of a sufficiently large number of iid random variables, each with finite mean and variance, will",
      "title": "Relationships among probability distributions",
      "url": "https://en.wikipedia.org/wiki/Relationships_among_probability_distributions"
    },
    {
      "type": "text_result",
      "domain": "arxiv.org",
      "ref_id": "turn0academia26",
      "snippet": "KEY WORDS: Beta, binomial, gamma, Poisson, and Polya (or beta-binomial) distributions; Conjugate prior distribution; Cumulative distribution function; Posterior distribution.",
      "title": "Some Relationships and Properties of the Hypergeometric Distribution",
      "url": "https://arxiv.org/abs/1610.07554"
    },
    {
      "type": "text_result",
      "domain": "arxiv.org",
      "ref_id": "turn0academia27",
      "snippet": "It is used to model data, and also, as a more flexible version of the uniform distribution, it serves as a prior distribution for a",
      "title": "Constructions for a bivariate beta distribution",
      "url": "https://arxiv.org/abs/1406.5881"
    },
    {
      "type": "text_result",
      "domain": "www.reddit.com",
      "ref_id": "turn0reddit28",
      "snippet": "I noticed that for the majority of the distributions, all of the theorems given and proven use a beta (bernoulli, binomical, negative binomial, geometric) or",
      "title": "Why are conjugate prior distributions usually the beta or gamma distribution?",
      "url": "https://www.reddit.com/r/AskStatistics/comments/jd8mzw"
    },
    {
      "type": "text_result",
      "domain": "www.reddit.com",
      "ref_id": "turn0reddit29",
      "snippet": "Regardless, could we then apply MLE like approaches to infer that the r.v is more likely to follow poisson distribution bases on the data we",
      "title": "[Q] Inferring underlying distributin of a random variable from sampling distributions",
      "url": "https://www.reddit.com/r/statistics/comments/1eq32h5"
    },
    {
      "type": "text_result",
      "domain": "www.reddit.com",
      "ref_id": "turn0reddit30",
      "snippet": "In the derivation of a MAP estimator of a Bernoulli distribution when using a Beta distribution prior (with alpha, beta as parameters), you get ...",
      "title": "Why can a MAP estimator go outside the range of the (beta) prior?",
      "url": "https://www.reddit.com/r/AskStatistics/comments/131f8uc"
    },
    {
      "type": "text_result",
      "domain": "www.reddit.com",
      "ref_id": "turn0reddit31",
      "snippet": "If you assume p has a uniform prior distrbiution, and you observe s successes out of n Bernoulli trials with parameter p, then the posterior",
      "title": "A binomial distribution with a probability that itself follows a distribution",
      "url": "https://www.reddit.com/r/math/comments/j2im5a"
    },
    {
      "type": "text_result",
      "domain": "www.reddit.com",
      "ref_id": "turn0reddit32",
      "snippet": "If there is such a distribution, I have not found it yet. ... Do you instead mean that you’ve sampled from Y? ... I think",
      "title": "Is there a distribution for p when the data is binomially distributed, and we know the other parameters?",
      "url": "https://www.reddit.com/r/askmath/comments/1fqqows"
    }
  ]
}
shell input
{
  "command": "/usr/bin/bash -lc \"cat checks/589b8c8ad6124887b939666f670c9191/verdict.json; find /harness/.lake/packages/mathlib/Mathlib -iname '*Pochhammer*' -o -iname '*BetaBinomial*' -o -iname '*Binomial*'\""
}
shell output · exit 1 · failed
{
  "ok": true,
  "check_complete": true,
  "reviewable": true,
  "verdict": "proved",
  "time": "2026-11-16T15:38:27.280903+00:00",
  "lean_exit": 0,
  "added_assumptions": [],
  "conditional_on": [],
  "extraction": {
    "file": "/work/checks/589b8c8ad6124887b939666f670c9191/submitted.lean",
    "conclusions": [
      "bayesian_answer",
      "moments_do_not_identify_answer"
    ],
    "lean_exit": 0,
    "ok": true,
    "compiles_alone": true,
    "faithful": {
      "bayesian_answer": true,
      "moments_do_not_identify_answer": true
    },
    "assumption_declarations": [
      "compatible",
      "likelihood",
      "evidence",
      "posterior",
      "prediction"
    ],
    "identity_method": "kernel-expression-repr-v1",
    "conclusion_identities": {
      "bayesian_answer": {
        "original_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585",
        "extracted_sha256": "a12ac8dc3513e9592d2d8f93e1726daef47e8b9b61bc917e4c334271f3712585"
      },
      "moments_do_not_identify_answer": {
        "original_sha256": "8b53d298f5f1e2d1b615a9d19d1275c2648305e06659b9780deee0e46f085f1f",
        "extracted_sha256": "8b53d298f5f1e2d1b615a9d19d1275c2648305e06659b9780deee0e46f085f1f"
      }
    },
    "dependency_faithful": {
      "compatible": true,
      "compatible._proof_1": true,
      "compatible._proof_2": true,
      "compatible._proof_3": true,
      "compatible._proof_4": true,
      "prediction": true,
      "posterior": true,
      "likelihood": true,
      "evidence": true,
      "prediction._proof_1": true
    },
    "dependency_identities": {
      "compatible": {
        "original_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7",
        "extracted_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7"
      },
      "compatible._proof_1": {
        "original_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52",
        "extracted_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52"
      },
      "compatible._proof_2": {
        "original_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1",
        "extracted_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1"
      },
      "compatible._proof_3": {
        "original_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2",
        "extracted_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2"
      },
      "compatible._proof_4": {
        "original_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472",
        "extracted_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472"
      },
      "prediction": {
        "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
        "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
      },
      "posterior": {
        "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
        "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
      },
      "likelihood": {
        "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
        "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
      },
      "evidence": {
        "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
        "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
      },
      "prediction._proof_1": {
        "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
        "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
      }
    },
    "unranged": [],
    "added_assumptions": [],
    "conclusions_as_proved": {
      "bayesian_answer": "\u2200 (p : Fin 51 \u2192 \u211d), compatible p \u2192 (\u2200 (k : Fin 51), 0 \u2264 posterior p k) \u2227 \u2211 k, posterior p k = 1 \u2227 (\u2200 (k : Fin 51), posterior p k * evidence p 10 = p k * likelihood 10 k) \u2227 prediction p = evidence p 11 / evidence p 10",
      "moments_do_not_identify_answer": "\u2203 p q, compatible p \u2227 compatible q \u2227 prediction p = \u21914435250809 / \u21915307493622 \u2227 prediction q = \u219110053879039 / \u219111910436744 \u2227 prediction p \u2260 prediction q"
    },
    "extracted_file": "/work/checks/589b8c8ad6124887b939666f670c9191/extracted.lean",
    "errors": []
  },
  "scientific_relevance": "requires human review"
}
find: ‘/harness/.lake/packages/mathlib/Mathlib’: No such file or directory
shell input
{
  "command": "/usr/bin/bash -lc \"ls /harness/.lake/packages; find /opt /harness -path '*Mathlib*Pochhammer*' -o -path '*Mathlib*Binomial*'\""
}
shell output · exit 0
LeanSearchClient
Qq
aesop
batteries
importGraph
mathlib
plausible
proofwidgets
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.trace
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.ir.sig
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.olean.server
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.olean.private
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.ir.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.olean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.ir
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.olean.server.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.olean.private.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.ilean.hash
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.olean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.ir.sig.hash
assistant
A beta-binomial model gives a conditional prediction of **81.51%**. It treats each box as having a latent black-ball propensity, with 50 ball colors generated from that propensity.

The reported standard deviation describes the actual fraction in 50-ball boxes, so the parameter fit must include that finite-box variation. This gives α = 21.3 and β = 7.1. I’m formalizing the fit, the without-replacement likelihood, and the posterior prediction; the beta-binomial family remains an additional assumption for human review.
shell input
{
  "command": "/usr/bin/bash -lc \"ls -la /harness/.lake/packages/mathlib; find / -path '*Pochhammer.lean' -o -path '*Choose*Sum.lean' 2>/dev/null | head -30\""
}
shell output · exit 0
total 12
drwxr-xr-x  3 root root 4096 Nov 16 16:02 .
drwxr-xr-x 10 root root 4096 Nov 16 16:02 ..
drwxr-xr-x  3 root root 4096 Nov 16 16:02 .lake
web_search input
{
  "query": "https://inla.r-inla-download.org/r-inla.org/doc/likelihood/betabinomial.pdf",
  "action": {
    "type": "open_page",
    "url": "https://inla.r-inla-download.org/r-inla.org/doc/likelihood/betabinomial.pdf"
  }
}
web_search output
{
  "results": [
    {
      "type": "text_result",
      "domain": "inla.r-inla-download.org",
      "ref_id": "turn1view0",
      "snippet": "Total lines: 100",
      "url": "https://inla.r-inla-download.org/r-inla.org/doc/likelihood/betabinomial.pdf"
    }
  ]
}
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nimport json,pathlib\np=pathlib.Path('/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Polynomial/Pochhammer.ilean')\ns=p.read_text()\nimport re\nfor x in sorted(set(re.findall(r'\\\"([A-Za-z_][A-Za-z_0-9.\\\\']*)\\\"',s))):\n if any(w in x.lower() for w in ['sum','pochhammer','eval','asc']): print(x)\nPY\""
}
shell output · exit 0
Mathlib.Algebra.Polynomial.Eval.Algebra
Mathlib.RingTheory.Polynomial.Pochhammer
Nat.cast_ascFactorial
Nat.cast_choose_eq_ascPochhammer_div
Nat.cast_choose_eq_descPochhammer_div
ascPochhammer
ascPochhammer_eval_cast
ascPochhammer_eval_comp
ascPochhammer_eval_eq_zero_iff
ascPochhammer_eval_neg_coe_nat_of_lt
ascPochhammer_eval_neg_eq_descPochhammer
ascPochhammer_eval_one
ascPochhammer_eval_succ
ascPochhammer_eval_zero
ascPochhammer_map
ascPochhammer_mul
ascPochhammer_natDegree
ascPochhammer_nat_eq_ascFactorial
ascPochhammer_nat_eq_descFactorial
ascPochhammer_nat_eq_natCast_ascFactorial
ascPochhammer_nat_eq_natCast_descFactorial
ascPochhammer_nat_eval_succ
ascPochhammer_ne_zero_eval_zero
ascPochhammer_one
ascPochhammer_pos
ascPochhammer_succ_comp_X_add_one
ascPochhammer_succ_eval
ascPochhammer_succ_left
ascPochhammer_succ_right
ascPochhammer_zero
ascPochhammer_zero_eval_zero
descPochhammer
descPochhammer_eq_ascPochhammer
descPochhammer_eval_cast
descPochhammer_eval_coe_nat_of_lt
descPochhammer_eval_eq_ascPochhammer
descPochhammer_eval_eq_descFactorial
descPochhammer_eval_eq_prod_range
descPochhammer_eval_zero
descPochhammer_int_eq_ascFactorial
descPochhammer_map
descPochhammer_mul
descPochhammer_natDegree
descPochhammer_ne_zero_eval_zero
descPochhammer_nonneg
descPochhammer_one
descPochhammer_pos
descPochhammer_succ_comp_X_sub_one
descPochhammer_succ_eval
descPochhammer_succ_left
descPochhammer_succ_right
descPochhammer_zero
descPochhammer_zero_eval_zero
factorial_mul_ascPochhammer
monic_ascPochhammer
monic_descPochhammer
monotoneOn_descPochhammer_eval
pow_le_descPochhammer_eval
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\nimport re\nfor p in Path('/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib').rglob('*.ilean'):\n if any(x in str(p) for x in ['Choose','Pochhammer','Factorial','Antidiagonal']):\n  names=sorted(set(re.findall(r'\\\"([A-Za-z_][A-Za-z_0-9.\\\\']*)\\\"',p.read_text())))\n  for name in names:\n   if ('sum' in name.lower() and any(x in name.lower() for x in ['choose','poch','factorial','succ','antidiagonal'])) or 'add_choose' in name: print(p.stem,name)\nPY\""
}
shell output · exit 0
Antidiagonal Finsupp.image_sumElim_product_antidiagonal
Sum Finset.sum_antidiagonal_choose_add
Sum Finset.sum_antidiagonal_choose_succ_mul
Sum Finset.sum_choose_succ_mul
Sum Int.alternating_sum_range_choose
Sum Int.alternating_sum_range_choose_eq_choose
Sum Int.alternating_sum_range_choose_of_ne
Sum Mathlib.Data.Nat.Choose.Sum
Sum Nat.sum_Icc_choose
Sum Nat.sum_range_add_choose
Sum Nat.sum_range_choose
Sum Nat.sum_range_choose_halfway
Sum Nat.sum_range_mul_choose
Sum Nat.sum_range_multichoose
Cast Nat.cast_add_choose
Vandermonde Nat.add_choose_eq
Vandermonde Nat.sum_range_choose_sq
Basic Nat.add_choose
Basic Nat.add_choose_mul_factorial_mul_factorial
BigOperators Nat.prod_factorial_dvd_factorial_sum
shell input
{
  "command": "/usr/bin/bash -lc \"cp Model.lean Cycle1-preserved.lean\ncp report.txt Cycle1-preserved-report.txt\ncp candidate.json Cycle1-preserved-candidate.json\ncat > Explore.lean <<'EOF'\nimport Mathlib.Data.Nat.Choose.Sum\nimport Mathlib.RingTheory.Polynomial.Pochhammer\nimport Mathlib.Tactic\n#check Finset.sum_choose_succ_mul\n#check Finset.sum_antidiagonal_choose_succ_mul\n#check Finset.sum_antidiagonal_eq_sum_range_succ\n#check Nat.mul_choose_eq\n#check Nat.succ_mul_choose_eq\n#check Finset.sum_range_succ'\n#check Finset.sum_range_succ\n#check ascPochhammer_succ_eval\n#check ascPochhammer_succ_right\nEOF\npython compile.py explore\""
}
shell output · exit 0
0  
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\ns=Path('compile.py').read_text().replace(\\\"'/work/Model.lean'\\\",\\\"('/work/'+sys.argv[2] if len(sys.argv)>2 else '/work/Model.lean')\\\")\nPath('compile.py').write_text(s)\nPY\npython compile.py explore Explore.lean\""
}
shell input
{
  "command": "/usr/bin/bash -lc 'ps -eo pid,etime,args | head -25'"
}
shell output · exit 0
/usr/bin/bash: line 1: ps: command not found
shell input
{
  "command": "/usr/bin/bash -lc 'ls /harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic.olean /harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Nat/Choose/Sum.olean; cat local-explore.log'"
}
shell output · exit 0
ls: cannot access '/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic.olean': No such file or directory
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Nat/Choose/Sum.olean
shell input
{
  "command": "/usr/bin/bash -lc \"sed -i '/import Mathlib.Tactic\"'$/c'\"\\\\import Mathlib.Tactic.Ring' Explore.lean\npython compile.py explore2 Explore.lean\""
}
assistant
The formalization will use probabilities on the 51 possible original black-ball counts and condition on the exact likelihood of ten black draws without replacement. That makes the depletion of the box explicit.

I’m also proving that the supplied moments determine α and β within the chosen family. The earlier nonuniqueness result remains a limitation, but it will no longer be the main answer.
shell output · exit 0
1 /work/Explore.lean:1:0: error: object file '/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic.olean' of module Mathlib.Tactic does not exist
 
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nimport json\np='/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Nat/Choose/Sum.ilean'\nx=json.load(open(p));print(x.keys());print(str(x)[:1000])\nPY\""
}
shell output · exit 0
dict_keys(['decls', 'directImports', 'module', 'references', 'version'])
{'decls': {'Commute.add_pow': [32, 0, 63, 95, 33, 8, 33, 15], "Commute.add_pow'": [65, 0, 70, 39, 67, 8, 67, 16], 'Finset.prod_antidiagonal_pow_choose_succ': [233, 0, 244, 32, 234, 8, 234, 41], 'Finset.prod_pow_choose_succ': [222, 0, 231, 86, 223, 8, 223, 28], 'Finset.sum_antidiagonal_choose_add': [262, 0, 266, 100, 262, 8, 262, 35], 'Finset.sum_antidiagonal_choose_succ_mul': [254, 0, 260, 72, 256, 8, 256, 40], 'Finset.sum_choose_succ_mul': [246, 0, 252, 59, 248, 8, 248, 27], 'Finset.sum_powerset_apply_card': [196, 0, 207, 34, 196, 8, 196, 31], 'Finset.sum_powerset_neg_one_pow_card': [209, 0, 212, 77, 209, 8, 209, 37], 'Finset.sum_powerset_neg_one_pow_card_of_nonempty': [214, 0, 218, 50, 214, 8, 214, 49], 'Int.alternating_sum_range_choose': [184, 0, 188, 63, 184, 8, 184, 40], 'Int.alternating_sum_range_choose_eq_choose': [176, 0, 182, 9, 176, 8, 176, 50], 'Int.alternating_sum_range_choose_of_ne': [190, 0, 192, 56, 190, 8, 190, 46], 'Nat.choose_middle_le_pow': [115, 0, 118, 44, 115, 8, 
shell output · exit 0
1 Finset.sum_choose_succ_mul.{u_1} {R : Type u_1} [NonAssocSemiring R] (f : ℕ → ℕ → R) (n : ℕ) :
  ∑ i ∈ Finset.range (n + 2), ↑((n + 1).choose i) * f i (n + 1 - i) =
    ∑ i ∈ Finset.range (n + 1), ↑(n.choose i) * f i (n + 1 - i) +
      ∑ i ∈ Finset.range (n + 1), ↑(n.choose i) * f (i + 1) (n - i)
Finset.sum_antidiagonal_choose_succ_mul.{u_1} {R : Type u_1} [NonAssocSemiring R] (f : ℕ → ℕ → R) (n : ℕ) :
  ∑ ij ∈ Finset.antidiagonal (n + 1), ↑((n + 1).choose ij.1) * f ij.1 ij.2 =
    ∑ ij ∈ Finset.antidiagonal n, ↑(n.choose ij.1) * f ij.1 (ij.2 + 1) +
      ∑ ij ∈ Finset.antidiagonal n, ↑(n.choose ij.2) * f (ij.1 + 1) ij.2
/work/Explore.lean:6:7: error(lean.unknownIdentifier): Unknown constant `Finset.sum_antidiagonal_eq_sum_range_succ`
/work/Explore.lean:7:7: error(lean.unknownIdentifier): Unknown constant `Nat.mul_choose_eq`
/work/Explore.lean:8:7: error(lean.unknownIdentifier): Unknown constant `Nat.succ_mul_choose_eq`
Finset.sum_range_succ'.{u_4} {M : Type u_4} [AddCommMonoid M] (f : ℕ → M) (n : ℕ) :
  ∑ k ∈ Finset.range (n + 1), f k = ∑ k ∈ Finset.range n, f (k + 1) + f 0
Finset.sum_range_succ.{u_4} {M : Type u_4} [AddCommMonoid M] (f : ℕ → M) (n : ℕ) :
  ∑ x ∈ Finset.range (n + 1), f x = ∑ x ∈ Finset.range n, f x + f n
ascPochhammer_succ_eval.{u_1} {S : Type u_1} [Semiring S] (n : ℕ) (k : S) :
  Polynomial.eval k (ascPochhammer S (n + 1)) = Polynomial.eval k (ascPochhammer S n) * (k + ↑n)
ascPochhammer_succ_right.{u} (S : Type u) [Semiring S] (n : ℕ) :
  ascPochhammer S (n + 1) = ascPochhammer S n * (Polynomial.X + ↑n)
 
shell input
{
  "command": "/usr/bin/bash -lc \"cat > Moments.lean <<'EOF'\nimport Mathlib.Basic.Real.Basic\nimport Mathlib.Data.Nat.Choose.Sum\nimport Mathlib.Algebra.BigOperators.Field\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.FieldSimp\n\nset_option maxRecDepth 4096\nset_option maxHeartbeats 4000000\n\n-- Rising factorial: a(a+1)...(a+n-1).\nnoncomputable def rising (a : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rising a n * (a+n)\n\nlemma rising_pos : ∀ a : ℝ, 0 < a → ∀ n, 0 < rising a n := by\n  intro a ha n\n  induction n with\n  | zero => simpa [rising]\n  | succ n ih => exact mul_pos ih (by positivity)\n\n-- A general Pascal-rule recurrence, used only to derive the family moments.\nlemma weighted_sum_step (a b : ℝ) (f : ℕ → ℝ) (n : ℕ) :\n    (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * f k) =\n    ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) *\n      ((b + (n-k : ℕ)) * f k + (a+k) * f (k+1)) := by\n  have h := Finset.sum_choose_succ_mul\n    (fun i j => rising a i * rising b j * f i) n\n  simp only [mul_assoc] at h ⊢\n  rw [h, ← Finset.sum_add_distrib]\n  apply Finset.sum_congr rfl\n  intro k hk\n  have hk' : k ≤ n := by have := Finset.mem_range.mp hk; omega\n  have hs : n+1-k = (n-k)+1 := by omega\n  rw [hs, rising, rising]\n  ring\n\n-- Raw mass, first count moment and second factorial count moment.\n-- These are derived simultaneously, not assumed moment formulas.\nlemma family_sums (a b : ℝ) (ha : 0 < a) (hb : 0 < b) : ∀ n : ℕ,\n    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k)) = rising (a+b) n ∧\n    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) =\n      (n : ℝ) * a / (a+b) * rising (a+b) n ∧\n    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ) * (k-1))) =\n      (n : ℝ) * (n-1) * a * (a+1) / ((a+b)*(a+b+1)) * rising (a+b) n := by\n  have hs : a+b ≠ 0 := ne_of_gt (by linarith)\n  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)\n  intro n\n  induction n with\n  | zero => simp [rising]\n  | succ n ih =>\n    have cast_sub : ∀ k ∈ Finset.range (n+1), ((n-k : ℕ) : ℝ) = (n : ℝ) - k := by\n      intro k hk\n      exact Nat.cast_sub (by have := Finset.mem_range.mp hk; omega)\n    have h0 := weighted_sum_step a b (fun _ => 1) n\n    have h1 := weighted_sum_step a b (fun k => (k : ℝ)) n\n    have h2 := weighted_sum_step a b (fun k => (k : ℝ) * (k-1)) n\n    have r0 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k)) =\n        (a+b+n) * rising (a+b) n := by\n      simpa only [mul_one] using h0.trans (by\n        calc\n          _ = (a+b+n) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by\n            rw [Finset.mul_sum]\n            apply Finset.sum_congr rfl\n            intro k hk\n            rw [cast_sub k hk]\n            ring\n          _ = _ := by rw [ih.1])\n    have r1 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * (k : ℝ)) =\n        (a+b+n+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) + a * rising (a+b) n := by\n      rw [h1]\n      calc\n        _ = (a+b+n+1) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) +\n            a * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by\n          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]\n          apply Finset.sum_congr rfl\n          intro k hk\n          rw [cast_sub k hk]\n          push_cast\n          ring\n        _ = _ := by rw [ih.1, ih.2.1]\n    have r2 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * ((k : ℝ)*(k-1))) =\n        (a+b+n+2) * ((n : ℝ)*(n-1)*a*(a+1)/((a+b)*(a+b+1))*rising (a+b) n) +\n        2*(a+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) := by\n      rw [h2]\n      calc\n        _ = (a+b+n+2) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ)*(k-1))) +\n            2*(a+1) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ) := by\n          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]\n          apply Finset.sum_congr rfl\n          intro k hk\n          rw [cast_sub k hk]\n          push_cast\n          ring\n        _ = _ := by rw [ih.2.1, ih.2.2]\n    refine ⟨?_, ?_, ?_⟩\n    · rw [r0, rising]\n      ring\n    · rw [r1, rising]\n      push_cast\n      field_simp\n      <;> ring\n    · rw [r2, rising]\n      push_cast\n      field_simp\n      <;> ring\nEOF\npython compile.py moments Moments.lean\""
}
shell output · exit 0
0 /work/Moments.lean:21:12: warning: `simp` already closes the goal

Hint: Use `simp` instead of `simpa`:
  [apply] simp [rising]

Note: This linter can be disabled with `set_option linter.unnecessarySimpa false`
/work/Moments.lean:104:6: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Moments.lean:108:6: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Moments.lean:104:6: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
/work/Moments.lean:108:6: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
 
shell input
{
  "command": "/usr/bin/bash -lc \"cat >> Explore.lean <<'EOF'\n#check Fin.sum_univ_eq_sum_range\n#check Finset.sum_range_le_sum_range_of_subset\n#check Nat.cast_sub\n#check Finset.sum_div\n#check Nat.choose_pos\n#check Finset.sum_range_succ_sub_sum\nEOF\npython compile.py explore3 Explore.lean\""
}
shell output · exit 0
1 Finset.sum_choose_succ_mul.{u_1} {R : Type u_1} [NonAssocSemiring R] (f : ℕ → ℕ → R) (n : ℕ) :
  ∑ i ∈ Finset.range (n + 2), ↑((n + 1).choose i) * f i (n + 1 - i) =
    ∑ i ∈ Finset.range (n + 1), ↑(n.choose i) * f i (n + 1 - i) +
      ∑ i ∈ Finset.range (n + 1), ↑(n.choose i) * f (i + 1) (n - i)
Finset.sum_antidiagonal_choose_succ_mul.{u_1} {R : Type u_1} [NonAssocSemiring R] (f : ℕ → ℕ → R) (n : ℕ) :
  ∑ ij ∈ Finset.antidiagonal (n + 1), ↑((n + 1).choose ij.1) * f ij.1 ij.2 =
    ∑ ij ∈ Finset.antidiagonal n, ↑(n.choose ij.1) * f ij.1 (ij.2 + 1) +
      ∑ ij ∈ Finset.antidiagonal n, ↑(n.choose ij.2) * f (ij.1 + 1) ij.2
/work/Explore.lean:6:7: error(lean.unknownIdentifier): Unknown constant `Finset.sum_antidiagonal_eq_sum_range_succ`
/work/Explore.lean:7:7: error(lean.unknownIdentifier): Unknown constant `Nat.mul_choose_eq`
/work/Explore.lean:8:7: error(lean.unknownIdentifier): Unknown constant `Nat.succ_mul_choose_eq`
Finset.sum_range_succ'.{u_4} {M : Type u_4} [AddCommMonoid M] (f : ℕ → M) (n : ℕ) :
  ∑ k ∈ Finset.range (n + 1), f k = ∑ k ∈ Finset.range n, f (k + 1) + f 0
Finset.sum_range_succ.{u_4} {M : Type u_4} [AddCommMonoid M] (f : ℕ → M) (n : ℕ) :
  ∑ x ∈ Finset.range (n + 1), f x = ∑ x ∈ Finset.range n, f x + f n
ascPochhammer_succ_eval.{u_1} {S : Type u_1} [Semiring S] (n : ℕ) (k : S) :
  Polynomial.eval k (ascPochhammer S (n + 1)) = Polynomial.eval k (ascPochhammer S n) * (k + ↑n)
ascPochhammer_succ_right.{u} (S : Type u) [Semiring S] (n : ℕ) :
  ascPochhammer S (n + 1) = ascPochhammer S n * (Polynomial.X + ↑n)
Fin.sum_univ_eq_sum_range.{u_1} {α : Type u_1} [AddCommMonoid α] (f : ℕ → α) (n : ℕ) :
  ∑ i, f ↑i = ∑ i ∈ Finset.range n, f i
/work/Explore.lean:14:7: error(lean.unknownIdentifier): Unknown constant `Finset.sum_range_le_sum_range_of_subset`
Nat.cast_sub.{u} {R : Type u} [AddGroupWithOne R] {m n : ℕ} (h : m ≤ n) : ↑(n - m) = ↑n - ↑m
/work/Explore.lean:16:7: error(lean.unknownIdentifier): Unknown constant `Finset.sum_div`
Nat.choose_pos {n k : ℕ} : k ≤ n → 0 < n.choose k
Finset.sum_range_succ_sub_sum.{u_4} {M : Type u_4} (f : ℕ → M) {n : ℕ} [AddCommGroup M] :
  ∑ i ∈ Finset.range (n + 1), f i - ∑ i ∈ Finset.range n, f i = f n
 
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom fractions import Fraction as Q\nfrom math import comb\nfrom pathlib import Path\na,b=Q(213,10),Q(71,10)\ndef r(x,n):\n z=Q(1)\n for i in range(n): z*=x+i\n return z\np=[comb(50,k)*r(a,k)*r(b,50-k)/r(a+b,50) for k in range(51)]\ne=[sum((p[k]*Q(comb(k,n),comb(50,n)) for k in range(51)),Q(0)) for n in (10,11)]\nout=f'a={a}, b={b}\\\\nsum={sum(p)}\\\\nmean fraction={sum(p[k]*Q(k,50) for k in range(51))}\\\\nvariance fraction={sum(p[k]*(Q(k,50)-Q(3,4))**2 for k in range(51))}\\\\nevidence10={e[0]}\\\\nevidence11={e[1]}\\\\nprediction={e[1]/e[0]} = {float(e[1]/e[0])}\\\\n'\nprint(out);Path('cycle2-calculation.txt').write_text(out)\nPY\""
}
shell output · exit 0
a=213/10, b=71/10
sum=1
mean fraction=3/4
variance fraction=1/100
evidence10=23689849826939661/275978414373208064
evidence11=2471640998610704631/35325237039770632192
prediction=313/384 = 0.8151041666666666

shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\ns=Path('Moments.lean').read_text().replace('import Mathlib.Tactic.FieldSimp','import Mathlib.Tactic.FieldSimp\\\\nimport Mathlib.Tactic.FinCases\\\\nimport Mathlib.Algebra.Order.BigOperators.Group.Finset')\nold=Path('Cycle1-preserved.lean').read_text()\nstart=old.index('-- k is the original')\nend=old.index('-- Two witnesses')\nold=old[start:end]\n# position prior definitions before compatible\nprior='''-- The finite beta-binomial family for the original black count K in 0,...,50.\n-- Equivalent to drawing a latent propensity from Beta(a,b), then 50 colors.\nnoncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=\n  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50\n\n'''\ns += '\\\\n'+prior+old\nPath('Model.lean').write_text(s)\nPY\ncat >> Model.lean <<'EOF'\n\n-- Derived finite-family moments. No distributional moment identities are axioms.\nlemma prior_moments (a b : ℝ) (ha : 0 < a) (hb : 0 < b) :\n    (∀ k, 0 ≤ prior a b k) ∧ (∑ k, prior a b k) = 1 ∧\n    (∑ k, prior a b k * ((k.val : ℝ)/50)) = a/(a+b) ∧\n    (∑ k, prior a b k * ((k.val : ℝ)/50-a/(a+b))\"'^2) =\n      a*b*(a+b+50)/(50*(a+b)''^2*(a+b+1)) := by\n  have hs : a+b ≠ 0 := ne_of_gt (by linarith)\n  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)\n  have hd : rising (a+b) 50 ≠ 0 := ne_of_gt (rising_pos _ (by linarith) _)\n  have hm := family_sums a b ha hb 50\n  have h0 : (∑ k, prior a b k) = 1 := by\n    unfold prior\n    rw [← Finset.sum_div, Fin.sum_univ_eq_sum_range, hm.1, div_self hd]\n  have h1 : (∑ k, prior a b k * (k.val : ℝ)) = 50*a/(a+b) := by\n    calc\n      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * (k.val : ℝ)) / rising (a+b) 50 := by\n        rw [Finset.sum_div]\n        apply Finset.sum_congr rfl\n        intro k _\n        unfold prior\n        ring\n      _ = _ := by\n        rw [Fin.sum_univ_eq_sum_range, hm.2.1]\n        norm_num\n        exact mul_div_cancel_right₀ _ hd\n  have h2 : (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1))) =\n      50*49*a*(a+1)/((a+b)*(a+b+1)) := by\n    calc\n      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * ((k.val : ℝ)*(k.val-1))) / rising (a+b) 50 := by\n        rw [Finset.sum_div]\n        apply Finset.sum_congr rfl\n        intro k _\n        unfold prior\n        ring\n      _ = _ := by\n        rw [Fin.sum_univ_eq_sum_range, hm.2.2]\n        norm_num\n        exact mul_div_cancel_right₀ _ hd\n  refine ⟨?_, h0, ?_, ?_⟩\n  · intro k\n    exact div_nonneg (mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (rising_pos a ha _)))\n      (le_of_lt (rising_pos b hb _))) (le_of_lt (rising_pos _ (by linarith) _))\n  · calc\n      _ = (∑ k, prior a b k * (k.val : ℝ))/50 := by\n        rw [Finset.sum_div]\n        apply Finset.sum_congr rfl\n        intro k _\n        ring\n      _ = _ := by rw [h1]; ring\n  · calc\n      _ = (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1)))/2500 +\n          (1/2500-2*(a/(a+b))/50)*(∑ k, prior a b k * (k.val : ℝ)) +\n          (a/(a+b))''^2 * (∑ k, prior a b k) := by\n        rw [Finset.sum_div, Finset.mul_sum, Finset.mul_sum,\n          ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]\n        apply Finset.sum_congr rfl\n        intro k _\n        ring\n      _ = _ := by\n        rw [h0, h1, h2]\n        field_simp\n        <;> ring\n\n-- The supplied moments identify the two parameters WITHIN this family.\n-- They do not identify the family itself.\nlemma parameters_from_moments : ∀ a b : ℝ, 0 < a → 0 < b →\n    compatible (prior a b) → a = 213/10 ∧ b = 71/10 := by\n  intro a b ha hb hp\n  have hm := prior_moments a b ha hb\n  have hs : a+b ≠ 0 := ne_of_gt (by linarith)\n  have mean : a/(a+b) = 3/4 := hm.2.2.1.symm.trans hp.2.2.1\n  have variance : a*b*(a+b+50)/(50*(a+b)''^2*(a+b+1)) = 1/100 := by\n    rw [← hm.2.2.2, mean]\n    exact hp.2.2.2\n  have hab : a = 3*b := by\n    have h := (div_eq_iff hs).mp mean\n    linarith\n  have hden : 50*(a+b)''^2*(a+b+1) ≠ 0 := by positivity\n  have hv := (div_eq_iff hden).mp variance\n  rw [hab] at hv\n  have hb0 : b''^2 ≠ 0 := pow_ne_zero _ (ne_of_gt hb)\n  have hpoly : b''^2 * (10*b-71) = 0 := by nlinarith [hv]\n  have hbval : b = 71/10 := by\n    have := (mul_eq_zero.mp hpoly).resolve_left hb0\n    linarith\n  exact ⟨by rw [hab, hbval]; norm_num, hbval⟩\n\n-- Feasibility is proved, so the moment-fitting conditions are not vacuous.\nlemma fitted_prior_compatible : compatible (prior (213/10) (71/10)) := by\n  have hm := prior_moments (213/10) (71/10) (by norm_num) (by norm_num)\n  refine ⟨hm.1, hm.2.1, ?_, ?_⟩\n  · convert hm.2.2.1 using 1 <;> norm_num\n  · convert hm.2.2.2 using 1 <;> norm_num\nEOF\npython compile.py cycle2-01'"
}
shell output · exit 0
1 /work/Model.lean:23:12: warning: `simp` already closes the goal

Hint: Use `simp` instead of `simpa`:
  [apply] simp [rising]

Note: This linter can be disabled with `set_option linter.unnecessarySimpa false`
/work/Model.lean:106:6: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:110:6: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:106:6: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
/work/Model.lean:110:6: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
/work/Model.lean:219:26: error: Tactic `rewrite` failed: Did not find an occurrence of the pattern
  ∑ i, ?f ↑i
in the target expression
  (∑ i, ↑(Nat.choose 50 ↑i) * rising a ↑i * rising b (50 - ↑i)) / rising (a + b) 50 = 1

a b : ℝ
ha : 0 < a
hb : 0 < b
hs : a + b ≠ 0
hs1 : a + b + 1 ≠ 0
hd : rising (a + b) 50 ≠ 0
hm :
  ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) = rising (a + b) 50 ∧
    ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) * ↑k =
        ↑50 * a / (a + b) * rising (a + b) 50 ∧
      ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) * (↑k * (↑k - 1)) =
        ↑50 * (↑50 - 1) * a * (a + 1) / ((a + b) * (a + b + 1)) * rising (a + b) 50
⊢ (∑ i, ↑(Nat.choose 50 ↑i) * rising a ↑i * rising b (50 - ↑i)) / rising (a + b) 50 = 1
/work/Model.lean:229:12: error: Tactic `rewrite` failed: Did not find an occurrence of the pattern
  ∑ i, ?f ↑i
in the target expression
  (∑ k, ↑(Nat.choose 50 ↑k) * rising a ↑k * rising b (50 - ↑k) * ↑↑k) / rising (a + b) 50 = 50 * a / (a + b)

a b : ℝ
ha : 0 < a
hb : 0 < b
hs : a + b ≠ 0
hs1 : a + b + 1 ≠ 0
hd : rising (a + b) 50 ≠ 0
hm :
  ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) = rising (a + b) 50 ∧
    ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) * ↑k =
        ↑50 * a / (a + b) * rising (a + b) 50 ∧
      ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) * (↑k * (↑k - 1)) =
        ↑50 * (↑50 - 1) * a * (a + 1) / ((a + b) * (a + b + 1)) * rising (a + b) 50
h0 : ∑ k, prior a b k = 1
⊢ (∑ k, ↑(Nat.choose 50 ↑k) * rising a ↑k * rising b (50 - ↑k) * ↑↑k) / rising (a + b) 50 = 50 * a / (a + b)
/work/Model.lean:242:12: error: Tactic `rewrite` failed: Did not find an occurrence of the pattern
  ∑ i, ?f ↑i
in the target expression
  (∑ k, ↑(Nat.choose 50 ↑k) * rising a ↑k * rising b (50 - ↑k) * (↑↑k * (↑↑k - 1))) / rising (a + b) 50 =
    50 * 49 * a * (a + 1) / ((a + b) * (a + b + 1))

a b : ℝ
ha : 0 < a
hb : 0 < b
hs : a + b ≠ 0
hs1 : a + b + 1 ≠ 0
hd : rising (a + b) 50 ≠ 0
hm :
  ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) = rising (a + b) 50 ∧
    ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) * ↑k =
        ↑50 * a / (a + b) * rising (a + b) 50 ∧
      ∑ k ∈ Finset.range (50 + 1), ↑(Nat.choose 50 k) * rising a k * rising b (50 - k) * (↑k * (↑k - 1)) =
        ↑50 * (↑50 - 1) * a * (a + 1) / ((a + b) * (a + b + 1)) * rising (a + b) 50
h0 : ∑ k, prior a b k = 1
h1 : ∑ k, prior a b k * ↑↑k = 50 * a / (a + b)
⊢ (∑ k, ↑(Nat.choose 50 ↑k) * rising a ↑k * rising b (50 - ↑k) * (↑↑k * (↑↑k - 1))) / rising (a + b) 50 =
    50 * 49 * a * (a + 1) / ((a + b) * (a + b + 1))
/work/Model.lean:298:29: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:298:29: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
 
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\ns=Path('Model.lean').read_text();s=s[:s.index('lemma rising_pos')]+s[s.index('-- The finite beta-binomial'):s.index('lemma observation_step')]\ns+='''\\\\nlemma fitted_evidence10 : evidence (prior (213/10) (71/10)) 10 =\n    ((23689849826939661 : ℕ) : ℝ)/((275978414373208064 : ℕ) : ℝ) := by\n  norm_num [evidence, prior, likelihood, Fin.sum_univ_succ, rising, Nat.choose]\n\nlemma fitted_evidence11 : evidence (prior (213/10) (71/10)) 11 =\n    ((2471640998610704631 : ℕ) : ℝ)/((35325237039770632192 : ℕ) : ℝ) := by\n  norm_num [evidence, prior, likelihood, Fin.sum_univ_succ, rising, Nat.choose]\n'''\nPath('Numeric.lean').write_text(s)\nPY\npython compile.py numeric Numeric.lean\""
}
shell output · exit 0
1 /work/Numeric.lean:52:41: error(lean.unknownIdentifier): Unknown constant `Fin.sum_univ_succ`
/work/Numeric.lean:51:68: error: unsolved goals
⊢ ∑ x,
      ↑(Nat.choose 50 ↑x) * rising (213 / 10) ↑x * rising (71 / 10) (50 - ↑x) /
          (1788969975678487733504009294936795265331877906839616254730256827667315071722583993821744125837477799461284187201154842624 /
            88817841970012523233890533447265625) *
        (↑((↑x).choose 10) / 10272278170) =
    23689849826939661 / 275978414373208064
/work/Numeric.lean:56:41: error(lean.unknownIdentifier): Unknown constant `Fin.sum_univ_succ`
/work/Numeric.lean:55:72: error: unsolved goals
⊢ ∑ x,
      ↑(Nat.choose 50 ↑x) * rising (213 / 10) ↑x * rising (71 / 10) (50 - ↑x) /
          (1788969975678487733504009294936795265331877906839616254730256827667315071722583993821744125837477799461284187201154842624 /
            88817841970012523233890533447265625) *
        (↑((↑x).choose 11) / 37353738800) =
    2471640998610704631 / 35325237039770632192
 
assistant
The general normalization and moment proofs now compile. They derive the beta-binomial moments from its finite mass function using Pascal’s rule, so those formulas do not need to be extra review assumptions.

The fitted model matches the supplied mean and variance exactly. An independent exact-fraction calculation also gives 313/384 for the prediction. I’m checking the remaining Lean steps before submitting to the actual harness.
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\nimport json\nfor p in Path('/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Algebra').rglob('*.ilean'):\n if 'Fin' in str(p):\n  d=json.loads(p.read_text())\n  for n in d['decls']:\n   if 'sum_univ' in n or 'sum_fin' in n:print(p.relative_to('/harness/.lake/packages/mathlib/.lake/build/lib/lean'),n)\nPY\""
}
shell output · exit 0
Mathlib/Algebra/BigOperators/Finsupp/Basic.ilean Finsupp.sum_finsetSum
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\nimport json\nfor p in Path('/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib').rglob('*.ilean'):\n if 'Fin.sum_univ_succ' in p.read_text():\n  d=json.loads(p.read_text())\n  if 'Fin.sum_univ_succ' in d['decls']:print(p)\nPY\""
}
shell input
{
  "command": "/usr/bin/bash -lc \"find /harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib -name '*Fin*.ilean' | head -40\""
}
shell output · exit 0
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/Fin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Fintype/EquivFin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Nat/Find.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Nat/PrimeFin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/SetLike/Fintype.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/List/Find.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/List/NodupEquivFin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/List/FinRange.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Multiset/Find.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Multiset/Fintype.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Multiset/FinsetOps.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Finsupp/Fin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Finsupp/ToDFinsupp.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Finsupp/Fintype.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Data/Finset/Fin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/Finiteness/Finsupp.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/FiniteLength.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/UniqueFactorizationDomain/Finite.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/FiniteStability.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/TensorProduct/Finite.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/FinitePresentation.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/EssentialFiniteness.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/RingTheory/FiniteType.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/Multilinear/DFinsupp.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/Multilinear/Finsupp.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/DFinsupp.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/Dimension/Finrank.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/Dimension/Finite.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/Basis/Fin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/DirectSum/Finsupp.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/LinearAlgebra/TensorProduct/Finiteness.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/CompleteLattice/Finset.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/Interval/Set/Fin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/Interval/Finset/Fin.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/SuccPred/LinearLocallyFinite.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/Preorder/Finsupp.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/Preorder/Finite.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/Filter/AtTopBot/Finite.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/Filter/AtTopBot/Finset.ilean
/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Order/Filter/Bases/Finite.ilean
shell input
{
  "command": "/usr/bin/bash -lc \"cp Model.lean Cycle2-attempt-01.lean\npython - <<'PY'\nfrom pathlib import Path\np=Path('Model.lean');s=p.read_text()\nf0='(fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k))'\nf1='(fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * (k : ℝ))'\nf2='(fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * ((k : ℝ)*(k-1)))'\ns=s.replace('Fin.sum_univ_eq_sum_range, hm.1',f'Fin.sum_univ_eq_sum_range {f0} 51, hm.1')\ns=s.replace('Fin.sum_univ_eq_sum_range, hm.2.1',f'Fin.sum_univ_eq_sum_range {f1} 51, hm.2.1')\ns=s.replace('Fin.sum_univ_eq_sum_range, hm.2.2',f'Fin.sum_univ_eq_sum_range {f2} 51, hm.2.2')\np.write_text(s)\np=Path('Numeric.lean');s=p.read_text()\nfor n in [10,11]:\n s=s.replace('  norm_num [evidence, prior, likelihood, Fin.sum_univ_succ, rising, Nat.choose]',f'''  unfold evidence prior likelihood\n  rw [Fin.sum_univ_eq_sum_range\n    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /\n      rising (213/10+71/10) 50 * ((Nat.choose k {n} : ℝ)/(Nat.choose 50 {n} : ℝ))) 51]\n  norm_num [Finset.sum_range_succ, rising, Nat.choose]''',1)\np.write_text(s)\nPY\npython compile.py cycle2-02\""
}
shell input
{
  "command": "/usr/bin/bash -lc 'python compile.py numeric2 Numeric.lean'"
}
shell output · exit 0
0 /work/Model.lean:23:12: warning: `simp` already closes the goal

Hint: Use `simp` instead of `simpa`:
  [apply] simp [rising]

Note: This linter can be disabled with `set_option linter.unnecessarySimpa false`
/work/Model.lean:106:6: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:110:6: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:106:6: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
/work/Model.lean:110:6: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
/work/Model.lean:268:8: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:268:8: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
/work/Model.lean:298:29: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:298:29: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
 
shell output · exit 0
0  
shell output · exit 0
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\np=Path('Model.lean');s=p.read_text()\ns+='\\\\n-- Exact evidences for the fitted finite model; computed inside Lean.\\\\n'+Path('Numeric.lean').read_text().split('lemma fitted_evidence10')[1].join([]) if False else s\nnum=Path('Numeric.lean').read_text();num=num[num.index('lemma fitted_evidence10'):]\ns+='\\\\n-- Exact evidences for the fitted finite model; both sums are evaluated in Lean.\\\\n'+num\ns+='''\n-- Conditional scientific answer: any positive-parameter member of the stated\n-- family matching the supplied population moments predicts 313/384.\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    compatible (prior a b) → prediction (prior a b) = 313/384 := by\n  intro a b ha hb hp\n  obtain ⟨ha', hb'⟩ := parameters_from_moments a b ha hb hp\n  rw [ha', hb']\n  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,\n    fitted_evidence11, fitted_evidence10]\n  norm_num\n'''\ns=s.replace('| zero => simpa [rising]', '| zero => simp [rising]')\ns=s.replace('      <;> ring','      ring').replace('        <;> ring','        ring')\ns=s.replace('have hpoly : b\"'^2 * (10*b-71) = 0 := by nlinarith [hv]'\"', 'have hpoly : b\"'^2 * (10*b-71) = 0 := by nlinarith [hv]'\"')\np.write_text(s)\nPY\npython compile.py cycle2-final\""
}
assistant
The model, parameter fit, Bayesian update, and exact evidence calculations compile in Lean. The result is conditional: every positive-parameter beta-binomial model matching the supplied moments predicts **313/384 ≈ 81.51%**.

I’m preparing the compact review packet and running the required extraction and kernel checks. Those checks will not establish that the beta-binomial assumption is true for these boxes; that remains for human review.
shell output · exit 0
1 /work/Model.lean:298:29: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/Model.lean:298:29: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
/work/Model.lean:300:0: error: invalid 'import' command, it must be used in the beginning of the file
 
shell input
{
  "command": "/usr/bin/bash -lc \"cat > report.txt <<'EOF'\nCycle 2: usable Bayesian prediction under an explicit finite-box model\n\nAnswer: 313/384 = 0.8151041666666667, approximately 81.51%, conditional on\nadopting the beta-binomial family for original black counts. The supplied\nmoments alone do not uniquely specify a distribution, so this is a model-based\nanswer, not a probability compelled by those moments without assumptions.\n\nCompact review boundary\n\nSupplied information:\n* Initially 50 black-or-white balls; ten drawn balls were black, without\n  replacement; forty remain. Original black count K is unknown.\n* Across same-kind boxes, the actual original fraction K/50 has mean 3/4 and\n  standard deviation 1/10, hence variance 1/100.\n\nAdditional scientific assumptions:\n* Treat those reported moments as exact population quantities. Their rounding\n  and estimation uncertainty are unavailable; no uncertainty for them is fitted.\n* The particular box is representative of that population before observing its\n  draws, with no additional selection information.\n* Draw uniformly among remaining balls, with fixed colors, and condition on\n  the ten-black event alone. This supplies the hypergeometric likelihood.\n* Choose a beta-binomial distribution for K, with positive, initially UNKNOWN\n  parameters a,b. Equivalently, a box has latent propensity theta ~ Beta(a,b),\n  and its 50 colors are conditionally independent Bernoulli(theta). This is\n  a population model for how boxes are made, not drawing with replacement.\n  No manufacturing evidence was supplied to establish this family. Its shape\n  and conditional independence are substantive assumptions for human review.\n\nNecessary definitions and their Lean names:\n* rising a n = a(a+1)...(a+n-1), with empty product one. This gives a compact,\n  finite formula without assuming any analytic beta-integral identities.\n* prior a b k = choose(50,k) rising(a,k) rising(b,50-k) / rising(a+b,50),\n  for k : Fin 51 (the original black count 0,...,50). This is the beta-binomial\n  mass function, not a continuous law on the finite-grid fraction K/50.\n* compatible p says p is nonnegative, sums to one, and the finite expectations\n  of K/50 and (K/50-3/4)\"'^2 are 3/4 and 1/100. Thus the user moments constrain\n  the actual finite-box distribution, not an unobserved latent propensity.\n* likelihood n k = choose(k,n)/choose(50,n), the probability that a uniform\n  n-subset of the 50 balls is entirely black, conditional on K=k. In the proof\n  the observation lengths used are n=10 and n=11, for which denominators are\n  positive. Uniform-subset counting is the physical justification for this\n  observation model; individual labeled balls are not separately formalized.\n* evidence p n = sum_k p_k likelihood(n,k), the all-black event probability.\n* posterior p k = p_k likelihood(10,k)/evidence(p,10), Bayes conditioning.\n* prediction p = sum_k posterior(p,k) (k-10)/40, the next-black probability.\n  Natural subtraction truncates below ten; these impossible counts have zero\n  ten-black likelihood, so their terms are zero.\n\nProved final conclusion (the only manifest conclusion):\n  theorem answer_theorem : forall a b : real, 0<a -> 0<b ->\n    compatible (prior a b) -> prediction (prior a b) = 313/384.\nPlain language: within the chosen positive-parameter beta-binomial family,\nmatching the population moments and observing the specified ten black draws\nimplies a next-black probability of 313/384. Parameter values are inferred,\nnot independent premises of this theorem.\n\nWhy this family, and how the parameters are inferred\n\nAn ordinary Binomial(50,3/4) population model would give fraction variance\n(3/4)(1/4)/50 = 0.00375, smaller than the reported 0.01. Random box propensities\nallow positive association among colors within a box and this extra population\nvariation. A beta mixing distribution is a conventional, bounded two-parameter\nchoice, permitting the two supplied moments to determine its parameters. Its\nconjugacy also gives a transparent update. This is a justified conditional\nmodeling choice, not an assertion that every distribution sharing these two\nmoments is beta-binomial, or that the data identify its shape.\n\nLet s=a+b and mu=a/s. The finite beta-binomial mass function has\n  E[K/50] = mu,\n  Var(K/50) = mu(1-mu)(s+50)/(50(s+1)).\nThe finite-box variation is essential. Substituting mu=3/4 and variance=1/100\nand clearing denominators gives\n  50(1/100)(s+1) = (3/16)(s+50),\nso s=142/5=28.4, a=mu*s=213/10=21.3, b=(1-mu)*s=71/10=7.1.\nThese are the unique positive parameters in the family matching the moments.\nThe usual continuous beta moment fit applied directly to K/50 would use a\nvariance for the wrong random variable. Here the latent propensity variance is\n(3/16)/(s+1), while the actual fraction variance is the stated 1/100.\n\nBayes updating and the scientific prediction\n\nFor the original count K=k, the exact observation likelihood is\n  L10(k)=choose(k,10)/choose(50,10).\nThe posterior on K is proportional to prior(k)*L10(k). Given this count and\nthe observation, there are k-10 black balls among forty. Averaging (k-10)/40\nover the posterior gives the answer. The formal observation_step establishes\n  L10(k)*(k-10)/40 = L11(k)\nfor every one of the 51 possible original counts. Consequently the prediction\nis evidence(11)/evidence(10). The fitted finite sums evaluate exactly to\n  evidence(10) = 23689849826939661 / 275978414373208064,\n  evidence(11) = 2471640998610704631 / 35325237039770632192,\nand their ratio is 313/384. These sums are evaluated by Lean, independently of\nthe Python calculation retained in cycle2-calculation.txt.\n\nThe equivalent latent-propensity explanation is theta | ten black ~\nBeta(a+10,b), giving (a+10)/(a+b+10)=31.3/38.4=313/384. The finite proof uses\nthe count posterior above, not an assumed posterior-beta rule. Thus it explicitly\naccounts for removing ten balls. It does not mistake the prior expectation for\nthe fraction still remaining or treat the unknown count as fixed at its mean.\n\nFormal proof coverage\n\nweighted_sum_step is a Pascal-rule recurrence for finite rising-factorial\nweighted sums. family_sums proves their normalization, first count moment and\nsecond factorial count moment simultaneously by induction for every population\nsize n and positive real a,b. prior_moments derives nonnegative masses, total\nmass one, the mean and central variance for n=50. These generic formulas are\nproved, not additional axioms or literature premises. parameters_from_moments\nthen solves the user moment constraints, and fitted_prior_compatible proves\nfeasibility at the derived solution, so the inference conditions are nonvacuous.\n\nThe supporting bayesian_answer lemma proves that conditioning has positive\nevidence for any compatible prior, that the posterior is nonnegative and sums\nto one, that it satisfies the finite-event Bayes identity, and that the posterior\nnext-draw expectation equals evidence(11)/evidence(10). Its positivity proof\nuses the supplied mean: a distribution supported only on counts below ten\ncannot have mean fraction 3/4. The final theorem combines this general Bayesian\nupdate with parameter inference and the two exact evidence calculations.\n\nNo sorry, new axioms, external computed-number premises, or unproved scientific\nlemmas are used. The kernel certifies mathematical implications of the exposed\nmodel. It does not certify population representativeness, manufacturing\nindependence, unbiased physical sampling, exactness of reported moments, or\nthat the chosen family is scientifically true. The beta mixture interpretation\nis the motivation for the finite mass function; no continuous measure-theoretic\nbeta-density construction is claimed as formalized.\n\nSources and limitations\n\nGeneral primary reference consulted on the Internet during this cycle:\nR-INLA, '\"'Beta-binomial', p.1,\nhttps://inla.r-inla-download.org/r-inla.org/doc/likelihood/betabinomial.pdf\nIt describes the beta/binomial hierarchy and gives the count mass function,\nmean and variance. It supplies neither this task's parameters nor its prediction.\nThe family normalization and moments are independently derived in Lean.\nThe supplied numerical observations come from the user's task, not literature.\nNo operator request was made and no response ID is invented or incorporated.\n\nMoments do not establish this family or a unique prediction across all priors.\nDifferent plausible population families may yield different answers. Population\ncount frequencies, manufacturing information, or a sample size for the reported\nmoments would help evaluate or refine this model. No human acceptance is claimed.\n\nLineage and real diagnostic history\n\nCycle 1 is preserved in Cycle1-preserved.lean, Cycle1-preserved-report.txt and\nCycle1-preserved-candidate.json, with its original checks and raw logs. Its first\ncheck failed independent extraction; explicit natural-to-real numeral casts\nfixed that elaboration mismatch, and check 589b8c8ad6124887b939666f670c9191\nreported proved. The human nevertheless rejected its scientific content\n(human-feedback.json): it gave nonuniqueness witnesses without a usable\nscientifically justified predictive model. Cycle 2 accepts that feedback:\nit replaces the counterexample-focused family with an explicit beta-binomial\nmodel, derives its parameters, and gives a usable conditional prediction.\nNonuniqueness remains only a limitation. This is a substantive model revision,\nnot a claim that the rejected candidate was acceptable.\n\nCycle 2 local raw traces are local-moments.log, local-cycle2-01.log,\nlocal-cycle2-02.log, local-numeric.log, local-numeric2.log and\nlocal-cycle2-final.log. The first general moments proof compiled. Integration\ninitially failed to infer functions in a Fin-to-range sum rewrite; explicit\nfunctions fixed it. The initial evidence evaluation referred to an unavailable\nFin.sum_univ_succ; explicit Fin-to-range rewriting and sum_range_succ fixed it.\nThese were technical repairs, with the model and target prediction unchanged.\nCycle2-attempt-01.lean and Numeric.lean retain those proof-development paths;\nraw protocol check traces are retained in checks/. Only the actual latest\ncheck verdict establishes verification status; a failed or unknown check is\nnot success, and mathematical verification is not human scientific approval.\nEOF\npython - <<'PY'\nimport json\nfrom pathlib import Path\nc={\n 'proof_file':'Model.lean','narrative_file':'report.txt',\n 'conclusions':{'next_black_probability':'answer_theorem'},\n 'user_facts':[\n  'Initially 50 balls, black or white; ten drawn were all black without replacement; forty remain; original count unknown.',\n  'Across same-kind boxes, actual initial black fraction K/50 has mean 0.75 and standard deviation 0.1.'\n ],\n 'model_choices':[\n  'Treat supplied moments as exact population values; no sampling uncertainty or rounding information is available.',\n  'The particular box is representative of that population before observing its draws, with no additional selection information.',\n  'Uniform sampling without replacement and fixed colors give all-black likelihood choose(K,n)/choose(50,n); condition on the ten-black event alone.',\n  'Original count K has a beta-binomial(50,a,b) distribution with initially unknown positive real parameters. This is a substantive family choice motivated by finite support and overdispersion, equivalent to a beta latent box propensity with conditionally independent ball colors. Population moments do not establish the family.',\n  'Parameters are derived from finite-family moment constraints, not independently assumed: a=213/10 and b=71/10. Family moments and uniqueness of this fit are proved in Lean.'\n ],\n 'sources':[\n  'User task: population moments, box size, observed ten black draws and no replacement.',\n  'Host-recorded human rejection and /work/human-feedback.json: revise from nonuniqueness examples to a usable justified conditional prediction.',\n  'R-INLA, Beta-binomial, p.1, https://inla.r-inla-download.org/r-inla.org/doc/likelihood/betabinomial.pdf ; general hierarchy, mass function and moments, consulted online in cycle 2. No task-specific solution or parameters obtained.'\n ],\n 'incorporated_inputs':[],\n 'proof_scope':'Derives finite beta-binomial normalization and first two factorial moments by induction for arbitrary positive real parameters, then the actual fraction mean and variance. Proves supplied moments uniquely imply a=21.3,b=7.1 within this family and verifies feasibility. For the explicit hypergeometric observation model proves positive evidence, normalized nonnegative Bayes posterior and next-draw expectation equal to evidence(11)/evidence(10). Evaluates the fitted finite evidences in Lean and proves the final conditional prediction 313/384. No added axioms or sorry. Physical sampling, representative selection, exact population moments and beta-binomial family truth remain for human review; no human approval claimed.'\n}\nPath('candidate.json').write_text(json.dumps(c,indent=2)+'\\\\n')\nPY\""
}
shell output · exit 0
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\np=Path('Model.lean');s=p.read_text();i=s.find('import Mathlib.',1)\nassert i>0\ns=s[i:]\np.write_text(s)\nPY\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json\""
}
shell output · exit 1 · failed
{
  "ok": false,
  "check_complete": false,
  "reviewable": false,
  "verdict": "not_proved",
  "time": "2026-11-16T16:11:17.655886+00:00",
  "error": "Lean body must contain at most 24000 UTF-8 bytes"
}
shell input
{
  "command": "/usr/bin/bash -lc \"wc -c Model.lean; head -20 Model.lean; sed -n '288,325p' Model.lean; tail -30 Model.lean\""
}
shell output · exit 0
27730 Model.lean
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- Rising factorial: a(a+1)...(a+n-1).
noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

lemma rising_pos : ∀ a : ℝ, 0 < a → ∀ n, 0 < rising a n := by
  intro a ha n
  have hbval : b = 71/10 := by
    have := (mul_eq_zero.mp hpoly).resolve_left hb0
    linarith
  exact ⟨by rw [hab, hbval]; norm_num, hbval⟩

-- Feasibility is proved, so the moment-fitting conditions are not vacuous.
lemma fitted_prior_compatible : compatible (prior (213/10) (71/10)) := by
  have hm := prior_moments (213/10) (71/10) (by norm_num) (by norm_num)
  refine ⟨hm.1, hm.2.1, ?_, ?_⟩
  · convert hm.2.2.1 using 1 <;> norm_num
  · convert hm.2.2.2 using 1 <;> norm_num
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- Rising factorial: a(a+1)...(a+n-1).
noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

lemma rising_pos : ∀ a : ℝ, 0 < a → ∀ n, 0 < rising a n := by
  intro a ha n
  induction n with
  | zero => simp [rising]
  | succ n ih => exact mul_pos ih (by positivity)

-- A general Pascal-rule recurrence, used only to derive the family moments.
lemma weighted_sum_step (a b : ℝ) (f : ℕ → ℝ) (n : ℕ) :
  · convert hm.2.2.1 using 1 <;> norm_num
  · convert hm.2.2.2 using 1 <;> norm_num

-- Exact evidences for the fitted finite model; both sums are evaluated in Lean.
lemma fitted_evidence10 : evidence (prior (213/10) (71/10)) 10 =
    ((23689849826939661 : ℕ) : ℝ)/((275978414373208064 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 10 : ℝ)/(Nat.choose 50 10 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

lemma fitted_evidence11 : evidence (prior (213/10) (71/10)) 11 =
    ((2471640998610704631 : ℕ) : ℝ)/((35325237039770632192 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 11 : ℝ)/(Nat.choose 50 11 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

-- Conditional scientific answer: any positive-parameter member of the stated
-- family matching the supplied population moments predicts 313/384.
theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →
    compatible (prior a b) → prediction (prior a b) = 313/384 := by
  intro a b ha hb hp
  obtain ⟨ha', hb'⟩ := parameters_from_moments a b ha hb hp
  rw [ha', hb']
  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,
    fitted_evidence11, fitted_evidence10]
  norm_num
shell input
{
  "command": "/usr/bin/bash -lc \"cp Model.lean Cycle2-assembly-error.lean\npython - <<'PY'\nfrom pathlib import Path\np=Path('Model.lean');s=p.read_text();i=s.index('import Mathlib.Basic.Real.Basic');p.write_text(s[i:])\np=Path('report.txt');s=p.read_text();s+='\\\\nFinal assembly initially duplicated the proof body (local-cycle2-final.log).\\\\nThe first protocol invocation rejected the overlong body before checking Lean:\\\\n\\\"Lean body must contain at most 24000 UTF-8 bytes\\\". The duplicate was removed,\\\\nwith the failed assembly retained in Cycle2-assembly-error.lean. This did not\\\\nchange any scientific assumptions or mathematical statements.\\\\n';p.write_text(s)\nPY\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json\""
}
shell input
{
  "command": "/usr/bin/bash -lc 'ls -lt checks | head -6; wc -c Model.lean report.txt'"
}
shell output · exit 0
total 16
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:11 1979df9673ad4e099fa055acb34fad8a
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:11 f686d2bc798c48a3a791bc4eba6251b5
drwxr-xr-x 2 1001 1001 4096 Nov 16 15:39 589b8c8ad6124887b939666f670c9191
drwxr-xr-x 2 1001 1001 4096 Nov 16 15:36 d3b2ddd0289f4b9c92d67be787fe45dc
14614 Model.lean
10624 report.txt
25238 total
assistant
The first harness invocation rejected an accidentally duplicated proof body for exceeding its size limit. I removed the duplicate and preserved the error trace; the scientific statements are unchanged. The full check is now running.

I also found a useful simplification to the final statement: it can assume just the two supplied moment equations and positive family parameters. Normalization and nonnegative probabilities have already been proved.
shell input
{
  "command": "/usr/bin/bash -lc 'ls -l checks/1979df9673ad4e099fa055acb34fad8a; cat checks/1979df9673ad4e099fa055acb34fad8a/lean.log'"
}
shell output · exit 0
total 80
-rw-r--r-- 1 1001 1001 17779 Nov 16 16:11 Checked.lean
-rw-r--r-- 1 1001 1001 20881 Nov 16 16:12 extracted.probe.lean
-rw-r--r-- 1 1001 1001   552 Nov 16 16:12 lean.log
-rw------- 1 1001 1001  2611 Nov 16 16:11 submitted-candidate.json
-rw-r--r-- 1 1001 1001 10624 Nov 16 16:11 submitted-report.txt
-rw-r--r-- 1 1001 1001 14614 Nov 16 16:11 submitted.lean
/work/checks/1979df9673ad4e099fa055acb34fad8a/Checked.lean:298:29: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/checks/1979df9673ad4e099fa055acb34fad8a/Checked.lean:298:29: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
'answer_theorem' depends on axioms: [propext, Classical.choice, Quot.sound]
VAS_LISTED

leanchecker exit 0

shell input
{
  "command": "/usr/bin/bash -lc \"cp Model.lean Cycle2-before-boundary-simplification.lean\npython - <<'PY'\nfrom pathlib import Path\np=Path('Model.lean');s=p.read_text();s=s[:s.index('theorem answer_theorem')]+'''theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50)) = 3/4 →\n    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50-3/4)\"'^2) = 1/100 →\n    prediction (prior a b) = 313/384 := by\n  intro a b ha hb hmean hvariance\n  have hm := prior_moments a b ha hb\n  have hp : compatible (prior a b) := ⟨hm.1, hm.2.1, hmean, hvariance⟩\n  obtain ⟨ha'\"', hb'⟩ := parameters_from_moments a b ha hb hp\n  rw [ha', hb']\n  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,\n    fitted_evidence11, fitted_evidence10]\n  norm_num\n'''\np.write_text(s)\np=Path('report.txt');s=p.read_text()\ns=s.replace('* compatible p says p is nonnegative, sums to one, and the finite expectations\\\\n  of K/50 and (K/50-3/4)\"'^2 are 3/4 and 1/100. Thus the user moments constrain'\"\\\\n  the actual finite-box distribution, not an unobserved latent propensity.\\\\n','')\ns=s.replace('    compatible (prior a b) -> prediction (prior a b) = 313/384.', '''    (sum_k prior(a,b,k)*(k/50) = 3/4) ->\n    (sum_k prior(a,b,k)*(k/50-3/4)\"'^2 = 1/100) ->\n    prediction (prior a b) = 313/384.'\"''')\ns=s.replace('The supporting bayesian_answer lemma proves that conditioning has positive', '''The proof helper compatible p combines nonnegative masses, normalization and\nthese two supplied moment equations. It is not an extra assumption in the final\nstatement: nonnegativity and normalization follow from positive family\nparameters, as proved in prior_moments. The public statement retains just\nparameter positivity and the two supplied population moment equations.\n\nThe supporting bayesian_answer lemma proves that conditioning has positive''')\ns+='\\\\nBefore final submission the public statement was simplified to list the two\\\\nuser moment equations directly. Nonnegativity and normalization were removed\\\\nfrom its premises because they are derived from the family. The prediction,\\\\nmodel and parameter fit are unchanged. The earlier boundary is preserved in\\\\nCycle2-before-boundary-simplification.lean.\\\\n'\np.write_text(s)\nPY\""
}
shell output · exit 0
shell input
{
  "command": "/usr/bin/bash -lc 'ls -l checks/1979df9673ad4e099fa055acb34fad8a; cat checks/f686d2bc798c48a3a791bc4eba6251b5/verdict.json'"
}
shell output · exit 0
total 80
-rw-r--r-- 1 1001 1001 17779 Nov 16 16:11 Checked.lean
-rw-r--r-- 1 1001 1001 20881 Nov 16 16:12 extracted.probe.lean
-rw-r--r-- 1 1001 1001   552 Nov 16 16:12 lean.log
-rw------- 1 1001 1001  2611 Nov 16 16:11 submitted-candidate.json
-rw-r--r-- 1 1001 1001 10624 Nov 16 16:11 submitted-report.txt
-rw-r--r-- 1 1001 1001 14614 Nov 16 16:11 submitted.lean
{
  "ok": false,
  "check_complete": false,
  "reviewable": false,
  "verdict": "not_proved",
  "time": "2026-11-16T16:11:17.655886+00:00",
  "error": "Lean body must contain at most 24000 UTF-8 bytes"
}
shell output · exit 1 · failed
{
 "file": "/work/checks/1979df9673ad4e099fa055acb34fad8a/submitted.lean",
 "conclusions": [
  "answer_theorem"
 ],
 "lean_exit": 0,
 "ok": false,
 "compiles_alone": true,
 "faithful": {
  "answer_theorem": false
 },
 "assumption_declarations": [
  "rising",
  "prior",
  "compatible",
  "likelihood",
  "evidence",
  "posterior",
  "prediction"
 ],
 "identity_method": "kernel-expression-repr-v1",
 "conclusion_identities": {
  "answer_theorem": {
   "original_sha256": "4ef8987f94845270f42cba897aa50a4eb123d3b4c8193ce03b73b5c0fab3e115",
   "extracted_sha256": "a3b97d3b7781da234e85ffd5e85b4b7df2ab755fbb613c770357c6fe53c35644"
  }
 },
 "dependency_faithful": {
  "compatible": true,
  "compatible._proof_1": true,
  "compatible._proof_2": true,
  "compatible._proof_3": true,
  "compatible._proof_4": true,
  "prior": true,
  "rising": true,
  "rising._f": true,
  "rising.match_1": true,
  "prediction": true,
  "posterior": true,
  "likelihood": true,
  "evidence": true,
  "prediction._proof_1": true
 },
 "dependency_identities": {
  "compatible": {
   "original_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7",
   "extracted_sha256": "3f5a18fedbef8d3603cd8aedd33d23cb38ce5939cc17377bb4ae152bb4a3ffd7"
  },
  "compatible._proof_1": {
   "original_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52",
   "extracted_sha256": "b72c8e5d64de311f5f6da844e4f4d9a0889ed1bcade11c998a8a85830fc77b52"
  },
  "compatible._proof_2": {
   "original_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1",
   "extracted_sha256": "5b8dc4e7dfc14b328d72030c801202919be7dde430a9fe4e86b2f03d65f5c3b1"
  },
  "compatible._proof_3": {
   "original_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2",
   "extracted_sha256": "824e3350fac12338087ba6aa697f4b06547dbeb25cc2283e5261677fe2759ae2"
  },
  "compatible._proof_4": {
   "original_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472",
   "extracted_sha256": "7bb889d46cc76bcb2cc9e5e670df469595a74df8cf7126322071ab7c0be53472"
  },
  "prior": {
   "original_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2",
   "extracted_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2"
  },
  "rising": {
   "original_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e",
   "extracted_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e"
  },
  "rising._f": {
   "original_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800",
   "extracted_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800"
  },
  "rising.match_1": {
   "original_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf",
   "extracted_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf"
  },
  "prediction": {
   "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
   "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
  },
  "posterior": {
   "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
   "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
  },
  "likelihood": {
   "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
   "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
  },
  "evidence": {
   "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
   "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
  },
  "prediction._proof_1": {
   "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
   "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
  }
 },
 "unranged": [],
 "added_assumptions": [],
 "conclusions_as_proved": {
  "answer_theorem": "\u2200 (a b : \u211d), 0 < a \u2192 0 < b \u2192 compatible (prior a b) \u2192 prediction (prior a b) = 313 / 384"
 },
 "extracted_file": "/work/checks/1979df9673ad4e099fa055acb34fad8a/extracted.lean",
 "errors": []
}
{
  "ok": false,
  "check_complete": false,
  "reviewable": false,
  "verdict": "not_proved",
  "time": "2026-11-16T16:11:29.006847+00:00",
  "lean_exit": 0,
  "error": "independent extraction failed"
}
shell input
{
  "command": "/usr/bin/bash -lc 'cat diagnose.py; head -60 checks/1979df9673ad4e099fa055acb34fad8a/extracted.lean; head -40 diagnostic-original.lean'"
}
shell output · exit 0
import sys,pathlib
sys.path.insert(0,'/harness/src')
import vcs_extract as v
root=pathlib.Path('/work')
t='moments_do_not_identify_answer'
for which,src,tail in [
 ('original',(root/'Model.lean').read_text(),v.REACH.replace('TARGETS','[``'+t+']')),
 ('extracted',(root/'checks/d3b2ddd0289f4b9c92d67be787fe45dc/extracted.lean').read_text(),v.COMPARE.replace('NAMES','[``conclusion_'+t+']').replace('DEPENDENCIES','[]'))]:
 path=root/('diagnostic-'+which+'.lean')
 path.write_text(src+'\n'+v.IDENTITY+tail)
 status,out=v.run_lean(path)
 (root/('diagnostic-'+which+'.log')).write_text(out)
 print(which,status)
 if which=='original':
  a=v.expression_identities(out,'VAS_ORIGINAL_IDENTITY')[t]
 else:
  b=v.expression_identities(out,'VAS_EXTRACTED_IDENTITY')['conclusion_'+t]
import difflib
(root/'identity-diff.txt').write_text('\n'.join(difflib.ndiff(a.split(', '),b.split(', '))))
print('original length',len(a),'extracted',len(b))
print('\n'.join(x for x in difflib.ndiff(a.split(', '),b.split(', ')) if x.startswith(('- ','+ ','? '))))
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

noncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=
  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50

def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40


/-! Conclusions (statements of the proved theorems). -/
def conclusion_answer_theorem : Prop := ∀ a b : ℝ, 0 < a → 0 < b → compatible (prior a b) → prediction (prior a b) = 313/384
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
shell input
{
  "command": "/usr/bin/bash -lc \"python - <<'PY'\nfrom pathlib import Path\ns=Path('diagnose.py').read_text().replace(\\\"t='moments_do_not_identify_answer'\\\",\\\"t='answer_theorem'\\\")\ns=s.replace(\\\"(root/'Model.lean')\\\",\\\"(root/'checks/1979df9673ad4e099fa055acb34fad8a/submitted.lean')\\\")\ns=s.replace('checks/d3b2ddd0289f4b9c92d67be787fe45dc','checks/1979df9673ad4e099fa055acb34fad8a')\ns=s.replace(\\\"'diagnostic-'\\\",\\\"'cycle2-diagnostic-'\\\").replace(\\\"'identity-diff.txt'\\\",\\\"'cycle2-identity-diff.txt'\\\")\nPath('cycle2-diagnose.py').write_text(s)\np=Path('Model.lean');s=p.read_text().replace('prediction (prior a b) = 313/384 := by','prediction (prior a b) = ((313 : ℕ) : ℝ)/((384 : ℕ) : ℝ) := by');p.write_text(s)\np=Path('report.txt');s=p.read_text();s+='\\\\nCheck 1979df9673ad4e099fa055acb34fad8a compiled and passed leanchecker,\\\\nbut failed exact conclusion extraction (faithful=false); all model definition\\\\ndependencies were faithful. It is recorded as not_proved, not success.\\\\nThe final ratio is now spelled with explicit natural-to-real casts for 313\\\\nand 384, following the numeral-elaboration issue identified in cycle 1.\\\\nCycle2 diagnostic files retain the actual expression comparison. The ratio\\\\nand scientific content are unchanged; the next actual check decides validity.\\\\n';p.write_text(s)\nPY\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json\""
}
shell input
{
  "command": "/usr/bin/bash -lc 'python cycle2-diagnose.py'"
}
assistant
The full Lean proof and separate kernel check passed, but the harness’s exact statement comparison failed. That submission therefore remains **not proved** under the protocol.

I’ve rewritten the same final ratio using explicit natural-number-to-real casts, addressing the numeral-elaboration issue seen in the previous cycle. I’m rerunning the check with the simplified moment premises. The model and prediction are unchanged.
shell output · exit 0
original 0
extracted 0
original length 4424 extracted 3228
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 313))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 313))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 312))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 312))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 311))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 311))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 384))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 384))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 383))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 383))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 382))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 382)))))))))) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 313))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 313))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_1 [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 384))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 384))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_2 []))))) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)) (Lean.BinderInfo.default)
shell input
{
  "command": "/usr/bin/bash -lc 'ls -lt checks | head -6; tail -25 Model.lean'"
}
shell output · exit 0
total 20
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:14 e0c7eb186fb646479deb5e3acccc85a4
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:12 1979df9673ad4e099fa055acb34fad8a
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:11 f686d2bc798c48a3a791bc4eba6251b5
drwxr-xr-x 2 1001 1001 4096 Nov 16 15:39 589b8c8ad6124887b939666f670c9191
drwxr-xr-x 2 1001 1001 4096 Nov 16 15:36 d3b2ddd0289f4b9c92d67be787fe45dc
      rising (213/10+71/10) 50 * ((Nat.choose k 10 : ℝ)/(Nat.choose 50 10 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

lemma fitted_evidence11 : evidence (prior (213/10) (71/10)) 11 =
    ((2471640998610704631 : ℕ) : ℝ)/((35325237039770632192 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 11 : ℝ)/(Nat.choose 50 11 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

-- Conditional scientific answer: any positive-parameter member of the stated
-- family matching the supplied population moments predicts 313/384.
theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →
    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50)) = 3/4 →
    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50-3/4)^2) = 1/100 →
    prediction (prior a b) = ((313 : ℕ) : ℝ)/((384 : ℕ) : ℝ) := by
  intro a b ha hb hmean hvariance
  have hm := prior_moments a b ha hb
  have hp : compatible (prior a b) := ⟨hm.1, hm.2.1, hmean, hvariance⟩
  obtain ⟨ha', hb'⟩ := parameters_from_moments a b ha hb hp
  rw [ha', hb']
  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,
    fitted_evidence11, fitted_evidence10]
  norm_num
shell output · exit 1 · failed
{
 "file": "/work/checks/e0c7eb186fb646479deb5e3acccc85a4/submitted.lean",
 "conclusions": [
  "answer_theorem"
 ],
 "lean_exit": 0,
 "ok": false,
 "compiles_alone": true,
 "faithful": {
  "answer_theorem": false
 },
 "assumption_declarations": [
  "rising",
  "prior",
  "likelihood",
  "evidence",
  "posterior",
  "prediction"
 ],
 "identity_method": "kernel-expression-repr-v1",
 "conclusion_identities": {
  "answer_theorem": {
   "original_sha256": "716ca1fd3b702dededc1aee9ebad9bd296f6a7717df3af54421d7efe2b5dcb7a",
   "extracted_sha256": "3f9719a2a6be93a587b0cbc04d1e220646c2ef85bfa4972c422ff847bced72c6"
  }
 },
 "dependency_faithful": {
  "prior": true,
  "rising": true,
  "rising._f": true,
  "rising.match_1": true,
  "prediction": true,
  "posterior": true,
  "likelihood": true,
  "evidence": true,
  "prediction._proof_1": true
 },
 "dependency_identities": {
  "prior": {
   "original_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2",
   "extracted_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2"
  },
  "rising": {
   "original_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e",
   "extracted_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e"
  },
  "rising._f": {
   "original_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800",
   "extracted_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800"
  },
  "rising.match_1": {
   "original_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf",
   "extracted_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf"
  },
  "prediction": {
   "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
   "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
  },
  "posterior": {
   "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
   "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
  },
  "likelihood": {
   "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
   "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
  },
  "evidence": {
   "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
   "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
  },
  "prediction._proof_1": {
   "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
   "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
  }
 },
 "unranged": [],
 "added_assumptions": [],
 "conclusions_as_proved": {
  "answer_theorem": "\u2200 (a b : \u211d), 0 < a \u2192 0 < b \u2192 \u2211 k, prior a b k * (\u2191\u2191k / 50) = 3 / 4 \u2192 \u2211 k, prior a b k * (\u2191\u2191k / 50 - 3 / 4) ^ 2 = 1 / 100 \u2192 prediction (prior a b) = \u2191313 / \u2191384"
 },
 "extracted_file": "/work/checks/e0c7eb186fb646479deb5e3acccc85a4/extracted.lean",
 "errors": []
}
{
  "ok": false,
  "check_complete": false,
  "reviewable": false,
  "verdict": "not_proved",
  "time": "2026-11-16T16:13:26.208602+00:00",
  "lean_exit": 0,
  "error": "independent extraction failed"
}
shell input
{
  "command": "/usr/bin/bash -lc 'ls -l checks/e0c7eb186fb646479deb5e3acccc85a4; cat checks/e0c7eb186fb646479deb5e3acccc85a4/lean.log'"
}
shell output · exit 0
total 68
-rw-r--r-- 1 1001 1001 18047 Nov 16 16:13 Checked.lean
-rw-r--r-- 1 1001 1001  3131 Nov 16 16:14 extracted.json
-rw-r--r-- 1 1001 1001  1357 Nov 16 16:14 extracted.lean
-rw-r--r-- 1 1001 1001   552 Nov 16 16:14 lean.log
-rw------- 1 1001 1001  2611 Nov 16 16:13 submitted-candidate.json
-rw-r--r-- 1 1001 1001 11702 Nov 16 16:13 submitted-report.txt
-rw-r--r-- 1 1001 1001 14882 Nov 16 16:13 submitted.lean
-rw------- 1 1001 1001   203 Nov 16 16:14 verdict.json
/work/checks/e0c7eb186fb646479deb5e3acccc85a4/Checked.lean:298:29: warning: Unused tactic linter: `<;>` should be replaced with `;` or be removed.

Note: This linter can be disabled with `set_option linter.unusedTactic false`
/work/checks/e0c7eb186fb646479deb5e3acccc85a4/Checked.lean:298:29: warning: Used `tac1 <;> tac2` where `(tac1; tac2)` would suffice

Note: This linter can be disabled with `set_option linter.unnecessarySeqFocus false`
'answer_theorem' depends on axioms: [propext, Classical.choice, Quot.sound]
VAS_LISTED

leanchecker exit 0

shell input
{
  "command": "/usr/bin/bash -lc \"cat checks/e0c7eb186fb646479deb5e3acccc85a4/extracted.lean\npython - <<'PY'\nfrom pathlib import Path\ns=Path('cycle2-diagnose.py').read_text().replace('1979df9673ad4e099fa055acb34fad8a','e0c7eb186fb646479deb5e3acccc85a4')\ns=s.replace('cycle2-diagnostic-','cycle2b-diagnostic-').replace('cycle2-identity-diff','cycle2b-identity-diff')\nPath('cycle2b-diagnose.py').write_text(s)\nPY\npython cycle2b-diagnose.py\""
}
shell input
{
  "command": "/usr/bin/bash -lc 'ls -l cycle2b*'"
}
shell output · exit 0
-rw-r--r-- 1 1001 1001  1090 Nov 16 16:15 cycle2b-diagnose.py
-rw-r--r-- 1 1001 1001 17983 Nov 16 16:15 cycle2b-diagnostic-original.lean
shell output · exit 0
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

noncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=
  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50

noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40


/-! Conclusions (statements of the proved theorems). -/
def conclusion_answer_theorem : Prop := ∀ a b : ℝ, 0 < a → 0 < b → (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50)) = 3/4 → (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50-3/4)^2) = 1/100 → prediction (prior a b) = ((313 : ℕ) : ℝ)/((384 : ℕ) : ℝ)
original 0
extracted 0
original length 20053 extracted 15911
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.cast [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Fin.val []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 51))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 51))))) (Lean.Expr.bvar 0)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 49))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 49))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 48))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 48)))))))))) (Lean.BinderInfo.default)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.cast [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Fin.val []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 51))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 51))))) (Lean.Expr.bvar 0)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_1 []))))) (Lean.BinderInfo.default)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 2))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 2))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 1))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 1))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 3))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 2))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 2)))))))))) (Lean.Expr.forallE Lean.Name.anonymous (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Eq [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Finset.sum [Lean.Level.zero
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_2 [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_3 []))))) (Lean.Expr.forallE Lean.Name.anonymous (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Eq [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Finset.sum [Lean.Level.zero
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.cast [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Fin.val []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 51))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 51))))) (Lean.Expr.bvar 0)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 49))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 49))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 48))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 48)))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.cast [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Fin.val []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 51))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 51))))) (Lean.Expr.bvar 0)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 50))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_1 []))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 2))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 2))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 1))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 1))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 3))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 2))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 2))))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 2))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 2)))))) (Lean.BinderInfo.default)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 3))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_2 [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 4))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_3 [])))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 2))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 2)))))) (Lean.BinderInfo.default)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
- Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 1))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `One.toOfNat1 [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instOne [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 100))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 100))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Nat.instAtLeastTwoHAddOfNat []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 99))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 99))))) (Lean.Expr.app (Lean.Expr.const `Nat.instNeZeroSucc []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Nat [])) (Lean.Expr.lit (Lean.Literal.natVal 98))) (Lean.Expr.app (Lean.Expr.const `instOfNatNat []) (Lean.Expr.lit (Lean.Literal.natVal 98)))))))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Eq [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `prior []) (Lean.Expr.bvar 5)) (Lean.Expr.bvar 4)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
+ Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instHDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `DivInvMonoid.toDiv [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instDivInvMonoid [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 1))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `One.toOfNat1 [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.const `Real.instOne [])))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `OfNat.ofNat [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 100))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `instOfNatAtLeastTwo [Lean.Level.zero]) (Lean.Expr.const `Real [])) (Lean.Expr.lit (Lean.Literal.natVal 100))) (Lean.Expr.const `Real.instNatCast [])) (Lean.Expr.const `conclusion_answer_theorem._proof_4 []))))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `Eq [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Real [])) (Lean.Expr.app (Lean.Expr.const `prediction []) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `prior []) (Lean.Expr.bvar 5)) (Lean.Expr.bvar 4)))) (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.app (Lean.Expr.const `HDiv.hDiv [Lean.Level.zero
shell input
{
  "command": "/usr/bin/bash -lc \"cp Model.lean Cycle2-direct-moments-extraction-failure.lean\npython - <<'PY'\nfrom pathlib import Path\np=Path('Model.lean');s=p.read_text();s=s.replace('    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50)) = 3/4 →','    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/((50 : ℕ) : ℝ))) =\\\\n      ((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ) →')\ns=s.replace('    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50-3/4)\"'^2) = 1/100 →'\"','    (∑ k : Fin 51, prior a b k *\\\\n      ((k.val : ℝ)/((50 : ℕ) : ℝ)-((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ))\"'^2) ='\"\\\\n      1/((100 : ℕ) : ℝ) →')\np.write_text(s)\np=Path('report.txt');s=p.read_text();s+='\\\\nCheck e0c7eb186fb646479deb5e3acccc85a4 also passed compilation and\\\\nleanchecker but failed exact statement extraction, after the moment equations\\\\nwere moved directly into the theorem. The natural-to-real spelling is now\\\\nused for the real numerals in those equations as well. Their ordinary\\\\nmathematical content is exactly the mean and variance displayed above.\\\\nThe explicit casts are a tool-compatibility annotation, not a model change.\\\\nRaw comparison traces for that submission are cycle2b-diagnostic-* and\\\\ncycle2b-identity-diff.txt. Both extraction failures remain failures.\\\\n';p.write_text(s)\nPY\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json\""
}
assistant
The diagnostics confirmed that the first mismatch came from how Lean elaborated numerals in the theorem and extracted definition. A second extraction check failed after the moment equations were moved into the final statement.

I’ve applied explicit casts to those numerals too. The current candidate still states the two supplied moment constraints directly and predicts 313/384. Another full check is running.
shell input
{
  "command": "/usr/bin/bash -lc 'ls -lt checks | head -4'"
}
shell output · exit 0
total 24
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:15 ef2f01ce2af94e3b911086145d3daf33
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:14 e0c7eb186fb646479deb5e3acccc85a4
drwxr-xr-x 2 1001 1001 4096 Nov 16 16:12 1979df9673ad4e099fa055acb34fad8a
shell input
{
  "command": "/usr/bin/bash -lc 'ls -l checks/ef2f01ce2af94e3b911086145d3daf33'"
}
shell output · exit 0
total 80
-rw-r--r-- 1 1001 1001 18177 Nov 16 16:15 Checked.lean
-rw-r--r-- 1 1001 1001 21279 Nov 16 16:16 extracted.probe.lean
-rw-r--r-- 1 1001 1001   552 Nov 16 16:16 lean.log
-rw------- 1 1001 1001  2611 Nov 16 16:15 submitted-candidate.json
-rw-r--r-- 1 1001 1001 12279 Nov 16 16:15 submitted-report.txt
-rw-r--r-- 1 1001 1001 15012 Nov 16 16:15 submitted.lean
assistant
The latest proof has compiled and passed the separate kernel check. The harness is still checking that the extracted conclusion and model definitions match exactly. I’m waiting for that verdict before reporting verification success.
shell output · exit 0
{
 "file": "/work/checks/ef2f01ce2af94e3b911086145d3daf33/submitted.lean",
 "conclusions": [
  "answer_theorem"
 ],
 "lean_exit": 0,
 "ok": true,
 "compiles_alone": true,
 "faithful": {
  "answer_theorem": true
 },
 "assumption_declarations": [
  "rising",
  "prior",
  "likelihood",
  "evidence",
  "posterior",
  "prediction"
 ],
 "identity_method": "kernel-expression-repr-v1",
 "conclusion_identities": {
  "answer_theorem": {
   "original_sha256": "142009b9f031615644f583ca43e84fc401e7ec3e5d305d8e43964951e7664245",
   "extracted_sha256": "142009b9f031615644f583ca43e84fc401e7ec3e5d305d8e43964951e7664245"
  }
 },
 "dependency_faithful": {
  "prior": true,
  "rising": true,
  "rising._f": true,
  "rising.match_1": true,
  "prediction": true,
  "posterior": true,
  "likelihood": true,
  "evidence": true,
  "prediction._proof_1": true
 },
 "dependency_identities": {
  "prior": {
   "original_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2",
   "extracted_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2"
  },
  "rising": {
   "original_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e",
   "extracted_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e"
  },
  "rising._f": {
   "original_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800",
   "extracted_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800"
  },
  "rising.match_1": {
   "original_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf",
   "extracted_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf"
  },
  "prediction": {
   "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
   "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
  },
  "posterior": {
   "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
   "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
  },
  "likelihood": {
   "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
   "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
  },
  "evidence": {
   "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
   "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
  },
  "prediction._proof_1": {
   "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
   "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
  }
 },
 "unranged": [],
 "added_assumptions": [],
 "conclusions_as_proved": {
  "answer_theorem": "\u2200 (a b : \u211d), 0 < a \u2192 0 < b \u2192 \u2211 k, prior a b k * (\u2191\u2191k / \u219150) = \u21913 / \u21914 \u2192 \u2211 k, prior a b k * (\u2191\u2191k / \u219150 - \u21913 / \u21914) ^ 2 = 1 / \u2191100 \u2192 prediction (prior a b) = \u2191313 / \u2191384"
 },
 "extracted_file": "/work/checks/ef2f01ce2af94e3b911086145d3daf33/extracted.lean",
 "errors": []
}
{
  "ok": true,
  "check_complete": true,
  "reviewable": true,
  "verdict": "proved",
  "time": "2026-11-16T16:15:53.236088+00:00",
  "lean_exit": 0,
  "added_assumptions": [],
  "conditional_on": [],
  "extraction": {
    "file": "/work/checks/ef2f01ce2af94e3b911086145d3daf33/submitted.lean",
    "conclusions": [
      "answer_theorem"
    ],
    "lean_exit": 0,
    "ok": true,
    "compiles_alone": true,
    "faithful": {
      "answer_theorem": true
    },
    "assumption_declarations": [
      "rising",
      "prior",
      "likelihood",
      "evidence",
      "posterior",
      "prediction"
    ],
    "identity_method": "kernel-expression-repr-v1",
    "conclusion_identities": {
      "answer_theorem": {
        "original_sha256": "142009b9f031615644f583ca43e84fc401e7ec3e5d305d8e43964951e7664245",
        "extracted_sha256": "142009b9f031615644f583ca43e84fc401e7ec3e5d305d8e43964951e7664245"
      }
    },
    "dependency_faithful": {
      "prior": true,
      "rising": true,
      "rising._f": true,
      "rising.match_1": true,
      "prediction": true,
      "posterior": true,
      "likelihood": true,
      "evidence": true,
      "prediction._proof_1": true
    },
    "dependency_identities": {
      "prior": {
        "original_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2",
        "extracted_sha256": "4e3854da3c1e1cb8b9132a6e22c802ca7f4b231f8f02640c480a0e976fa9b7e2"
      },
      "rising": {
        "original_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e",
        "extracted_sha256": "40bc662705806d4d6ebc081a587cdb6b63d51b27c648203703839834fddb5c1e"
      },
      "rising._f": {
        "original_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800",
        "extracted_sha256": "f5df2f957b9c3e9af08d7a7d09c92681f592c2928d3a33a6d78a8c59597f1800"
      },
      "rising.match_1": {
        "original_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf",
        "extracted_sha256": "5e0240c1f777986c60694f217c7acb93070ff47360c39a66b2780f3b97b9d3cf"
      },
      "prediction": {
        "original_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe",
        "extracted_sha256": "f2355ffd28c11d0f15396af34cb5696eb705734a2c01b332b02d7b47c5161afe"
      },
      "posterior": {
        "original_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e",
        "extracted_sha256": "28d1c1befeff4dbefe659428c6a167b9be0279197af329b95062667ced27a58e"
      },
      "likelihood": {
        "original_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd",
        "extracted_sha256": "099d0923d428052b578b381ba5e00e97e120cd84ededa1ed0b63f216765505cd"
      },
      "evidence": {
        "original_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124",
        "extracted_sha256": "3ba9a5354000a800e01ae31014765c49add5158e9ad7eb0c7cb0de26e92b1124"
      },
      "prediction._proof_1": {
        "original_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d",
        "extracted_sha256": "6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d"
      }
    },
    "unranged": [],
    "added_assumptions": [],
    "conclusions_as_proved": {
      "answer_theorem": "\u2200 (a b : \u211d), 0 < a \u2192 0 < b \u2192 \u2211 k, prior a b k * (\u2191\u2191k / \u219150) = \u21913 / \u21914 \u2192 \u2211 k, prior a b k * (\u2191\u2191k / \u219150 - \u21913 / \u21914) ^ 2 = 1 / \u2191100 \u2192 prediction (prior a b) = \u2191313 / \u2191384"
    },
    "extracted_file": "/work/checks/ef2f01ce2af94e3b911086145d3daf33/extracted.lean",
    "errors": []
  },
  "scientific_relevance": "requires human review"
}
assistant
Under the explicitly assumed beta-binomial model, the probability is **313/384 ≈ 81.51%**.

Matching the supplied finite-box moments derives α = 21.3 and β = 7.1. After ten black draws, the prediction is
\[
\frac{21.3+10}{21.3+7.1+10}=\frac{313}{384}.
\]
The family is an additional assumption; the moments alone do not determine a unique answer.

The [candidate](/work/candidate.json), [report](/work/report.txt), and [Lean proof](/work/Model.lean) are ready. The actual [check passed](/work/checks/ef2f01ce2af94e3b911086145d3daf33/verdict.json), including faithful extraction and kernel verification, with no added axioms or `sorry`. Scientific acceptance remains for human review.

Produced code

attempt-002/Model.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- Rising factorial: a(a+1)...(a+n-1).
noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

lemma rising_pos : ∀ a : ℝ, 0 < a → ∀ n, 0 < rising a n := by
  intro a ha n
  induction n with
  | zero => simp [rising]
  | succ n ih => exact mul_pos ih (by positivity)

-- A general Pascal-rule recurrence, used only to derive the family moments.
lemma weighted_sum_step (a b : ℝ) (f : ℕ → ℝ) (n : ℕ) :
    (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * f k) =
    ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) *
      ((b + (n-k : ℕ)) * f k + (a+k) * f (k+1)) := by
  have h := Finset.sum_choose_succ_mul
    (fun i j => rising a i * rising b j * f i) n
  simp only [mul_assoc] at h ⊢
  rw [h, ← Finset.sum_add_distrib]
  apply Finset.sum_congr rfl
  intro k hk
  have hk' : k ≤ n := by have := Finset.mem_range.mp hk; omega
  have hs : n+1-k = (n-k)+1 := by omega
  rw [hs, rising, rising]
  ring

-- Raw mass, first count moment and second factorial count moment.
-- These are derived simultaneously, not assumed moment formulas.
lemma family_sums (a b : ℝ) (ha : 0 < a) (hb : 0 < b) : ∀ n : ℕ,
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k)) = rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) =
      (n : ℝ) * a / (a+b) * rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ) * (k-1))) =
      (n : ℝ) * (n-1) * a * (a+1) / ((a+b)*(a+b+1)) * rising (a+b) n := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  intro n
  induction n with
  | zero => simp [rising]
  | succ n ih =>
    have cast_sub : ∀ k ∈ Finset.range (n+1), ((n-k : ℕ) : ℝ) = (n : ℝ) - k := by
      intro k hk
      exact Nat.cast_sub (by have := Finset.mem_range.mp hk; omega)
    have h0 := weighted_sum_step a b (fun _ => 1) n
    have h1 := weighted_sum_step a b (fun k => (k : ℝ)) n
    have h2 := weighted_sum_step a b (fun k => (k : ℝ) * (k-1)) n
    have r0 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k)) =
        (a+b+n) * rising (a+b) n := by
      simpa only [mul_one] using h0.trans (by
        calc
          _ = (a+b+n) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
            rw [Finset.mul_sum]
            apply Finset.sum_congr rfl
            intro k hk
            rw [cast_sub k hk]
            ring
          _ = _ := by rw [ih.1])
    have r1 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * (k : ℝ)) =
        (a+b+n+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) + a * rising (a+b) n := by
      rw [h1]
      calc
        _ = (a+b+n+1) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) +
            a * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.1, ih.2.1]
    have r2 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * ((k : ℝ)*(k-1))) =
        (a+b+n+2) * ((n : ℝ)*(n-1)*a*(a+1)/((a+b)*(a+b+1))*rising (a+b) n) +
        2*(a+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) := by
      rw [h2]
      calc
        _ = (a+b+n+2) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ)*(k-1))) +
            2*(a+1) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.2.1, ih.2.2]
    refine ⟨?_, ?_, ?_⟩
    · rw [r0, rising]
      ring
    · rw [r1, rising]
      push_cast
      field_simp
      ring
    · rw [r2, rising]
      push_cast
      field_simp
      ring

-- The finite beta-binomial family for the original black count K in 0,...,50.
-- Equivalent to drawing a latent propensity from Beta(a,b), then 50 colors.
noncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=
  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl


-- Derived finite-family moments. No distributional moment identities are axioms.
lemma prior_moments (a b : ℝ) (ha : 0 < a) (hb : 0 < b) :
    (∀ k, 0 ≤ prior a b k) ∧ (∑ k, prior a b k) = 1 ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50)) = a/(a+b) ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50-a/(a+b))^2) =
      a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  have hd : rising (a+b) 50 ≠ 0 := ne_of_gt (rising_pos _ (by linarith) _)
  have hm := family_sums a b ha hb 50
  have h0 : (∑ k, prior a b k) = 1 := by
    unfold prior
    rw [← Finset.sum_div, Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k)) 51, hm.1, div_self hd]
  have h1 : (∑ k, prior a b k * (k.val : ℝ)) = 50*a/(a+b) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * (k.val : ℝ)) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * (k : ℝ)) 51, hm.2.1]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  have h2 : (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1))) =
      50*49*a*(a+1)/((a+b)*(a+b+1)) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * ((k.val : ℝ)*(k.val-1))) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * ((k : ℝ)*(k-1))) 51, hm.2.2]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  refine ⟨?_, h0, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (rising_pos a ha _)))
      (le_of_lt (rising_pos b hb _))) (le_of_lt (rising_pos _ (by linarith) _))
  · calc
      _ = (∑ k, prior a b k * (k.val : ℝ))/50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by rw [h1]; ring
  · calc
      _ = (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1)))/2500 +
          (1/2500-2*(a/(a+b))/50)*(∑ k, prior a b k * (k.val : ℝ)) +
          (a/(a+b))^2 * (∑ k, prior a b k) := by
        rw [Finset.sum_div, Finset.mul_sum, Finset.mul_sum,
          ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by
        rw [h0, h1, h2]
        field_simp
        ring

-- The supplied moments identify the two parameters WITHIN this family.
-- They do not identify the family itself.
lemma parameters_from_moments : ∀ a b : ℝ, 0 < a → 0 < b →
    compatible (prior a b) → a = 213/10 ∧ b = 71/10 := by
  intro a b ha hb hp
  have hm := prior_moments a b ha hb
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have mean : a/(a+b) = 3/4 := hm.2.2.1.symm.trans hp.2.2.1
  have variance : a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) = 1/100 := by
    rw [← hm.2.2.2, mean]
    exact hp.2.2.2
  have hab : a = 3*b := by
    have h := (div_eq_iff hs).mp mean
    linarith
  have hden : 50*(a+b)^2*(a+b+1) ≠ 0 := by positivity
  have hv := (div_eq_iff hden).mp variance
  rw [hab] at hv
  have hb0 : b^2 ≠ 0 := pow_ne_zero _ (ne_of_gt hb)
  have hpoly : b^2 * (10*b-71) = 0 := by nlinarith [hv]
  have hbval : b = 71/10 := by
    have := (mul_eq_zero.mp hpoly).resolve_left hb0
    linarith
  exact ⟨by rw [hab, hbval]; norm_num, hbval⟩

-- Feasibility is proved, so the moment-fitting conditions are not vacuous.
lemma fitted_prior_compatible : compatible (prior (213/10) (71/10)) := by
  have hm := prior_moments (213/10) (71/10) (by norm_num) (by norm_num)
  refine ⟨hm.1, hm.2.1, ?_, ?_⟩
  · convert hm.2.2.1 using 1 <;> norm_num
  · convert hm.2.2.2 using 1 <;> norm_num

-- Exact evidences for the fitted finite model; both sums are evaluated in Lean.
lemma fitted_evidence10 : evidence (prior (213/10) (71/10)) 10 =
    ((23689849826939661 : ℕ) : ℝ)/((275978414373208064 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 10 : ℝ)/(Nat.choose 50 10 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

lemma fitted_evidence11 : evidence (prior (213/10) (71/10)) 11 =
    ((2471640998610704631 : ℕ) : ℝ)/((35325237039770632192 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 11 : ℝ)/(Nat.choose 50 11 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

-- Conditional scientific answer: any positive-parameter member of the stated
-- family matching the supplied population moments predicts 313/384.
theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →
    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/((50 : ℕ) : ℝ))) =
      ((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ) →
    (∑ k : Fin 51, prior a b k *
      ((k.val : ℝ)/((50 : ℕ) : ℝ)-((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ))^2) =
      1/((100 : ℕ) : ℝ) →
    prediction (prior a b) = ((313 : ℕ) : ℝ)/((384 : ℕ) : ℝ) := by
  intro a b ha hb hmean hvariance
  have hm := prior_moments a b ha hb
  have hp : compatible (prior a b) := ⟨hm.1, hm.2.1, hmean, hvariance⟩
  obtain ⟨ha', hb'⟩ := parameters_from_moments a b ha hb hp
  rw [ha', hb']
  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,
    fitted_evidence11, fitted_evidence10]
  norm_num
attempt-002/extracted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

noncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=
  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50

noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40


/-! Conclusions (statements of the proved theorems). -/
def conclusion_answer_theorem : Prop := ∀ a b : ℝ, 0 < a → 0 < b → (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/((50 : ℕ) : ℝ))) = ((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ) → (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/((50 : ℕ) : ℝ)-((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ))^2) = 1/((100 : ℕ) : ℝ) → prediction (prior a b) = ((313 : ℕ) : ℝ)/((384 : ℕ) : ℝ)
checks/1979df9673ad4e099fa055acb34fad8a/submitted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- Rising factorial: a(a+1)...(a+n-1).
noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

lemma rising_pos : ∀ a : ℝ, 0 < a → ∀ n, 0 < rising a n := by
  intro a ha n
  induction n with
  | zero => simp [rising]
  | succ n ih => exact mul_pos ih (by positivity)

-- A general Pascal-rule recurrence, used only to derive the family moments.
lemma weighted_sum_step (a b : ℝ) (f : ℕ → ℝ) (n : ℕ) :
    (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * f k) =
    ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) *
      ((b + (n-k : ℕ)) * f k + (a+k) * f (k+1)) := by
  have h := Finset.sum_choose_succ_mul
    (fun i j => rising a i * rising b j * f i) n
  simp only [mul_assoc] at h ⊢
  rw [h, ← Finset.sum_add_distrib]
  apply Finset.sum_congr rfl
  intro k hk
  have hk' : k ≤ n := by have := Finset.mem_range.mp hk; omega
  have hs : n+1-k = (n-k)+1 := by omega
  rw [hs, rising, rising]
  ring

-- Raw mass, first count moment and second factorial count moment.
-- These are derived simultaneously, not assumed moment formulas.
lemma family_sums (a b : ℝ) (ha : 0 < a) (hb : 0 < b) : ∀ n : ℕ,
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k)) = rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) =
      (n : ℝ) * a / (a+b) * rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ) * (k-1))) =
      (n : ℝ) * (n-1) * a * (a+1) / ((a+b)*(a+b+1)) * rising (a+b) n := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  intro n
  induction n with
  | zero => simp [rising]
  | succ n ih =>
    have cast_sub : ∀ k ∈ Finset.range (n+1), ((n-k : ℕ) : ℝ) = (n : ℝ) - k := by
      intro k hk
      exact Nat.cast_sub (by have := Finset.mem_range.mp hk; omega)
    have h0 := weighted_sum_step a b (fun _ => 1) n
    have h1 := weighted_sum_step a b (fun k => (k : ℝ)) n
    have h2 := weighted_sum_step a b (fun k => (k : ℝ) * (k-1)) n
    have r0 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k)) =
        (a+b+n) * rising (a+b) n := by
      simpa only [mul_one] using h0.trans (by
        calc
          _ = (a+b+n) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
            rw [Finset.mul_sum]
            apply Finset.sum_congr rfl
            intro k hk
            rw [cast_sub k hk]
            ring
          _ = _ := by rw [ih.1])
    have r1 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * (k : ℝ)) =
        (a+b+n+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) + a * rising (a+b) n := by
      rw [h1]
      calc
        _ = (a+b+n+1) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) +
            a * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.1, ih.2.1]
    have r2 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * ((k : ℝ)*(k-1))) =
        (a+b+n+2) * ((n : ℝ)*(n-1)*a*(a+1)/((a+b)*(a+b+1))*rising (a+b) n) +
        2*(a+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) := by
      rw [h2]
      calc
        _ = (a+b+n+2) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ)*(k-1))) +
            2*(a+1) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.2.1, ih.2.2]
    refine ⟨?_, ?_, ?_⟩
    · rw [r0, rising]
      ring
    · rw [r1, rising]
      push_cast
      field_simp
      ring
    · rw [r2, rising]
      push_cast
      field_simp
      ring

-- The finite beta-binomial family for the original black count K in 0,...,50.
-- Equivalent to drawing a latent propensity from Beta(a,b), then 50 colors.
noncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=
  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl


-- Derived finite-family moments. No distributional moment identities are axioms.
lemma prior_moments (a b : ℝ) (ha : 0 < a) (hb : 0 < b) :
    (∀ k, 0 ≤ prior a b k) ∧ (∑ k, prior a b k) = 1 ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50)) = a/(a+b) ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50-a/(a+b))^2) =
      a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  have hd : rising (a+b) 50 ≠ 0 := ne_of_gt (rising_pos _ (by linarith) _)
  have hm := family_sums a b ha hb 50
  have h0 : (∑ k, prior a b k) = 1 := by
    unfold prior
    rw [← Finset.sum_div, Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k)) 51, hm.1, div_self hd]
  have h1 : (∑ k, prior a b k * (k.val : ℝ)) = 50*a/(a+b) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * (k.val : ℝ)) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * (k : ℝ)) 51, hm.2.1]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  have h2 : (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1))) =
      50*49*a*(a+1)/((a+b)*(a+b+1)) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * ((k.val : ℝ)*(k.val-1))) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * ((k : ℝ)*(k-1))) 51, hm.2.2]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  refine ⟨?_, h0, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (rising_pos a ha _)))
      (le_of_lt (rising_pos b hb _))) (le_of_lt (rising_pos _ (by linarith) _))
  · calc
      _ = (∑ k, prior a b k * (k.val : ℝ))/50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by rw [h1]; ring
  · calc
      _ = (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1)))/2500 +
          (1/2500-2*(a/(a+b))/50)*(∑ k, prior a b k * (k.val : ℝ)) +
          (a/(a+b))^2 * (∑ k, prior a b k) := by
        rw [Finset.sum_div, Finset.mul_sum, Finset.mul_sum,
          ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by
        rw [h0, h1, h2]
        field_simp
        ring

-- The supplied moments identify the two parameters WITHIN this family.
-- They do not identify the family itself.
lemma parameters_from_moments : ∀ a b : ℝ, 0 < a → 0 < b →
    compatible (prior a b) → a = 213/10 ∧ b = 71/10 := by
  intro a b ha hb hp
  have hm := prior_moments a b ha hb
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have mean : a/(a+b) = 3/4 := hm.2.2.1.symm.trans hp.2.2.1
  have variance : a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) = 1/100 := by
    rw [← hm.2.2.2, mean]
    exact hp.2.2.2
  have hab : a = 3*b := by
    have h := (div_eq_iff hs).mp mean
    linarith
  have hden : 50*(a+b)^2*(a+b+1) ≠ 0 := by positivity
  have hv := (div_eq_iff hden).mp variance
  rw [hab] at hv
  have hb0 : b^2 ≠ 0 := pow_ne_zero _ (ne_of_gt hb)
  have hpoly : b^2 * (10*b-71) = 0 := by nlinarith [hv]
  have hbval : b = 71/10 := by
    have := (mul_eq_zero.mp hpoly).resolve_left hb0
    linarith
  exact ⟨by rw [hab, hbval]; norm_num, hbval⟩

-- Feasibility is proved, so the moment-fitting conditions are not vacuous.
lemma fitted_prior_compatible : compatible (prior (213/10) (71/10)) := by
  have hm := prior_moments (213/10) (71/10) (by norm_num) (by norm_num)
  refine ⟨hm.1, hm.2.1, ?_, ?_⟩
  · convert hm.2.2.1 using 1 <;> norm_num
  · convert hm.2.2.2 using 1 <;> norm_num

-- Exact evidences for the fitted finite model; both sums are evaluated in Lean.
lemma fitted_evidence10 : evidence (prior (213/10) (71/10)) 10 =
    ((23689849826939661 : ℕ) : ℝ)/((275978414373208064 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 10 : ℝ)/(Nat.choose 50 10 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

lemma fitted_evidence11 : evidence (prior (213/10) (71/10)) 11 =
    ((2471640998610704631 : ℕ) : ℝ)/((35325237039770632192 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 11 : ℝ)/(Nat.choose 50 11 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

-- Conditional scientific answer: any positive-parameter member of the stated
-- family matching the supplied population moments predicts 313/384.
theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →
    compatible (prior a b) → prediction (prior a b) = 313/384 := by
  intro a b ha hb hp
  obtain ⟨ha', hb'⟩ := parameters_from_moments a b ha hb hp
  rw [ha', hb']
  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,
    fitted_evidence11, fitted_evidence10]
  norm_num
checks/589b8c8ad6124887b939666f670c9191/submitted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl

-- Two witnesses, rather than an inferred choice between them: the supplied
-- population moments do not identify the requested posterior probability.
theorem moments_do_not_identify_answer :
    ∃ p q : Fin 51 → ℝ, compatible p ∧ compatible q ∧
      prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) ∧
      prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) ∧
      prediction p ≠ prediction q := by
  let p : Fin 51 → ℝ := fun k =>
    (if k = 30 then 9/32 else 0) +
    (if k = 40 then 11/16 else 0) +
    (if k = 50 then 1/32 else 0)
  let q : Fin 51 → ℝ := fun k =>
    (if k = 25 then 1/32 else 0) +
    (if k = 35 then 11/16 else 0) +
    (if k = 45 then 9/32 else 0)
  have sp : ∀ f : Fin 51 → ℝ, (∑ k, p k * f k) =
      (9/32) * f 30 + (11/16) * f 40 + (1/32) * f 50 := by
    intro f
    simp [p, add_mul, ite_mul, Finset.sum_add_distrib]
  have sq : ∀ f : Fin 51 → ℝ, (∑ k, q k * f k) =
      (1/32) * f 25 + (11/16) * f 35 + (9/32) * f 45 := by
    intro f
    simp [q, add_mul, ite_mul, Finset.sum_add_distrib]
  have hp : compatible p := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [p]
      split_ifs <;> norm_num
    · have h := sp (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sp]
      norm_num
    · rw [sp]
      norm_num
  have hq : compatible q := by
    refine ⟨?_, ?_, ?_, ?_⟩
    · intro k
      dsimp [q]
      split_ifs <;> norm_num
    · have h := sq (fun _ => 1)
      norm_num at h ⊢
      exact h
    · rw [sq]
      norm_num
    · rw [sq]
      norm_num
  have ap : prediction p = ((4435250809 : ℕ) : ℝ)/((5307493622 : ℕ) : ℝ) := by
    rw [(bayesian_answer p hp).2.2.2]
    unfold evidence
    rw [sp, sp]
    norm_num [likelihood, Nat.choose]
  have aq : prediction q = ((10053879039 : ℕ) : ℝ)/((11910436744 : ℕ) : ℝ) := by
    rw [(bayesian_answer q hq).2.2.2]
    unfold evidence
    rw [sq, sq]
    norm_num [likelihood, Nat.choose]
  refine ⟨p, q, hp, hq, ap, aq, ?_⟩
  rw [ap, aq]
  norm_num
checks/e0c7eb186fb646479deb5e3acccc85a4/submitted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- Rising factorial: a(a+1)...(a+n-1).
noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

lemma rising_pos : ∀ a : ℝ, 0 < a → ∀ n, 0 < rising a n := by
  intro a ha n
  induction n with
  | zero => simp [rising]
  | succ n ih => exact mul_pos ih (by positivity)

-- A general Pascal-rule recurrence, used only to derive the family moments.
lemma weighted_sum_step (a b : ℝ) (f : ℕ → ℝ) (n : ℕ) :
    (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * f k) =
    ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) *
      ((b + (n-k : ℕ)) * f k + (a+k) * f (k+1)) := by
  have h := Finset.sum_choose_succ_mul
    (fun i j => rising a i * rising b j * f i) n
  simp only [mul_assoc] at h ⊢
  rw [h, ← Finset.sum_add_distrib]
  apply Finset.sum_congr rfl
  intro k hk
  have hk' : k ≤ n := by have := Finset.mem_range.mp hk; omega
  have hs : n+1-k = (n-k)+1 := by omega
  rw [hs, rising, rising]
  ring

-- Raw mass, first count moment and second factorial count moment.
-- These are derived simultaneously, not assumed moment formulas.
lemma family_sums (a b : ℝ) (ha : 0 < a) (hb : 0 < b) : ∀ n : ℕ,
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k)) = rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) =
      (n : ℝ) * a / (a+b) * rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ) * (k-1))) =
      (n : ℝ) * (n-1) * a * (a+1) / ((a+b)*(a+b+1)) * rising (a+b) n := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  intro n
  induction n with
  | zero => simp [rising]
  | succ n ih =>
    have cast_sub : ∀ k ∈ Finset.range (n+1), ((n-k : ℕ) : ℝ) = (n : ℝ) - k := by
      intro k hk
      exact Nat.cast_sub (by have := Finset.mem_range.mp hk; omega)
    have h0 := weighted_sum_step a b (fun _ => 1) n
    have h1 := weighted_sum_step a b (fun k => (k : ℝ)) n
    have h2 := weighted_sum_step a b (fun k => (k : ℝ) * (k-1)) n
    have r0 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k)) =
        (a+b+n) * rising (a+b) n := by
      simpa only [mul_one] using h0.trans (by
        calc
          _ = (a+b+n) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
            rw [Finset.mul_sum]
            apply Finset.sum_congr rfl
            intro k hk
            rw [cast_sub k hk]
            ring
          _ = _ := by rw [ih.1])
    have r1 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * (k : ℝ)) =
        (a+b+n+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) + a * rising (a+b) n := by
      rw [h1]
      calc
        _ = (a+b+n+1) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) +
            a * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.1, ih.2.1]
    have r2 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * ((k : ℝ)*(k-1))) =
        (a+b+n+2) * ((n : ℝ)*(n-1)*a*(a+1)/((a+b)*(a+b+1))*rising (a+b) n) +
        2*(a+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) := by
      rw [h2]
      calc
        _ = (a+b+n+2) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ)*(k-1))) +
            2*(a+1) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.2.1, ih.2.2]
    refine ⟨?_, ?_, ?_⟩
    · rw [r0, rising]
      ring
    · rw [r1, rising]
      push_cast
      field_simp
      ring
    · rw [r2, rising]
      push_cast
      field_simp
      ring

-- The finite beta-binomial family for the original black count K in 0,...,50.
-- Equivalent to drawing a latent propensity from Beta(a,b), then 50 colors.
noncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=
  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl


-- Derived finite-family moments. No distributional moment identities are axioms.
lemma prior_moments (a b : ℝ) (ha : 0 < a) (hb : 0 < b) :
    (∀ k, 0 ≤ prior a b k) ∧ (∑ k, prior a b k) = 1 ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50)) = a/(a+b) ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50-a/(a+b))^2) =
      a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  have hd : rising (a+b) 50 ≠ 0 := ne_of_gt (rising_pos _ (by linarith) _)
  have hm := family_sums a b ha hb 50
  have h0 : (∑ k, prior a b k) = 1 := by
    unfold prior
    rw [← Finset.sum_div, Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k)) 51, hm.1, div_self hd]
  have h1 : (∑ k, prior a b k * (k.val : ℝ)) = 50*a/(a+b) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * (k.val : ℝ)) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * (k : ℝ)) 51, hm.2.1]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  have h2 : (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1))) =
      50*49*a*(a+1)/((a+b)*(a+b+1)) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * ((k.val : ℝ)*(k.val-1))) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * ((k : ℝ)*(k-1))) 51, hm.2.2]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  refine ⟨?_, h0, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (rising_pos a ha _)))
      (le_of_lt (rising_pos b hb _))) (le_of_lt (rising_pos _ (by linarith) _))
  · calc
      _ = (∑ k, prior a b k * (k.val : ℝ))/50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by rw [h1]; ring
  · calc
      _ = (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1)))/2500 +
          (1/2500-2*(a/(a+b))/50)*(∑ k, prior a b k * (k.val : ℝ)) +
          (a/(a+b))^2 * (∑ k, prior a b k) := by
        rw [Finset.sum_div, Finset.mul_sum, Finset.mul_sum,
          ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by
        rw [h0, h1, h2]
        field_simp
        ring

-- The supplied moments identify the two parameters WITHIN this family.
-- They do not identify the family itself.
lemma parameters_from_moments : ∀ a b : ℝ, 0 < a → 0 < b →
    compatible (prior a b) → a = 213/10 ∧ b = 71/10 := by
  intro a b ha hb hp
  have hm := prior_moments a b ha hb
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have mean : a/(a+b) = 3/4 := hm.2.2.1.symm.trans hp.2.2.1
  have variance : a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) = 1/100 := by
    rw [← hm.2.2.2, mean]
    exact hp.2.2.2
  have hab : a = 3*b := by
    have h := (div_eq_iff hs).mp mean
    linarith
  have hden : 50*(a+b)^2*(a+b+1) ≠ 0 := by positivity
  have hv := (div_eq_iff hden).mp variance
  rw [hab] at hv
  have hb0 : b^2 ≠ 0 := pow_ne_zero _ (ne_of_gt hb)
  have hpoly : b^2 * (10*b-71) = 0 := by nlinarith [hv]
  have hbval : b = 71/10 := by
    have := (mul_eq_zero.mp hpoly).resolve_left hb0
    linarith
  exact ⟨by rw [hab, hbval]; norm_num, hbval⟩

-- Feasibility is proved, so the moment-fitting conditions are not vacuous.
lemma fitted_prior_compatible : compatible (prior (213/10) (71/10)) := by
  have hm := prior_moments (213/10) (71/10) (by norm_num) (by norm_num)
  refine ⟨hm.1, hm.2.1, ?_, ?_⟩
  · convert hm.2.2.1 using 1 <;> norm_num
  · convert hm.2.2.2 using 1 <;> norm_num

-- Exact evidences for the fitted finite model; both sums are evaluated in Lean.
lemma fitted_evidence10 : evidence (prior (213/10) (71/10)) 10 =
    ((23689849826939661 : ℕ) : ℝ)/((275978414373208064 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 10 : ℝ)/(Nat.choose 50 10 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

lemma fitted_evidence11 : evidence (prior (213/10) (71/10)) 11 =
    ((2471640998610704631 : ℕ) : ℝ)/((35325237039770632192 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 11 : ℝ)/(Nat.choose 50 11 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

-- Conditional scientific answer: any positive-parameter member of the stated
-- family matching the supplied population moments predicts 313/384.
theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →
    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50)) = 3/4 →
    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/50-3/4)^2) = 1/100 →
    prediction (prior a b) = ((313 : ℕ) : ℝ)/((384 : ℕ) : ℝ) := by
  intro a b ha hb hmean hvariance
  have hm := prior_moments a b ha hb
  have hp : compatible (prior a b) := ⟨hm.1, hm.2.1, hmean, hvariance⟩
  obtain ⟨ha', hb'⟩ := parameters_from_moments a b ha hb hp
  rw [ha', hb']
  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,
    fitted_evidence11, fitted_evidence10]
  norm_num
checks/ef2f01ce2af94e3b911086145d3daf33/submitted.lean
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.Order.BigOperators.Group.Finset

set_option maxRecDepth 4096
set_option maxHeartbeats 4000000

-- Rising factorial: a(a+1)...(a+n-1).
noncomputable def rising (a : ℝ) : ℕ → ℝ
  | 0 => 1
  | n+1 => rising a n * (a+n)

lemma rising_pos : ∀ a : ℝ, 0 < a → ∀ n, 0 < rising a n := by
  intro a ha n
  induction n with
  | zero => simp [rising]
  | succ n ih => exact mul_pos ih (by positivity)

-- A general Pascal-rule recurrence, used only to derive the family moments.
lemma weighted_sum_step (a b : ℝ) (f : ℕ → ℝ) (n : ℕ) :
    (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * f k) =
    ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) *
      ((b + (n-k : ℕ)) * f k + (a+k) * f (k+1)) := by
  have h := Finset.sum_choose_succ_mul
    (fun i j => rising a i * rising b j * f i) n
  simp only [mul_assoc] at h ⊢
  rw [h, ← Finset.sum_add_distrib]
  apply Finset.sum_congr rfl
  intro k hk
  have hk' : k ≤ n := by have := Finset.mem_range.mp hk; omega
  have hs : n+1-k = (n-k)+1 := by omega
  rw [hs, rising, rising]
  ring

-- Raw mass, first count moment and second factorial count moment.
-- These are derived simultaneously, not assumed moment formulas.
lemma family_sums (a b : ℝ) (ha : 0 < a) (hb : 0 < b) : ∀ n : ℕ,
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k)) = rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) =
      (n : ℝ) * a / (a+b) * rising (a+b) n ∧
    (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ) * (k-1))) =
      (n : ℝ) * (n-1) * a * (a+1) / ((a+b)*(a+b+1)) * rising (a+b) n := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  intro n
  induction n with
  | zero => simp [rising]
  | succ n ih =>
    have cast_sub : ∀ k ∈ Finset.range (n+1), ((n-k : ℕ) : ℝ) = (n : ℝ) - k := by
      intro k hk
      exact Nat.cast_sub (by have := Finset.mem_range.mp hk; omega)
    have h0 := weighted_sum_step a b (fun _ => 1) n
    have h1 := weighted_sum_step a b (fun k => (k : ℝ)) n
    have h2 := weighted_sum_step a b (fun k => (k : ℝ) * (k-1)) n
    have r0 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k)) =
        (a+b+n) * rising (a+b) n := by
      simpa only [mul_one] using h0.trans (by
        calc
          _ = (a+b+n) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
            rw [Finset.mul_sum]
            apply Finset.sum_congr rfl
            intro k hk
            rw [cast_sub k hk]
            ring
          _ = _ := by rw [ih.1])
    have r1 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * (k : ℝ)) =
        (a+b+n+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) + a * rising (a+b) n := by
      rw [h1]
      calc
        _ = (a+b+n+1) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ)) +
            a * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.1, ih.2.1]
    have r2 : (∑ k ∈ Finset.range (n+2), ((n+1).choose k : ℝ) * rising a k * rising b (n+1-k) * ((k : ℝ)*(k-1))) =
        (a+b+n+2) * ((n : ℝ)*(n-1)*a*(a+1)/((a+b)*(a+b+1))*rising (a+b) n) +
        2*(a+1) * ((n : ℝ)*a/(a+b)*rising (a+b) n) := by
      rw [h2]
      calc
        _ = (a+b+n+2) * (∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * ((k : ℝ)*(k-1))) +
            2*(a+1) * ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ) * rising a k * rising b (n-k) * (k : ℝ) := by
          rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
          apply Finset.sum_congr rfl
          intro k hk
          rw [cast_sub k hk]
          push_cast
          ring
        _ = _ := by rw [ih.2.1, ih.2.2]
    refine ⟨?_, ?_, ?_⟩
    · rw [r0, rising]
      ring
    · rw [r1, rising]
      push_cast
      field_simp
      ring
    · rw [r2, rising]
      push_cast
      field_simp
      ring

-- The finite beta-binomial family for the original black count K in 0,...,50.
-- Equivalent to drawing a latent propensity from Beta(a,b), then 50 colors.
noncomputable def prior (a b : ℝ) (k : Fin 51) : ℝ :=
  (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) / rising (a+b) 50

-- k is the original number of black balls. The supplied moments concern k/50.
def compatible (p : Fin 51 → ℝ) : Prop :=
  (∀ k, 0 ≤ p k) ∧ (∑ k, p k) = 1 ∧
  (∑ k, p k * ((k.val : ℝ) / 50)) = 3/4 ∧
  (∑ k, p k * ((k.val : ℝ) / 50 - 3/4)^2) = 1/100

-- Under uniform draws without replacement, every n-subset is equally likely.
-- All n draws are black exactly when that subset is among the choose(k,n) black subsets.
noncomputable def likelihood (n : ℕ) (k : Fin 51) : ℝ :=
  (Nat.choose k.val n : ℝ) / (Nat.choose 50 n : ℝ)

-- Marginal probability of an all-black run of length n.
noncomputable def evidence (p : Fin 51 → ℝ) (n : ℕ) : ℝ :=
  ∑ k, p k * likelihood n k

-- Bayes conditioning on the observed ten black draws.
noncomputable def posterior (p : Fin 51 → ℝ) (k : Fin 51) : ℝ :=
  p k * likelihood 10 k / evidence p 10

-- Given k and the observation, k-10 black balls remain among forty balls.
-- Truncated subtraction at k<10 is harmless: the likelihood is zero there.
noncomputable def prediction (p : Fin 51 → ℝ) : ℝ :=
  ∑ k, posterior p k * ((k.val - 10 : ℕ) : ℝ) / 40

lemma observation_step : ∀ k : Fin 51,
    likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40 = likelihood 11 k := by
  intro k
  fin_cases k <;> norm_num [likelihood, Nat.choose]

lemma likelihood_nonneg : ∀ n k, 0 ≤ likelihood n k := by
  intros n k
  exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

lemma likelihood_positive : ∀ k : Fin 51, 10 ≤ k.val → 0 < likelihood 10 k := by
  intro k hk
  fin_cases k <;> norm_num [likelihood, Nat.choose] at *

lemma evidence_positive : ∀ p, compatible p → 0 < evidence p 10 := by
  intro p hp
  have hnon : ∀ k, 0 ≤ p k * likelihood 10 k :=
    fun k => mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)
  have he : 0 ≤ evidence p 10 := Finset.sum_nonneg (fun k _ => hnon k)
  by_contra h
  have hz : evidence p 10 = 0 := le_antisymm (le_of_not_gt h) he
  have hzero : ∀ k, p k * likelihood 10 k = 0 := by
    intro k
    exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hnon j)).mp hz k (Finset.mem_univ k)
  have bound : ∀ k : Fin 51, p k * ((k.val : ℝ) / 50) ≤ p k * (9/50) := by
    intro k
    by_cases hk : 10 ≤ k.val
    · have pk : p k = 0 := (mul_eq_zero.mp (hzero k)).resolve_right (ne_of_gt (likelihood_positive k hk))
      simp [pk]
    · have kl : (k.val : ℝ) ≤ 9 := by exact_mod_cast (by omega : k.val ≤ 9)
      exact mul_le_mul_of_nonneg_left (by linarith) (hp.1 k)
  have hb := Finset.sum_le_sum (fun k (_ : k ∈ Finset.univ) => bound k)
  have hs : (∑ k, p k * (9/50 : ℝ)) = 9/50 := by
    rw [← Finset.sum_mul, hp.2.1]
    ring
  rw [hp.2.2.1, hs] at hb
  norm_num at hb

-- For every compatible prior, conditioning is well-defined, yields a probability
-- distribution, satisfies Bayes' update, and gives the next-draw prediction.
theorem bayesian_answer : ∀ p : Fin 51 → ℝ, compatible p →
    (∀ k, 0 ≤ posterior p k) ∧ (∑ k, posterior p k) = 1 ∧
    (∀ k, posterior p k * evidence p 10 = p k * likelihood 10 k) ∧
    prediction p = evidence p 11 / evidence p 10 := by
  intro p hp
  have he := evidence_positive p hp
  have hn : evidence p 10 ≠ 0 := ne_of_gt he
  refine ⟨?_, ?_, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (hp.1 k) (likelihood_nonneg 10 k)) (le_of_lt he)
  · simp only [posterior, ← Finset.sum_div]
    exact div_self hn
  · intro k
    exact div_mul_cancel₀ _ hn
  · unfold prediction posterior
    calc
      (∑ k, p k * likelihood 10 k / evidence p 10 * ((k.val - 10 : ℕ) : ℝ) / 40) =
          ∑ k, (p k * (likelihood 10 k * ((k.val - 10 : ℕ) : ℝ) / 40)) / evidence p 10 := by
            apply Finset.sum_congr rfl
            intro k _
            ring
      _ = (∑ k, p k * likelihood 11 k) / evidence p 10 := by
        simp_rw [observation_step]
        rw [Finset.sum_div]
      _ = evidence p 11 / evidence p 10 := rfl


-- Derived finite-family moments. No distributional moment identities are axioms.
lemma prior_moments (a b : ℝ) (ha : 0 < a) (hb : 0 < b) :
    (∀ k, 0 ≤ prior a b k) ∧ (∑ k, prior a b k) = 1 ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50)) = a/(a+b) ∧
    (∑ k, prior a b k * ((k.val : ℝ)/50-a/(a+b))^2) =
      a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) := by
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have hs1 : a+b+1 ≠ 0 := ne_of_gt (by linarith)
  have hd : rising (a+b) 50 ≠ 0 := ne_of_gt (rising_pos _ (by linarith) _)
  have hm := family_sums a b ha hb 50
  have h0 : (∑ k, prior a b k) = 1 := by
    unfold prior
    rw [← Finset.sum_div, Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k)) 51, hm.1, div_self hd]
  have h1 : (∑ k, prior a b k * (k.val : ℝ)) = 50*a/(a+b) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * (k.val : ℝ)) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * (k : ℝ)) 51, hm.2.1]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  have h2 : (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1))) =
      50*49*a*(a+1)/((a+b)*(a+b+1)) := by
    calc
      _ = (∑ k : Fin 51, (Nat.choose 50 k.val : ℝ) * rising a k.val * rising b (50-k.val) * ((k.val : ℝ)*(k.val-1))) / rising (a+b) 50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        unfold prior
        ring
      _ = _ := by
        rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising a k * rising b (50-k) * ((k : ℝ)*(k-1))) 51, hm.2.2]
        norm_num
        exact mul_div_cancel_right₀ _ hd
  refine ⟨?_, h0, ?_, ?_⟩
  · intro k
    exact div_nonneg (mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (rising_pos a ha _)))
      (le_of_lt (rising_pos b hb _))) (le_of_lt (rising_pos _ (by linarith) _))
  · calc
      _ = (∑ k, prior a b k * (k.val : ℝ))/50 := by
        rw [Finset.sum_div]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by rw [h1]; ring
  · calc
      _ = (∑ k, prior a b k * ((k.val : ℝ)*(k.val-1)))/2500 +
          (1/2500-2*(a/(a+b))/50)*(∑ k, prior a b k * (k.val : ℝ)) +
          (a/(a+b))^2 * (∑ k, prior a b k) := by
        rw [Finset.sum_div, Finset.mul_sum, Finset.mul_sum,
          ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]
        apply Finset.sum_congr rfl
        intro k _
        ring
      _ = _ := by
        rw [h0, h1, h2]
        field_simp
        ring

-- The supplied moments identify the two parameters WITHIN this family.
-- They do not identify the family itself.
lemma parameters_from_moments : ∀ a b : ℝ, 0 < a → 0 < b →
    compatible (prior a b) → a = 213/10 ∧ b = 71/10 := by
  intro a b ha hb hp
  have hm := prior_moments a b ha hb
  have hs : a+b ≠ 0 := ne_of_gt (by linarith)
  have mean : a/(a+b) = 3/4 := hm.2.2.1.symm.trans hp.2.2.1
  have variance : a*b*(a+b+50)/(50*(a+b)^2*(a+b+1)) = 1/100 := by
    rw [← hm.2.2.2, mean]
    exact hp.2.2.2
  have hab : a = 3*b := by
    have h := (div_eq_iff hs).mp mean
    linarith
  have hden : 50*(a+b)^2*(a+b+1) ≠ 0 := by positivity
  have hv := (div_eq_iff hden).mp variance
  rw [hab] at hv
  have hb0 : b^2 ≠ 0 := pow_ne_zero _ (ne_of_gt hb)
  have hpoly : b^2 * (10*b-71) = 0 := by nlinarith [hv]
  have hbval : b = 71/10 := by
    have := (mul_eq_zero.mp hpoly).resolve_left hb0
    linarith
  exact ⟨by rw [hab, hbval]; norm_num, hbval⟩

-- Feasibility is proved, so the moment-fitting conditions are not vacuous.
lemma fitted_prior_compatible : compatible (prior (213/10) (71/10)) := by
  have hm := prior_moments (213/10) (71/10) (by norm_num) (by norm_num)
  refine ⟨hm.1, hm.2.1, ?_, ?_⟩
  · convert hm.2.2.1 using 1 <;> norm_num
  · convert hm.2.2.2 using 1 <;> norm_num

-- Exact evidences for the fitted finite model; both sums are evaluated in Lean.
lemma fitted_evidence10 : evidence (prior (213/10) (71/10)) 10 =
    ((23689849826939661 : ℕ) : ℝ)/((275978414373208064 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 10 : ℝ)/(Nat.choose 50 10 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

lemma fitted_evidence11 : evidence (prior (213/10) (71/10)) 11 =
    ((2471640998610704631 : ℕ) : ℝ)/((35325237039770632192 : ℕ) : ℝ) := by
  unfold evidence prior likelihood
  rw [Fin.sum_univ_eq_sum_range
    (fun k : ℕ => (Nat.choose 50 k : ℝ) * rising (213/10) k * rising (71/10) (50-k) /
      rising (213/10+71/10) 50 * ((Nat.choose k 11 : ℝ)/(Nat.choose 50 11 : ℝ))) 51]
  norm_num [Finset.sum_range_succ, rising, Nat.choose]

-- Conditional scientific answer: any positive-parameter member of the stated
-- family matching the supplied population moments predicts 313/384.
theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →
    (∑ k : Fin 51, prior a b k * ((k.val : ℝ)/((50 : ℕ) : ℝ))) =
      ((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ) →
    (∑ k : Fin 51, prior a b k *
      ((k.val : ℝ)/((50 : ℕ) : ℝ)-((3 : ℕ) : ℝ)/((4 : ℕ) : ℝ))^2) =
      1/((100 : ℕ) : ℝ) →
    prediction (prior a b) = ((313 : ℕ) : ℝ)/((384 : ℕ) : ℝ) := by
  intro a b ha hb hmean hvariance
  have hm := prior_moments a b ha hb
  have hp : compatible (prior a b) := ⟨hm.1, hm.2.1, hmean, hvariance⟩
  obtain ⟨ha', hb'⟩ := parameters_from_moments a b ha hb hp
  rw [ha', hb']
  rw [(bayesian_answer _ fitted_prior_compatible).2.2.2,
    fitted_evidence11, fitted_evidence10]
  norm_num

accepted