eyeling 1.5.40 → 1.5.42
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.
- package/examples/cranberry-calculus.n3 +167 -0
- package/examples/output/cranberry-calculus.n3 +1334 -0
- package/examples/output/saffron-slopeworks.n3 +1470 -0
- package/examples/saffron-slopeworks.n3 +216 -0
- package/eyeling.js +64 -16
- package/package.json +2 -2
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# ================================================================
|
|
2
|
+
# Heavy-Math N3 Demo: "Cranberry Calculus"
|
|
3
|
+
# ------------------------------------------------
|
|
4
|
+
# A showcase ruleset for N3 reasoners implementing the W3C/N3 math
|
|
5
|
+
# builtins strictly.
|
|
6
|
+
#
|
|
7
|
+
# What it does:
|
|
8
|
+
# 1) Statistics on a dataset: mean, variance, stddev + z-score outliers
|
|
9
|
+
# 2) Vector math: dot product, norms, angle between vectors (rad/deg)
|
|
10
|
+
# 3) Projectile motion: vx/vy, flight time, range, max height, sample pos
|
|
11
|
+
#
|
|
12
|
+
# Notes:
|
|
13
|
+
# - Uses only standard builtins: math:, list:, log:
|
|
14
|
+
# - Intended as a regression test for datatype strictness in math builtins.
|
|
15
|
+
# ================================================================
|
|
16
|
+
|
|
17
|
+
@prefix : <http://example.org/cranberry-calculus#> .
|
|
18
|
+
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
|
|
19
|
+
@prefix list: <http://www.w3.org/2000/10/swap/list#> .
|
|
20
|
+
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
|
|
21
|
+
|
|
22
|
+
############
|
|
23
|
+
# DATA
|
|
24
|
+
############
|
|
25
|
+
|
|
26
|
+
:DataSet1 :values (1.2 1.3 1.4 1.25 1.35 2.0 10.0) ;
|
|
27
|
+
:zThreshold 2.0 .
|
|
28
|
+
|
|
29
|
+
:VecA :x 3.0 ; :y 4.0 .
|
|
30
|
+
:VecB :x 4.0 ; :y 0.0 .
|
|
31
|
+
|
|
32
|
+
:Shot1 :speed 30.0 ;
|
|
33
|
+
:angleRad 0.7853981633974483 ; # 45° in radians
|
|
34
|
+
:g 9.81 ;
|
|
35
|
+
:tSample 2.5 .
|
|
36
|
+
|
|
37
|
+
############
|
|
38
|
+
# (1) STATS: mean, variance, stddev
|
|
39
|
+
############
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
:DataSet1 :values ?xs ; :zThreshold ?thr .
|
|
43
|
+
|
|
44
|
+
?xs list:length ?n .
|
|
45
|
+
?xs math:sum ?sum .
|
|
46
|
+
(?sum ?n) math:quotient ?mean .
|
|
47
|
+
|
|
48
|
+
# Collect squared deviations: (x - mean)^2 for each x in the list
|
|
49
|
+
( ?sq
|
|
50
|
+
{
|
|
51
|
+
?xs list:member ?x .
|
|
52
|
+
(?x ?mean) math:difference ?d .
|
|
53
|
+
(?d 2.0) math:exponentiation ?sq .
|
|
54
|
+
}
|
|
55
|
+
?sqList
|
|
56
|
+
) log:collectAllIn _:statsScope .
|
|
57
|
+
|
|
58
|
+
?sqList math:sum ?sse .
|
|
59
|
+
(?sse ?n) math:quotient ?var .
|
|
60
|
+
(?var 0.5) math:exponentiation ?std . # sqrt(var)
|
|
61
|
+
}
|
|
62
|
+
=>
|
|
63
|
+
{
|
|
64
|
+
:DataSet1 :mean ?mean ;
|
|
65
|
+
:variance ?var ;
|
|
66
|
+
:stddev ?std .
|
|
67
|
+
} .
|
|
68
|
+
|
|
69
|
+
# Outliers: |z| > threshold, where z = (x - mean) / stddev
|
|
70
|
+
{
|
|
71
|
+
:DataSet1 :values ?xs ; :mean ?mean ; :stddev ?std ; :zThreshold ?thr .
|
|
72
|
+
?xs list:member ?x .
|
|
73
|
+
|
|
74
|
+
(?x ?mean) math:difference ?d .
|
|
75
|
+
(?d ?std) math:quotient ?z .
|
|
76
|
+
?z math:absoluteValue ?absz .
|
|
77
|
+
?absz math:greaterThan ?thr .
|
|
78
|
+
}
|
|
79
|
+
=>
|
|
80
|
+
{
|
|
81
|
+
:DataSet1 :outlier [ :value ?x ; :zScore ?z ] .
|
|
82
|
+
} .
|
|
83
|
+
|
|
84
|
+
############
|
|
85
|
+
# (2) VECTORS: dot product, norms, angle between vectors
|
|
86
|
+
############
|
|
87
|
+
|
|
88
|
+
{
|
|
89
|
+
:VecA :x ?ax ; :y ?ay .
|
|
90
|
+
:VecB :x ?bx ; :y ?by .
|
|
91
|
+
|
|
92
|
+
# dot = ax*bx + ay*by
|
|
93
|
+
(?ax ?bx) math:product ?axbx .
|
|
94
|
+
(?ay ?by) math:product ?ayby .
|
|
95
|
+
(?axbx ?ayby) math:sum ?dot .
|
|
96
|
+
|
|
97
|
+
# |a| = sqrt(ax^2 + ay^2)
|
|
98
|
+
(?ax 2.0) math:exponentiation ?ax2 .
|
|
99
|
+
(?ay 2.0) math:exponentiation ?ay2 .
|
|
100
|
+
(?ax2 ?ay2) math:sum ?a2 .
|
|
101
|
+
(?a2 0.5) math:exponentiation ?aNorm .
|
|
102
|
+
|
|
103
|
+
# |b| = sqrt(bx^2 + by^2)
|
|
104
|
+
(?bx 2.0) math:exponentiation ?bx2 .
|
|
105
|
+
(?by 2.0) math:exponentiation ?by2 .
|
|
106
|
+
(?bx2 ?by2) math:sum ?b2 .
|
|
107
|
+
(?b2 0.5) math:exponentiation ?bNorm .
|
|
108
|
+
|
|
109
|
+
# cos(theta) = dot / (|a||b|)
|
|
110
|
+
(?aNorm ?bNorm) math:product ?den .
|
|
111
|
+
(?dot ?den) math:quotient ?cosTheta .
|
|
112
|
+
|
|
113
|
+
?cosTheta math:acos ?thetaRad .
|
|
114
|
+
?thetaRad math:degrees ?thetaDeg .
|
|
115
|
+
}
|
|
116
|
+
=>
|
|
117
|
+
{
|
|
118
|
+
:VecA :dotWithVecB ?dot ;
|
|
119
|
+
:angleToVecB [ :radians ?thetaRad ; :degrees ?thetaDeg ] .
|
|
120
|
+
} .
|
|
121
|
+
|
|
122
|
+
############
|
|
123
|
+
# (3) PROJECTILE (no air resistance)
|
|
124
|
+
############
|
|
125
|
+
|
|
126
|
+
{
|
|
127
|
+
:Shot1 :speed ?v ; :angleRad ?theta ; :g ?g ; :tSample ?t .
|
|
128
|
+
|
|
129
|
+
?theta math:sin ?sinT .
|
|
130
|
+
?theta math:cos ?cosT .
|
|
131
|
+
|
|
132
|
+
(?v ?cosT) math:product ?vx .
|
|
133
|
+
(?v ?sinT) math:product ?vy .
|
|
134
|
+
|
|
135
|
+
(2.0 ?vy) math:product ?twoVy .
|
|
136
|
+
(?twoVy ?g) math:quotient ?tFlight .
|
|
137
|
+
|
|
138
|
+
(?vx ?tFlight) math:product ?range .
|
|
139
|
+
|
|
140
|
+
(?vy 2.0) math:exponentiation ?vy2 .
|
|
141
|
+
(2.0 ?g) math:product ?twoG .
|
|
142
|
+
(?vy2 ?twoG) math:quotient ?hMax .
|
|
143
|
+
|
|
144
|
+
(?vx ?t) math:product ?xAtT .
|
|
145
|
+
(?vy ?t) math:product ?vy_t .
|
|
146
|
+
(?t 2.0) math:exponentiation ?t2 .
|
|
147
|
+
(?g ?t2) math:product ?g_t2 .
|
|
148
|
+
(0.5 ?g_t2) math:product ?half_g_t2 .
|
|
149
|
+
(?vy_t ?half_g_t2) math:difference ?yAtT .
|
|
150
|
+
}
|
|
151
|
+
=>
|
|
152
|
+
{
|
|
153
|
+
:Shot1 :vx ?vx ;
|
|
154
|
+
:vy ?vy ;
|
|
155
|
+
:timeOfFlight ?tFlight ;
|
|
156
|
+
:range ?range ;
|
|
157
|
+
:maxHeight ?hMax ;
|
|
158
|
+
:positionAtSample [ :t ?t ; :x ?xAtT ; :y ?yAtT ] .
|
|
159
|
+
} .
|
|
160
|
+
|
|
161
|
+
############
|
|
162
|
+
# STRICTNESS REGRESSION HOOK (should fail in a strict implementation)
|
|
163
|
+
############
|
|
164
|
+
# {
|
|
165
|
+
# "-1"^^<http://example.org/gooblygook> math:absoluteValue "1"^^<http://example.org/foobar> .
|
|
166
|
+
# } => { :bad :datatype :accepted . } .
|
|
167
|
+
|