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

Commit 4226502

Browse files
committed
コメントアウト位置修正
1 parent 7c2db83 commit 4226502

File tree

1 file changed

+76
-34
lines changed
  • functional-programming-lean/src/getting-to-know

1 file changed

+76
-34
lines changed

functional-programming-lean/src/getting-to-know/summary.md

+76-34
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,155 @@
1-
<!-- # Summary -->
1+
<!--
2+
# Summary
3+
-->
24

35
# まとめ
46

5-
<!-- ## Evaluating Expressions -->
7+
<!--
8+
## Evaluating Expressions
9+
-->
610

711
## 式の評価
812

9-
<!-- In Lean, computation occurs when expressions are evaluated.
13+
<!--
14+
In Lean, computation occurs when expressions are evaluated.
1015
This follows the usual rules of mathematical expressions: sub-expressions are replaced by their values following the usual order of operations, until the entire expression has become a value.
11-
When evaluating an `if` or a `match`, the expressions in the branches are not evaluated until the value of the condition or the match subject has been found. -->
16+
When evaluating an `if` or a `match`, the expressions in the branches are not evaluated until the value of the condition or the match subject has been found.
17+
-->
1218

1319
Leanでは,式が評価されるときに計算も行われます.これは数式の通常のルールに従って行われます:式全体が値になるまで,通常の演算順序に従って部分式が値で置き換えられます.`if``match` を評価する場合,条件の値やマッチの対象が見つかるまでは枝の中の式は評価されません.
1420

15-
<!-- Once they have been given a value, variables never change.
21+
<!--
22+
Once they have been given a value, variables never change.
1623
Similarly to mathematics but unlike most programming languages, Lean variables are simply placeholders for values, rather than addresses to which new values can be written.
17-
Variables' values may come from global definitions with `def`, local definitions with `let`, as named arguments to functions, or from pattern matching. -->
24+
Variables' values may come from global definitions with `def`, local definitions with `let`, as named arguments to functions, or from pattern matching.
25+
-->
1826

1927
一度値が与えられると,変数は決して変化しません.これは数学と似ている一方でほとんどのプログラミング言語と異なった性質です.Leanの変数は単に値のプレースホルダであり,新しい値を書き込むことができるアドレスではありません.変数の値は `def` によるグローバル定義,`let` によるローカル定義,関数への名前付き引数,パターンマッチによって得られます.
2028

21-
<!-- ## Functions -->
29+
<!--
30+
## Functions
31+
-->
2232

2333
## 関数
2434

25-
<!-- Functions in Lean are first-class values, meaning that they can be passed as arguments to other functions, saved in variables, and used like any other value.
35+
<!--
36+
Functions in Lean are first-class values, meaning that they can be passed as arguments to other functions, saved in variables, and used like any other value.
2637
Every Lean function takes exactly one argument.
2738
To encode a function that takes more than one argument, Lean uses a technique called currying, where providing the first argument returns a function that expects the remaining arguments.
28-
To encode a function that takes no arguments, Lean uses the `Unit` type, which is the least informative possible argument. -->
39+
To encode a function that takes no arguments, Lean uses the `Unit` type, which is the least informative possible argument.
40+
-->
2941

3042
Leanにおいて関数は第一級です.つまり,関数をほかの関数に引数として渡したり,変数に保存したり,ほかの値と同じように使用することができます.Leanのすべての関数は必ず1つの引数を取ります.2つ以上の引数を取る関数を実装する場合には,Leanはカリー化と呼ばれるテクニックを使います.これは複数引数のうち最初の引数を受け取ってそれ以降の引数を受け取るような関数を返すようにするものです.引数を取らない関数を実装する場合には,Leanでは `Unit` 型という引数として最低限の情報を持つ型を使用します.
3143

32-
<!-- There are three primary ways of creating functions: -->
44+
<!--
45+
There are three primary ways of creating functions:
46+
-->
3347

3448
関数の実装方法は主に以下の3つがあります:
3549

36-
<!-- 1. Anonymous functions are written using `fun`.
37-
For instance, a function that swaps the fields of a `Point` can be written `{{#example_in Examples/Intro.lean swapLambda}}` -->
50+
<!--
51+
1. Anonymous functions are written using `fun`.
52+
For instance, a function that swaps the fields of a `Point` can be written `{{#example_in Examples/Intro.lean swapLambda}}`
53+
-->
3854
1. `fun` を用いた無名関数.例として,`Point` のフィールドの交換を行う関数は `{{#example_in Examples/Intro.lean swapLambda}}` と書くことができます.
39-
<!-- 2. Very simple anonymous functions are written by placing one or more centered dots `·` inside of parentheses.
55+
<!--
56+
2. Very simple anonymous functions are written by placing one or more centered dots `·` inside of parentheses.
4057
Each centered dot becomes an argument to the function, and the parentheses delimit its body.
41-
For instance, a function that subtracts one from its argument can be written as `{{#example_in Examples/Intro.lean subOneDots}}` instead of as `{{#example_out Examples/Intro.lean subOneDots}}`. -->
58+
For instance, a function that subtracts one from its argument can be written as `{{#example_in Examples/Intro.lean subOneDots}}` instead of as `{{#example_out Examples/Intro.lean subOneDots}}`.
59+
-->
4260
2. 括弧の中で一つ以上の中黒点を置いた非常にシンプルな無名関数.各中黒点は関数の引数になり,括弧は関数の本体の範囲を仕切ります.例として,引数から1を引く関数 `{{#example_in Examples/Intro.lean subOneDots}}` の代わりに `{{#example_out Examples/Intro.lean subOneDots}}` とも書けます.
43-
<!-- 3. Functions can be defined using `def` or `let` by adding an argument list or by using pattern-matching notation. -->
61+
<!--
62+
3. Functions can be defined using `def` or `let` by adding an argument list or by using pattern-matching notation.
63+
-->
4464
3. `def``let` に引数のリストかパターンマッチ記法を続けるようにして定義した関数.
4565

46-
<!-- ## Types -->
66+
<!--
67+
## Types
68+
-->
4769

4870
##
4971

50-
<!-- Lean checks that every expression has a type.
72+
<!--
73+
Lean checks that every expression has a type.
5174
Types, such as `Int`, `Point`, `{α : Type} → Nat → α → List α`, and `Option (String ⊕ (Nat × String))`, describe the values that may eventually be found for an expression.
5275
Like other languages, types in Lean can express lightweight specifications for programs that are checked by the Lean compiler, obviating the need for certain classes of unit test.
5376
Unlike most languages, Lean's types can also express arbitrary mathematics, unifying the worlds of programming and theorem proving.
54-
While using Lean for proving theorems is mostly out of scope for this book, _[Theorem Proving in Lean 4](https://leanprover.github.io/theorem_proving_in_lean4/)_ contains more information on this topic. -->
77+
While using Lean for proving theorems is mostly out of scope for this book, _[Theorem Proving in Lean 4](https://leanprover.github.io/theorem_proving_in_lean4/)_ contains more information on this topic.
78+
-->
5579

5680
Leanはすべての式が型を持っていることをチェックします.Leanでの型とは何かしらの式について最終的に見つかるかもしれない値を記述したもので,例えば `Int``Potin``{α : Type} → Nat → α → List α``Option (String ⊕ (Nat × String))` のようなものになります.ほかの言語と同様に,Leanの型はLeanのコンパイラによってチェックされるプログラムのための軽量な仕様を表現することができ,一部の単体テストの必要性を排除します.ほとんどの言語とは異なり,Leanの型は任意の数学も表現でき,プログラミングと定理証明の世界を統合しています.Leanを定理証明に使うことは本書の範囲外ですが, _[Theorem Proving in Lean 4](https://leanprover.github.io/theorem_proving_in_lean4/)_ にてこのトピックに関する詳細な情報があります.[^1]
5781

58-
<!-- Some expressions can be given multiple types.
82+
<!--
83+
Some expressions can be given multiple types.
5984
For instance, `3` can be an `Int` or a `Nat`.
60-
In Lean, this should be understood as two separate expressions, one with type `Nat` and one with type `Int`, that happen to be written in the same way, rather than as two different types for the same thing. -->
85+
In Lean, this should be understood as two separate expressions, one with type `Nat` and one with type `Int`, that happen to be written in the same way, rather than as two different types for the same thing.
86+
-->
6187

6288
式の中には複数の型を指定できるものもあります.例えば,`3``Int` にも `Nat` にもなります.Leanでは,これは同じものに対して2つの異なる型あるというよりも,一つは `Nat` 型でもう一つは `Int` 型である2つの別々の式がたまたま同じように書かれたと理解すべきです.
6389

64-
<!-- Lean is sometimes able to determine types automatically, but types must often be provided by the user.
90+
<!--
91+
Lean is sometimes able to determine types automatically, but types must often be provided by the user.
6592
This is because Lean's type system is so expressive.
6693
Even when Lean can find a type, it may not find the desired type—`3` could be intended to be used as an `Int`, but Lean will give it the type `Nat` if there are no further constraints.
6794
In general, it is a good idea to write most types explicitly, only letting Lean fill out the very obvious types.
68-
This improves Lean's error messages and helps make programmer intent more clear. -->
95+
This improves Lean's error messages and helps make programmer intent more clear.
96+
-->
6997

7098
Leanは自動的に型を決定できることもありますが,多くの場合,型はユーザによって提供されなければなりません.これはLeanの型システムが非常に表現力豊かだからです.仮にLeanが型を見つけることが出来たとしても,それが期待した型ではない可能性があります.`3``Int` として使用されることを意図しているかもしれませんが,一切制約がない場合,Leanは `Nat` という型を与えます.一般的に,ほとんどの型は明示的に記述し,非常に明白な型はLeanに埋めてもらうようにするとよいでしょう.これはLeanのエラーメッセージを改善し,プログラマの意図をより明確にするのに役立ちます.
7199

72-
<!-- Some functions or datatypes take types as arguments.
100+
<!--
101+
Some functions or datatypes take types as arguments.
73102
They are called _polymorphic_.
74103
Polymorphism allows programs such as one that calculates the length of a list without caring what type the entries in the list have.
75104
Because types are first class in Lean, polymorphism does not require any special syntax, so types are passed just like other arguments.
76-
Giving an argument a name in a function type allows later types to mention that argument, and the type of applying that function to an argument is found by replacing the argument's name with the argument's value. -->
105+
Giving an argument a name in a function type allows later types to mention that argument, and the type of applying that function to an argument is found by replacing the argument's name with the argument's value.
106+
-->
77107

78108
関数やデータ型の中には,型を引数に取るものがあります.これは **多相性** (polymorphic)と呼ばれます.多相性によって,リストの要素がどの型を持っているかを気にせずにリストの長さを計算するようなプログラムが可能になります.型はLeanにおいて第一級であるため,多相性は特別な構文を必要とせず,型はほかの引数と同じように渡されます.関数型において型引数に名前を与えることで,後の型がその引数に言及できるようになり,その関数を引数に適用した型は引数の名前を引数の値に置き換えることで求められます.
79109

80-
<!-- ## Structures and Inductive Types -->
110+
<!--
111+
## Structures and Inductive Types
112+
-->
81113

82114
## 構造体と帰納的型
83115

84-
<!-- Brand new datatypes can be introduced to Lean using the `structure` or `inductive` features.
116+
<!--
117+
Brand new datatypes can be introduced to Lean using the `structure` or `inductive` features.
85118
These new types are not considered to be equivalent to any other type, even if their definitions are otherwise identical.
86119
Datatypes have _constructors_ that explain the ways in which their values can be constructed, and each constructor takes some number of arguments.
87-
Constructors in Lean are not the same as constructors in object-oriented languages: Lean's constructors are inert holders of data, rather than active code that initializes an allocated object. -->
120+
Constructors in Lean are not the same as constructors in object-oriented languages: Lean's constructors are inert holders of data, rather than active code that initializes an allocated object.
121+
-->
88122

89123
Leanでは `structure``inductive` の機能を使って,全く新しいデータ型を導入することができます.これらの新しいデータ型はたとえ定義が同じであったとしても他のデータ型と同じであるとはみなされません.データ型はその値を構築する方法を説明する **コンストラクタ** (constructor)を持ち,各コンストラクタはいくつかの引数を取ります.Leanのコンストラクタはオブジェクト指向言語のコンストラクタとは異なります:Leanのコンストラクタは,割り当てられたオブジェクトを初期化するアクティブなコードではなく,データを保持する不活性なものです.
90124

91-
<!-- Typically, `structure` is used to introduce a product type (that is, a type with just one constructor that takes any number of arguments), while `inductive` is used to introduce a sum type (that is, a type with many distinct constructors).
125+
<!--
126+
Typically, `structure` is used to introduce a product type (that is, a type with just one constructor that takes any number of arguments), while `inductive` is used to introduce a sum type (that is, a type with many distinct constructors).
92127
Datatypes defined with `structure` are provided with one accessor function for each of the constructor's arguments.
93128
Both structures and inductive datatypes may be consumed with pattern matching, which exposes the values stored inside of constructors using a subset of the syntax used to call said constructors.
94-
Pattern matching means that knowing how to create a value implies knowing how to consume it. -->
129+
Pattern matching means that knowing how to create a value implies knowing how to consume it.
130+
-->
95131

96132
一般的に,`sturucture` は直積型(つまり,任意の数の引数を取るコンストラクタを1つだけ持つ型)を導入するために使用され,`inductive` は直和型(つまり,多数の異なるコンストラクタを持つ型)を導入するために使用されます.`sturucture` で定義されたデータ型はコンストラクタの引数ごとにアクセサ関数が提供されます.構造体と帰納的データ型のどちらもパターンマッチにかけることができます.パターンマッチはコンストラクタを呼び出すために使用される構文のサブセットを使用して,コンストラクタの内部に格納されている値を展開します.パターンマッチは,値の作成方法を知るにはその値を消費する方法を知る必要があることを意味します.
97133

98-
<!-- ## Recursion -->
134+
<!--
135+
## Recursion
136+
-->
99137

100138
## 再帰
101139

102-
<!-- A definition is recursive when the name being defined is used in the definition itself.
140+
<!--
141+
A definition is recursive when the name being defined is used in the definition itself.
103142
Because Lean is an interactive theorem prover in addition to being a programming language, there are certain restrictions placed on recursive definitions.
104-
In Lean's logical side, circular definitions could lead to logical inconsistency. -->
143+
In Lean's logical side, circular definitions could lead to logical inconsistency.
144+
-->
105145

106146
定義されている名前がその定義自体で使われている場合,定義は再帰的です.Leanはプログラミング言語であると同時に対話型定理証明機であるため,再帰的定義には一定の制限があります.Leanの論理的な側面では,循環的な定義は論理的な矛盾につながる可能性があります.
107147

108-
<!-- In order to ensure that recursive definitions do not undermine the logical side of Lean, Lean must be able to prove that all recursive functions terminate, no matter what arguments they are called with.
148+
<!--
149+
In order to ensure that recursive definitions do not undermine the logical side of Lean, Lean must be able to prove that all recursive functions terminate, no matter what arguments they are called with.
109150
In practice, this means either that recursive calls are all performed on a structurally-smaller piece of the input, which ensures that there is always progress towards a base case, or that users must provide some other evidence that the function always terminates.
110-
Similarly, recursive inductive types are not allowed to have a constructor that takes a function _from_ the type as an argument, because this would make it possible to encode non-terminating functions. -->
151+
Similarly, recursive inductive types are not allowed to have a constructor that takes a function _from_ the type as an argument, because this would make it possible to encode non-terminating functions.
152+
-->
111153

112154
再帰的定義がLeanの論理的側面を損なわないようにするために,Leanは再帰関数がどのような引数で呼び出されたとしても,すべての再帰関数が終了することを証明できなければなりません.実用としては,これは①再帰的な呼び出しがすべて入力の構造的に小さい部分で実行され,常にその構造の基底のケースに向かって進むことを保証するか,②ユーザが関数が常に終了するという他の証拠を提供する必要があること,のどちらかを意味します.同様に,再帰的帰納型はその型を引数として **受け取る** 関数を取るコンストラクタを持つことはできません.なぜならこれは終了しない関数の実装を可能にするからです.
113155

0 commit comments

Comments
 (0)