@louisultra/dsh-verymath 0.0.0-stage → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +133 -0
- package/LICENSE +21 -0
- package/NOTICE.md +35 -0
- package/README.md +108 -2
- package/README_EN.md +105 -0
- package/UPSTREAM.json +106 -0
- package/cordis.patch.yml +12 -0
- package/docs/capability-examples.md +581 -0
- package/docs/examples/README.md +32 -0
- package/docs/examples/bad_scan.md +10 -0
- package/docs/examples/broken-proof.lean +9 -0
- package/docs/examples/claims.md +7 -0
- package/docs/examples/knapsack.json +10 -0
- package/docs/examples/matrix.json +1 -0
- package/docs/examples/points.csv +21 -0
- package/docs/examples/qp.json +8 -0
- package/docs/examples/research-ws/project/GOALS.yaml +4 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/report.md +13 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/reviews/r1.json +1 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/status.yaml +1 -0
- package/docs/examples/source.csv +4 -0
- package/lib/core/error.d.ts +20 -0
- package/lib/core/error.js +25 -0
- package/lib/core/gates.d.ts +42 -0
- package/lib/core/gates.js +217 -0
- package/lib/core/glossary.d.ts +101 -0
- package/lib/core/glossary.js +243 -0
- package/lib/core/graph.d.ts +118 -0
- package/lib/core/graph.js +460 -0
- package/lib/core/index.d.ts +120 -0
- package/lib/core/index.js +197 -0
- package/lib/core/paper.d.ts +163 -0
- package/lib/core/paper.js +73 -0
- package/lib/core/paths.d.ts +2 -0
- package/lib/core/paths.js +12 -0
- package/lib/core/sage.d.ts +61 -0
- package/lib/core/sage.js +212 -0
- package/lib/core/skills.d.ts +11 -0
- package/lib/core/skills.js +110 -0
- package/lib/tool/index.d.ts +21 -0
- package/lib/tool/index.js +1144 -0
- package/package.json +92 -4
- package/skills/after-ocr/SKILL.md +123 -0
- package/skills/after-ocr/references/audit-schema.md +94 -0
- package/skills/after-ocr/references/error-taxonomy.md +179 -0
- package/skills/after-ocr/scripts/merge_audit_logs.py +329 -0
- package/skills/after-ocr/scripts/scan_markdown_ocr.py +350 -0
- package/skills/after-ocr/tests/test_scripts.py +84 -0
- package/skills/discover-math-problems/SKILL.md +115 -0
- package/skills/discover-math-problems/references/artifact-contract.md +93 -0
- package/skills/discover-math-problems/references/autonomous-research-protocol.md +86 -0
- package/skills/discover-math-problems/references/conjecture-generation-protocol.md +63 -0
- package/skills/discover-math-problems/references/extremal-graph-variants.md +53 -0
- package/skills/graph-theory-paper-reading/SKILL.md +600 -0
- package/skills/invariant-computation/SKILL.md +169 -0
- package/skills/invariant-computation/examples/invariant_summary.example.json +51 -0
- package/skills/invariant-computation/manifest.yaml +46 -0
- package/skills/invariant-computation/references/INDEX.md +20 -0
- package/skills/invariant-computation/references/failure_modes.md +40 -0
- package/skills/invariant-computation/references/method_route_map.md +177 -0
- package/skills/invariant-computation/references/source_notes.md +19 -0
- package/skills/invariant-computation/references/tool_catalog.md +65 -0
- package/skills/invariant-computation/references/validation_checks.md +52 -0
- package/skills/invariant-computation/schema/invariant_summary.schema.json +260 -0
- package/skills/lean-formalization/SKILL.md +111 -0
- package/skills/lean-formalization/lean-runtime/config/env.example +5 -0
- package/skills/lean-formalization/lean-runtime/config/lean_agent.example.toml +28 -0
- package/skills/lean-formalization/lean-runtime/config/numina_runtime.example.toml +12 -0
- package/skills/lean-formalization/lean-runtime/examples/smoke/LocalLeanSmoke.lean +7 -0
- package/skills/lean-formalization/lean-runtime/prompts/complete_sorries.md +3 -0
- package/skills/lean-formalization/lean-runtime/prompts/formalize_statement.md +3 -0
- package/skills/lean-formalization/lean-runtime/prompts/prove_theorem.md +3 -0
- package/skills/lean-formalization/lean-runtime/prompts/repair_lean_file.md +3 -0
- package/skills/lean-formalization/lean-runtime/references/backend_adapter_checklist.md +36 -0
- package/skills/lean-formalization/lean-runtime/references/direct_lean_workflow.md +48 -0
- package/skills/lean-formalization/lean-runtime/references/failure_taxonomy.md +17 -0
- package/skills/lean-formalization/lean-runtime/references/interactive_orchestration.md +83 -0
- package/skills/lean-formalization/lean-runtime/references/lean_agent_capability_map.md +116 -0
- package/skills/lean-formalization/lean-runtime/references/lean_lsp_mcp_adapter.md +219 -0
- package/skills/lean-formalization/lean-runtime/references/lean_runtime_configuration.md +92 -0
- package/skills/lean-formalization/lean-runtime/references/numina_reverse_analysis.md +80 -0
- package/skills/lean-formalization/lean-runtime/references/numina_runtime.md +41 -0
- package/skills/lean-formalization/lean-runtime/references/numina_subagent_troubleshooting.md +77 -0
- package/skills/lean-formalization/lean-runtime/references/review_checklist.md +10 -0
- package/skills/lean-formalization/lean-runtime/references/specialist_agent_patterns.md +65 -0
- package/skills/lean-formalization/lean-runtime/schemas/config.schema.json +12 -0
- package/skills/lean-formalization/lean-runtime/schemas/result.schema.json +33 -0
- package/skills/lean-formalization/lean-runtime/schemas/task.schema.json +30 -0
- package/skills/lean-formalization/lean-runtime/scripts/ai4m_lean.py +222 -0
- package/skills/lean-formalization/lean-runtime/scripts/check_lean_project.py +134 -0
- package/skills/lean-formalization/lean-runtime/scripts/common.py +296 -0
- package/skills/lean-formalization/lean-runtime/scripts/configure_lean.py +222 -0
- package/skills/lean-formalization/lean-runtime/scripts/detect_sorry.py +49 -0
- package/skills/lean-formalization/lean-runtime/scripts/direct_task.py +100 -0
- package/skills/lean-formalization/lean-runtime/scripts/extract_minimal_failure.py +74 -0
- package/skills/lean-formalization/lean-runtime/scripts/numina_runtime.py +414 -0
- package/skills/lean-formalization/lean-runtime/scripts/smoke_test.py +75 -0
- package/skills/lean-formalization/lean-runtime/scripts/tool_status.py +79 -0
- package/skills/lean-formalization/lean-runtime/scripts/validate_patch.py +81 -0
- package/skills/lean-formalization/lean-runtime/scripts/verify_delivery.py +484 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/after_bad.lean +4 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/after_statement_changed.lean +4 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/before.lean +4 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/failure.lean +7 -0
- package/skills/lean-formalization/lean-runtime/tests/test_check_lean_project.py +59 -0
- package/skills/lean-formalization/lean-runtime/tests/test_cli.py +377 -0
- package/skills/lean-formalization/lean-runtime/tests/test_common_config.py +84 -0
- package/skills/lean-formalization/lean-runtime/tests/test_configure_lean.py +138 -0
- package/skills/lean-formalization/lean-runtime/tests/test_detect_sorry.py +24 -0
- package/skills/lean-formalization/lean-runtime/tests/test_direct_task.py +69 -0
- package/skills/lean-formalization/lean-runtime/tests/test_numina_runtime.py +168 -0
- package/skills/lean-formalization/lean-runtime/tests/test_validate_patch.py +29 -0
- package/skills/lean-setup/SKILL.md +99 -0
- package/skills/least-squares/README.md +85 -0
- package/skills/least-squares/SKILL.md +613 -0
- package/skills/least-squares/examples.md +380 -0
- package/skills/math-beamer/SKILL.md +325 -0
- package/skills/math-beamer/references/build-and-layout-audit.md +63 -0
- package/skills/math-beamer/references/math-domain-patterns.md +56 -0
- package/skills/math-beamer/references/template-policy.md +43 -0
- package/skills/math-beamer/references/template-source-index.md +51 -0
- package/skills/math-beamer/templates/catalog.yaml +235 -0
- package/skills/math-beamer/templates/packs/algebra-number-theory-talk/main.tex +45 -0
- package/skills/math-beamer/templates/packs/algebra-number-theory-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/algorithm-talk/main.tex +43 -0
- package/skills/math-beamer/templates/packs/algorithm-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/analysis-core-talk/main.tex +49 -0
- package/skills/math-beamer/templates/packs/analysis-core-talk/template.yaml +19 -0
- package/skills/math-beamer/templates/packs/backup-heavy-talk/main.tex +40 -0
- package/skills/math-beamer/templates/packs/backup-heavy-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/beamerposter-a0/main.tex +45 -0
- package/skills/math-beamer/templates/packs/beamerposter-a0/template.yaml +12 -0
- package/skills/math-beamer/templates/packs/combinatorics-graph-talk/main.tex +53 -0
- package/skills/math-beamer/templates/packs/combinatorics-graph-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/control-systems-talk/main.tex +51 -0
- package/skills/math-beamer/templates/packs/control-systems-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/course-lecture-zh/main.tex +43 -0
- package/skills/math-beamer/templates/packs/course-lecture-zh/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/data-experiment-results/main.tex +45 -0
- package/skills/math-beamer/templates/packs/data-experiment-results/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/dynamical-systems-talk/main.tex +42 -0
- package/skills/math-beamer/templates/packs/dynamical-systems-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/geometry-topology-talk/main.tex +43 -0
- package/skills/math-beamer/templates/packs/geometry-topology-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/information-coding-crypto-talk/main.tex +49 -0
- package/skills/math-beamer/templates/packs/information-coding-crypto-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/logic-foundations-category-talk/main.tex +51 -0
- package/skills/math-beamer/templates/packs/logic-foundations-category-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/numerical-analysis-talk/main.tex +51 -0
- package/skills/math-beamer/templates/packs/numerical-analysis-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/optimization-talk/main.tex +58 -0
- package/skills/math-beamer/templates/packs/optimization-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/pde-analysis-talk/main.tex +49 -0
- package/skills/math-beamer/templates/packs/pde-analysis-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/probability-statistics-talk/main.tex +52 -0
- package/skills/math-beamer/templates/packs/probability-statistics-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/reading-group-paper/main.tex +46 -0
- package/skills/math-beamer/templates/packs/reading-group-paper/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-en/main.tex +60 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-en/template.yaml +13 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-zh/main.tex +60 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-zh/template.yaml +13 -0
- package/skills/math-beamer/templates/packs/theorem-proof-talk/main.tex +60 -0
- package/skills/math-beamer/templates/packs/theorem-proof-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/thesis-defense/main.tex +42 -0
- package/skills/math-beamer/templates/packs/thesis-defense/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/workshop-tutorial/main.tex +32 -0
- package/skills/math-beamer/templates/packs/workshop-tutorial/template.yaml +9 -0
- package/skills/math-beamer/templates/preview-gallery.md +32 -0
- package/skills/math-beamer/templates/previews/algebra-number-theory-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/algebra-number-theory-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/algorithm-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/algorithm-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/analysis-core-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/analysis-core-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/backup-heavy-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/backup-heavy-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/beamerposter-a0-content.png +0 -0
- package/skills/math-beamer/templates/previews/beamerposter-a0-cover.png +0 -0
- package/skills/math-beamer/templates/previews/combinatorics-graph-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/combinatorics-graph-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/control-systems-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/control-systems-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/course-lecture-zh-content.png +0 -0
- package/skills/math-beamer/templates/previews/course-lecture-zh-cover.png +0 -0
- package/skills/math-beamer/templates/previews/data-experiment-results-content.png +0 -0
- package/skills/math-beamer/templates/previews/data-experiment-results-cover.png +0 -0
- package/skills/math-beamer/templates/previews/dynamical-systems-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/dynamical-systems-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/geometry-topology-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/geometry-topology-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/information-coding-crypto-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/information-coding-crypto-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/logic-foundations-category-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/logic-foundations-category-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/numerical-analysis-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/numerical-analysis-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/optimization-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/optimization-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/pde-analysis-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/pde-analysis-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/probability-statistics-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/probability-statistics-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/reading-group-paper-content.png +0 -0
- package/skills/math-beamer/templates/previews/reading-group-paper-cover.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-en-content.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-en-cover.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-zh-content.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-zh-cover.png +0 -0
- package/skills/math-beamer/templates/previews/theorem-proof-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/theorem-proof-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/thesis-defense-content.png +0 -0
- package/skills/math-beamer/templates/previews/thesis-defense-cover.png +0 -0
- package/skills/math-beamer/templates/previews/workshop-tutorial-content.png +0 -0
- package/skills/math-beamer/templates/previews/workshop-tutorial-cover.png +0 -0
- package/skills/math-beamer/templates/review-report.md +54 -0
- package/skills/math-beamer/templates/slide-source-ledger.md +22 -0
- package/skills/math-beamer/templates/source-packet.md +50 -0
- package/skills/math-glossary/SKILL.md +347 -0
- package/skills/math-glossary/references/glossary-schema.md +71 -0
- package/skills/math-glossary/references/glossary-usage-guide.md +176 -0
- package/skills/math-glossary/references/glossary-web-template.md +127 -0
- package/skills/math-glossary/references/glossary.schema.json +76 -0
- package/skills/math-glossary/references/user-manual.md +435 -0
- package/skills/math-glossary/requirements-ai.txt +3 -0
- package/skills/math-glossary/requirements.txt +3 -0
- package/skills/math-glossary/scripts/glossary_backup.py +42 -0
- package/skills/math-glossary/scripts/glossary_build.py +467 -0
- package/skills/math-glossary/scripts/glossary_enrich_examples.py +283 -0
- package/skills/math-glossary/scripts/glossary_export.py +333 -0
- package/skills/math-glossary/scripts/glossary_web.py +1265 -0
- package/skills/math-paper-reading/README.md +163 -0
- package/skills/math-paper-reading/SKILL.md +48 -0
- package/skills/math-paper-reading/agent_router.md +36 -0
- package/skills/math-paper-reading/references/proof_pattern_taxonomy.md +123 -0
- package/skills/math-paper-reading/references/quality_rubric.md +36 -0
- package/skills/math-paper-reading/skill_base.md +627 -0
- package/skills/math-paper-reading/skill_literature_search.md +866 -0
- package/skills/math-paper-reading/skill_paper_deep_read.md +1024 -0
- package/skills/math-paper-reading/skill_pathway_proof.md +718 -0
- package/skills/math-paper-reading/skill_reference_manager.md +746 -0
- package/skills/matlab-runner/SKILL.md +217 -0
- package/skills/matlab-runner/examples/README.md +33 -0
- package/skills/matlab-runner/examples/matrix_report.m +28 -0
- package/skills/matlab-runner/examples/plot_damped_sine.m +64 -0
- package/skills/matlab-runner/examples/test_vector_norm.m +12 -0
- package/skills/matlab-runner/references/client-setup.md +24 -0
- package/skills/matlab-runner/references/file-session-safety.md +86 -0
- package/skills/matlab-runner/references/numerical-safety.md +126 -0
- package/skills/matlab-runner/references/resource-safety.md +125 -0
- package/skills/mixed-integer-programming/SKILL.md +119 -0
- package/skills/mixed-integer-programming/lp-examples.md +251 -0
- package/skills/mixed-integer-programming/mip-examples-verified.md +118 -0
- package/skills/open-problem-research-pipeline/SKILL.md +76 -0
- package/skills/open-problem-research-pipeline/skill_literature_analysis.md +201 -0
- package/skills/open-problem-research-pipeline/skill_literature_proof_framework.md +206 -0
- package/skills/open-problem-research-pipeline/skill_literature_search.md +172 -0
- package/skills/open-problem-research-pipeline/skill_qskill.md +177 -0
- package/skills/osqp-solver/SKILL.md +245 -0
- package/skills/osqp-solver/references/citation.md +25 -0
- package/skills/osqp-solver/references/dual-infeasible-example.json +14 -0
- package/skills/osqp-solver/references/feasible-example.json +21 -0
- package/skills/osqp-solver/references/primal-infeasible-example.json +17 -0
- package/skills/osqp-solver/references/python-api.md +95 -0
- package/skills/osqp-solver/references/verification.md +94 -0
- package/skills/osqp-solver/scripts/check_osqp_environment.py +120 -0
- package/skills/osqp-solver/scripts/solve_qp.py +943 -0
- package/skills/paper-writing/SKILL.md +115 -0
- package/skills/paper-writing/skill_claim_evidence_ledger.md +55 -0
- package/skills/paper-writing/skill_formula_environment_and_readability.md +41 -0
- package/skills/paper-writing/skill_latex_build_and_layout_audit.md +73 -0
- package/skills/paper-writing/skill_notation_and_variable_consistency.md +42 -0
- package/skills/paper-writing/skill_paper_skeleton_and_logical_architecture.md +54 -0
- package/skills/paper-writing/skill_proof_obligation_and_assumption_audit.md +57 -0
- package/skills/paper-writing/templates/claim-evidence-ledger.md +23 -0
- package/skills/paper-writing/templates/proof-obligation-ledger.md +22 -0
- package/skills/paper-writing/templates/rapid-prototype-paper-skeleton.md +46 -0
- package/skills/paper-writing/templates/source-packet.md +37 -0
- package/skills/paper-writing/templates/submission-readiness.md +41 -0
- package/skills/proof-blueprint-review/SKILL.md +129 -0
- package/skills/proof-blueprint-review/references/agent-mediated-proof-protocol.md +57 -0
- package/skills/proof-blueprint-review/references/generation-agent.md +45 -0
- package/skills/proof-blueprint-review/references/proof-acceptance-contract.md +41 -0
- package/skills/proof-blueprint-review/references/verification-agent.md +37 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
import unittest
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from unittest.mock import patch
|
|
9
|
+
|
|
10
|
+
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
|
|
11
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
12
|
+
|
|
13
|
+
from direct_task import build_direct_task, run_direct_task # noqa: E402
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DirectTaskTests(unittest.TestCase):
|
|
17
|
+
def test_managed_workspace_routes_standalone_file_to_coding_agent(self) -> None:
|
|
18
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
19
|
+
root = Path(tmp)
|
|
20
|
+
workspace = root / ".ai4math" / "lean-workspace"
|
|
21
|
+
workspace.mkdir(parents=True)
|
|
22
|
+
(workspace / "lean-toolchain").write_text("leanprover/lean4:v4.28.0\n", encoding="utf-8")
|
|
23
|
+
(workspace / "lakefile.toml").write_text('name = "lean_workspace"\n', encoding="utf-8")
|
|
24
|
+
target = root / "Standalone.lean"
|
|
25
|
+
target.write_text("example : True := by trivial\n", encoding="utf-8")
|
|
26
|
+
|
|
27
|
+
with patch.dict(os.environ, {"AI4MATH_LEAN_WORKSPACE": str(workspace)}, clear=False):
|
|
28
|
+
result = build_direct_task("prove", root, target)
|
|
29
|
+
|
|
30
|
+
self.assertTrue(result["ok"])
|
|
31
|
+
self.assertEqual(result["status"], "coding_agent_task_ready")
|
|
32
|
+
self.assertEqual(result["agent_mode"], "coding-agent")
|
|
33
|
+
self.assertEqual(result["backend"], "none")
|
|
34
|
+
self.assertEqual(result["workspace_mode"], "managed_workspace")
|
|
35
|
+
self.assertEqual(result["missing_config"], [])
|
|
36
|
+
|
|
37
|
+
def test_missing_workspace_reports_required_input(self) -> None:
|
|
38
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
39
|
+
root = Path(tmp)
|
|
40
|
+
target = root / "Standalone.lean"
|
|
41
|
+
target.write_text("example : True := by trivial\n", encoding="utf-8")
|
|
42
|
+
|
|
43
|
+
with patch.dict(os.environ, {"AI4MATH_HOME": str(root / "shared-ai4math"), "AI4MATH_LEAN_WORKSPACE": ""}, clear=False):
|
|
44
|
+
result = build_direct_task("prove", root, target)
|
|
45
|
+
|
|
46
|
+
self.assertFalse(result["ok"])
|
|
47
|
+
self.assertEqual(result["status"], "missing_config")
|
|
48
|
+
self.assertIn("lean_workspace", result["missing_config"])
|
|
49
|
+
self.assertEqual(result["backend"], "none")
|
|
50
|
+
|
|
51
|
+
def test_dry_run_marks_ready_task_without_external_command(self) -> None:
|
|
52
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
53
|
+
root = Path(tmp)
|
|
54
|
+
(root / "lean-toolchain").write_text("leanprover/lean4:v4.28.0\n", encoding="utf-8")
|
|
55
|
+
(root / "lakefile.toml").write_text('name = "proj"\n', encoding="utf-8")
|
|
56
|
+
target = root / "Main.lean"
|
|
57
|
+
target.write_text("example : True := by trivial\n", encoding="utf-8")
|
|
58
|
+
|
|
59
|
+
result = run_direct_task("repair", root, target, dry_run=True)
|
|
60
|
+
|
|
61
|
+
self.assertTrue(result["ok"])
|
|
62
|
+
self.assertEqual(result["status"], "dry_run")
|
|
63
|
+
self.assertEqual(result["backend"], "none")
|
|
64
|
+
self.assertIn("direct_workflow", result)
|
|
65
|
+
self.assertNotIn("command", result)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
unittest.main()
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from unittest.mock import patch
|
|
9
|
+
|
|
10
|
+
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
|
|
11
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
12
|
+
|
|
13
|
+
from common import ensure_ai4math_gitignore # noqa: E402
|
|
14
|
+
from numina_runtime import ( # noqa: E402
|
|
15
|
+
DEFAULT_UPSTREAM_URL,
|
|
16
|
+
build_configure_plan,
|
|
17
|
+
build_install_plan,
|
|
18
|
+
build_run_plan,
|
|
19
|
+
credential_report,
|
|
20
|
+
read_numina_env_local,
|
|
21
|
+
runtime_paths,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class NuminaRuntimePathTests(unittest.TestCase):
|
|
26
|
+
def test_runtime_paths_default_under_ai4math(self) -> None:
|
|
27
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
28
|
+
root = Path(tmp)
|
|
29
|
+
shared = root / "shared-ai4math"
|
|
30
|
+
|
|
31
|
+
with patch.dict(os.environ, {"AI4MATH_HOME": str(shared), "AI4MATH_NUMINA_HOME": ""}, clear=False):
|
|
32
|
+
paths = runtime_paths(root)
|
|
33
|
+
|
|
34
|
+
runtime = shared / "numina-runtime"
|
|
35
|
+
self.assertEqual(paths["root"], str(runtime))
|
|
36
|
+
self.assertEqual(paths["upstream"], str(runtime / "upstream"))
|
|
37
|
+
self.assertEqual(paths["results"], str(runtime / "results"))
|
|
38
|
+
self.assertEqual(paths["default_upstream_url"], DEFAULT_UPSTREAM_URL)
|
|
39
|
+
|
|
40
|
+
def test_runtime_paths_honor_ai4math_numina_home(self) -> None:
|
|
41
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
42
|
+
custom = Path(tmp) / "custom-numina"
|
|
43
|
+
with patch.dict(os.environ, {"AI4MATH_NUMINA_HOME": str(custom)}, clear=False):
|
|
44
|
+
paths = runtime_paths(Path(tmp))
|
|
45
|
+
|
|
46
|
+
expected = Path(os.path.abspath(custom))
|
|
47
|
+
self.assertEqual(paths["root"], str(expected))
|
|
48
|
+
self.assertEqual(paths["upstream"], str(expected / "upstream"))
|
|
49
|
+
|
|
50
|
+
def test_numina_runtime_is_ignored(self) -> None:
|
|
51
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
52
|
+
gitignore = ensure_ai4math_gitignore(tmp)
|
|
53
|
+
|
|
54
|
+
lines = gitignore.read_text(encoding="utf-8").splitlines()
|
|
55
|
+
|
|
56
|
+
self.assertIn("numina-runtime/", lines)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class NuminaRuntimeCredentialTests(unittest.TestCase):
|
|
60
|
+
def test_env_local_is_read_from_numina_runtime_root(self) -> None:
|
|
61
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
62
|
+
root = Path(tmp)
|
|
63
|
+
shared = root / "shared-ai4math"
|
|
64
|
+
env_path = shared / "numina-runtime" / ".env.local"
|
|
65
|
+
env_path.parent.mkdir(parents=True)
|
|
66
|
+
env_path.write_text(
|
|
67
|
+
"export ANTHROPIC_AUTH_TOKEN=secret-token\n"
|
|
68
|
+
"OPENAI_API_KEY=placeholder-openai-token\n",
|
|
69
|
+
encoding="utf-8",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
with patch.dict(os.environ, {"AI4MATH_HOME": str(shared), "AI4MATH_NUMINA_HOME": ""}, clear=False):
|
|
73
|
+
values = read_numina_env_local(root)
|
|
74
|
+
|
|
75
|
+
self.assertEqual(values["ANTHROPIC_AUTH_TOKEN"], "secret-token")
|
|
76
|
+
self.assertEqual(values["OPENAI_API_KEY"], "placeholder-openai-token")
|
|
77
|
+
|
|
78
|
+
def test_credential_report_redacts_values(self) -> None:
|
|
79
|
+
report = credential_report({
|
|
80
|
+
"ANTHROPIC_AUTH_TOKEN": "secret-token",
|
|
81
|
+
"OPENAI_API_KEY": "placeholder-openai-token",
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
self.assertTrue(report["claude"]["configured"])
|
|
85
|
+
self.assertEqual(report["claude"]["variables"]["ANTHROPIC_AUTH_TOKEN"], "<redacted>")
|
|
86
|
+
self.assertEqual(report["skill_keys"]["OPENAI_API_KEY"], "<redacted>")
|
|
87
|
+
self.assertNotIn("secret-token", str(report))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class NuminaRuntimePlanTests(unittest.TestCase):
|
|
91
|
+
def test_install_plan_clones_official_upstream_when_missing(self) -> None:
|
|
92
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
93
|
+
root = Path(tmp)
|
|
94
|
+
shared = root / "shared-ai4math"
|
|
95
|
+
with patch.dict(os.environ, {"AI4MATH_HOME": str(shared), "AI4MATH_NUMINA_HOME": ""}, clear=False):
|
|
96
|
+
plan = build_install_plan(root, dry_run=True)
|
|
97
|
+
|
|
98
|
+
self.assertTrue(plan["ok"])
|
|
99
|
+
self.assertEqual(plan["status"], "install_plan_ready")
|
|
100
|
+
self.assertEqual(plan["actions"][0]["command"][0:2], ["git", "clone"])
|
|
101
|
+
self.assertEqual(plan["actions"][0]["command"][2], DEFAULT_UPSTREAM_URL)
|
|
102
|
+
|
|
103
|
+
def test_install_plan_blocks_dirty_upstream(self) -> None:
|
|
104
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
105
|
+
root = Path(tmp)
|
|
106
|
+
shared = root / "shared-ai4math"
|
|
107
|
+
upstream = shared / "numina-runtime" / "upstream"
|
|
108
|
+
upstream.mkdir(parents=True)
|
|
109
|
+
(upstream / ".git").mkdir()
|
|
110
|
+
|
|
111
|
+
with patch.dict(os.environ, {"AI4MATH_HOME": str(shared), "AI4MATH_NUMINA_HOME": ""}, clear=False), \
|
|
112
|
+
patch("numina_runtime.run_command", return_value={
|
|
113
|
+
"ok": True,
|
|
114
|
+
"returncode": 0,
|
|
115
|
+
"stdout": " M tutorial/foo.py\n",
|
|
116
|
+
"stderr": "",
|
|
117
|
+
"command": ["git", "status", "--short"],
|
|
118
|
+
}):
|
|
119
|
+
plan = build_install_plan(root, dry_run=False)
|
|
120
|
+
|
|
121
|
+
self.assertFalse(plan["ok"])
|
|
122
|
+
self.assertEqual(plan["status"], "dirty_upstream")
|
|
123
|
+
self.assertEqual(plan["actions"], [])
|
|
124
|
+
|
|
125
|
+
def test_configure_plan_uses_official_setup_and_uv_commands(self) -> None:
|
|
126
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
127
|
+
root = Path(tmp)
|
|
128
|
+
shared = root / "shared-ai4math"
|
|
129
|
+
upstream = shared / "numina-runtime" / "upstream"
|
|
130
|
+
(upstream / ".git").mkdir(parents=True)
|
|
131
|
+
|
|
132
|
+
with patch.dict(os.environ, {"AI4MATH_HOME": str(shared), "AI4MATH_NUMINA_HOME": ""}, clear=False), \
|
|
133
|
+
patch("numina_runtime.run_command", return_value={
|
|
134
|
+
"ok": True,
|
|
135
|
+
"returncode": 0,
|
|
136
|
+
"stdout": "",
|
|
137
|
+
"stderr": "",
|
|
138
|
+
"command": ["git", "status", "--short"],
|
|
139
|
+
}):
|
|
140
|
+
plan = build_configure_plan(root, project_name="demo_project", dry_run=True)
|
|
141
|
+
|
|
142
|
+
commands = [action["command"] for action in plan["actions"]]
|
|
143
|
+
self.assertTrue(plan["ok"])
|
|
144
|
+
self.assertIn(["./setup.sh", "demo_project"], commands)
|
|
145
|
+
self.assertIn(["uv", "python", "install"], commands)
|
|
146
|
+
self.assertIn(["uv", "sync"], commands)
|
|
147
|
+
self.assertNotIn(["uv", "run", "scripts/sync_projects.py"], commands)
|
|
148
|
+
|
|
149
|
+
def test_run_plan_uses_official_runner_without_executing(self) -> None:
|
|
150
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
151
|
+
root = Path(tmp)
|
|
152
|
+
theorem = root / "Demo.lean"
|
|
153
|
+
theorem.write_text("example : True := by\n trivial\n", encoding="utf-8")
|
|
154
|
+
shared = root / "shared-ai4math"
|
|
155
|
+
upstream = shared / "numina-runtime" / "upstream"
|
|
156
|
+
upstream.mkdir(parents=True)
|
|
157
|
+
|
|
158
|
+
with patch.dict(os.environ, {"AI4MATH_HOME": str(shared), "AI4MATH_NUMINA_HOME": ""}, clear=False):
|
|
159
|
+
plan = build_run_plan(root, file=theorem, max_iters=3)
|
|
160
|
+
|
|
161
|
+
self.assertTrue(plan["ok"])
|
|
162
|
+
self.assertEqual(plan["status"], "run_plan_ready")
|
|
163
|
+
self.assertEqual(plan["command"][0:5], ["uv", "run", "python", "-m", "scripts.run_claude"])
|
|
164
|
+
self.assertIn(str(Path(os.path.abspath(theorem))), plan["command"])
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if __name__ == "__main__":
|
|
168
|
+
unittest.main()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import unittest
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
SCRIPT_DIR = Path(__file__).resolve().parents[1] / "scripts"
|
|
8
|
+
sys.path.insert(0, str(SCRIPT_DIR))
|
|
9
|
+
|
|
10
|
+
from validate_patch import review_files # noqa: E402
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
FIXTURES = Path(__file__).resolve().parent / "fixtures"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ValidatePatchTests(unittest.TestCase):
|
|
17
|
+
def test_rejects_sorry(self) -> None:
|
|
18
|
+
result = review_files(FIXTURES / "before.lean", FIXTURES / "after_bad.lean")
|
|
19
|
+
self.assertFalse(result["ok"])
|
|
20
|
+
self.assertTrue(result["forbidden_findings"])
|
|
21
|
+
|
|
22
|
+
def test_rejects_statement_change(self) -> None:
|
|
23
|
+
result = review_files(FIXTURES / "before.lean", FIXTURES / "after_statement_changed.lean")
|
|
24
|
+
self.assertFalse(result["ok"])
|
|
25
|
+
self.assertTrue(result["statement_changes"])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
unittest.main()
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lean-setup
|
|
3
|
+
description: Use when a coding agent needs to install or verify Lean 4, elan, lake, create or reuse a mathlib workspace, configure a shared Lean environment, or run Lean readiness checks before formalization.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Lean Setup
|
|
7
|
+
|
|
8
|
+
## DSH Integration Notes
|
|
9
|
+
|
|
10
|
+
- 本技能由 `@louisultra/dsh-verymath` 插件提供;共享支撑层位于
|
|
11
|
+
`../lean-formalization/lean-runtime/`(DSH 捆绑布局;上游为兄弟目录 lean-runtime/)。
|
|
12
|
+
- 先调 `verymath_lean_check` 拿两级 readiness(leanCoreReady / mathlibReady / partial);
|
|
13
|
+
缺失组件的安装提示原样告知用户,**绝不自动安装**(安装必须用户批准)。
|
|
14
|
+
- 工具链版本从项目的 `lean-toolchain` 文件读取;不要对 `.elan/bin` 下的 shim 跑 `--version`。
|
|
15
|
+
|
|
16
|
+
Use this setup-only entrypoint when the user only wants a Lean 4 environment, `elan`/`lake` readiness, or a reusable mathlib workspace. Do not ask for a theorem target in setup-only mode.
|
|
17
|
+
|
|
18
|
+
The shared implementation lives in `../lean-formalization/lean-runtime/`. This skill must reuse the same helper CLI, configuration rules, and runtime references rather than duplicating setup logic or depending on the formalization entrypoint.
|
|
19
|
+
|
|
20
|
+
## Setup-Only Flow
|
|
21
|
+
|
|
22
|
+
1. Match the user's language by default; if ambiguous, default to Chinese.
|
|
23
|
+
2. Inspect tool and workspace readiness with `doctor` or `env`.
|
|
24
|
+
3. If `elan`, `lean`, or `lake` is missing, explain the required Lean installation step first. Install Lean through the official `elan` channel appropriate for the user's OS after approval; `lean` and `lake` should come from the `elan` toolchain rather than a repository-local copy.
|
|
25
|
+
4. Prefer an existing Lake project when the user points to one.
|
|
26
|
+
5. When creating an isolated test directory or workspace, suggest a safe default name and let the user confirm or rename it; use the default if the user has no naming preference.
|
|
27
|
+
6. For standalone future Lean work, create or reuse the canonical managed workspace `${AI4MATH_HOME:-~/.ai4math}/lean-workspace` with the AI4Math managed baseline toolchain `leanprover/lean4:v4.28.0`.
|
|
28
|
+
7. Create the workspace only after explaining that Lean/mathlib artifacts may be downloaded or built. If the canonical workspace already exists and is complete, reuse it instead of rebuilding or downloading again.
|
|
29
|
+
8. Run the bundled smoke test after setup.
|
|
30
|
+
9. Report the installed tools, workspace path, Lean toolchain, mathlib revision when available, smoke-test result, and any remaining action. Distinguish Lean core ready from mathlib ready.
|
|
31
|
+
10. If Lean toolchain and pure Lean smoke tests pass but `lake update`, `lake exe cache get`, `lake build`, or `import Mathlib` is blocked by GitHub/network/cache failure, report partial readiness instead of total failure or full success.
|
|
32
|
+
11. After successful setup or smoke-test validation, do not end passively. Offer a short next-step menu and recommend one default next action.
|
|
33
|
+
12. Include an optional cross-platform IDE frontend path in that menu: identify the user's OS when needed, then guide them to install or verify VS Code with the Lean 4 extension on macOS, Windows, or Linux, open the verified Lake project or shared workspace, open a known passing `.lean` file, and confirm Lean InfoView is connected to the same toolchain that passed local validation.
|
|
34
|
+
13. If the user next wants formalization, proof repair, theorem transcription, `sorry` completion, patch review, or Numina proof search, hand off to `lean-formalization`.
|
|
35
|
+
|
|
36
|
+
## Readiness Levels
|
|
37
|
+
|
|
38
|
+
Report setup status in two layers:
|
|
39
|
+
|
|
40
|
+
- Lean core ready: `lean --version`, `lake --version`, and a pure Lean smoke theorem pass.
|
|
41
|
+
- mathlib ready: the workspace can run `lake update`, `lake exe cache get`, `lake build`, and a file with `import Mathlib`.
|
|
42
|
+
|
|
43
|
+
If Lean core ready passes but mathlib ready fails because GitHub, proxy, or cache download is unavailable, call it partial readiness. `import Mathlib` tasks are blocked, but pure `.lean` files and basic Lean compilation can still be verified. Do not present this as full mathlib workspace readiness. Do not recommend formalization, `sorry` completion, or Numina as the default next step while mathlib is missing. The default next step should be to diagnose Git/mathlib access or continue only with pure Lean smoke validation.
|
|
44
|
+
|
|
45
|
+
For Windows mathlib clone/cache failures, use copyable recovery commands such as:
|
|
46
|
+
|
|
47
|
+
```powershell
|
|
48
|
+
git ls-remote https://github.com/leanprover-community/mathlib4.git HEAD
|
|
49
|
+
Remove-Item -Recurse -Force .lake\packages\mathlib
|
|
50
|
+
lake update
|
|
51
|
+
lake exe cache get
|
|
52
|
+
lake build
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
If `git ls-remote` fails, diagnose Git proxy/network inheritance before rerunning Lake. If it succeeds but Lake reports that `.lake\packages\mathlib` cannot resolve `HEAD`, remove that corrupted package directory and rerun `lake update`.
|
|
56
|
+
|
|
57
|
+
## Post-Setup Guidance
|
|
58
|
+
|
|
59
|
+
Offer a short next-step menu after setup succeeds:
|
|
60
|
+
|
|
61
|
+
- inspect an existing Lean/Lake project;
|
|
62
|
+
- run or explain the built-in smoke theorem result;
|
|
63
|
+
- configure the VS Code / Lean 4 extension frontend for the verified project on macOS, Windows, or Linux, and confirm Lean InfoView works;
|
|
64
|
+
- repair a Lean file or complete `sorry`;
|
|
65
|
+
- formalize a natural-language or LaTeX theorem;
|
|
66
|
+
- continue setup-only validation if the user only wants environment readiness.
|
|
67
|
+
|
|
68
|
+
If only partial readiness is available, limit the default menu to Git/mathlib recovery, pure Lean smoke validation, or IDE frontend verification for the same pure Lean file. Do not offer Mathlib-dependent proof work as ready.
|
|
69
|
+
|
|
70
|
+
As a rule, mention optional Numina only when the user explicitly asks for the official Lean Agent, batch proof search, or an external backend adapter; do not make Numina or API keys part of the default next step.
|
|
71
|
+
|
|
72
|
+
## Commands
|
|
73
|
+
|
|
74
|
+
Resolve the helper from the shared runtime path `../lean-formalization/lean-runtime/scripts/ai4m_lean.py`, then run it with `--cwd <target-project-or-workspace>`. In a source checkout this is the same helper under `skills/lean-runtime/scripts/ai4m_lean.py`.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
python ../lean-formalization/lean-runtime/scripts/ai4m_lean.py doctor --cwd <target-project-or-workspace>
|
|
78
|
+
python ../lean-formalization/lean-runtime/scripts/ai4m_lean.py env --cwd <target-project-or-workspace>
|
|
79
|
+
python ../lean-formalization/lean-runtime/scripts/ai4m_lean.py configure --cwd <target-project-or-workspace> --create-workspace
|
|
80
|
+
python ../lean-formalization/lean-runtime/scripts/ai4m_lean.py smoke-test --cwd <target-project-or-workspace>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use `--dry-run` before setup when the user wants to review commands.
|
|
84
|
+
|
|
85
|
+
## Boundaries
|
|
86
|
+
|
|
87
|
+
- Do not create a second setup implementation.
|
|
88
|
+
- Do not change a user project's `lean-toolchain` or mathlib revision without approval.
|
|
89
|
+
- Do not overwrite the canonical managed workspace for a different Lean/mathlib revision. Use `${AI4MATH_HOME:-~/.ai4math}/lean-workspaces/<version-key>/` only when the user explicitly needs a different standalone version.
|
|
90
|
+
- Do not require API keys for Lean/mathlib workspace setup.
|
|
91
|
+
- Do not require VS Code, Lean InfoView, or any IDE frontend for headless setup validation; offer it as a recommended human-facing follow-up after Lean/Lake readiness is confirmed.
|
|
92
|
+
- Do not configure or call official Numina unless the user explicitly asks for that optional backend.
|
|
93
|
+
- Do not commit machine-specific paths, downloaded runtime state, or secrets.
|
|
94
|
+
|
|
95
|
+
## References
|
|
96
|
+
|
|
97
|
+
- Read `../lean-formalization/lean-runtime/references/lean_runtime_configuration.md` for shared workspace layout, local configuration, and version policy.
|
|
98
|
+
- Read `../lean-formalization/lean-runtime/references/numina_runtime.md` only when the user asks for optional official Numina setup.
|
|
99
|
+
- Use `../lean-formalization/lean-runtime/scripts/ai4m_lean.py verify-delivery --cwd . --run-tests` for package validation.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!-- 作者:李爽夕 -->
|
|
2
|
+
|
|
3
|
+
# 最小二乘拟合
|
|
4
|
+
|
|
5
|
+
## 简介
|
|
6
|
+
|
|
7
|
+
对数据做**最小二乘回归与曲线拟合**,找到最佳参数使残差平方和最小。
|
|
8
|
+
|
|
9
|
+
$$
|
|
10
|
+
\min_{\theta} \sum_i (y_i - f(x_i; \theta))^2
|
|
11
|
+
$$
|
|
12
|
+
|
|
13
|
+
## 适用场景
|
|
14
|
+
|
|
15
|
+
- 线性回归、多项式拟合
|
|
16
|
+
- 自定义非线性函数拟合(指数、对数、有理函数等)
|
|
17
|
+
- 加权最小二乘(异方差数据)
|
|
18
|
+
- 正则化回归(Ridge/Lasso 防过拟合)
|
|
19
|
+
- 带约束拟合(参数有物理限制)
|
|
20
|
+
- MCMC 贝叶斯参数估计
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
23
|
+
|
|
24
|
+
直接向 AI 提供数据点,例如:
|
|
25
|
+
|
|
26
|
+
> "对 x=[1,2,3,4,5], y=[1.2,2.1,2.9,4.0,5.1] 做线性拟合"
|
|
27
|
+
|
|
28
|
+
或指定模型:
|
|
29
|
+
> "用 y = a*exp(-b*x) + c 拟合以下数据..."
|
|
30
|
+
|
|
31
|
+
## 环境
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install numpy scipy matplotlib # 必装
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
支持 **10 种工具**:scipy.curve_fit、numpy.linalg.lstsq、scikit-learn、lmfit、cvxpy、iminuit、nlopt、jaxopt、emcee、statsmodels。无任何工具时自动从 GitHub 搜索开源代码。
|
|
38
|
+
|
|
39
|
+
## 输出格式
|
|
40
|
+
|
|
41
|
+
AI 回答包含:**环境与依赖**(工具选择及原因)→ **问题重述** → **拟合方法**(模型类型/求解器) → **拟合结果**(参数及误差) → **拟合质量**(R²/RSS/RMSE) → **诊断信息**(条件数/耗时)
|
|
42
|
+
|
|
43
|
+
## 示例
|
|
44
|
+
|
|
45
|
+
详见 [examples.md](examples.md),含 8 个完整示例(线性、多项式、指数衰减、Ridge、加权、非线性、Lasso、有理函数拟合)。
|
|
46
|
+
|
|
47
|
+
## 基准测试
|
|
48
|
+
|
|
49
|
+
基于 NIST StRD 学术测试集(选取 7 个代表性数据集,覆盖不同难度和模型类型),对本 skill 进行验证。
|
|
50
|
+
|
|
51
|
+
| 指标 | 数值 |
|
|
52
|
+
|------|------|
|
|
53
|
+
| 测试集 | [NIST StRD](https://itl.nist.gov/div898/strd/) |
|
|
54
|
+
| 通过率 | **100.0%** (7/7) |
|
|
55
|
+
| 平均求解时间 | 0.003 s |
|
|
56
|
+
| 求解器 | scipy.optimize.curve_fit(经环境检测 → 优先级选择自动选定) |
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
### Direct vs Skill 求解对比
|
|
61
|
+
|
|
62
|
+
同一测试集(7 个 NIST StRD 数据集)上,对比**直接调用求解器 API** 和 **经由 skill 工作流求解**:
|
|
63
|
+
|
|
64
|
+
| 指标 | 直接求解 | Skill 求解 |
|
|
65
|
+
|------|---------|-----------|
|
|
66
|
+
| 通过率 | 100.0% (7/7) | 100.0% (7/7) |
|
|
67
|
+
| 平均求解时间 | 0.003 s | 0.003 s |
|
|
68
|
+
| 状态一致性 | — | 100.0% |
|
|
69
|
+
| 时间比 (skill/direct) | — | 1.00x |
|
|
70
|
+
| Skill 额外开销 | — | ~0 s(同一工具,无额外开销) |
|
|
71
|
+
| 选用工具 | scipy.curve_fit | scipy(经优先级链选定) |
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
> Skill 工作流(环境检测 → 工具选择 → 模型识别 → 拟合 → R²/RMSE 评估)的通过率和 direct 模式完全一致,开销在测量噪声范围内。
|
|
76
|
+
|
|
77
|
+
## 边界
|
|
78
|
+
|
|
79
|
+
- 能求解:线性和自定义非线性最小二乘(≤ 10^5 样本,≤ 1000 特征)
|
|
80
|
+
- 不能:非高斯误差模型、自动模型选择、大规模在线学习
|
|
81
|
+
|
|
82
|
+
## 数据引用
|
|
83
|
+
|
|
84
|
+
部分示例数据来自 [NIST StRD](https://itl.nist.gov/div898/strd/nls/nls_main.shtml)。美国政府公共领域数据,可自由使用,需注明来源。
|
|
85
|
+
|