@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/kkk.k ADDED
@@ -0,0 +1,197 @@
1
+ -- core.k — the k standard core library
2
+ --
3
+ -- Defines:
4
+ -- 1. $bits — the canonical binary number / bit-path type
5
+ -- 2. $string — unicode strings (used for labels)
6
+ -- 3. $pattern — the type of pattern graphs
7
+ -- 4. Basic $bits arithmetic: succ, plus, times
8
+
9
+ ---------------------------------------------------------------
10
+ -- §1. Bits
11
+ ---------------------------------------------------------------
12
+
13
+ $ bit = < {} 0, {} 1 >;
14
+ b0 = {}|0 $bit;
15
+ b1 = {}|1 $bit;
16
+
17
+ $ bits = < {} _, bits 0, bits 1 >;
18
+
19
+ _ = {}|_;
20
+
21
+ 0 = _ |0;
22
+ 1 = _ |1;
23
+
24
+ inv = {() x, _ r} _inv;
25
+ _inv = ${bits x, bits r} < {.x /0 x, .r |0 r} _inv, {.x /1 x, .r |1 r} _inv, .r >;
26
+
27
+ concat = ${bits x, bits y} {.x inv x, .y y} concat_;
28
+ concat_ = ${bits x, bits y}
29
+ <
30
+ {.x /0 x, .y |0 y} concat_,
31
+ {.x /1 x, .y |1 y} concat_,
32
+ .y
33
+ >;
34
+
35
+ ---------------------------------------------------------------
36
+ -- §2. Bits arithmetic
37
+ ---------------------------------------------------------------
38
+
39
+ -- successor (increment by 1)
40
+ succ = {inv x, _ y} _inc;
41
+
42
+ _inc = ${bits x, bits y} <
43
+ {.x /0 x, .y |1 y} concat_,
44
+ {.x /1 x, .y |0 y} _inc,
45
+ .y |1
46
+ >;
47
+
48
+ -- constants
49
+ 2 = 1 succ;
50
+ 3 = 2 succ;
51
+ 4 = 3 succ;
52
+ 5 = 4 succ;
53
+ 6 = 5 succ;
54
+ 7 = 6 succ;
55
+ 8 = 7 succ;
56
+ 9 = 8 succ;
57
+ 10 = 9 succ;
58
+
59
+ -- addition on $bits (unsigned, LSB-first with carry)
60
+ plus = ${bits x, bits y} {.x inv x, .y inv y, b0 c} _plus;
61
+ _plus = ${bits x, bits y, bit c}
62
+ <
63
+ {.x /_ if, .y /_ and, <.c/0 0, 1> then} .then,
64
+ {.x /_ if, .c/0 and, .y then} .then,
65
+ {.x y, .y /_|_ x, .c c} _plus,
66
+ {<.c/0 0, 1> x, .y y, .x /_ b0 c} _plus,
67
+ {.x /0 x, .y /0 y, .c/0 b0 c} _plus |0,
68
+ {.x /0 x, .y /0 y, .c/1 b0 c} _plus |1,
69
+ {.x /0 x, .y /1 y, .c/0 b0 c} _plus |1,
70
+ {.x /0 x, .y /1 y, .c/1 b1 c} _plus |0,
71
+ {.x /1 x, .y /0 y, .c/0 b0 c} _plus |1,
72
+ {.x /1 x, .y /0 y, .c/1 b1 c} _plus |0,
73
+ {.x /1 x, .y /1 y, .c/0 b1 c} _plus |0,
74
+ {.x /1 x, .y /1 y, .c/1 b1 c} _plus |1
75
+ >;
76
+
77
+ -- multiplication on $bits (unsigned, shift-and-add)
78
+ times = ${bits x, bits y} {0 result, .x inv _x, .y y} _times;
79
+ _times = ${bits result, bits _x, bits y}
80
+ <
81
+ { .y /_ if, .result then } .then,
82
+ {
83
+ .result |0 result,
84
+ ._x _x,
85
+ .y /0 y
86
+ } _times,
87
+ {
88
+ {._x x, .result |0 y, b0 c} _plus result,
89
+ ._x _x,
90
+ .y /1 y
91
+ } _times
92
+ >;
93
+
94
+ ---------------------------------------------------------------
95
+ -- §3. Unicode and String
96
+ ---------------------------------------------------------------
97
+
98
+ -- 8-bit octet used as a building block for UTF-8 payload pieces.
99
+ $ byte = {
100
+ bit 0, bit 1, bit 2, bit 3,
101
+ bit 4, bit 5, bit 6, bit 7
102
+ };
103
+
104
+ -- 7-bit ASCII code point payload (U+0000..U+007F).
105
+ $ ascii = { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
106
+
107
+ -- 11-bit payload used for Plane 0 code points U+0080..U+07FF.
108
+ -- Plane 0 is the Basic Multilingual Plane (BMP): U+0000..U+FFFF.
109
+ $ u0080_07FF = { bit 10, bit 9, bit 8, bit 7, bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 };
110
+
111
+ -- High-byte classes for common BMP ranges, excluding surrogate/private-use partitions.
112
+ -- BMP (Basic Multilingual Plane) is Plane 0: the first 65,536 code points.
113
+ $ bmp_hi_common = <
114
+ { bit 2, bit 1, bit 0 } h08_0F,
115
+ { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 } h10_7F,
116
+ { bit 6, bit 5, bit 4, bit 3, bit 2, bit 1, bit 0 } h80_CF,
117
+ { bit 2, bit 1, bit 0 } hD0_D7,
118
+ {} hF9,
119
+ { bit 0 } hFA_FB,
120
+ { bit 0 } hFC_FD,
121
+ { bit 0 } hFE_FF
122
+ >;
123
+
124
+ -- High-byte classes for BMP private-use/high-reserved slices.
125
+ -- These partitions keep Plane 0 subsets explicit in the type encoding.
126
+ $ bmp_hi_private_use = <
127
+ { bit 3, bit 2, bit 1, bit 0 } hE0_EF,
128
+ { bit 2, bit 1, bit 0 } hF0_F7,
129
+ {} hF8
130
+ >;
131
+
132
+ -- Plane selector for supplementary code points in Planes 2..16.
133
+ -- Supplementary planes are all planes above BMP (Plane 0).
134
+ $ plane_02_10 = <
135
+ { bit 0 } p02_03,
136
+ { bit 1, bit 0 } p04_07,
137
+ { bit 2, bit 1, bit 0 } p08_0F,
138
+ {} p10
139
+ >;
140
+
141
+ -- Canonical Unicode scalar-value partition used by string encoding.
142
+ -- Branch meaning:
143
+ -- - ascii: U+0000..U+007F (subset of BMP / Plane 0)
144
+ -- - plane0: U+0080..U+07FF (still Plane 0)
145
+ -- - bmp_common, bmp_private_use: U+0800..U+FFFF partitions (Plane 0)
146
+ -- - supplementary_plane1: U+10000..U+1FFFF (Plane 1)
147
+ -- - supplementary_planes2_16: U+20000..U+10FFFF (Planes 2..16)
148
+ $ unicode = <
149
+ ascii ascii,
150
+ u0080_07FF plane0,
151
+ { bmp_hi_common hi, byte lo } bmp_common,
152
+ { bmp_hi_private_use hi, byte lo } bmp_private_use,
153
+ { byte mid, byte lo } supplementary_plane1,
154
+ { plane_02_10 plane, byte mid, byte lo } supplementary_planes2_16
155
+ >;
156
+
157
+ -- Linked-list string: nil or (unicode car, string cdr).
158
+ $ string = < {} nil, { unicode car, string cdr } cons >;
159
+
160
+ ---------------------------------------------------------------
161
+ -- §4. Pattern
162
+ ---------------------------------------------------------------
163
+
164
+ -- Edge: a labeled edge in a pattern graph.
165
+ -- 'label' is the field name or tag name.
166
+ -- 'target' is the index (as $bits) of the target node in the pattern list.
167
+
168
+ $ edge = { string label, bits target };
169
+
170
+ -- Edge list: the edges of a pattern node, sorted by label.
171
+
172
+ $ edges = < {} nil, { edge car, edges cdr } cons >;
173
+
174
+ -- Pattern node: one of five kinds.
175
+ -- "any" is the unconstrained position (...), carrying no edges.
176
+ -- The four others carry their edge list directly.
177
+
178
+ $ pattern-node = <
179
+ {} any,
180
+ edges open-product,
181
+ edges open-union,
182
+ edges closed-product,
183
+ edges closed-union
184
+ >;
185
+
186
+ -- Pattern: a cons-list of pattern nodes.
187
+ -- Node 0 (first element) is the root.
188
+ -- Edges reference nodes by their index in this list, encoded as $bits.
189
+ --
190
+ -- The singleton pattern of $pattern itself is a fixed constant.
191
+ -- That constant is the implicit framing for all k wire formats:
192
+ -- to decode any value, first decode a $pattern under that constant,
193
+ -- then decode the value under the pattern just obtained.
194
+
195
+ $ pattern = < {} nil, { pattern-node car, pattern cdr } cons >;
196
+
197
+ $pattern
package/kkk.klib ADDED
Binary file
package/kkk.klib~ ADDED
Binary file
package/nak.klib ADDED
@@ -0,0 +1 @@
1
+ {"format":"k-object","codes":{"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c":{"code":"product","product":{},"def":"$C0={};"},"@w8iSHeQQE738vEmWNGja3FQWk3XuExQKZ2pbm8ApEdkF":{"code":"union","union":{"zero":"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c","succ":"@w8iSHeQQE738vEmWNGja3FQWk3XuExQKZ2pbm8ApEdkF"},"def":"$C0=<C0\"succ\",C1\"zero\">;$C1={};"}},"rels":{"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM":{"def":{"op":"comp","comp":[{"op":"product","product":[],"patterns":[0,1]},{"op":"vid","vid":"zero","patterns":[1,2]}],"patterns":[0,2]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"(...)","fields":[]},{"pattern":"type","type":"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c"},{"pattern":"<...>","fields":["zero"]}],"parent":[]},"edges":[{},{},{"zero":[1]}],"codeId":{"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c":1}}},"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5":{"def":{"op":"comp","comp":[{"op":"product","product":[{"label":"if","exp":{"op":"div","div":"zero","patterns":[2,1]}},{"label":"then","exp":{"op":"identity","patterns":[2,2]}}],"patterns":[2,0]},{"op":"dot","dot":"then","patterns":[0,2]}],"patterns":[2,2]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"{}","fields":["if","then"],"rule":"comp:chain"},{"pattern":"(...)","fields":[]},{"pattern":"<...>","fields":["zero"],"rule":"comp:chain."}],"parent":[]},"edges":[{"if":[1],"then":[2]},{},{"zero":[1]}],"codeId":{}}},"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj":{"def":{"op":"vid","vid":"succ","patterns":[0,1]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"(...)","fields":[]},{"pattern":"<...>","fields":["succ"]}],"parent":[]},"edges":[{},{"succ":[0]}],"codeId":{}}},"@mKEAm5rV7BDCh244NfCQgYE8wbEqbQMN3dbbPqBPg393":{"def":{"op":"union","union":[{"op":"comp","comp":[{"op":"product","product":[{"label":"x","exp":{"op":"comp","comp":[{"op":"dot","dot":"x","patterns":[0,1]},{"op":"div","div":"succ","patterns":[1,1]}],"patterns":[0,1]}},{"label":"y","exp":{"op":"comp","comp":[{"op":"dot","dot":"y","patterns":[0,2]},{"op":"ref","ref":"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj","patterns":[2,2]}],"patterns":[0,2]}}],"patterns":[0,0]},{"op":"ref","ref":"@mKEAm5rV7BDCh244NfCQgYE8wbEqbQMN3dbbPqBPg393","patterns":[0,2]}],"patterns":[0,2]},{"op":"dot","dot":"y","patterns":[0,2]}],"patterns":[0,2]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"{}","fields":["x","y"],"rule":"ref:input add(add)"},{"pattern":"<...>","fields":["succ"],"rule":"ref:input add(add)."},{"pattern":"<...>","fields":["succ"],"rule":"ref:input add(add)."}],"parent":[]},"edges":[{"x":[1],"y":[2]},{"succ":[1]},{"succ":[2]}],"codeId":{}}},"@2BBEqu8VuB2NPE89pNNCe9hPbmesi5JFSUQmGgnSRchp":{"def":{"op":"union","union":[{"op":"comp","comp":[{"op":"union","union":[{"op":"comp","comp":[{"op":"dot","dot":"x","patterns":[1,3]},{"op":"ref","ref":"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5","patterns":[3,3]}],"patterns":[1,3]},{"op":"comp","comp":[{"op":"dot","dot":"y","patterns":[1,3]},{"op":"ref","ref":"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5","patterns":[3,3]}],"patterns":[1,3]}],"patterns":[1,3]},{"op":"ref","ref":"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM","patterns":[3,3]}],"patterns":[1,3]},{"op":"comp","comp":[{"op":"product","product":[{"label":"x","exp":{"op":"comp","comp":[{"op":"product","product":[{"label":"x","exp":{"op":"comp","comp":[{"op":"dot","dot":"x","patterns":[1,3]},{"op":"div","div":"succ","patterns":[3,3]}],"patterns":[1,3]}},{"label":"y","exp":{"op":"dot","dot":"y","patterns":[1,3]}}],"patterns":[1,0]},{"op":"ref","ref":"@2BBEqu8VuB2NPE89pNNCe9hPbmesi5JFSUQmGgnSRchp","patterns":[0,3]}],"patterns":[1,3]}},{"label":"y","exp":{"op":"dot","dot":"y","patterns":[1,3]}}],"patterns":[1,0]},{"op":"ref","ref":"@mKEAm5rV7BDCh244NfCQgYE8wbEqbQMN3dbbPqBPg393","patterns":[0,3]}],"patterns":[1,3]}],"patterns":[1,3]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"{}","fields":["x","y"],"rule":"ref:input mult(mult)"},{"pattern":"{...}","fields":["x","y"],"rule":"union:input"},{"pattern":"type","type":"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c"},{"pattern":"<...>","fields":["succ","zero"],"rule":"ref:input mult(add)."}],"parent":[]},"edges":[{"x":[3],"y":[3]},{"x":[3],"y":[3]},{},{"succ":[3],"zero":[2]}],"codeId":{"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c":2}}}},"relAlias":{"zero?":"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5","zero":"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM","succ":"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj","add":"@mKEAm5rV7BDCh244NfCQgYE8wbEqbQMN3dbbPqBPg393","mult":"@2BBEqu8VuB2NPE89pNNCe9hPbmesi5JFSUQmGgnSRchp","__main__":"@227p5FPVzZxF4qFe77EaaQNFyMPU5xSbpHWz6vaEwmrN"},"compileStats":{"sccs":[{"members":["zero?"],"strategy":"single_pass","iterations":1,"converged":true},{"members":["zero"],"strategy":"single_pass","iterations":1,"converged":true},{"members":["succ"],"strategy":"single_pass","iterations":1,"converged":true},{"members":["add"],"strategy":"fixed_point","iterations":2,"converged":true},{"members":["mult"],"strategy":"fixed_point","iterations":2,"converged":true},{"members":["__main__"],"strategy":"single_pass","iterations":1,"converged":true}],"sccCount":6},"meta":{"@w8iSHeQQE738vEmWNGja3FQWk3XuExQKZ2pbm8ApEdkF":{"type":"code","origins":[{"source":"Examples/nat.k","name":"nat","compiledAt":"2026-05-29T01:54:22.928Z","start":{"line":1,"column":9},"end":{"line":1,"column":30}}]},"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5":{"type":"rel","origins":[{"source":"Examples/nat.k","name":"zero?","compiledAt":"2026-05-29T01:54:22.928Z","start":{"line":3,"column":9},"end":{"line":3,"column":34}}]},"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM":{"type":"rel","origins":[{"source":"Examples/nat.k","name":"zero","compiledAt":"2026-05-29T01:54:22.928Z","start":{"line":2,"column":8},"end":{"line":2,"column":17}}]},"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj":{"type":"rel","origins":[{"source":"Examples/nat.k","name":"succ","compiledAt":"2026-05-29T01:54:22.928Z","start":{"line":4,"column":8},"end":{"line":4,"column":14}}]},"@mKEAm5rV7BDCh244NfCQgYE8wbEqbQMN3dbbPqBPg393":{"type":"rel","origins":[{"source":"Examples/nat.k","name":"add","compiledAt":"2026-05-29T01:54:22.928Z","start":{"line":5,"column":10},"end":{"line":8,"column":2}}]},"@2BBEqu8VuB2NPE89pNNCe9hPbmesi5JFSUQmGgnSRchp":{"type":"rel","origins":[{"source":"Examples/nat.k","name":"mult","compiledAt":"2026-05-29T01:54:22.928Z","start":{"line":9,"column":8},"end":{"line":12,"column":2}}]}},"main":null}
package/nak2.klib ADDED
@@ -0,0 +1 @@
1
+ {"format":"k-object","codes":{"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c":{"code":"product","product":{},"def":"$C0={};"},"@w8iSHeQQE738vEmWNGja3FQWk3XuExQKZ2pbm8ApEdkF":{"code":"union","union":{"succ":"@w8iSHeQQE738vEmWNGja3FQWk3XuExQKZ2pbm8ApEdkF","zero":"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c"},"def":"$C0=<C0\"succ\",C1\"zero\">;$C1={};"}},"rels":{"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM":{"def":{"op":"comp","comp":[{"op":"product","product":[],"patterns":[1,0]},{"op":"vid","vid":"zero","patterns":[0,2]}],"patterns":[1,2]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"type","type":"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c"},{"pattern":"(...)","fields":[],"rule":"comp:chain"},{"pattern":"<...>","fields":["zero"],"rule":"comp:chain"}],"parent":[]},"edges":[{},{},{"zero":[0]}],"codeId":{"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c":0}}},"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5":{"def":{"op":"comp","comp":[{"op":"product","product":[{"label":"if","exp":{"op":"div","div":"zero","patterns":[1,2]}},{"label":"then","exp":{"op":"identity","patterns":[1,1]}}],"patterns":[1,0]},{"op":"dot","dot":"then","patterns":[0,1]}],"patterns":[1,1]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"{}","fields":["if","then"],"rule":"comp:chain"},{"pattern":"<...>","fields":["zero"],"rule":"comp:chain"},{"pattern":"(...)","fields":[],"rule":"comp:chain."}],"parent":[]},"edges":[{"if":[2],"then":[1]},{"zero":[2]},{}],"codeId":{}}},"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj":{"def":{"op":"vid","vid":"succ","patterns":[1,0]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"<...>","fields":["succ"],"rule":"comp:chain"},{"pattern":"(...)","fields":[],"rule":"comp:chain."}],"parent":[]},"edges":[{"succ":[1]},{}],"codeId":{}}},"@TJpAUPHR8Nch4PrWdXvg6D7qTtJ37vDvYdSkTvg6qX65":{"def":{"op":"union","union":[{"op":"comp","comp":[{"op":"product","product":[{"label":"x","exp":{"op":"comp","comp":[{"op":"dot","dot":"x","patterns":[0,1]},{"op":"div","div":"succ","patterns":[1,1]}],"patterns":[0,1]}},{"label":"y","exp":{"op":"comp","comp":[{"op":"dot","dot":"y","patterns":[0,1]},{"op":"ref","ref":"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj","patterns":[1,1]}],"patterns":[0,1]}}],"patterns":[0,0]},{"op":"ref","ref":"@TJpAUPHR8Nch4PrWdXvg6D7qTtJ37vDvYdSkTvg6qX65","patterns":[0,1]}],"patterns":[0,1]},{"op":"dot","dot":"y","patterns":[0,1]}],"patterns":[0,1]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"{}","fields":["x","y"],"rule":"comp:chain"},{"pattern":"<...>","fields":["succ"],"rule":"ref:input mKEA(mKEA)."}],"parent":[]},"edges":[{"x":[1],"y":[1]},{"succ":[1]}],"codeId":{}}},"@ELHmpgN5z5NNrDHPffcKRspqmivABSpjM4fbd25TyWw8":{"def":{"op":"union","union":[{"op":"comp","comp":[{"op":"union","union":[{"op":"comp","comp":[{"op":"dot","dot":"x","patterns":[2,3]},{"op":"ref","ref":"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5","patterns":[3,3]}],"patterns":[2,3]},{"op":"comp","comp":[{"op":"dot","dot":"y","patterns":[2,3]},{"op":"ref","ref":"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5","patterns":[3,3]}],"patterns":[2,3]}],"patterns":[2,3]},{"op":"ref","ref":"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM","patterns":[3,3]}],"patterns":[2,3]},{"op":"comp","comp":[{"op":"product","product":[{"label":"x","exp":{"op":"comp","comp":[{"op":"product","product":[{"label":"x","exp":{"op":"comp","comp":[{"op":"dot","dot":"x","patterns":[2,3]},{"op":"div","div":"succ","patterns":[3,3]}],"patterns":[2,3]}},{"label":"y","exp":{"op":"dot","dot":"y","patterns":[2,3]}}],"patterns":[2,0]},{"op":"ref","ref":"@ELHmpgN5z5NNrDHPffcKRspqmivABSpjM4fbd25TyWw8","patterns":[0,3]}],"patterns":[2,3]}},{"label":"y","exp":{"op":"dot","dot":"y","patterns":[2,3]}}],"patterns":[2,0]},{"op":"ref","ref":"@TJpAUPHR8Nch4PrWdXvg6D7qTtJ37vDvYdSkTvg6qX65","patterns":[0,3]}],"patterns":[2,3]}],"patterns":[2,3]},"typeDerivation":{"status":"converged"},"typePatternGraph":{"patterns":{"nodes":[{"pattern":"{}","fields":["x","y"],"rule":"ref:input 2BBE(2BBE)"},{"pattern":"type","type":"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c"},{"pattern":"{...}","fields":["x","y"],"rule":"comp:chain"},{"pattern":"<...>","fields":["succ","zero"],"rule":"ref:input 2BBE(mKEA)."}],"parent":[]},"edges":[{"x":[3],"y":[3]},{},{"x":[3],"y":[3]},{"succ":[3],"zero":[1]}],"codeId":{"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c":1}}}},"relAlias":{"nXXq":"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5","p5vX":"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM","Swjz":"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj","mKEA":"@TJpAUPHR8Nch4PrWdXvg6D7qTtJ37vDvYdSkTvg6qX65","2BBE":"@ELHmpgN5z5NNrDHPffcKRspqmivABSpjM4fbd25TyWw8","__main__":"@QfyLpmn56wuppuGvrrUJz8LKtgaXfbMtad7RnzBcFk2S"},"compileStats":{"sccs":[{"members":["nXXq"],"strategy":"single_pass","iterations":1,"converged":true},{"members":["p5vX"],"strategy":"single_pass","iterations":1,"converged":true},{"members":["Swjz"],"strategy":"single_pass","iterations":1,"converged":true},{"members":["mKEA"],"strategy":"fixed_point","iterations":1,"converged":true},{"members":["2BBE"],"strategy":"fixed_point","iterations":1,"converged":true},{"members":["__main__"],"strategy":"single_pass","iterations":1,"converged":true}],"sccCount":6},"meta":{"@NiDZqYggx3VZ6b8quBZKTfkgJztWctkesuX4CrhTxM5c":{"type":"code","origins":[{"source":"nat.k","name":"NiDZ","compiledAt":"2026-05-29T01:55:17.693Z","start":{"line":2,"column":10},"end":{"line":2,"column":12}}]},"@w8iSHeQQE738vEmWNGja3FQWk3XuExQKZ2pbm8ApEdkF":{"type":"code","origins":[{"source":"nat.k","name":"w8iS","compiledAt":"2026-05-29T01:55:17.693Z","start":{"line":3,"column":10},"end":{"line":3,"column":38}}]},"@nXXqMAi2PVsBzSN2KidWgg74hYhBbHQt5hw5TgPKvEy5":{"type":"rel","origins":[{"source":"nat.k","name":"nXXq","compiledAt":"2026-05-29T01:55:17.693Z","start":{"line":6,"column":8},"end":{"line":6,"column":71}}]},"@p5vX3t22gqMxGDRMngp7bGmHwhxZT5hXHFVb862a2kvM":{"type":"rel","origins":[{"source":"nat.k","name":"p5vX","compiledAt":"2026-05-29T01:55:17.693Z","start":{"line":5,"column":8},"end":{"line":5,"column":42}}]},"@SwjzXdcxv8ZbpCkF4cXGtgKkqPTfYqGGP5erQE7DCCsj":{"type":"rel","origins":[{"source":"nat.k","name":"Swjz","compiledAt":"2026-05-29T01:55:17.693Z","start":{"line":7,"column":15},"end":{"line":7,"column":20}}]},"@TJpAUPHR8Nch4PrWdXvg6D7qTtJ37vDvYdSkTvg6qX65":{"type":"rel","origins":[{"source":"nat.k","name":"mKEA","compiledAt":"2026-05-29T01:55:17.693Z","start":{"line":8,"column":52},"end":{"line":8,"column":86}}]},"@ELHmpgN5z5NNrDHPffcKRspqmivABSpjM4fbd25TyWw8":{"type":"rel","origins":[{"source":"nat.k","name":"2BBE","compiledAt":"2026-05-29T01:55:17.693Z","start":{"line":9,"column":54},"end":{"line":9,"column":119}}]}},"main":null}
package/nat.k ADDED
@@ -0,0 +1,10 @@
1
+ ----- codes -----
2
+ $ NiDZ = {};
3
+ $ w8iS = < w8iS "succ", NiDZ "zero" >;
4
+ ----- rels -----
5
+ p5vX = ?(...) {} |zero ?<$NiDZ zero, ...>;
6
+ nXXq = ?<(...) zero, ...> {/zero if, () then} .then ?<(...) zero, ...>;
7
+ Swjz = ?(...) |succ ?<(...) succ, ...>;
8
+ mKEA = ?{<X0 succ, ...>=X0 x, <X1 succ, ...>=X1 y} <{.x /succ x, .y Swjz y} mKEA, .y> ?<X0 succ, ...>=X0;
9
+ 2BBE = ?{<X0 succ, $NiDZ zero, ...>=X0 x, X0 y, ...} <<.x nXXq, .y nXXq> p5vX, {{.x /succ x, .y y} 2BBE x, .y y} mKEA> ?<X0 succ, $NiDZ zero, ...>=X0;
10
+ ()
package/nat2.k ADDED
@@ -0,0 +1,9 @@
1
+ ----- codes -----
2
+ $ NiDZ = {};
3
+ $ w8iS = < w8iS "succ", NiDZ "zero" >;
4
+ ----- rels -----
5
+ p5vX = ?(...) {} |zero ?<$NiDZ zero, ...>;
6
+ nXXq = ?<(...) zero, ...> {/zero if, () then} .then ?<(...) zero, ...>;
7
+ Swjz = ?(...) |succ ?<(...) succ, ...>;
8
+ TJpA = ?{<X0 succ, ...>=X0 x, X0 y} <{.x /succ x, .y Swjz y} TJpA, .y> ?<X0 succ, ...>=X0;
9
+ ELHm = ?{<X0 succ, $NiDZ zero, ...>=X0 x, X0 y, ...} <<.x nXXq, .y nXXq> p5vX, {{.x /succ x, .y y} ELHm x, .y y} TJpA> ?<X0 succ, $NiDZ zero, ...>=X0;
package/object.mjs CHANGED
@@ -702,21 +702,29 @@ function codeToSource(code, aliases) {
702
702
  return code.code === "product" ? `{${body}}` : `< ${body} >`;
703
703
  }
704
704
 
705
- function boundaryFilterSource(typePatternGraph, patternId, aliases) {
706
- const [filter] = patterns2filters(typePatternGraph, patternId);
707
- return prettyRel({ op: "filter", filter: rewriteCodesInFilter(filter, aliases) });
705
+ function boundaryFilterSources(typePatternGraph, patternIds, aliases) {
706
+ return patterns2filters(typePatternGraph, ...patternIds)
707
+ .map((filter) => prettyRel({
708
+ op: "filter",
709
+ filter: rewriteCodesInFilter(filter, aliases)
710
+ }));
708
711
  }
709
712
 
710
713
  function prettyRelation(rel, aliases = {}, relAliases = {}) {
714
+ const [inputFilter, outputFilter] = boundaryFilterSources(
715
+ rel.typePatternGraph,
716
+ [rel.def.patterns[0], rel.def.patterns[1]],
717
+ aliases
718
+ );
711
719
  const body = rewriteRefsInExp(
712
720
  stripRelationBoundaryFilters(stripDebugFieldsFromExp(rel.def), rel.typePatternGraph),
713
721
  aliases,
714
722
  relAliases
715
723
  );
716
724
  return [
717
- boundaryFilterSource(rel.typePatternGraph, rel.def.patterns[0], aliases),
725
+ inputFilter,
718
726
  prettyRel(body),
719
- boundaryFilterSource(rel.typePatternGraph, rel.def.patterns[1], aliases)
727
+ outputFilter
720
728
  ].join(" ");
721
729
  }
722
730
 
@@ -768,10 +776,15 @@ function decompileObject(object) {
768
776
 
769
777
  const mainRel = relAliases[hydrated.main] || hydrated.main;
770
778
  const mainRelDef = rels[hydrated.main];
779
+ const [mainInputFilter, mainOutputFilter] = boundaryFilterSources(
780
+ mainRelDef.typePatternGraph,
781
+ [mainRelDef.def.patterns[0], mainRelDef.def.patterns[1]],
782
+ aliases
783
+ );
771
784
  const main = [
772
- boundaryFilterSource(mainRelDef.typePatternGraph, mainRelDef.def.patterns[0], aliases),
785
+ mainInputFilter,
773
786
  aliases[mainRel] || mainRel,
774
- boundaryFilterSource(mainRelDef.typePatternGraph, mainRelDef.def.patterns[1], aliases)
787
+ mainOutputFilter
775
788
  ].join(" ");
776
789
 
777
790
  return [