Skip to content
This repository was archived by the owner on Jan 5, 2025. It is now read-only.

Commit 3026bb9

Browse files
authored
10_cheat-sheet (#11)
* 翻訳開始 * 翻訳完了
1 parent 39a2b7e commit 3026bb9

File tree

2 files changed

+93
-5
lines changed

2 files changed

+93
-5
lines changed

lean/main/10_cheat-sheet.lean

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
/-
2+
--#--
23
# Lean4 Cheat-sheet
34
5+
--#--
6+
# Lean4 チートシート
7+
8+
--#--
49
## Extracting information
510
11+
--#--
12+
## 情報の抽出
13+
14+
--#--
615
* Extract the goal: `Lean.Elab.Tactic.getMainGoal`
716
17+
--#--
18+
* ゴールの抽出:`Lean.Elab.Tactic.getMainGoal`
19+
20+
--#--
821
Use as `let goal ← Lean.Elab.Tactic.getMainGoal`
922
* Extract the declaration out of a metavariable: `mvarId.getDecl`
1023
when `mvarId : Lean.MVarId` is in context.
@@ -13,53 +26,128 @@
1326
when `mvarId : Lean.MVarId` is in context.
1427
* Extract the type of the main goal: `Lean.Elab.Tactic.getMainTarget`
1528
29+
--#--
30+
これは `let goal ← Lean.Elab.Tactic.getMainGoal` のように使います。
31+
* メタ変数からの宣言の抽出:`mvarId.getDecl`、ここで `mvarId : Lean.MVarId` がコンテキストにあるとします。例えば、ゴールの `mvarId` は `getMainGoal` を使用して抽出することができます。
32+
* メタ変数の型の抽出:`mvarId.getType`、ここで `mvarId : Lean.MVarId` がコンテキストにあるとします。
33+
* メインのゴールの型の抽出:`Lean.Elab.Tactic.getMainTarget`
34+
35+
--#--
1636
Use as `let goal_type ← Lean.Elab.Tactic.getMainTarget`
1737
18-
Achieves the same as
38+
--#--
39+
これは `let goal_type ← Lean.Elab.Tactic.getMainTarget` のように使います。
40+
41+
--#--
42+
Achieves the same as
43+
--#--
44+
これは下記と同じ結果になります。
45+
1946
```lean
2047
let goal ← Lean.Elab.Tactic.getMainGoal
2148
let goal_type ← goal.getType
2249
```
50+
--#--
2351
* Extract local context: `Lean.MonadLCtx.getLCtx`
2452
53+
--#--
54+
* ローカルコンテキストの抽出:`Lean.MonadLCtx.getLCtx`
55+
56+
--#--
2557
Use as `let lctx ← Lean.MonadLCtx.getLCtx`
2658
* Extract the name of a declaration: `Lean.LocalDecl.userName ldecl`
2759
when `ldecl : Lean.LocalDecl` is in context
2860
* Extract the type of an expression: `Lean.Meta.inferType expr`
2961
when `expr : Lean.Expr` is an expression in context
3062
63+
--#--
64+
これは `let lctx ← Lean.MonadLCtx.getLCtx` のように使います。
65+
* 宣言の名前の抽出:`Lean.LocalDecl.userName ldecl`、ここで `ldecl : Lean.LocalDecl` がコンテキストにあるとします。
66+
* 式の型の抽出:`Lean.Meta.inferType expr`、ここで `expr : Lean.Expr` がコンテキストにあるとします。
67+
68+
--#--
3169
Use as `let expr_type ← Lean.Meta.inferType expr`
3270
71+
--#--
72+
これは `let expr_type ← Lean.Meta.inferType expr` のように使います。
73+
74+
75+
--#--
3376
## Playing around with expressions
3477
78+
--#--
79+
## 式で遊ぶ
80+
81+
--#--
3582
* Convert a declaration into an expression: `Lean.LocalDecl.toExpr`
36-
83+
84+
--#--
85+
* 宣言を式に変換する:`Lean.LocalDecl.toExpr`
86+
87+
--#--
3788
Use as `ldecl.toExpr`, when `ldecl : Lean.LocalDecl` is in context
38-
89+
90+
--#--
91+
これは `ldecl : Lean.LocalDecl` がコンテキストにある場合に `ldecl.toExpr` のように使います。
92+
93+
--#--
3994
For instance, `ldecl` could be `let ldecl ← Lean.MonadLCtx.getLCtx`
4095
* Check whether two expressions are definitionally equal: `Lean.Meta.isDefEq ex1 ex2`
4196
when `ex1 ex2 : Lean.Expr` are in context. Returns a `Lean.MetaM Bool`
4297
* Close a goal: `Lean.Elab.Tactic.closeMainGoal expr`
4398
when `expr : Lean.Expr` is in context
4499
100+
--#--
101+
この `ldecl` は例えば、`let ldecl ← Lean.MonadLCtx.getLCtx` などで取得されます。
102+
* 2つの式が定義上等しいかどうかのチェック:`Lean.Meta.isDefEq ex1 ex2`、ここで `ex1 ex2 : Lean.Expr` がコンテキストにあるとします。これは `Lean.MetaM Bool` を返します。
103+
* ゴールを閉じる:`Lean.Elab.Tactic.closeMainGoal expr`、ここで `expr : Lean.Expr` がコンテキストにあるとします。
104+
105+
--#--
45106
## Further commands
46107
108+
--#--
109+
## さらなるコマンド
110+
111+
--#--
47112
* meta-sorry: `Lean.Elab.admitGoal goal`, when `goal : Lean.MVarId` is the current goal
48113
114+
--#--
115+
* メタ-sorry:`Lean.Elab.admitGoal goal`、ここで `goal : Lean.MVarId` がコンテキストにあるとします。
116+
117+
--#--
49118
## Printing and errors
50119
120+
--#--
121+
## 表示とエラー
122+
123+
--#--
51124
* Print a "permanent" message in normal usage:
52125
126+
--#--
127+
* 通常の用途での「永久な」メッセージの表示:
128+
53129
`Lean.logInfo f!"Hi, I will print\n{Syntax}"`
130+
--#--
54131
* Print a message while debugging:
55132
133+
--#--
134+
* デバッグ中のメッセージの表示:
135+
56136
`dbg_trace f!"1) goal: {Syntax_that_will_be_interpreted}"`.
137+
--#--
57138
* Throw an error: `Lean.Meta.throwTacticEx name mvar message_data`
58139
where `name : Lean.Name` is the name of a tactic and `mvar` contains error data.
59-
140+
141+
--#--
142+
* 例外を投げる:`Lean.Meta.throwTacticEx name mvar message_data`、ここで `name : Lean.Name` はタクティクの名前で `mvar` はエラーのデータを保持しているとします。
143+
144+
--#--
60145
Use as `Lean.Meta.throwTacticEx `tac goal (m!"unable to find matching hypothesis of type ({goal_type})")`
61146
where the `m!` formatting builds a `MessageData` for better printing of terms
62147
148+
--#--
149+
これは ``Lean.Meta.throwTacticEx `tac goal (m!"unable to find matching hypothesis of type ({goal_type})")`` のように用い、ここでフォーマッタ `m!` は項をより見やすく表示する `MessageData` を構築します。
150+
63151
TODO: Add?
64152
* Lean.LocalContext.forM
65153
* Lean.LocalContext.findDeclM?

md/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- [エラボレーション](./main/07_elaboration.md)
1414
- [エラボレーションによる DSL の埋め込み](./main/08_dsls.md)
1515
- [タクティク](./main/09_tactics.md)
16-
- [Lean4 Cheat-sheet](./main/10_cheat-sheet.md)
16+
- [Lean4 チートシート](./main/10_cheat-sheet.md)
1717

1818
<!-- # Extra -->
1919

0 commit comments

Comments
 (0)