interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / arboris_ontology.om

395 lines · 8901 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Domain and range tables transcribed from Adam Pippert, Arboris (Apache-2.0),
3note commit 803b432c9be11f0150faa7199d33c40adbda9ae6, ontologies/ upper and domains v0.1.0.
4note Profile 1 selects upper, 2 infrastructure. Type and relation handles are
5note zero-based document order. Property bits in order: name, schedulable, phase, replicas, active.
6om2
7
8note upper-0.1.0 type order:
9note Entity, Agent, Object, System, Component, Event, State, Action, Process, Place, Time, Quantity, Observation, Goal, Claim, Hypothesis, Prediction, Constraint, Resource, Capability
10fn arboris_rule_1 relation ulong to ulong
11 note is_a
12 if eq relation 0
13 ret 0x100000001
14 end
15 note part_of
16 if eq relation 1
17 ret 0x100000001
18 end
19 note contains
20 if eq relation 2
21 ret 0x100000001
22 end
23 note located_in
24 if eq relation 3
25 ret 0x20100000001
26 end
27 note participates_in
28 if eq relation 4
29 ret 0x12000000001
30 end
31 note acts_on
32 if eq relation 5
33 ret 0x100000082
34 end
35 note causes
36 if eq relation 6
37 ret 0x60000000e0
38 end
39 note enables
40 if eq relation 7
41 ret 0x1c000000041
42 end
43 note prevents
44 if eq relation 8
45 ret 0x1c000000041
46 end
47 note precedes
48 if eq relation 9
49 ret 0xe0000000e0
50 end
51 note follows
52 if eq relation 10
53 ret 0xe0000000e0
54 end
55 note depends_on
56 if eq relation 11
57 ret 0x100000001
58 end
59 note supports
60 if eq relation 12
61 ret 0x400100004001
62 end
63 note contradicts
64 if eq relation 13
65 ret 0x504000005040
66 end
67 note observes
68 if eq relation 14
69 ret 0x6100001002
70 end
71 note has_state
72 if eq relation 15
73 ret 0x4000000001
74 end
75 note transforms_into
76 if eq relation 16
77 ret 0x4100000041
78 end
79 note owns
80 if eq relation 17
81 ret 0x10000000a
82 end
83 note controls
84 if eq relation 18
85 ret 0x10000000a
86 end
87 note connected_to
88 if eq relation 19
89 ret 0x100000001
90 end
91 note communicates_with
92 if eq relation 20
93 ret 0x100000001
94 end
95 note requires
96 if eq relation 21
97 ret 0x4004100000181
98 end
99 note produces
100 if eq relation 22
101 ret 0x4000100000101
102 end
103 note consumes
104 if eq relation 23
105 ret 0x4000100000101
106 end
107 ret 0
108end
109
110note infrastructure-0.1.0 type order:
111note Host, Process, Service, Container, Image, Cluster, Node, Pod, Deployment, ReplicaSet, Network, Route, Volume, Certificate, Alert, Request, Dependency, State, Action, Observation
112fn arboris_rule_2 relation ulong to ulong
113 note part_of
114 if eq relation 0
115 ret 0x20000009c4
116 end
117 note scheduled_on
118 if eq relation 1
119 ret 0x4000000080
120 end
121 note managed_by
122 if eq relation 2
123 ret 0x30000000280
124 end
125 note selects
126 if eq relation 3
127 ret 0x18000000004
128 end
129 note routes_to
130 if eq relation 4
131 ret 0x8400000804
132 end
133 note depends_on
134 if eq relation 5
135 ret 0x380400000184
136 end
137 note has_state
138 if eq relation 6
139 ret 0x20000000009ef
140 end
141 ret 0
142end
143
144fn arboris_node_ok profile ulong kind ulong properties uint states uint to bool
145 if ge kind 20
146 ret false
147 end
148 if eq and states 3 3
149 ret false
150 end
151 if eq profile 1
152 ret true
153 end
154 if ne profile 2
155 ret false
156 end
157 note Cluster requires name
158 if eq kind 5
159 ret eq and properties 1 1
160 end
161 note Node requires name, schedulable
162 if eq kind 6
163 ret eq and properties 3 3
164 end
165 note Pod requires name, phase
166 if eq kind 7
167 ret eq and properties 5 5
168 end
169 note Deployment requires name, replicas
170 if eq kind 8
171 ret eq and properties 9 9
172 end
173 note Service requires name
174 if eq kind 2
175 ret eq and properties 1 1
176 end
177 note Route requires active
178 if eq kind 11
179 ret eq and properties 16 16
180 end
181 ret true
182end
183
184fn arboris_edge_ok profile ulong relation ulong subject ulong object_type ulong to bool
185 if or ge subject 20 ge object_type 20
186 ret false
187 end
188 rule = ulong 0
189 if eq profile 1
190 rule = arboris_rule_1 relation
191 end
192 if eq profile 2
193 rule = arboris_rule_2 relation
194 end
195 return_domain = and shr rule subject 1
196 return_range = and shr shr rule 32 object_type 1
197 ret ne and return_domain return_range 0
198end
199
200note Finite non-negative binary32 check: sign bit 0 and exponent < 0xff (< 0x7f800000).
201fn arboris_f32_nonneg_finite bits uint to bool
202 ret lt bits 0x7f800000
203end
204
205note Validate a pull-based incoming-edge CSR in Slab 1 layout (hdr[1]=V, hdr[2]=E, hdr[11]=off_in_src, hdr[12]=off_in_weight).
206note Returns 0 on success, non-zero fail-closed error code on any invalid input.
207fn arboris_check_in_csr_impl hdr view ulong 16 csr view uint * to ulong
208 v_cnt = get hdr 1
209 e_cnt = get hdr 2
210 off_src = div get hdr 11 4
211 off_w = div get hdr 12 4
212 if or eq v_cnt 0 gt v_cnt 0x1fffffff
213 ret 1
214 end
215 if gt e_cnt 0xffffffff
216 ret 1
217 end
218 if or ne and get hdr 11 127 0 ne and get hdr 12 127 0
219 ret 2
220 end
221 if or lt off_src add v_cnt 1 or lt off_w add off_src e_cnt lt len csr add off_w e_cnt
222 ret 2
223 end
224 if ne get csr 0 0
225 ret 3
226 end
227 prev = ulong 0
228 for i ulong v_cnt bound 0x1fffffff
229 nxt = ulong get csr add i 1
230 if or lt nxt prev gt nxt e_cnt
231 ret 3
232 end
233 prev = nxt
234 end
235 if ne prev e_cnt
236 ret 3
237 end
238 for e ulong e_cnt bound 0xffffffff
239 if ge ulong get csr add off_src e v_cnt
240 ret 4
241 end
242 if not arboris_f32_nonneg_finite get csr add off_w e
243 ret 5
244 end
245 end
246 ret 0
247end
248
249fn arboris_in_edge_ok r view uint * epos ulong to ulong
250 prof = ulong get r 1
251 v_cnt = ulong get r 2
252 src = ulong get r epos
253 rel = ulong get r add epos 1
254 dst = ulong get r add epos 2
255 wbits = get r add epos 3
256 if or ge src v_cnt ge dst v_cnt
257 ret 4
258 end
259 ksrc = ulong get r add 6 mul src 3
260 kdst = ulong get r add 6 mul dst 3
261 if not arboris_edge_ok prof rel ksrc kdst
262 ret 7
263 end
264 if not arboris_f32_nonneg_finite wbits
265 ret 5
266 end
267 ret 0
268end
269
270fn arboris_in_records_valid r view uint * to ulong
271 if lt len r 6
272 ret 1
273 end
274 if ne get r 0 0x41523031
275 ret 1
276 end
277 prof = ulong get r 1
278 if or lt prof 1 gt prof 2
279 ret 1
280 end
281 v_cnt = ulong get r 2
282 e_cnt = ulong get r 3
283 if or eq v_cnt 0 gt v_cnt 0x1fffffff
284 ret 1
285 end
286 if gt e_cnt 0xffffffff
287 ret 1
288 end
289 if not arboris_f32_nonneg_finite get r 5
290 ret 5
291 end
292 if ne len r add 6 add mul v_cnt 3 mul e_cnt 4
293 ret 1
294 end
295 for i ulong v_cnt bound 0x1fffffff
296 pos = add 6 mul i 3
297 if not arboris_node_ok prof ulong get r pos get r add pos 1 get r add pos 2
298 ret 6
299 end
300 end
301 ebase = add 6 mul v_cnt 3
302 for e ulong e_cnt bound 0xffffffff
303 rc = arboris_in_edge_ok r add ebase mul e 4
304 if ne rc 0
305 ret rc
306 end
307 end
308 ret 0
309end
310
311fn arboris_scatter_one r view uint * hdr view ulong 16 csr edit uint * epos ulong to void
312 dst = ulong get r add epos 2
313 idx = ulong get csr dst
314 put csr add div get hdr 11 4 idx get r epos
315 put csr add div get hdr 12 4 idx get r add epos 3
316 put csr dst add uint idx 1
317end
318
319fn arboris_scatter_in_csr r view uint * hdr view ulong 16 csr edit uint * to void
320 v_cnt = ulong get r 2
321 e_cnt = ulong get r 3
322 ebase = add 6 mul v_cnt 3
323 for e ulong e_cnt bound 0xffffffff
324 arboris_scatter_one r hdr csr add ebase mul e 4
325 end
326 for i ulong v_cnt bound 0x1fffffff
327 slot = sub v_cnt i
328 put csr slot get csr sub slot 1
329 end
330 put csr 0 0
331end
332
333fn arboris_csr_buf_ok hdr view ulong 16 v_cnt ulong e_cnt ulong csr_len ulong to bool
334 if or ne get hdr 1 v_cnt ne get hdr 2 e_cnt
335 ret false
336 end
337 if ne and get hdr 11 127 0
338 ret false
339 end
340 if ne and get hdr 12 127 0
341 ret false
342 end
343 off_src = div get hdr 11 4
344 off_w = div get hdr 12 4
345 if lt off_src add v_cnt 1
346 ret false
347 end
348 if lt off_w add off_src e_cnt
349 ret false
350 end
351 ret ge csr_len add off_w e_cnt
352end
353
354fn arboris_count_in_rows r view uint * csr edit uint * to void
355 v_cnt = ulong get r 2
356 e_cnt = ulong get r 3
357 for i ulong add v_cnt 1 bound 0x20000000
358 put csr i 0
359 end
360 ebase = add 6 mul v_cnt 3
361 for e ulong e_cnt bound 0xffffffff
362 dst = ulong get r add add ebase mul e 4 2
363 put csr dst add get csr dst 1
364 end
365 cur = uint 0
366 for v ulong v_cnt bound 0x1fffffff
367 cnt = get csr v
368 put csr v cur
369 cur = add cur cnt
370 end
371 put csr v_cnt cur
372end
373
374note Compile validated Arboris AR01 records into pull-based incoming-edge CSR in Slab 1 layout.
375note Fail closed before writing any output word.
376fn arboris_compile_in_csr_impl r view uint * hdr view ulong 16 csr edit uint * to ulong
377 rc = arboris_in_records_valid r
378 if ne rc 0
379 ret rc
380 end
381 if not arboris_csr_buf_ok hdr ulong get r 2 ulong get r 3 len csr
382 ret 2
383 end
384 arboris_count_in_rows r csr
385 arboris_scatter_in_csr r hdr csr
386 ret 0
387end
388
389export fn arboris_validate_in_csr hdr view ulong 16 csr view uint * to ulong
390 ret arboris_check_in_csr_impl hdr csr
391end
392
393export fn arboris_compile_in_csr r view uint * hdr view ulong 16 csr edit uint * to ulong
394 ret arboris_compile_in_csr_impl r hdr csr
395end