This repository was archived by the owner on Aug 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathagda.alfa
More file actions
268 lines (239 loc) · 9.41 KB
/
agda.alfa
File metadata and controls
268 lines (239 loc) · 9.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
{- some general logical concepts and principles -}
rel (A::Set) :: Type
= A -> A -> Set
pred (A::Set) :: Type
= A -> Set
exists :: (A::Set) -> (B::A -> Set) -> Set
= \(A::Set) -> \(B::(x::A) -> Set) -> data Witness (u::A) (v::B u)
existsElim (A::Set)(B::A -> Set)(C::Set)
:: (h1::exists A B) -> (h2::(x::A) -> B x -> C) -> C
= \(h1::exists A B) ->
\(h2::(x::A) -> (x'::B x) -> C) ->
case h1 of { (Witness u v) -> h2 u v;}
and (A::Set)(B::Set) :: Set
= data Pair (a::A) (b::B)
andElimLeft (A::Set)(B::Set) :: and A B -> A
= \(h::and A B) -> case h of { (Pair a b) -> a;}
andElimRight (A::Set)(B::Set) :: and A B -> B
= \(h::and A B) -> case h of { (Pair a b) -> b;}
or (A::Set)(B::Set) :: Set
= data Inl (a::A) | Inr (b::B)
orElim (A::Set)(B::Set)(C::Set) :: (A -> C) -> (B -> C) -> or A B -> C
= \(h1::(x::A) -> C) ->
\(h2::(x::B) -> C) ->
\(h3::or A B) ->
case h3 of {
(Inl a) -> h1 a;
(Inr b) -> h2 b;}
noether (A::Set)(R::rel A) :: Type
= (P::pred A) -> ((x::A) -> ((y::A) -> R y x -> P y) -> P x) -> (x::A) -> P x
N0 :: Set
= data
not (A::Set) :: Set
= A -> N0
{- The principle of infinite descent, following Fermat -}
infiniteDescent (A::Set)
(R::rel A)
(P::pred A)
:: noether A R ->
((x::A) -> P x -> exists A (\(x1::A) -> and (R x1 x) (P x1))) ->
(x::A) -> not (P x)
= \ (h1::noether A R) ->
\ (h2::(x::A) -> P x -> exists A (\(x1::A) -> and (R x1 x) (P x1))) ->
\ (x::A) ->
h1 (\(y::A) -> not (P y))
(\(z::A) ->
\(h3::(y::A) -> (x'::R y z) -> not (P y)) ->
\(h4::P z) ->
existsElim A (\(x1::A) -> and (R x1 z) (P x1)) N0 (h2 z h4)
(\(y::A) ->
\(h5::and (R y z) (P y)) ->
h3 y (andElimLeft (R y z) (P y) h5) (andElimRight (R y z) (P y) h5)))
x
{-# Alfa hiding on
var "not" as "#" with symbolfont
var "existsElim" hide 3
var "or" infix 0 as "#" with symbolfont
var "orElim" hide 3
var "and" infix 0 as "#" with symbolfont
var "andElimLeft" hide 2
var "andElimRight" hide 2
var "N0" as "^" with symbolfont
#-}
--#include "noether.alfa"
{- Definition of commutative monoid; for the main proof, it
will be the monoid N* for multiplication -}
AbMonoid (A::Set)(eq::rel A) :: Set
= sig {ref :: (x::A) -> eq x x;
sym :: (x::A) -> (y::A) -> eq x y -> eq y x;
trans :: (x::A) -> (y::A) -> (z::A) -> eq x y -> eq y z -> eq x z;
ss :: A -> A -> A;
cong ::
(x1::A) ->
(x2::A) ->
(y1::A) ->
(y2::A) ->
eq x1 x2 -> eq y1 y2 -> eq (ss x1 y1) (ss x2 y2);
assoc :: (x::A) -> (y::A) -> (z::A) -> eq (ss x (ss y z)) (ss (ss x y) z);
comm :: (x::A) -> (y::A) -> eq (ss x y) (ss y x);}
{- A beginning of the theory of commutative monoid -}
package ThAbMonoid (A::Set)(eq::rel A)(m::AbMonoid A eq) where
open m use ref, sym, trans, cong, ss, assoc, comm
square (x::A) :: A
= ss x x
multiple (p::A) :: rel A
= \(x::A) -> \(y::A) -> eq (ss p x) y
congLeft (x::A)(y::A)(z::A) :: eq y z -> eq (ss y x) (ss z x)
= \(h::eq y z) -> cong y z x x h (ref x)
congRight (x::A)(y::A)(z::A) :: eq y z -> eq (ss x y) (ss x z)
= \(h::eq y z) -> cong x x y z (ref x) h
lemma0 (x::A)(y::A)(z::A) :: eq x z -> eq y z -> eq x y
= \(h::eq x z) -> \(h'::eq y z) -> trans x z y h (sym y z h')
lemma2 (x::A)(y::A) :: eq x y -> eq (square x) (square y)
= \(h::eq x y) -> cong x y x y h h
lemma3 (x::A)(y::A)(z::A) :: eq (ss x (ss y z)) (ss y (ss x z))
= lemma0 (ss x (ss y z)) (ss y (ss x z)) (ss (ss x y) z) (assoc x y z)
(trans (ss y (ss x z)) (ss (ss y x) z) (ss (ss x y) z) (assoc y x z)
(congLeft z (ss y x) (ss x y) (comm y x)))
lemma4 (x::A)(y::A) :: eq (ss x (ss x (square y))) (square (ss x y))
= trans (ss x (ss x (square y))) (ss x (ss y (ss x y))) (square (ss x y))
(congRight x (ss x (square y)) (ss y (ss x y)) (lemma3 x y y))
(assoc x y (ss x y))
lemma5 (p::A)(y::A)(y1::A)
:: eq (ss p y1) y -> eq (ss p (ss p (square y1))) (square y)
= \(h::multiple p y1 y) ->
trans (ss p (ss p (square y1))) (square (ss p y1)) (square y) (lemma4 p y1)
(lemma2 (ss p y1) y h)
{-# Alfa hiding on
var "square"
var "trans" hide 3
var "cong" hide 4
var "assoc" hide 3
var "comm" hide 2
var "lemma0" hide 3
var "lemma3" hide 3
var "lemma2" hide 2
var "congLeft" hide 3
var "congRight" hide 3
var "lemma4" hide 2
var "lemma5" hide 3
var "eq" infix 0 as "=="
var "ss" infix 0 as "