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

Commit 86cf87e

Browse files
committed
BasicClasses_DerivingHandlers翻訳 (#18)
* 翻訳開始 * 翻訳完了
1 parent fcffe4b commit 86cf87e

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/Language/Classes/BasicClasses.lean

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,63 @@ 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

60+
:::
61+
62+
# 決定可能性(Decidability)
63+
64+
:::comment
4165
A proposition is {deftech}_decidable_ if it can be checked algorithmically.{index}[decidable]{index subterm:="decidable"}[proposition]
4266
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.
4367
By default, only algorithmic {lean}`Decidable` instances for which code can be generated are in scope; opening the `Classical` namespace makes every proposition decidable.
4468

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

4775
{docstring DecidableRel}
@@ -52,9 +80,17 @@ By default, only algorithmic {lean}`Decidable` instances for which code can be g
5280

5381
{docstring Decidable.byCases}
5482

55-
::::keepEnv
56-
:::example "Excluded Middle and {lean}`Decidable`"
83+
:::::keepEnv
84+
:::comment
85+
::example "Excluded Middle and {lean}`Decidable`"
86+
:::
87+
::::example "排中律と {lean}`Decidable`"
88+
:::comment
5789
The equality of functions from {lean}`Nat` to {lean}`Nat` is not decidable:
90+
:::
91+
92+
{lean}`Nat` から {lean}`Nat` への関数の等価性は決定不可能です:
93+
5894
```lean (error:=true) (name := NatFunNotDecEq)
5995
example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
6096
```
@@ -64,24 +100,39 @@ failed to synthesize
64100
Additional diagnostic information may be available using the `set_option diagnostics true` command.
65101
```
66102

103+
:::comment
67104
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.
105+
:::
106+
107+
`Classical` を開くと、すえbての命題が決定可能になります;しかし、この事実を使用する宣言と例には、コードを生成すべきでないことを示すために {keywordOf Lean.Parser.Command.declaration}`noncomputable` とマークしなければなりません。
108+
68109
```lean
69110
open Classical
70111
noncomputable example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
71112
```
72113

73-
:::
74114
::::
115+
:::::
75116

76117

118+
:::comment
77119
# Inhabited Types
78120

121+
:::
122+
123+
# inhabited な型(Inhabited Types)
124+
79125
{docstring Inhabited}
80126

81127
{docstring Nonempty}
82128

129+
:::comment
83130
# Visible Representations
84131

132+
:::
133+
134+
# 表現の可視化(Visible Representations)
135+
85136
:::planned 135
86137

87138
* How to write a correct {name}`Repr` instance
@@ -94,8 +145,13 @@ noncomputable example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
94145

95146
{docstring ToString}
96147

148+
:::comment
97149
# Arithmetic and Bitwise Operators
98150

151+
:::
152+
153+
# 算術・ビット演算子(Arithmetic and Bitwise Operators)
154+
99155
{docstring Zero}
100156

101157
{docstring NeZero}
@@ -146,14 +202,24 @@ noncomputable example (f g : Nat → Nat) : Decidable (f = g) := inferInstance
146202

147203
{docstring HXor}
148204

205+
:::comment
149206
# Append
150207

208+
:::
209+
210+
# 結合(Append)
211+
151212
{docstring HAppend}
152213

153214
{docstring Append}
154215

216+
:::comment
155217
# Data Lookups
156218

219+
:::
220+
221+
# データの検索(Data Lookups)
222+
157223
{docstring GetElem}
158224

159225
{docstring GetElem?}

Manual/Language/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)