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

Commit 88371e0

Browse files
committed
BasicClasses_DerivingHandlers翻訳 (#18)
* 翻訳開始 * 翻訳完了
1 parent 254cc72 commit 88371e0

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

GLOSSARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
| term || |
262262
| term elaboration | 項エラボレーション | |
263263
| termination | 停止 | |
264+
| The Law of the Excluded Middle | 排中律 | |
264265
| theorem | 定理 | |
265266
| token | 字句 | |
266267
| top-level | トップレベル | |
@@ -298,6 +299,7 @@
298299
| choice node | |
299300
| cumulative | |
300301
| impredicativity, predicativity | |
302+
| inhabited | |
301303
| no confusion | |
302304
| out, semi-out | |
303305
| packed array | System Verilogという言語にこの名前の文法要素がある? |

Manual/Classes/BasicClasses.lean

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,66 @@ open Manual
1313
open Verso.Genre
1414
open Verso.Genre.Manual
1515

16+
/-
1617
#doc (Manual) "Basic Classes" =>
18+
-/
19+
#doc (Manual) "基本的なクラス(Basic Classes)" =>
1720
%%%
1821
tag := "basic-classes"
1922
%%%
2023

24+
:::comment
2125
Many Lean type classes exist in order to allow built-in notations such as addition or array indexing to be overloaded.
2226

27+
:::
28+
29+
Lean の型クラスの多くは、加算や配列インデックスのような組み込み記法をオーバーロードできるようにするために存在します。
30+
31+
:::comment
2332
# Boolean Equality Tests
2433

34+
:::
35+
36+
# 真偽値上の等価性のテスト(Boolean Equality Tests)
37+
2538
{docstring BEq}
2639

2740
{docstring Hashable}
2841

2942
{docstring LawfulBEq}
3043

44+
:::comment
3145
# Ordering
3246

47+
:::
48+
49+
# 順序(Ordering)
50+
3351
{docstring Ord}
3452

3553
{docstring LT}
3654

3755
{docstring LE}
3856

57+
:::comment
3958
# Decidability
4059
%%%
4160
tag := "decidable-propositions"
4261
%%%
4362

63+
:::
64+
65+
# 決定可能性(Decidability)
66+
67+
:::comment
4468
A proposition is {deftech}_decidable_ if it can be checked algorithmically.{index}[decidable]{index subterm:="decidable"}[proposition]
4569
The Law of the Excluded Middle means that every proposition is true or false, but it provides no way to check which of the two cases holds, which can often be useful.
4670
By default, only algorithmic {lean}`Decidable` instances for which code can be generated are in scope; opening the `Classical` namespace makes every proposition decidable.
4771

72+
:::
73+
74+
アルゴリズム的にチェック可能である命題は {deftech}_決定可能_ (decidable)であると言います。 {index}[decidable]{index subterm:="decidable"}[proposition] 排中律は、すべての命題が真か偽であることを意味しますが、2つのケースのどちらが成り立つかをチェックする方法は提供しません。デフォルトでは、コードを生成できるアルゴリズム的な {lean}`Decidable` インスタンスのみがスコープに含まれます;`Classical` 名前空間を開くと、すべての命題が決定可能になります。
75+
4876
{docstring Decidable}
4977

5078
{docstring DecidableRel}
@@ -55,9 +83,17 @@ By default, only algorithmic {lean}`Decidable` instances for which code can be g
5583

5684
{docstring Decidable.byCases}
5785

58-
::::keepEnv
59-
:::example "Excluded Middle and {lean}`Decidable`"
86+
:::::keepEnv
87+
:::comment
88+
::example "Excluded Middle and {lean}`Decidable`"
89+
:::
90+
::::example "排中律と {lean}`Decidable`"
91+
:::comment
6092
The equality of functions from {lean}`Nat` to {lean}`Nat` is not decidable:
93+
:::
94+
95+
{lean}`Nat` から {lean}`Nat` への関数の等価性は決定不可能です:
96+
6197
```lean (error:=true) (name := NatFunNotDecEq)
6298
example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
6399
```
@@ -67,24 +103,39 @@ failed to synthesize
67103
Additional diagnostic information may be available using the `set_option diagnostics true` command.
68104
```
69105

106+
:::comment
70107
Opening `Classical` makes every proposition decidable; however, declarations and examples that use this fact must be marked {keywordOf Lean.Parser.Command.declaration}`noncomputable` to indicate that code should not be generated for them.
108+
:::
109+
110+
`Classical` を開くと、すえbての命題が決定可能になります;しかし、この事実を使用する宣言と例には、コードを生成すべきでないことを示すために {keywordOf Lean.Parser.Command.declaration}`noncomputable` とマークしなければなりません。
111+
71112
```lean
72113
open Classical
73114
noncomputable example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
74115
```
75116

76-
:::
77117
::::
118+
:::::
78119

79120

121+
:::comment
80122
# Inhabited Types
81123

124+
:::
125+
126+
# inhabited な型(Inhabited Types)
127+
82128
{docstring Inhabited}
83129

84130
{docstring Nonempty}
85131

132+
:::comment
86133
# Visible Representations
87134

135+
:::
136+
137+
# 表現の可視化(Visible Representations)
138+
88139
:::planned 135
89140

90141
* How to write a correct {name}`Repr` instance
@@ -97,8 +148,13 @@ noncomputable example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
97148

98149
{docstring ToString}
99150

151+
:::comment
100152
# Arithmetic and Bitwise Operators
101153

154+
:::
155+
156+
# 算術・ビット演算子(Arithmetic and Bitwise Operators)
157+
102158
{docstring Zero}
103159

104160
{docstring NeZero}
@@ -149,14 +205,24 @@ noncomputable example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
149205

150206
{docstring HXor}
151207

208+
:::comment
152209
# Append
153210

211+
:::
212+
213+
# 結合(Append)
214+
154215
{docstring HAppend}
155216

156217
{docstring Append}
157218

219+
:::comment
158220
# Data Lookups
159221

222+
:::
223+
224+
# データの検索(Data Lookups)
225+
160226
{docstring GetElem}
161227

162228
{docstring GetElem?}

Manual/Classes/DerivingHandlers.lean

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,49 @@ def derivableClassList : DirectiveExpander
4040
let theList ← `(Verso.Doc.Block.ul #[$[⟨0, #[Verso.Doc.Block.para #[$itemStx]]⟩],*])
4141
return #[theList]
4242

43+
/-
4344
#doc (Manual) "Deriving Handlers" =>
45+
-/
46+
#doc (Manual) "導出ハンドラ(Deriving Handlers)" =>
4447
%%%
4548
tag := "deriving-handlers"
4649
%%%
4750

51+
:::comment
4852
Instance deriving uses a table of {deftech}_deriving handlers_ that maps type class names to metaprograms that derive instances for them.
4953
Deriving handlers may be added to the table using {lean}`registerDerivingHandler`, which should be called in an {keywordOf Lean.Parser.Command.initialize}`initialize` block.
5054
Each deriving handler should have the type {lean}`Array Name → CommandElabM Bool`.
5155
When a user requests that an instance of a class be derived, its registered handlers are called one at a time.
5256
They are provided with all of the names in the mutual block for which the instance is to be derived, and should either correctly derive an instance and return {lean}`true` or have no effect and return {lean}`false`.
5357
When a handler returns {lean}`true`, no further handlers are called.
5458

59+
:::
60+
61+
インスタンスの導出は {deftech}_導出ハンドラ_ (deriving handler)のテーブルを使用し、型クラス名をインスタンスを導出するメタプログラムにマッピングします。導出ハンドラは {lean}`registerDerivingHandler` を使用してテーブルに追加することができます。これは {keywordOf Lean.Parser.Command.initialize}`initialize` ブロック内で呼び出す必要があります。それぞれの導出ハンドラは {lean}`Array Name → CommandElabM Bool` 型を持つ必要があります。ユーザがクラスのインスタンス導出を要求すると、登録されているハンドラが1つずつ呼び出されます。これらのハンドラにはインスタンスを導出させる相互ブロック内のすべての名前が提供され、正しくインスタンスを導出した場合は {lean}`true` を、そうでない場合は何もせずに {lean}`false` を返します。ハンドラが {lean}`true` を返すと、それ以降のハンドラは呼び出されません。
62+
63+
:::comment
5564
Lean includes deriving handlers for the following classes:
65+
:::
66+
67+
Lean には以下のクラスの導出ハンドラがあります:
68+
5669
:::derivableClassList
5770
:::
5871

5972
{docstring Lean.Elab.registerDerivingHandler}
6073

6174

62-
::::keepEnv
63-
:::example "Deriving Handlers"
75+
:::::keepEnv
76+
:::comment
77+
::example "Deriving Handlers"
78+
:::
79+
::::example "導出ハンドラ"
80+
:::comment
6481
Instances of the {name}`IsEnum` class demonstrate that a type is a finite enumeration by providing a bijection between the type and a suitably-sized {name}`Fin`:
82+
:::
83+
84+
{name}`IsEnum` クラスのインスタンスは型に対して適切なサイズの {name}`Fin` との間に全単射を提供することによって型が有限に列挙されることを示します:
85+
6586
```lean
6687
class IsEnum (α : Type) where
6788
size : Nat
@@ -71,8 +92,13 @@ class IsEnum (α : Type) where
7192
from_to_id : ∀ (x : α), fromIdx (toIdx x) = x
7293
```
7394

95+
:::comment
7496
For inductive types that are trivial enumerations, where no constructor expects any parameters, instances of this class are quite repetitive.
7597
The instance for `Bool` is typical:
98+
:::
99+
100+
帰納型は自明な列挙であり、コンストラクタがパラメータを期待しない帰納型ではこのクラスのインスタンスにおいては非常に繰り返しが多いコードになります。 `Bool` のインスタンスが典型的です:
101+
76102
```lean
77103
instance : IsEnum Bool where
78104
size := 2
@@ -90,7 +116,12 @@ instance : IsEnum Bool where
90116
| true => rfl
91117
```
92118

119+
:::comment
93120
The deriving handler programmatically constructs each pattern case, by analogy to the {lean}`IsEnum Bool` implementation:
121+
:::
122+
123+
導出ハンドラは {lean}`IsEnum Bool` の実装をなぞるようにそれぞれのパターンのケースをプログラムで構築します:
124+
94125
```lean
95126
open Lean Elab Parser Term Command
96127

@@ -129,5 +160,5 @@ def deriveIsEnum (declNames : Array Name) : CommandElabM Bool := do
129160
initialize
130161
registerDerivingHandler ``IsEnum deriveIsEnum
131162
```
132-
:::
133163
::::
164+
:::::

0 commit comments

Comments
 (0)