nudojs 1.3.1 → 1.3.2

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 (2) hide show
  1. package/dist/index.js +71 -24
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -17635,6 +17635,29 @@ var init_may_throw = __esm({
17635
17635
  });
17636
17636
 
17637
17637
  // ../core/src/algebra/arithmetic.ts
17638
+ function distributeSumBinOp(op, a, b, phi2, eval2) {
17639
+ if (a.shape.k !== "sum" && b.shape.k !== "sum") return void 0;
17640
+ const parts = [];
17641
+ const as = a.shape.k === "sum" ? a.shape.members : [a];
17642
+ const bs = b.shape.k === "sum" ? b.shape.members : [b];
17643
+ for (const x of as) {
17644
+ for (const y of bs) {
17645
+ const r = eval2(x, y, phi2);
17646
+ if (r.shape.k === "never") continue;
17647
+ if (r.shape.k === "sum") parts.push(...r.shape.members);
17648
+ else parts.push(r);
17649
+ }
17650
+ }
17651
+ const uniq = dedupAbsMembers(parts);
17652
+ const term = a.term && b.term ? simplifyTerm(app(op, [a.term, b.term])) : void 0;
17653
+ if (uniq.length === 0) {
17654
+ return abs({ k: "unknown" }, term, void 0, "partial");
17655
+ }
17656
+ if (uniq.length === 1) {
17657
+ return abs(uniq[0].shape, term, uniq[0].pred, confJoin(a.conf, b.conf));
17658
+ }
17659
+ return abs({ k: "sum", members: uniq }, term, void 0, "partial");
17660
+ }
17638
17661
  function add(a, b, phi2 = pTrue) {
17639
17662
  if (isSymbolAbs(a) || isSymbolAbs(b)) {
17640
17663
  throw new NudoThrow(errorTypeAbs("TypeError"));
@@ -17692,28 +17715,8 @@ function add(a, b, phi2 = pTrue) {
17692
17715
  "partial"
17693
17716
  );
17694
17717
  }
17695
- if (a.shape.k === "sum" || b.shape.k === "sum") {
17696
- const parts = [];
17697
- const as = a.shape.k === "sum" ? a.shape.members : [a];
17698
- const bs = b.shape.k === "sum" ? b.shape.members : [b];
17699
- for (const x of as) {
17700
- for (const y of bs) {
17701
- const r = add(x, y, phi2);
17702
- if (r.shape.k === "never") continue;
17703
- if (r.shape.k === "sum") parts.push(...r.shape.members);
17704
- else parts.push(r);
17705
- }
17706
- }
17707
- const uniq = dedupAbsMembers(parts);
17708
- const term = a.term && b.term ? simplifyTerm(app("+", [a.term, b.term])) : void 0;
17709
- if (uniq.length === 0) {
17710
- return abs({ k: "unknown" }, term, void 0, "partial");
17711
- }
17712
- if (uniq.length === 1) {
17713
- return abs(uniq[0].shape, term, uniq[0].pred, confJoin(a.conf, b.conf));
17714
- }
17715
- return abs({ k: "sum", members: uniq }, term, void 0, "partial");
17716
- }
17718
+ const distributed = distributeSumBinOp("+", a, b, phi2, add);
17719
+ if (distributed) return distributed;
17717
17720
  if (isNumPrim(a) || isNumPrim(b) || isBigPrim(a) || isBigPrim(b) || a.shape.k === "unknown" || b.shape.k === "unknown" || a.shape.k === "obj" || b.shape.k === "obj" || a.shape.k === "fn" || b.shape.k === "fn" || a.shape.k === "brand" || b.shape.k === "brand") {
17718
17721
  return abs({ k: "sum", members: [num(), str()] }, void 0, void 0, "partial");
17719
17722
  }
@@ -17830,6 +17833,35 @@ function addPred(a, b, sumTerm, phi2) {
17830
17833
  return and(...facts);
17831
17834
  }
17832
17835
  function numericBounds(a, phi2 = pTrue) {
17836
+ if (a.shape.k === "sum") {
17837
+ const members = a.shape.members;
17838
+ let lo;
17839
+ let hi;
17840
+ let loOpen = false;
17841
+ let hiOpen = false;
17842
+ for (const m of members) {
17843
+ const mb = numericBounds(m, phi2);
17844
+ if (!mb) return void 0;
17845
+ if (mb.lo === void 0) {
17846
+ loOpen = true;
17847
+ } else if (!loOpen) {
17848
+ if (lo === void 0 || mb.lo.value < lo.value || mb.lo.value === lo.value && !mb.lo.strict && lo.strict) {
17849
+ lo = mb.lo;
17850
+ }
17851
+ }
17852
+ if (mb.hi === void 0) {
17853
+ hiOpen = true;
17854
+ } else if (!hiOpen) {
17855
+ if (hi === void 0 || mb.hi.value > hi.value || mb.hi.value === hi.value && !mb.hi.strict && hi.strict) {
17856
+ hi = mb.hi;
17857
+ }
17858
+ }
17859
+ }
17860
+ if (loOpen) lo = void 0;
17861
+ if (hiOpen) hi = void 0;
17862
+ if (lo === void 0 && hi === void 0) return void 0;
17863
+ return { lo, hi };
17864
+ }
17833
17865
  if (!isNumPrim(a)) return void 0;
17834
17866
  const result = {};
17835
17867
  if (a.pred && a.term) {
@@ -17936,6 +17968,8 @@ function sub(a, b, phi2 = pTrue) {
17936
17968
  if (isAnyLike(a) || isAnyLike(b)) {
17937
17969
  return toNumberResult(a, b, "-");
17938
17970
  }
17971
+ const distributed = distributeSumBinOp("-", a, b, phi2, sub);
17972
+ if (distributed) return distributed;
17939
17973
  return abs({ k: "unknown" }, void 0, void 0, "partial");
17940
17974
  }
17941
17975
  function mul(a, b, phi2 = pTrue) {
@@ -18008,6 +18042,8 @@ function mul(a, b, phi2 = pTrue) {
18008
18042
  if (isAnyLike(a) || isAnyLike(b)) {
18009
18043
  return toNumberResult(a, b, "*");
18010
18044
  }
18045
+ const distributed = distributeSumBinOp("*", a, b, phi2, mul);
18046
+ if (distributed) return distributed;
18011
18047
  return abs({ k: "unknown" }, void 0, void 0, "partial");
18012
18048
  }
18013
18049
  function div(a, b, phi2 = pTrue) {
@@ -18068,6 +18104,8 @@ function div(a, b, phi2 = pTrue) {
18068
18104
  if (isAnyLike(a) || isAnyLike(b)) {
18069
18105
  return toNumberResult(a, b, "/");
18070
18106
  }
18107
+ const distributed = distributeSumBinOp("/", a, b, phi2, div);
18108
+ if (distributed) return distributed;
18071
18109
  return abs({ k: "unknown" }, void 0, void 0, "partial");
18072
18110
  }
18073
18111
  function mod(a, b, phi2 = pTrue) {
@@ -18118,6 +18156,8 @@ function mod(a, b, phi2 = pTrue) {
18118
18156
  if (isAnyLike(a) || isAnyLike(b)) {
18119
18157
  return toNumberResult(a, b, "%");
18120
18158
  }
18159
+ const distributed = distributeSumBinOp("%", a, b, phi2, mod);
18160
+ if (distributed) return distributed;
18121
18161
  return abs({ k: "unknown" }, void 0, void 0, "partial");
18122
18162
  }
18123
18163
  function cmp(op, a, b, phi2 = pTrue) {
@@ -18722,6 +18762,11 @@ function isNonNaN(a, phi2) {
18722
18762
  if (a.term?.op === "lit") {
18723
18763
  return typeof a.term.value === "number" && !Number.isNaN(a.term.value);
18724
18764
  }
18765
+ if (a.shape.k === "sum") {
18766
+ return a.shape.members.every(
18767
+ (m) => isNonNaN(m, phi2)
18768
+ );
18769
+ }
18725
18770
  const hasNonNaNFact = (p) => {
18726
18771
  if (!p) return false;
18727
18772
  if (p.op === "and") return p.args.some(hasNonNaNFact);
@@ -18843,7 +18888,9 @@ function roundingAbs(name, arg) {
18843
18888
  const impl = name === "round" ? Math.round : name === "floor" ? Math.floor : name === "ceil" ? Math.ceil : Math.trunc;
18844
18889
  const b = numericBounds(arg, phi2);
18845
18890
  const mayNaN = !isNonNaN(arg, phi2);
18846
- const term = arg.term ? simplifyTerm(app(`Math.${name}`, [arg.term])) : void 0;
18891
+ const term = simplifyTerm(
18892
+ app(`Math.${name}`, [arg.term ?? app("arg0", [])])
18893
+ );
18847
18894
  let out = {};
18848
18895
  if (b) {
18849
18896
  if (b.lo !== void 0) {
@@ -18855,7 +18902,7 @@ function roundingAbs(name, arg) {
18855
18902
  out.hi = Number.isNaN(v2) ? void 0 : { value: v2, strict: false };
18856
18903
  }
18857
18904
  }
18858
- const pred = term ? boundsToPred(term, out) : void 0;
18905
+ const pred = boundsToPred(term, out);
18859
18906
  const bounded = abs({ k: "prim", type: "number" }, term, pred, "path");
18860
18907
  if (!mayNaN) return bounded;
18861
18908
  return makeSum(numLit(NaN), bounded);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nudojs",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -46,10 +46,10 @@
46
46
  "dependencies": {
47
47
  "@babel/generator": "^8.0.6",
48
48
  "@babel/types": "^8.0.6",
49
- "@nudojs/core": "1.7.0",
50
- "@nudojs/parser": "1.3.1",
51
- "@nudojs/service": "1.6.0",
52
- "@nudojs/harvester": "0.3.1",
49
+ "@nudojs/core": "1.7.1",
50
+ "@nudojs/parser": "1.3.2",
51
+ "@nudojs/service": "1.6.1",
52
+ "@nudojs/harvester": "0.3.2",
53
53
  "commander": "^15.0.0"
54
54
  },
55
55
  "devDependencies": {