このCoqのコードは、Ltac2を使用して、Coqの証明アシスタント内で再書き込み(rewrite)戦術をより細かく制御するためのデータ型と外部関数を定義しています。以下に各部分の詳細な解説を提供します。
1. 基本的な型定義
coq
Ltac2 Type evar_flag := bool.
evar_flag は、存在変数(evar)の扱い方を指定するためのフラグです。bool 型なので、true または false のいずれかになります。true の場合、再書き込み中に存在変数が生成されることを許容します。
coq
Ltac2 Type orientation := [ LTR | RTL ].
orientation は、再書き込みの方向を指定します。LTR(Left-To-Right)は左から右への再書き込み、RTL(Right-To-Left)は右から左への再書き込みを表します。
coq
Ltac2 Type repeat := [
| Precisely (int)
| UpTo (int)
| RepeatStar
| RepeatPlus
].
repeat は、再書き込みの繰り返し回数を指定します。
Precisely (int): 정확히指定された回数だけ再書き込みを行います。
UpTo (int): 指定された回数まで再書き込みを行いますが、それ未満でも停止します。
RepeatStar: 0回以上の再書き込みを行います(Kleene star)。
RepeatPlus: 1回以上の再書き込みを行います(Kleene plus)。
coq
Ltac2 Type hypothesis := [ AnonHyp (int) | NamedHyp (ident) ].
hypothesis は、仮説(hypothesis)を指定するための型です。
AnonHyp (int): 無名仮説をインデックスで指定します。
NamedHyp (ident): 名前付き仮説を識別子(ident)で指定します。
coq
Ltac2 Type bindings := [
| NoBindings
| ImplicitBindings (constr list)
| ExplicitBindings ((hypothesis * constr) list)
].
bindings は、再書き込み時に使用される束縛(bindings)を指定します。
NoBindings: 束縛なし。
ImplicitBindings (constr list): 暗黙の束縛を constr のリストで指定します。
ExplicitBindings ((hypothesis * constr) list): 明示的な束縛を、仮説と constr のペアリストで指定します。
coq
Ltac2 Type constr_with_bindings := constr * bindings.
constr_with_bindings は、Coqの項(constr)とその項に関連する束縛(bindings)のペアを表します。
coq
Ltac2 Type rewriting := {
rew_orient : orientation option;
rew_repeat : repeat;
rew_equatn : (unit -> constr_with_bindings);
}.
rewriting は、再書き込み操作を記述するためのレコード型です。
rew_orient: 再書き込みの方向を指定します(None の場合はデフォルトの方向を使用)。
rew_repeat: 再書き込みの繰り返し回数を指定します。
rew_equatn: 再書き込みに使用する等式(equation)を生成する関数です。この関数は unit を受け取り、constr_with_bindings を返します。
2. 外部関数の定義
coq
Ltac2 @ external rewrite : evar_flag -> rewriting list -> clause -> (unit -> unit) option -> unit := "rocq-runtime.plugins.ltac2" "tac_rewrite".
- この行は、Ltac2の外部関数
rewrite を定義しています。この関数は、Coqのランタイムシステム(rocq-runtime.plugins.ltac2)に実装された tac_rewrite 関数にバインドされています。
- 引数:
evar_flag: 存在変数の扱い方を指定するフラグ。
rewriting list: 再書き込み操作のリスト。各操作は rewriting 型で記述されます。
clause: 再書き込みの対象となる目標(goal)または仮説を指定する句(clause)。
(unit -> unit) option: 再書き込み後の後処理を指定するオプションの関数。None の場合は後処理を行いません。
- 戻り値:
unit。この関数は副作用として再書き込みを行います。
まとめ
このコードは、CoqのLtac2を使用して、再書き込み戦術を細かく制御するためのデータ型と外部関数を定義しています。これにより、ユーザーは再書き込みの方向、繰り返し回数、束縛、および存在変数の扱い方などを詳細に指定することができます。外部関数 rewrite は、これらの設定に基づいて実際の再書き込み操作を実行します。