eyeling 1.22.5 → 1.22.7

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 (38) hide show
  1. package/HANDBOOK.md +258 -9
  2. package/dist/browser/eyeling.browser.js +162 -11
  3. package/examples/act-alarm-bit-interoperability.n3 +180 -0
  4. package/examples/act-barley-seed-lineage.n3 +565 -0
  5. package/examples/act-docking-abort.n3 +285 -0
  6. package/examples/act-gravity-mediator-witness.n3 +235 -0
  7. package/examples/act-isolation-breach.n3 +354 -0
  8. package/examples/act-photosynthetic-exciton-transfer.n3 +245 -0
  9. package/examples/act-sensor-memory-reset.n3 +190 -0
  10. package/examples/act-tunnel-junction-wake-switch.n3 +225 -0
  11. package/examples/act-yeast-self-reproduction.n3 +248 -0
  12. package/examples/complex-matrix-stability.n3 +288 -0
  13. package/examples/deck/act-barley-seed-lineage.md +593 -0
  14. package/examples/fundamental-theorem-arithmetic.n3 +244 -0
  15. package/examples/harborsmr.n3 +233 -0
  16. package/examples/meta-rule-audit.n3 +135 -0
  17. package/examples/output/act-alarm-bit-interoperability.txt +20 -0
  18. package/examples/output/act-barley-seed-lineage.txt +25 -0
  19. package/examples/output/act-docking-abort.txt +22 -0
  20. package/examples/output/act-gravity-mediator-witness.txt +24 -0
  21. package/examples/output/act-isolation-breach.txt +27 -0
  22. package/examples/output/act-photosynthetic-exciton-transfer.txt +20 -0
  23. package/examples/output/act-sensor-memory-reset.txt +20 -0
  24. package/examples/output/act-tunnel-junction-wake-switch.txt +21 -0
  25. package/examples/output/act-yeast-self-reproduction.txt +23 -0
  26. package/examples/output/complex-matrix-stability.txt +14 -0
  27. package/examples/output/fundamental-theorem-arithmetic.txt +15 -0
  28. package/examples/output/get-uuid.n3 +2 -2
  29. package/examples/output/harborsmr.txt +20 -0
  30. package/examples/output/meta-rule-audit.n3 +44 -0
  31. package/examples/output/theory-diff.n3 +22 -0
  32. package/examples/theory-diff.n3 +125 -0
  33. package/eyeling.js +162 -11
  34. package/lib/builtins.js +52 -1
  35. package/lib/cli.js +31 -5
  36. package/lib/engine.js +79 -5
  37. package/package.json +1 -1
  38. package/test/api.test.js +127 -0
@@ -0,0 +1,288 @@
1
+ # ==========================================================================
2
+ # Complex Matrix Stability — ARC-style
3
+ #
4
+ # Single scenario:
5
+ # A_unstable = diag(1+i, 2)
6
+ # A_stable = diag(1, -1)
7
+ # A_damped = diag(0, 0)
8
+ #
9
+ # This example translates the Eyelet/Prolog ARC example into Notation3 for
10
+ # Eyeling. It computes spectral-radius-squared values for three diagonal 2x2
11
+ # complex matrices, classifies them for discrete-time dynamics, and includes
12
+ # checks for the eigenvalues, modulus arithmetic, and scaling behaviour.
13
+ # ==========================================================================
14
+
15
+ @prefix : <https://example.org/complex-matrix-stability#> .
16
+ @prefix log: <http://www.w3.org/2000/10/swap/log#> .
17
+ @prefix math: <http://www.w3.org/2000/10/swap/math#> .
18
+ @prefix string: <http://www.w3.org/2000/10/swap/string#> .
19
+
20
+ # --------------
21
+ # Editable input
22
+ # --------------
23
+
24
+ :Case
25
+ :unstableMatrix :A_unstable;
26
+ :stableMatrix :A_stable;
27
+ :dampedMatrix :A_damped.
28
+
29
+ :Scale2 :k 2.
30
+
31
+ # ----------------------
32
+ # Complex-number constants
33
+ # ----------------------
34
+
35
+ :c_0_0 :re 0; :im 0; :pretty "(0,0)".
36
+ :c_0_1 :re 0; :im 1; :pretty "(0,1)".
37
+ :c_1_0 :re 1; :im 0; :pretty "(1,0)".
38
+ :c_m1_0 :re -1; :im 0; :pretty "(-1,0)".
39
+ :c_1_1 :re 1; :im 1; :pretty "(1,1)".
40
+ :c_1_2 :re 1; :im 2; :pretty "(1,2)".
41
+ :c_2_0 :re 2; :im 0; :pretty "(2,0)".
42
+
43
+ # --------
44
+ # Matrices
45
+ # --------
46
+
47
+ :A_unstable
48
+ :a11 :c_1_1;
49
+ :a12 :c_0_0;
50
+ :a21 :c_0_0;
51
+ :a22 :c_2_0;
52
+ :pretty "[[(1,1),(0,0)],[(0,0),(2,0)]]".
53
+
54
+ :A_stable
55
+ :a11 :c_1_0;
56
+ :a12 :c_0_0;
57
+ :a21 :c_0_0;
58
+ :a22 :c_m1_0;
59
+ :pretty "[[(1,0),(0,0)],[(0,0),(-1,0)]]".
60
+
61
+ :A_damped
62
+ :a11 :c_0_0;
63
+ :a12 :c_0_0;
64
+ :a21 :c_0_0;
65
+ :a22 :c_0_0;
66
+ :pretty "[[(0,0),(0,0)],[(0,0),(0,0)]]".
67
+
68
+ # -------------------------
69
+ # Backward helper relations
70
+ # -------------------------
71
+
72
+ # |z|^2 = Re^2 + Im^2
73
+ { ?Z :abs2 ?A2 }
74
+ <=
75
+ { ?Z :re ?R; :im ?I.
76
+ (?R ?R) math:product ?R2.
77
+ (?I ?I) math:product ?I2.
78
+ (?R2 ?I2) math:sum ?A2. } .
79
+
80
+ # Detect zero complex numbers.
81
+ { ?Z :isZero true }
82
+ <=
83
+ { ?Z :re 0; :im 0. } .
84
+
85
+ # Eigenvalues of a diagonal 2x2 complex matrix are its diagonal entries.
86
+ { ?M :eigenvalue1 ?L1 }
87
+ <=
88
+ { ?M :a11 ?L1; :a12 ?Z1; :a21 ?Z2; :a22 ?L2.
89
+ ?Z1 :isZero true.
90
+ ?Z2 :isZero true. } .
91
+
92
+ { ?M :eigenvalue2 ?L2 }
93
+ <=
94
+ { ?M :a11 ?L1; :a12 ?Z1; :a21 ?Z2; :a22 ?L2.
95
+ ?Z1 :isZero true.
96
+ ?Z2 :isZero true. } .
97
+
98
+ # Spectral radius squared is the maximum squared modulus of the eigenvalues.
99
+ { ?M :spectralRadiusSq ?A1 }
100
+ <=
101
+ { ?M :eigenvalue1 ?L1; :eigenvalue2 ?L2.
102
+ ?L1 :abs2 ?A1.
103
+ ?L2 :abs2 ?A2.
104
+ ?A1 math:notLessThan ?A2. } .
105
+
106
+ { ?M :spectralRadiusSq ?A2 }
107
+ <=
108
+ { ?M :eigenvalue1 ?L1; :eigenvalue2 ?L2.
109
+ ?L1 :abs2 ?A1.
110
+ ?L2 :abs2 ?A2.
111
+ ?A2 math:greaterThan ?A1. } .
112
+
113
+ # Exact radii for the three scenario outcomes we need.
114
+ { ?M :spectralRadius 2 }
115
+ <=
116
+ { ?M :spectralRadiusSq 4. } .
117
+
118
+ { ?M :spectralRadius 1 }
119
+ <=
120
+ { ?M :spectralRadiusSq 1. } .
121
+
122
+ { ?M :spectralRadius 0 }
123
+ <=
124
+ { ?M :spectralRadiusSq 0. } .
125
+
126
+ # Discrete-time stability classification.
127
+ { ?M :classification :unstable }
128
+ <=
129
+ { ?M :spectralRadiusSq ?R2.
130
+ ?R2 math:greaterThan 1. } .
131
+
132
+ { ?M :classification :stable }
133
+ <=
134
+ { ?M :spectralRadiusSq 1. } .
135
+
136
+ { ?M :classification :damped }
137
+ <=
138
+ { ?M :spectralRadiusSq ?R2.
139
+ ?R2 math:lessThan 1. } .
140
+
141
+ # A concrete complex product for the modulus-multiplication check.
142
+ { :sampleProduct :re ?Cr }
143
+ <=
144
+ { :c_1_2 :re ?Ar; :im ?Ai.
145
+ :c_0_1 :re ?Br; :im ?Bi.
146
+ (?Ar ?Br) math:product ?P1.
147
+ (?Ai ?Bi) math:product ?P2.
148
+ (?P1 ?P2) math:difference ?Cr.
149
+ (?Ar ?Bi) math:product ?P3.
150
+ (?Ai ?Br) math:product ?P4.
151
+ (?P3 ?P4) math:sum ?Ci. } .
152
+
153
+ { :sampleProduct :im ?Ci }
154
+ <=
155
+ { :c_1_2 :re ?Ar; :im ?Ai.
156
+ :c_0_1 :re ?Br; :im ?Bi.
157
+ (?Ar ?Br) math:product ?P1.
158
+ (?Ai ?Bi) math:product ?P2.
159
+ (?P1 ?P2) math:difference ?Cr.
160
+ (?Ar ?Bi) math:product ?P3.
161
+ (?Ai ?Br) math:product ?P4.
162
+ (?P3 ?P4) math:sum ?Ci. } .
163
+
164
+ # Spectral-radius-squared for 2*A_unstable, derived from the scaled eigenvalue moduli.
165
+ { :A_unstable :scaledRadiusSq ?S2 }
166
+ <=
167
+ { :Scale2 :k ?K.
168
+ (?K ?K) math:product ?K2.
169
+ (?K2 2) math:product ?S1.
170
+ (?K2 4) math:product ?S2.
171
+ ?S2 math:greaterThan ?S1. } .
172
+
173
+ # ---------------------------
174
+ # Materialized scenario facts
175
+ # ---------------------------
176
+
177
+ { :Case :unstableMatrix ?Mu; :stableMatrix ?Ms; :dampedMatrix ?Md.
178
+ ?Mu :classification :unstable; :spectralRadius 2.
179
+ ?Ms :classification :stable; :spectralRadius 1.
180
+ ?Md :classification :damped; :spectralRadius 0. }
181
+ =>
182
+ { :Case :scenarioOk true. } .
183
+
184
+ # ------
185
+ # Checks
186
+ # ------
187
+
188
+ { :A_unstable :eigenvalue1 :c_1_1; :eigenvalue2 :c_2_0; :spectralRadiusSq 4; :spectralRadius 2; :classification :unstable. }
189
+ =>
190
+ { :Check :c1 "OK - A_unstable has eigenvalues (1,1) and (2,0) with spectral radius 2, so it is unstable.". } .
191
+
192
+ { :A_stable :eigenvalue1 :c_1_0; :eigenvalue2 :c_m1_0; :spectralRadiusSq 1; :spectralRadius 1; :classification :stable. }
193
+ =>
194
+ { :Check :c2 "OK - A_stable has eigenvalues (1,0) and (-1,0) with spectral radius 1, so it is marginally stable.". } .
195
+
196
+ { :A_damped :eigenvalue1 :c_0_0; :eigenvalue2 :c_0_0; :spectralRadiusSq 0; :spectralRadius 0; :classification :damped. }
197
+ =>
198
+ { :Check :c3 "OK - A_damped has eigenvalues (0,0) and (0,0) with spectral radius 0, so every mode decays to zero.". } .
199
+
200
+ { :c_1_2 :abs2 ?AZ2.
201
+ :c_0_1 :abs2 ?AW2.
202
+ :sampleProduct :abs2 ?AZW2.
203
+ (?AZ2 ?AW2) math:product ?Target.
204
+ ?AZW2 math:equalTo ?Target. }
205
+ =>
206
+ { :Check :c4 "OK - for z = (1,2) and w = (0,1), the squared modulus of z*w equals the product of the squared moduli.". } .
207
+
208
+ { :A_unstable :spectralRadiusSq ?Ru2.
209
+ :A_unstable :scaledRadiusSq ?Ru2Scaled.
210
+ (4 ?Ru2) math:product ?Target.
211
+ ?Ru2Scaled math:equalTo ?Target. }
212
+ =>
213
+ { :Check :c5 "OK - the spectral-radius-squared of 2*A_unstable is four times that of A_unstable.". } .
214
+
215
+ # -----
216
+ # Fuses
217
+ # -----
218
+
219
+ { 1 log:notIncludes { :Case :scenarioOk true. }. }
220
+ => false .
221
+
222
+ { 1 log:notIncludes { :Check :c1 ?C. }. }
223
+ => false .
224
+
225
+ { 1 log:notIncludes { :Check :c2 ?C. }. }
226
+ => false .
227
+
228
+ { 1 log:notIncludes { :Check :c3 ?C. }. }
229
+ => false .
230
+
231
+ { 1 log:notIncludes { :Check :c4 ?C. }. }
232
+ => false .
233
+
234
+ { 1 log:notIncludes { :Check :c5 ?C. }. }
235
+ => false .
236
+
237
+ # ---------------------
238
+ # Answer and reason why
239
+ # ---------------------
240
+
241
+ { :Case :scenarioOk true;
242
+ :unstableMatrix ?Mu;
243
+ :stableMatrix ?Ms;
244
+ :dampedMatrix ?Md.
245
+ ?Mu :pretty ?MuS; :spectralRadius ?Ru.
246
+ ?Ms :pretty ?MsS; :spectralRadius ?Rs.
247
+ ?Md :pretty ?MdS; :spectralRadius ?Rd.
248
+ :Check :c1 ?C1.
249
+ :Check :c2 ?C2.
250
+ :Check :c3 ?C3.
251
+ :Check :c4 ?C4.
252
+ :Check :c5 ?C5.
253
+ (
254
+ "Complex Matrix Stability — ARC-style
255
+
256
+ "
257
+ "Answer
258
+ "
259
+ "We compare three diagonal 2x2 complex matrices for discrete-time stability: "
260
+ "A_unstable = " ?MuS ", A_stable = " ?MsS ", and A_damped = " ?MdS ". "
261
+ "Their spectral radii are ρ(A_unstable) = " ?Ru ", ρ(A_stable) = " ?Rs ", and ρ(A_damped) = " ?Rd ". "
262
+ "So A_unstable is unstable, A_stable is marginally stable, and A_damped is damped.
263
+
264
+ "
265
+ "Reason Why
266
+ "
267
+ "For a discrete-time linear system x_{k+1} = A x_k, the eigenvalues of A govern the behaviour of the modes. "
268
+ "Because these matrices are diagonal, the eigenvalues are just the diagonal entries. "
269
+ "The spectral radius is the maximum modulus of the eigenvalues: if it is greater than 1 a mode grows, "
270
+ "if it equals 1 the modes remain bounded without decaying, and if it is less than 1 all modes decay to zero. "
271
+ "Here the diagonal entries give radii 2, 1, and 0 respectively, which explains the three classifications.
272
+
273
+ "
274
+ "Check
275
+ "
276
+ "C1 " ?C1 "
277
+ "
278
+ "C2 " ?C2 "
279
+ "
280
+ "C3 " ?C3 "
281
+ "
282
+ "C4 " ?C4 "
283
+ "
284
+ "C5 " ?C5 "
285
+ "
286
+ ) string:concatenation ?Block. }
287
+ =>
288
+ { :report log:outputString ?Block. } .