tactic ::= ... |simpThe `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.optConfig only? ([ (Configuration options for tactics.simpStar |The simp lemma specification `*` means to rewrite with all hypothesessimpErase |An erasure specification `-thm` says to remove `thm` from the simp setsimpLemma),* ] )? (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 withatLocation 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(term |A sequence of one or more locations at which a tactic should operate. These can include local hypotheses and `⊢`, which denotes the goal.locationType)*)?The `⊢` location refers to the current goal.
15.1. 调用简化器
Lean 的简化器可以通过多种方式调用。 一组策略涵盖了最常见的调用模式。 策略参考中列出了完整的简化策略。
所有简化策略的名称都包含 simp。
除此之外,它们还按照一套描述其功能的前缀和后缀体系来命名:
-
-!后缀 将
autoUnfold配置选项设为true,使简化器展开所有定义-
-?后缀 使简化器记录简化期间用过哪些规则,并建议把策略脚本改为使用一个最小的 simp 集
-
-_arith后缀 启用线性算术简化规则
-
d-前缀 使简化器仅使用在定义意义下成立的重写进行简化
-
-_all后缀 使简化器反复简化所有假设和目标结论,并尽可能多地考虑各项假设,直到无法继续简化为止
此外还有两个简化策略 simpa 和 simpa!,它们先同时简化目标以及一个证明项或假设,再完成目标。
这种同步简化使证明面对 simp 集的变化时更加稳健。
15.1.1. 参数
简化策略采用以下语法:
换言之,调用简化策略时依次接受以下修饰项,且每一项都是可选的:
-
一组配置选项;根据所调用的简化器是
simp还是dsimp的变体,其中应分别包含Lean.Meta.Simp.Config或Lean.Meta.DSimp.Config的字段。 -
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_self和iff_self。simp 集开始。 -
引理列表向 simp 集添加引理或从中移除引理。引理列表中的引理有三种指定方式:
-
*,将证明状态中的所有假设添加到 simp 集 -
-后接一个引理,将该引理从 simp 集中移除 -
引理说明符,由以下各项依次组成:
-
可选的
↓或↑,分别使引理在进入子项之前或之后应用(默认为↑)。简化后的参数通常能让更多规则适用,因此简化器一般先简化子项,再尝试简化父项;↓则使规则在子项简化之前先简化父项。 -
可选的
←,使等式引理从右向左而非从左向右使用。 -
必需的引理,可以是 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开头,由一系列位置组成。位置可以是:-
假设的名称,表示应简化其类型
-
星号
*,表示应简化所有假设和结论 -
推导符号
⊢,表示应简化结论
默认只简化结论。
-
simp 的位置说明符
在此证明状态中,
策略 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 (x + 7):
使用 p:Nat → Propx:Nath:p (x + 7)h':p (x + 12)⊢ p (x + 7) 会简化所有假设以及结论: