|
1 | 1 | /-
|
| 2 | +--#-- |
2 | 3 | # Lean4 Cheat-sheet
|
3 | 4 |
|
| 5 | +--#-- |
| 6 | +# Lean4 チートシート |
| 7 | +
|
| 8 | +--#-- |
4 | 9 | ## Extracting information
|
5 | 10 |
|
| 11 | +--#-- |
| 12 | +## 情報の抽出 |
| 13 | +
|
| 14 | +--#-- |
6 | 15 | * Extract the goal: `Lean.Elab.Tactic.getMainGoal`
|
7 | 16 |
|
| 17 | +--#-- |
| 18 | +* ゴールの抽出:`Lean.Elab.Tactic.getMainGoal` |
| 19 | +
|
| 20 | +--#-- |
8 | 21 | Use as `let goal ← Lean.Elab.Tactic.getMainGoal`
|
9 | 22 | * Extract the declaration out of a metavariable: `mvarId.getDecl`
|
10 | 23 | when `mvarId : Lean.MVarId` is in context.
|
|
13 | 26 | when `mvarId : Lean.MVarId` is in context.
|
14 | 27 | * Extract the type of the main goal: `Lean.Elab.Tactic.getMainTarget`
|
15 | 28 |
|
| 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 | +--#-- |
16 | 36 | Use as `let goal_type ← Lean.Elab.Tactic.getMainTarget`
|
17 | 37 |
|
18 |
| - Achieves the same as |
| 38 | +--#-- |
| 39 | + これは `let goal_type ← Lean.Elab.Tactic.getMainTarget` のように使います。 |
| 40 | +
|
| 41 | +--#-- |
| 42 | + Achieves the same as |
| 43 | +--#-- |
| 44 | + これは下記と同じ結果になります。 |
| 45 | +
|
19 | 46 | ```lean
|
20 | 47 | let goal ← Lean.Elab.Tactic.getMainGoal
|
21 | 48 | let goal_type ← goal.getType
|
22 | 49 | ```
|
| 50 | +--#-- |
23 | 51 | * Extract local context: `Lean.MonadLCtx.getLCtx`
|
24 | 52 |
|
| 53 | +--#-- |
| 54 | +* ローカルコンテキストの抽出:`Lean.MonadLCtx.getLCtx` |
| 55 | +
|
| 56 | +--#-- |
25 | 57 | Use as `let lctx ← Lean.MonadLCtx.getLCtx`
|
26 | 58 | * Extract the name of a declaration: `Lean.LocalDecl.userName ldecl`
|
27 | 59 | when `ldecl : Lean.LocalDecl` is in context
|
28 | 60 | * Extract the type of an expression: `Lean.Meta.inferType expr`
|
29 | 61 | when `expr : Lean.Expr` is an expression in context
|
30 | 62 |
|
| 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 | +--#-- |
31 | 69 | Use as `let expr_type ← Lean.Meta.inferType expr`
|
32 | 70 |
|
| 71 | +--#-- |
| 72 | + これは `let expr_type ← Lean.Meta.inferType expr` のように使います。 |
| 73 | +
|
| 74 | +
|
| 75 | +--#-- |
33 | 76 | ## Playing around with expressions
|
34 | 77 |
|
| 78 | +--#-- |
| 79 | +## 式で遊ぶ |
| 80 | +
|
| 81 | +--#-- |
35 | 82 | * Convert a declaration into an expression: `Lean.LocalDecl.toExpr`
|
36 |
| - |
| 83 | +
|
| 84 | +--#-- |
| 85 | +* 宣言を式に変換する:`Lean.LocalDecl.toExpr` |
| 86 | +
|
| 87 | +--#-- |
37 | 88 | Use as `ldecl.toExpr`, when `ldecl : Lean.LocalDecl` is in context
|
38 |
| - |
| 89 | +
|
| 90 | +--#-- |
| 91 | + これは `ldecl : Lean.LocalDecl` がコンテキストにある場合に `ldecl.toExpr` のように使います。 |
| 92 | +
|
| 93 | +--#-- |
39 | 94 | For instance, `ldecl` could be `let ldecl ← Lean.MonadLCtx.getLCtx`
|
40 | 95 | * Check whether two expressions are definitionally equal: `Lean.Meta.isDefEq ex1 ex2`
|
41 | 96 | when `ex1 ex2 : Lean.Expr` are in context. Returns a `Lean.MetaM Bool`
|
42 | 97 | * Close a goal: `Lean.Elab.Tactic.closeMainGoal expr`
|
43 | 98 | when `expr : Lean.Expr` is in context
|
44 | 99 |
|
| 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 | +--#-- |
45 | 106 | ## Further commands
|
46 | 107 |
|
| 108 | +--#-- |
| 109 | +## さらなるコマンド |
| 110 | +
|
| 111 | +--#-- |
47 | 112 | * meta-sorry: `Lean.Elab.admitGoal goal`, when `goal : Lean.MVarId` is the current goal
|
48 | 113 |
|
| 114 | +--#-- |
| 115 | +* メタ-sorry:`Lean.Elab.admitGoal goal`、ここで `goal : Lean.MVarId` がコンテキストにあるとします。 |
| 116 | +
|
| 117 | +--#-- |
49 | 118 | ## Printing and errors
|
50 | 119 |
|
| 120 | +--#-- |
| 121 | +## 表示とエラー |
| 122 | +
|
| 123 | +--#-- |
51 | 124 | * Print a "permanent" message in normal usage:
|
52 | 125 |
|
| 126 | +--#-- |
| 127 | +* 通常の用途での「永久な」メッセージの表示: |
| 128 | +
|
53 | 129 | `Lean.logInfo f!"Hi, I will print\n{Syntax}"`
|
| 130 | +--#-- |
54 | 131 | * Print a message while debugging:
|
55 | 132 |
|
| 133 | +--#-- |
| 134 | +* デバッグ中のメッセージの表示: |
| 135 | +
|
56 | 136 | `dbg_trace f!"1) goal: {Syntax_that_will_be_interpreted}"`.
|
| 137 | +--#-- |
57 | 138 | * Throw an error: `Lean.Meta.throwTacticEx name mvar message_data`
|
58 | 139 | 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 | +--#-- |
60 | 145 | Use as `Lean.Meta.throwTacticEx `tac goal (m!"unable to find matching hypothesis of type ({goal_type})")`
|
61 | 146 | where the `m!` formatting builds a `MessageData` for better printing of terms
|
62 | 147 |
|
| 148 | +--#-- |
| 149 | + これは ``Lean.Meta.throwTacticEx `tac goal (m!"unable to find matching hypothesis of type ({goal_type})")`` のように用い、ここでフォーマッタ `m!` は項をより見やすく表示する `MessageData` を構築します。 |
| 150 | +
|
63 | 151 | TODO: Add?
|
64 | 152 | * Lean.LocalContext.forM
|
65 | 153 | * Lean.LocalContext.findDeclM?
|
|
0 commit comments