eyeling 1.19.3 → 1.19.4

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/eyeling.js CHANGED
@@ -2576,6 +2576,24 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen, maxResults) {
2576
2576
 
2577
2577
  // math:absoluteValue
2578
2578
  if (pv === MATH_NS + 'absoluteValue') {
2579
+ const ai = parseIntLiteral(g.s);
2580
+ if (ai !== null) {
2581
+ const outVal = ai < 0n ? -ai : ai;
2582
+ const lit = makeNumericOutputLiteral(outVal, XSD_INTEGER_DT);
2583
+
2584
+ if (g.o instanceof Var) {
2585
+ const s2 = { ...subst };
2586
+ s2[g.o.name] = lit;
2587
+ return [s2];
2588
+ }
2589
+ if (g.o instanceof Blank) return [{ ...subst }];
2590
+
2591
+ const oi = parseIntLiteral(g.o);
2592
+ if (oi !== null && oi === outVal) return [{ ...subst }];
2593
+ if (numEqualTerm(g.o, Number(outVal))) return [{ ...subst }];
2594
+ return [];
2595
+ }
2596
+
2579
2597
  const a = parseNum(g.s);
2580
2598
  if (a === null) return [];
2581
2599
 
@@ -2648,6 +2666,38 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen, maxResults) {
2648
2666
 
2649
2667
  // math:negation (inverse is itself)
2650
2668
  if (pv === MATH_NS + 'negation') {
2669
+ const si = parseIntLiteral(g.s);
2670
+ if (si !== null) {
2671
+ const outVal = -si;
2672
+ const lit = makeNumericOutputLiteral(outVal, XSD_INTEGER_DT);
2673
+ if (g.o instanceof Var) {
2674
+ const s2 = { ...subst };
2675
+ s2[g.o.name] = lit;
2676
+ return [s2];
2677
+ }
2678
+ if (g.o instanceof Blank) return [{ ...subst }];
2679
+ const oi = parseIntLiteral(g.o);
2680
+ if (oi !== null && oi === outVal) return [{ ...subst }];
2681
+ if (numEqualTerm(g.o, Number(outVal))) return [{ ...subst }];
2682
+ return [];
2683
+ }
2684
+
2685
+ const oi = parseIntLiteral(g.o);
2686
+ if (oi !== null) {
2687
+ const inVal = -oi;
2688
+ const lit = makeNumericOutputLiteral(inVal, XSD_INTEGER_DT);
2689
+ if (g.s instanceof Var) {
2690
+ const s2 = { ...subst };
2691
+ s2[g.s.name] = lit;
2692
+ return [s2];
2693
+ }
2694
+ if (g.s instanceof Blank) return [{ ...subst }];
2695
+ const si2 = parseIntLiteral(g.s);
2696
+ if (si2 !== null && si2 === inVal) return [{ ...subst }];
2697
+ if (numEqualTerm(g.s, Number(inVal))) return [{ ...subst }];
2698
+ return [];
2699
+ }
2700
+
2651
2701
  const neg = (x) => -x;
2652
2702
  return evalUnaryMathRel(g, subst, neg, neg);
2653
2703
  }
@@ -2706,6 +2756,25 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen, maxResults) {
2706
2756
  // Schema: $s+ math:rounded $o-
2707
2757
  // Note: spec says $o is xsd:integer, but we also accept any numeric $o that equals the rounded value.
2708
2758
  if (pv === MATH_NS + 'rounded') {
2759
+ const ai = parseIntLiteral(g.s);
2760
+ if (ai !== null) {
2761
+ const lit = makeNumericOutputLiteral(ai, XSD_INTEGER_DT);
2762
+
2763
+ if (g.o instanceof Var) {
2764
+ const s2 = { ...subst };
2765
+ s2[g.o.name] = lit;
2766
+ return [s2];
2767
+ }
2768
+ if (g.o instanceof Blank) return [{ ...subst }];
2769
+
2770
+ const oi = parseIntLiteral(g.o);
2771
+ if (oi !== null && oi === ai) return [{ ...subst }];
2772
+ if (numEqualTerm(g.o, Number(ai))) return [{ ...subst }];
2773
+
2774
+ const s2 = unifyTerm(g.o, lit, subst);
2775
+ return s2 !== null ? [s2] : [];
2776
+ }
2777
+
2709
2778
  const a = parseNum(g.s);
2710
2779
  if (a === null) return [];
2711
2780
  if (Number.isNaN(a)) return [];
package/lib/builtins.js CHANGED
@@ -2096,6 +2096,24 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen, maxResults) {
2096
2096
 
2097
2097
  // math:absoluteValue
2098
2098
  if (pv === MATH_NS + 'absoluteValue') {
2099
+ const ai = parseIntLiteral(g.s);
2100
+ if (ai !== null) {
2101
+ const outVal = ai < 0n ? -ai : ai;
2102
+ const lit = makeNumericOutputLiteral(outVal, XSD_INTEGER_DT);
2103
+
2104
+ if (g.o instanceof Var) {
2105
+ const s2 = { ...subst };
2106
+ s2[g.o.name] = lit;
2107
+ return [s2];
2108
+ }
2109
+ if (g.o instanceof Blank) return [{ ...subst }];
2110
+
2111
+ const oi = parseIntLiteral(g.o);
2112
+ if (oi !== null && oi === outVal) return [{ ...subst }];
2113
+ if (numEqualTerm(g.o, Number(outVal))) return [{ ...subst }];
2114
+ return [];
2115
+ }
2116
+
2099
2117
  const a = parseNum(g.s);
2100
2118
  if (a === null) return [];
2101
2119
 
@@ -2168,6 +2186,38 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen, maxResults) {
2168
2186
 
2169
2187
  // math:negation (inverse is itself)
2170
2188
  if (pv === MATH_NS + 'negation') {
2189
+ const si = parseIntLiteral(g.s);
2190
+ if (si !== null) {
2191
+ const outVal = -si;
2192
+ const lit = makeNumericOutputLiteral(outVal, XSD_INTEGER_DT);
2193
+ if (g.o instanceof Var) {
2194
+ const s2 = { ...subst };
2195
+ s2[g.o.name] = lit;
2196
+ return [s2];
2197
+ }
2198
+ if (g.o instanceof Blank) return [{ ...subst }];
2199
+ const oi = parseIntLiteral(g.o);
2200
+ if (oi !== null && oi === outVal) return [{ ...subst }];
2201
+ if (numEqualTerm(g.o, Number(outVal))) return [{ ...subst }];
2202
+ return [];
2203
+ }
2204
+
2205
+ const oi = parseIntLiteral(g.o);
2206
+ if (oi !== null) {
2207
+ const inVal = -oi;
2208
+ const lit = makeNumericOutputLiteral(inVal, XSD_INTEGER_DT);
2209
+ if (g.s instanceof Var) {
2210
+ const s2 = { ...subst };
2211
+ s2[g.s.name] = lit;
2212
+ return [s2];
2213
+ }
2214
+ if (g.s instanceof Blank) return [{ ...subst }];
2215
+ const si2 = parseIntLiteral(g.s);
2216
+ if (si2 !== null && si2 === inVal) return [{ ...subst }];
2217
+ if (numEqualTerm(g.s, Number(inVal))) return [{ ...subst }];
2218
+ return [];
2219
+ }
2220
+
2171
2221
  const neg = (x) => -x;
2172
2222
  return evalUnaryMathRel(g, subst, neg, neg);
2173
2223
  }
@@ -2226,6 +2276,25 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen, maxResults) {
2226
2276
  // Schema: $s+ math:rounded $o-
2227
2277
  // Note: spec says $o is xsd:integer, but we also accept any numeric $o that equals the rounded value.
2228
2278
  if (pv === MATH_NS + 'rounded') {
2279
+ const ai = parseIntLiteral(g.s);
2280
+ if (ai !== null) {
2281
+ const lit = makeNumericOutputLiteral(ai, XSD_INTEGER_DT);
2282
+
2283
+ if (g.o instanceof Var) {
2284
+ const s2 = { ...subst };
2285
+ s2[g.o.name] = lit;
2286
+ return [s2];
2287
+ }
2288
+ if (g.o instanceof Blank) return [{ ...subst }];
2289
+
2290
+ const oi = parseIntLiteral(g.o);
2291
+ if (oi !== null && oi === ai) return [{ ...subst }];
2292
+ if (numEqualTerm(g.o, Number(ai))) return [{ ...subst }];
2293
+
2294
+ const s2 = unifyTerm(g.o, lit, subst);
2295
+ return s2 !== null ? [s2] : [];
2296
+ }
2297
+
2229
2298
  const a = parseNum(g.s);
2230
2299
  if (a === null) return [];
2231
2300
  if (Number.isNaN(a)) return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.19.3",
3
+ "version": "1.19.4",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
5
  "main": "./index.js",
6
6
  "keywords": [
package/test/api.test.js CHANGED
@@ -1498,6 +1498,33 @@ _:x :hates { _:foo :making :mess }.
1498
1498
  ],
1499
1499
  },
1500
1500
 
1501
+ {
1502
+ name: '59c regression: integer-safe math absoluteValue, negation, and rounded preserve large integers',
1503
+ opt: { proofComments: false },
1504
+ input: `@prefix : <http://example.org/> .
1505
+ @prefix math: <http://www.w3.org/2000/10/swap/math#> .
1506
+ @base <http://example.org/> .
1507
+
1508
+ { 9999999999999999 math:absoluteValue ?X. ?X math:notEqualTo 9999999999999999. } => { :result :has :fail-abs. }.
1509
+ { 9999999999999999 math:negation ?X. ?X math:negation ?Y. ?Y math:notEqualTo 9999999999999999. } => { :result :has :fail-neg. }.
1510
+ { 9999999999999999 math:rounded ?X. ?X math:notEqualTo 9999999999999999. } => { :result :has :fail-round. }.
1511
+
1512
+ { } => {
1513
+ :test :contains :fail-abs, :fail-neg, :fail-round.
1514
+ }.
1515
+ `,
1516
+ expect: [
1517
+ /:(?:test)\s+:(?:contains)\s+:(?:fail-abs)\s*\./,
1518
+ /:(?:test)\s+:(?:contains)\s+:(?:fail-neg)\s*\./,
1519
+ /:(?:test)\s+:(?:contains)\s+:(?:fail-round)\s*\./,
1520
+ ],
1521
+ notExpect: [
1522
+ /:(?:result)\s+:(?:has)\s+:(?:fail-abs)\s*\./,
1523
+ /:(?:result)\s+:(?:has)\s+:(?:fail-neg)\s*\./,
1524
+ /:(?:result)\s+:(?:has)\s+:(?:fail-round)\s*\./,
1525
+ ],
1526
+ },
1527
+
1501
1528
  {
1502
1529
  name: '60 regression: log:includes must match quoted triples with variable predicates',
1503
1530
  opt: { proofComments: false },
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- 'http://example.org/test#bad-return': () => ({ nope: true }),
5
- };