{
  "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?\n",
  "harness": {
    "name": "Claude Code",
    "model": "claude-sonnet-5-5"
  },
  "messages": [
    {
      "messages": [
        {
          "type": "message",
          "role": "user",
          "content": "Balls protocol v1 — human-in-the-loop scientific workflow.\n\n1. 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.\n2. 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.\n3. 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.\n4. 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.\n5. 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.\n6. 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.\n7. 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.\n8. 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.\n\nHuman-readability requirements:\n- 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.\n- 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.\n- 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.\n- 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.\n- 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.\n\nIsolation 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 subscription client needs its existing 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.\n\nTools (run in the terminal):\n  python /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json\n  python /harness/src/vcs_protocol.py tool request --kind literature --question '...'\nKinds 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.\n\nWrite /work/candidate.json with this shape (all paths relative to /work):\n{\"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\"}\nList 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.\n"
        },
        {
          "type": "message",
          "role": "user",
          "content": "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?\n"
        },
        {
          "type": "message",
          "role": "user",
          "content": "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."
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01LhVwTdLFN5fGicnE5GWwBN",
          "input": {
            "command": "cd /work; ls -la; cat candidate.json; head -c 3000 report.txt; ls *feedback* 2>/dev/null"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01LhVwTdLFN5fGicnE5GWwBN",
          "output": "Exit code 2\ntotal 8\ndrwxrwxr-x 2 1001 1001 4096 Nov 16 16:19 .\ndrwxr-xr-x 1 root root 4096 Nov 16 16:19 ..\ncat: candidate.json: No such file or directory\nhead: cannot open 'report.txt' for reading: No such file or directory",
          "is_error": true
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01NKDkpcRe9r8Xo1QYZCyTMV",
          "input": {
            "command": "cd /root 2>/dev/null; M=$(find / -type d -path '*Mathlib/RingTheory/Polynomial' 2>/dev/null | head -1); echo $M; grep -rn \"theorem.*add_choose\\|Vandermonde\\|ascPochhammer.*add\" $M/Pochhammer.lean $M/../../Algebra/Polynomial 2>/dev/null | head; grep -rln \"ascPochhammer\" $(dirname $(dirname $M)) | head -20"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01NKDkpcRe9r8Xo1QYZCyTMV",
          "output": "[… earlier output omitted; full output: /tmp/claude-1001/-work/ec6ec679-09c9-4a18-83b4-1e3b0610c611/tasks/buoy55c0q.output]\nll,\"usages\":[[150,8,150,29,\"Polynomial.factorial_smul_hasseDeriv\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Data.Nat.Choose.Basic\\\",\\\"n\\\":\\\"Nat.choose_zero_right\\\"}}\":{\"definition\":null,\"usages\":[[83,45,83,62,\"Polynomial.hasseDeriv_zero'\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Data.Nat.Choose.Cast\\\",\\\"n\\\":\\\"Nat.cast_choose\\\"}}\":{\"definition\":null,\"usages\":[[174,6,174,17,\"Polynomial.hasseDeriv_comp\"],[174,24,174,35,\"Polynomial.hasseDeriv_comp\"],[174,42,174,53,\"Polynomial.hasseDeriv_comp\"],[174,60,174,71,\"Polynomial.hasseDeriv_comp\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Data.Nat.Choose.Vandermonde\\\",\\\"n\\\":\\\"Nat.add_choose_eq\\\"}}\":{\"definition\":null,\"usages\":[[244,17,244,34,\"Polynomial.hasseDeriv_mul\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Data.Nat.Factorial.Basic\\\",\\\"n\\\":\\\"Nat.factorial_succ\\\"}}\":{\"definition\":null,\"usages\":[[141,27,141,41,\"Polynomial.factorial_smul_hasseDeriv\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Data.Nat.Factorial.Basic\\\",\\\"n\\\":\\\"Nat.factorial_zero\\\"}}\":{\"definition\":null,\"usages\":[[135,33,135,47,\"Polynomial.factorial_smul_hasseDeriv\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Logic.Function.Iterate\\\",\\\"n\\\":\\\"Function.iterate_succ_apply'\\\"}}\":{\"definition\":null,\"usages\":[[138,6,138,25,\"Polynomial.factorial_smul_hasseDeriv\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Logic.Function.Iterate\\\",\\\"n\\\":\\\"Function.iterate_zero\\\"}}\":{\"definition\":null,\"usages\":[[135,49,135,61,\"Polynomial.factorial_smul_hasseDeriv\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Order.Basic\\\",\\\"n\\\":\\\"LE.le.trans\\\"}}\":{\"definition\":null,\"usages\":[[183,34,183,39,\"Polynomial.natDegree_hasseDeriv_le\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Order.Basic\\\",\\\"n\\\":\\\"LE.le.trans_lt\\\"}}\":{\"definition\":null,\"usages\":[[93,66,93,74,\"Polynomial.hasseDeriv_eq_zero_of_lt_natDegree\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Order.Defs.LinearOrder\\\",\\\"n\\\":\\\"max_eq_right\\\"}}\":{\"definition\":null,\"usages\":[[186,27,186,39,\"Polynomial.natDegree_hasseDeriv_le\"]]},\"{\\\"c\\\":{\\\"m\\\":\\\"Mathlib.Order.Defs.PartialOrder\\\",\\\"n\\\":\\\"le_of_lt\\\"}}\":{\"definition\":null,\"usages\":[[203,60,203,68,\"Polynomial.natDegree_hasseDeriv\"]]}},\"version\":5}\nCommand did not complete within its 120s timeout and was moved to the background (ID: buoy55c0q). Output is being written to: /tmp/claude-1001/-work/ec6ec679-09c9-4a18-83b4-1e3b0610c611/tasks/buoy55c0q.output. You will be notified when it completes. If it is still running after 10m in the background, it will be stopped and you will be notified. It is running now: do not start a second copy while it runs. If it is no longer needed, stop it with TaskStop. To check interim output, use Read on that file path.\nSession cwd remains /work; directory changes made by the backgrounded command do not apply to subsequent commands."
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01PwRLTQU5m69k9tmGfbBheJ",
          "input": {
            "command": "cd /work; cat > Model.lean <<'EOF'\nimport Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Algebra.BigOperators.Group.Finset.Basic\nimport Mathlib.Tactic\n\n/-! Beta-binomial model for the number K of black balls in a 50-ball box.\n Prior: p ~ Beta(a,b), K | p ~ Binomial(50,p).  Prior pmf of K is proportional to\n C(50,k) * a^(k rising) * b^((50-k) rising)  (normalizer cancels in the posterior). -/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℚ) : ℕ → ℚ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Fitted prior parameters (derived in `params_unique`): a = 21.3, b = 7.1 -/\ndef a : ℚ := 213/10\ndef b : ℚ := 71/10\n\n/-- Unnormalised prior weight of K = k black balls out of 50 -/\ndef prior (k : ℕ) : ℚ := (Nat.choose 50 k : ℚ) * rise a k * rise b (50 - k)\n\n/-- Data: first 10 draws (without replacement) all black, given k black of 50 -/\ndef lik (k : ℕ) : ℚ := (Nat.descFactorial k 10 : ℚ) / (Nat.descFactorial 50 10 : ℚ)\n\n/-- Next draw black given k black initially and 10 black removed -/\ndef nextBlack (k : ℕ) : ℚ := ((k : ℚ) - 10) / 40\n\n/-- Posterior predictive probability that the 11th ball is black. -/\ndef predictive : ℚ :=\n  (∑ k ∈ Finset.range 51, prior k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior k * lik k)\n\n/-- Moment matching: fraction K/50 has mean m and sd s0 across boxes. Under the\nbeta-binomial with concentration c = a+b and mean m = a/c, Var(K/N) =\nm(1-m)(N+c)/(N(c+1)).  Given m = 3/4, Var = 1/100, N = 50, c is uniquely 142/5,\nhence a = 213/10, b = 71/10. -/\ntheorem params_unique (c : ℚ) (hc : 0 < c)\n    (hvar : (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100) :\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n  have h : c + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hc' : c = 142/5 := by linarith\n  subst hc'\n  refine ⟨rfl, ?_, ?_⟩ <;> norm_num [a, b]\n\n/-- Check that the explicit prior pmf with these parameters really has the\nmoments the closed form assumed (mean 0.75, sd 0.1 of K/50). -/\ntheorem prior_moments :\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50)) / (∑ k ∈ Finset.range 51, prior k) = 3/4 ∧\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50 - 3/4)^2) / (∑ k ∈ Finset.range 51, prior k) = 1/100 := by\n  constructor <;> simp [Finset.sum_range_succ, prior, rise, a, b, Nat.choose] <;> norm_num\n\n/-- ANSWER: posterior predictive probability that the next ball is black = 313/384 ≈ 0.815. -/\ntheorem answer_theorem : predictive = 313/384 := by\n  simp [predictive, Finset.sum_range_succ, prior, lik, nextBlack, rise, a, b, Nat.choose,\n    Nat.descFactorial]\n  norm_num\nEOF\ncat > candidate.json <<'EOF'\n{\"proof_file\":\"Model.lean\",\"narrative_file\":\"report.txt\",\"conclusions\":{\"answer\":\"answer_theorem\",\"parameters\":\"params_unique\"},\n\"user_facts\":[\"Box had 50 balls, black or white\",\"10 drawn without replacement, all black; 40 remain\",\"Across boxes the fraction black has mean 0.75 and sd 0.1\"],\n\"model_choices\":[\"Beta-binomial: p~Beta(a,b), K|p~Binomial(50,p) (conjugate, exchangeable, standard for overdispersed counts); the 0.75/0.1 moments are for the realised fraction K/50, not p\",\"Beta parameters derived from the moments: a+b=28.4, a=21.3, b=7.1\",\"Draws are uniformly random without replacement given K\",\"Other boxes are exchangeable with mine (my box is a random draw from that population)\"],\n\"sources\":[\"Standard beta-binomial variance formula Var(K/N)=m(1-m)(N+c)/(N(c+1))\"],\n\"incorporated_inputs\":[],\n\"proof_scope\":\"Proves: moment equations have unique solution; explicit prior pmf has those moments; explicit posterior predictive (sum over K of prior*likelihood*next-draw prob, normalised) equals 313/384. The closed-form variance formula is used in params_unique as a stated hypothesis form (verified numerically by prior_moments, not proved in general). Whether the beta-binomial family fits is for human review.\"}\nEOF\ncat > report.txt <<'EOF'\nModel: K = initial black count of my box. p~Beta(a,b); K|p~Bin(50,p). Supplied: mean 0.75, sd 0.1 of K/50 across boxes; 10 black draws w/o replacement.\nMoments: E[K/50]=a/(a+b)=0.75. Var(K/50)=m(1-m)(N+c)/(N(c+1)), c=a+b => c=28.4, a=21.3, b=7.1 (Note: naive Beta sd 0.1 would give c=17.75; but sd applies to K/50 incl. binomial noise.)\nUpdate: P(K=k|data) ∝ prior(k)*k!/(k-10)!/(50!/40!). Prediction: sum_k post(k)(k-10)/40.\nResult: (a+10)/(a+b+10)=31.3/38.4=313/384≈0.815 (matches Polya-urn exchangeability: independent of N).\nLimitations: other prior families matching the same two moments give different answers (nonuniqueness); beta-binomial is an assumption.\nEOF\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | tail -40"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01PwRLTQU5m69k9tmGfbBheJ",
          "output": "{\n  \"ok\": false,\n  \"check_complete\": false,\n  \"reviewable\": false,\n  \"verdict\": \"not_proved\",\n  \"time\": \"2026-11-16T16:22:00.126977+00:00\",\n  \"error\": \"conclusion binders must be inside the statement after ':'\"\n}"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_013LVBUi1iFLSGv946Gc54Yj",
          "input": {
            "command": "cd /work; python - <<'EOF'\ns=open('Model.lean').read()\ns=s.replace(\"\"\"theorem params_unique (c : ℚ) (hc : 0 < c)\n    (hvar : (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100) :\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n\"\"\",\"\"\"theorem params_unique : ∀ c : ℚ, 0 < c →\n    (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100 →\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n  intro c hc hvar\n\"\"\")\nopen('Model.lean','w').write(s)\nEOF\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | tail -40"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_013LVBUi1iFLSGv946Gc54Yj",
          "output": "{\n  \"ok\": false,\n  \"check_complete\": false,\n  \"reviewable\": false,\n  \"verdict\": \"not_proved\",\n  \"time\": \"2026-11-16T16:22:03.386842+00:00\",\n  \"lean_exit\": 1,\n  \"error\": \"Lean, kernel recheck or axiom audit failed; see lean.log\"\n}"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01PFdgJ5Uomk7Dcaq8PU1dA7",
          "input": {
            "command": "cd /work; ls; find . -name 'lean.log' | head; tail -40 $(find . -name lean.log | head -1)"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01PFdgJ5Uomk7Dcaq8PU1dA7",
          "output": "Model.lean\ncandidate.json\nchecks\nreport.txt\n./checks/e6357f3853974ad19ebb61bcf0f0ffda/lean.log\n/work/checks/e6357f3853974ad19ebb61bcf0f0ffda/Checked.lean:1:0: error: object file '/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib/Tactic.olean' of module Mathlib.Tactic does not exist"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01DwvhWVZP4zoxPUBQtjJwDD",
          "input": {
            "command": "cd /work; sed -i 's/^import Mathlib.Tactic$/import Mathlib.Tactic.NormNum\\nimport Mathlib.Tactic.FieldSimp\\nimport Mathlib.Tactic.Linarith\\nimport Mathlib.Algebra.BigOperators.Intervals\\nimport Mathlib.Data.Nat.Factorial.Basic/' Model.lean\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | tail -8; tail -30 $(ls -td checks/*/ | head -1)lean.log"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01DwvhWVZP4zoxPUBQtjJwDD",
          "output": "      \"answer_theorem\": \"predictive = 313 / 384\",\n      \"params_unique\": \"\\u2200 (c : \\u211a), 0 < c \\u2192 3 / 4 * (1 - 3 / 4) * (50 + c) / (50 * (c + 1)) = 1 / 100 \\u2192 c = 142 / 5 \\u2227 3 / 4 * c = _root_.a \\u2227 (1 - 3 / 4) * c = b\"\n    },\n    \"extracted_file\": \"/work/checks/d97395b5496f40279d9affe5df3bac7c/extracted.lean\",\n    \"errors\": []\n  },\n  \"scientific_relevance\": \"requires human review\"\n}\n'answer_theorem' depends on axioms: [propext, Classical.choice, Quot.sound]\n'params_unique' depends on axioms: [propext, Classical.choice, Quot.sound]\nVAS_LISTED\n\nleanchecker exit 0"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01BuCE5AT5i6BxBWFAT4hCt1",
          "input": {
            "command": "cd /work; python /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | head -12"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01BuCE5AT5i6BxBWFAT4hCt1",
          "output": "{\n \"file\": \"/work/checks/2002a8e5e2b2477abd99a1242b028073/submitted.lean\",\n \"conclusions\": [\n  \"answer_theorem\",\n  \"params_unique\"\n ],\n \"lean_exit\": 0,\n \"ok\": true,\n \"compiles_alone\": true,\n \"faithful\": {\n  \"answer_theorem\": true,\n  \"params_unique\": true"
        },
        {
          "type": "message",
          "role": "assistant",
          "content": "The candidate passes the check tool: Lean compiles it, the kernel recheck passes, and there is no `sorry` and no extra axiom. Scientific relevance is left to you.\n\n**Answer: P(next ball is black) = 313/384 ≈ 0.815.**\n\n**Model:**\n- The prior is beta-binomial: each box has a black-fraction p drawn from Beta(a, b), and its black count is K | p ~ Binomial(50, p). I chose this family because it is the standard conjugate model for overdispersed counts across similar boxes. I also assume your box is exchangeable with the other boxes, and that the 10 draws were uniformly random without replacement.\n- The supplied mean 0.75 and sd 0.1 describe the realised fraction K/50. They are not the moments of p, so the sd includes binomial noise. Matching them gives a+b = 28.4, a = 21.3 and b = 7.1. Treating the sd as that of p would wrongly give a+b = 17.75.\n- The update is an explicit sum over K = 0..50 of prior × likelihood. The likelihood is \"first 10 draws all black\", which is k!/(k−10)! divided by 50!/40!. The next-draw probability given K is (k−10)/40.\n- The result equals (a+10)/(a+b+10) = 31.3/38.4, which is what the Pólya-urn argument predicts. It does not depend on the box size.\n\n**What Lean proves:**\n- `params_unique`: given the closed-form variance formula, the moment equations have the unique solution a+b = 142/5, so a = 213/10 and b = 71/10.\n- `prior_moments` checks that the explicit prior pmf with those values really has mean 3/4 and variance 1/100.\n- `answer_theorem` states that the normalised posterior-predictive sum equals 313/384.\n\n**Limits for you to review:**\n- The beta-binomial variance formula is not proved from the pmf in general. It is used as the hypothesis form in `params_unique`, and `prior_moments` verifies it numerically for the fitted values.\n- The answer is conditional on the beta-binomial family. Other priors with the same mean and sd would give different predictions. I report that as a limitation and did not try to prove it.\n- No literature or experiment requests were made, so `incorporated_inputs` is empty.\n\nFiles are in /work:\n- Model.lean\n- candidate.json\n- report.txt"
        },
        {
          "type": "message",
          "role": "assistant",
          "content": "That notification is just the background file search I started earlier finishing. It needs no action, and it isn't a response from you. The search was only for Mathlib lemmas, and I didn't use its results.\n\nThe candidate is still the one I reported: `answer_theorem` (313/384 ≈ 0.815) and `params_unique`, in `/work/Model.lean`. It passes the check tool. I haven't received any human review or approval, so it is waiting for your assessment."
        }
      ],
      "produced_code": [
        {
          "name": "attempt-001/Model.lean",
          "content": "import Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Algebra.BigOperators.Group.Finset.Basic\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Data.Nat.Factorial.Basic\n\n/-! Beta-binomial model for the number K of black balls in a 50-ball box.\n Prior: p ~ Beta(a,b), K | p ~ Binomial(50,p).  Prior pmf of K is proportional to\n C(50,k) * a^(k rising) * b^((50-k) rising)  (normalizer cancels in the posterior). -/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℚ) : ℕ → ℚ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Fitted prior parameters (derived in `params_unique`): a = 21.3, b = 7.1 -/\ndef a : ℚ := 213/10\ndef b : ℚ := 71/10\n\n/-- Unnormalised prior weight of K = k black balls out of 50 -/\ndef prior (k : ℕ) : ℚ := (Nat.choose 50 k : ℚ) * rise a k * rise b (50 - k)\n\n/-- Data: first 10 draws (without replacement) all black, given k black of 50 -/\ndef lik (k : ℕ) : ℚ := (Nat.descFactorial k 10 : ℚ) / (Nat.descFactorial 50 10 : ℚ)\n\n/-- Next draw black given k black initially and 10 black removed -/\ndef nextBlack (k : ℕ) : ℚ := ((k : ℚ) - 10) / 40\n\n/-- Posterior predictive probability that the 11th ball is black. -/\ndef predictive : ℚ :=\n  (∑ k ∈ Finset.range 51, prior k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior k * lik k)\n\n/-- Moment matching: fraction K/50 has mean m and sd s0 across boxes. Under the\nbeta-binomial with concentration c = a+b and mean m = a/c, Var(K/N) =\nm(1-m)(N+c)/(N(c+1)).  Given m = 3/4, Var = 1/100, N = 50, c is uniquely 142/5,\nhence a = 213/10, b = 71/10. -/\ntheorem params_unique : ∀ c : ℚ, 0 < c →\n    (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100 →\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n  intro c hc hvar\n  have h : c + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hc' : c = 142/5 := by linarith\n  subst hc'\n  refine ⟨rfl, ?_, ?_⟩ <;> norm_num [a, b]\n\n/-- Check that the explicit prior pmf with these parameters really has the\nmoments the closed form assumed (mean 0.75, sd 0.1 of K/50). -/\ntheorem prior_moments :\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50)) / (∑ k ∈ Finset.range 51, prior k) = 3/4 ∧\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50 - 3/4)^2) / (∑ k ∈ Finset.range 51, prior k) = 1/100 := by\n  constructor <;> simp [Finset.sum_range_succ, prior, rise, a, b, Nat.choose] <;> norm_num\n\n/-- ANSWER: posterior predictive probability that the next ball is black = 313/384 ≈ 0.815. -/\ntheorem answer_theorem : predictive = 313/384 := by\n  simp [predictive, Finset.sum_range_succ, prior, lik, nextBlack, rise, a, b, Nat.choose,\n    Nat.descFactorial]\n  norm_num\n"
        },
        {
          "name": "attempt-001/extracted.lean",
          "content": "import Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Algebra.BigOperators.Group.Finset.Basic\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Data.Nat.Factorial.Basic\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℚ) : ℕ → ℚ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Fitted prior parameters (derived in `params_unique`): a = 21.3, b = 7.1 -/\ndef a : ℚ := 213/10\n\ndef b : ℚ := 71/10\n\n/-- Unnormalised prior weight of K = k black balls out of 50 -/\ndef prior (k : ℕ) : ℚ := (Nat.choose 50 k : ℚ) * rise a k * rise b (50 - k)\n\n/-- Data: first 10 draws (without replacement) all black, given k black of 50 -/\ndef lik (k : ℕ) : ℚ := (Nat.descFactorial k 10 : ℚ) / (Nat.descFactorial 50 10 : ℚ)\n\n/-- Next draw black given k black initially and 10 black removed -/\ndef nextBlack (k : ℕ) : ℚ := ((k : ℚ) - 10) / 40\n\n/-- Posterior predictive probability that the 11th ball is black. -/\ndef predictive : ℚ :=\n  (∑ k ∈ Finset.range 51, prior k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior k * lik k)\n\n\n/-! Conclusions (statements of the proved theorems). -/\ndef conclusion_answer_theorem : Prop := predictive = 313/384\ndef conclusion_params_unique : Prop := ∀ c : ℚ, 0 < c → (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100 → c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b\n"
        },
        {
          "name": "checks/2002a8e5e2b2477abd99a1242b028073/submitted.lean",
          "content": "import Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Algebra.BigOperators.Group.Finset.Basic\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Data.Nat.Factorial.Basic\n\n/-! Beta-binomial model for the number K of black balls in a 50-ball box.\n Prior: p ~ Beta(a,b), K | p ~ Binomial(50,p).  Prior pmf of K is proportional to\n C(50,k) * a^(k rising) * b^((50-k) rising)  (normalizer cancels in the posterior). -/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℚ) : ℕ → ℚ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Fitted prior parameters (derived in `params_unique`): a = 21.3, b = 7.1 -/\ndef a : ℚ := 213/10\ndef b : ℚ := 71/10\n\n/-- Unnormalised prior weight of K = k black balls out of 50 -/\ndef prior (k : ℕ) : ℚ := (Nat.choose 50 k : ℚ) * rise a k * rise b (50 - k)\n\n/-- Data: first 10 draws (without replacement) all black, given k black of 50 -/\ndef lik (k : ℕ) : ℚ := (Nat.descFactorial k 10 : ℚ) / (Nat.descFactorial 50 10 : ℚ)\n\n/-- Next draw black given k black initially and 10 black removed -/\ndef nextBlack (k : ℕ) : ℚ := ((k : ℚ) - 10) / 40\n\n/-- Posterior predictive probability that the 11th ball is black. -/\ndef predictive : ℚ :=\n  (∑ k ∈ Finset.range 51, prior k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior k * lik k)\n\n/-- Moment matching: fraction K/50 has mean m and sd s0 across boxes. Under the\nbeta-binomial with concentration c = a+b and mean m = a/c, Var(K/N) =\nm(1-m)(N+c)/(N(c+1)).  Given m = 3/4, Var = 1/100, N = 50, c is uniquely 142/5,\nhence a = 213/10, b = 71/10. -/\ntheorem params_unique : ∀ c : ℚ, 0 < c →\n    (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100 →\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n  intro c hc hvar\n  have h : c + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hc' : c = 142/5 := by linarith\n  subst hc'\n  refine ⟨rfl, ?_, ?_⟩ <;> norm_num [a, b]\n\n/-- Check that the explicit prior pmf with these parameters really has the\nmoments the closed form assumed (mean 0.75, sd 0.1 of K/50). -/\ntheorem prior_moments :\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50)) / (∑ k ∈ Finset.range 51, prior k) = 3/4 ∧\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50 - 3/4)^2) / (∑ k ∈ Finset.range 51, prior k) = 1/100 := by\n  constructor <;> simp [Finset.sum_range_succ, prior, rise, a, b, Nat.choose] <;> norm_num\n\n/-- ANSWER: posterior predictive probability that the next ball is black = 313/384 ≈ 0.815. -/\ntheorem answer_theorem : predictive = 313/384 := by\n  simp [predictive, Finset.sum_range_succ, prior, lik, nextBlack, rise, a, b, Nat.choose,\n    Nat.descFactorial]\n  norm_num\n"
        },
        {
          "name": "checks/d97395b5496f40279d9affe5df3bac7c/submitted.lean",
          "content": "import Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Algebra.BigOperators.Group.Finset.Basic\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Data.Nat.Factorial.Basic\n\n/-! Beta-binomial model for the number K of black balls in a 50-ball box.\n Prior: p ~ Beta(a,b), K | p ~ Binomial(50,p).  Prior pmf of K is proportional to\n C(50,k) * a^(k rising) * b^((50-k) rising)  (normalizer cancels in the posterior). -/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℚ) : ℕ → ℚ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Fitted prior parameters (derived in `params_unique`): a = 21.3, b = 7.1 -/\ndef a : ℚ := 213/10\ndef b : ℚ := 71/10\n\n/-- Unnormalised prior weight of K = k black balls out of 50 -/\ndef prior (k : ℕ) : ℚ := (Nat.choose 50 k : ℚ) * rise a k * rise b (50 - k)\n\n/-- Data: first 10 draws (without replacement) all black, given k black of 50 -/\ndef lik (k : ℕ) : ℚ := (Nat.descFactorial k 10 : ℚ) / (Nat.descFactorial 50 10 : ℚ)\n\n/-- Next draw black given k black initially and 10 black removed -/\ndef nextBlack (k : ℕ) : ℚ := ((k : ℚ) - 10) / 40\n\n/-- Posterior predictive probability that the 11th ball is black. -/\ndef predictive : ℚ :=\n  (∑ k ∈ Finset.range 51, prior k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior k * lik k)\n\n/-- Moment matching: fraction K/50 has mean m and sd s0 across boxes. Under the\nbeta-binomial with concentration c = a+b and mean m = a/c, Var(K/N) =\nm(1-m)(N+c)/(N(c+1)).  Given m = 3/4, Var = 1/100, N = 50, c is uniquely 142/5,\nhence a = 213/10, b = 71/10. -/\ntheorem params_unique : ∀ c : ℚ, 0 < c →\n    (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100 →\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n  intro c hc hvar\n  have h : c + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hc' : c = 142/5 := by linarith\n  subst hc'\n  refine ⟨rfl, ?_, ?_⟩ <;> norm_num [a, b]\n\n/-- Check that the explicit prior pmf with these parameters really has the\nmoments the closed form assumed (mean 0.75, sd 0.1 of K/50). -/\ntheorem prior_moments :\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50)) / (∑ k ∈ Finset.range 51, prior k) = 3/4 ∧\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50 - 3/4)^2) / (∑ k ∈ Finset.range 51, prior k) = 1/100 := by\n  constructor <;> simp [Finset.sum_range_succ, prior, rise, a, b, Nat.choose] <;> norm_num\n\n/-- ANSWER: posterior predictive probability that the next ball is black = 313/384 ≈ 0.815. -/\ntheorem answer_theorem : predictive = 313/384 := by\n  simp [predictive, Finset.sum_range_succ, prior, lik, nextBlack, rise, a, b, Nat.choose,\n    Nat.descFactorial]\n  norm_num\n"
        },
        {
          "name": "checks/e6357f3853974ad19ebb61bcf0f0ffda/submitted.lean",
          "content": "import Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Algebra.BigOperators.Group.Finset.Basic\nimport Mathlib.Tactic\n\n/-! Beta-binomial model for the number K of black balls in a 50-ball box.\n Prior: p ~ Beta(a,b), K | p ~ Binomial(50,p).  Prior pmf of K is proportional to\n C(50,k) * a^(k rising) * b^((50-k) rising)  (normalizer cancels in the posterior). -/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℚ) : ℕ → ℚ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Fitted prior parameters (derived in `params_unique`): a = 21.3, b = 7.1 -/\ndef a : ℚ := 213/10\ndef b : ℚ := 71/10\n\n/-- Unnormalised prior weight of K = k black balls out of 50 -/\ndef prior (k : ℕ) : ℚ := (Nat.choose 50 k : ℚ) * rise a k * rise b (50 - k)\n\n/-- Data: first 10 draws (without replacement) all black, given k black of 50 -/\ndef lik (k : ℕ) : ℚ := (Nat.descFactorial k 10 : ℚ) / (Nat.descFactorial 50 10 : ℚ)\n\n/-- Next draw black given k black initially and 10 black removed -/\ndef nextBlack (k : ℕ) : ℚ := ((k : ℚ) - 10) / 40\n\n/-- Posterior predictive probability that the 11th ball is black. -/\ndef predictive : ℚ :=\n  (∑ k ∈ Finset.range 51, prior k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior k * lik k)\n\n/-- Moment matching: fraction K/50 has mean m and sd s0 across boxes. Under the\nbeta-binomial with concentration c = a+b and mean m = a/c, Var(K/N) =\nm(1-m)(N+c)/(N(c+1)).  Given m = 3/4, Var = 1/100, N = 50, c is uniquely 142/5,\nhence a = 213/10, b = 71/10. -/\ntheorem params_unique : ∀ c : ℚ, 0 < c →\n    (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100 →\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n  intro c hc hvar\n  have h : c + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hc' : c = 142/5 := by linarith\n  subst hc'\n  refine ⟨rfl, ?_, ?_⟩ <;> norm_num [a, b]\n\n/-- Check that the explicit prior pmf with these parameters really has the\nmoments the closed form assumed (mean 0.75, sd 0.1 of K/50). -/\ntheorem prior_moments :\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50)) / (∑ k ∈ Finset.range 51, prior k) = 3/4 ∧\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50 - 3/4)^2) / (∑ k ∈ Finset.range 51, prior k) = 1/100 := by\n  constructor <;> simp [Finset.sum_range_succ, prior, rise, a, b, Nat.choose] <;> norm_num\n\n/-- ANSWER: posterior predictive probability that the next ball is black = 313/384 ≈ 0.815. -/\ntheorem answer_theorem : predictive = 313/384 := by\n  simp [predictive, Finset.sum_range_succ, prior, lik, nextBlack, rise, a, b, Nat.choose,\n    Nat.descFactorial]\n  norm_num\n"
        }
      ],
      "user_feedback": "Prove the general beta-binomial variance formula from the distribution definition too. The human is still reviewing the remaining assumptions; do not resume until that review is complete."
    },
    {
      "messages": [
        {
          "type": "message",
          "role": "user",
          "content": "revise and run the proof now. Prove the general variance formula from the distribution definition. Restore the prior normalizing denominator for clarity. Start with an explicit distribution family with unspecified parameters and the supplied moments; derive the parameters and variance formula in intermediate lemmas rather than assuming fitted parameters. Keep final assumptions and conclusion compact and scientifically interpretable. the revision has not been accepted."
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01D2dmBoCyMDybAbhFeTG9Gp",
          "input": {
            "command": "cd /work; ls -la; cat candidate.json; cat Model.lean; cat report.txt | head -80; ls *feedback* 2>/dev/null"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01D2dmBoCyMDybAbhFeTG9Gp",
          "output": "total 40\ndrwxrwxr-x 4 1001 1001 4096 Nov 17 13:16 .\ndrwxr-xr-x 1 root root 4096 Nov 17 13:17 ..\n-rw-r--r-- 1 1001 1001 2810 Nov 16 16:22 Model.lean\n-rw-r--r-- 1 1001 1001 1226 Nov 16 16:21 candidate.json\ndrwxr-xr-x 6 1001 1001 4096 Nov 16 16:23 checks\n-rw------- 1 1001 1001  417 Nov 17 13:06 human-feedback.json\ndrwx------ 2 1001 1001 4096 Nov 17 13:16 inputs\n-rw------- 1 1001 1001 7111 Nov 16 16:32 last-review-packet.json\n-rw-r--r-- 1 1001 1001  669 Nov 16 16:21 report.txt\n{\"proof_file\":\"Model.lean\",\"narrative_file\":\"report.txt\",\"conclusions\":{\"answer\":\"answer_theorem\",\"parameters\":\"params_unique\"},\n\"user_facts\":[\"Box had 50 balls, black or white\",\"10 drawn without replacement, all black; 40 remain\",\"Across boxes the fraction black has mean 0.75 and sd 0.1\"],\n\"model_choices\":[\"Beta-binomial: p~Beta(a,b), K|p~Binomial(50,p) (conjugate, exchangeable, standard for overdispersed counts); the 0.75/0.1 moments are for the realised fraction K/50, not p\",\"Beta parameters derived from the moments: a+b=28.4, a=21.3, b=7.1\",\"Draws are uniformly random without replacement given K\",\"Other boxes are exchangeable with mine (my box is a random draw from that population)\"],\n\"sources\":[\"Standard beta-binomial variance formula Var(K/N)=m(1-m)(N+c)/(N(c+1))\"],\n\"incorporated_inputs\":[],\n\"proof_scope\":\"Proves: moment equations have unique solution; explicit prior pmf has those moments; explicit posterior predictive (sum over K of prior*likelihood*next-draw prob, normalised) equals 313/384. The closed-form variance formula is used in params_unique as a stated hypothesis form (verified numerically by prior_moments, not proved in general). Whether the beta-binomial family fits is for human review.\"}\nimport Mathlib.Data.Rat.Defs\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Algebra.BigOperators.Group.Finset.Basic\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Data.Nat.Factorial.Basic\n\n/-! Beta-binomial model for the number K of black balls in a 50-ball box.\n Prior: p ~ Beta(a,b), K | p ~ Binomial(50,p).  Prior pmf of K is proportional to\n C(50,k) * a^(k rising) * b^((50-k) rising)  (normalizer cancels in the posterior). -/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℚ) : ℕ → ℚ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Fitted prior parameters (derived in `params_unique`): a = 21.3, b = 7.1 -/\ndef a : ℚ := 213/10\ndef b : ℚ := 71/10\n\n/-- Unnormalised prior weight of K = k black balls out of 50 -/\ndef prior (k : ℕ) : ℚ := (Nat.choose 50 k : ℚ) * rise a k * rise b (50 - k)\n\n/-- Data: first 10 draws (without replacement) all black, given k black of 50 -/\ndef lik (k : ℕ) : ℚ := (Nat.descFactorial k 10 : ℚ) / (Nat.descFactorial 50 10 : ℚ)\n\n/-- Next draw black given k black initially and 10 black removed -/\ndef nextBlack (k : ℕ) : ℚ := ((k : ℚ) - 10) / 40\n\n/-- Posterior predictive probability that the 11th ball is black. -/\ndef predictive : ℚ :=\n  (∑ k ∈ Finset.range 51, prior k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior k * lik k)\n\n/-- Moment matching: fraction K/50 has mean m and sd s0 across boxes. Under the\nbeta-binomial with concentration c = a+b and mean m = a/c, Var(K/N) =\nm(1-m)(N+c)/(N(c+1)).  Given m = 3/4, Var = 1/100, N = 50, c is uniquely 142/5,\nhence a = 213/10, b = 71/10. -/\ntheorem params_unique : ∀ c : ℚ, 0 < c →\n    (3/4 : ℚ) * (1 - 3/4) * (50 + c) / (50 * (c + 1)) = 1/100 →\n    c = 142/5 ∧ (3/4 : ℚ) * c = a ∧ (1 - 3/4 : ℚ) * c = b := by\n  intro c hc hvar\n  have h : c + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hc' : c = 142/5 := by linarith\n  subst hc'\n  refine ⟨rfl, ?_, ?_⟩ <;> norm_num [a, b]\n\n/-- Check that the explicit prior pmf with these parameters really has the\nmoments the closed form assumed (mean 0.75, sd 0.1 of K/50). -/\ntheorem prior_moments :\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50)) / (∑ k ∈ Finset.range 51, prior k) = 3/4 ∧\n    (∑ k ∈ Finset.range 51, prior k * ((k:ℚ)/50 - 3/4)^2) / (∑ k ∈ Finset.range 51, prior k) = 1/100 := by\n  constructor <;> simp [Finset.sum_range_succ, prior, rise, a, b, Nat.choose] <;> norm_num\n\n/-- ANSWER: posterior predictive probability that the next ball is black = 313/384 ≈ 0.815. -/\ntheorem answer_theorem : predictive = 313/384 := by\n  simp [predictive, Finset.sum_range_succ, prior, lik, nextBlack, rise, a, b, Nat.choose,\n    Nat.descFactorial]\n  norm_num\nModel: K = initial black count of my box. p~Beta(a,b); K|p~Bin(50,p). Supplied: mean 0.75, sd 0.1 of K/50 across boxes; 10 black draws w/o replacement.\nMoments: E[K/50]=a/(a+b)=0.75. Var(K/50)=m(1-m)(N+c)/(N(c+1)), c=a+b => c=28.4, a=21.3, b=7.1 (Note: naive Beta sd 0.1 would give c=17.75; but sd applies to K/50 incl. binomial noise.)\nUpdate: P(K=k|data) ∝ prior(k)*k!/(k-10)!/(50!/40!). Prediction: sum_k post(k)(k-10)/40.\nResult: (a+10)/(a+b+10)=31.3/38.4=313/384≈0.815 (matches Polya-urn exchangeability: independent of N).\nLimitations: other prior families matching the same two moments give different answers (nonuniqueness); beta-binomial is an assumption.\nhuman-feedback.json"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01RLxaSiPQ46CFpvGHLyQ8SH",
          "input": {
            "command": "cd /work; cat human-feedback.json | head -c 600; ls checks checks/*|head -30; grep -rn \"theorem ascPochhammer_add\\|add_pow\\b.*ascPoch\\|ascPochhammer_eval_add\\|theorem ascPochhammer_succ_eval\\|ascPochhammer_nat_eq\\|descPochhammer_add\" $(find / -path '*Mathlib/RingTheory/Polynomial/Pochhammer.lean' 2>/dev/null | head -1) | head; find / -name Pochhammer.lean 2>/dev/null | head -3"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01RLxaSiPQ46CFpvGHLyQ8SH",
          "output": "{\n  \"decision\": \"reject\",\n  \"binding\": \"83f45ad8ea4e26d08ea981d547955f61e0ed738fbce31f2d083292a5e26238fb\",\n  \"reason\": \"Human review: rejected. Prove the general beta-binomial variance formula from the distribution definition too. The human is still reviewing the remaining assumptions; do not resume until that review is complete.\",\n  \"time\": \"2026-11-17T13:06:36.637490+00:00\",\n  \"verification_verdict\": \"proved\"\n}\nchecks:\n2002a8e5e2b2477abd99a1242b028073\n27c584ed375641d3ad964d4f86b6c9dc\nd97395b5496f40279d9affe5df3bac7c\ne6357f3853974ad19ebb61bcf0f0ffda\n\nchecks/2002a8e5e2b2477abd99a1242b028073:\nChecked.lean\nextracted.json\nextracted.lean\nlean.log\nsubmitted-candidate.json\nsubmitted-report.txt\nsubmitted.lean\nverdict.json\n\nchecks/27c584ed375641d3ad964d4f86b6c9dc:\nsubmitted-candidate.json\nsubmitted-report.txt\nsubmitted.lean\nverdict.json\n\nchecks/d97395b5496f40279d9affe5df3bac7c:\nChecked.lean\nextracted.json\nextracted.lean\nlean.log\nsubmitted-candidate.json\nsubmitted-report.txt\nsubmitted.lean"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01LafRgitZi323bJNzudwvC7",
          "input": {
            "command": "cd /work; cp Model.lean Model_v1_cycle1.lean; cp candidate.json candidate_v1_cycle1.json; M=$(find / -type d -name Mathlib -path '*packages*' 2>/dev/null | head -1); echo $M; find / -type d -name Mathlib 2>/dev/null | head -3; grep -rln \"ascPochhammer\" $(find / -type d -name Mathlib 2>/dev/null | head -1) | head; "
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01LafRgitZi323bJNzudwvC7",
          "output": "/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib\n/harness/.lake/packages/mathlib/.lake/build/lib/lean/Mathlib\nCommand did not complete within its 120s timeout and was moved to the background (ID: b7he3r24j). Output is being written to: /tmp/claude-1001/-work/e26bd21e-ea94-4e52-a03d-5084dfd79fc7/tasks/b7he3r24j.output. You will be notified when it completes. If it is still running after 10m in the background, it will be stopped and you will be notified. It is running now: do not start a second copy while it runs. If it is no longer needed, stop it with TaskStop. To check interim output, use Read on that file path.\nSession cwd remains /work; directory changes made by the backgrounded command do not apply to subsequent commands."
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01DoPC3ZKByWy1LhgXtf78WT",
          "input": {
            "command": "cd /harness; ls; which lake lean; ls /harness/src | head"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01DoPC3ZKByWy1LhgXtf78WT",
          "output": "entrypoint.sh\nlean-toolchain\nsrc\n/opt/lean/bin/lake\n/opt/lean/bin/lean\nvcs_extract.py\nvcs_lean.py\nvcs_protocol.py\nShell cwd was reset to /work"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_019hE2euZGndcNtHrYwvBXXC",
          "input": {
            "command": "cd /work; cat > Model.lean <<'EOF'\nimport Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Algebra.BigOperators.Ring.Finset\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.LinearCombination\n\n/-!\n# Beta-binomial model for the black count of a 50-ball box\n\nSUPPLIED: box of N = 50 balls; K = unknown number of black ones; 10 balls drawn without\nreplacement, all black; across boxes the fraction K/50 has mean 3/4 and sd 1/10.\n\nMODEL CHOICE (assumption, for review): across boxes K follows a beta-binomial law with\nUNSPECIFIED positive parameters a, b:\n   P(K = k) = C(N,k) * a^(k rising) * b^((N-k) rising) / (a+b)^(N rising)\n(= the law of K | p ~ Binomial(N,p) with p ~ Beta(a,b)).  a, b are NOT assumed: they are\nderived below from the supplied mean and sd.  Given K = k, the 10 draws are a uniformly\nrandom sample without replacement, and my box is exchangeable with the other boxes.\n-/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Beta-binomial prior pmf of the initial black count k, box size N, parameters a b. -/\nnoncomputable def prior (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k) / rise (a + b) N\n\n/-- Likelihood of 10 black draws without replacement if k of 50 balls are black. -/\nnoncomputable def lik (k : ℕ) : ℝ := (k.descFactorial 10 : ℝ) / ((50 : ℕ).descFactorial 10 : ℝ)\n\n/-- Chance the 11th ball is black given k black initially and 10 black removed (40 left). -/\nnoncomputable def nextBlack (k : ℕ) : ℝ := ((k : ℝ) - 10) / 40\n\n/-- Posterior predictive probability that the next ball is black. -/\nnoncomputable def predictive (a b : ℝ) : ℝ :=\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k)\n\n/-! ### Technical lemmas (proved, not assumed) -/\n\nlemma rise_succ (x : ℝ) (n : ℕ) : rise x (n+1) = rise x n * (x + n) := rfl\n\nlemma rise_pos {x : ℝ} (hx : 0 < x) : ∀ n, 0 < rise x n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ]\n    have : (0:ℝ) ≤ n := Nat.cast_nonneg n\n    exact mul_pos ih (by linarith)\n\nlemma rise_shift (x : ℝ) : ∀ n, rise x (n+1) = x * rise (x+1) n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ x (n+1), ih, rise_succ (x+1) n]\n    push_cast\n    ring\n\n/-- unnormalised weight -/\nnoncomputable def w (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k)\n\nlemma w_succ_sum (a b : ℝ) (N : ℕ) :\n    ∑ k ∈ Finset.range (N+2), w (N+1) a b k\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n  have h1 : ∀ i : ℕ, w (N+1) a b (i+1)\n      = w N a b i * (a + i) + w N a b (i+1) * (b + N - (i+1)) := by\n    intro i\n    unfold w\n    rw [Nat.choose_succ_succ, Nat.add_sub_add_right, rise_succ a i]\n    rcases Nat.lt_or_ge i N with h | h\n    · have e : N - i = (N - (i+1)) + 1 := by omega\n      rw [e, rise_succ b (N-(i+1)), Nat.cast_sub (by omega : i+1 ≤ N)]\n      push_cast\n      ring\n    · have h0 : N.choose (i+1) = 0 := Nat.choose_eq_zero_of_lt (by omega)\n      rw [h0]\n      push_cast\n      ring\n  have hz : w N a b (N+1) = 0 := by simp [w]\n  have hA : ∑ i ∈ Finset.range (N+1), w N a b (i+1) * (b + N - (i+1))\n      = ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k) - rise b (N+1) := by\n    have := Finset.sum_range_succ' (fun k => w N a b k * (b + N - k)) (N+1)\n    rw [Finset.sum_range_succ] at this\n    have h0 : w N a b 0 * (b + N - ((0:ℕ):ℝ)) = rise b (N+1) := by\n      simp [w, rise_succ]\n    simp only [hz, zero_mul, add_zero, h0] at this\n    push_cast at this ⊢\n    linarith\n  rw [Finset.sum_range_succ' _ (N+1)]\n  simp only [h1, Finset.sum_add_distrib]\n  rw [hA]\n  have h00 : w (N+1) a b 0 = rise b (N+1) := by simp [w]\n  rw [h00]\n  have key : ∑ k ∈ Finset.range (N+1), w N a b k * (a + k)\n      + ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k)\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n    rw [Finset.mul_sum, ← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  linarith\n\n/-- The prior is normalised: Vandermonde identity for rising factorials. -/\nlemma w_sum (a b : ℝ) : ∀ N : ℕ, ∑ k ∈ Finset.range (N+1), w N a b k = rise (a+b) N := by\n  intro N\n  induction N with\n  | zero => simp [w, rise]\n  | succ n ih =>\n    rw [w_succ_sum, ih, rise_succ]\n    ring\n\nlemma shift (M : ℕ) (a b : ℝ) (f : ℕ → ℝ) :\n    ∑ k ∈ Finset.range (M+2), f k * ((k:ℝ) * w (M+1) a b k)\n      = ((M:ℝ)+1) * a * ∑ i ∈ Finset.range (M+1), f (i+1) * w M (a+1) b i := by\n  rw [Finset.sum_range_succ']\n  simp only [Nat.cast_zero, zero_mul, mul_zero, add_zero]\n  rw [Finset.mul_sum]\n  apply Finset.sum_congr rfl\n  intro i _\n  have hc := Nat.succ_mul_choose_eq M i\n  have hc' : ((M:ℝ)+1) * (M.choose i : ℝ) = ((M+1).choose (i+1) : ℝ) * ((i:ℝ)+1) := by\n    exact_mod_cast hc\n  unfold w\n  rw [Nat.add_sub_add_right, rise_shift a i]\n  push_cast\n  linear_combination (-(f (i+1)) * a * rise (a+1) i * rise b (M-i)) * hc'\n\nlemma Zr (a b : ℝ) (L : ℕ) :\n    rise (a+b) (L+2) = (a+b) * (a+b+1) * rise (a+b+2) L := by\n  rw [rise_shift (a+b) (L+1), rise_shift (a+b+1) L]\n  have : a+b+1+1 = a+b+2 := by ring\n  rw [this]\n  ring\n\nlemma S1 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k\n      = ((L:ℝ)+2) * a * ((a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun _ => 1)\n  simp only [one_mul] at h\n  have h2 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h2\n  rw [h2, h3] at h\n  push_cast at h\n  convert h using 2\n  ring\n\nlemma S2 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) * rise (a+b+2) L\n          + (a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun k => (k:ℝ))\n  have hs : ∑ i ∈ Finset.range (L+1+1), ((i+1:ℕ):ℝ) * w (L+1) (a+1) b i\n      = ∑ i ∈ Finset.range (L+1+1), (i:ℝ) * w (L+1) (a+1) b i\n        + ∑ i ∈ Finset.range (L+1+1), w (L+1) (a+1) b i := by\n    rw [← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    push_cast\n    ring\n  have h4 := shift L (a+1) b (fun _ => 1)\n  simp only [one_mul] at h4\n  have h5 := w_sum (a+1+1) b L\n  have h6 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  have e3 : a+1+1+b = a+b+2 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h6\n  rw [e3] at h5\n  rw [h5] at h4\n  rw [h6, h3] at hs\n  have hs' : ∑ i ∈ Finset.range (L+1+1), ((i:ℝ)) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := by\n    have : ∑ i ∈ Finset.range (L+2), (i:ℝ) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := h4\n    exact this\n  push_cast at h hs\n  sorry\n\nEOF\ncat > /tmp/t.sh <<'EOF'\ncd /harness && timeout 900 lake env lean /work/Model.lean 2>&1 | head -${1:-60}\nEOF\nbash /tmp/t.sh"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_019hE2euZGndcNtHrYwvBXXC",
          "output": "/work/Model.lean:1:0: error: unknown module prefix 'Mathlib'\n\nNo directory 'Mathlib' or file 'Mathlib.olean' in the search path entries:\n/opt/lean/lib/lean\n/opt/lean/lib/lean"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01Tc23g4G9YRmrbaBytxsJ1D",
          "input": {
            "command": "cd /harness/.lake/packages/mathlib 2>/dev/null && ls | head -3; cat > /tmp/t.sh <<'EOF'\ncd /harness/.lake/packages/mathlib && LEAN_PATH=$(ls -d /harness/.lake/packages/*/.lake/build/lib/lean | tr '\\n' ':') timeout 900 lean /work/Model.lean 2>&1 | head -${1:-60}\nEOF\nbash /tmp/t.sh"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01Tc23g4G9YRmrbaBytxsJ1D",
          "output": "Command did not complete within its 120s timeout and was moved to the background (ID: bx70pcvjs). Output is being written to: /tmp/claude-1001/-work/e26bd21e-ea94-4e52-a03d-5084dfd79fc7/tasks/bx70pcvjs.output. You will be notified when it completes. If it is still running after 10m in the background, it will be stopped and you will be notified. It is running now: do not start a second copy while it runs. If it is no longer needed, stop it with TaskStop. No output had been read from it when it was moved. A program that buffers its output, or a pipe into one such as tail, can keep the output file empty until the command finishes. To check interim output, use Read on that file path.\nSession cwd remains /work; directory changes made by the backgrounded command do not apply to subsequent commands."
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_013UvNBiEqwpyLm7xefGPEpT",
          "input": {
            "command": "sleep 100; cat /tmp/claude-1001/-work/*/tasks/bx70pcvjs.output"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_013UvNBiEqwpyLm7xefGPEpT",
          "output": "<tool_use_error>Blocked: sleep 100 followed by: cat /tmp/claude-1001/-work/*/tasks/bx70pcvjs.output. To wait for a condition, use Monitor with an until-loop (e.g. `until <check>; do sleep 2; done`). To wait for a command you started, use run_in_background: true. Do not chain shorter sleeps to work around this block.</tool_use_error>",
          "is_error": true
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01NgnMkGuwRd58xPzYTTc9gQ",
          "input": {
            "command": "until [ -s /tmp/claude-1001/-work/e26bd21e-ea94-4e52-a03d-5084dfd79fc7/tasks/bx70pcvjs.output ] || ! pgrep -x lean >/dev/null; do sleep 3; done; cat /tmp/claude-1001/-work/e26bd21e-ea94-4e52-a03d-5084dfd79fc7/tasks/bx70pcvjs.output",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01NgnMkGuwRd58xPzYTTc9gQ",
          "output": "/bin/bash: line 1: pgrep: command not found"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01486Qo2nF62eikrQBY2vKKv",
          "input": {
            "command": "cat /tmp/claude-1001/-work/e26bd21e-ea94-4e52-a03d-5084dfd79fc7/tasks/bx70pcvjs.output; ps aux | grep -c \"[l]ean /work\""
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01486Qo2nF62eikrQBY2vKKv",
          "output": "/bin/bash: line 1: ps: command not found\n0"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01Jvj28t4LP5Dw6am1jY5VP1",
          "input": {
            "command": "cd /work; (bash /tmp/t.sh 100 > /tmp/out.txt 2>&1; echo DONE >> /tmp/out.txt) & \nuntil grep -q DONE /tmp/out.txt 2>/dev/null; do sleep 3; done; cat /tmp/out.txt",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01Jvj28t4LP5Dw6am1jY5VP1",
          "output": "/work/Model.lean:1:0: warning: \n'Mathlib.Data.Real.Basic' has been deprecated: please replace this import by\n\nimport Mathlib.Basic.Real.Basic\n/work/Model.lean:95:64: error: unsolved goals\na b : ℝ\nN : ℕ\nh1 : ∀ (i : ℕ), w (N + 1) a b (i + 1) = w N a b i * (a + ↑i) + w N a b (i + 1) * (b + ↑N - (↑i + 1))\nhz : w N a b (N + 1) = 0\nthis :\n  ∑ x ∈ Finset.range (N + 1), w N a b x * (b + ↑N - ↑x) + w N a b (N + 1) * (b + ↑N - ↑(N + 1)) =\n    ∑ k ∈ Finset.range (N + 1), w N a b (k + 1) * (b + ↑N - ↑(k + 1)) + w N a b 0 * (b + ↑N - ↑0)\n⊢ rise a 0 * rise b N = rise b N ∨ b + ↑N = 0\n/work/Model.lean:103:45: error: unsolved goals\na b : ℝ\nN : ℕ\nh1 : ∀ (i : ℕ), w (N + 1) a b (i + 1) = w N a b i * (a + ↑i) + w N a b (i + 1) * (b + ↑N - (↑i + 1))\nhz : w N a b (N + 1) = 0\nhA :\n  ∑ i ∈ Finset.range (N + 1), w N a b (i + 1) * (b + ↑N - (↑i + 1)) =\n    ∑ k ∈ Finset.range (N + 1), w N a b k * (b + ↑N - ↑k) - rise b (N + 1)\n⊢ rise a 0 * rise b (N + 1) = rise b (N + 1)\n/work/Model.lean:131:13: error(lean.unknownIdentifier): Unknown constant `Nat.succ_mul_choose_eq`\n/work/Model.lean:125:77: error: unsolved goals\nM : ℕ\na b : ℝ\nf : ℕ → ℝ\ni : ℕ\na✝ : i ∈ Finset.range (M + 1)\n⊢ f (i + 1) * (↑(i + 1) * w (M + 1) a b (i + 1)) = (↑M + 1) * a * (f (i + 1) * w M (a + 1) b i)\n/work/Model.lean:162:6: warning: declaration uses `sorry`\nDONE"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01Lo41LXoikHdtBUVN2wki2U",
          "input": {
            "command": "cd /work; python3 - <<'EOF'\ns=open('Model.lean').read()\ns=s.replace(\"import Mathlib.Data.Real.Basic\",\"import Mathlib.Data.Real.Basic\",1)\ns=s.replace(\"lemma rise_succ (x : ℝ) (n : ℕ) : rise x (n+1) = rise x n * (x + n) := rfl\",\n\"lemma rise_succ (x : ℝ) (n : ℕ) : rise x (n+1) = rise x n * (x + n) := rfl\\n\\nlemma rise_zero (x : ℝ) : rise x 0 = 1 := rfl\")\ns=s.replace(\"simp [w, rise_succ]\\n    simp only\",\"simp [w, rise_succ, rise_zero]\\n    simp only\")\ns=s.replace(\"\"\"      simp [w, rise_succ]\n    simp only\"\"\",\"\"\"      simp [w, rise_succ, rise_zero]\n    simp only\"\"\")\ns=s.replace(\"have h00 : w (N+1) a b 0 = rise b (N+1) := by simp [w]\",\"have h00 : w (N+1) a b 0 = rise b (N+1) := by simp [w, rise_zero]\")\ns=s.replace(\"Nat.succ_mul_choose_eq\",\"Nat.add_one_mul_choose_eq\")\ni=s.index(\"  push_cast at h hs\\n  sorry\")\ns=s[:i]+\"\"\"  show ∑ k ∈ Finset.range (L+1+2), (k:ℝ) * ((k:ℝ) * w (L+1+1) a b k) = _\n  rw [h]\n  simp only []\n  rw [hs, hs']\n  push_cast\n  ring\n\nlemma prior_eq (N : ℕ) (a b : ℝ) (k : ℕ) : prior N a b k = w N a b k / rise (a+b) N := rfl\n\nlemma E0 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k = 1 := by\n  have hZ : rise (a+b) (L+2) ≠ 0 := (rise_pos (by linarith) _).ne'\n  have := w_sum a b (L+2)\n  simp only [prior_eq]\n  rw [← Finset.sum_div]\n  exact (div_eq_one_iff_eq hZ).2 this\n\nlemma E1 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ) = ((L:ℝ)+2) * a / (a+b) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S1, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\nlemma E2 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) + (a+b+1)) / ((a+b) * (a+b+1)) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S2, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\n/-- General beta-binomial variance, proved from the definition of `prior`:\nVar(K) = N a b (a+b+N) / ((a+b)^2 (a+b+1)), N = L+2 (mean is N a/(a+b)). -/\nlemma var_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * ((k:ℝ) - ((L:ℝ)+2) * a / (a+b))^2\n      = ((L:ℝ)+2) * a * b * (a+b+((L:ℝ)+2)) / ((a+b)^2 * (a+b+1)) := by\n  set μ : ℝ := ((L:ℝ)+2) * a / (a+b) with hμ\n  have e : ∀ k : ℕ, prior (L+2) a b k * ((k:ℝ) - μ)^2\n      = prior (L+2) a b k * (k:ℝ)^2 - 2 * μ * (prior (L+2) a b k * (k:ℝ))\n        + μ^2 * prior (L+2) a b k := by\n    intro k; ring\n  simp only [e, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum]\n  rw [E2 ha hb, E1 ha hb, E0 ha hb, hμ]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n  ring\n\n/-- Parameters are determined by the supplied mean and sd (intermediate result). -/\nlemma params {a b : ℝ} (ha : 0 < a) (hb : 0 < b)\n    (hmean : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4)\n    (hvar : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100) :\n    a = 213/10 ∧ b = 71/10 := by\n  have h1 := E1 ha hb 48\n  have hv := var_formula ha hb 48\n  have hs : a + b ≠ 0 := by linarith\n  have hm : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50)\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ)) / 50 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  have h1' : ∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ) = 50 * a / (a + b) := by\n    have := h1\n    norm_num at this\n    exact this\n  rw [hm, h1'] at hmean\n  have hab : a = 3 * b := by\n    field_simp at hmean\n    linarith\n  have hμ : (50 : ℝ) * a / (a + b) = 75 / 2 := by\n    rw [hab]; field_simp; ring\n  have hv' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 50 * a / (a + b))^2\n      = 50 * a * b * (a + b + 50) / ((a+b)^2 * (a+b+1)) := by\n    have := hv\n    norm_num at this\n    exact this\n  rw [hμ] at hv'\n  have hvar' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 75/2)^2) / 2500 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  rw [hvar', hv'] at hvar\n  subst hab\n  have hb2 : b ≠ 0 := hb.ne'\n  have h4 : 3 * b + b + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hb' : b = 71/10 := by\n    have : b^2 * (b * 100000 - 7100 * 100) = 0 := by nlinarith [hvar]\n    have hb2' : b^2 ≠ 0 := pow_ne_zero 2 hb2\n    have := (mul_eq_zero.mp this).resolve_left hb2'\n    linarith\n  subst hb'\n  norm_num\n\n/-! ### Final answer -/\n\n/-- ANSWER.  If K has the beta-binomial prior (unspecified a,b>0) whose K/50 has mean 3/4 and\nvariance 1/100, then after 10 black draws without replacement the probability that the\nnext ball is black is 313/384 ≈ 0.815. -/\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 →\n    predictive a b = 313/384 := by\n  intro a b ha hb hm hv\n  obtain ⟨rfl, rfl⟩ := params ha hb hm hv\n  simp only [predictive, prior, lik, nextBlack, Finset.sum_range_succ, Finset.sum_range_zero,\n    rise, Nat.choose, Nat.descFactorial]\n  norm_num\n\"\"\"\nopen('Model.lean','w').write(s)\nEOF\n(bash /tmp/t.sh 100 > /tmp/out.txt 2>&1; echo DONE >> /tmp/out.txt) & \nuntil grep -q DONE /tmp/out.txt 2>/dev/null; do sleep 3; done; cat /tmp/out.txt",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01Lo41LXoikHdtBUVN2wki2U",
          "output": "/work/Model.lean:1:0: warning: \n'Mathlib.Data.Real.Basic' has been deprecated: please replace this import by\n\nimport Mathlib.Basic.Real.Basic\n/work/Model.lean:197:2: error: `simp` made no progress\n/work/Model.lean:209:8: error(lean.unknownIdentifier): Unknown constant `Finset.sum_div`\n/work/Model.lean:205:55: error: unsolved goals\na b : ℝ\nha : 0 < a\nhb : 0 < b\nL : ℕ\nhZ : rise (a + b) (L + 2) ≠ 0\nthis : ∑ k ∈ Finset.range (L + 2 + 1), w (L + 2) a b k = rise (a + b) (L + 2)\n⊢ ∑ k ∈ Finset.range (L + 3), w (L + 2) a b k / rise (a + b) (L + 2) = 1\n/work/Model.lean:217:8: error(lean.unknownIdentifier): Unknown constant `Finset.sum_div`\n/work/Model.lean:233:8: error(lean.unknownIdentifier): Unknown constant `Finset.sum_div`\n/work/Model.lean:270:8: error(lean.unknownIdentifier): Unknown constant `Finset.sum_div`\n/work/Model.lean:292:8: error(lean.unknownIdentifier): Unknown constant `Finset.sum_div`\n/work/Model.lean:311:0: error: (deterministic) timeout at `whnf`, maximum number of heartbeats (200000) has been reached\n\nNote: Use `set_option maxHeartbeats <num>` to set the limit.\n\nHint: Additional diagnostic information may be available using the `set_option diagnostics true` command.\nDONE"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_018cPfcwgqKtEXNU34TwoBPQ",
          "input": {
            "command": "cd /work; python3 - <<'EOF'\ns=open('Model.lean').read()\ns=s.replace(\"import Mathlib.Algebra.BigOperators.Ring.Finset\",\"import Mathlib.Algebra.BigOperators.Ring.Finset\\nimport Mathlib.Algebra.BigOperators.Field\")\ns=s.replace(\"  simp only []\\n  rw [hs, hs']\",\"  beta_reduce at h\\n  rw [hs, hs']\")\ns=s.replace(\"theorem answer_theorem\",\"set_option maxHeartbeats 4000000 in\\ntheorem answer_theorem\")\nopen('Model.lean','w').write(s)\nEOF\n(bash /tmp/t.sh 100 > /tmp/out.txt 2>&1; echo DONE >> /tmp/out.txt) & \nuntil grep -q DONE /tmp/out.txt 2>/dev/null; do sleep 3; done; cat /tmp/out.txt",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_018cPfcwgqKtEXNU34TwoBPQ",
          "output": "/work/Model.lean:1:0: warning: \n'Mathlib.Data.Real.Basic' has been deprecated: please replace this import by\n\nimport Mathlib.Basic.Real.Basic\n/work/Model.lean:314:41: error: unexpected token 'set_option'; expected 'lemma'\n/work/Model.lean:316:0: error: (deterministic) timeout at `whnf`, maximum number of heartbeats (4000000) has been reached\n\nNote: Use `set_option maxHeartbeats <num>` to set the limit.\n\nHint: Additional diagnostic information may be available using the `set_option diagnostics true` command.\nDONE"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_0148tFaHw8Nu5sJVSSX3fhma",
          "input": {
            "command": "cd /work; python3 - <<'EOF'\ns=open('Model.lean').read()\ni=s.index(\"/-! ### Final answer -/\")\ns=s[:i]+\"\"\"/-! ### Posterior predictive (general Polya-urn identity, proved from the definitions) -/\n\nlemma Fdesc (b : ℝ) : ∀ n N : ℕ, ∀ a : ℝ, n ≤ N →\n    ∑ k ∈ Finset.range (N+1), ((k.descFactorial n : ℕ) : ℝ) * w N a b k\n      = ((N.descFactorial n : ℕ) : ℝ) * rise a n * rise (a + n + b) (N - n) := by\n  intro n\n  induction n with\n  | zero =>\n    intro N a _\n    simp only [Nat.descFactorial_zero, Nat.cast_one, one_mul, Nat.sub_zero, Nat.cast_zero,\n      add_zero, rise_zero]\n    exact w_sum a b N\n  | succ n ih =>\n    intro N a hn\n    obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by omega⟩\n    have h := shift M a b (fun k => ((( k - 1).descFactorial n : ℕ) : ℝ))\n    have e : ∀ k : ℕ, ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) := by\n      intro k\n      cases k with\n      | zero => simp\n      | succ i =>\n        rw [Nat.succ_descFactorial_succ]\n        simp only [Nat.add_sub_cancel]\n        push_cast\n        ring\n    have hL : ∑ k ∈ Finset.range (M+1+1), ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ∑ k ∈ Finset.range (M+2), ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) :=\n      Finset.sum_congr rfl (fun k _ => e k)\n    rw [hL, h]\n    simp only [Nat.add_sub_cancel]\n    rw [ih M (a+1) (by omega), Nat.succ_descFactorial_succ, rise_shift a n]\n    have e2 : M + 1 - (n + 1) = M - n := by omega\n    rw [e2]\n    have e3 : a + 1 + (n:ℝ) + b = a + ((n+1 : ℕ) : ℝ) + b := by push_cast; ring\n    rw [e3]\n    push_cast\n    ring\n\n/-- General result: after n black draws, the predictive probability is (a+n)/(a+b+n);\nhere specialised to N = 50, n = 10. -/\nlemma predictive_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) :\n    predictive a b = (a + 10) / (a + b + 10) := by\n  have hZ : rise (a+b) 50 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hD : (((50:ℕ).descFactorial 10 : ℕ) : ℝ) ≠ 0 := by\n    norm_num [Nat.descFactorial]\n  have hR : rise (a + 11 + b) 39 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hA : rise a 10 ≠ 0 := (rise_pos ha _).ne'\n  have hx : a + 10 + b ≠ 0 := by linarith\n  have h11 := Fdesc b 11 50 a (by norm_num)\n  have h10 := Fdesc b 10 50 a (by norm_num)\n  have hd : ((50:ℕ).descFactorial 11 : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) := by\n    norm_num [Nat.descFactorial]\n  have hr11 : rise a 11 = rise a 10 * (a + 10) := by\n    have := rise_succ a 10\n    norm_num at this\n    exact this\n  have hr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39 := by\n    have := rise_shift (a + 10 + b) 39\n    have e : a + 10 + b + 1 = a + 11 + b := by ring\n    rw [e] at this\n    exact this\n  have hk : ∀ k : ℕ, ((k.descFactorial 11 : ℕ) : ℝ) = ((k.descFactorial 10 : ℕ) : ℝ) * ((k:ℝ) - 10) := by\n    intro k\n    rcases Nat.lt_or_ge k 10 with h | h\n    · have h0 : k.descFactorial 10 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr h\n      have h1 : k.descFactorial 11 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr (by omega)\n      rw [h0, h1]; simp\n    · rw [show (11:ℕ) = 10 + 1 from rfl, Nat.descFactorial_succ, Nat.cast_mul, Nat.cast_sub h]\n      push_cast\n      ring\n  set Z := rise (a+b) 50 with hZdef\n  set D : ℝ := (((50:ℕ).descFactorial 10 : ℕ) : ℝ) with hDdef\n  have hnum : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k) / (Z * D * 40) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik, nextBlack, hk k]\n    field_simp\n  have hden : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k) / (Z * D) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik]\n    field_simp\n  unfold predictive\n  rw [hnum, hden]\n  norm_num at h11 h10\n  rw [h11, h10, hd, hr11, hr40]\n  field_simp\n  ring\n\n/-! ### Final answer -/\n\n/-- ANSWER.  If K has the beta-binomial prior (unspecified a,b>0) whose K/50 has mean 3/4 and\nvariance 1/100, then after 10 black draws without replacement the probability that the\nnext ball is black is 313/384 ≈ 0.815. -/\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 →\n    predictive a b = 313/384 := by\n  intro a b ha hb hm hv\n  obtain ⟨rfl, rfl⟩ := params ha hb hm hv\n  rw [predictive_formula ha hb]\n  norm_num\n\"\"\"\nopen('Model.lean','w').write(s)\nEOF\n(bash /tmp/t.sh 120 > /tmp/out.txt 2>&1; echo DONE >> /tmp/out.txt) & \nuntil grep -q DONE /tmp/out.txt 2>/dev/null; do sleep 3; done; cat /tmp/out.txt",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_0148tFaHw8Nu5sJVSSX3fhma",
          "output": "/work/Model.lean:1:0: warning: \n'Mathlib.Data.Real.Basic' has been deprecated: please replace this import by\n\nimport Mathlib.Basic.Real.Basic\n/work/Model.lean:384:95: error: unsolved goals\na b : ℝ\nha : 0 < a\nhb : 0 < b\nhR : rise (a + 11 + b) 39 ≠ 0\nhA : rise a 10 ≠ 0\nhx : a + 10 + b ≠ 0\nh11 :\n  ∑ k ∈ Finset.range (50 + 1), ↑(k.descFactorial 11) * w 50 a b k =\n    ↑(Nat.descFactorial 50 11) * rise a 11 * rise (a + ↑11 + b) (50 - 11)\nhr11 : rise a 11 = rise a 10 * (a + 10)\nhr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39\nhk : ∀ (k : ℕ), ↑(k.descFactorial 11) = ↑(k.descFactorial 10) * (↑k - 10)\nZ : ℝ := rise (a + b) 50\nhZ : Z ≠ 0\nhZdef : Z = rise (a + b) 50\nD : ℝ := ↑(Nat.descFactorial 50 10)\nhD : D ≠ 0\nh10 : ∑ k ∈ Finset.range (50 + 1), ↑(k.descFactorial 10) * w 50 a b k = D * rise a 10 * rise (a + ↑10 + b) (50 - 10)\nhd : ↑(Nat.descFactorial 50 11) = 40 * D\nhDdef : D = ↑(Nat.descFactorial 50 10)\nk : ℕ\na✝ : k ∈ Finset.range 51\n⊢ w 50 a b k * ↑(k.descFactorial 10) * (↑k - 10) * Z * D / rise (a + b) 50 =\n    w 50 a b k * ↑(k.descFactorial 10) * ↑(Nat.descFactorial 50 10) * (↑k - 10)\n/work/Model.lean:391:90: error: unsolved goals\na b : ℝ\nha : 0 < a\nhb : 0 < b\nhR : rise (a + 11 + b) 39 ≠ 0\nhA : rise a 10 ≠ 0\nhx : a + 10 + b ≠ 0\nh11 :\n  ∑ k ∈ Finset.range (50 + 1), ↑(k.descFactorial 11) * w 50 a b k =\n    ↑(Nat.descFactorial 50 11) * rise a 11 * rise (a + ↑11 + b) (50 - 11)\nhr11 : rise a 11 = rise a 10 * (a + 10)\nhr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39\nhk : ∀ (k : ℕ), ↑(k.descFactorial 11) = ↑(k.descFactorial 10) * (↑k - 10)\nZ : ℝ := rise (a + b) 50\nhZ : Z ≠ 0\nhZdef : Z = rise (a + b) 50\nD : ℝ := ↑(Nat.descFactorial 50 10)\nhD : D ≠ 0\nh10 : ∑ k ∈ Finset.range (50 + 1), ↑(k.descFactorial 10) * w 50 a b k = D * rise a 10 * rise (a + ↑10 + b) (50 - 10)\nhd : ↑(Nat.descFactorial 50 11) = 40 * D\nhDdef : D = ↑(Nat.descFactorial 50 10)\nhnum :\n  ∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k =\n    (∑ k ∈ Finset.range 51, ↑(k.descFactorial 11) * w 50 a b k) / (Z * D * 40)\nk : ℕ\na✝ : k ∈ Finset.range 51\n⊢ w 50 a b k * ↑(k.descFactorial 10) * Z * D / rise (a + b) 50 =\n    w 50 a b k * ↑(k.descFactorial 10) * ↑(Nat.descFactorial 50 10)\n/work/Model.lean:400:6: error: Tactic `rewrite` failed: Did not find an occurrence of the pattern\n  ∑ x ∈ Finset.range 51,\n    ↑(x - 10) *\n        (↑(x - 9) *\n          (↑(x - 8) * (↑(x - 7) * (↑(x - 6) * (↑(x - 5) * (↑(x - 4) * (↑(x - 3) * (↑(x - 2) * (↑(x - 1) * ↑x))))))))) *\n      w 50 a b x\nin the target expression\n  (∑ k ∈ Finset.range 51, ↑(k.descFactorial 11) * w 50 a b k) / (Z * D * 40) /\n      ((∑ k ∈ Finset.range 51, ↑(k.descFactorial 10) * w 50 a b k) / (Z * D)) =\n    (a + 10) / (a + b + 10)\n\na b : ℝ\nha : 0 < a\nhb : 0 < b\nhR : rise (a + 11 + b) 39 ≠ 0\nhA : rise a 10 ≠ 0\nhx : a + 10 + b ≠ 0\nhr11 : rise a 11 = rise a 10 * (a + 10)\nhr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39\nhk : ∀ (k : ℕ), ↑(k.descFactorial 11) = ↑(k.descFactorial 10) * (↑k - 10)\nZ : ℝ := rise (a + b) 50\nhZ : Z ≠ 0\nhZdef : Z = rise (a + b) 50\nD : ℝ := ↑(Nat.descFactorial 50 10)\nhD : D ≠ 0\nhd : ↑(Nat.descFactorial 50 11) = 40 * D\nhDdef : D = ↑(Nat.descFactorial 50 10)\nhnum :\n  ∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k =\n    (∑ k ∈ Finset.range 51, ↑(k.descFactorial 11) * w 50 a b k) / (Z * D * 40)\nhden :\n  ∑ k ∈ Finset.range 51, prior 50 a b k * lik k = (∑ k ∈ Finset.range 51, ↑(k.descFactorial 10) * w 50 a b k) / (Z * D)\nh11 :\n  ∑ x ∈ Finset.range 51,\n      ↑(x - 10) *\n          (↑(x - 9) *\n            (↑(x - 8) *\n              (↑(x - 7) * (↑(x - 6) * (↑(x - 5) * (↑(x - 4) * (↑(x - 3) * (↑(x - 2) * (↑(x - 1) * ↑x))))))))) *\n        w 50 a b x =\n    1491041720931840000 * rise a 11 * rise (a + 11 + b) 39\nh10 :\n  ∑ x ∈ Finset.range 51,\n      ↑(x - 9) *\n          (↑(x - 8) * (↑(x - 7) * (↑(x - 6) * (↑(x - 5) * (↑(x - 4) * (↑(x - 3) * (↑(x - 2) * (↑(x - 1) * ↑x)))))))) *\n        w 50 a b x =\n    D * rise a 10 * rise (a + 10 + b) 40\n⊢ (∑ k ∈ Finset.range 51, ↑(k.descFactorial 11) * w 50 a b k) / (Z * D * 40) /\n      ((∑ k ∈ Finset.range 51, ↑(k.descFactorial 10) * w 50 a b k) / (Z * D)) =\n    (a + 10) / (a + b + 10)\nDONE"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01SXy4ifmi2rVxCReYs2WK9o",
          "input": {
            "command": "cd /work; python3 - <<'EOF'\ns=open('Model.lean').read()\na=s.index(\"  have h11 := Fdesc b 11 50 a\")\nb_=s.index(\"  have hd :\")\ns=s[:a]+\"\"\"  have h11 : ∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 11 : ℕ) : ℝ) * rise a 11 * rise (a + 11 + b) 39 := by\n    have h := Fdesc b 11 50 a (by norm_num)\n    rw [show a + ((11:ℕ):ℝ) + b = a + 11 + b by push_cast; ring] at h\n    exact h\n  have h10 : ∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * rise a 10 * rise (a + 10 + b) 40 := by\n    have h := Fdesc b 10 50 a (by norm_num)\n    rw [show a + ((10:ℕ):ℝ) + b = a + 10 + b by push_cast; ring] at h\n    exact h\n\"\"\"+s[b_:]\ns=s.replace(\"  set Z := rise (a+b) 50 with hZdef\\n  set D : ℝ := (((50:ℕ).descFactorial 10 : ℕ) : ℝ) with hDdef\\n\",\"\")\ns=s.replace(\"(Z * D * 40)\",\"(rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * 40)\").replace(\"(Z * D)\",\"(rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ))\")\ns=s.replace(\"  norm_num at h11 h10\\n  rw [h11\",\"  rw [h11\")\ns=s.replace(\"hd : ((50:ℕ).descFactorial 11 : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ)\",\"hd : (((50:ℕ).descFactorial 11 : ℕ) : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ)\")\nopen('Model.lean','w').write(s)\nEOF\ngrep -n \"have hd\" Model.lean\n(bash /tmp/t.sh 80 > /tmp/out.txt 2>&1; echo DONE >> /tmp/out.txt) & \nuntil grep -q DONE /tmp/out.txt 2>/dev/null; do sleep 3; done; cat /tmp/out.txt",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01SXy4ifmi2rVxCReYs2WK9o",
          "output": "369:  have hd : (((50:ℕ).descFactorial 11 : ℕ) : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) := by\n396:  have hden : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k\n/work/Model.lean:1:0: warning: \n'Mathlib.Data.Real.Basic' has been deprecated: please replace this import by\n\nimport Mathlib.Basic.Real.Basic\nDONE"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01FJLWSwLgMndKaBiU522diR",
          "input": {
            "command": "cd /work; cat > report.txt <<'EOF'\nCYCLE 2 REVISION (responds to human review: start from family with unspecified parameters, restore prior denominator, prove variance formula, derive a,b in lemmas)\n\nSUPPLIED: box of 50 balls; 10 drawn without replacement, all black; across boxes fraction black K/50 has mean 0.75, sd 0.1; K unknown.\nMODEL CHOICES (for review): K ~ beta-binomial(N=50; a,b) with a,b>0 UNSPECIFIED:\n  prior N a b k = C(N,k) rise(a,k) rise(b,N-k) / rise(a+b,N)   (normalising denominator included)\n  (= K|p~Bin(N,p), p~Beta(a,b); standard conjugate family for overdispersed counts.)\n  Supplied moments apply to K/50 (hypotheses: E[K/50]=3/4, E[(K/50-3/4)^2]=1/100).\n  Given K=k, the 10 draws are uniform sampling without replacement; my box is exchangeable with the other boxes.\nPROVED (Lean, no sorry, no axioms):\n  E0 normalisation (Vandermonde for rising factorials), E1 mean N a/(a+b), E2 second moment,\n  var_formula: Var(K)=N a b (a+b+N)/((a+b)^2 (a+b+1)) from the definition,\n  params: the two moments force a=21.3, b=7.1 (intermediate lemma),\n  predictive_formula: posterior predictive = (a+10)/(a+b+10) for all a,b>0 (general Polya-urn identity via Fdesc),\n  answer_theorem: under the hypotheses, predictive = 313/384 ~ 0.815.\nLIMITATION: the two moments fix a,b only within the beta-binomial family; other families matching the moments would give other answers (nonuniqueness is a limitation, not the target).\nEOF\ncat > candidate.json <<'EOF'\n{\"proof_file\":\"Model.lean\",\"narrative_file\":\"report.txt\",\"conclusions\":{\"answer\":\"answer_theorem\"},\n\"user_facts\":[\"Box had 50 balls, each black or white\",\"10 balls drawn without replacement, all black; 40 remain\",\"Across boxes the fraction of black balls has mean 0.75 and sd 0.1\",\"Original black count of this box unknown\"],\n\"model_choices\":[\"K (initial black count) is beta-binomial(50; a, b) with unspecified a,b>0: K|p~Bin(50,p), p~Beta(a,b); chosen as the standard conjugate family for overdispersed counts\",\"The supplied mean 0.75 and sd 0.1 refer to the realised fraction K/50 across boxes; a and b are derived from them (not assumed)\",\"Given K, draws are uniform without replacement\",\"My box is exchangeable with the other boxes (a random draw from the population)\"],\n\"sources\":[\"Standard beta-binomial / Polya urn theory (all results re-proved in Lean)\"],\n\"incorporated_inputs\":[\"cca5e000963947c68cdbede5e2bec77f\"],\n\"proof_scope\":\"Proves from the explicit pmf: normalisation, mean, general variance formula, a=21.3 and b=7.1 from the moments, general posterior predictive (a+10)/(a+b+10), and final 313/384. Premises are only the beta-binomial family choice, the moment hypotheses, and the sampling model; whether the family is appropriate is for human review. Previous attempt kept as Model_v1_cycle1.lean.\"}\nEOF\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | tail -30",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01FJLWSwLgMndKaBiU522diR",
          "output": "  \"nextBlack\": {\n   \"original_sha256\": \"e75530b9806e64a0c7ac14c63bdc84d67f094e067c6da349df2bbc32ed103ea7\",\n   \"extracted_sha256\": \"e75530b9806e64a0c7ac14c63bdc84d67f094e067c6da349df2bbc32ed103ea7\"\n  },\n  \"nextBlack._proof_1\": {\n   \"original_sha256\": \"a052b10c67fb53d7d230a6030a8bdb3873a340a597be56e14e518c2949c4bd6e\",\n   \"extracted_sha256\": \"a052b10c67fb53d7d230a6030a8bdb3873a340a597be56e14e518c2949c4bd6e\"\n  },\n  \"nextBlack._proof_2\": {\n   \"original_sha256\": \"6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d\",\n   \"extracted_sha256\": \"6b903157af08e027f7f4b04e5f87949afd8146c81cb280d9647828c9c6683a4d\"\n  }\n },\n \"unranged\": [],\n \"added_assumptions\": [],\n \"conclusions_as_proved\": {\n  \"answer_theorem\": \"\\u2200 (a b : \\u211d), 0 < a \\u2192 0 < b \\u2192 \\u2211 k \\u2208 Finset.range 51, prior 50 a b k * (\\u2191k / 50) = 3 / 4 \\u2192 \\u2211 k \\u2208 Finset.range 51, prior 50 a b k * (\\u2191k / 50 - 3 / 4) ^ 2 = 1 / 100 \\u2192 predictive a b = 313 / 384\"\n },\n \"extracted_file\": \"/work/checks/42f5113ca21243669beaab7811fe04d4/extracted.lean\",\n \"errors\": []\n}\n{\n  \"ok\": false,\n  \"check_complete\": false,\n  \"reviewable\": false,\n  \"verdict\": \"not_proved\",\n  \"time\": \"2026-11-17T13:35:47.668361+00:00\",\n  \"lean_exit\": 0,\n  \"error\": \"independent extraction failed\"\n}"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01YBXKhMg2Vxkrwz4v9SacuH",
          "input": {
            "command": "cd /work/checks/42f5113ca21243669beaab7811fe04d4; ls; cat verdict.json; head -c 1500 lean.log; python /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | head -40",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01YBXKhMg2Vxkrwz4v9SacuH",
          "output": "Checked.lean\nextracted.json\nextracted.lean\nlean.log\nsubmitted-candidate.json\nsubmitted-report.txt\nsubmitted.lean\nverdict.json\n{\n  \"ok\": false,\n  \"check_complete\": false,\n  \"reviewable\": false,\n  \"verdict\": \"not_proved\",\n  \"time\": \"2026-11-17T13:35:47.668361+00:00\",\n  \"lean_exit\": 0,\n  \"error\": \"independent extraction failed\"\n}\n/work/checks/42f5113ca21243669beaab7811fe04d4/Checked.lean:1:0: warning: \n'Mathlib.Data.Real.Basic' has been deprecated: please replace this import by\n\nimport Mathlib.Basic.Real.Basic\n'answer_theorem' depends on axioms: [propext, Classical.choice, Quot.sound]\nVAS_LISTED\n\nleanchecker exit 0\n\n{\n \"file\": \"/work/checks/6ecce009375a4db9ace0f8950a9032ce/submitted.lean\",\n \"conclusions\": [\n  \"answer_theorem\"\n ],\n \"lean_exit\": 0,\n \"ok\": false,\n \"compiles_alone\": true,\n \"faithful\": {\n  \"answer_theorem\": false\n },\n \"assumption_declarations\": [\n  \"rise\",\n  \"prior\",\n  \"lik\",\n  \"nextBlack\",\n  \"predictive\"\n ],\n \"identity_method\": \"kernel-expression-repr-v1\",\n \"conclusion_identities\": {\n  \"answer_theorem\": {\n   \"original_sha256\": \"612a9333746984b9a5d52f613b7a3ce090fb899b242aee9b04c757998b9eb6e3\",\n   \"extracted_sha256\": \"b71e000d908a78e08d0dd3cd1149ddebe2642685f2fa7cbc36e2c022bc03b829\"\n  }\n },\n \"dependency_faithful\": {\n  \"prior\": true,\n  \"rise\": true,\n  \"rise._f\": true,\n  \"rise.match_1\": true,\n  \"predictive\": true,\n  \"lik\": true,\n  \"nextBlack\": true,\n  \"nextBlack._proof_1\": true,\n  \"nextBlack._proof_2\": true\n },\n \"dependency_identities\": {\n  \"prior\": {\n   \"original_sha256\": \"05aa796521ade75cf04c2fe62259f0435b4947f704abbf8e06b7061d62bd350d\",\n   \"extracted_sha256\": \"05aa796521ade75cf04c2fe62259f0435b4947f704abbf8e06b7061d62bd350d\""
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01VYC3fMrpeiFvBXKQFsz2e6",
          "input": {
            "command": "cd /work/checks/42f5113ca21243669beaab7811fe04d4; cat extracted.lean | head -60; diff <(sed -n '1,400p' /work/Model.lean) submitted.lean | head"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01VYC3fMrpeiFvBXKQFsz2e6",
          "output": "import Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Algebra.BigOperators.Ring.Finset\nimport Mathlib.Algebra.BigOperators.Field\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.LinearCombination\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Beta-binomial prior pmf of the initial black count k, box size N, parameters a b. -/\nnoncomputable def prior (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k) / rise (a + b) N\n\n/-- Likelihood of 10 black draws without replacement if k of 50 balls are black. -/\nnoncomputable def lik (k : ℕ) : ℝ := (k.descFactorial 10 : ℝ) / ((50 : ℕ).descFactorial 10 : ℝ)\n\n/-- Chance the 11th ball is black given k black initially and 10 black removed (40 left). -/\nnoncomputable def nextBlack (k : ℕ) : ℝ := ((k : ℝ) - 10) / 40\n\n/-- Posterior predictive probability that the next ball is black. -/\nnoncomputable def predictive (a b : ℝ) : ℝ :=\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k)\n\n\n/-! Conclusions (statements of the proved theorems). -/\ndef conclusion_answer_theorem : Prop := ∀ a b : ℝ, 0 < a → 0 < b → ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 → ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 → predictive a b = 313/384\n400a401,421\n>     rw [prior_eq, lik]\n>     field_simp\n>   unfold predictive\n>   rw [hnum, hden]\n>   rw [h11, h10, hd, hr11, hr40]\n>   field_simp\n>   ring\n> \n> /-! ### Final answer -/"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01SWe4KK8vmSJrN3KMg8gJVU",
          "input": {
            "command": "cd /work; python /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | grep -v sha256 | head -60; grep -n \"unsupported\\|reprs\\|repr\" /harness/src/vcs_extract.py | head -30",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01SWe4KK8vmSJrN3KMg8gJVU",
          "output": "{\n \"file\": \"/work/checks/a13c66c5450348d7838838d13ab7ba13/submitted.lean\",\n \"conclusions\": [\n  \"answer_theorem\"\n ],\n \"lean_exit\": 0,\n \"ok\": false,\n \"compiles_alone\": true,\n \"faithful\": {\n  \"answer_theorem\": false\n },\n \"assumption_declarations\": [\n  \"rise\",\n  \"prior\",\n  \"lik\",\n  \"nextBlack\",\n  \"predictive\"\n ],\n \"identity_method\": \"kernel-expression-repr-v1\",\n \"conclusion_identities\": {\n  \"answer_theorem\": {\n  }\n },\n \"dependency_faithful\": {\n  \"prior\": true,\n  \"rise\": true,\n  \"rise._f\": true,\n  \"rise.match_1\": true,\n  \"predictive\": true,\n  \"lik\": true,\n  \"nextBlack\": true,\n  \"nextBlack._proof_1\": true,\n  \"nextBlack._proof_2\": true\n },\n \"dependency_identities\": {\n  \"prior\": {\n  },\n  \"rise\": {\n  },\n  \"rise._f\": {\n  },\n  \"rise.match_1\": {\n  },\n  \"predictive\": {\n  },\n  \"lik\": {\n  },\n  \"nextBlack\": {\n  },\n  \"nextBlack._proof_1\": {\n  },\n  \"nextBlack._proof_2\": {\n  }\n },\n \"unranged\": [],\n \"added_assumptions\": [],\n \"conclusions_as_proved\": {\n  \"answer_theorem\": \"\\u2200 (a b : \\u211d), 0 < a \\u2192 0 < b \\u2192 \\u2211 k \\u2208 Finset.range 51, prior 50 a b k * (\\u2191k / 50) = 3 / 4 \\u2192 \\u2211 k \\u2208 Finset.range 51, prior 50 a b k * (\\u2191k / 50 - 3 / 4) ^ 2 = 1 / 100 \\u2192 predictive a b = 313 / 384\"\n },\n \"extracted_file\": \"/work/checks/a13c66c5450348d7838838d13ab7ba13/extracted.lean\",\n38:    | .inductInfo info => s!\"inductive {info.numParams} {info.numIndices} {reprStr info.ctors}\"\n42:    | some body => reprStr (VAS_identityExpr body)\n44:  s!\"{kind}|levels={reprStr ci.levelParams}|type={reprStr (VAS_identityExpr ci.type)}|value={value}\"\n59:    logInfo m!\"VAS_ORIGINAL_IDENTITY {t} : {reprStr (VAS_identityExpr ci.type)} VAS_END\"\n93:    logInfo m!\"VAS_EXTRACTED_IDENTITY {n} : {reprStr (VAS_identityExpr v)} VAS_END\"\n245:               \"identity_method\": \"kernel-expression-repr-v1\", \"conclusion_identities\": identity_hashes,"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_014yovpw2AqeYty6LnearDoM",
          "input": {
            "command": "sed -n 20,110p /harness/src/vcs_extract.py"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_014yovpw2AqeYty6LnearDoM",
          "output": "# levels, implicit arguments and binder information remain in the identity.\nIDENTITY = \"\"\"\nprivate partial def VAS_identityExpr : Lean.Expr → Lean.Expr\n  | .mdata _ value => VAS_identityExpr value\n  | .app fn arg => .app (VAS_identityExpr fn) (VAS_identityExpr arg)\n  | .lam _ typ body info => .lam .anonymous (VAS_identityExpr typ) (VAS_identityExpr body) info\n  | .forallE _ typ body info => .forallE .anonymous (VAS_identityExpr typ) (VAS_identityExpr body) info\n  | .letE _ typ value body flag => .letE .anonymous (VAS_identityExpr typ) (VAS_identityExpr value) (VAS_identityExpr body) flag\n  | .proj owner idx value => .proj owner idx (VAS_identityExpr value)\n  | value => value\n\nprivate def VAS_declarationIdentity (ci : Lean.ConstantInfo) : String :=\n  let kind := match ci with\n    | .axiomInfo _ => \"axiom\"\n    | .defnInfo _ => \"definition\"\n    | .thmInfo _ => \"theorem\"\n    | .opaqueInfo _ => \"opaque\"\n    | .quotInfo _ => \"quotient\"\n    | .inductInfo info => s!\"inductive {info.numParams} {info.numIndices} {reprStr info.ctors}\"\n    | .ctorInfo info => s!\"constructor {info.induct} {info.cidx} {info.numParams} {info.numFields}\"\n    | .recInfo info => s!\"recursor {info.numParams} {info.numIndices} {info.numMotives} {info.numMinors}\"\n  let value := match ci.value? with\n    | some body => reprStr (VAS_identityExpr body)\n    | none => \"no value\"\n  s!\"{kind}|levels={reprStr ci.levelParams}|type={reprStr (VAS_identityExpr ci.type)}|value={value}\"\n\"\"\"\n\nREACH = \"\"\"\nopen Lean Elab Command Meta in\nrun_cmd do\n  let kenv := (← getEnv).checked.get\n  let localSet : NameSet := kenv.constants.map₂.toList.foldl (fun s (n, _) => s.insert n) {}\n  -- statements only: from each conclusion's type, through definitions' types and values\n  let mut seen : NameSet := {}\n  let mut todo : List Name := []\n  for t in TARGETS do\n    let some ci := kenv.find? t | throwError m!\"no theorem {t}\"\n    todo := ci.type.getUsedConstants.toList ++ todo\n    logInfo m!\"VAS_CONCLUSION {t} : {← liftTermElabM <| ppExpr ci.type} VAS_END\"\n    logInfo m!\"VAS_ORIGINAL_IDENTITY {t} : {reprStr (VAS_identityExpr ci.type)} VAS_END\"\n  while !todo.isEmpty do\n    let n := todo.head!\n    todo := todo.tail!\n    if seen.contains n || !localSet.contains n then continue\n    seen := seen.insert n\n    let some ci := kenv.find? n | continue\n    logInfo m!\"VAS_DEPENDENCY_IDENTITY {n} : {VAS_declarationIdentity ci} VAS_END\"\n    let more := ci.type.getUsedConstants ++ (match ci with\n      | .defnInfo v => v.value.getUsedConstants | .thmInfo v => v.value.getUsedConstants\n      | .opaqueInfo v => v.value.getUsedConstants\n      | .inductInfo v => v.ctors.toArray | .ctorInfo v => #[v.induct] | _ => #[])\n    todo := more.toList ++ todo\n    -- auxiliary constants (matchers, constructors, projections, equation lemmas) map to the nearest ancestor\n    -- whose source range Lean recorded\n    let mut m := n\n    let mut r ← findDeclarationRanges? m\n    while r.isNone && !m.isAnonymous do\n      m := m.getPrefix\n      r ← findDeclarationRanges? m\n    match r with\n    | some rg => logInfo m!\"VAS_DECL {m} {rg.range.pos.line} {rg.range.endPos.line}\"\n    | none => logInfo m!\"VAS_UNRANGED {n}\"\n  logInfo \"VAS_REACHED\"\n\"\"\"\n\nCOMPARE = \"\"\"\nset_option format.width 100000 in\nopen Lean Elab Command Meta in\nrun_cmd do\n  for n in NAMES do\n    let some ci := (← getEnv).find? n | throwError m!\"no {n}\"\n    let some v := ci.value? | throwError m!\"no value {n}\"\n    logInfo m!\"VAS_EXTRACTED {n} : {← liftTermElabM <| ppExpr v} VAS_END\"\n    logInfo m!\"VAS_EXTRACTED_IDENTITY {n} : {reprStr (VAS_identityExpr v)} VAS_END\"\n  for n in DEPENDENCIES do\n    let some ci := (← getEnv).find? n | throwError m!\"missing extracted dependency {n}\"\n    logInfo m!\"VAS_EXTRACTED_DEPENDENCY_IDENTITY {n} : {VAS_declarationIdentity ci} VAS_END\"\n\"\"\"\n\n\ndef run_lean(path):\n    \"\"\"Lean, then leanchecker on the compiled module (OT-1861): a nonzero status if either fails.\"\"\"\n    libs = sorted((ROOT / \".lake/packages\").glob(\"*/.lake/build/lib/lean\"))\n    env = dict(os.environ, LEAN_PATH=\":\".join(map(str, libs)), LEAN_NUM_THREADS=\"1\")\n    with tempfile.TemporaryDirectory(prefix=\"vcs-olean-\") as build:\n        r = subprocess.run([LEAN, \"-j1\", f\"--root={Path(path).resolve().parent}\", \"-o\", str(Path(build) / \"VasExtract.olean\"), str(path)], cwd=ROOT,\n                           env=env, capture_output=True, text=True, timeout=900)\n        if r.returncode != 0:\n            return r.returncode, r.stdout + r.stderr\n        c = subprocess.run([LEANCHECKER, \"VasExtract\"], cwd=ROOT, capture_output=True, text=True, timeout=900,\n                           env=dict(env, LEAN_PATH=env[\"LEAN_PATH\"] + \":\" + build,"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01Bd5U1ee8MSGFgSTJEt59cc",
          "input": {
            "command": "cd /work/checks/a13c66c5450348d7838838d13ab7ba13; ls; grep -o \"VAS_ORIGINAL_IDENTITY.*\" *.log *.json 2>/dev/null | head -c 300; python3 - <<'EOF'\nimport json,glob\nfor f in glob.glob('*.json'): print(f, list(json.load(open(f)).keys())[:12])\nEOF"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01Bd5U1ee8MSGFgSTJEt59cc",
          "output": "Checked.lean\nextracted.json\nextracted.lean\nlean.log\nsubmitted-candidate.json\nsubmitted-report.txt\nsubmitted.lean\nverdict.json\nsubmitted-candidate.json ['proof_file', 'narrative_file', 'conclusions', 'user_facts', 'model_choices', 'sources', 'incorporated_inputs', 'proof_scope']\nextracted.json ['file', 'conclusions', 'lean_exit', 'ok', 'compiles_alone', 'faithful', 'assumption_declarations', 'identity_method', 'conclusion_identities', 'dependency_faithful', 'dependency_identities', 'unranged']\nverdict.json ['ok', 'check_complete', 'reviewable', 'verdict', 'time', 'lean_exit', 'error']"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_015oFJ6NCnhXh5dzXVfAXXcN",
          "input": {
            "command": "mkdir -p /tmp/exp && cd /tmp/exp && python3 - <<'EOF'\ne=open('/work/checks/a13c66c5450348d7838838d13ab7ba13/extracted.lean').read()\ni=e.index(\"/-! Conclusions\")\nhead=e[:i]\nthm=\"\"\"\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 →\n    predictive a b = 313/384 := by sorry\ndef conclusion_answer_theorem : Prop := ∀ a b : ℝ, 0 < a → 0 < b → ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 → ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 → predictive a b = 313/384\nset_option pp.all true in\n#print answer_theorem\nset_option pp.all true in\n#print conclusion_answer_theorem\n\"\"\"\nopen('t.lean','w').write(head+thm)\nEOF\ncd /harness/.lake/packages/mathlib && LEAN_PATH=$(ls -d /harness/.lake/packages/*/.lake/build/lib/lean | tr '\\n' ':') timeout 500 lean /tmp/exp/t.lean > /tmp/exp/o.txt 2>&1; wc -c /tmp/exp/o.txt; grep -v \"^$\" /tmp/exp/o.txt | cut -c1-3000 | tail -8",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_015oFJ6NCnhXh5dzXVfAXXcN",
          "output": "16947 /tmp/exp/o.txt\n                (@instOfNatAtLeastTwo.{0} Real (nat_lit 100) Real.instNatCast conclusion_answer_theorem._proof_4))) →\n          @Eq.{1} Real (predictive a b)\n            (@HDiv.hDiv.{0, 0, 0} Real Real Real\n              (@instHDiv.{0} Real (@DivInvMonoid.toDiv.{0} Real Real.instDivInvMonoid))\n              (@OfNat.ofNat.{0} Real (nat_lit 313)\n                (@instOfNatAtLeastTwo.{0} Real (nat_lit 313) Real.instNatCast conclusion_answer_theorem._proof_5))\n              (@OfNat.ofNat.{0} Real (nat_lit 384)\n                (@instOfNatAtLeastTwo.{0} Real (nat_lit 384) Real.instNatCast conclusion_answer_theorem._proof_6)))\nShell cwd was reset to /work"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_01WU7hPksxPfojE8HSHVqwLW",
          "input": {
            "command": "grep -o \"[a-zA-Z_.]*_proof_[0-9]*\" /tmp/exp/o.txt | sort | uniq -c"
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_01WU7hPksxPfojE8HSHVqwLW",
          "output": "      2 conclusion_answer_theorem._proof_1\n      2 conclusion_answer_theorem._proof_2\n      2 conclusion_answer_theorem._proof_3\n      1 conclusion_answer_theorem._proof_4\n      1 conclusion_answer_theorem._proof_5\n      1 conclusion_answer_theorem._proof_6"
        },
        {
          "type": "tool_call",
          "name": "Bash",
          "call_id": "toolu_017YBSXt18TJgWJR42uutRp3",
          "input": {
            "command": "cd /work; python3 - <<'EOF'\ns=open('Model.lean').read()\ni=s.index(\"theorem answer_theorem\")\ns=s[:i]+\"\"\"theorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / ((50:ℕ):ℝ)) = ((3:ℕ):ℝ) / ((4:ℕ):ℝ) →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / ((50:ℕ):ℝ) - ((3:ℕ):ℝ) / ((4:ℕ):ℝ))^2\n      = ((1:ℕ):ℝ) / ((100:ℕ):ℝ) →\n    predictive a b = ((313:ℕ):ℝ) / ((384:ℕ):ℝ) := by\n  intro a b ha hb hm hv\n  simp only [Nat.cast_ofNat, Nat.cast_one] at hm hv ⊢\n  obtain ⟨rfl, rfl⟩ := params ha hb hm hv\n  rw [predictive_formula ha hb]\n  norm_num\n\"\"\"\ns=s.replace(\"(next ball is black is 313/384\",\"(next ball is black is 313/384\")\nopen('Model.lean','w').write(s)\nEOF\npython /harness/src/vcs_protocol.py tool check --manifest /work/candidate.json 2>&1 | grep -v sha256 | grep -n \"ok\\|faithful\\|error\\|verdict\\|axioms\" | head",
            "timeout": 600000
          }
        },
        {
          "type": "tool_result",
          "call_id": "toolu_017YBSXt18TJgWJR42uutRp3",
          "output": "7: \"ok\": true,\n9: \"faithful\": {\n24: \"dependency_faithful\": {\n61: \"errors\": []\n64:  \"ok\": true,\n67:  \"verdict\": \"proved\",\n78:    \"ok\": true,\n80:    \"faithful\": {\n95:    \"dependency_faithful\": {\n132:    \"errors\": []"
        },
        {
          "type": "message",
          "role": "assistant",
          "content": "The check tool returns `verdict: proved` for the revised candidate. I have not accepted it; the decision is yours.\n\n**Result:** the probability that the next ball is black is 313/384 ≈ 0.815 under the model below.\n\n**What changed in response to your feedback**\n- **Family first, parameters derived:** the model starts from a beta-binomial family for the initial black count K, with a and b left unspecified. The supplied moments are the hypotheses of `answer_theorem`: mean of K/50 is 3/4, variance is 1/100.\n- **Prior denominator restored:** the prior is `prior N a b k = C(N,k)·rise a k·rise b (N−k) / rise (a+b) N`.\n- **Variance proved from the definition:** `var_formula` shows Var(K) = N·a·b·(a+b+N) / ((a+b)²(a+b+1)). It relies on the lemmas `w_sum` (normalisation via a Vandermonde identity), `E1` (mean) and `E2` (second moment).\n- **a and b are intermediate:** the lemma `params` shows the two moments force a = 21.3 and b = 7.1.\n- **General predictive formula:** `predictive_formula` proves the posterior predictive is (a+10)/(a+b+10) for any a, b > 0. It comes from a general identity, `Fdesc`, proved by induction.\n- **Final theorem:** `answer_theorem` states that under the two moment hypotheses, the predictive probability is 313/384. It uses no `sorry` and no extra axioms; the kernel check lists only the standard axioms (propext, Classical.choice, Quot.sound).\n\n**Assumptions to review**\n- **Beta-binomial family:** K | p ~ Binomial(50, p) with p ~ Beta(a, b). This is a modelling choice, and other families matching the same two moments would give other answers.\n- **Moments of K/50:** the 0.75 and 0.1 are taken to describe the realised fraction K/50 across boxes, not p. That is why a + b comes out as 28.4 rather than 17.75.\n- **Sampling model:** given K, the 10 draws are uniform without replacement.\n- **Exchangeability:** your box is exchangeable with the other boxes.\n\nOne technical point: the extraction check first failed on identity because real-number literals like `3/4` create auxiliary proof terms whose names differ between a theorem and its extracted copy. I rewrote the statement's literals as natural-number casts, e.g. `((3:ℕ):ℝ)/((4:ℕ):ℝ)`. The meaning is unchanged.\n\nThe previous attempt is kept as `Model_v1_cycle1.lean` and `candidate_v1_cycle1.json`. The current files are `Model.lean`, `report.txt` and `candidate.json`."
        }
      ],
      "produced_code": [
        {
          "name": "attempt-002/Model.lean",
          "content": "import Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Algebra.BigOperators.Ring.Finset\nimport Mathlib.Algebra.BigOperators.Field\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.LinearCombination\n\n/-!\n# Beta-binomial model for the black count of a 50-ball box\n\nSUPPLIED: box of N = 50 balls; K = unknown number of black ones; 10 balls drawn without\nreplacement, all black; across boxes the fraction K/50 has mean 3/4 and sd 1/10.\n\nMODEL CHOICE (assumption, for review): across boxes K follows a beta-binomial law with\nUNSPECIFIED positive parameters a, b:\n   P(K = k) = C(N,k) * a^(k rising) * b^((N-k) rising) / (a+b)^(N rising)\n(= the law of K | p ~ Binomial(N,p) with p ~ Beta(a,b)).  a, b are NOT assumed: they are\nderived below from the supplied mean and sd.  Given K = k, the 10 draws are a uniformly\nrandom sample without replacement, and my box is exchangeable with the other boxes.\n-/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Beta-binomial prior pmf of the initial black count k, box size N, parameters a b. -/\nnoncomputable def prior (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k) / rise (a + b) N\n\n/-- Likelihood of 10 black draws without replacement if k of 50 balls are black. -/\nnoncomputable def lik (k : ℕ) : ℝ := (k.descFactorial 10 : ℝ) / ((50 : ℕ).descFactorial 10 : ℝ)\n\n/-- Chance the 11th ball is black given k black initially and 10 black removed (40 left). -/\nnoncomputable def nextBlack (k : ℕ) : ℝ := ((k : ℝ) - 10) / 40\n\n/-- Posterior predictive probability that the next ball is black. -/\nnoncomputable def predictive (a b : ℝ) : ℝ :=\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k)\n\n/-! ### Technical lemmas (proved, not assumed) -/\n\nlemma rise_succ (x : ℝ) (n : ℕ) : rise x (n+1) = rise x n * (x + n) := rfl\n\nlemma rise_zero (x : ℝ) : rise x 0 = 1 := rfl\n\nlemma rise_pos {x : ℝ} (hx : 0 < x) : ∀ n, 0 < rise x n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ]\n    have : (0:ℝ) ≤ n := Nat.cast_nonneg n\n    exact mul_pos ih (by linarith)\n\nlemma rise_shift (x : ℝ) : ∀ n, rise x (n+1) = x * rise (x+1) n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ x (n+1), ih, rise_succ (x+1) n]\n    push_cast\n    ring\n\n/-- unnormalised weight -/\nnoncomputable def w (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k)\n\nlemma w_succ_sum (a b : ℝ) (N : ℕ) :\n    ∑ k ∈ Finset.range (N+2), w (N+1) a b k\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n  have h1 : ∀ i : ℕ, w (N+1) a b (i+1)\n      = w N a b i * (a + i) + w N a b (i+1) * (b + N - (i+1)) := by\n    intro i\n    unfold w\n    rw [Nat.choose_succ_succ, Nat.add_sub_add_right, rise_succ a i]\n    rcases Nat.lt_or_ge i N with h | h\n    · have e : N - i = (N - (i+1)) + 1 := by omega\n      rw [e, rise_succ b (N-(i+1)), Nat.cast_sub (by omega : i+1 ≤ N)]\n      push_cast\n      ring\n    · have h0 : N.choose (i+1) = 0 := Nat.choose_eq_zero_of_lt (by omega)\n      rw [h0]\n      push_cast\n      ring\n  have hz : w N a b (N+1) = 0 := by simp [w]\n  have hA : ∑ i ∈ Finset.range (N+1), w N a b (i+1) * (b + N - (i+1))\n      = ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k) - rise b (N+1) := by\n    have := Finset.sum_range_succ' (fun k => w N a b k * (b + N - k)) (N+1)\n    rw [Finset.sum_range_succ] at this\n    have h0 : w N a b 0 * (b + N - ((0:ℕ):ℝ)) = rise b (N+1) := by\n      simp [w, rise_succ, rise_zero]\n    simp only [hz, zero_mul, add_zero, h0] at this\n    push_cast at this ⊢\n    linarith\n  rw [Finset.sum_range_succ' _ (N+1)]\n  simp only [h1, Finset.sum_add_distrib]\n  rw [hA]\n  have h00 : w (N+1) a b 0 = rise b (N+1) := by simp [w, rise_zero]\n  rw [h00]\n  have key : ∑ k ∈ Finset.range (N+1), w N a b k * (a + k)\n      + ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k)\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n    rw [Finset.mul_sum, ← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  linarith\n\n/-- The prior is normalised: Vandermonde identity for rising factorials. -/\nlemma w_sum (a b : ℝ) : ∀ N : ℕ, ∑ k ∈ Finset.range (N+1), w N a b k = rise (a+b) N := by\n  intro N\n  induction N with\n  | zero => simp [w, rise]\n  | succ n ih =>\n    rw [w_succ_sum, ih, rise_succ]\n    ring\n\nlemma shift (M : ℕ) (a b : ℝ) (f : ℕ → ℝ) :\n    ∑ k ∈ Finset.range (M+2), f k * ((k:ℝ) * w (M+1) a b k)\n      = ((M:ℝ)+1) * a * ∑ i ∈ Finset.range (M+1), f (i+1) * w M (a+1) b i := by\n  rw [Finset.sum_range_succ']\n  simp only [Nat.cast_zero, zero_mul, mul_zero, add_zero]\n  rw [Finset.mul_sum]\n  apply Finset.sum_congr rfl\n  intro i _\n  have hc := Nat.add_one_mul_choose_eq M i\n  have hc' : ((M:ℝ)+1) * (M.choose i : ℝ) = ((M+1).choose (i+1) : ℝ) * ((i:ℝ)+1) := by\n    exact_mod_cast hc\n  unfold w\n  rw [Nat.add_sub_add_right, rise_shift a i]\n  push_cast\n  linear_combination (-(f (i+1)) * a * rise (a+1) i * rise b (M-i)) * hc'\n\nlemma Zr (a b : ℝ) (L : ℕ) :\n    rise (a+b) (L+2) = (a+b) * (a+b+1) * rise (a+b+2) L := by\n  rw [rise_shift (a+b) (L+1), rise_shift (a+b+1) L]\n  have : a+b+1+1 = a+b+2 := by ring\n  rw [this]\n  ring\n\nlemma S1 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k\n      = ((L:ℝ)+2) * a * ((a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun _ => 1)\n  simp only [one_mul] at h\n  have h2 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h2\n  rw [h2, h3] at h\n  push_cast at h\n  convert h using 2\n  ring\n\nlemma S2 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) * rise (a+b+2) L\n          + (a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun k => (k:ℝ))\n  have hs : ∑ i ∈ Finset.range (L+1+1), ((i+1:ℕ):ℝ) * w (L+1) (a+1) b i\n      = ∑ i ∈ Finset.range (L+1+1), (i:ℝ) * w (L+1) (a+1) b i\n        + ∑ i ∈ Finset.range (L+1+1), w (L+1) (a+1) b i := by\n    rw [← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    push_cast\n    ring\n  have h4 := shift L (a+1) b (fun _ => 1)\n  simp only [one_mul] at h4\n  have h5 := w_sum (a+1+1) b L\n  have h6 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  have e3 : a+1+1+b = a+b+2 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h6\n  rw [e3] at h5\n  rw [h5] at h4\n  rw [h6, h3] at hs\n  have hs' : ∑ i ∈ Finset.range (L+1+1), ((i:ℝ)) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := by\n    have : ∑ i ∈ Finset.range (L+2), (i:ℝ) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := h4\n    exact this\n  show ∑ k ∈ Finset.range (L+1+2), (k:ℝ) * ((k:ℝ) * w (L+1+1) a b k) = _\n  rw [h]\n  beta_reduce at h\n  rw [hs, hs']\n  push_cast\n  ring\n\nlemma prior_eq (N : ℕ) (a b : ℝ) (k : ℕ) : prior N a b k = w N a b k / rise (a+b) N := rfl\n\nlemma E0 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k = 1 := by\n  have hZ : rise (a+b) (L+2) ≠ 0 := (rise_pos (by linarith) _).ne'\n  have := w_sum a b (L+2)\n  simp only [prior_eq]\n  rw [← Finset.sum_div]\n  exact (div_eq_one_iff_eq hZ).2 this\n\nlemma E1 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ) = ((L:ℝ)+2) * a / (a+b) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S1, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\nlemma E2 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) + (a+b+1)) / ((a+b) * (a+b+1)) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S2, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\n/-- General beta-binomial variance, proved from the definition of `prior`:\nVar(K) = N a b (a+b+N) / ((a+b)^2 (a+b+1)), N = L+2 (mean is N a/(a+b)). -/\nlemma var_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * ((k:ℝ) - ((L:ℝ)+2) * a / (a+b))^2\n      = ((L:ℝ)+2) * a * b * (a+b+((L:ℝ)+2)) / ((a+b)^2 * (a+b+1)) := by\n  set μ : ℝ := ((L:ℝ)+2) * a / (a+b) with hμ\n  have e : ∀ k : ℕ, prior (L+2) a b k * ((k:ℝ) - μ)^2\n      = prior (L+2) a b k * (k:ℝ)^2 - 2 * μ * (prior (L+2) a b k * (k:ℝ))\n        + μ^2 * prior (L+2) a b k := by\n    intro k; ring\n  simp only [e, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum]\n  rw [E2 ha hb, E1 ha hb, E0 ha hb, hμ]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n  ring\n\n/-- Parameters are determined by the supplied mean and sd (intermediate result). -/\nlemma params {a b : ℝ} (ha : 0 < a) (hb : 0 < b)\n    (hmean : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4)\n    (hvar : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100) :\n    a = 213/10 ∧ b = 71/10 := by\n  have h1 := E1 ha hb 48\n  have hv := var_formula ha hb 48\n  have hs : a + b ≠ 0 := by linarith\n  have hm : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50)\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ)) / 50 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  have h1' : ∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ) = 50 * a / (a + b) := by\n    have := h1\n    norm_num at this\n    exact this\n  rw [hm, h1'] at hmean\n  have hab : a = 3 * b := by\n    field_simp at hmean\n    linarith\n  have hμ : (50 : ℝ) * a / (a + b) = 75 / 2 := by\n    rw [hab]; field_simp; ring\n  have hv' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 50 * a / (a + b))^2\n      = 50 * a * b * (a + b + 50) / ((a+b)^2 * (a+b+1)) := by\n    have := hv\n    norm_num at this\n    exact this\n  rw [hμ] at hv'\n  have hvar' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 75/2)^2) / 2500 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  rw [hvar', hv'] at hvar\n  subst hab\n  have hb2 : b ≠ 0 := hb.ne'\n  have h4 : 3 * b + b + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hb' : b = 71/10 := by\n    have : b^2 * (b * 100000 - 7100 * 100) = 0 := by nlinarith [hvar]\n    have hb2' : b^2 ≠ 0 := pow_ne_zero 2 hb2\n    have := (mul_eq_zero.mp this).resolve_left hb2'\n    linarith\n  subst hb'\n  norm_num\n\n/-! ### Posterior predictive (general Polya-urn identity, proved from the definitions) -/\n\nlemma Fdesc (b : ℝ) : ∀ n N : ℕ, ∀ a : ℝ, n ≤ N →\n    ∑ k ∈ Finset.range (N+1), ((k.descFactorial n : ℕ) : ℝ) * w N a b k\n      = ((N.descFactorial n : ℕ) : ℝ) * rise a n * rise (a + n + b) (N - n) := by\n  intro n\n  induction n with\n  | zero =>\n    intro N a _\n    simp only [Nat.descFactorial_zero, Nat.cast_one, one_mul, Nat.sub_zero, Nat.cast_zero,\n      add_zero, rise_zero]\n    exact w_sum a b N\n  | succ n ih =>\n    intro N a hn\n    obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by omega⟩\n    have h := shift M a b (fun k => ((( k - 1).descFactorial n : ℕ) : ℝ))\n    have e : ∀ k : ℕ, ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) := by\n      intro k\n      cases k with\n      | zero => simp\n      | succ i =>\n        rw [Nat.succ_descFactorial_succ]\n        simp only [Nat.add_sub_cancel]\n        push_cast\n        ring\n    have hL : ∑ k ∈ Finset.range (M+1+1), ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ∑ k ∈ Finset.range (M+2), ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) :=\n      Finset.sum_congr rfl (fun k _ => e k)\n    rw [hL, h]\n    simp only [Nat.add_sub_cancel]\n    rw [ih M (a+1) (by omega), Nat.succ_descFactorial_succ, rise_shift a n]\n    have e2 : M + 1 - (n + 1) = M - n := by omega\n    rw [e2]\n    have e3 : a + 1 + (n:ℝ) + b = a + ((n+1 : ℕ) : ℝ) + b := by push_cast; ring\n    rw [e3]\n    push_cast\n    ring\n\n/-- General result: after n black draws, the predictive probability is (a+n)/(a+b+n);\nhere specialised to N = 50, n = 10. -/\nlemma predictive_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) :\n    predictive a b = (a + 10) / (a + b + 10) := by\n  have hZ : rise (a+b) 50 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hD : (((50:ℕ).descFactorial 10 : ℕ) : ℝ) ≠ 0 := by\n    norm_num [Nat.descFactorial]\n  have hR : rise (a + 11 + b) 39 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hA : rise a 10 ≠ 0 := (rise_pos ha _).ne'\n  have hx : a + 10 + b ≠ 0 := by linarith\n  have h11 : ∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 11 : ℕ) : ℝ) * rise a 11 * rise (a + 11 + b) 39 := by\n    have h := Fdesc b 11 50 a (by norm_num)\n    rw [show a + ((11:ℕ):ℝ) + b = a + 11 + b by push_cast; ring] at h\n    exact h\n  have h10 : ∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * rise a 10 * rise (a + 10 + b) 40 := by\n    have h := Fdesc b 10 50 a (by norm_num)\n    rw [show a + ((10:ℕ):ℝ) + b = a + 10 + b by push_cast; ring] at h\n    exact h\n  have hd : (((50:ℕ).descFactorial 11 : ℕ) : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) := by\n    norm_num [Nat.descFactorial]\n  have hr11 : rise a 11 = rise a 10 * (a + 10) := by\n    have := rise_succ a 10\n    norm_num at this\n    exact this\n  have hr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39 := by\n    have := rise_shift (a + 10 + b) 39\n    have e : a + 10 + b + 1 = a + 11 + b := by ring\n    rw [e] at this\n    exact this\n  have hk : ∀ k : ℕ, ((k.descFactorial 11 : ℕ) : ℝ) = ((k.descFactorial 10 : ℕ) : ℝ) * ((k:ℝ) - 10) := by\n    intro k\n    rcases Nat.lt_or_ge k 10 with h | h\n    · have h0 : k.descFactorial 10 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr h\n      have h1 : k.descFactorial 11 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr (by omega)\n      rw [h0, h1]; simp\n    · rw [show (11:ℕ) = 10 + 1 from rfl, Nat.descFactorial_succ, Nat.cast_mul, Nat.cast_sub h]\n      push_cast\n      ring\n  have hnum : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * 40) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik, nextBlack, hk k]\n    field_simp\n  have hden : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ)) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik]\n    field_simp\n  unfold predictive\n  rw [hnum, hden]\n  rw [h11, h10, hd, hr11, hr40]\n  field_simp\n  ring\n\n/-! ### Final answer -/\n\n/-- ANSWER.  If K has the beta-binomial prior (unspecified a,b>0) whose K/50 has mean 3/4 and\nvariance 1/100, then after 10 black draws without replacement the probability that the\nnext ball is black is 313/384 ≈ 0.815. -/\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / ((50:ℕ):ℝ)) = ((3:ℕ):ℝ) / ((4:ℕ):ℝ) →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / ((50:ℕ):ℝ) - ((3:ℕ):ℝ) / ((4:ℕ):ℝ))^2\n      = ((1:ℕ):ℝ) / ((100:ℕ):ℝ) →\n    predictive a b = ((313:ℕ):ℝ) / ((384:ℕ):ℝ) := by\n  intro a b ha hb hm hv\n  simp only [Nat.cast_ofNat, Nat.cast_one] at hm hv ⊢\n  obtain ⟨rfl, rfl⟩ := params ha hb hm hv\n  rw [predictive_formula ha hb]\n  norm_num\n"
        },
        {
          "name": "attempt-002/extracted.lean",
          "content": "import Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Algebra.BigOperators.Ring.Finset\nimport Mathlib.Algebra.BigOperators.Field\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.LinearCombination\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Beta-binomial prior pmf of the initial black count k, box size N, parameters a b. -/\nnoncomputable def prior (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k) / rise (a + b) N\n\n/-- Likelihood of 10 black draws without replacement if k of 50 balls are black. -/\nnoncomputable def lik (k : ℕ) : ℝ := (k.descFactorial 10 : ℝ) / ((50 : ℕ).descFactorial 10 : ℝ)\n\n/-- Chance the 11th ball is black given k black initially and 10 black removed (40 left). -/\nnoncomputable def nextBlack (k : ℕ) : ℝ := ((k : ℝ) - 10) / 40\n\n/-- Posterior predictive probability that the next ball is black. -/\nnoncomputable def predictive (a b : ℝ) : ℝ :=\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k)\n\n\n/-! Conclusions (statements of the proved theorems). -/\ndef conclusion_answer_theorem : Prop := ∀ a b : ℝ, 0 < a → 0 < b → ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / ((50:ℕ):ℝ)) = ((3:ℕ):ℝ) / ((4:ℕ):ℝ) → ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / ((50:ℕ):ℝ) - ((3:ℕ):ℝ) / ((4:ℕ):ℝ))^2 = ((1:ℕ):ℝ) / ((100:ℕ):ℝ) → predictive a b = ((313:ℕ):ℝ) / ((384:ℕ):ℝ)\n"
        },
        {
          "name": "checks/42f5113ca21243669beaab7811fe04d4/submitted.lean",
          "content": "import Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Algebra.BigOperators.Ring.Finset\nimport Mathlib.Algebra.BigOperators.Field\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.LinearCombination\n\n/-!\n# Beta-binomial model for the black count of a 50-ball box\n\nSUPPLIED: box of N = 50 balls; K = unknown number of black ones; 10 balls drawn without\nreplacement, all black; across boxes the fraction K/50 has mean 3/4 and sd 1/10.\n\nMODEL CHOICE (assumption, for review): across boxes K follows a beta-binomial law with\nUNSPECIFIED positive parameters a, b:\n   P(K = k) = C(N,k) * a^(k rising) * b^((N-k) rising) / (a+b)^(N rising)\n(= the law of K | p ~ Binomial(N,p) with p ~ Beta(a,b)).  a, b are NOT assumed: they are\nderived below from the supplied mean and sd.  Given K = k, the 10 draws are a uniformly\nrandom sample without replacement, and my box is exchangeable with the other boxes.\n-/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Beta-binomial prior pmf of the initial black count k, box size N, parameters a b. -/\nnoncomputable def prior (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k) / rise (a + b) N\n\n/-- Likelihood of 10 black draws without replacement if k of 50 balls are black. -/\nnoncomputable def lik (k : ℕ) : ℝ := (k.descFactorial 10 : ℝ) / ((50 : ℕ).descFactorial 10 : ℝ)\n\n/-- Chance the 11th ball is black given k black initially and 10 black removed (40 left). -/\nnoncomputable def nextBlack (k : ℕ) : ℝ := ((k : ℝ) - 10) / 40\n\n/-- Posterior predictive probability that the next ball is black. -/\nnoncomputable def predictive (a b : ℝ) : ℝ :=\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k)\n\n/-! ### Technical lemmas (proved, not assumed) -/\n\nlemma rise_succ (x : ℝ) (n : ℕ) : rise x (n+1) = rise x n * (x + n) := rfl\n\nlemma rise_zero (x : ℝ) : rise x 0 = 1 := rfl\n\nlemma rise_pos {x : ℝ} (hx : 0 < x) : ∀ n, 0 < rise x n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ]\n    have : (0:ℝ) ≤ n := Nat.cast_nonneg n\n    exact mul_pos ih (by linarith)\n\nlemma rise_shift (x : ℝ) : ∀ n, rise x (n+1) = x * rise (x+1) n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ x (n+1), ih, rise_succ (x+1) n]\n    push_cast\n    ring\n\n/-- unnormalised weight -/\nnoncomputable def w (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k)\n\nlemma w_succ_sum (a b : ℝ) (N : ℕ) :\n    ∑ k ∈ Finset.range (N+2), w (N+1) a b k\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n  have h1 : ∀ i : ℕ, w (N+1) a b (i+1)\n      = w N a b i * (a + i) + w N a b (i+1) * (b + N - (i+1)) := by\n    intro i\n    unfold w\n    rw [Nat.choose_succ_succ, Nat.add_sub_add_right, rise_succ a i]\n    rcases Nat.lt_or_ge i N with h | h\n    · have e : N - i = (N - (i+1)) + 1 := by omega\n      rw [e, rise_succ b (N-(i+1)), Nat.cast_sub (by omega : i+1 ≤ N)]\n      push_cast\n      ring\n    · have h0 : N.choose (i+1) = 0 := Nat.choose_eq_zero_of_lt (by omega)\n      rw [h0]\n      push_cast\n      ring\n  have hz : w N a b (N+1) = 0 := by simp [w]\n  have hA : ∑ i ∈ Finset.range (N+1), w N a b (i+1) * (b + N - (i+1))\n      = ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k) - rise b (N+1) := by\n    have := Finset.sum_range_succ' (fun k => w N a b k * (b + N - k)) (N+1)\n    rw [Finset.sum_range_succ] at this\n    have h0 : w N a b 0 * (b + N - ((0:ℕ):ℝ)) = rise b (N+1) := by\n      simp [w, rise_succ, rise_zero]\n    simp only [hz, zero_mul, add_zero, h0] at this\n    push_cast at this ⊢\n    linarith\n  rw [Finset.sum_range_succ' _ (N+1)]\n  simp only [h1, Finset.sum_add_distrib]\n  rw [hA]\n  have h00 : w (N+1) a b 0 = rise b (N+1) := by simp [w, rise_zero]\n  rw [h00]\n  have key : ∑ k ∈ Finset.range (N+1), w N a b k * (a + k)\n      + ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k)\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n    rw [Finset.mul_sum, ← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  linarith\n\n/-- The prior is normalised: Vandermonde identity for rising factorials. -/\nlemma w_sum (a b : ℝ) : ∀ N : ℕ, ∑ k ∈ Finset.range (N+1), w N a b k = rise (a+b) N := by\n  intro N\n  induction N with\n  | zero => simp [w, rise]\n  | succ n ih =>\n    rw [w_succ_sum, ih, rise_succ]\n    ring\n\nlemma shift (M : ℕ) (a b : ℝ) (f : ℕ → ℝ) :\n    ∑ k ∈ Finset.range (M+2), f k * ((k:ℝ) * w (M+1) a b k)\n      = ((M:ℝ)+1) * a * ∑ i ∈ Finset.range (M+1), f (i+1) * w M (a+1) b i := by\n  rw [Finset.sum_range_succ']\n  simp only [Nat.cast_zero, zero_mul, mul_zero, add_zero]\n  rw [Finset.mul_sum]\n  apply Finset.sum_congr rfl\n  intro i _\n  have hc := Nat.add_one_mul_choose_eq M i\n  have hc' : ((M:ℝ)+1) * (M.choose i : ℝ) = ((M+1).choose (i+1) : ℝ) * ((i:ℝ)+1) := by\n    exact_mod_cast hc\n  unfold w\n  rw [Nat.add_sub_add_right, rise_shift a i]\n  push_cast\n  linear_combination (-(f (i+1)) * a * rise (a+1) i * rise b (M-i)) * hc'\n\nlemma Zr (a b : ℝ) (L : ℕ) :\n    rise (a+b) (L+2) = (a+b) * (a+b+1) * rise (a+b+2) L := by\n  rw [rise_shift (a+b) (L+1), rise_shift (a+b+1) L]\n  have : a+b+1+1 = a+b+2 := by ring\n  rw [this]\n  ring\n\nlemma S1 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k\n      = ((L:ℝ)+2) * a * ((a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun _ => 1)\n  simp only [one_mul] at h\n  have h2 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h2\n  rw [h2, h3] at h\n  push_cast at h\n  convert h using 2\n  ring\n\nlemma S2 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) * rise (a+b+2) L\n          + (a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun k => (k:ℝ))\n  have hs : ∑ i ∈ Finset.range (L+1+1), ((i+1:ℕ):ℝ) * w (L+1) (a+1) b i\n      = ∑ i ∈ Finset.range (L+1+1), (i:ℝ) * w (L+1) (a+1) b i\n        + ∑ i ∈ Finset.range (L+1+1), w (L+1) (a+1) b i := by\n    rw [← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    push_cast\n    ring\n  have h4 := shift L (a+1) b (fun _ => 1)\n  simp only [one_mul] at h4\n  have h5 := w_sum (a+1+1) b L\n  have h6 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  have e3 : a+1+1+b = a+b+2 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h6\n  rw [e3] at h5\n  rw [h5] at h4\n  rw [h6, h3] at hs\n  have hs' : ∑ i ∈ Finset.range (L+1+1), ((i:ℝ)) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := by\n    have : ∑ i ∈ Finset.range (L+2), (i:ℝ) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := h4\n    exact this\n  show ∑ k ∈ Finset.range (L+1+2), (k:ℝ) * ((k:ℝ) * w (L+1+1) a b k) = _\n  rw [h]\n  beta_reduce at h\n  rw [hs, hs']\n  push_cast\n  ring\n\nlemma prior_eq (N : ℕ) (a b : ℝ) (k : ℕ) : prior N a b k = w N a b k / rise (a+b) N := rfl\n\nlemma E0 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k = 1 := by\n  have hZ : rise (a+b) (L+2) ≠ 0 := (rise_pos (by linarith) _).ne'\n  have := w_sum a b (L+2)\n  simp only [prior_eq]\n  rw [← Finset.sum_div]\n  exact (div_eq_one_iff_eq hZ).2 this\n\nlemma E1 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ) = ((L:ℝ)+2) * a / (a+b) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S1, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\nlemma E2 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) + (a+b+1)) / ((a+b) * (a+b+1)) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S2, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\n/-- General beta-binomial variance, proved from the definition of `prior`:\nVar(K) = N a b (a+b+N) / ((a+b)^2 (a+b+1)), N = L+2 (mean is N a/(a+b)). -/\nlemma var_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * ((k:ℝ) - ((L:ℝ)+2) * a / (a+b))^2\n      = ((L:ℝ)+2) * a * b * (a+b+((L:ℝ)+2)) / ((a+b)^2 * (a+b+1)) := by\n  set μ : ℝ := ((L:ℝ)+2) * a / (a+b) with hμ\n  have e : ∀ k : ℕ, prior (L+2) a b k * ((k:ℝ) - μ)^2\n      = prior (L+2) a b k * (k:ℝ)^2 - 2 * μ * (prior (L+2) a b k * (k:ℝ))\n        + μ^2 * prior (L+2) a b k := by\n    intro k; ring\n  simp only [e, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum]\n  rw [E2 ha hb, E1 ha hb, E0 ha hb, hμ]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n  ring\n\n/-- Parameters are determined by the supplied mean and sd (intermediate result). -/\nlemma params {a b : ℝ} (ha : 0 < a) (hb : 0 < b)\n    (hmean : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4)\n    (hvar : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100) :\n    a = 213/10 ∧ b = 71/10 := by\n  have h1 := E1 ha hb 48\n  have hv := var_formula ha hb 48\n  have hs : a + b ≠ 0 := by linarith\n  have hm : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50)\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ)) / 50 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  have h1' : ∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ) = 50 * a / (a + b) := by\n    have := h1\n    norm_num at this\n    exact this\n  rw [hm, h1'] at hmean\n  have hab : a = 3 * b := by\n    field_simp at hmean\n    linarith\n  have hμ : (50 : ℝ) * a / (a + b) = 75 / 2 := by\n    rw [hab]; field_simp; ring\n  have hv' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 50 * a / (a + b))^2\n      = 50 * a * b * (a + b + 50) / ((a+b)^2 * (a+b+1)) := by\n    have := hv\n    norm_num at this\n    exact this\n  rw [hμ] at hv'\n  have hvar' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 75/2)^2) / 2500 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  rw [hvar', hv'] at hvar\n  subst hab\n  have hb2 : b ≠ 0 := hb.ne'\n  have h4 : 3 * b + b + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hb' : b = 71/10 := by\n    have : b^2 * (b * 100000 - 7100 * 100) = 0 := by nlinarith [hvar]\n    have hb2' : b^2 ≠ 0 := pow_ne_zero 2 hb2\n    have := (mul_eq_zero.mp this).resolve_left hb2'\n    linarith\n  subst hb'\n  norm_num\n\n/-! ### Posterior predictive (general Polya-urn identity, proved from the definitions) -/\n\nlemma Fdesc (b : ℝ) : ∀ n N : ℕ, ∀ a : ℝ, n ≤ N →\n    ∑ k ∈ Finset.range (N+1), ((k.descFactorial n : ℕ) : ℝ) * w N a b k\n      = ((N.descFactorial n : ℕ) : ℝ) * rise a n * rise (a + n + b) (N - n) := by\n  intro n\n  induction n with\n  | zero =>\n    intro N a _\n    simp only [Nat.descFactorial_zero, Nat.cast_one, one_mul, Nat.sub_zero, Nat.cast_zero,\n      add_zero, rise_zero]\n    exact w_sum a b N\n  | succ n ih =>\n    intro N a hn\n    obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by omega⟩\n    have h := shift M a b (fun k => ((( k - 1).descFactorial n : ℕ) : ℝ))\n    have e : ∀ k : ℕ, ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) := by\n      intro k\n      cases k with\n      | zero => simp\n      | succ i =>\n        rw [Nat.succ_descFactorial_succ]\n        simp only [Nat.add_sub_cancel]\n        push_cast\n        ring\n    have hL : ∑ k ∈ Finset.range (M+1+1), ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ∑ k ∈ Finset.range (M+2), ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) :=\n      Finset.sum_congr rfl (fun k _ => e k)\n    rw [hL, h]\n    simp only [Nat.add_sub_cancel]\n    rw [ih M (a+1) (by omega), Nat.succ_descFactorial_succ, rise_shift a n]\n    have e2 : M + 1 - (n + 1) = M - n := by omega\n    rw [e2]\n    have e3 : a + 1 + (n:ℝ) + b = a + ((n+1 : ℕ) : ℝ) + b := by push_cast; ring\n    rw [e3]\n    push_cast\n    ring\n\n/-- General result: after n black draws, the predictive probability is (a+n)/(a+b+n);\nhere specialised to N = 50, n = 10. -/\nlemma predictive_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) :\n    predictive a b = (a + 10) / (a + b + 10) := by\n  have hZ : rise (a+b) 50 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hD : (((50:ℕ).descFactorial 10 : ℕ) : ℝ) ≠ 0 := by\n    norm_num [Nat.descFactorial]\n  have hR : rise (a + 11 + b) 39 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hA : rise a 10 ≠ 0 := (rise_pos ha _).ne'\n  have hx : a + 10 + b ≠ 0 := by linarith\n  have h11 : ∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 11 : ℕ) : ℝ) * rise a 11 * rise (a + 11 + b) 39 := by\n    have h := Fdesc b 11 50 a (by norm_num)\n    rw [show a + ((11:ℕ):ℝ) + b = a + 11 + b by push_cast; ring] at h\n    exact h\n  have h10 : ∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * rise a 10 * rise (a + 10 + b) 40 := by\n    have h := Fdesc b 10 50 a (by norm_num)\n    rw [show a + ((10:ℕ):ℝ) + b = a + 10 + b by push_cast; ring] at h\n    exact h\n  have hd : (((50:ℕ).descFactorial 11 : ℕ) : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) := by\n    norm_num [Nat.descFactorial]\n  have hr11 : rise a 11 = rise a 10 * (a + 10) := by\n    have := rise_succ a 10\n    norm_num at this\n    exact this\n  have hr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39 := by\n    have := rise_shift (a + 10 + b) 39\n    have e : a + 10 + b + 1 = a + 11 + b := by ring\n    rw [e] at this\n    exact this\n  have hk : ∀ k : ℕ, ((k.descFactorial 11 : ℕ) : ℝ) = ((k.descFactorial 10 : ℕ) : ℝ) * ((k:ℝ) - 10) := by\n    intro k\n    rcases Nat.lt_or_ge k 10 with h | h\n    · have h0 : k.descFactorial 10 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr h\n      have h1 : k.descFactorial 11 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr (by omega)\n      rw [h0, h1]; simp\n    · rw [show (11:ℕ) = 10 + 1 from rfl, Nat.descFactorial_succ, Nat.cast_mul, Nat.cast_sub h]\n      push_cast\n      ring\n  have hnum : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * 40) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik, nextBlack, hk k]\n    field_simp\n  have hden : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ)) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik]\n    field_simp\n  unfold predictive\n  rw [hnum, hden]\n  rw [h11, h10, hd, hr11, hr40]\n  field_simp\n  ring\n\n/-! ### Final answer -/\n\n/-- ANSWER.  If K has the beta-binomial prior (unspecified a,b>0) whose K/50 has mean 3/4 and\nvariance 1/100, then after 10 black draws without replacement the probability that the\nnext ball is black is 313/384 ≈ 0.815. -/\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 →\n    predictive a b = 313/384 := by\n  intro a b ha hb hm hv\n  obtain ⟨rfl, rfl⟩ := params ha hb hm hv\n  rw [predictive_formula ha hb]\n  norm_num\n"
        },
        {
          "name": "checks/6ecce009375a4db9ace0f8950a9032ce/submitted.lean",
          "content": "import Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Algebra.BigOperators.Ring.Finset\nimport Mathlib.Algebra.BigOperators.Field\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.LinearCombination\n\n/-!\n# Beta-binomial model for the black count of a 50-ball box\n\nSUPPLIED: box of N = 50 balls; K = unknown number of black ones; 10 balls drawn without\nreplacement, all black; across boxes the fraction K/50 has mean 3/4 and sd 1/10.\n\nMODEL CHOICE (assumption, for review): across boxes K follows a beta-binomial law with\nUNSPECIFIED positive parameters a, b:\n   P(K = k) = C(N,k) * a^(k rising) * b^((N-k) rising) / (a+b)^(N rising)\n(= the law of K | p ~ Binomial(N,p) with p ~ Beta(a,b)).  a, b are NOT assumed: they are\nderived below from the supplied mean and sd.  Given K = k, the 10 draws are a uniformly\nrandom sample without replacement, and my box is exchangeable with the other boxes.\n-/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Beta-binomial prior pmf of the initial black count k, box size N, parameters a b. -/\nnoncomputable def prior (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k) / rise (a + b) N\n\n/-- Likelihood of 10 black draws without replacement if k of 50 balls are black. -/\nnoncomputable def lik (k : ℕ) : ℝ := (k.descFactorial 10 : ℝ) / ((50 : ℕ).descFactorial 10 : ℝ)\n\n/-- Chance the 11th ball is black given k black initially and 10 black removed (40 left). -/\nnoncomputable def nextBlack (k : ℕ) : ℝ := ((k : ℝ) - 10) / 40\n\n/-- Posterior predictive probability that the next ball is black. -/\nnoncomputable def predictive (a b : ℝ) : ℝ :=\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k)\n\n/-! ### Technical lemmas (proved, not assumed) -/\n\nlemma rise_succ (x : ℝ) (n : ℕ) : rise x (n+1) = rise x n * (x + n) := rfl\n\nlemma rise_zero (x : ℝ) : rise x 0 = 1 := rfl\n\nlemma rise_pos {x : ℝ} (hx : 0 < x) : ∀ n, 0 < rise x n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ]\n    have : (0:ℝ) ≤ n := Nat.cast_nonneg n\n    exact mul_pos ih (by linarith)\n\nlemma rise_shift (x : ℝ) : ∀ n, rise x (n+1) = x * rise (x+1) n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ x (n+1), ih, rise_succ (x+1) n]\n    push_cast\n    ring\n\n/-- unnormalised weight -/\nnoncomputable def w (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k)\n\nlemma w_succ_sum (a b : ℝ) (N : ℕ) :\n    ∑ k ∈ Finset.range (N+2), w (N+1) a b k\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n  have h1 : ∀ i : ℕ, w (N+1) a b (i+1)\n      = w N a b i * (a + i) + w N a b (i+1) * (b + N - (i+1)) := by\n    intro i\n    unfold w\n    rw [Nat.choose_succ_succ, Nat.add_sub_add_right, rise_succ a i]\n    rcases Nat.lt_or_ge i N with h | h\n    · have e : N - i = (N - (i+1)) + 1 := by omega\n      rw [e, rise_succ b (N-(i+1)), Nat.cast_sub (by omega : i+1 ≤ N)]\n      push_cast\n      ring\n    · have h0 : N.choose (i+1) = 0 := Nat.choose_eq_zero_of_lt (by omega)\n      rw [h0]\n      push_cast\n      ring\n  have hz : w N a b (N+1) = 0 := by simp [w]\n  have hA : ∑ i ∈ Finset.range (N+1), w N a b (i+1) * (b + N - (i+1))\n      = ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k) - rise b (N+1) := by\n    have := Finset.sum_range_succ' (fun k => w N a b k * (b + N - k)) (N+1)\n    rw [Finset.sum_range_succ] at this\n    have h0 : w N a b 0 * (b + N - ((0:ℕ):ℝ)) = rise b (N+1) := by\n      simp [w, rise_succ, rise_zero]\n    simp only [hz, zero_mul, add_zero, h0] at this\n    push_cast at this ⊢\n    linarith\n  rw [Finset.sum_range_succ' _ (N+1)]\n  simp only [h1, Finset.sum_add_distrib]\n  rw [hA]\n  have h00 : w (N+1) a b 0 = rise b (N+1) := by simp [w, rise_zero]\n  rw [h00]\n  have key : ∑ k ∈ Finset.range (N+1), w N a b k * (a + k)\n      + ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k)\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n    rw [Finset.mul_sum, ← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  linarith\n\n/-- The prior is normalised: Vandermonde identity for rising factorials. -/\nlemma w_sum (a b : ℝ) : ∀ N : ℕ, ∑ k ∈ Finset.range (N+1), w N a b k = rise (a+b) N := by\n  intro N\n  induction N with\n  | zero => simp [w, rise]\n  | succ n ih =>\n    rw [w_succ_sum, ih, rise_succ]\n    ring\n\nlemma shift (M : ℕ) (a b : ℝ) (f : ℕ → ℝ) :\n    ∑ k ∈ Finset.range (M+2), f k * ((k:ℝ) * w (M+1) a b k)\n      = ((M:ℝ)+1) * a * ∑ i ∈ Finset.range (M+1), f (i+1) * w M (a+1) b i := by\n  rw [Finset.sum_range_succ']\n  simp only [Nat.cast_zero, zero_mul, mul_zero, add_zero]\n  rw [Finset.mul_sum]\n  apply Finset.sum_congr rfl\n  intro i _\n  have hc := Nat.add_one_mul_choose_eq M i\n  have hc' : ((M:ℝ)+1) * (M.choose i : ℝ) = ((M+1).choose (i+1) : ℝ) * ((i:ℝ)+1) := by\n    exact_mod_cast hc\n  unfold w\n  rw [Nat.add_sub_add_right, rise_shift a i]\n  push_cast\n  linear_combination (-(f (i+1)) * a * rise (a+1) i * rise b (M-i)) * hc'\n\nlemma Zr (a b : ℝ) (L : ℕ) :\n    rise (a+b) (L+2) = (a+b) * (a+b+1) * rise (a+b+2) L := by\n  rw [rise_shift (a+b) (L+1), rise_shift (a+b+1) L]\n  have : a+b+1+1 = a+b+2 := by ring\n  rw [this]\n  ring\n\nlemma S1 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k\n      = ((L:ℝ)+2) * a * ((a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun _ => 1)\n  simp only [one_mul] at h\n  have h2 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h2\n  rw [h2, h3] at h\n  push_cast at h\n  convert h using 2\n  ring\n\nlemma S2 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) * rise (a+b+2) L\n          + (a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun k => (k:ℝ))\n  have hs : ∑ i ∈ Finset.range (L+1+1), ((i+1:ℕ):ℝ) * w (L+1) (a+1) b i\n      = ∑ i ∈ Finset.range (L+1+1), (i:ℝ) * w (L+1) (a+1) b i\n        + ∑ i ∈ Finset.range (L+1+1), w (L+1) (a+1) b i := by\n    rw [← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    push_cast\n    ring\n  have h4 := shift L (a+1) b (fun _ => 1)\n  simp only [one_mul] at h4\n  have h5 := w_sum (a+1+1) b L\n  have h6 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  have e3 : a+1+1+b = a+b+2 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h6\n  rw [e3] at h5\n  rw [h5] at h4\n  rw [h6, h3] at hs\n  have hs' : ∑ i ∈ Finset.range (L+1+1), ((i:ℝ)) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := by\n    have : ∑ i ∈ Finset.range (L+2), (i:ℝ) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := h4\n    exact this\n  show ∑ k ∈ Finset.range (L+1+2), (k:ℝ) * ((k:ℝ) * w (L+1+1) a b k) = _\n  rw [h]\n  beta_reduce at h\n  rw [hs, hs']\n  push_cast\n  ring\n\nlemma prior_eq (N : ℕ) (a b : ℝ) (k : ℕ) : prior N a b k = w N a b k / rise (a+b) N := rfl\n\nlemma E0 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k = 1 := by\n  have hZ : rise (a+b) (L+2) ≠ 0 := (rise_pos (by linarith) _).ne'\n  have := w_sum a b (L+2)\n  simp only [prior_eq]\n  rw [← Finset.sum_div]\n  exact (div_eq_one_iff_eq hZ).2 this\n\nlemma E1 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ) = ((L:ℝ)+2) * a / (a+b) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S1, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\nlemma E2 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) + (a+b+1)) / ((a+b) * (a+b+1)) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S2, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\n/-- General beta-binomial variance, proved from the definition of `prior`:\nVar(K) = N a b (a+b+N) / ((a+b)^2 (a+b+1)), N = L+2 (mean is N a/(a+b)). -/\nlemma var_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * ((k:ℝ) - ((L:ℝ)+2) * a / (a+b))^2\n      = ((L:ℝ)+2) * a * b * (a+b+((L:ℝ)+2)) / ((a+b)^2 * (a+b+1)) := by\n  set μ : ℝ := ((L:ℝ)+2) * a / (a+b) with hμ\n  have e : ∀ k : ℕ, prior (L+2) a b k * ((k:ℝ) - μ)^2\n      = prior (L+2) a b k * (k:ℝ)^2 - 2 * μ * (prior (L+2) a b k * (k:ℝ))\n        + μ^2 * prior (L+2) a b k := by\n    intro k; ring\n  simp only [e, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum]\n  rw [E2 ha hb, E1 ha hb, E0 ha hb, hμ]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n  ring\n\n/-- Parameters are determined by the supplied mean and sd (intermediate result). -/\nlemma params {a b : ℝ} (ha : 0 < a) (hb : 0 < b)\n    (hmean : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4)\n    (hvar : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100) :\n    a = 213/10 ∧ b = 71/10 := by\n  have h1 := E1 ha hb 48\n  have hv := var_formula ha hb 48\n  have hs : a + b ≠ 0 := by linarith\n  have hm : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50)\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ)) / 50 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  have h1' : ∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ) = 50 * a / (a + b) := by\n    have := h1\n    norm_num at this\n    exact this\n  rw [hm, h1'] at hmean\n  have hab : a = 3 * b := by\n    field_simp at hmean\n    linarith\n  have hμ : (50 : ℝ) * a / (a + b) = 75 / 2 := by\n    rw [hab]; field_simp; ring\n  have hv' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 50 * a / (a + b))^2\n      = 50 * a * b * (a + b + 50) / ((a+b)^2 * (a+b+1)) := by\n    have := hv\n    norm_num at this\n    exact this\n  rw [hμ] at hv'\n  have hvar' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 75/2)^2) / 2500 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  rw [hvar', hv'] at hvar\n  subst hab\n  have hb2 : b ≠ 0 := hb.ne'\n  have h4 : 3 * b + b + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hb' : b = 71/10 := by\n    have : b^2 * (b * 100000 - 7100 * 100) = 0 := by nlinarith [hvar]\n    have hb2' : b^2 ≠ 0 := pow_ne_zero 2 hb2\n    have := (mul_eq_zero.mp this).resolve_left hb2'\n    linarith\n  subst hb'\n  norm_num\n\n/-! ### Posterior predictive (general Polya-urn identity, proved from the definitions) -/\n\nlemma Fdesc (b : ℝ) : ∀ n N : ℕ, ∀ a : ℝ, n ≤ N →\n    ∑ k ∈ Finset.range (N+1), ((k.descFactorial n : ℕ) : ℝ) * w N a b k\n      = ((N.descFactorial n : ℕ) : ℝ) * rise a n * rise (a + n + b) (N - n) := by\n  intro n\n  induction n with\n  | zero =>\n    intro N a _\n    simp only [Nat.descFactorial_zero, Nat.cast_one, one_mul, Nat.sub_zero, Nat.cast_zero,\n      add_zero, rise_zero]\n    exact w_sum a b N\n  | succ n ih =>\n    intro N a hn\n    obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by omega⟩\n    have h := shift M a b (fun k => ((( k - 1).descFactorial n : ℕ) : ℝ))\n    have e : ∀ k : ℕ, ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) := by\n      intro k\n      cases k with\n      | zero => simp\n      | succ i =>\n        rw [Nat.succ_descFactorial_succ]\n        simp only [Nat.add_sub_cancel]\n        push_cast\n        ring\n    have hL : ∑ k ∈ Finset.range (M+1+1), ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ∑ k ∈ Finset.range (M+2), ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) :=\n      Finset.sum_congr rfl (fun k _ => e k)\n    rw [hL, h]\n    simp only [Nat.add_sub_cancel]\n    rw [ih M (a+1) (by omega), Nat.succ_descFactorial_succ, rise_shift a n]\n    have e2 : M + 1 - (n + 1) = M - n := by omega\n    rw [e2]\n    have e3 : a + 1 + (n:ℝ) + b = a + ((n+1 : ℕ) : ℝ) + b := by push_cast; ring\n    rw [e3]\n    push_cast\n    ring\n\n/-- General result: after n black draws, the predictive probability is (a+n)/(a+b+n);\nhere specialised to N = 50, n = 10. -/\nlemma predictive_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) :\n    predictive a b = (a + 10) / (a + b + 10) := by\n  have hZ : rise (a+b) 50 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hD : (((50:ℕ).descFactorial 10 : ℕ) : ℝ) ≠ 0 := by\n    norm_num [Nat.descFactorial]\n  have hR : rise (a + 11 + b) 39 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hA : rise a 10 ≠ 0 := (rise_pos ha _).ne'\n  have hx : a + 10 + b ≠ 0 := by linarith\n  have h11 : ∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 11 : ℕ) : ℝ) * rise a 11 * rise (a + 11 + b) 39 := by\n    have h := Fdesc b 11 50 a (by norm_num)\n    rw [show a + ((11:ℕ):ℝ) + b = a + 11 + b by push_cast; ring] at h\n    exact h\n  have h10 : ∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * rise a 10 * rise (a + 10 + b) 40 := by\n    have h := Fdesc b 10 50 a (by norm_num)\n    rw [show a + ((10:ℕ):ℝ) + b = a + 10 + b by push_cast; ring] at h\n    exact h\n  have hd : (((50:ℕ).descFactorial 11 : ℕ) : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) := by\n    norm_num [Nat.descFactorial]\n  have hr11 : rise a 11 = rise a 10 * (a + 10) := by\n    have := rise_succ a 10\n    norm_num at this\n    exact this\n  have hr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39 := by\n    have := rise_shift (a + 10 + b) 39\n    have e : a + 10 + b + 1 = a + 11 + b := by ring\n    rw [e] at this\n    exact this\n  have hk : ∀ k : ℕ, ((k.descFactorial 11 : ℕ) : ℝ) = ((k.descFactorial 10 : ℕ) : ℝ) * ((k:ℝ) - 10) := by\n    intro k\n    rcases Nat.lt_or_ge k 10 with h | h\n    · have h0 : k.descFactorial 10 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr h\n      have h1 : k.descFactorial 11 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr (by omega)\n      rw [h0, h1]; simp\n    · rw [show (11:ℕ) = 10 + 1 from rfl, Nat.descFactorial_succ, Nat.cast_mul, Nat.cast_sub h]\n      push_cast\n      ring\n  have hnum : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * 40) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik, nextBlack, hk k]\n    field_simp\n  have hden : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ)) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik]\n    field_simp\n  unfold predictive\n  rw [hnum, hden]\n  rw [h11, h10, hd, hr11, hr40]\n  field_simp\n  ring\n\n/-! ### Final answer -/\n\n/-- ANSWER.  If K has the beta-binomial prior (unspecified a,b>0) whose K/50 has mean 3/4 and\nvariance 1/100, then after 10 black draws without replacement the probability that the\nnext ball is black is 313/384 ≈ 0.815. -/\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 →\n    predictive a b = 313/384 := by\n  intro a b ha hb hm hv\n  obtain ⟨rfl, rfl⟩ := params ha hb hm hv\n  rw [predictive_formula ha hb]\n  norm_num\n"
        },
        {
          "name": "checks/a13c66c5450348d7838838d13ab7ba13/submitted.lean",
          "content": "import Mathlib.Data.Real.Basic\nimport Mathlib.Data.Nat.Choose.Basic\nimport Mathlib.Data.Nat.Factorial.Basic\nimport Mathlib.Algebra.BigOperators.Intervals\nimport Mathlib.Algebra.BigOperators.Ring.Finset\nimport Mathlib.Algebra.BigOperators.Field\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.Positivity\nimport Mathlib.Tactic.LinearCombination\n\n/-!\n# Beta-binomial model for the black count of a 50-ball box\n\nSUPPLIED: box of N = 50 balls; K = unknown number of black ones; 10 balls drawn without\nreplacement, all black; across boxes the fraction K/50 has mean 3/4 and sd 1/10.\n\nMODEL CHOICE (assumption, for review): across boxes K follows a beta-binomial law with\nUNSPECIFIED positive parameters a, b:\n   P(K = k) = C(N,k) * a^(k rising) * b^((N-k) rising) / (a+b)^(N rising)\n(= the law of K | p ~ Binomial(N,p) with p ~ Beta(a,b)).  a, b are NOT assumed: they are\nderived below from the supplied mean and sd.  Given K = k, the 10 draws are a uniformly\nrandom sample without replacement, and my box is exchangeable with the other boxes.\n-/\n\n/-- rising factorial x (x+1) ... (x+n-1) -/\ndef rise (x : ℝ) : ℕ → ℝ\n  | 0 => 1\n  | n+1 => rise x n * (x + n)\n\n/-- Beta-binomial prior pmf of the initial black count k, box size N, parameters a b. -/\nnoncomputable def prior (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k) / rise (a + b) N\n\n/-- Likelihood of 10 black draws without replacement if k of 50 balls are black. -/\nnoncomputable def lik (k : ℕ) : ℝ := (k.descFactorial 10 : ℝ) / ((50 : ℕ).descFactorial 10 : ℝ)\n\n/-- Chance the 11th ball is black given k black initially and 10 black removed (40 left). -/\nnoncomputable def nextBlack (k : ℕ) : ℝ := ((k : ℝ) - 10) / 40\n\n/-- Posterior predictive probability that the next ball is black. -/\nnoncomputable def predictive (a b : ℝ) : ℝ :=\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k) /\n  (∑ k ∈ Finset.range 51, prior 50 a b k * lik k)\n\n/-! ### Technical lemmas (proved, not assumed) -/\n\nlemma rise_succ (x : ℝ) (n : ℕ) : rise x (n+1) = rise x n * (x + n) := rfl\n\nlemma rise_zero (x : ℝ) : rise x 0 = 1 := rfl\n\nlemma rise_pos {x : ℝ} (hx : 0 < x) : ∀ n, 0 < rise x n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ]\n    have : (0:ℝ) ≤ n := Nat.cast_nonneg n\n    exact mul_pos ih (by linarith)\n\nlemma rise_shift (x : ℝ) : ∀ n, rise x (n+1) = x * rise (x+1) n := by\n  intro n\n  induction n with\n  | zero => simp [rise]\n  | succ n ih =>\n    rw [rise_succ x (n+1), ih, rise_succ (x+1) n]\n    push_cast\n    ring\n\n/-- unnormalised weight -/\nnoncomputable def w (N : ℕ) (a b : ℝ) (k : ℕ) : ℝ :=\n  (N.choose k : ℝ) * rise a k * rise b (N - k)\n\nlemma w_succ_sum (a b : ℝ) (N : ℕ) :\n    ∑ k ∈ Finset.range (N+2), w (N+1) a b k\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n  have h1 : ∀ i : ℕ, w (N+1) a b (i+1)\n      = w N a b i * (a + i) + w N a b (i+1) * (b + N - (i+1)) := by\n    intro i\n    unfold w\n    rw [Nat.choose_succ_succ, Nat.add_sub_add_right, rise_succ a i]\n    rcases Nat.lt_or_ge i N with h | h\n    · have e : N - i = (N - (i+1)) + 1 := by omega\n      rw [e, rise_succ b (N-(i+1)), Nat.cast_sub (by omega : i+1 ≤ N)]\n      push_cast\n      ring\n    · have h0 : N.choose (i+1) = 0 := Nat.choose_eq_zero_of_lt (by omega)\n      rw [h0]\n      push_cast\n      ring\n  have hz : w N a b (N+1) = 0 := by simp [w]\n  have hA : ∑ i ∈ Finset.range (N+1), w N a b (i+1) * (b + N - (i+1))\n      = ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k) - rise b (N+1) := by\n    have := Finset.sum_range_succ' (fun k => w N a b k * (b + N - k)) (N+1)\n    rw [Finset.sum_range_succ] at this\n    have h0 : w N a b 0 * (b + N - ((0:ℕ):ℝ)) = rise b (N+1) := by\n      simp [w, rise_succ, rise_zero]\n    simp only [hz, zero_mul, add_zero, h0] at this\n    push_cast at this ⊢\n    linarith\n  rw [Finset.sum_range_succ' _ (N+1)]\n  simp only [h1, Finset.sum_add_distrib]\n  rw [hA]\n  have h00 : w (N+1) a b 0 = rise b (N+1) := by simp [w, rise_zero]\n  rw [h00]\n  have key : ∑ k ∈ Finset.range (N+1), w N a b k * (a + k)\n      + ∑ k ∈ Finset.range (N+1), w N a b k * (b + N - k)\n      = (a + b + N) * ∑ k ∈ Finset.range (N+1), w N a b k := by\n    rw [Finset.mul_sum, ← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  linarith\n\n/-- The prior is normalised: Vandermonde identity for rising factorials. -/\nlemma w_sum (a b : ℝ) : ∀ N : ℕ, ∑ k ∈ Finset.range (N+1), w N a b k = rise (a+b) N := by\n  intro N\n  induction N with\n  | zero => simp [w, rise]\n  | succ n ih =>\n    rw [w_succ_sum, ih, rise_succ]\n    ring\n\nlemma shift (M : ℕ) (a b : ℝ) (f : ℕ → ℝ) :\n    ∑ k ∈ Finset.range (M+2), f k * ((k:ℝ) * w (M+1) a b k)\n      = ((M:ℝ)+1) * a * ∑ i ∈ Finset.range (M+1), f (i+1) * w M (a+1) b i := by\n  rw [Finset.sum_range_succ']\n  simp only [Nat.cast_zero, zero_mul, mul_zero, add_zero]\n  rw [Finset.mul_sum]\n  apply Finset.sum_congr rfl\n  intro i _\n  have hc := Nat.add_one_mul_choose_eq M i\n  have hc' : ((M:ℝ)+1) * (M.choose i : ℝ) = ((M+1).choose (i+1) : ℝ) * ((i:ℝ)+1) := by\n    exact_mod_cast hc\n  unfold w\n  rw [Nat.add_sub_add_right, rise_shift a i]\n  push_cast\n  linear_combination (-(f (i+1)) * a * rise (a+1) i * rise b (M-i)) * hc'\n\nlemma Zr (a b : ℝ) (L : ℕ) :\n    rise (a+b) (L+2) = (a+b) * (a+b+1) * rise (a+b+2) L := by\n  rw [rise_shift (a+b) (L+1), rise_shift (a+b+1) L]\n  have : a+b+1+1 = a+b+2 := by ring\n  rw [this]\n  ring\n\nlemma S1 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k\n      = ((L:ℝ)+2) * a * ((a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun _ => 1)\n  simp only [one_mul] at h\n  have h2 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h2\n  rw [h2, h3] at h\n  push_cast at h\n  convert h using 2\n  ring\n\nlemma S2 (a b : ℝ) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) * rise (a+b+2) L\n          + (a+b+1) * rise (a+b+2) L) := by\n  have h := shift (L+1) a b (fun k => (k:ℝ))\n  have hs : ∑ i ∈ Finset.range (L+1+1), ((i+1:ℕ):ℝ) * w (L+1) (a+1) b i\n      = ∑ i ∈ Finset.range (L+1+1), (i:ℝ) * w (L+1) (a+1) b i\n        + ∑ i ∈ Finset.range (L+1+1), w (L+1) (a+1) b i := by\n    rw [← Finset.sum_add_distrib]\n    apply Finset.sum_congr rfl\n    intros\n    push_cast\n    ring\n  have h4 := shift L (a+1) b (fun _ => 1)\n  simp only [one_mul] at h4\n  have h5 := w_sum (a+1+1) b L\n  have h6 := w_sum (a+1) b (L+1)\n  have h3 := rise_shift (a+1+b) L\n  have e : a+1+b+1 = a+b+2 := by ring\n  have e2 : a+1+b = a+b+1 := by ring\n  have e3 : a+1+1+b = a+b+2 := by ring\n  rw [e, e2] at h3\n  rw [e2] at h6\n  rw [e3] at h5\n  rw [h5] at h4\n  rw [h6, h3] at hs\n  have hs' : ∑ i ∈ Finset.range (L+1+1), ((i:ℝ)) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := by\n    have : ∑ i ∈ Finset.range (L+2), (i:ℝ) * w (L+1) (a+1) b i\n      = ((L:ℝ)+1) * (a+1) * rise (a+b+2) L := h4\n    exact this\n  show ∑ k ∈ Finset.range (L+1+2), (k:ℝ) * ((k:ℝ) * w (L+1+1) a b k) = _\n  rw [h]\n  beta_reduce at h\n  rw [hs, hs']\n  push_cast\n  ring\n\nlemma prior_eq (N : ℕ) (a b : ℝ) (k : ℕ) : prior N a b k = w N a b k / rise (a+b) N := rfl\n\nlemma E0 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k = 1 := by\n  have hZ : rise (a+b) (L+2) ≠ 0 := (rise_pos (by linarith) _).ne'\n  have := w_sum a b (L+2)\n  simp only [prior_eq]\n  rw [← Finset.sum_div]\n  exact (div_eq_one_iff_eq hZ).2 this\n\nlemma E1 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ) = ((L:ℝ)+2) * a / (a+b) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * w (L+2) a b k) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S1, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\nlemma E2 {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = ((L:ℝ)+2) * a * (((L:ℝ)+1) * (a+1) + (a+b+1)) / ((a+b) * (a+b+1)) := by\n  have hr : rise (a+b+2) L ≠ 0 := (rise_pos (by linarith) _).ne'\n  have e : ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * (k:ℝ)^2\n      = (∑ k ∈ Finset.range (L+3), (k:ℝ) * ((k:ℝ) * w (L+2) a b k)) / rise (a+b) (L+2) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    rw [prior_eq]\n    ring\n  rw [e, S2, Zr]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n\n/-- General beta-binomial variance, proved from the definition of `prior`:\nVar(K) = N a b (a+b+N) / ((a+b)^2 (a+b+1)), N = L+2 (mean is N a/(a+b)). -/\nlemma var_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (L : ℕ) :\n    ∑ k ∈ Finset.range (L+3), prior (L+2) a b k * ((k:ℝ) - ((L:ℝ)+2) * a / (a+b))^2\n      = ((L:ℝ)+2) * a * b * (a+b+((L:ℝ)+2)) / ((a+b)^2 * (a+b+1)) := by\n  set μ : ℝ := ((L:ℝ)+2) * a / (a+b) with hμ\n  have e : ∀ k : ℕ, prior (L+2) a b k * ((k:ℝ) - μ)^2\n      = prior (L+2) a b k * (k:ℝ)^2 - 2 * μ * (prior (L+2) a b k * (k:ℝ))\n        + μ^2 * prior (L+2) a b k := by\n    intro k; ring\n  simp only [e, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum]\n  rw [E2 ha hb, E1 ha hb, E0 ha hb, hμ]\n  have : a + b ≠ 0 := by linarith\n  have : a + b + 1 ≠ 0 := by linarith\n  field_simp\n  ring\n\n/-- Parameters are determined by the supplied mean and sd (intermediate result). -/\nlemma params {a b : ℝ} (ha : 0 < a) (hb : 0 < b)\n    (hmean : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4)\n    (hvar : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100) :\n    a = 213/10 ∧ b = 71/10 := by\n  have h1 := E1 ha hb 48\n  have hv := var_formula ha hb 48\n  have hs : a + b ≠ 0 := by linarith\n  have hm : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50)\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ)) / 50 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  have h1' : ∑ k ∈ Finset.range 51, prior 50 a b k * (k:ℝ) = 50 * a / (a + b) := by\n    have := h1\n    norm_num at this\n    exact this\n  rw [hm, h1'] at hmean\n  have hab : a = 3 * b := by\n    field_simp at hmean\n    linarith\n  have hμ : (50 : ℝ) * a / (a + b) = 75 / 2 := by\n    rw [hab]; field_simp; ring\n  have hv' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 50 * a / (a + b))^2\n      = 50 * a * b * (a + b + 50) / ((a+b)^2 * (a+b+1)) := by\n    have := hv\n    norm_num at this\n    exact this\n  rw [hμ] at hv'\n  have hvar' : ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2\n      = (∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) - 75/2)^2) / 2500 := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intros\n    ring\n  rw [hvar', hv'] at hvar\n  subst hab\n  have hb2 : b ≠ 0 := hb.ne'\n  have h4 : 3 * b + b + 1 ≠ 0 := by linarith\n  field_simp at hvar\n  have hb' : b = 71/10 := by\n    have : b^2 * (b * 100000 - 7100 * 100) = 0 := by nlinarith [hvar]\n    have hb2' : b^2 ≠ 0 := pow_ne_zero 2 hb2\n    have := (mul_eq_zero.mp this).resolve_left hb2'\n    linarith\n  subst hb'\n  norm_num\n\n/-! ### Posterior predictive (general Polya-urn identity, proved from the definitions) -/\n\nlemma Fdesc (b : ℝ) : ∀ n N : ℕ, ∀ a : ℝ, n ≤ N →\n    ∑ k ∈ Finset.range (N+1), ((k.descFactorial n : ℕ) : ℝ) * w N a b k\n      = ((N.descFactorial n : ℕ) : ℝ) * rise a n * rise (a + n + b) (N - n) := by\n  intro n\n  induction n with\n  | zero =>\n    intro N a _\n    simp only [Nat.descFactorial_zero, Nat.cast_one, one_mul, Nat.sub_zero, Nat.cast_zero,\n      add_zero, rise_zero]\n    exact w_sum a b N\n  | succ n ih =>\n    intro N a hn\n    obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by omega⟩\n    have h := shift M a b (fun k => ((( k - 1).descFactorial n : ℕ) : ℝ))\n    have e : ∀ k : ℕ, ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) := by\n      intro k\n      cases k with\n      | zero => simp\n      | succ i =>\n        rw [Nat.succ_descFactorial_succ]\n        simp only [Nat.add_sub_cancel]\n        push_cast\n        ring\n    have hL : ∑ k ∈ Finset.range (M+1+1), ((k.descFactorial (n+1) : ℕ) : ℝ) * w (M+1) a b k\n        = ∑ k ∈ Finset.range (M+2), ((((k - 1).descFactorial n : ℕ)) : ℝ) * ((k:ℝ) * w (M+1) a b k) :=\n      Finset.sum_congr rfl (fun k _ => e k)\n    rw [hL, h]\n    simp only [Nat.add_sub_cancel]\n    rw [ih M (a+1) (by omega), Nat.succ_descFactorial_succ, rise_shift a n]\n    have e2 : M + 1 - (n + 1) = M - n := by omega\n    rw [e2]\n    have e3 : a + 1 + (n:ℝ) + b = a + ((n+1 : ℕ) : ℝ) + b := by push_cast; ring\n    rw [e3]\n    push_cast\n    ring\n\n/-- General result: after n black draws, the predictive probability is (a+n)/(a+b+n);\nhere specialised to N = 50, n = 10. -/\nlemma predictive_formula {a b : ℝ} (ha : 0 < a) (hb : 0 < b) :\n    predictive a b = (a + 10) / (a + b + 10) := by\n  have hZ : rise (a+b) 50 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hD : (((50:ℕ).descFactorial 10 : ℕ) : ℝ) ≠ 0 := by\n    norm_num [Nat.descFactorial]\n  have hR : rise (a + 11 + b) 39 ≠ 0 := (rise_pos (by linarith) _).ne'\n  have hA : rise a 10 ≠ 0 := (rise_pos ha _).ne'\n  have hx : a + 10 + b ≠ 0 := by linarith\n  have h11 : ∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 11 : ℕ) : ℝ) * rise a 11 * rise (a + 11 + b) 39 := by\n    have h := Fdesc b 11 50 a (by norm_num)\n    rw [show a + ((11:ℕ):ℝ) + b = a + 11 + b by push_cast; ring] at h\n    exact h\n  have h10 : ∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k\n      = (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * rise a 10 * rise (a + 10 + b) 40 := by\n    have h := Fdesc b 10 50 a (by norm_num)\n    rw [show a + ((10:ℕ):ℝ) + b = a + 10 + b by push_cast; ring] at h\n    exact h\n  have hd : (((50:ℕ).descFactorial 11 : ℕ) : ℝ) = 40 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) := by\n    norm_num [Nat.descFactorial]\n  have hr11 : rise a 11 = rise a 10 * (a + 10) := by\n    have := rise_succ a 10\n    norm_num at this\n    exact this\n  have hr40 : rise (a + 10 + b) 40 = (a + 10 + b) * rise (a + 11 + b) 39 := by\n    have := rise_shift (a + 10 + b) 39\n    have e : a + 10 + b + 1 = a + 11 + b := by ring\n    rw [e] at this\n    exact this\n  have hk : ∀ k : ℕ, ((k.descFactorial 11 : ℕ) : ℝ) = ((k.descFactorial 10 : ℕ) : ℝ) * ((k:ℝ) - 10) := by\n    intro k\n    rcases Nat.lt_or_ge k 10 with h | h\n    · have h0 : k.descFactorial 10 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr h\n      have h1 : k.descFactorial 11 = 0 := Nat.descFactorial_eq_zero_iff_lt.mpr (by omega)\n      rw [h0, h1]; simp\n    · rw [show (11:ℕ) = 10 + 1 from rfl, Nat.descFactorial_succ, Nat.cast_mul, Nat.cast_sub h]\n      push_cast\n      ring\n  have hnum : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k * nextBlack k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 11 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ) * 40) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik, nextBlack, hk k]\n    field_simp\n  have hden : ∑ k ∈ Finset.range 51, prior 50 a b k * lik k\n      = (∑ k ∈ Finset.range 51, ((k.descFactorial 10 : ℕ) : ℝ) * w 50 a b k) / (rise (a+b) 50 * (((50:ℕ).descFactorial 10 : ℕ) : ℝ)) := by\n    rw [Finset.sum_div]\n    apply Finset.sum_congr rfl\n    intro k _\n    rw [prior_eq, lik]\n    field_simp\n  unfold predictive\n  rw [hnum, hden]\n  rw [h11, h10, hd, hr11, hr40]\n  field_simp\n  ring\n\n/-! ### Final answer -/\n\n/-- ANSWER.  If K has the beta-binomial prior (unspecified a,b>0) whose K/50 has mean 3/4 and\nvariance 1/100, then after 10 black draws without replacement the probability that the\nnext ball is black is 313/384 ≈ 0.815. -/\ntheorem answer_theorem : ∀ a b : ℝ, 0 < a → 0 < b →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50) = 3/4 →\n    ∑ k ∈ Finset.range 51, prior 50 a b k * ((k:ℝ) / 50 - 3/4)^2 = 1/100 →\n    predictive a b = 313/384 := by\n  intro a b ha hb hm hv\n  obtain ⟨rfl, rfl⟩ := params ha hb hm hv\n  rw [predictive_formula ha hb]\n  norm_num\n"
        }
      ],
      "user_feedback": "accepted"
    }
  ]
}
