Lean 语言参考

15.1. 调用简化器🔗

Lean 的简化器可以通过多种方式调用。 最常见的模式在一组策略中捕获。 策略参考包含简化策略的完整列表。

简化策略名称中均包含 simp。 除此之外,它们是根据描述其功能的前缀和后缀系统命名的:

-!后缀

autoUnfold 配置选项设置为 true,使简化器展开所有定义

-?后缀

使简化器跟踪简化过程中使用的规则,并建议最小的 simp set 作为对策略脚本的编辑

-_arith后缀

允许使用线性算术简化规则

d- 前缀

导致简化器仅通过定义保留的重写来简化

-_all后缀

使简化器反复简化所有假设和目标结论,考虑尽可能多的假设,直到不可能进一步简化

还有两个进一步的简化策略、simpasimpa!,用于在实现目标之前同时简化目标和证明项或假设。 这种同时简化使得证明对于 simp set 中的变化更加稳健。

15.1.1. 参数🔗

简化策略具有以下语法:

syntaxSimplification Tactics
tactic ::= ...
    | The `simp` tactic uses lemmas and hypotheses to simplify the main goal target or
non-dependent hypotheses. It has many variants:
- `simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`.
- `simp [h₁, h₂, ..., hₙ]` simplifies the main goal target using the lemmas tagged
  with the attribute `[simp]` and the given `hᵢ`'s, where the `hᵢ`'s are expressions.-
- If an `hᵢ` is a defined constant `f`, then `f` is unfolded. If `f` has equational lemmas associated
  with it (and is not a projection or a `reducible` definition), these are used to rewrite with `f`.
- `simp [*]` simplifies the main goal target using the lemmas tagged with the
  attribute `[simp]` and all hypotheses.
- `simp only [h₁, h₂, ..., hₙ]` is like `simp [h₁, h₂, ..., hₙ]` but does not use `[simp]` lemmas.
- `simp [-id₁, ..., -idₙ]` simplifies the main goal target using the lemmas tagged
  with the attribute `[simp]`, but removes the ones named `idᵢ`.
- `simp at h₁ h₂ ... hₙ` simplifies the hypotheses `h₁ : T₁` ... `hₙ : Tₙ`. If
  the target or another hypothesis depends on `hᵢ`, a new simplified hypothesis
  `hᵢ` is introduced, but the old one remains in the local context.
- `simp at *` simplifies all the hypotheses and the target.
- `simp [*] at *` simplifies target and all (propositional) hypotheses using the
  other hypotheses.
simp Configuration options for tactics. optConfig only? ([ (The simp lemma specification `*` means to rewrite with all hypotheses simpStar | An erasure specification `-thm` says to remove `thm` from the simp set simpErase | A simp lemma specification is:
* optional `↑` or `↓` to specify use before or after entering the subterm
* optional `←` to use the lemma backward
* `thm` for the theorem to rewrite with
simpLemma),* ] )? (Location specifications are used by many tactics that can operate on either the
hypotheses or the goal. It can have one of the forms:
* 'empty' is not actually present in this syntax, but most tactics use
  `(location)?` matchers. It means to target the goal only.
* `at h₁ ... hₙ`: target the hypotheses `h₁`, ..., `hₙ`
* `at h₁ h₂ ⊢`: target the hypotheses `h₁` and `h₂`, and the goal
* `at *`: target all hypotheses and the goal
at A sequence of one or more locations at which a tactic should operate. These can include local
hypotheses and `⊢`, which denotes the goal.
(term | The `⊢` location refers to the current goal. locationType)*)?

换句话说,简化策略的调用按顺序采用以下修饰符,所有这些修饰符都是可选的:

  • 一组 配置选项,其中应包括 Lean.Meta.Simp.ConfigLean.Meta.DSimp.Config 字段,具体取决于所调用的简化器是 simp 版本还是 dsimp 版本。

  • Lean.Parser.Tactic.simp : tacticThe `simp` tactic uses lemmas and hypotheses to simplify the main goal target or non-dependent hypotheses. It has many variants: - `simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`. - `simp [h₁, h₂, ..., hₙ]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and the given `hᵢ`'s, where the `hᵢ`'s are expressions.- - If an `hᵢ` is a defined constant `f`, then `f` is unfolded. If `f` has equational lemmas associated with it (and is not a projection or a `reducible` definition), these are used to rewrite with `f`. - `simp [*]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and all hypotheses. - `simp only [h₁, h₂, ..., hₙ]` is like `simp [h₁, h₂, ..., hₙ]` but does not use `[simp]` lemmas. - `simp [-id₁, ..., -idₙ]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]`, but removes the ones named `idᵢ`. - `simp at h₁ h₂ ... hₙ` simplifies the hypotheses `h₁ : T₁` ... `hₙ : Tₙ`. If the target or another hypothesis depends on `hᵢ`, a new simplified hypothesis `hᵢ` is introduced, but the old one remains in the local context. - `simp at *` simplifies all the hypotheses and the target. - `simp [*] at *` simplifies target and all (propositional) hypotheses using the other hypotheses. only 修饰符不包括默认的 simp 集,而是以空的从技术上讲,simp 集始终包含 eq_selfiff_self,以便释放自反情况。 simp 集开始。

  • 引理列表在 simp 集中添加或删除引理。可以通过三种方式在引理列表中指定引理:

    • *,将证明状态中的所有假设添加到 simp 集中

    • - 后跟引理,从 simpl 集中删除引理

    • 引理说明符,按顺序包含以下内容:

      • 可选的 ,分别导致在输入子项之前或之后应用引理( 是默认值)。简化者通常会在尝试简化父项之前先简化子项,因为简化的参数通常会使更多规则适用; 导致使用子项简化之前的规则来简化父项。

      • 可选的 ,它导致等式引理从右到左而不是从左到右使用。

      • 强制引理,可以是 simp 集名称、引理名称或术语。术语被视为就像用新名称命名的引理一样。

  • 位置说明符,前面带有 Lean.Parser.Tactic.simp : tacticThe `simp` tactic uses lemmas and hypotheses to simplify the main goal target or non-dependent hypotheses. It has many variants: - `simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`. - `simp [h₁, h₂, ..., hₙ]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and the given `hᵢ`'s, where the `hᵢ`'s are expressions.- - If an `hᵢ` is a defined constant `f`, then `f` is unfolded. If `f` has equational lemmas associated with it (and is not a projection or a `reducible` definition), these are used to rewrite with `f`. - `simp [*]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and all hypotheses. - `simp only [h₁, h₂, ..., hₙ]` is like `simp [h₁, h₂, ..., hₙ]` but does not use `[simp]` lemmas. - `simp [-id₁, ..., -idₙ]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]`, but removes the ones named `idᵢ`. - `simp at h₁ h₂ ... hₙ` simplifies the hypotheses `h₁ : T₁` ... `hₙ : Tₙ`. If the target or another hypothesis depends on `hᵢ`, a new simplified hypothesis `hᵢ` is introduced, but the old one remains in the local context. - `simp at *` simplifies all the hypotheses and the target. - `simp [*] at *` simplifies target and all (propositional) hypotheses using the other hypotheses. at,由位置序列组成。地点可能是:

    • 假设的名称,表明其类型应简化

    • 星号*,表示所有假设和结论都应该简化

    • 一个转门,说明结论应该简化

    默认情况下,仅对结论进行简化。

Location specifiers for simp

在这种证明状态下,

p:Nat Propx:Nath:p (x + 5 + 2)h':p (3 + x + 9)p (6 + x + 1)

策略p:Nat Propx:Nath:p (x + 5 + 2)h':p (3 + x + 9)p (x + 7) 仅简化了目标:

p:Nat Propx:Nath:p (x + 5 + 2)h':p (3 + x + 9)p (x + 7)

调用 p:Nat Propx:Nath':p (3 + x + 9)h:p (x + 7)p (6 + x + 1) 会产生一个目标,其中假设 h 已被简化:

p:Nat Propx:Nath':p (3 + x + 9)h:p (x + 7)p (6 + x + 1)

结论还可以通过添加来进一步简化,即p:Nat Propx:Nath':p (3 + x + 9)h:p (x + 7)p (x + 7)

p:Nat Propx:Nath':p (3 + x + 9)h:p (x + 7)p (x + 7)

使用 p:Nat Propx:Nath:p (x + 7)h':p (x + 12)p (x + 7) 简化了所有假设以及结论:

p:Nat Propx:Nath:p (x + 7)h':p (x + 12)p (x + 7)