diff --git a/docs/web-workbench.md b/docs/web-workbench.md index 894af170..ef096f6d 100644 --- a/docs/web-workbench.md +++ b/docs/web-workbench.md @@ -371,7 +371,7 @@ bun run build:web bun run build bun run test:web-task-source bun run test:web-knowledge-context -bun run frontend -- bun scripts/e2e/test-web-round8-approval.ts +bun run frontend -- bun scripts/e2e/test-web-project-route-approval.ts bun run test:web-guidance-recovery bun run test:web-research-progress bun run test:web-mathematical-changes @@ -444,7 +444,7 @@ bun run frontend -- bun scripts/e2e/test-web-runtime.ts `test:web-live-sync` 使用真实本地 HTTP 服务、可控 runner、Chromium 和浏览器原生 EventSource,验证连续变化合并、旧读取期间的新通知、双标签页更新与取消、SSE 不可用时的轮询、连接中断后的自动重连、页面隐藏与恢复,以及迟到的创建响应不覆盖新状态,共 7 个场景。同时检查草稿、焦点和滚动保留及写入不重放;报告写入 `out/web-live-sync/report.json`。`tests/webRunStream.test.ts` 覆盖通知鉴权、会话隔离、版本与 ETag 一致、删除、心跳、退订、过期和服务关闭。两者均不调用模型、Docker 或 Lean。 -`test:web-task-source` 验证同任务真实 Git 快照的源码比较、同版本不同 commit、身份绑定、轮询与迟到请求隔离,以及手机布局和大差异降级。`test:web-knowledge-context` 验证检索传入真实任务与环境、保留跨问题材料、环境匹配、版本化引用及切换后的请求隔离。`test-web-round8-approval.ts` 验证原生团队的项目审批在路线修订期间暂停,旧审批请求及回执仍可核对,批准新版本需要再次确认。它们均使用本地 HTTP 与 Chromium,报告分别写入 `out/web-task-source/`、`out/web-knowledge-context/`、`out/frontend-round8/approval/`。 +`test:web-task-source` 验证同任务真实 Git 快照的源码比较、同版本不同 commit、身份绑定、轮询与迟到请求隔离,以及手机布局和大差异降级。`test:web-knowledge-context` 验证检索传入真实任务与环境、保留跨问题材料、环境匹配、版本化引用及切换后的请求隔离。`test-web-project-route-approval.ts` 验证原生团队的项目审批在路线修订期间暂停,旧审批请求及回执仍可核对,批准新版本需要再次确认。它们均使用本地 HTTP 与 Chromium,报告分别写入 `out/web-task-source/`、`out/web-knowledge-context/`、`out/web-project-route-approval/`。 `test:web-guidance-recovery` 使用真实本地 HTTP 与 Chromium,覆盖指导的 unknown 到已投递或失败、丢失响应、原快照重试、读取失败不重发、任务版本人工确认、失效目标、同文字更换接收方、跨研究迟到回执及 320 / 375 像素布局,共 12 个场景。报告与截图写入 `out/web-guidance-recovery/`;worker 桥的明确拒绝、原 ID 幂等核对和未知存储错误另由 `tests/webWorkerBridge.test.ts` 覆盖。不调用模型或重新执行 Lean。 diff --git a/frontend-revision b/frontend-revision index d14f9007..174caae3 100644 --- a/frontend-revision +++ b/frontend-revision @@ -1 +1 @@ -36410a555b2e0df099123566b4b35c6161e37f81 +3b23c5e420387e10377e39d8424f09134e93492d diff --git a/package.json b/package.json index 34f1266d..1c64e7f5 100644 --- a/package.json +++ b/package.json @@ -33,15 +33,15 @@ "build:web-preview": "bun scripts/frontend.ts preview", "test:web-review-regressions": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-review-regressions.ts'", "test:frontend-audit": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-audit-workbench.ts && bun scripts/e2e/test-web-audit-library.ts && bun scripts/e2e/test-frontend-audit-layout.ts'", - "test:frontend-round2": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round2-collaboration.ts && bun scripts/e2e/test-web-round2-workbench.ts && bun scripts/e2e/test-web-round2-routes.ts && bun scripts/e2e/test-web-round2-login.ts'", + "test:frontend-round2": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round2-collaboration.ts && bun scripts/e2e/test-web-round2-workbench.ts && bun scripts/e2e/test-web-round2-routes.ts && bun scripts/e2e/test-web-login-recovery.ts'", "test:frontend-round3": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round3-approval.ts && bun scripts/e2e/test-web-round3-collaboration.ts && bun scripts/e2e/test-web-round3-library.ts && bun scripts/e2e/test-web-round3-routes.ts && bun scripts/e2e/test-web-round3-workbench.ts'", "test:frontend-round4": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round4-sharing.ts && bun scripts/e2e/test-web-round4-library.ts'", - "test:frontend-round5": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round5-workbench.ts && bun scripts/e2e/test-web-round5-collaboration.ts && bun scripts/e2e/test-web-round5-people.ts && bun scripts/e2e/test-web-round5-library.ts'", + "test:frontend-round5": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round5-workbench.ts && bun scripts/e2e/test-web-round5-collaboration.ts && bun scripts/e2e/test-web-round5-people.ts && bun scripts/e2e/test-web-library-write-recovery.ts'", "test:frontend-round6": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round6-people.ts && bun scripts/e2e/test-web-round6-collaboration.ts && bun scripts/e2e/test-web-round6-library.ts && bun scripts/e2e/test-web-round6-routes.ts'", - "test:frontend-round7": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round7-session.ts && bun scripts/e2e/test-web-round7-people.ts && bun scripts/e2e/test-web-round7-library.ts && bun scripts/e2e/test-web-round7-routes.ts'", - "test:frontend-round8": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round8-budget.ts && bun scripts/e2e/test-web-round8-keys.ts && bun scripts/e2e/test-web-round8-approval.ts && bun scripts/e2e/test-web-round8-routes.ts'", - "test:frontend-round9": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round9-availability.ts && bun scripts/e2e/test-web-round9-mobile.ts && bun scripts/e2e/test-web-round9-routes.ts'", - "test:frontend-round10": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round10-workbench.ts && bun scripts/e2e/test-web-round10-math.ts && bun scripts/e2e/test-web-round10-routes.ts'", + "test:frontend-round7": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-session-renewal.ts && bun scripts/e2e/test-web-round7-people.ts && bun scripts/e2e/test-web-library-draft-reload.ts && bun scripts/e2e/test-web-round7-routes.ts'", + "test:frontend-round8": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round8-budget.ts && bun scripts/e2e/test-web-round8-keys.ts && bun scripts/e2e/test-web-project-route-approval.ts && bun scripts/e2e/test-web-round8-routes.ts'", + "test:frontend-round9": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round9-availability.ts && bun scripts/e2e/test-web-round9-mobile.ts && bun scripts/e2e/test-web-route-search-ime.ts'", + "test:frontend-round10": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-round10-workbench.ts && bun scripts/e2e/test-web-round10-math.ts && bun scripts/e2e/test-web-archive-source-links.ts'", "test:web-ui": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-ui.ts'", "test:web-product-flow": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-product-flow.ts'", "test:web-login": "bun scripts/frontend.ts run bash -c 'bun scripts/e2e/test-web-login.ts'", diff --git a/scripts/mathematics/benchmarkTheoremSearch.ts b/scripts/mathematics/benchmarkTheoremSearch.ts deleted file mode 100644 index e76ad036..00000000 --- a/scripts/mathematics/benchmarkTheoremSearch.ts +++ /dev/null @@ -1,640 +0,0 @@ -#!/usr/bin/env bun -import { parseArgs } from 'node:util'; -import { searchMathRetrievalCorpusBatch } from '../../src/math/mathRetrievalCorpus'; -import { mathDigest, readMathText } from '../../src/math/mathRuntimeIo'; - -type Declaration = { qualifiedName: string; sourceModule: string }; -type QueryCase = { - group: 'zh' | 'en' | 'ranking' | 'control' | 'negative' | 'generatedName' | 'leanReference'; - query: string; - expected?: Declaration; -}; -type GoalCase = { - group: - 'goal' | 'algebraGoal' | 'generatedGoal' | 'orderGoal' | 'specializedGoal' | 'specializedPremise' | 'symmetricGoal'; - goal: string; - expected?: Declaration; -}; -type SearchResult = ReturnType['queries'][number]; - -// These paraphrases exercise a small set of concepts on the pinned Mathlib release. -const concepts = [ - [ - 'isClosed_closure', - 'Mathlib.Topology.Closure', - '一个集合取闭包之后得到的是闭集', - 'taking the closure of a set produces a closed set', - ], - [ - 'IsCompact.isClosed', - 'Mathlib.Topology.Separation.Hausdorff', - '豪斯多夫空间里的紧子集一定是闭集', - 'every compact subset of a Hausdorff space is closed', - ], - [ - 'IsCompact.image', - 'Mathlib.Topology.Compactness.Compact', - '连续映射把紧集变成紧集', - 'the image of a compact set under a continuous map is compact', - ], - [ - 'Matrix.det_mul', - 'Mathlib.LinearAlgebra.Matrix.Determinant.Basic', - '两个方阵相乘后的行列式等于各自行列式相乘', - 'the determinant of a matrix product equals the product of the determinants', - ], - [ - 'Finset.card_union_add_card_inter', - 'Mathlib.Data.Finset.Card', - '有限集的并集与交集的基数相加等于两集合的基数之和', - 'for two finite sets the cardinality of the union plus that of the intersection equals the sum of their cardinalities', - ], - [ - 'Finset.card_inter_add_card_union', - 'Mathlib.Data.Finset.Card', - '有限集的交集与并集的基数相加等于两集合的基数之和', - 'for two finite sets the cardinality of the intersection plus that of the union equals the sum of their cardinalities', - ], - [ - 'MeasureTheory.integral_add', - 'Mathlib.MeasureTheory.Integral.Bochner.Basic', - '两个可积函数的和的积分等于它们各自的积分相加', - 'the integral of the sum of two integrable functions is the sum of their integrals', - ], - [ - 'Int.gcd_eq_gcd_ab', - 'Mathlib.Data.Int.GCD', - '两个整数的最大公约数可以表示成它们的整数线性组合', - 'the gcd of two integers is an integer linear combination of those integers', - ], - [ - 'norm_inner_le_norm', - 'Mathlib.Analysis.InnerProductSpace.Basic', - '两个向量内积的绝对值不超过它们范数的乘积', - 'Cauchy Schwarz inequality for inner products', - ], - [ - 'MeasureTheory.measure_union_le', - 'Mathlib.MeasureTheory.OuterMeasure.Basic', - '可测集合的并的测度小于等于各自测度之和', - 'the measure of a union is at most the sum of the measures', - ], - [ - 'Continuous.comp', - 'Mathlib.Topology.Continuous', - '两个连续函数复合后仍然是连续的', - 'the composition of two continuous functions is continuous', - ], -] as const; - -export const theoremSearchCases: readonly QueryCase[] = [ - ...[ - ['_root_.Set.mem_union', 'Set.mem_union', 'Mathlib.Data.Set.Basic'], - ['_root_.Matrix.det_mul', 'Matrix.det_mul', 'Mathlib.LinearAlgebra.Matrix.Determinant.Basic'], - ['_root_.norm_add_le', 'norm_add_le', 'Mathlib.Analysis.Normed.Group.Basic'], - ["_root_.Real.sqrt_mul'", "Real.sqrt_mul'", 'Mathlib.Analysis.Real.Sqrt'], - ['#check Real.exp_log', 'Real.exp_log', 'Mathlib.Analysis.SpecialFunctions.Log.Basic'], - ['#check @Set.inter_union_distrib_left', 'Set.inter_union_distrib_left', 'Mathlib.Data.Set.Basic'], - ['@Finset.sum_add_distrib', 'Finset.sum_add_distrib', 'Mathlib.Algebra.BigOperators.Group.Finset.Basic'], - ["Real.sqrt_mul'", "Real.sqrt_mul'", 'Mathlib.Analysis.Real.Sqrt'], - ].map(([query, qualifiedName, sourceModule]): QueryCase => ({ - group: 'leanReference', - query, - expected: { qualifiedName, sourceModule }, - })), - ...concepts.flatMap(([qualifiedName, sourceModule, zh, en]): QueryCase[] => { - const expected = { qualifiedName, sourceModule }; - return [ - { group: 'zh', query: zh, expected }, - { group: 'en', query: en, expected }, - ]; - }), - ...[ - [ - 'the closure of a set equals the set if and only if the set is closed', - 'closure_eq_iff_isClosed', - 'Mathlib.Topology.Closure', - ], - ['转置矩阵的行列式等于原矩阵的行列式', 'Matrix.det_transpose', 'Mathlib.LinearAlgebra.Matrix.Determinant.Basic'], - ['两个有限集的交集包含于第一个有限集', 'Finset.inter_subset_left', 'Mathlib.Data.Finset.Lattice.Basic'], - ['两个有限集的交集包含于第二个有限集', 'Finset.inter_subset_right', 'Mathlib.Data.Finset.Lattice.Basic'], - [ - 'the first finite set is a subset of the union of the two finite sets', - 'Finset.subset_union_left', - 'Mathlib.Data.Finset.Lattice.Basic', - ], - [ - 'the second finite set is a subset of the union of the two finite sets', - 'Finset.subset_union_right', - 'Mathlib.Data.Finset.Lattice.Basic', - ], - ['the intersection of two sets is contained in the second set', 'Set.inter_subset_right', 'Mathlib.Data.Set.Basic'], - ['第一个集合包含于两个集合的并集', 'Set.subset_union_left', 'Mathlib.Data.Set.Basic'], - [ - '两个可积函数的差的积分等于各自积分的差', - 'MeasureTheory.integral_sub', - 'Mathlib.MeasureTheory.Integral.Bochner.Basic', - ], - [ - 'if two integrable functions are ordered almost everywhere then their integrals are ordered', - 'MeasureTheory.integral_mono_ae', - 'Mathlib.MeasureTheory.Integral.Bochner.Basic', - ], - [ - '两个函数几乎处处相等时它们的积分相等', - 'MeasureTheory.integral_congr_ae', - 'Mathlib.MeasureTheory.Integral.Bochner.Basic', - ], - [ - 'the cardinality of a finite subset is at most the cardinality of the containing finite set', - 'Finset.card_le_card', - 'Mathlib.Data.Finset.Card', - ], - ].map(([query, qualifiedName, sourceModule]): QueryCase => ({ - group: 'ranking', - query, - expected: { qualifiedName, sourceModule }, - })), - { - group: 'control', - query: 'Matrix.det_mul', - expected: { qualifiedName: 'Matrix.det_mul', sourceModule: 'Mathlib.LinearAlgebra.Matrix.Determinant.Basic' }, - }, - { - group: 'control', - query: '凯莱–哈密顿定理', - expected: { - qualifiedName: 'Matrix.aeval_self_charpoly', - sourceModule: 'Mathlib.LinearAlgebra.Matrix.Charpoly.Basic', - }, - }, - { - group: 'control', - query: 'the square root of two is irrational', - expected: { qualifiedName: 'irrational_sqrt_two', sourceModule: 'Mathlib.NumberTheory.Real.Irrational' }, - }, - { group: 'negative', query: 'the difference of two convex functions is necessarily convex' }, - { group: 'negative', query: '连续函数的复合一定有界' }, -]; - -export const theoremSearchGoalCases: readonly GoalCase[] = [ - ...[ - ['a b : Set α\n⊢ (a ∪ b) = (b ∪ a)', 'Set.union_comm', 'Mathlib.Data.Set.Basic'], - ['a b : Set α\n⊢ (a ∩ b) = b ∩ a', 'Set.inter_comm', 'Mathlib.Data.Set.Basic'], - ['a b : Set α\n⊢ (a ∩ b) ⊆ (a)', 'Set.inter_subset_left', 'Mathlib.Data.Set.Basic'], - ['a b : Set α\n⊢ (b) ⊆ (a ∪ b)', 'Set.subset_union_right', 'Mathlib.Data.Set.Basic'], - ['x y : ℝ\n⊢ (|x * y|) = (|x| * |y|)', 'abs_mul', 'Mathlib.Algebra.Order.Ring.Abs'], - ['x y : ℝ\n⊢ |x * y| = |x| * |y|', 'abs_mul', 'Mathlib.Algebra.Order.Ring.Abs'], - ['x y : ℝ\n⊢ abs (x * y) = abs x * abs y', 'abs_mul', 'Mathlib.Algebra.Order.Ring.Abs'], - ['x y : ℝ\n⊢ abs (x / y) = |x| / |y|', 'abs_div', 'Mathlib.Algebra.Order.Field.Basic'], - ['x y : ℝ\n⊢ abs (x ^ 2) = x ^ 2', 'abs_sq', 'Mathlib.Algebra.Order.Ring.Abs'], - ['x y : ℝ\n⊢ |x| * |y| = abs (x * y)', 'abs_mul', 'Mathlib.Algebra.Order.Ring.Abs'], - ['x : ℝ\n⊢ (Real.log ∘ Real.exp) x = x', 'Real.log_exp', 'Mathlib.Analysis.SpecialFunctions.Log.Basic'], - ['x : ℝ\nh : 0 < x\n⊢ (Real.exp ∘ Real.log) x = x', 'Real.exp_log', 'Mathlib.Analysis.SpecialFunctions.Log.Basic'], - [ - 'x : ℝ\n⊢ (Real.tan ∘ Real.arctan) x = x', - 'Real.tan_arctan', - 'Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan', - ], - [ - 'x : ℝ\nh₁ : -1 ≤ x\nh₂ : x ≤ 1\n⊢ (Real.sin ∘ Real.arcsin) x = x', - 'Real.sin_arcsin', - 'Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse', - ], - ['x : ℝ\n⊢ (Real.sinh ∘ Real.arsinh) x = x', 'Real.sinh_arsinh', 'Mathlib.Analysis.SpecialFunctions.Arsinh'], - [ - 'x y : ℝ\nh : 0 < x + y\n⊢ x + y = (Real.exp ∘ Real.log) (x + y)', - 'Real.exp_log', - 'Mathlib.Analysis.SpecialFunctions.Log.Basic', - ], - [ - "α β : Type\nφ : α → β\np q : Set β\n⊢ φ ⁻¹' (p ∪ q) = φ ⁻¹' p ∪ φ ⁻¹' q", - 'Set.preimage_union', - 'Mathlib.Data.Set.Image', - ], - [ - 'α β : Type\nφ : α → β\np q : Set β\n⊢ Set.preimage φ (p ∪ q) = Set.preimage φ p ∪ Set.preimage φ q', - 'Set.preimage_union', - 'Mathlib.Data.Set.Image', - ], - [ - 'α β : Type\nφ : α → β\np q : Set β\n⊢ Set.preimage φ (p ∩ q) = Set.preimage φ p ∩ Set.preimage φ q', - 'Set.preimage_inter', - 'Mathlib.Data.Set.Image', - ], - ['α β : Type\nφ : α → β\n⊢ Set.preimage φ ∅ = ∅', 'Set.preimage_empty', 'Mathlib.Data.Set.Image'], - [ - 'α β : Type\nφ : α → β\ns t : Set α\n⊢ Set.image φ (s ∪ t) = Set.image φ s ∪ Set.image φ t', - 'Set.image_union', - 'Mathlib.Data.Set.Image', - ], - [ - "α β : Type\nφ : α → β\ns t : Set α\n⊢ Set.image φ (s ∩ t) ⊆ φ '' s ∩ φ '' t", - 'Set.image_inter_subset', - 'Mathlib.Data.Set.Image', - ], - [ - 'α β : Type\nφ : α → β\ns : Set α\nt : Set β\n⊢ Set.image φ s ⊆ t ↔ s ⊆ Set.preimage φ t', - 'Set.image_subset_iff', - 'Mathlib.Data.Set.Image', - ], - ["α β : Type\nφ : α → β\n⊢ φ '' ∅ = ∅", 'Set.image_empty', 'Mathlib.Data.Set.Image'], - ['α : Type u\nA B : Set α\nx : α\n⊢ x ∈ Aᶜ ↔ x ∉ A', 'Set.mem_compl_iff', 'Mathlib.Data.Set.Operations'], - ['α : Type u\nA B : Set α\nx : α\n⊢ (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ', 'Set.compl_union', 'Mathlib.Order.BooleanAlgebra.Set'], - ['α : Type u\nA B : Set α\nx : α\n⊢ (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ', 'Set.compl_inter', 'Mathlib.Order.BooleanAlgebra.Set'], - ['α : Type u\nA B : Set α\nx : α\n⊢ Aᶜ ⊆ Bᶜ ↔ B ⊆ A', 'Set.compl_subset_compl', 'Mathlib.Order.BooleanAlgebra.Set'], - [ - 'α : Type u\ninst : Fintype α\ninst₂ : DecidableEq α\nA B : Finset α\nx : α\n⊢ x ∈ Aᶜ ↔ x ∉ A', - 'Finset.mem_compl', - 'Mathlib.Data.Finset.BooleanAlgebra', - ], - [ - 'α : Type u\ninst : Fintype α\ninst₂ : DecidableEq α\nA B : Finset α\nx : α\n⊢ (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ', - 'Finset.compl_union', - 'Mathlib.Data.Finset.BooleanAlgebra', - ], - [ - 'α : Type u\ninst : Fintype α\ninst₂ : DecidableEq α\nA B : Finset α\nx : α\n⊢ (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ', - 'Finset.compl_inter', - 'Mathlib.Data.Finset.BooleanAlgebra', - ], - [ - 'α : Type u\ninst : Fintype α\ninst₂ : DecidableEq α\nA B : Finset α\nx : α\n⊢ Aᶜ ⊆ Bᶜ ↔ B ⊆ A', - 'Finset.compl_subset_compl', - 'Mathlib.Data.Finset.BooleanAlgebra', - ], - ['α : Type u\nx : α\nu v : Set α\n⊢ x ∈ u \\ v ↔ x ∈ u ∧ x ∉ v', 'Set.mem_sdiff', 'Mathlib.Data.Set.Operations'], - ['α : Type u\nx : α\nu v : Set α\n⊢ u \\ u = ∅', 'Set.sdiff_self', 'Mathlib.Order.BooleanAlgebra.Set'], - ['α : Type u\nx : α\nu v : Set α\n⊢ u \\ ∅ = u', 'Set.sdiff_empty', 'Mathlib.Order.BooleanAlgebra.Set'], - [ - 'α : Type u\ninst : DecidableEq α\nx : α\nu v : Finset α\n⊢ x ∈ u \\ v ↔ x ∈ u ∧ x ∉ v', - 'Finset.mem_sdiff', - 'Mathlib.Data.Finset.SDiff', - ], - [ - 'α : Type u\ninst : DecidableEq α\nx : α\nu v : Finset α\n⊢ u \\ u = ∅', - 'Finset.sdiff_self', - 'Mathlib.Data.Finset.SDiff', - ], - [ - 'α : Type u\ninst : DecidableEq α\nx : α\nu v : Finset α\n⊢ u \\ ∅ = u', - 'Finset.sdiff_empty', - 'Mathlib.Data.Finset.SDiff', - ], - [ - 'α : Type u\ninst : MeasurableSpace α\ns t : Set α\nμ : MeasureTheory.Measure α\n⊢ μ (s ∪ t) ≤ μ s + μ t', - 'MeasureTheory.measure_union_le', - 'Mathlib.MeasureTheory.OuterMeasure.Basic', - ], - [ - 'E : Type u\ninst : SeminormedAddCommGroup E\ninst_1 : InnerProductSpace ℝ E\nx y : E\n⊢ ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖', - 'norm_inner_le_norm', - 'Mathlib.Analysis.InnerProductSpace.Basic', - ], - ['a b : Set α\n⊢ a ∪ b = b ∪ a', 'Set.union_comm', 'Mathlib.Data.Set.Basic'], - ['s t u : Set α\n⊢ s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u)', 'Set.inter_union_distrib_left', 'Mathlib.Data.Set.Basic'], - ['a b c : ℕ\nhb : a ∣ b\nhc : a ∣ c\n⊢ a ∣ b + c', 'dvd_add', 'Mathlib.Algebra.Ring.Divisibility.Basic'], - [ - 'f g : α → G\nμ : MeasureTheory.Measure α\nhf : MeasureTheory.Integrable f μ\nhg : MeasureTheory.Integrable g μ\n' + - '⊢ ∫ x, f x + g x ∂μ = ∫ y, f y ∂μ + ∫ z, g z ∂μ', - 'MeasureTheory.integral_add', - 'Mathlib.MeasureTheory.Integral.Bochner.Basic', - ], - ['x : ℝ\n⊢ 0 ≤ Real.sqrt x', 'Real.sqrt_nonneg', 'Mathlib.Analysis.Real.Sqrt'], - [ - 'M : Matrix n n R\n⊢ Polynomial.aeval M M.charpoly = 0', - 'Matrix.aeval_self_charpoly', - 'Mathlib.LinearAlgebra.Matrix.Charpoly.Basic', - ], - ].map(([goal, qualifiedName, sourceModule]): GoalCase => ({ - group: 'goal', - goal, - expected: { qualifiedName, sourceModule }, - })), - { group: 'goal', goal: 'x y : ℝ\n⊢ x = y' }, -]; - -export const theoremSearchAlgebraGoalCases: readonly GoalCase[] = [ - [ - 'R M : Type u\ni₀ : Semiring R\ni₁ : AddCommMonoid M\ni₂ : Module R M\nr : R\na b : M\n⊢ r • (a + b) = r • a + r • b', - 'smul_add', - 'Mathlib.Algebra.GroupWithZero.Action.Defs', - ], - [ - 'R M : Type u\ni₀ : Semiring R\ni₁ : AddCommMonoid M\ni₂ : Module R M\nr s : R\na : M\n⊢ (r + s) • a = r • a + s • a', - 'add_smul', - 'Mathlib.Algebra.Module.Defs', - ], - ['G : Type u\ninst : Group G\na b : G\n⊢ (a * b)⁻¹ = b⁻¹ * a⁻¹', 'mul_inv_rev', 'Mathlib.Algebra.Group.DivInvMonoid'], - [ - 'G : Type u\ninst : DivInvMonoid G\na b : G\n⊢ a / b = a * b⁻¹', - 'div_eq_mul_inv', - 'Mathlib.Algebra.Group.DivInvMonoid', - ], - [ - 'ι R : Type u\ninst : Semiring R\ns : Finset ι\nf : ι → R\na : R\n⊢ (∑ j ∈ s, f j) * a = ∑ k ∈ s, f k * a', - 'Finset.sum_mul', - 'Mathlib.Algebra.BigOperators.Ring.Finset', - ], - [ - 'ι M : Type u\ninst : CommMonoid M\ns : Finset ι\nf g : ι → M\n⊢ ∏ i ∈ s, f i * g i = (∏ j ∈ s, f j) * ∏ k ∈ s, g k', - 'Finset.prod_mul_distrib', - 'Mathlib.Algebra.BigOperators.Group.Finset.Basic', - ], - [ - 'ι E : Type u\ninst : SeminormedAddCommGroup E\ns : Finset ι\nf : ι → E\n⊢ ‖∑ j ∈ s, f j‖ ≤ ∑ k ∈ s, ‖f k‖', - 'norm_sum_le', - 'Mathlib.Analysis.Normed.Group.Basic', - ], - [ - 'E : Type u\ninst : SeminormedGroup E\nx y : E\n⊢ ‖x / y‖ ≤ ‖x‖ + ‖y‖', - 'norm_div_le', - 'Mathlib.Analysis.Normed.Group.Basic', - ], -].map(([goal, qualifiedName, sourceModule]) => ({ - group: 'algebraGoal', - goal, - expected: { qualifiedName, sourceModule }, -})); - -export const theoremSearchGeneratedGoalCases: readonly GoalCase[] = [ - [ - 'E : Type u\ninst : SeminormedAddGroup E\nx y : E\n⊢ ‖x + y‖ ≤ ‖x‖ + ‖y‖', - 'norm_add_le', - 'Mathlib.Analysis.Normed.Group.Basic', - ], - [ - 'E : Type u\ninst : SeminormedAddGroup E\nx y : E\n⊢ ‖x - y‖ = ‖y - x‖', - 'norm_sub_rev', - 'Mathlib.Analysis.Normed.Group.Basic', - ], - [ - 'ι M : Type u\ninst : AddCommMonoid M\ns : Finset ι\nf g : ι → M\n⊢ ∑ i ∈ s, (f i + g i) = ∑ j ∈ s, f j + ∑ k ∈ s, g k', - 'Finset.sum_add_distrib', - 'Mathlib.Algebra.BigOperators.Group.Finset.Basic', - ], - [ - 'ι M : Type u\ninst : AddCommMonoid M\ns : Finset ι\nf : ι → M\nh : ∀ i ∈ s, f i = 0\n⊢ ∑ j ∈ s, f j = 0', - 'Finset.sum_eq_zero', - 'Mathlib.Algebra.BigOperators.Group.Finset.Basic', - ], -].map(([goal, qualifiedName, sourceModule]) => ({ - group: 'generatedGoal', - goal, - expected: { qualifiedName, sourceModule }, -})); - -export const theoremSearchGeneratedNameCases: readonly QueryCase[] = theoremSearchGeneratedGoalCases.map( - ({ expected }) => ({ - group: 'generatedName', - query: expected!.qualifiedName, - expected, - }), -); - -export const theoremSearchOrderGoalCases: readonly GoalCase[] = [ - ['α : Type u\ns t : Set α\n⊢ s ∪ t ⊇ s', 'Set.subset_union_left', 'Mathlib.Data.Set.Basic'], - ['α : Type u\ns t : Set α\n⊢ t ⊇ s ∩ t', 'Set.inter_subset_right', 'Mathlib.Data.Set.Basic'], - ['α : Type u\ns t : Set α\na : α\nh : a ∉ s\n⊢ insert a s ⊃ s', 'Set.ssubset_insert', 'Mathlib.Data.Set.Insert'], - [ - 'α : Type u\ninst : DecidableEq α\ns t : Finset α\n⊢ s ∪ t ⊇ s', - 'Finset.subset_union_left', - 'Mathlib.Data.Finset.Lattice.Basic', - ], - [ - 'α : Type u\ninst : DecidableEq α\ns t : Finset α\n⊢ t ⊇ s ∩ t', - 'Finset.inter_subset_right', - 'Mathlib.Data.Finset.Lattice.Basic', - ], - [ - 'α : Type u\ninst : DecidableEq α\ns t : Finset α\na : α\nh : a ∉ s\n⊢ insert a s ⊃ s', - 'Finset.ssubset_insert', - 'Mathlib.Data.Finset.Insert', - ], - ['E : Type u\ninst : SeminormedAddGroup E\nx : E\n⊢ ‖x‖ ≥ 0', 'norm_nonneg', 'Mathlib.Analysis.Normed.Group.Basic'], - ['x : ℝ\n⊢ √x >= 0', 'Real.sqrt_nonneg', 'Mathlib.Analysis.Real.Sqrt'], - ['x : ℝ\n⊢ Real.exp x > 0', 'Real.exp_pos', 'Mathlib.Analysis.Complex.Exponential'], - [ - 'E : Type u\ninst : SeminormedGroup E\nx y : E\n⊢ ‖x‖ + ‖y‖ ≥ ‖x / y‖', - 'norm_div_le', - 'Mathlib.Analysis.Normed.Group.Basic', - ], - [ - 'α : Type u\ninst : MeasurableSpace α\ns t : Set α\nμ : MeasureTheory.Measure α\n⊢ μ s + μ t ≥ μ (s ∪ t)', - 'MeasureTheory.measure_union_le', - 'Mathlib.MeasureTheory.OuterMeasure.Basic', - ], - ['s t : Finset α\nh : s ⊆ t\n⊢ t.card >= s.card', 'Finset.card_le_card', 'Mathlib.Data.Finset.Card'], - [ - 'ι E : Type u\ninst : SeminormedAddCommGroup E\ns : Finset ι\nf : ι → E\n⊢ ∑ k ∈ s, ‖f k‖ ≥ ‖∑ j ∈ s, f j‖', - 'norm_sum_le', - 'Mathlib.Analysis.Normed.Group.Basic', - ], - ['x : ℝ\nhx : 0 < x\nhx1 : x < 1\n⊢ 0 > Real.log x', 'Real.log_neg', 'Mathlib.Analysis.SpecialFunctions.Log.Basic'], -].map(([goal, qualifiedName, sourceModule]) => ({ - group: 'orderGoal', - goal, - expected: { qualifiedName, sourceModule }, -})); - -export const theoremSearchSpecializedGoalCases: readonly GoalCase[] = [ - [ - 'E : Type u\ninst : SeminormedAddGroup E\nx y z : E\n⊢ ‖(x - y) + z‖ ≤ ‖x - y‖ + ‖z‖', - 'norm_add_le', - 'Mathlib.Analysis.Normed.Group.Basic', - ], - [ - 'E : Type u\ninst : SeminormedAddGroup E\nx y z : E\n⊢ ‖(x + y) - z‖ = ‖z - (x + y)‖', - 'norm_sub_rev', - 'Mathlib.Analysis.Normed.Group.Basic', - ], - ['s t u : Set α\n⊢ (s ∪ t) ∪ u = u ∪ (s ∪ t)', 'Set.union_comm', 'Mathlib.Data.Set.Basic'], - [ - 'α : Type u\ninst : MeasurableSpace α\ns t u : Set α\nμ : MeasureTheory.Measure α\n⊢ μ ((s ∪ t) ∪ u) ≤ μ (s ∪ t) + μ u', - 'MeasureTheory.measure_union_le', - 'Mathlib.MeasureTheory.OuterMeasure.Basic', - ], - [ - 'G : Type u\ninst : Group G\nx y z : G\n⊢ ((x * y) * z)⁻¹ = z⁻¹ * (x * y)⁻¹', - 'mul_inv_rev', - 'Mathlib.Algebra.Group.DivInvMonoid', - ], - ['x : ℝ\n⊢ 0 < Real.exp (x + 1)', 'Real.exp_pos', 'Mathlib.Analysis.Complex.Exponential'], - ['a b c d : ℕ\nhb : a ∣ b + c\nhd : a ∣ d\n⊢ a ∣ (b + c) + d', 'dvd_add', 'Mathlib.Algebra.Ring.Divisibility.Basic'], - [ - 'E : Type u\ninst : SeminormedAddCommGroup E\ninst_1 : InnerProductSpace ℝ E\nx y z : E\n⊢ ‖⟪(x + y), z⟫‖ ≤ ‖x + y‖ * ‖z‖', - 'norm_inner_le_norm', - 'Mathlib.Analysis.InnerProductSpace.Basic', - ], -].map(([goal, qualifiedName, sourceModule]) => ({ - group: 'specializedGoal', - goal, - expected: { qualifiedName, sourceModule }, -})); - -// The same conclusion can have separate lemmas for different available premises. -export const theoremSearchSpecializedPremiseCases: readonly GoalCase[] = [ - [ - 'x y : ℝ\nh : -1 > x + y\n⊢ 0 < Real.log (x + y)', - 'Real.log_pos_of_lt_neg_one', - 'Mathlib.Analysis.SpecialFunctions.Log.Basic', - ], - [ - 'x y : ℝ\nh : 0 > x + y ∧ x + y > -1\n⊢ Real.log (x + y) < 0', - 'Real.log_neg_of_lt_zero', - 'Mathlib.Analysis.SpecialFunctions.Log.Basic', - ], - ['x : ℝ\nh : 1 > x ∧ x > 0\n⊢ Real.log x < 0', 'Real.log_neg', 'Mathlib.Analysis.SpecialFunctions.Log.Basic'], - ['a b c : ℝ\nh : b + c ≥ 0\n⊢ √(a * (b + c)) = √a * √(b + c)', "Real.sqrt_mul'", 'Mathlib.Analysis.Real.Sqrt'], - ['a b c : ℝ\nh : b + c ≥ 0\n⊢ √(a / (b + c)) = √a / √(b + c)', "Real.sqrt_div'", 'Mathlib.Analysis.Real.Sqrt'], - [ - 'x y : ℝ\nh : x + y < -1\n⊢ 0 < Real.log (x + y)', - 'Real.log_pos_of_lt_neg_one', - 'Mathlib.Analysis.SpecialFunctions.Log.Basic', - ], - ['x y : ℝ\nh : 1 < x + y\n⊢ 0 < Real.log (x + y)', 'Real.log_pos', 'Mathlib.Analysis.SpecialFunctions.Log.Basic'], - [ - 'x y : ℝ\nh₀ : x + y < 0\nh₁ : -1 < x + y\n⊢ Real.log (x + y) < 0', - 'Real.log_neg_of_lt_zero', - 'Mathlib.Analysis.SpecialFunctions.Log.Basic', - ], - ['a b c : ℝ\nh : 0 ≤ b + c\n⊢ √(a * (b + c)) = √a * √(b + c)', "Real.sqrt_mul'", 'Mathlib.Analysis.Real.Sqrt'], - ['a b c : ℝ\nh : 0 ≤ b + c\n⊢ √(a / (b + c)) = √a / √(b + c)', "Real.sqrt_div'", 'Mathlib.Analysis.Real.Sqrt'], - ['a b c : ℝ\nh : 0 ≤ a + b\n⊢ √((a + b) * c) = √(a + b) * √c', 'Real.sqrt_mul', 'Mathlib.Analysis.Real.Sqrt'], -].map(([goal, qualifiedName, sourceModule]) => ({ - group: 'specializedPremise', - goal, - expected: { qualifiedName, sourceModule }, -})); - -export const theoremSearchSymmetricGoalCases: readonly GoalCase[] = [ - ['s t u : Set α\n⊢ s ∩ t ∪ s ∩ u = s ∩ (t ∪ u)', 'Set.inter_union_distrib_left', 'Mathlib.Data.Set.Basic'], - ['s t : Set α\n⊢ sᶜ ∩ tᶜ = (s ∪ t)ᶜ', 'Set.compl_union', 'Mathlib.Order.BooleanAlgebra.Set'], - ['x : α\ns t : Set α\n⊢ x ∈ s ∨ x ∈ t ↔ x ∈ s ∪ t', 'Set.mem_union', 'Mathlib.Data.Set.Basic'], - ['x : α\ns t : Set α\n⊢ x ∈ s ∧ x ∈ t ↔ x ∈ s ∩ t', 'Set.mem_inter_iff', 'Mathlib.Data.Set.Basic'], - [ - 'α : Type u\ninst : TopologicalSpace α\ns : Set α\n⊢ IsClosed s ↔ closure s = s', - 'closure_eq_iff_isClosed', - 'Mathlib.Topology.Closure', - ], - [ - 'x y : ℝ\nh : 0 < x + y\n⊢ x + y = Real.exp (Real.log (x + y))', - 'Real.exp_log', - 'Mathlib.Analysis.SpecialFunctions.Log.Basic', - ], -].map(([goal, qualifiedName, sourceModule]) => ({ - group: 'symmetricGoal', - goal, - expected: { qualifiedName, sourceModule }, -})); - -function scoreCase(test: QueryCase | GoalCase, result: SearchResult) { - const expected = test.expected; - const rank = expected - ? result.results.findIndex( - item => item.qualifiedName === expected.qualifiedName && item.sourceModule === expected.sourceModule, - ) + 1 - : 0; - return { - ...test, - rank: rank || null, - top: result.results - .slice(0, 3) - .map(({ qualifiedName, sourceModule, application }) => ({ qualifiedName, sourceModule, application })), - matches: result.totalMatches, - }; -} - -function run(workspace: string, corpusPath: string) { - const corpusText = readMathText(corpusPath); - const corpus = JSON.parse(corpusText); - const cases = []; - const queriesToTest = [...theoremSearchCases, ...theoremSearchGeneratedNameCases]; - for (let offset = 0; offset < queriesToTest.length; offset += 4) { - const batch = queriesToTest.slice(offset, offset + 4); - const { queries } = searchMathRetrievalCorpusBatch( - workspace, - corpus, - batch.map(item => item.query), - 3, - ); - for (const [index, result] of queries.entries()) { - cases.push(scoreCase(batch[index]!, result)); - } - } - for (const test of [ - ...theoremSearchGoalCases, - ...theoremSearchAlgebraGoalCases, - ...theoremSearchGeneratedGoalCases, - ...theoremSearchOrderGoalCases, - ...theoremSearchSpecializedGoalCases, - ...theoremSearchSpecializedPremiseCases, - ...theoremSearchSymmetricGoalCases, - ]) { - const { - queries: [result], - } = searchMathRetrievalCorpusBatch(workspace, corpus, [''], 3, test.goal); - cases.push(scoreCase(test, result!)); - } - const groups = [ - 'zh', - 'en', - 'ranking', - 'control', - 'leanReference', - 'goal', - 'algebraGoal', - 'generatedName', - 'generatedGoal', - 'orderGoal', - 'specializedGoal', - 'specializedPremise', - 'symmetricGoal', - ] as const; - const summary = Object.fromEntries( - groups.map(group => { - const items = cases.filter(item => item.group === group && item.expected); - return [ - group, - { - cases: items.length, - top1: items.filter(item => item.rank === 1).length, - top3: items.filter(item => item.rank !== null && item.rank <= 3).length, - }, - ]; - }), - ); - const negatives = cases.filter(item => item.group === 'negative'); - const negativeGoals = cases.filter(item => item.group === 'goal' && !item.expected); - console.log( - JSON.stringify( - { - corpusSha256: mathDigest(corpusText), - summary: { - ...summary, - negative: { cases: negatives.length, empty: negatives.filter(item => item.matches === 0).length }, - negativeGoal: { cases: negativeGoals.length, empty: negativeGoals.filter(item => item.matches === 0).length }, - }, - cases, - }, - null, - 2, - ), - ); -} - -if (import.meta.main) { - const { values } = parseArgs({ - options: { - workspace: { type: 'string' }, - corpus: { type: 'string' }, - help: { type: 'boolean' }, - }, - }); - if (values.help) { - console.log('Usage: bun scripts/mathematics/benchmarkTheoremSearch.ts --workspace DIR --corpus FILE'); - } else { - if (!values.workspace || !values.corpus) throw new Error('--workspace and --corpus are required'); - run(values.workspace, values.corpus); - } -} diff --git a/scripts/mathematics/checkRunStates.ts b/scripts/mathematics/checkRunStates.ts deleted file mode 100644 index 0af2c919..00000000 --- a/scripts/mathematics/checkRunStates.ts +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bun -import fs from 'node:fs'; -import { checkSolverRunState } from '../../src/solver/stateInvariants'; -import type { SolverRunState } from '../../src/solver/archive'; - -// Reads stored states only; old schemas are checked loosely instead of being rejected. -const paths = process.argv - .slice(2) - .flatMap(argument => (argument === '-' ? fs.readFileSync(0, 'utf8').split('\n') : [argument])) - .map(item => item.trim()) - .filter(Boolean); -if (!paths.length || paths.includes('--help')) { - console.log( - 'Usage: checkRunStates.ts STATE_JSON... | - (reads paths from stdin with -)\nPrints one JSON line per state with invariant violations.', - ); -} else { - let errors = 0; - for (const file of paths) { - let violations; - try { - violations = checkSolverRunState(JSON.parse(fs.readFileSync(file, 'utf8')) as SolverRunState); - } catch (error) { - violations = [{ code: 'state_unreadable', severity: 'error', message: String(error), refs: [] }]; - } - if (violations.some(item => item.severity === 'error')) errors++; - if (violations.length) console.log(JSON.stringify({ file, violations })); - } - if (errors) process.exitCode = 1; -} diff --git a/scripts/mathematics/runGoalsFirst.ts b/scripts/mathematics/runGoalsFirst.ts deleted file mode 100644 index 36c16302..00000000 --- a/scripts/mathematics/runGoalsFirst.ts +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bun -import { retiredResearchComponent } from '../../src/solver/researchRetirement'; - -process.exitCode = retiredResearchComponent(process.argv.slice(2)); diff --git a/src/math/leanDiagnostics.ts b/src/math/leanDiagnostics.ts index f86bdb48..ca07e0ff 100644 --- a/src/math/leanDiagnostics.ts +++ b/src/math/leanDiagnostics.ts @@ -265,7 +265,7 @@ export async function runLeanDiagnostics(input: { modules.map(module => [module.file, mathDigest(fs.readFileSync(path.join(project, module.file)))]); const initialSources = sourceFiles(); const sourceIdentity = () => mathDigest(JSON.stringify([configuration(), sourceFiles()])); - const sourceDigest = sourceIdentity(); + const sourceDigest = mathDigest(JSON.stringify([config, initialSources])); const builtModules = new Map(); const deadline = Date.now() + input.timeoutMs; const phases: {