@fraczak/k 6.1.1 → 6.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/.codex +0 -0
  2. package/Code-derivation-tests/pattern-envelope.mjs +26 -0
  3. package/DOCS/BIG_PICTURE.md +10 -10
  4. package/DOCS/DIVERGENCE_DETECTION.md +1 -1
  5. package/DOCS/REPL.md +33 -0
  6. package/DOCS/TYPE_DERIVATION.md +12 -12
  7. package/DOCS/a.html +398 -0
  8. package/DOCS/book/01-introduction.md +2 -2
  9. package/DOCS/book/02-syntax-and-values.md +8 -8
  10. package/DOCS/book/03-types-as-finite-automata.md +2 -2
  11. package/DOCS/book/04-partial-functions-and-composition.md +2 -2
  12. package/DOCS/book/05-typing-filters-and-normalization.md +3 -3
  13. package/DOCS/book/06-values-in-memory.md +3 -3
  14. package/DOCS/book/07-the-partial-function-abi.md +1 -1
  15. package/DOCS/book/08-operational-semantics-and-execution.md +1 -1
  16. package/DOCS/book/09-compiler-architecture.md +2 -2
  17. package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +1 -0
  18. package/DOCS/dependency-graph.html +140 -0
  19. package/DOCS/dependency-graph.md +144 -0
  20. package/NAT.k~ +452 -0
  21. package/README.md +7 -8
  22. package/UU/ta.k +1 -0
  23. package/UU/ta.k~ +0 -0
  24. package/UU/tb.k +0 -0
  25. package/UU/tc.k +0 -0
  26. package/a.k +138 -0
  27. package/a.klib +1 -0
  28. package/codecs/BINARY_FORMAT.html +471 -0
  29. package/codecs/BINARY_FORMAT.md +1 -1
  30. package/codecs/POLYMORPHIC_BINARY_FORMAT.html +355 -0
  31. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +1 -1
  32. package/codecs/ieee.mjs +19 -4
  33. package/codecs/int.mjs +11 -4
  34. package/codecs/json.mjs +7 -4
  35. package/codecs/k-parse.mjs +7 -4
  36. package/codecs/k-print.mjs +7 -4
  37. package/codecs/runtime/cli-entry.mjs +13 -0
  38. package/codecs/show.mjs +7 -4
  39. package/codecs/unit.mjs +23 -8
  40. package/codecs/utf16.mjs +27 -5
  41. package/codecs/utf8.mjs +27 -5
  42. package/codes.mjs +14 -33
  43. package/core.json +1 -0
  44. package/core.klib +1 -0
  45. package/core.klib~ +0 -0
  46. package/export.mjs +3 -3
  47. package/ieee.klib +1 -0
  48. package/k-vscode/package-lock.json +4176 -0
  49. package/kkk.k +197 -0
  50. package/kkk.klib +0 -0
  51. package/kkk.klib~ +0 -0
  52. package/nak.klib +1 -0
  53. package/nak2.klib +1 -0
  54. package/nat.k +10 -0
  55. package/nat2.k +9 -0
  56. package/object.mjs +20 -7
  57. package/p.json +5475 -0
  58. package/package.json +3 -2
  59. package/repl-codecs.mjs +173 -0
  60. package/repl.mjs +215 -5
  61. package/run.mjs +16 -2
  62. package/scripts/benchmark-idempotency.mjs +72 -0
  63. package/test-ieee-arithmetic.mjs +93 -0
  64. package/test-k-object.mjs +19 -0
  65. package/test-repl.mjs +60 -1
  66. package/tests.sh +10 -1
  67. package/type_registry/registry.mjs~ +105 -0
  68. package/type_registry/typeParser.jison~ +132 -0
  69. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  70. package/.idea/copilot.data.migration.agent.xml +0 -6
  71. package/.idea/copilot.data.migration.ask.xml +0 -6
  72. package/.idea/copilot.data.migration.ask2agent.xml +0 -6
  73. package/.idea/copilot.data.migration.edit.xml +0 -6
  74. package/.idea/k.iml +0 -9
  75. package/.idea/misc.xml +0 -6
  76. package/.idea/modules.xml +0 -8
  77. package/.idea/vcs.xml +0 -6
  78. package/k_compiler/runtime.c +0 -205
  79. package/k_compiler/runtime.h +0 -34
package/NAT.k~ ADDED
@@ -0,0 +1,452 @@
1
+ -- Examples for defining arithmetic functions natively
2
+ $ yes_no = < {} yes, {} no >;
3
+ swap_yes_no = < /yes |no, /no |yes > $yes_no;
4
+ yes = {}|yes $yes_no;
5
+ no = yes swap_yes_no;
6
+
7
+ list? = ?< {} nil, {X car, Y cdr} cons > = Y;
8
+ nil = {}|nil list?;
9
+ singleton = {() car, nil cdr} |cons list?;
10
+ cons = {.car car, .cdr cdr} |cons list?;
11
+ nil? = list? / nil nil;
12
+ car = list? /cons .car;
13
+ cdr = list? /cons .cdr;
14
+
15
+ $ bits = < {} _, bits 0, bits 1 >;
16
+
17
+ 0b = {} | _;
18
+ 1_ = | 1;
19
+ 0_ = | 0;
20
+
21
+ 0 = 0b 0_;
22
+ succ = {inv x, 0b y} _inc;
23
+ 1 = 0 succ;
24
+ 2 = 1 succ;
25
+ 3 = 2 succ;
26
+ 4 = 3 succ;
27
+ 5 = 4 succ;
28
+ 6 = 5 succ;
29
+ 7 = 6 succ;
30
+ 8 = 7 succ;
31
+ 9 = 8 succ;
32
+ 10 = 9 succ;
33
+ 11 = 10 succ;
34
+ 12 = 11 succ;
35
+
36
+ empty = $bits < /_ yes, no >;
37
+ empty? = {empty /yes if, () then} .then;
38
+
39
+ concat = ${bits x, bits y} {.x inv x, .y y} concat_;
40
+ concat_ = ${bits x, bits y}
41
+ <
42
+ {.x /0 x, .y 0_ y} concat_,
43
+ {.x /1 x, .y 1_ y} concat_,
44
+ .y
45
+ >;
46
+ inv = {()x, 0b r} _inv;
47
+ _inv = ${bits x, bits r} < {.x /0 x, .r 0_ r} _inv, {.x /1 x, .r 1_ r} _inv, .r >;
48
+
49
+ inOrder = ${bits x, bits y} {.x inv x, .y inv y, yes inOrder} inOrder_;
50
+ inOrder_ = ${bits x, bits y, yes_no inOrder}
51
+ <
52
+ {.x /0 x, .y /0 y, .inOrder inOrder} inOrder_,
53
+ {.x /1 x, .y /1 y, .inOrder inOrder} inOrder_,
54
+ {.x /0 x, .y /1 y, .inOrder inOrder} inOrder_,
55
+ {.x /1 y, .y /0 x, .inOrder swap_yes_no inOrder} inOrder_,
56
+ {.x </0,/1> if, .inOrder swap_yes_no then} .then,
57
+ .inOrder
58
+ >;
59
+
60
+ GT = {inOrder /no if, () then} . then;
61
+
62
+ EQ = GT {.x y, .y x} GT;
63
+
64
+ toBitList = {inv x, nil r} _toBitList;
65
+ _toBitList = <
66
+ {.x empty? if, .r then }.then,
67
+ {.x /0 x, {0 car, .r cdr} cons r} _toBitList,
68
+ {.x /1 x, {1 car, .r cdr} cons r} _toBitList
69
+ >;
70
+ fromBitList =
71
+ <
72
+ cdr <
73
+ {car /0 if, cdr fromBitList 0_ then} .then,
74
+ {car /1 if, cdr fromBitList 1_ then} .then
75
+ >,
76
+ 0b
77
+ > $bits;
78
+
79
+ --------------------------------------
80
+ $ int = < bits '+', bits '-' >;
81
+
82
+ remove_leading_zeros = <
83
+ /0 remove_leading_zeros,
84
+ ()
85
+ >;
86
+ nat = remove_leading_zeros <empty? 0, ()>;
87
+ int = nat | '+' $int;
88
+ abs = $int </'+',/'-'>;
89
+
90
+ pos? = $int {dec /'+' if, () then} .then;
91
+ neg? = $int {/'-' if, () then} .then;
92
+ zero_int? = $int {/'+' /0 empty? if, () then} .then;
93
+ minus_one? = $int {/'-' /1 empty? if, () then} .then;
94
+
95
+ inc = $int <
96
+ /'+' {inv x, 0b y} _inc |'+',
97
+ minus_one? 0 int,
98
+ /'-' {inv x, 0b y} _dec |'-'
99
+ >;
100
+
101
+ _inc = ${bits x, bits y} <
102
+ {.x /0 x, .y 1_ y} concat_,
103
+ {.x /1 x, .y 0_ y} _inc,
104
+ .y 1_
105
+ >;
106
+
107
+ dec = $int <
108
+ zero_int? 1 |'-',
109
+ /'+' {inv x, 0b y} _dec |'+',
110
+ /'-' {inv x, 0b y} _inc |'-'
111
+ > $int;
112
+
113
+ _dec = ?{X x, X y, ...} <
114
+ {.x /1 x, .y 0_ y} concat_,
115
+ {.x /0 x, .y 1_ y} _dec
116
+ > ?X;
117
+
118
+ $carry = <{} 0, {} 1>;
119
+ c0 = {}|0 $carry;
120
+ c1 = {}|1 $carry;
121
+
122
+ plus = ${int x, int y}
123
+ <
124
+ {.x/'+' inv x, .y/'+' inv y, c0 c } _plus inv nat | '+',
125
+ {.x/'-' inv x, .y/'-' inv y, c0 c } _plus inv nat | '-',
126
+ {.y/'-' x, .x/'+' y} GT {.x inv x, .y inv y, c0 c} _minus inv nat | '-',
127
+ {.x/'+' inv x, .y/'-' inv y, c0 c} _minus inv nat |'+',
128
+ {.x/'-' x, .y/'+' y} GT {.x inv x, .y inv y, c0 c} _minus inv nat | '-',
129
+ {.y/'+' inv x, .x/'-' inv y, c0 c} _minus inv nat | '+'
130
+ >
131
+ $int;
132
+
133
+ swap_sign = <
134
+ zero_int?,
135
+ /'+' | '-',
136
+ /'-' | '+'
137
+ >;
138
+
139
+ minus = ${int x, int y}
140
+ {.x x, .y swap_sign y} plus;
141
+
142
+ _plus =
143
+ -- least significant bit first addition with carry
144
+ ${bits x, bits y, carry c}
145
+ <
146
+ {.x empty? if, .y empty? and, <.c/0 0, 1> then} .then,
147
+ {.x empty? if, .c/0 and, .y then} .then,
148
+
149
+ {.x y, .y empty? x, .c c} _plus,
150
+ {<.c/0 0, 1> x,
151
+ .y y, .x empty? c0 c} _plus,
152
+
153
+ {.x /0 x, .y /0 y, .c/0 c0 c} _plus 0_,
154
+ {.x /0 x, .y /0 y, .c/1 c0 c} _plus 1_,
155
+
156
+ {.x /0 x, .y /1 y, .c/0 c0 c} _plus 1_,
157
+ {.x /0 x, .y /1 y, .c/1 c1 c} _plus 0_,
158
+ {.x /1 x, .y /0 y, .c/0 c0 c} _plus 1_,
159
+ {.x /1 x, .y /0 y, .c/1 c1 c} _plus 0_,
160
+
161
+ {.x /1 x, .y /1 y, .c/0 c1 c} _plus 0_,
162
+ {.x /1 x, .y /1 y, .c/1 c1 c} _plus 1_
163
+ >
164
+ ;
165
+
166
+ _minus =
167
+ -- least significat bit first substraction with carry
168
+ ${bits x, bits y, carry c}
169
+ <
170
+ {.x then, .y empty? if, .c/0 and} .then,
171
+ {.x/1 then, .y empty? if, .c/1 and} .then 0_,
172
+ {.x/0 x, .y empty? y, .c/1 c1 c} _minus 1_,
173
+ {.x/0 x, .y/0 y, .c/0 c0 c} _minus 0_,
174
+ {.x/0 x, .y/0 y, .c/1 c1 c} _minus 1_,
175
+ {.x/0 x, .y/1 y, .c/0 c1 c} _minus 1_,
176
+ {.x/0 x, .y/1 y, .c/1 c1 c} _minus 0_,
177
+ {.x/1 x, .y/0 y, .c/0 c0 c} _minus 1_,
178
+ {.x/1 x, .y/0 y, .c/1 c0 c} _minus 0_,
179
+ {.x/1 x, .y/1 y, .c/0 c0 c} _minus 0_,
180
+ {.x/1 x, .y/1 y, .c/1 c1 c} _minus 1_
181
+ >
182
+ ;
183
+
184
+ $ sign = < {} '+' , {} '-' >;
185
+ sign_plus = {}|'+' $sign;
186
+ sign_minus = {}|'-' $sign;
187
+ get_sign = $int </'+' sign_plus, /'-' sign_minus>;
188
+
189
+ times = ${int x, int y}
190
+ {
191
+ <
192
+ {.x/'+' if, .y /'+' and} sign_plus,
193
+ {.x/'-' if, .y /'-' and} sign_plus,
194
+ sign_minus
195
+ > sign,
196
+ {
197
+ 0 result,
198
+ .x abs inv _x,
199
+ .y abs y
200
+ } _times result
201
+ }
202
+ <
203
+ {.sign/'+' if, .result inv int then} .then,
204
+ {.sign/'-' if, .result inv int swap_sign then} .then
205
+ >
206
+ ;
207
+
208
+ _times =
209
+ ${bits result, bits _x, bits y}
210
+ <
211
+ { .y empty? if, .result then } .then,
212
+ {
213
+ .result 0_ result,
214
+ ._x _x,
215
+ .y /0 y
216
+ } _times,
217
+ {
218
+ {._x x, .result 0_ y, c0 c } _plus result,
219
+ ._x _x,
220
+ .y /1 y
221
+ } _times
222
+ >
223
+ ;
224
+
225
+
226
+ mod =
227
+ ${bits x, bits y}
228
+ _log!
229
+ <
230
+ -- if y > x then (x mod y) = x
231
+ {.y x, .x y} GT .y,
232
+ -- else, i.e.
233
+ -- if x >= y then (x mod y) = ((x-y mod 2y) mod y)
234
+ {
235
+ {
236
+ {.x int x, .y int y} minus /"+" x,
237
+ .y inv 0_ inv y
238
+ } mod x,
239
+ .y y
240
+ } mod
241
+ >
242
+ ;
243
+
244
+
245
+ // gratest common divisor
246
+ gcd = ${bits x, bits y}
247
+ <
248
+ {.y x, .x y} GT,
249
+ ()
250
+ > _gcd
251
+ ;
252
+
253
+ _gcd = <
254
+ { .y /0 if, .x then } .then,
255
+ { .y x, mod y } _gcd
256
+ >;
257
+
258
+
259
+
260
+ // div
261
+
262
+ log2_floor =
263
+ ${bits x, bits step}
264
+ -- finds the largest k, such that 'step * 2^k <= x',
265
+ -- returns k1_, i.e., 0 if x < step, and k1_ otherwise.
266
+ {.x x, .step step, 0 log} log2_floor_;
267
+
268
+ log2_floor_ = <
269
+ {{.step x,.x y} GT if, .log then} .then,
270
+ {.x x, {.step x,0 y} GT {.x x,2 y} {.x int x, .y int y} times abs step, .log int inc abs log} log2_floor_
271
+ >;
272
+
273
+
274
+ x_times_2_to_k =
275
+ ${bits x, bits k}
276
+ {.x inv _x, .k int k} _x_times_2_to_the_power_of_k inv
277
+ ;
278
+
279
+ _x_times_2_to_the_power_of_k = <
280
+ {.k zero_int? if, ._x then} .then,
281
+ {._x 0_ _x, .k dec k} _x_times_2_to_the_power_of_k
282
+ >
283
+ ;
284
+
285
+ div =
286
+ ${int x, int y}
287
+ // remember sign
288
+ {
289
+ <
290
+ { .x/'+' if, .y get_sign then } .then,
291
+ { .x/'-' if, .y swap_sign get_sign then } .then
292
+ > sign,
293
+ {.x abs x, .y abs step, 0 int res} _div res_wo_sign
294
+ }
295
+ <
296
+ {.sign/'+' if, {.res_wo_sign.div div, .res_wo_sign.rem rem} then} .then,
297
+ { .res_wo_sign.div swap_sign div, .res_wo_sign.rem rem }
298
+ >
299
+ ;
300
+
301
+ _div =
302
+ {
303
+ .x x,
304
+ .step step,
305
+ .res res,
306
+ {.x x, .step step} log2_floor log
307
+ }
308
+ <
309
+ { .log int zero_int? if, {.res div, .x rem} then } .then,
310
+ {
311
+ {1 x, .log int dec abs k} x_times_2_to_k factor,
312
+ () i
313
+ }
314
+ {
315
+ {.i.x int x, {.i.step int x, .factor int y} times y} minus abs x,
316
+ .i.step step,
317
+ {.i.res x, .factor int y} plus res
318
+ } _div
319
+ >;
320
+
321
+
322
+ lcm =
323
+ ${bits x, bits y}
324
+ {{.x int x, .y int y} times x, gcd int y} div .div abs
325
+ ;
326
+
327
+ factorial = <
328
+ zero_int? 1 int,
329
+ /"+" int {dec factorial x, () y} times
330
+ >;
331
+
332
+ fib_ =
333
+ <
334
+ { .n int dec /"+" n,
335
+ ."fib(n),fib(n.1)" {plus x, .x y} "fib(n),fib(n.1)"
336
+ } fib_,
337
+ ."fib(n),fib(n.1)"
338
+ >
339
+ ;
340
+
341
+ fib = {$bits n, {1 int x, 0 int y} "fib(n),fib(n.1)"} fib_ .x;
342
+
343
+
344
+ --------------------
345
+ $ rat = { int n, int d };
346
+
347
+ rat = ${bits n, bits d} {.n int n, .d int d } normalize_rat;
348
+
349
+ normalize_rat =
350
+ $rat
351
+ <
352
+ { .d/"-" if,
353
+ {
354
+ .n swap_sign n,
355
+ .d swap_sign d
356
+ } then
357
+ } .then,
358
+ ()
359
+ >
360
+ {() x, {.n abs x,.d abs y} gcd int y}
361
+ {
362
+ {.x.n x,.y y} div .div n,
363
+ {.x.d x,.y y} div .div d
364
+ }
365
+ $rat
366
+ ;
367
+
368
+
369
+ plus_rat =
370
+ ${rat x, rat y}
371
+ {
372
+ .x x,
373
+ .y y,
374
+ {.x.d abs x,.y.d abs y} lcm int lcm
375
+ }
376
+ {
377
+ {
378
+ {.x.n x, {.lcm x, .x.d y} div .div y} times x,
379
+ {.y.n x, {.lcm x, .y.d y} div .div y} times y
380
+ } plus n,
381
+ .lcm d
382
+ }
383
+ normalize_rat
384
+ ;
385
+
386
+
387
+ times_rat =
388
+ ${rat x, rat y}
389
+ {
390
+ {.x.n x,.y.n y} times n,
391
+ {.x.d x,.y.d y} times d
392
+ }
393
+ normalize_rat;
394
+
395
+
396
+ minus_rat =
397
+ ${rat x, rat y}
398
+ {
399
+ .x x,
400
+ .y {.n swap_sign n, .d d} y
401
+ }
402
+ plus_rat;
403
+
404
+ inverse_rat =
405
+ $rat
406
+ { .d n, .n d }
407
+ normalize_rat
408
+ ;
409
+
410
+ div_rat =
411
+ ${rat x, rat y}
412
+ { .x x, .y inverse_rat y} times_rat
413
+ ;
414
+
415
+
416
+ --------------------
417
+
418
+ int_rat =
419
+ $rat
420
+ { .n n, .d d, {.n x,.d y} div div }
421
+ { .div.div int, {.div.rem int n, .d d} rat}
422
+ ${int int, rat rat}
423
+ ;
424
+
425
+ /*
426
+ ratToString =
427
+ -- $rat
428
+ [
429
+ .n toJSON,
430
+ "/",
431
+ .d toJSON,
432
+ " = ",
433
+ normalize_rat
434
+ <
435
+ [.d,.n] GT [.1 toJSON ,"/", .0 toJSON] CONCAT,
436
+ {.n 0,[.d,1] EQ 1} [.0 toJSON] CONCAT,
437
+ int_rat [.int toJSON,"+",.rat.n toJSON,"/",.rat.d toJSON] CONCAT
438
+ >
439
+ ] CONCAT
440
+ -- $@string
441
+ ;
442
+
443
+ _rat! = $rat {
444
+ () carryOn,
445
+ ratToString _log! drop
446
+ } .carryOn;
447
+
448
+
449
+
450
+ */
451
+
452
+ times
package/README.md CHANGED
@@ -40,13 +40,12 @@ numbers are either `0` or one more than another natural number:
40
40
 
41
41
  ```k
42
42
  $ nat = < {} 0, nat +1 >;
43
-
44
- zero = {} |0;
45
- inc = |+1;
46
-
47
- add = ?X <
48
- { .x /+1 x, .y inc y } ?X add,
49
- .y
43
+ 0 = {} | 0 $ nat ;
44
+ inc = | +1 $ nat ;
45
+ dec = $ nat / +1 ; # undefined for '0'
46
+ add = $ { nat x, nat y } <
47
+ { . x dec x, . y inc y } add, # defined if 'x > 0'
48
+ . y # else, return 'y'
50
49
  >;
51
50
  ```
52
51
 
@@ -240,7 +239,7 @@ Still evolving:
240
239
  - optimization and backend experiments
241
240
  - larger real-world examples
242
241
 
243
- ## Good Areas For Contributors
242
+ ## Good Areas for Contributors
244
243
 
245
244
  k is small enough to study, but there are several useful directions:
246
245
 
package/UU/ta.k ADDED
@@ -0,0 +1 @@
1
+ $bit
package/UU/ta.k~ ADDED
File without changes
package/UU/tb.k ADDED
File without changes
package/UU/tc.k ADDED
File without changes
package/a.k ADDED
@@ -0,0 +1,138 @@
1
+ ----- codes -----
2
+ $ 2aks = {VtPH "factor", Envk "i"};
3
+ $ 2xPW = {PHbG "r", VtPH "x"};
4
+ $ 33dY = {VtPH "_x", VtPH "result", VtPH "y"};
5
+ $ 6d2A = {NiDZ "if", nh8T "then"};
6
+ $ 8MHR = {VtPH "if", 9bLM "then"};
7
+ $ 9bLM = < NiDZ "no", NiDZ "yes" >;
8
+ $ CuVs = {VtPH "k", VtPH "x"};
9
+ $ ERx5 = {Mjus "c", VtPH "x", VtPH "y"};
10
+ $ Envk = {VtPH "log", Nws3 "res", VtPH "step", VtPH "x"};
11
+ $ EvuD = {VtPH "if", VtPH "then"};
12
+ $ F7RN = < NiDZ "+", NiDZ "-" >;
13
+ $ FL4i = {nh8T "res_wo_sign", F7RN "sign"};
14
+ $ H24y = {VtPH "if", Nws3 "then"};
15
+ $ Hj9J = {NiDZ "if", Nws3 "then"};
16
+ $ KxW7 = {VtPH "log", VtPH "step", VtPH "x"};
17
+ $ Ljf9 = {VtPH "car", PHbG "cdr"};
18
+ $ Mjus = < NiDZ "0", NiDZ "1" >;
19
+ $ NiDZ = {};
20
+ $ Nws3 = < VtPH "+", VtPH "-" >;
21
+ $ PHbG = < Ljf9 "cons", NiDZ "nil" >;
22
+ $ R7RD = {VtPH "x", VtPH "y"};
23
+ $ RLhu = {NiDZ "if", R7RD "then"};
24
+ $ RknV = {VtPH "if", PHbG "then"};
25
+ $ S5nE = {Nws3 "int", muqD "rat"};
26
+ $ TcsE = {muqD "x", muqD "y"};
27
+ $ Thzc = {VtPH "r", VtPH "x"};
28
+ $ UFVU = {VtPH "_x", Nws3 "k"};
29
+ $ Vc85 = {Nws3 "x", Nws3 "y"};
30
+ $ VtPH = < VtPH "0", VtPH "1", NiDZ "_" >;
31
+ $ WWuP = {muqD "x", Nws3 "y"};
32
+ $ YeUu = {VtPH "and", VtPH "if"};
33
+ $ YfKH = {VtPH "d", VtPH "n"};
34
+ $ ZLDk = {VtPH "step", VtPH "x"};
35
+ $ bSFt = {NiDZ "and", VtPH "if", VtPH "then"};
36
+ $ dXdV = {9bLM "inOrder", VtPH "x", VtPH "y"};
37
+ $ eYsq = {NiDZ "if", VtPH "then"};
38
+ $ hJHA = {R7RD "if", VtPH "then"};
39
+ $ hPpx = {Nws3 "if", nh8T "then"};
40
+ $ muqD = {Nws3 "d", Nws3 "n"};
41
+ $ nPgb = {Nws3 "lcm", muqD "x", muqD "y"};
42
+ $ nh8T = {Nws3 "div", VtPH "rem"};
43
+ $ nhfK = {VtPH "and", VtPH "if", VtPH "then"};
44
+ $ prGg = {Vc85 "fib(n),fib(n.1)", VtPH "n"};
45
+ $ s7Sd = {Nws3 "res", VtPH "step", VtPH "x"};
46
+ $ sqr8 = {VtPH "if", F7RN "then"};
47
+ $ uMrJ = {VtPH "if", muqD "then"};
48
+ $ yYPm = {VtPH "result", F7RN "sign"};
49
+ $ zLbj = {Nws3 "d", nh8T "div", Nws3 "n"};
50
+ ----- rels -----
51
+ 8jvS = ?(...) 4Uqf mx7B ?<<$NiDZ _, ...> 0, ...>;
52
+ TLyi = ?(...) 8jvS 7GtG $VtPH;
53
+ 2ezj = ?(...) TLyi 7GtG $VtPH;
54
+ BHYs = ?(...) 2ezj 7GtG $VtPH;
55
+ XeYK = ?(...) BHYs 7GtG $VtPH;
56
+ ycSP = ?(...) XeYK 7GtG $VtPH;
57
+ c3fq = ?(...) ycSP 7GtG $VtPH;
58
+ ANDv = ?(...) c3fq 7GtG $VtPH;
59
+ BASZ = ?(...) ANDv 7GtG $VtPH;
60
+ Je6N = ?(...) BASZ 7GtG $VtPH;
61
+ PaZn = ?(...) Je6N 7GtG $VtPH;
62
+ 8Wzq = ?(...) PaZn 7GtG $VtPH;
63
+ 7gmR = ?(...) 8Wzq 7GtG $VtPH;
64
+ SCqj = ?<$NiDZ no, $NiDZ yes, ...> </yes |no, /no |yes> $9bLM;
65
+ KWT2 = ?(...) {} |yes $9bLM;
66
+ 7RTv = ?(...) KWT2 SCqj $9bLM;
67
+ L8iN = ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0 () ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0;
68
+ tyxZ = ?(...) {} |nil ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0;
69
+ C9mM = ?(...) {() car, tyxZ cdr} |cons ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0;
70
+ w6w6 = ?{X0 car, <{X0 car, X1 cdr} cons, $NiDZ nil>=X1 cdr, ...} {.car car, .cdr cdr} |cons ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0;
71
+ jhbb = ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0 /nil tyxZ ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0;
72
+ UY5b = ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0 /cons .car ?(...);
73
+ S7xP = ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0 /cons .cdr ?<{(...) car, X0 cdr} cons, $NiDZ nil>=X0;
74
+ 4Uqf = ?(...) {} |_ ?<$NiDZ _, ...>;
75
+ J6xt = ?(...) |1 ?<(...) 1, ...>;
76
+ mx7B = ?(...) |0 ?<(...) 0, ...>;
77
+ 7GtG = $VtPH {4YaF x, 4Uqf y} JfKb $VtPH;
78
+ ZTFs = $VtPH </_ KWT2, 7RTv> $9bLM;
79
+ AkEL = $VtPH {ZTFs /yes if, () then} .then $VtPH;
80
+ fKyL = $R7RD {.x 4YaF x, .y y} N8w3 $VtPH;
81
+ N8w3 = $R7RD <{.x /0 x, .y mx7B y} N8w3, {.x /1 x, .y J6xt y} N8w3, .y> $VtPH;
82
+ 4YaF = $VtPH {() x, 4Uqf r} NbnA $VtPH;
83
+ NbnA = $Thzc <{.x /0 x, .r mx7B r} NbnA, {.x /1 x, .r J6xt r} NbnA, .r> $VtPH;
84
+ vbhA = $R7RD {.x 4YaF x, .y 4YaF y, KWT2 inOrder} CaAi $9bLM;
85
+ CaAi = $dXdV <{.x /0 x, .y /0 y, .inOrder inOrder} CaAi, {.x /1 x, .y /1 y, .inOrder inOrder} CaAi, {.x /0 x, .y /1 y, .inOrder inOrder} CaAi, {.x /1 y, .y /0 x, .inOrder SCqj inOrder} CaAi, {.x </0, /1> if, .inOrder SCqj then} .then, .inOrder> $9bLM;
86
+ 6rrB = $R7RD {vbhA /no if, () then} .then $R7RD;
87
+ y3WV = $R7RD 6rrB {.x y, .y x} 6rrB $R7RD;
88
+ fSRE = $VtPH {4YaF x, tyxZ r} 9hTs $PHbG;
89
+ 9hTs = ?{$PHbG r, $VtPH x, ...} <{.x AkEL if, .r then} .then, {.x /0 x, {8jvS car, .r cdr} w6w6 r} 9hTs, {.x /1 x, {TLyi car, .r cdr} w6w6 r} 9hTs> $PHbG;
90
+ Ywaf = ?<{<(...) 0, (...) 1, ...> car, X0 cdr} cons, $NiDZ nil>=X0 <S7xP <{UY5b /0 if, S7xP Ywaf mx7B then} .then, {UY5b /1 if, S7xP Ywaf J6xt then} .then>, 4Uqf> $VtPH;
91
+ Prn6 = ?<X0 0, ...>=X0 </0 Prn6, ()> ?<X0 0, ...>=X0;
92
+ xX22 = $VtPH Prn6 <AkEL 8jvS, ()> $VtPH;
93
+ Phke = $VtPH xX22 |+ $Nws3;
94
+ xdAf = $Nws3 </+, /-> $VtPH;
95
+ JyBD = $Nws3 {7sp2 /+ if, () then} .then $Nws3;
96
+ BzLM = $Nws3 {/- if, () then} .then $Nws3;
97
+ NxZn = $Nws3 {/+ /0 AkEL if, () then} .then $Nws3;
98
+ NKnM = $Nws3 {/- /1 AkEL if, () then} .then $Nws3;
99
+ 6VKZ = $Nws3 </+ {4YaF x, 4Uqf y} JfKb |+, NKnM 8jvS Phke, /- {4YaF x, 4Uqf y} 9Cyq |-> $Nws3;
100
+ JfKb = $R7RD <{.x /0 x, .y J6xt y} N8w3, {.x /1 x, .y mx7B y} JfKb, .y J6xt> $VtPH;
101
+ 7sp2 = $Nws3 <NxZn TLyi |-, /+ {4YaF x, 4Uqf y} 9Cyq |+, /- {4YaF x, 4Uqf y} JfKb |-> $Nws3;
102
+ 9Cyq = ?{$VtPH x, $VtPH y, ...} <{.x /1 x, .y mx7B y} N8w3, {.x /0 x, .y J6xt y} 9Cyq> $VtPH;
103
+ vvzA = ?(...) {} |0 $Mjus;
104
+ nXAf = ?(...) {} |1 $Mjus;
105
+ APnt = $Vc85 <{.x /+ 4YaF x, .y /+ 4YaF y, vvzA c} 73G3 4YaF xX22 |+, {.x /- 4YaF x, .y /- 4YaF y, vvzA c} 73G3 4YaF xX22 |-, {.y /- x, .x /+ y} 6rrB {.x 4YaF x, .y 4YaF y, vvzA c} 3kn7 4YaF xX22 |-, {.x /+ 4YaF x, .y /- 4YaF y, vvzA c} 3kn7 4YaF xX22 |+, {.x /- x, .y /+ y} 6rrB {.x 4YaF x, .y 4YaF y, vvzA c} 3kn7 4YaF xX22 |-, {.y /+ 4YaF x, .x /- 4YaF y, vvzA c} 3kn7 4YaF xX22 |+> $Nws3;
106
+ 4ZfX = $Nws3 <NxZn, /+ |-, /- |+> $Nws3;
107
+ kBAy = $Vc85 {.x x, .y 4ZfX y} APnt $Nws3;
108
+ 73G3 = $ERx5 <{.x AkEL if, .y AkEL and, <.c /0 8jvS, TLyi> then} .then, {.x AkEL if, .c /0 and, .y then} .then, {.x y, .y AkEL x, .c c} 73G3, {<.c /0 8jvS, TLyi> x, .y y, .x AkEL vvzA c} 73G3, {.x /0 x, .y /0 y, .c /0 vvzA c} 73G3 mx7B, {.x /0 x, .y /0 y, .c /1 vvzA c} 73G3 J6xt, {.x /0 x, .y /1 y, .c /0 vvzA c} 73G3 J6xt, {.x /0 x, .y /1 y, .c /1 nXAf c} 73G3 mx7B, {.x /1 x, .y /0 y, .c /0 vvzA c} 73G3 J6xt, {.x /1 x, .y /0 y, .c /1 nXAf c} 73G3 mx7B, {.x /1 x, .y /1 y, .c /0 nXAf c} 73G3 mx7B, {.x /1 x, .y /1 y, .c /1 nXAf c} 73G3 J6xt> $VtPH;
109
+ 3kn7 = $ERx5 <{.x then, .y AkEL if, .c /0 and} .then, {.x /1 then, .y AkEL if, .c /1 and} .then mx7B, {.x /0 x, .y AkEL y, .c /1 nXAf c} 3kn7 J6xt, {.x /0 x, .y /0 y, .c /0 vvzA c} 3kn7 mx7B, {.x /0 x, .y /0 y, .c /1 nXAf c} 3kn7 J6xt, {.x /0 x, .y /1 y, .c /0 nXAf c} 3kn7 J6xt, {.x /0 x, .y /1 y, .c /1 nXAf c} 3kn7 mx7B, {.x /1 x, .y /0 y, .c /0 vvzA c} 3kn7 J6xt, {.x /1 x, .y /0 y, .c /1 vvzA c} 3kn7 mx7B, {.x /1 x, .y /1 y, .c /0 vvzA c} 3kn7 mx7B, {.x /1 x, .y /1 y, .c /1 nXAf c} 3kn7 J6xt> $VtPH;
110
+ NiRD = ?(...) {} |+ $F7RN;
111
+ u9uY = ?(...) {} |- $F7RN;
112
+ JEEj = $Nws3 </+ NiRD, /- u9uY> $F7RN;
113
+ 3PYm = $Vc85 {<{.x /+ if, .y /+ and} NiRD, {.x /- if, .y /- and} NiRD, u9uY> sign, {8jvS result, .x xdAf 4YaF _x, .y xdAf y} 9bpS result} <{.sign /+ if, .result 4YaF Phke then} .then, {.sign /- if, .result 4YaF Phke 4ZfX then} .then> $Nws3;
114
+ 9bpS = $33dY <{.y AkEL if, .result then} .then, {.result mx7B result, ._x _x, .y /0 y} 9bpS, {{._x x, .result mx7B y, vvzA c} 73G3 result, ._x _x, .y /1 y} 9bpS> $VtPH;
115
+ TPzm = $R7RD _log! <{.y x, .x y} 6rrB .y, {{{.x Phke x, .y Phke y} kBAy /+ x, .y 4YaF mx7B 4YaF y} TPzm x, .y y} TPzm> $VtPH;
116
+ Vs6b = $R7RD <{.y x, .x y} 6rrB, ()> Ah93 $VtPH;
117
+ Ah93 = $R7RD <{.y /0 if, .x then} .then, {.y x, TPzm y} Ah93> $VtPH;
118
+ nB9M = $ZLDk {.x x, .step step, 8jvS log} 5ivr $VtPH;
119
+ 5ivr = ?{$VtPH log, $VtPH step, $VtPH x, ...} <{{.step x, .x y} 6rrB if, .log then} .then, {.x x, {.step x, 8jvS y} 6rrB {.x x, 2ezj y} {.x Phke x, .y Phke y} 3PYm xdAf step, .log Phke 6VKZ xdAf log} 5ivr> $VtPH;
120
+ MTKW = $CuVs {.x 4YaF _x, .k Phke k} au4T 4YaF $VtPH;
121
+ au4T = ?{<X0 0, ...>=X0 _x, $Nws3 k, ...} <{.k NxZn if, ._x then} .then, {._x mx7B _x, .k 7sp2 k} au4T> ?<X0 0, ...>=X0;
122
+ Bs2e = $Vc85 {<{.x /+ if, .y JEEj then} .then, {.x /- if, .y 4ZfX JEEj then} .then> sign, {.x xdAf x, .y xdAf step, 8jvS Phke res} 8Dwz res_wo_sign} <{.sign /+ if, {.res_wo_sign .div div, .res_wo_sign .rem rem} then} .then, {.res_wo_sign .div 4ZfX div, .res_wo_sign .rem rem}> $nh8T;
123
+ 8Dwz = ?{$Nws3 res, $VtPH step, $VtPH x, ...} {.x x, .step step, .res res, {.x x, .step step} nB9M log} <{.log Phke NxZn if, {.res div, .x rem} then} .then, {{TLyi x, .log Phke 7sp2 xdAf k} MTKW factor, () i} {{.i .x Phke x, {.i .step Phke x, .factor Phke y} 3PYm y} kBAy xdAf x, .i .step step, {.i .res x, .factor Phke y} APnt res} 8Dwz> $nh8T;
124
+ GSLa = $R7RD {{.x Phke x, .y Phke y} 3PYm x, Vs6b Phke y} Bs2e .div xdAf $VtPH;
125
+ FaWv = $Nws3 <NxZn TLyi Phke, /+ Phke {7sp2 FaWv x, () y} 3PYm> $Nws3;
126
+ HZYv = ?{$Vc85"fib(n),fib(n.1)", $VtPH n, ...} <{.n Phke 7sp2 /+ n, ."fib(n),fib(n.1)" {APnt x, .x y}"fib(n),fib(n.1)"} HZYv, ."fib(n),fib(n.1)"> $Vc85;
127
+ aUJp = $VtPH {() n, {TLyi Phke x, 8jvS Phke y}"fib(n),fib(n.1)"} HZYv .x $Nws3;
128
+ sghj = $YfKH {.n Phke n, .d Phke d} 2zFi $muqD;
129
+ 2zFi = $muqD <{.d /- if, {.n 4ZfX n, .d 4ZfX d} then} .then, ()> {() x, {.n xdAf x, .d xdAf y} Vs6b Phke y} {{.x .n x, .y y} Bs2e .div n, {.x .d x, .y y} Bs2e .div d} $muqD;
130
+ Jn92 = $TcsE {.x x, .y y, {.x .d xdAf x, .y .d xdAf y} GSLa Phke lcm} {{{.x .n x, {.lcm x, .x .d y} Bs2e .div y} 3PYm x, {.y .n x, {.lcm x, .y .d y} Bs2e .div y} 3PYm y} APnt n, .lcm d} 2zFi $muqD;
131
+ 2Uyd = $TcsE {{.x .n x, .y .n y} 3PYm n, {.x .d x, .y .d y} 3PYm d} 2zFi $muqD;
132
+ uRTk = $TcsE {.x x, .y {.n 4ZfX n, .d d} y} Jn92 $muqD;
133
+ FtdC = $muqD {.d n, .n d} 2zFi $muqD;
134
+ MH4q = $TcsE {.x x, .y FtdC y} 2Uyd $muqD;
135
+ 8jRf = $muqD {.n n, .d d, {.n x, .d y} Bs2e div} {.div .div int, {.div .rem Phke n, .d d} rat} $S5nE;
136
+
137
+ ()
138
+