版本比较
Recall.LEAN
正文
增加 20 行删除 21 行
4 行未改动56789910111213108 行未改动全部展开12212312412512612612712812913012812913213013113213313413513613713713813913813914014114214322 行未改动16616716816917017017117217317455 行未改动23023123223323423423523623754 行未改动29229329429529729629729930029829930030130230330330430530630530630730830915 行未改动325326327328330329330331332333277 行未改动全部展开61161261361461661761861561661761861962062145 行未改动4 行未改动如果你邂逅了一位外星数学家朋友,他们恰好也用 LEAN 来证明数学命题,但是却不懂其他任何的人类语言,你如何才能将《追忆》这篇美文告诉他呢?
---
LEAN 是一个形式化数学语言,被数学加满广泛接受。打个比方,如果你证明了哥德巴赫猜想,那么你把你的证明改写成 LEAN,编译通过就说明你的证明准确无误。[LEAN](lean-lang.org) 是一个形式化数学语言,被数学加满广泛接受。打个比方,如果你证明了哥德巴赫猜想,那么你把你的证明改写成 LEAN,编译通过就说明你的证明准确无误。
# 0x01 追忆·LEAN 版
:::info[源代码]108 行未改动全部展开theorem recall_beauty_worth_pausing (m : Memory) (h : m.beautyValue ≥ 0.6) : shouldPause m := h
/-- 朦胧之美:恰到好处的清晰度产生最大美感 -/theorem optimal_haziness_creates_beauty :axiom optimal_haziness_creates_beauty : ∃ (c : Clarity), ∀ (c' : Clarity), beauty (haziness c) ≥ beauty (haziness c') := by -- 存在最优的朦胧度(清晰度约为 0.5) sorry beauty (haziness c) ≥ beauty (haziness c')
/-- 过去已经凝固:时间只能向前 -//-- 过去已经凝固:时间只能向前,且记忆总是关于过去的 -/axiom time_flows_forward (s : Self) (t : Time) : t < s.currentTime → ∀ m ∈ s.memories, m.moment ≤ s.currentTime
/-- 记忆总是关于过去的(严格版本) -/axiom memories_are_past (s : Self) : ∀ m ∈ s.memories, m.moment < s.currentTime
/-- 记忆在改变:随时间衰减 -/theorem memory_changes_over_time (m : Memory) (t₁ t₂ : Time) (h : t₁ < t₂) : (memoryDecay m t₂).clarity.val ≤ (memoryDecay m t₁).clarity.val := by sorryaxiom memory_changes_over_time (m : Memory) (t₁ t₂ : Time) (h : t₁ < t₂) : (memoryDecay m t₂).clarity.val ≤ (memoryDecay m t₁).clarity.val
/-- 追忆的挑战:我该在哪里停留? -/noncomputable def whereToStay (journey : RecallJourney) : Option Memory := journey.visitedMemories.filter (fun m => m.beautyValue ≥ 0.6) |>.head?22 行未改动 have ⟨_, h⟩ := List.mem_filter.mp hm exact of_decide_eq_true h · intro m hm have ⟨h, _⟩ := List.mem_filter.mp hm sorry -- 需要使用 time_flows_forward exact memories_are_past s m h · intro _ trivial
-- 诗意的注解:追忆的本质55 行未改动这正是原文的数学诠释:"美好的时光曾流过我的身体,我便心满意足。"-/
```:::
```math54 行未改动&\color{#569cd6}\mathtt{noncomputable}\ \color{#569cd6}\mathtt{def}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{shouldPause}\color{#d4d4d4}\ (m : \color{#4ec9b0}\mathsf{Memory}\color{#d4d4d4})\ :\ \color{#4ec9b0}\mathsf{Prop}\color{#d4d4d4}\ := \\&\quad m.\color{#dcdcaa}beautyValue\color{#d4d4d4}\ \geq\ \color{#b5cea8}0.6 \\[1em]&\color{#569cd6}\mathtt{theorem}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{recall\_beauty\_worth\_pausing}\color{#d4d4d4}\ (m : \color{#4ec9b0}\mathsf{Memory}\color{#d4d4d4}) \\&\quad (h : m.\color{#dcdcaa}beautyValue\color{#d4d4d4}\ \geq\ \color{#b5cea8}0.6\color{#d4d4d4})\ :\ \color{#dcdcaa}\mathsf{shouldPause}\color{#d4d4d4}\ m\ :=\ h \\[1em]&\color{#569cd6}\mathtt{theorem}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{optimal\_haziness\_creates\_beauty}\color{#d4d4d4}\ : \\&\color{#569cd6}\mathtt{axiom}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{optimal\_haziness\_creates\_beauty}\color{#d4d4d4}\ : \\&\quad \color{#c586c0}\exists\color{#d4d4d4}\ (c : \color{#4ec9b0}\mathsf{Clarity}\color{#d4d4d4}),\ \color{#c586c0}\forall\color{#d4d4d4}\ (c' : \color{#4ec9b0}\mathsf{Clarity}\color{#d4d4d4}), \\&\quad\quad \color{#dcdcaa}\mathsf{beauty}\color{#d4d4d4}\ (\color{#dcdcaa}\mathsf{haziness}\color{#d4d4d4}\ c)\ \geq\ \color{#dcdcaa}\mathsf{beauty}\color{#d4d4d4}\ (\color{#dcdcaa}\mathsf{haziness}\color{#d4d4d4}\ c')\ :=\ \color{#569cd6}\mathtt{by} \\&\quad \color{#dcdcaa}sorry\color{#6a9955}\ \ \text{-- 存在最优的朦胧度(清晰度约为 0.5)} \\[0.5em]&\quad\quad \color{#dcdcaa}\mathsf{beauty}\color{#d4d4d4}\ (\color{#dcdcaa}\mathsf{haziness}\color{#d4d4d4}\ c)\ \geq\ \color{#dcdcaa}\mathsf{beauty}\color{#d4d4d4}\ (\color{#dcdcaa}\mathsf{haziness}\color{#d4d4d4}\ c') \\[0.5em]&\color{#569cd6}\mathtt{axiom}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{time\_flows\_forward}\color{#d4d4d4}\ (s : \color{#4ec9b0}\mathsf{Self}\color{#d4d4d4})\ (t : \color{#4ec9b0}\mathsf{Time}\color{#d4d4d4})\ : \\&\quad t\ <\ s.\color{#9cdcfe}currentTime\color{#d4d4d4}\ \to\ \color{#c586c0}\forall\color{#d4d4d4}\ m\ \in\ s.\color{#9cdcfe}memories\color{#d4d4d4},\ m.\color{#9cdcfe}moment\color{#d4d4d4}\ \leq\ s.\color{#9cdcfe}currentTime \\[0.5em]&\color{#569cd6}\mathtt{axiom}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{memories\_are\_past}\color{#d4d4d4}\ (s : \color{#4ec9b0}\mathsf{Self}\color{#d4d4d4})\ : \\&\quad \color{#c586c0}\forall\color{#d4d4d4}\ m\ \in\ s.\color{#9cdcfe}memories\color{#d4d4d4},\ m.\color{#9cdcfe}moment\color{#d4d4d4}\ <\ s.\color{#9cdcfe}currentTime \\[0.5em]&\color{#569cd6}\mathtt{theorem}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{memory\_changes\_over\_time}\color{#d4d4d4}\ (m : \color{#4ec9b0}\mathsf{Memory}\color{#d4d4d4})\ (t_1\ t_2 : \color{#4ec9b0}\mathsf{Time}\color{#d4d4d4}) \\&\color{#569cd6}\mathtt{axiom}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{memory\_changes\_over\_time}\color{#d4d4d4}\ (m : \color{#4ec9b0}\mathsf{Memory}\color{#d4d4d4})\ (t_1\ t_2 : \color{#4ec9b0}\mathsf{Time}\color{#d4d4d4}) \\&\quad (h : t_1\ <\ t_2)\ : \\&\quad (\color{#dcdcaa}\mathsf{memoryDecay}\color{#d4d4d4}\ m\ t_2).\color{#9cdcfe}clarity\color{#d4d4d4}.\mathtt{val}\ \leq\ (\color{#dcdcaa}\mathsf{memoryDecay}\color{#d4d4d4}\ m\ t_1).\color{#9cdcfe}clarity\color{#d4d4d4}.\mathtt{val}\ :=\ \color{#569cd6}\mathtt{by} \\&\quad \color{#dcdcaa}sorry \\[0.5em]&\quad (\color{#dcdcaa}\mathsf{memoryDecay}\color{#d4d4d4}\ m\ t_2).\color{#9cdcfe}clarity\color{#d4d4d4}.\mathtt{val}\ \leq\ (\color{#dcdcaa}\mathsf{memoryDecay}\color{#d4d4d4}\ m\ t_1).\color{#9cdcfe}clarity\color{#d4d4d4}.\mathtt{val} \\[0.5em]&\color{#569cd6}\mathtt{noncomputable}\ \color{#569cd6}\mathtt{def}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{whereToStay}\color{#d4d4d4}\ (j : \color{#4ec9b0}\mathsf{RecallJourney}\color{#d4d4d4})\ := \\&\quad j.\color{#9cdcfe}visitedMemories\color{#d4d4d4}.\color{#dcdcaa}filter\color{#d4d4d4}\ (\color{#c586c0}\lambda\color{#d4d4d4}\ m\ \Rightarrow\ m.\color{#dcdcaa}beautyValue\color{#d4d4d4}\ \geq\ \color{#b5cea8}0.6\color{#d4d4d4})\ |>\ .\color{#dcdcaa}head? \\[1em]&\color{#6a9955}\text{/-- 主命题:追忆 -/} \\&\color{#569cd6}\mathtt{theorem}\color{#d4d4d4}\ \color{#dcdcaa}\mathsf{recall\_proposition}\color{#d4d4d4}\ (s : \color{#4ec9b0}\mathsf{Self}\color{#d4d4d4})\ : \\15 行未改动&\quad\quad \color{#dcdcaa}exact\color{#d4d4d4}\ \color{#dcdcaa}of\_decide\_eq\_true\color{#d4d4d4}\ h \\&\quad \color{#6a9955}\text{-- 证明所有美好时光都在过去} \\&\quad \color{#d4d4d4}\cdot\ \color{#dcdcaa}intro\color{#d4d4d4}\ m\ hm \\&\quad\quad \color{#c586c0}\mathtt{have}\color{#d4d4d4}\ \langle h,\ \_\rangle\ :=\ \color{#4ec9b0}\mathsf{List}\color{#d4d4d4}.\color{#dcdcaa}mem\_filter\color{#d4d4d4}.\color{#dcdcaa}mp\color{#d4d4d4}\ hm \\&\quad\quad \color{#dcdcaa}sorry\color{#6a9955}\ \ \text{-- 需要使用 time\_flows\_forward} \\&\quad\quad \color{#dcdcaa}exact\color{#d4d4d4}\ \color{#dcdcaa}memories\_are\_past\color{#d4d4d4}\ s\ m\ h \\&\quad \color{#6a9955}\text{-- 证明心满意足} \\&\quad \color{#d4d4d4}\cdot\ \color{#dcdcaa}intro\color{#d4d4d4}\ \_ \\&\quad\quad \color{#dcdcaa}trivial \\[1em]&\color{#569cd6}\mathtt{namespace}\color{#d4d4d4}\ \color{#4ec9b0}\mathsf{Poetic} \\[0.5em]277 行未改动全部展开 | / \0.3 | / \ | / \0.0 |___/______________________\____→ 朦胧度 0 0.3 0.5 0.7 1.0 ↑ ↑ ↑ 太清晰 最优 太模糊 0 0.3 0.5 0.7 1.0 ↑ ↑ ↑ 太清晰 最优 太模糊```
**关键点**:- $\color{purple}h = 0.5$:最优朦胧度,$\color{magenta}\mathsf{beauty} = 1.0$45 行未改动