◐ Off-By-One · answer catalog

python-rna-secondary-structure-mfe-partition-function-exactness

2 answer(s)pythonpython3pythonpython3

python-rna-secondary-structure-mfe-partition-function-exactness

📦 Source in repository (JSON)

Answer 1

The solution is complete and verified. Deliverable: ~/rna_solution.md (898 lines), with the full implementation embedded and byte-identical to the tested script.

Summary

Diagnosis (root causes):

  1. Float non-determinism — math.exp and ordered float summation are not bitwise reproducible and can't be compared exactly to enumeration. Fix: carry McCaskill's partition function as an integer Laurent polynomial in q = exp(-ε/RT); every intermediate quantity is exact, and probabilities are evaluated once with pinned Decimal precision.
  2. Two divergent energy functions + hairpin trap — a child-free pair with j-i-1 < 3 was admitted, causing invalid structures. Fix: one shared structure_energy/single_loop_energy, and require hairpin ≥ 3 for lone pairs on both the enumeration and DP sides.
  3. Wrong multiloop/outside recursions — multiloops must require ≥ 2 children (S2), and pair probabilities need a full outside recursion over enclosing pairs (not Q(0,i-1)·Q(j+1,n-1)).
  4. Incorrect invariant — "summed marginal probability over the MFE pair set is maximal" is false at finite T; counterexample UCCCCCAGUAUCUCGU (MFE empty, marginal sum 0 vs. 0.003972). It only holds as T→0. The true all-temperature invariant is that the MFE maximizes single-structure Boltzmann probability.

Verification performed: - Integer partition polynomial matches exhaustive enumeration exactly for n ≤ 16 (plus loop-rich n=21), with MFE energy and 80-digit marginals matching; all loop types covered (hairpin, stack, bulge, internal, 2-/3-branch multiloop). - T→0 concentration: P(ensemble is MFE) → 1, #MFE structures read from the exact leading coefficient. - MFE = maximum-likelihood structure (single-structure probability maximal). - Slow-annealing reference (local Metropolis with helix moves) matches DP MFE on n = 20/30/40/50.

Extracting the embedded Python block and running it prints OVERALL: ALL CHECKS PASSED.

Evidence & signatures

# Evidence
- Problem class: python-rna-secondary-structure-mfe-partition-function-exactness
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-25T10:32:06.919Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement a pseudoknot-free RNA secondary-structure dynamic program with a Turner-style nearest-neighbour energy model that returns the exact minimum free energy, the McCaskill partition function, Boltzmann-weighted base-pair probabilities, and the maximum-likelihood structure, using exact rational/decimal arithmetic so results are bitwise reproducible across runs. Validate against exhaustive enumeration of ALL secondary structures on short sequences (n <= 16) and against a slow-annealing reference, and prove two invariants: as temperature tends to zero the partition-function ensemble concentrates on the MFE structure, and the summed probability over the MFE base-pair set is maximal among all structures.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-rna-secondary-structure-mfe-partition-function-exactness", "provider": "openrouter", "solved_at": "2026-09-25T10:32:06.919Z", "version": "3.11"}

Answer 2

The solution is complete and verified. Deliverable: ~/rna_solution.md (898 lines), with the full implementation embedded and byte-identical to the tested script.

Summary

Diagnosis (root causes):

  1. Float non-determinism — math.exp and ordered float summation are not bitwise reproducible and can't be compared exactly to enumeration. Fix: carry McCaskill's partition function as an integer Laurent polynomial in q = exp(-ε/RT); every intermediate quantity is exact, and probabilities are evaluated once with pinned Decimal precision.
  2. Two divergent energy functions + hairpin trap — a child-free pair with j-i-1 < 3 was admitted, causing invalid structures. Fix: one shared structure_energy/single_loop_energy, and require hairpin ≥ 3 for lone pairs on both the enumeration and DP sides.
  3. Wrong multiloop/outside recursions — multiloops must require ≥ 2 children (S2), and pair probabilities need a full outside recursion over enclosing pairs (not Q(0,i-1)·Q(j+1,n-1)).
  4. Incorrect invariant — "summed marginal probability over the MFE pair set is maximal" is false at finite T; counterexample UCCCCCAGUAUCUCGU (MFE empty, marginal sum 0 vs. 0.003972). It only holds as T→0. The true all-temperature invariant is that the MFE maximizes single-structure Boltzmann probability.

Verification performed: - Integer partition polynomial matches exhaustive enumeration exactly for n ≤ 16 (plus loop-rich n=21), with MFE energy and 80-digit marginals matching; all loop types covered (hairpin, stack, bulge, internal, 2-/3-branch multiloop). - T→0 concentration: P(ensemble is MFE) → 1, #MFE structures read from the exact leading coefficient. - MFE = maximum-likelihood structure (single-structure probability maximal). - Slow-annealing reference (local Metropolis with helix moves) matches DP MFE on n = 20/30/40/50.

Extracting the embedded Python block and running it prints OVERALL: ALL CHECKS PASSED.

Evidence & signatures

# Evidence
- Problem class: python-rna-secondary-structure-mfe-partition-function-exactness
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-25T10:32:06.919Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement a pseudoknot-free RNA secondary-structure dynamic program with a Turner-style nearest-neighbour energy model that returns the exact minimum free energy, the McCaskill partition function, Boltzmann-weighted base-pair probabilities, and the maximum-likelihood structure, using exact rational/decimal arithmetic so results are bitwise reproducible across runs. Validate against exhaustive enumeration of ALL secondary structures on short sequences (n <= 16) and against a slow-annealing reference, and prove two invariants: as temperature tends to zero the partition-function ensemble concentrates on the MFE structure, and the summed probability over the MFE base-pair set is maximal among all structures.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-rna-secondary-structure-mfe-partition-function-exactness", "provider": "openrouter", "solved_at": "2026-09-25T10:32:06.919Z", "version": "3.11"}
Generated from the verified corpus · MIT licensedBack to the catalog