-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfork.ijs
372 lines (357 loc) · 8.35 KB
/
fork.ijs
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
NB. Extended forks
NB.
NB. fork3 Generalized fork with 3-depth execution graph
NB. fork4 Generalized fork with 4-depth execution graph
NB. fork5 Generalized fork with 5-depth execution graph
NB. fork6 Generalized fork with 6-depth execution graph
NB.
NB. Copyright 2010,2011,2013,2017,2018,2020,2021,2023,2024,
NB. 2025 Igor Zhuravlov
NB.
NB. This file is part of mt
NB.
NB. mt is free software: you can redistribute it and/or
NB. modify it under the terms of the GNU Lesser General
NB. Public License as published by the Free Software
NB. Foundation, either version 3 of the License, or (at your
NB. option) any later version.
NB.
NB. mt is distributed in the hope that it will be useful, but
NB. WITHOUT ANY WARRANTY; without even the implied warranty
NB. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
NB. See the GNU Lesser General Public License for more
NB. details.
NB.
NB. You should have received a copy of the GNU Lesser General
NB. Public License along with mt. If not, see
NB. <http://www.gnu.org/licenses/>.
NB. =========================================================
NB. Concepts
NB.
NB. Notation:
NB. n-fork - generalized fork of n layers
NB.
NB. Notes:
NB. - n-fork is a trellis automata
NB.
NB. References:
NB. [1] JWiki :: User:Igor Zhuravlov/Extended forks
NB. https://code.jsoftware.com/wiki/User:Igor_Zhuravlov/Extended_forks
NB. =========================================================
NB. Configuration
coclass 'mt'
NB. =========================================================
NB. Local definitions
NB. =========================================================
NB. Interface
NB. ---------------------------------------------------------
NB. fork2
NB.
NB. Description:
NB. 2-fork, the traditional fork with 2-depth execution
NB. graph
NB.
NB. Syntax:
NB. vapp=. a0`b0`a1 fork2
NB. vapp=. a0`b0`a1`:6
NB. vapp=. a0 b0 a1
NB. where
NB. ax - ambivalent verbs to define input nodes of
NB. execution graph
NB. b0 - dyad to define output node of execution graph
NB. vapp - 2-fork, is called as:
NB. out=. vapp y
NB. out=. x vapp y
NB.
NB. Execution graph:
NB. b0
NB. / \
NB. a0 a1
NB.
NB. Notes:
NB. - included just to eludicate generalized forks idea
NB. fork2=: 1 : 0
NB. '`a0 b0 a1'=. m
NB. o0=. a0 y
NB. o1=. a1 y
NB. o0=. o0 b0 o1
NB. :
NB. '`a0 b0 a1'=. m
NB. o0=. x a0 y
NB. o1=. x a1 y
NB. o0=. o0 b0 o1
NB. )
NB. ---------------------------------------------------------
NB. fork3
NB.
NB. Description:
NB. 3-fork, generalized fork with 3-depth execution graph
NB.
NB. Syntax:
NB. vapp=. a0`b0`a1`c0`b1`a2 fork3
NB. where
NB. ax - ambivalent verbs to define input nodes of
NB. execution graph
NB. bx - dyads to define intermediate nodes of execution
NB. graph
NB. c0 - dyad to define output node of execution graph
NB. vapp - 3-fork, is called as:
NB. out=. vapp y
NB. out=. x vapp y
NB.
NB. Execution graph:
NB. c0
NB. / \
NB. b0 b1
NB. / \ / \
NB. a0 a1 a2
NB.
NB. Notes:
NB. - local nouns are re-used to reduce memory consumption
NB. - another 2-fork compatible traverse order is possible:
NB. a0 b0 c0 b1 a2 a1
fork3=: 1 : 0
'`a0 b0 a1 c0 b1 a2'=. m
o0=. a0 y
o1=. a1 y
o2=. a2 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. 0
o0=. o0 c0 o1
:
'`a0 b0 a1 c0 b1 a2'=. m
o0=. x a0 y
o1=. x a1 y
o2=. x a2 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. 0
o0=. o0 c0 o1
)
NB. ---------------------------------------------------------
NB. fork4
NB.
NB. Description:
NB. 4-fork, generalized fork with 4-depth execution graph
NB.
NB. Syntax:
NB. vapp=. a0`b0`a1`c0`b1`a2`d0`c1`b2`a3 fork4
NB. where
NB. ax - ambivalent verbs to define input nodes of
NB. execution graph
NB. bx cx - dyads to define intermediate nodes of execution
NB. graph
NB. d0 - dyad to define output node of execution graph
NB. vapp - 4-fork, is called as:
NB. out=. vapp y
NB. out=. x vapp y
NB.
NB. Execution graph:
NB. d0
NB. / \
NB. c0 c1
NB. / \ / \
NB. b0 b1 b2
NB. / \ / \ / \
NB. a0 a1 a2 a3
NB.
NB. Notes:
NB. - local nouns are re-used to reduce memory consumption
NB. - another 2-fork compatible traverse order is possible:
NB. a0 b0 c0 d0 c1 b2 a3 a1 b1 a2
fork4=: 1 : 0
'`a0 b0 a1 c0 b1 a2 d0 c1 b2 a3'=. m
o0=. a0 y
o1=. a1 y
o2=. a2 y
o3=. a3 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. o2 b2 o3
o3=. 0
o0=. o0 c0 o1
o1=. o1 c1 o2
o2=. 0
o0=. o0 d0 o1
:
'`a0 b0 a1 c0 b1 a2 d0 c1 b2 a3'=. m
o0=. x a0 y
o1=. x a1 y
o2=. x a2 y
o3=. x a3 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. o2 b2 o3
o3=. 0
o0=. o0 c0 o1
o1=. o1 c1 o2
o2=. 0
o0=. o0 d0 o1
)
NB. ---------------------------------------------------------
NB. fork5
NB.
NB. Description:
NB. 5-fork, generalized fork with 5-depth execution graph
NB.
NB. Syntax:
NB. vapp=. a0`b0`a1`c0`b1`a2`d0`c1`b2`a3`e0`d1`c2`b3`a4 fork5
NB. where
NB. ax - ambivalent verbs to define input nodes of
NB. execution graph
NB. bx cx dx - dyads to define intermediate nodes of
NB. execution graph
NB. e0 - dyad to define output node of execution
NB. graph
NB. vapp - 5-fork, is called as:
NB. out=. vapp y
NB. out=. x vapp y
NB.
NB. Execution graph:
NB. e0
NB. / \
NB. d0 d1
NB. / \ / \
NB. c0 c1 c2
NB. / \ / \ / \
NB. b0 b1 b2 b3
NB. / \ / \ / \ / \
NB. a0 a1 a2 a3 a4
NB.
NB. Notes:
NB. - local nouns are re-used to reduce memory consumption
NB. - another 2-fork compatible traverse order is possible:
NB. a0 b0 c0 d0 e0 d1 c2 b3 a4 a1 b1 c1 b2 a3 a2
fork5=: 1 : 0
'`a0 b0 a1 c0 b1 a2 d0 c1 b2 a3 e0 d1 c2 b3 a4'=. m
o0=. a0 y
o1=. a1 y
o2=. a2 y
o3=. a3 y
o4=. a4 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. o2 b2 o3
o3=. o3 b3 o4
o4=. 0
o0=. o0 c0 o1
o1=. o1 c1 o2
o2=. o2 c2 o3
o3=. 0
o0=. o0 d0 o1
o1=. o1 d1 o2
o2=. 0
o0=. o0 e0 o1
:
'`a0 b0 a1 c0 b1 a2 d0 c1 b2 a3 e0 d1 c2 b3 a4'=. m
o0=. x a0 y
o1=. x a1 y
o2=. x a2 y
o3=. x a3 y
o4=. x a4 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. o2 b2 o3
o3=. o3 b3 o4
o4=. 0
o0=. o0 c0 o1
o1=. o1 c1 o2
o2=. o2 c2 o3
o3=. 0
o0=. o0 d0 o1
o1=. o1 d1 o2
o2=. 0
o0=. o0 e0 o1
)
NB. ---------------------------------------------------------
NB. fork6
NB.
NB. Description:
NB. 6-fork, generalized fork with 6-depth execution graph
NB.
NB. Syntax:
NB. vapp=. a0`b0`a1`c0`b1`a2`d0`c1`b2`a3`e0`d1`c2`b3`a4`f0`e1`d2`c3`b4`a5 fork5
NB. where
NB. ax - ambivalent verbs to define input nodes of
NB. execution graph
NB. bx cx dx ex - dyads to define intermediate nodes of
NB. execution graph
NB. f0 - dyad to define output node of execution
NB. graph
NB. vapp - 6-fork, is called as:
NB. out=. vapp y
NB. out=. x vapp y
NB.
NB. Execution graph:
NB. f0
NB. / \
NB. e0 e1
NB. / \ / \
NB. d0 d1 d2
NB. / \ / \ / \
NB. c0 c1 c2 c3
NB. / \ / \ / \ / \
NB. b0 b1 b2 b3 b4
NB. / \ / \ / \ / \ / \
NB. a0 a1 a2 a3 a4 a5
NB.
NB. Notes:
NB. - local nouns are re-used to reduce memory consumption
NB. - another 2-fork compatible traverse order is possible:
NB. a0 b0 c0 d0 e0 f0 e1 d2 c3 b4 a5 a1 b1 c1 d1 c2 b3 a4 a2 b2 a3
fork6=: 1 : 0
'`a0 b0 a1 c0 b1 a2 d0 c1 b2 a3 e0 d1 c2 b3 a4 f0 e1 d2 c3 b4 a5'=. m
o0=. a0 y
o1=. a1 y
o2=. a2 y
o3=. a3 y
o4=. a4 y
o5=. a5 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. o2 b2 o3
o3=. o3 b3 o4
o4=. o4 b4 o5
o5=. 0
o0=. o0 c0 o1
o1=. o1 c1 o2
o2=. o2 c2 o3
o3=. o3 c3 o4
o4=. 0
o0=. o0 d0 o1
o1=. o1 d1 o2
o2=. o2 d2 o3
o3=. 0
o0=. o0 e0 o1
o1=. o1 e1 o2
o2=. 0
o0=. o0 f0 o1
:
'`a0 b0 a1 c0 b1 a2 d0 c1 b2 a3 e0 d1 c2 b3 a4 f0 e1 d2 c3 b4 a5'=. m
o0=. x a0 y
o1=. x a1 y
o2=. x a2 y
o3=. x a3 y
o4=. x a4 y
o5=. x a5 y
o0=. o0 b0 o1
o1=. o1 b1 o2
o2=. o2 b2 o3
o3=. o3 b3 o4
o4=. o4 b4 o5
o5=. 0
o0=. o0 c0 o1
o1=. o1 c1 o2
o2=. o2 c2 o3
o3=. o3 c3 o4
o4=. 0
o0=. o0 d0 o1
o1=. o1 d1 o2
o2=. o2 d2 o3
o3=. 0
o0=. o0 e0 o1
o1=. o1 e1 o2
o2=. 0
o0=. o0 f0 o1
)