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 goalterm*)?A hypothesis location specification consists of 1 or more hypothesis references and optionally `⊢` denoting the goal.
11.1. 単純化器の呼び出し(Invoking the Simplifier)
Lean の単純化器はさまざまな方法で呼び出すことができます。最も一般的なパターンはタクティクのセットに含まれています。 タクティクのリファレンス には、単純化タクティクの完全なリストが含まれています。
単純化器のタクティクはすべて名前に simp を含んでいます。それはともかく、それらはその機能を表す接頭辞と接尾辞のシステムに従って命名されます:
-
-!接尾辞 autoUnfold設定オプションをtrueにし、これにより単純化器はすべての定義を展開します
-
-?接尾辞 単純化スクリプトが単純化中にどの規則を採用したかを追跡し、単純化スクリプトを記述する上で最小の simp セット を提案するようにします
-
-_arith接尾辞 線形算術の単純化規則の使用を可能にします
-
d-接頭辞 definitionally に成立する書き換えのみを単純化します
-
-_all接尾辞 これ以上の単純化が不可能になるまで、可能な限り多くの仮定を考慮に入れながら単純化器にすべての仮定とゴールの結論を繰り返し単純化させます
これらに加えて2つの単純化タクティク simpa と simpa! があります。これらはゴールを終了する前に、ゴールと証明項・仮定を同時に単純化するために用いられます。この同時単純化により、 simp セット の変更に対して証明がより頑強になります。
11.1.1. パラメータ(Parameters)
単純化タクティクは以下のような文法を持ちます:
言い換えれば、単純化タクティクの呼び出しは以下の修飾子を順番に取ります。またこれらはすべて任意です:
-
設定オプション 、呼び出される単純化器が
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 セットに補題を追加したり削除したりします。補題リストで補題を指定する方法は3つあります:
-
*、これは証明状態にあるすべての仮定を 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) を使うことで結論を含めすべての仮定が単純化されます: