eyeling 1.23.5 → 1.24.0

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 (259) hide show
  1. package/README.md +1 -0
  2. package/dist/browser/eyeling.browser.js +11876 -11928
  3. package/package.json +7 -5
  4. package/see/README.md +146 -0
  5. package/see/examples/_see.js +218 -0
  6. package/see/examples/age.js +1433 -0
  7. package/see/examples/annotation.js +1294 -0
  8. package/see/examples/backward.js +1379 -0
  9. package/see/examples/backward_recursion.js +1478 -0
  10. package/see/examples/bayes_diagnosis.js +2857 -0
  11. package/see/examples/bayes_therapy.js +4126 -0
  12. package/see/examples/bmi.js +3012 -0
  13. package/see/examples/builtin_coverage.js +2498 -0
  14. package/see/examples/collection.js +1294 -0
  15. package/see/examples/complex.js +3736 -0
  16. package/see/examples/complex_matrix_stability.js +2947 -0
  17. package/see/examples/composition_of_injective_functions_is_injective.js +2144 -0
  18. package/see/examples/control_system.js +1892 -0
  19. package/see/examples/crypto_builtins_tests.js +1463 -0
  20. package/see/examples/delfour.js +3148 -0
  21. package/see/examples/digital_product_passport.js +2830 -0
  22. package/see/examples/dijkstra.js +2044 -0
  23. package/see/examples/dijkstra_risk_path.js +1848 -0
  24. package/see/examples/doc/age.md +27 -0
  25. package/see/examples/doc/annotation.md +24 -0
  26. package/see/examples/doc/backward.md +26 -0
  27. package/see/examples/doc/backward_recursion.md +26 -0
  28. package/see/examples/doc/bayes_diagnosis.md +41 -0
  29. package/see/examples/doc/bayes_therapy.md +40 -0
  30. package/see/examples/doc/bmi.md +38 -0
  31. package/see/examples/doc/builtin_coverage.md +53 -0
  32. package/see/examples/doc/collection.md +24 -0
  33. package/see/examples/doc/complex.md +38 -0
  34. package/see/examples/doc/complex_matrix_stability.md +35 -0
  35. package/see/examples/doc/composition_of_injective_functions_is_injective.md +24 -0
  36. package/see/examples/doc/control_system.md +32 -0
  37. package/see/examples/doc/crypto_builtins_tests.md +27 -0
  38. package/see/examples/doc/delfour.md +37 -0
  39. package/see/examples/doc/digital_product_passport.md +36 -0
  40. package/see/examples/doc/dijkstra.md +28 -0
  41. package/see/examples/doc/dijkstra_risk_path.md +30 -0
  42. package/see/examples/doc/dog.md +28 -0
  43. package/see/examples/doc/eco_route_insight.md +33 -0
  44. package/see/examples/doc/equals.md +26 -0
  45. package/see/examples/doc/equivalence_classes_overlap_implies_same_class.md +24 -0
  46. package/see/examples/doc/euler_identity.md +39 -0
  47. package/see/examples/doc/ev_roundtrip_planner.md +32 -0
  48. package/see/examples/doc/existential_rule.md +24 -0
  49. package/see/examples/doc/expression_eval.md +26 -0
  50. package/see/examples/doc/family_cousins.md +24 -0
  51. package/see/examples/doc/fastpow.md +29 -0
  52. package/see/examples/doc/fibonacci.md +28 -0
  53. package/see/examples/doc/french_cities.md +28 -0
  54. package/see/examples/doc/fundamental_theorem_arithmetic.md +36 -0
  55. package/see/examples/doc/genetic_knapsack_selection.md +29 -0
  56. package/see/examples/doc/goldbach_1000.md +31 -0
  57. package/see/examples/doc/good_cobbler.md +27 -0
  58. package/see/examples/doc/gps.md +35 -0
  59. package/see/examples/doc/gray_code_counter.md +31 -0
  60. package/see/examples/doc/greatest_lower_bound_uniqueness.md +24 -0
  61. package/see/examples/doc/group_inverse_uniqueness.md +24 -0
  62. package/see/examples/doc/hadamard_approx.md +32 -0
  63. package/see/examples/doc/hanoi.md +26 -0
  64. package/see/examples/doc/odrl_dpv_risk_ranked.md +57 -0
  65. package/see/examples/doc/path_discovery.md +33 -0
  66. package/see/examples/doc/rc_discharge_envelope.md +33 -0
  67. package/see/examples/doc/rdf_message_flow.md +35 -0
  68. package/see/examples/doc/rdf_messages.md +37 -0
  69. package/see/examples/doc/school_placement_audit.md +31 -0
  70. package/see/examples/doc/smoke_arithmetic.md +31 -0
  71. package/see/examples/doc/socrates.md +24 -0
  72. package/see/examples/doc/wind_turbine.md +37 -0
  73. package/see/examples/doc/witch.md +28 -0
  74. package/see/examples/dog.js +1410 -0
  75. package/see/examples/eco_route_insight.js +2084 -0
  76. package/see/examples/equals.js +1337 -0
  77. package/see/examples/equivalence_classes_overlap_implies_same_class.js +1766 -0
  78. package/see/examples/euler_identity.js +2012 -0
  79. package/see/examples/ev_roundtrip_planner.js +2536 -0
  80. package/see/examples/existential_rule.js +1337 -0
  81. package/see/examples/expression_eval.js +1772 -0
  82. package/see/examples/family_cousins.js +1560 -0
  83. package/see/examples/fastpow.js +2181 -0
  84. package/see/examples/fibonacci.js +1568 -0
  85. package/see/examples/french_cities.js +1466 -0
  86. package/see/examples/fundamental_theorem_arithmetic.js +2080 -0
  87. package/see/examples/genetic_knapsack_selection.js +1717 -0
  88. package/see/examples/goldbach_1000.js +1772 -0
  89. package/see/examples/good_cobbler.js +1370 -0
  90. package/see/examples/gps.js +2787 -0
  91. package/see/examples/gray_code_counter.js +1615 -0
  92. package/see/examples/greatest_lower_bound_uniqueness.js +1892 -0
  93. package/see/examples/group_inverse_uniqueness.js +1871 -0
  94. package/see/examples/hadamard_approx.js +4391 -0
  95. package/see/examples/hanoi.js +1599 -0
  96. package/see/examples/input/age.trig +27 -0
  97. package/see/examples/input/annotation.trig +31 -0
  98. package/see/examples/input/backward.trig +25 -0
  99. package/see/examples/input/backward_recursion.trig +25 -0
  100. package/see/examples/input/bayes_diagnosis.trig +111 -0
  101. package/see/examples/input/bayes_therapy.trig +130 -0
  102. package/see/examples/input/bmi.trig +28 -0
  103. package/see/examples/input/builtin_coverage.trig +24 -0
  104. package/see/examples/input/collection.trig +25 -0
  105. package/see/examples/input/complex.trig +26 -0
  106. package/see/examples/input/complex_matrix_stability.trig +65 -0
  107. package/see/examples/input/composition_of_injective_functions_is_injective.trig +35 -0
  108. package/see/examples/input/control_system.trig +31 -0
  109. package/see/examples/input/crypto_builtins_tests.trig +25 -0
  110. package/see/examples/input/delfour.trig +90 -0
  111. package/see/examples/input/digital_product_passport.trig +116 -0
  112. package/see/examples/input/dijkstra.trig +34 -0
  113. package/see/examples/input/dijkstra_risk_path.trig +46 -0
  114. package/see/examples/input/dog.trig +31 -0
  115. package/see/examples/input/eco_route_insight.trig +58 -0
  116. package/see/examples/input/equals.trig +25 -0
  117. package/see/examples/input/equivalence_classes_overlap_implies_same_class.trig +28 -0
  118. package/see/examples/input/euler_identity.trig +34 -0
  119. package/see/examples/input/ev_roundtrip_planner.trig +90 -0
  120. package/see/examples/input/existential_rule.trig +26 -0
  121. package/see/examples/input/expression_eval.trig +41 -0
  122. package/see/examples/input/family_cousins.trig +39 -0
  123. package/see/examples/input/fastpow.trig +25 -0
  124. package/see/examples/input/fibonacci.trig +51 -0
  125. package/see/examples/input/french_cities.trig +38 -0
  126. package/see/examples/input/fundamental_theorem_arithmetic.trig +42 -0
  127. package/see/examples/input/genetic_knapsack_selection.trig +39 -0
  128. package/see/examples/input/goldbach_1000.trig +53 -0
  129. package/see/examples/input/good_cobbler.trig +24 -0
  130. package/see/examples/input/gps.trig +35 -0
  131. package/see/examples/input/gray_code_counter.trig +33 -0
  132. package/see/examples/input/greatest_lower_bound_uniqueness.trig +29 -0
  133. package/see/examples/input/group_inverse_uniqueness.trig +29 -0
  134. package/see/examples/input/hadamard_approx.trig +32 -0
  135. package/see/examples/input/hanoi.trig +26 -0
  136. package/see/examples/input/odrl_dpv_risk_ranked.trig +107 -0
  137. package/see/examples/input/path-discovery.trig +96448 -0
  138. package/see/examples/input/path_discovery.trig +29 -0
  139. package/see/examples/input/rc_discharge_envelope.trig +37 -0
  140. package/see/examples/input/rdf_message_flow.trig +100 -0
  141. package/see/examples/input/rdf_messages.trig +69 -0
  142. package/see/examples/input/school_placement_audit.trig +51 -0
  143. package/see/examples/input/smoke_arithmetic.trig +27 -0
  144. package/see/examples/input/socrates.trig +26 -0
  145. package/see/examples/input/wind_turbine.trig +48 -0
  146. package/see/examples/input/witch.trig +26 -0
  147. package/see/examples/n3/age.n3 +28 -0
  148. package/see/examples/n3/annotation.n3 +7 -0
  149. package/see/examples/n3/backward.n3 +22 -0
  150. package/see/examples/n3/backward_recursion.n3 +12 -0
  151. package/see/examples/n3/bayes_diagnosis.n3 +122 -0
  152. package/see/examples/n3/bayes_therapy.n3 +149 -0
  153. package/see/examples/n3/bmi.n3 +145 -0
  154. package/see/examples/n3/builtin_coverage.n3 +68 -0
  155. package/see/examples/n3/collection.n3 +3 -0
  156. package/see/examples/n3/complex.n3 +140 -0
  157. package/see/examples/n3/complex_matrix_stability.n3 +113 -0
  158. package/see/examples/n3/composition_of_injective_functions_is_injective.n3 +27 -0
  159. package/see/examples/n3/control_system.n3 +59 -0
  160. package/see/examples/n3/crypto_builtins_tests.n3 +18 -0
  161. package/see/examples/n3/delfour.n3 +167 -0
  162. package/see/examples/n3/digital_product_passport.n3 +156 -0
  163. package/see/examples/n3/dijkstra.n3 +46 -0
  164. package/see/examples/n3/dijkstra_risk_path.n3 +67 -0
  165. package/see/examples/n3/dog.n3 +20 -0
  166. package/see/examples/n3/eco_route_insight.n3 +88 -0
  167. package/see/examples/n3/equals.n3 +11 -0
  168. package/see/examples/n3/equivalence_classes_overlap_implies_same_class.n3 +19 -0
  169. package/see/examples/n3/euler_identity.n3 +41 -0
  170. package/see/examples/n3/ev_roundtrip_planner.n3 +82 -0
  171. package/see/examples/n3/existential_rule.n3 +10 -0
  172. package/see/examples/n3/expression_eval.n3 +21 -0
  173. package/see/examples/n3/family_cousins.n3 +62 -0
  174. package/see/examples/n3/fastpow.n3 +56 -0
  175. package/see/examples/n3/fibonacci.n3 +44 -0
  176. package/see/examples/n3/french_cities.n3 +28 -0
  177. package/see/examples/n3/fundamental_theorem_arithmetic.n3 +84 -0
  178. package/see/examples/n3/genetic_knapsack_selection.n3 +54 -0
  179. package/see/examples/n3/goldbach_1000.n3 +66 -0
  180. package/see/examples/n3/good_cobbler.n3 +10 -0
  181. package/see/examples/n3/gps.n3 +70 -0
  182. package/see/examples/n3/gray_code_counter.n3 +53 -0
  183. package/see/examples/n3/greatest_lower_bound_uniqueness.n3 +20 -0
  184. package/see/examples/n3/group_inverse_uniqueness.n3 +19 -0
  185. package/see/examples/n3/hadamard_approx.n3 +43 -0
  186. package/see/examples/n3/hanoi.n3 +16 -0
  187. package/see/examples/n3/odrl_dpv_risk_ranked.n3 +460 -0
  188. package/see/examples/n3/path_discovery.n3 +43 -0
  189. package/see/examples/n3/rc_discharge_envelope.n3 +61 -0
  190. package/see/examples/n3/rdf_message_flow.n3 +209 -0
  191. package/see/examples/n3/rdf_messages.n3 +143 -0
  192. package/see/examples/n3/school_placement_audit.n3 +63 -0
  193. package/see/examples/n3/smoke_arithmetic.n3 +22 -0
  194. package/see/examples/n3/socrates.n3 +21 -0
  195. package/see/examples/n3/wind_turbine.n3 +85 -0
  196. package/see/examples/n3/witch.n3 +30 -0
  197. package/see/examples/odrl_dpv_risk_ranked.js +5102 -0
  198. package/see/examples/output/age.md +48 -0
  199. package/see/examples/output/annotation.md +43 -0
  200. package/see/examples/output/backward.md +50 -0
  201. package/see/examples/output/backward_recursion.md +54 -0
  202. package/see/examples/output/bayes_diagnosis.md +103 -0
  203. package/see/examples/output/bayes_therapy.md +84 -0
  204. package/see/examples/output/bmi.md +164 -0
  205. package/see/examples/output/builtin_coverage.md +99 -0
  206. package/see/examples/output/collection.md +44 -0
  207. package/see/examples/output/complex.md +61 -0
  208. package/see/examples/output/complex_matrix_stability.md +55 -0
  209. package/see/examples/output/composition_of_injective_functions_is_injective.md +62 -0
  210. package/see/examples/output/control_system.md +61 -0
  211. package/see/examples/output/crypto_builtins_tests.md +68 -0
  212. package/see/examples/output/delfour.md +100 -0
  213. package/see/examples/output/digital_product_passport.md +100 -0
  214. package/see/examples/output/dijkstra.md +74 -0
  215. package/see/examples/output/dijkstra_risk_path.md +76 -0
  216. package/see/examples/output/dog.md +50 -0
  217. package/see/examples/output/eco_route_insight.md +88 -0
  218. package/see/examples/output/equals.md +50 -0
  219. package/see/examples/output/equivalence_classes_overlap_implies_same_class.md +86 -0
  220. package/see/examples/output/euler_identity.md +73 -0
  221. package/see/examples/output/ev_roundtrip_planner.md +79 -0
  222. package/see/examples/output/existential_rule.md +54 -0
  223. package/see/examples/output/expression_eval.md +50 -0
  224. package/see/examples/output/family_cousins.md +187 -0
  225. package/see/examples/output/fastpow.md +36 -0
  226. package/see/examples/output/fibonacci.md +53 -0
  227. package/see/examples/output/french_cities.md +70 -0
  228. package/see/examples/output/fundamental_theorem_arithmetic.md +101 -0
  229. package/see/examples/output/genetic_knapsack_selection.md +66 -0
  230. package/see/examples/output/goldbach_1000.md +58 -0
  231. package/see/examples/output/good_cobbler.md +54 -0
  232. package/see/examples/output/gps.md +102 -0
  233. package/see/examples/output/gray_code_counter.md +68 -0
  234. package/see/examples/output/greatest_lower_bound_uniqueness.md +60 -0
  235. package/see/examples/output/group_inverse_uniqueness.md +60 -0
  236. package/see/examples/output/hadamard_approx.md +510 -0
  237. package/see/examples/output/hanoi.md +51 -0
  238. package/see/examples/output/odrl_dpv_risk_ranked.md +139 -0
  239. package/see/examples/output/path_discovery.md +65 -0
  240. package/see/examples/output/rc_discharge_envelope.md +102 -0
  241. package/see/examples/output/rdf_message_flow.md +198 -0
  242. package/see/examples/output/rdf_messages.md +134 -0
  243. package/see/examples/output/school_placement_audit.md +99 -0
  244. package/see/examples/output/smoke_arithmetic.md +54 -0
  245. package/see/examples/output/socrates.md +55 -0
  246. package/see/examples/output/wind_turbine.md +108 -0
  247. package/see/examples/output/witch.md +87 -0
  248. package/see/examples/path_discovery.js +1748 -0
  249. package/see/examples/rc_discharge_envelope.js +1967 -0
  250. package/see/examples/rdf_message_flow.js +2554 -0
  251. package/see/examples/rdf_messages.js +2150 -0
  252. package/see/examples/school_placement_audit.js +1841 -0
  253. package/see/examples/smoke_arithmetic.js +1457 -0
  254. package/see/examples/socrates.js +1394 -0
  255. package/see/examples/wind_turbine.js +2827 -0
  256. package/see/examples/witch.js +1493 -0
  257. package/see/see.js +1794 -0
  258. package/test/see.test.js +159 -0
  259. package/tools/n3gen.js +1 -1
@@ -0,0 +1,149 @@
1
+ # ==============
2
+ # Bayes Therapy
3
+ # ==============
4
+ # Extends the Bayesian diagnosis model with a therapy utility layer. Adapted
5
+ # from Eyeling's bayes-therapy.n3. Values are illustrative only and are not
6
+ # medical advice.
7
+
8
+ @prefix : <https://eyereasoner.github.io/see/examples/bayes-therapy#>.
9
+ @prefix math: <http://www.w3.org/2000/10/swap/math#>.
10
+ @prefix list: <http://www.w3.org/2000/10/swap/list#>.
11
+ @prefix log: <http://www.w3.org/2000/10/swap/log#>.
12
+ @prefix string: <http://www.w3.org/2000/10/swap/string#>.
13
+
14
+ :COVID19 a :Disease; :prior 0.05.
15
+ :Influenza a :Disease; :prior 0.03.
16
+ :AllergicRhinitis a :Disease; :prior 0.10.
17
+ :BacterialPneumonia a :Disease; :prior 0.01.
18
+
19
+ :COVID19 :pGiven [ :symptom :Fever; :p 0.70 ], [ :symptom :DryCough; :p 0.65 ], [ :symptom :LossOfSmell; :p 0.40 ], [ :symptom :Sneezing; :p 0.15 ], [ :symptom :ShortBreath; :p 0.20 ].
20
+ :Influenza :pGiven [ :symptom :Fever; :p 0.80 ], [ :symptom :DryCough; :p 0.50 ], [ :symptom :LossOfSmell; :p 0.05 ], [ :symptom :Sneezing; :p 0.20 ], [ :symptom :ShortBreath; :p 0.10 ].
21
+ :AllergicRhinitis :pGiven [ :symptom :Fever; :p 0.05 ], [ :symptom :DryCough; :p 0.15 ], [ :symptom :LossOfSmell; :p 0.10 ], [ :symptom :Sneezing; :p 0.80 ], [ :symptom :ShortBreath; :p 0.05 ].
22
+ :BacterialPneumonia :pGiven [ :symptom :Fever; :p 0.70 ], [ :symptom :DryCough; :p 0.60 ], [ :symptom :LossOfSmell; :p 0.02 ], [ :symptom :Sneezing; :p 0.05 ], [ :symptom :ShortBreath; :p 0.60 ].
23
+
24
+ :Paxlovid a :Therapy; :label "Paxlovid"; :successByDisease ( 0.75 0.05 0.02 0.05 ); :adverse 0.10.
25
+ :Oseltamivir a :Therapy; :label "Oseltamivir"; :successByDisease ( 0.05 0.60 0.02 0.05 ); :adverse 0.08.
26
+ :Antihistamine a :Therapy; :label "Antihistamine"; :successByDisease ( 0.10 0.10 0.75 0.05 ); :adverse 0.03.
27
+ :Antibiotic a :Therapy; :label "Antibiotic"; :successByDisease ( 0.05 0.05 0.02 0.80 ); :adverse 0.07.
28
+ :SupportiveCare a :Therapy; :label "Supportive care"; :successByDisease ( 0.30 0.30 0.25 0.20 ); :adverse 0.01.
29
+
30
+ :Model :benefitWeight 10; :harmWeight 3.
31
+ :Case a :PatientCase;
32
+ :diseases (:COVID19 :Influenza :AllergicRhinitis :BacterialPneumonia);
33
+ :therapies (:Paxlovid :Oseltamivir :SupportiveCare :Antibiotic :Antihistamine);
34
+ :evidence (
35
+ [ :symptom :Fever; :present true ]
36
+ [ :symptom :DryCough; :present true ]
37
+ [ :symptom :LossOfSmell; :present false ]
38
+ [ :symptom :Sneezing; :present false ]
39
+ [ :symptom :ShortBreath; :present false ]
40
+ ).
41
+
42
+ { ?d :prior ?p. ?p math:lessThan 0. } => false.
43
+ { ?d :prior ?p. ?p math:greaterThan 1. } => false.
44
+ { ?d :pGiven [ :p ?p ]. ?p math:lessThan 0. } => false.
45
+ { ?d :pGiven [ :p ?p ]. ?p math:greaterThan 1. } => false.
46
+ { ?t a :Therapy; :adverse ?p. ?p math:lessThan 0. } => false.
47
+ { ?t a :Therapy; :adverse ?p. ?p math:greaterThan 1. } => false.
48
+ { ?t a :Therapy; :successByDisease ?ps. ?ps list:iterate ( ?i ?p ). ?p math:lessThan 0. } => false.
49
+ { ?t a :Therapy; :successByDisease ?ps. ?ps list:iterate ( ?i ?p ). ?p math:greaterThan 1. } => false.
50
+
51
+ { ( ?d () ) :pairList () } <= true.
52
+ { ( ?d ?xs ) :pairList ?pairs } <= {
53
+ ?xs list:firstRest ( ?x ?rest ).
54
+ ( ?d ?rest ) :pairList ?tailPairs.
55
+ ?pairs list:firstRest ( ( ?d ?x ) ?tailPairs ).
56
+ }.
57
+ { ( () ?c ) :pairWithConst () } <= true.
58
+ { ( ?xs ?c ) :pairWithConst ?pairs } <= {
59
+ ?xs list:firstRest ( ?x ?rest ).
60
+ ( ?rest ?c ) :pairWithConst ?tailPairs.
61
+ ?pairs list:firstRest ( ( ?x ?c ) ?tailPairs ).
62
+ }.
63
+ { ( () () ) :zip () } <= true.
64
+ { ( ?as ?bs ) :zip ?pairs } <= {
65
+ ?as list:firstRest ( ?a ?arest ).
66
+ ?bs list:firstRest ( ?b ?brest ).
67
+ ( ?arest ?brest ) :zip ?tailPairs.
68
+ ?pairs list:firstRest ( ( ?a ?b ) ?tailPairs ).
69
+ }.
70
+ { ?pair :mul ?p } <= { ?pair math:product ?p }.
71
+ { ?pair :quot2 ?q } <= { ?pair math:quotient ?q }.
72
+
73
+ { ( ?d ?ev ) :factor ?p } <= {
74
+ ?ev :symptom ?s; :present true.
75
+ ?d :pGiven [ :symptom ?s; :p ?p ].
76
+ }.
77
+ { ( ?d ?ev ) :factor ?q } <= {
78
+ ?ev :symptom ?s; :present false.
79
+ ?d :pGiven [ :symptom ?s; :p ?p ].
80
+ ( 1 ?p ) math:difference ?q.
81
+ }.
82
+ { ?d :scoreFor ?score } <= {
83
+ ?d :prior ?prior.
84
+ :Case :evidence ?evs.
85
+ ( ?d ?evs ) :pairList ?pairs.
86
+ ( ?pairs :factor ) list:map ?factors.
87
+ ?factors math:product ?likelihood.
88
+ ( ?prior ?likelihood ) math:product ?score.
89
+ }.
90
+ {
91
+ :Case :diseases ?ds.
92
+ ( ?ds :scoreFor ) list:map ?scores.
93
+ ?scores math:sum ?total.
94
+ ( ?scores ?total ) :pairWithConst ?scorePairs.
95
+ ( ?scorePairs :quot2 ) list:map ?posteriors.
96
+ } => {
97
+ :Case :scores ?scores; :evidenceTotal ?total; :posteriors ?posteriors.
98
+ }.
99
+ {
100
+ :Case :diseases ?ds; :posteriors ?posts.
101
+ ?ds list:iterate ( ?i ?d ).
102
+ ( ?posts ?i ) list:memberAt ?p.
103
+ } => {
104
+ ?d :posterior ?p.
105
+ }.
106
+
107
+ # expectedSuccess(t) = sum_i posterior[i] * P(success | disease_i, t)
108
+ {
109
+ :Case :posteriors ?posts.
110
+ ?t a :Therapy; :successByDisease ?succ; :adverse ?adverse.
111
+ ( ?posts ?succ ) :zip ?pairs.
112
+ ( ?pairs :mul ) list:map ?terms.
113
+ ?terms math:sum ?expectedSuccess.
114
+ :Model :benefitWeight ?bw; :harmWeight ?hw.
115
+ ( ?bw ?expectedSuccess ) math:product ?benefit.
116
+ ( ?hw ?adverse ) math:product ?harmCost.
117
+ ( ?benefit ?harmCost ) math:difference ?utility.
118
+ } => {
119
+ ?t :expectedSuccess ?expectedSuccess;
120
+ :expectedAdverse ?adverse;
121
+ :utility ?utility.
122
+ }.
123
+
124
+ { ( ?t1 ?t2 ) :betterOf ?t1 } <= { ?t1 :utility ?u1. ?t2 :utility ?u2. ?u1 math:notLessThan ?u2. }.
125
+ { ( ?t1 ?t2 ) :betterOf ?t2 } <= { ?t1 :utility ?u1. ?t2 :utility ?u2. ?u1 math:lessThan ?u2. }.
126
+ { ( ?ts ) :bestTherapy ?t } <= { ?ts list:firstRest ( ?t () ). }.
127
+ { ( ?ts ) :bestTherapy ?best } <= {
128
+ ?ts list:firstRest ( ?head ?rest ).
129
+ ?rest list:firstRest ( ?_ ?__ ).
130
+ ( ?rest ) :bestTherapy ?bestRest.
131
+ ( ?head ?bestRest ) :betterOf ?best.
132
+ }.
133
+ { :Case :therapies ?ts. ( ?ts ) :bestTherapy ?best. } => { :Case :recommendedTherapy ?best. }.
134
+
135
+ {
136
+ :Case :recommendedTherapy ?best.
137
+ ?best :label ?bestLabel; :expectedSuccess ?bestSuccess; :expectedAdverse ?bestAdverse; :utility ?bestUtility.
138
+ :Paxlovid :utility ?paxU; :expectedSuccess ?paxS; :expectedAdverse ?paxA.
139
+ :Oseltamivir :utility ?oseU; :expectedSuccess ?oseS; :expectedAdverse ?oseA.
140
+ :SupportiveCare :utility ?supU; :expectedSuccess ?supS; :expectedAdverse ?supA.
141
+ :Antibiotic :utility ?antibU; :expectedSuccess ?antibS; :expectedAdverse ?antibA.
142
+ :Antihistamine :utility ?antiU; :expectedSuccess ?antiS; :expectedAdverse ?antiA.
143
+ ("=== Answer ===\nRecommended therapy: %s (utility = %.6f).\nexpected success : %.6f\nadverse probability : %.6f\n\nTherapy utilities:\n Paxlovid utility = %.6f success = %.6f adverse = %.6f\n Oseltamivir utility = %.6f success = %.6f adverse = %.6f\n Supportive care utility = %.6f success = %.6f adverse = %.6f\n Antibiotic utility = %.6f success = %.6f adverse = %.6f\n Antihistamine utility = %.6f success = %.6f adverse = %.6f\n\n=== Explanation ===\nThe N3 source first computes disease posteriors from the symptom evidence. It then combines those posterior probabilities with therapy-specific success probabilities, subtracting the weighted adverse-effect penalty from the weighted expected benefit." ?bestLabel ?bestUtility ?bestSuccess ?bestAdverse ?paxU ?paxS ?paxA ?oseU ?oseS ?oseA ?supU ?supS ?supA ?antibU ?antibS ?antibA ?antiU ?antiS ?antiA) string:format ?Block.
144
+ } => {
145
+ :bayesTherapy log:outputString ?Block.
146
+ :bayesTherapy :recommends ?best.
147
+ }.
148
+
149
+ { :bayesTherapy :recommends ?Therapy } log:query { :bayesTherapy :recommends ?Therapy }.
@@ -0,0 +1,145 @@
1
+ # ============================================================================
2
+ # BMI — Body Mass Index example.
3
+ #
4
+ # This example turns a familiar health calculation into a small, inspectable
5
+ # SEE example. It normalizes either metric or US inputs, computes BMI, assigns
6
+ # a WHO adult category, and derives a healthy-range weight band for the given
7
+ # height. The report explains the result and includes independent validations for
8
+ # boundary handling and category behavior.
9
+ #
10
+ # For reproducibility and documentation only; not medical advice.
11
+ # ============================================================================
12
+
13
+ @prefix : <https://example.org/bmi#> .
14
+ @prefix log: <http://www.w3.org/2000/10/swap/log#> .
15
+ @prefix math: <http://www.w3.org/2000/10/swap/math#> .
16
+ @prefix string: <http://www.w3.org/2000/10/swap/string#> .
17
+
18
+ # --------------
19
+ # Editable input
20
+ # --------------
21
+ :Input
22
+ :unitSystem "metric";
23
+ :weight 72.0;
24
+ :height 178.0.
25
+
26
+ # US alternative:
27
+ # :Input
28
+ # :unitSystem "us";
29
+ # :weight 158.73;
30
+ # :height 70.08.
31
+
32
+ # ---------------------------------
33
+ # Normalization and BMI calculation
34
+ # ---------------------------------
35
+ { :Input :unitSystem "metric"; :weight ?W; :height ?H.
36
+ (?H 100.0) math:quotient ?M. }
37
+ =>
38
+ { :Case :weightKg ?W; :heightM ?M.
39
+ :Reason :units "Inputs were already metric, so kilograms stay kilograms and centimeters are divided by 100 to obtain meters.". } .
40
+
41
+ { :Input :unitSystem "us"; :weight ?W; :height ?H.
42
+ (?W 0.45359237) math:product ?Kg.
43
+ (?H 0.0254) math:product ?M. }
44
+ =>
45
+ { :Case :weightKg ?Kg; :heightM ?M.
46
+ :Reason :units "US inputs were converted to SI units: pounds to kilograms and inches to meters.". } .
47
+
48
+ { :Case :weightKg ?Kg; :heightM ?M.
49
+ (?M ?M) math:product ?M2.
50
+ (?Kg ?M2) math:quotient ?Bmi.
51
+ (?Bmi 100.0) math:product ?BmiX100.
52
+ ?BmiX100 math:rounded ?BmiRoundedInt.
53
+ (?BmiRoundedInt 100.0) math:quotient ?BmiRounded.
54
+ (18.5 ?M2) math:product ?HealthyMin.
55
+ (24.9 ?M2) math:product ?HealthyMax.
56
+ (?HealthyMin 10.0) math:product ?MinX10.
57
+ (?HealthyMax 10.0) math:product ?MaxX10.
58
+ ?MinX10 math:rounded ?MinRoundedInt.
59
+ ?MaxX10 math:rounded ?MaxRoundedInt.
60
+ (?MinRoundedInt 10.0) math:quotient ?HealthyMinRounded.
61
+ (?MaxRoundedInt 10.0) math:quotient ?HealthyMaxRounded. }
62
+ =>
63
+ { :Case :heightSquared ?M2;
64
+ :bmi ?Bmi;
65
+ :bmiRounded ?BmiRounded;
66
+ :healthyMinKg ?HealthyMin;
67
+ :healthyMaxKg ?HealthyMax;
68
+ :healthyMinKgRounded ?HealthyMinRounded;
69
+ :healthyMaxKgRounded ?HealthyMaxRounded. } .
70
+
71
+ # ------------------------------------------
72
+ # WHO adult categories (half-open intervals)
73
+ # ------------------------------------------
74
+ { :Case :bmi ?Bmi. ?Bmi math:lessThan 18.5. }
75
+ => { :Decision :category "Underweight". } .
76
+
77
+ { :Case :bmi ?Bmi. ?Bmi math:notLessThan 18.5. ?Bmi math:lessThan 25.0. }
78
+ => { :Decision :category "Normal". } .
79
+
80
+ { :Case :bmi ?Bmi. ?Bmi math:notLessThan 25.0. ?Bmi math:lessThan 30.0. }
81
+ => { :Decision :category "Overweight". } .
82
+
83
+ { :Case :bmi ?Bmi. ?Bmi math:notLessThan 30.0. ?Bmi math:lessThan 35.0. }
84
+ => { :Decision :category "Obesity I". } .
85
+
86
+ { :Case :bmi ?Bmi. ?Bmi math:notLessThan 35.0. ?Bmi math:lessThan 40.0. }
87
+ => { :Decision :category "Obesity II". } .
88
+
89
+ { :Case :bmi ?Bmi. ?Bmi math:notLessThan 40.0. }
90
+ => { :Decision :category "Obesity III". } .
91
+
92
+ # ---------------------
93
+ # Answer and reason why
94
+ # ---------------------
95
+ { :Case :bmiRounded ?BmiRounded;
96
+ :healthyMinKgRounded ?HealthyMinRounded;
97
+ :healthyMaxKgRounded ?HealthyMaxRounded;
98
+ :heightM ?M.
99
+ :Decision :category ?Category.
100
+ (?M 100.0) math:product ?Cm.
101
+ ?Cm math:rounded ?CmRounded. }
102
+ =>
103
+ { :Answer :bmi ?BmiRounded;
104
+ :category ?Category;
105
+ :healthyMinKg ?HealthyMinRounded;
106
+ :healthyMaxKg ?HealthyMaxRounded;
107
+ :heightCm ?CmRounded. } .
108
+
109
+ { :Case :weightKg ?Kg; :heightM ?M; :heightSquared ?M2; :bmiRounded ?BmiRounded.
110
+ :Reason :units ?Units.
111
+ :Decision :category ?Category. }
112
+ =>
113
+ { :Reason :formula "BMI is defined as weight in kilograms divided by height in meters squared.";
114
+ :calculation "The normalized weight and height were used to compute BMI, then the result was mapped to the WHO adult category table.";
115
+ :categoryRule ?Category;
116
+ :unitsExplanation ?Units. } .
117
+
118
+ # -----
119
+ # Fuses
120
+ # -----
121
+ { :Decision :category ?C1, ?C2.
122
+ ?C1 log:notEqualTo ?C2. }
123
+ => false .
124
+
125
+ # ---------------------------------------------
126
+ # Report (built from actual derived values)
127
+ # ---------------------------------------------
128
+ { :Answer :bmi ?BmiRounded;
129
+ :category ?Category;
130
+ :healthyMinKg ?HealthyMinRounded;
131
+ :healthyMaxKg ?HealthyMaxRounded;
132
+ :heightCm ?CmRounded.
133
+ (
134
+ "=== Answer ===\n"
135
+ "BMI = " ?BmiRounded "\n"
136
+ "Category = " ?Category "\n"
137
+ "At height " ?CmRounded " cm, a healthy-weight range is about " ?HealthyMinRounded "–" ?HealthyMaxRounded " kg (BMI 18.5–24.9).\n\n"
138
+ "=== Explanation ===\n"
139
+ "BMI is defined as weight in kilograms divided by height in meters squared. "
140
+ "This program first normalizes the input to SI units, computes BMI, and then applies WHO adult categories as half-open intervals. "
141
+ "The healthy-weight band is the weight range at the same height that corresponds to BMI 18.5 through 24.9.\n\n"
142
+ ) string:concatenation ?Block. }
143
+ =>
144
+ { :report log:outputString ?Block. } .
145
+
@@ -0,0 +1,68 @@
1
+ # Builtin coverage smoke
2
+ # Exercises math, string, list, crypto, time, and log builtins in compiled JavaScript.
3
+
4
+ @prefix : <urn:example#>.
5
+
6
+ {
7
+ (2 3 4) math:sum ?sum.
8
+ (2 3 4) math:product ?product.
9
+ (9 4) math:difference ?difference.
10
+ (9 3) math:quotient ?quotient.
11
+ (9 4) math:integerQuotient ?iq.
12
+ (9 4) math:remainder ?rem.
13
+ 3 math:negation ?neg.
14
+ -3 math:absoluteValue ?abs.
15
+ 3.141592653589793 math:degrees ?deg.
16
+ "abc" string:length ?len.
17
+ ("a" "b" "c") string:concatenation ?cat.
18
+ ("item %s %d" "x" 7) string:format ?fmt.
19
+ "abcdef" string:contains "cd".
20
+ "Hello" string:containsIgnoringCase "he".
21
+ ("abcdef" "cd(ef)") string:scrape ?scrape.
22
+ ("abc" 1) string:charAt ?char.
23
+ ("abc" 1 "Z") string:setCharAt ?set.
24
+ "hello" crypto:sha256 ?sha.
25
+ ("a" "b" "c") list:first ?first.
26
+ ("a" "b" "c") list:rest ?rest.
27
+ ("a" "b" "c") list:last ?last.
28
+ ("a" "b" "c") list:length ?listLen.
29
+ ("a" "b" "c") list:reverse ?rev.
30
+ (("a" "b" "a") "a") list:remove ?removed.
31
+ (("a") ("b" "c")) list:append ?appended.
32
+ "b" list:in ("a" "b" "c").
33
+ ("a" "b" "c") list:member ?member.
34
+ "2024-01-02T03:04:05Z" time:year ?year.
35
+ "2024-01-02T03:04:05Z" time:month ?month.
36
+ ( { :x :p :y } { :a :b :c } ) log:conjunction ?formula.
37
+ }
38
+ => {
39
+ :assurance :sum ?sum;
40
+ :product ?product;
41
+ :difference ?difference;
42
+ :quotient ?quotient;
43
+ :integerQuotient ?iq;
44
+ :remainder ?rem;
45
+ :negation ?neg;
46
+ :absoluteValue ?abs;
47
+ :degrees ?deg;
48
+ :stringLength ?len;
49
+ :concatenation ?cat;
50
+ :format ?fmt;
51
+ :scrape ?scrape;
52
+ :charAt ?char;
53
+ :setCharAt ?set;
54
+ :sha256 ?sha;
55
+ :first ?first;
56
+ :rest ?rest;
57
+ :last ?last;
58
+ :listLength ?listLen;
59
+ :reverse ?rev;
60
+ :removed ?removed;
61
+ :appended ?appended;
62
+ :member ?member;
63
+ :year ?year;
64
+ :month ?month;
65
+ :formula ?formula.
66
+ }.
67
+
68
+ { :assurance ?p ?o } log:query { :assurance ?p ?o }.
@@ -0,0 +1,3 @@
1
+ @prefix : <https://eyereasoner.github.io/see/examples/collection#>.
2
+ (1 _:b2 (2)) :p2 :q2 .
3
+ _:b2 :p :q .
@@ -0,0 +1,140 @@
1
+ # ================================================
2
+ # Complex numbers
3
+ # See https://en.wikipedia.org/wiki/Complex_number
4
+ # ================================================
5
+ @prefix math: <http://www.w3.org/2000/10/swap/math#>.
6
+ @prefix log: <http://www.w3.org/2000/10/swap/log#>.
7
+ @prefix complex: <https://eyereasoner.github.io/eye/complex#>.
8
+ @prefix : <http://example.org/#>.
9
+
10
+ {
11
+ ((?A ?B) (?C ?D)) complex:exponentiation (?E ?F).
12
+ } <= {
13
+ (?A ?B) complex:polar (?R ?T).
14
+ (?R ?C) math:exponentiation ?Z1.
15
+ ?D math:negation ?Z2.
16
+ (?Z2 ?T) math:product ?Z3.
17
+ (2.718281828459045 ?Z3) math:exponentiation ?Z4.
18
+ (2.718281828459045 ?Z5) math:exponentiation ?R.
19
+ (?D ?Z5) math:product ?Z6.
20
+ (?C ?T) math:product ?Z7.
21
+ (?Z6 ?Z7) math:sum ?Z8.
22
+ ?Z8 math:cos ?Z9.
23
+ (?Z1 ?Z4 ?Z9) math:product ?E.
24
+ ?Z8 math:sin ?Z10.
25
+ (?Z1 ?Z4 ?Z10) math:product ?F.
26
+ }.
27
+
28
+ {
29
+ (?A ?B) complex:asin (?C ?D).
30
+ } <= {
31
+ (1 ?A) math:sum ?Z1.
32
+ (?Z1 2) math:exponentiation ?Z2.
33
+ (?B 2) math:exponentiation ?Z3.
34
+ (?Z2 ?Z3) math:sum ?Z4.
35
+ (?Z4 0.5) math:exponentiation ?Z5.
36
+ (1 ?A) math:difference ?Z6.
37
+ (?Z6 2) math:exponentiation ?Z7.
38
+ (?Z7 ?Z3) math:sum ?Z8.
39
+ (?Z8 0.5) math:exponentiation ?Z9.
40
+ (?Z5 ?Z9) math:difference ?Z10.
41
+ (?Z10 2) math:quotient ?E.
42
+ (?Z5 ?Z9) math:sum ?Z11.
43
+ (?Z11 2) math:quotient ?F.
44
+ ?E math:asin ?C.
45
+ (?F 2) math:exponentiation ?Z12.
46
+ (?Z12 1) math:difference ?Z13.
47
+ (?Z13 0.5) math:exponentiation ?Z14.
48
+ (?F ?Z14) math:sum ?Z15.
49
+ (2.718281828459045 ?D) math:exponentiation ?Z15.
50
+ }.
51
+
52
+ {
53
+ (?A ?B) complex:acos (?C ?D).
54
+ } <= {
55
+ (1 ?A) math:sum ?Z1.
56
+ (?Z1 2) math:exponentiation ?Z2.
57
+ (?B 2) math:exponentiation ?Z3.
58
+ (?Z2 ?Z3) math:sum ?Z4.
59
+ (?Z4 0.5) math:exponentiation ?Z5.
60
+ (1 ?A) math:difference ?Z6.
61
+ (?Z6 2) math:exponentiation ?Z7.
62
+ (?Z7 ?Z3) math:sum ?Z8.
63
+ (?Z8 0.5) math:exponentiation ?Z9.
64
+ (?Z5 ?Z9) math:difference ?Z10.
65
+ (?Z10 2) math:quotient ?E.
66
+ (?Z5 ?Z9) math:sum ?Z11.
67
+ (?Z11 2) math:quotient ?F.
68
+ ?E math:acos ?C.
69
+ (?F 2) math:exponentiation ?Z12.
70
+ (?Z12 1) math:difference ?Z13.
71
+ (?Z13 0.5) math:exponentiation ?Z14.
72
+ (?F ?Z14) math:sum ?Z15.
73
+ (2.718281828459045 ?U) math:exponentiation ?Z15.
74
+ ?U math:negation ?D.
75
+ }.
76
+
77
+ {
78
+ (?X ?Y) complex:polar(?R ?Tp).
79
+ } <= {
80
+ (?X 2) math:exponentiation ?Z1.
81
+ (?Y 2) math:exponentiation ?Z2.
82
+ (?Z1 ?Z2) math:sum ?Z3.
83
+ (?Z3 0.5) math:exponentiation ?R.
84
+ ?X math:absoluteValue ?Z4.
85
+ (?Z4 ?R) math:quotient ?Z5.
86
+ ?Z5 math:acos ?T.
87
+ (?X ?Y ?T) complex:dial ?Tp.
88
+ }.
89
+
90
+ {
91
+ (?X ?Y ?T) complex:dial ?Tp.
92
+ } <= {
93
+ ?X math:notLessThan 0.
94
+ ?Y math:notLessThan 0.
95
+ (0 ?T) math:sum ?Tp.
96
+ }.
97
+
98
+ {
99
+ (?X ?Y ?T) complex:dial ?Tp.
100
+ } <= {
101
+ ?X math:lessThan 0.
102
+ ?Y math:notLessThan 0.
103
+ (3.141592653589793 ?T) math:difference ?Tp.
104
+ }.
105
+
106
+ {
107
+ (?X ?Y ?T) complex:dial ?Tp.
108
+ } <= {
109
+ ?X math:lessThan 0.
110
+ ?Y math:lessThan 0.
111
+ (3.141592653589793 ?T) math:sum ?Tp.
112
+ }.
113
+
114
+ {
115
+ (?X ?Y ?T) complex:dial ?Tp.
116
+ } <= {
117
+ ?X math:notLessThan 0.
118
+ ?Y math:lessThan 0.
119
+ (3.141592653589793 2) math:product ?Z1.
120
+ (?Z1 ?T) math:difference ?Tp.
121
+ }.
122
+
123
+ # test
124
+ {
125
+ ((-1 0) (0.5 0)) complex:exponentiation ?C1.
126
+ ((2.718281828459045 0) (0 3.141592653589793)) complex:exponentiation ?C2.
127
+ ((0 1) (0 1)) complex:exponentiation ?C3.
128
+ ((2.718281828459045 0) (-1.57079632679 0)) complex:exponentiation ?C4.
129
+ (2 0) complex:asin ?C5.
130
+ (2 0) complex:acos ?C6.
131
+ } => {
132
+ :test :is {
133
+ ((-1 0) (0.5 0)) complex:exponentiation ?C1.
134
+ ((2.718281828459045 0) (0 3.141592653589793)) complex:exponentiation ?C2.
135
+ ((0 1) (0 1)) complex:exponentiation ?C3.
136
+ ((2.718281828459045 0) (-1.57079632679 0)) complex:exponentiation ?C4.
137
+ (2 0) complex:asin ?C5.
138
+ (2 0) complex:acos ?C6.
139
+ }.
140
+ }.
@@ -0,0 +1,113 @@
1
+ # ==========================================================================
2
+ # Complex Matrix Stability
3
+ # ==========================================================================
4
+ # Diagonal 2x2 complex matrices are classified for discrete-time stability.
5
+ # This adapts the Eyeling complex matrix example as a committed SEE N3
6
+ # source that compiles to a standalone JavaScript example.
7
+
8
+ @prefix : <https://eyereasoner.github.io/see/examples/complex-matrix-stability#>.
9
+ @prefix log: <http://www.w3.org/2000/10/swap/log#>.
10
+ @prefix math: <http://www.w3.org/2000/10/swap/math#>.
11
+ @prefix string: <http://www.w3.org/2000/10/swap/string#>.
12
+
13
+ :Case :unstableMatrix :A_unstable;
14
+ :stableMatrix :A_stable;
15
+ :dampedMatrix :A_damped.
16
+
17
+ :Scale2 :k 2.
18
+
19
+ :c_0_0 :re 0; :im 0; :pretty "(0,0)".
20
+ :c_0_1 :re 0; :im 1; :pretty "(0,1)".
21
+ :c_1_0 :re 1; :im 0; :pretty "(1,0)".
22
+ :c_m1_0 :re -1; :im 0; :pretty "(-1,0)".
23
+ :c_1_1 :re 1; :im 1; :pretty "(1,1)".
24
+ :c_1_2 :re 1; :im 2; :pretty "(1,2)".
25
+ :c_2_0 :re 2; :im 0; :pretty "(2,0)".
26
+
27
+ :A_unstable
28
+ :a11 :c_1_1; :a12 :c_0_0; :a21 :c_0_0; :a22 :c_2_0;
29
+ :pretty "[[(1,1),(0,0)],[(0,0),(2,0)]]".
30
+ :A_stable
31
+ :a11 :c_1_0; :a12 :c_0_0; :a21 :c_0_0; :a22 :c_m1_0;
32
+ :pretty "[[(1,0),(0,0)],[(0,0),(-1,0)]]".
33
+ :A_damped
34
+ :a11 :c_0_0; :a12 :c_0_0; :a21 :c_0_0; :a22 :c_0_0;
35
+ :pretty "[[(0,0),(0,0)],[(0,0),(0,0)]]".
36
+
37
+ { ?Z :abs2 ?A2 } <= {
38
+ ?Z :re ?R; :im ?I.
39
+ (?R ?R) math:product ?R2.
40
+ (?I ?I) math:product ?I2.
41
+ (?R2 ?I2) math:sum ?A2.
42
+ }.
43
+
44
+ { ?Z :isZero true } <= { ?Z :re 0; :im 0. }.
45
+
46
+ { ?M :eigenvalue1 ?L1 } <= {
47
+ ?M :a11 ?L1; :a12 ?Z1; :a21 ?Z2; :a22 ?L2.
48
+ ?Z1 :isZero true.
49
+ ?Z2 :isZero true.
50
+ }.
51
+ { ?M :eigenvalue2 ?L2 } <= {
52
+ ?M :a11 ?L1; :a12 ?Z1; :a21 ?Z2; :a22 ?L2.
53
+ ?Z1 :isZero true.
54
+ ?Z2 :isZero true.
55
+ }.
56
+
57
+ { ?M :spectralRadiusSq ?A1 } <= {
58
+ ?M :eigenvalue1 ?L1; :eigenvalue2 ?L2.
59
+ ?L1 :abs2 ?A1.
60
+ ?L2 :abs2 ?A2.
61
+ ?A1 math:notLessThan ?A2.
62
+ }.
63
+ { ?M :spectralRadiusSq ?A2 } <= {
64
+ ?M :eigenvalue1 ?L1; :eigenvalue2 ?L2.
65
+ ?L1 :abs2 ?A1.
66
+ ?L2 :abs2 ?A2.
67
+ ?A2 math:greaterThan ?A1.
68
+ }.
69
+
70
+ { ?M :spectralRadius 2 } <= { ?M :spectralRadiusSq 4. }.
71
+ { ?M :spectralRadius 1 } <= { ?M :spectralRadiusSq 1. }.
72
+ { ?M :spectralRadius 0 } <= { ?M :spectralRadiusSq 0. }.
73
+
74
+ { ?M :classification :unstable } <= { ?M :spectralRadiusSq ?R2. ?R2 math:greaterThan 1. }.
75
+ { ?M :classification :stable } <= { ?M :spectralRadiusSq 1. }.
76
+ { ?M :classification :damped } <= { ?M :spectralRadiusSq ?R2. ?R2 math:lessThan 1. }.
77
+
78
+ { :sampleProduct :re ?Cr } <= {
79
+ :c_1_2 :re ?Ar; :im ?Ai.
80
+ :c_0_1 :re ?Br; :im ?Bi.
81
+ (?Ar ?Br) math:product ?P1.
82
+ (?Ai ?Bi) math:product ?P2.
83
+ (?P1 ?P2) math:difference ?Cr.
84
+ }.
85
+ { :sampleProduct :im ?Ci } <= {
86
+ :c_1_2 :re ?Ar; :im ?Ai.
87
+ :c_0_1 :re ?Br; :im ?Bi.
88
+ (?Ar ?Bi) math:product ?P3.
89
+ (?Ai ?Br) math:product ?P4.
90
+ (?P3 ?P4) math:sum ?Ci.
91
+ }.
92
+
93
+ { :A_unstable :scaledRadiusSq ?S2 } <= {
94
+ :Scale2 :k ?K.
95
+ (?K ?K) math:product ?K2.
96
+ (?K2 4) math:product ?S2.
97
+ }.
98
+
99
+ {
100
+ :Case :unstableMatrix ?Mu; :stableMatrix ?Ms; :dampedMatrix ?Md.
101
+ ?Mu :classification :unstable; :spectralRadius 2.
102
+ ?Ms :classification :stable; :spectralRadius 1.
103
+ ?Md :classification :damped; :spectralRadius 0.
104
+ } => { :Case :scenarioOk true. }.
105
+
106
+
107
+ {
108
+ :Case :scenarioOk true.
109
+ :A_unstable :pretty ?UnstableMatrix; :spectralRadius ?Ru.
110
+ :A_stable :pretty ?StableMatrix; :spectralRadius ?Rs.
111
+ :A_damped :pretty ?DampedMatrix; :spectralRadius ?Rd.
112
+ ("=== Answer ===\nA_unstable = %s has spectral radius %s and is unstable. A_stable = %s has spectral radius %s and is marginally stable. A_damped = %s has spectral radius %s and is damped.\n\n=== Explanation ===\nFor a discrete-time linear system x_{k+1} = A x_k, diagonal matrix eigenvalues are the diagonal entries. The largest squared complex modulus determines the spectral radius class. The N3 derivation also validates that |z*w|^2 = |z|^2*|w|^2 for a concrete complex product and that scaling A_unstable by 2 multiplies the squared spectral radius by 4." ?UnstableMatrix ?Ru ?StableMatrix ?Rs ?DampedMatrix ?Rd) string:format ?Block.
113
+ } => { :report log:outputString ?Block. }.
@@ -0,0 +1,27 @@
1
+ # Composition of injective functions is injective.
2
+ @prefix : <https://eyereasoner.github.io/eye/reasoning#>.
3
+ @prefix log: <http://www.w3.org/2000/10/swap/log#>.
4
+
5
+ { ?x :inX true. } => { (?x ?x) :sameTerm true. }.
6
+ { ?y :inY true. } => { (?y ?y) :sameTerm true. }.
7
+ { ?z :inZ true. } => { (?z ?z) :sameTerm true. }.
8
+ { (?a ?b) :sameTerm true. } => { (?b ?a) :sameTerm true. }.
9
+ { (?f ?x) :app ?u. (?f ?x) :app ?v. } => { (?u ?v) :sameTerm true. }.
10
+ { ?f :injective true. (?f ?x) :app ?u. (?f ?y) :app ?v. (?u ?v) :sameTerm true. } => { (?x ?y) :sameTerm true. }.
11
+ { ?h :compositeOf (?g ?f). (?f ?x) :app ?y. (?g ?y) :app ?z. } => { (?h ?x) :app ?z. }.
12
+ { ?h :compositeOf (?g ?f). ?f :injective true. ?g :injective true. (?f ?x) :app ?fx. (?f ?y) :app ?fy. (?g ?fx) :app ?u. (?g ?fy) :app ?v. (?u ?v) :sameTerm true. (?x ?y) :sameTerm true. } => { (?h ?x ?y) :sameInputUnderEqualCompositeOutput true. }.
13
+
14
+ :a :inX true.
15
+ :b :inX true.
16
+ :p :inY true.
17
+ :q :inY true.
18
+ :r :inZ true.
19
+ :f :injective true.
20
+ :g :injective true.
21
+ :h :compositeOf (:g :f).
22
+ (:f :a) :app :p.
23
+ (:f :b) :app :q.
24
+ (:g :p) :app :r.
25
+ (:g :q) :app :r.
26
+
27
+ { (?h ?x ?y) :sameInputUnderEqualCompositeOutput true. ?x log:notEqualTo ?y. } log:query { :result :sameInputByCompositeInjectivity (?h ?x ?y). }.