@mojir/lits 2.1.10 → 2.1.11

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.
@@ -10,5 +10,6 @@ export declare function cloneColl<T extends Coll>(value: T): T;
10
10
  export declare function createNativeJsFunction(fn: (...args: any[]) => unknown, name?: string): NativeJsFunction;
11
11
  export declare function joinSets<T>(...results: Set<T>[]): Set<T>;
12
12
  export declare function addToSet<T>(target: Set<T>, source: Set<T>): void;
13
+ export declare const EPSILON = 1e-10;
13
14
  export declare function approxEqual(a: number, b: number, epsilon?: number): boolean;
14
- export declare function approxZero(value: number, epsilon?: number): boolean;
15
+ export declare function approxZero(value: number): boolean;
package/dist/index.esm.js CHANGED
@@ -695,7 +695,7 @@ function deepEqual(a, b, sourceCodeInfo) {
695
695
  if (a === b)
696
696
  return true;
697
697
  if (typeof a === 'number' && typeof b === 'number')
698
- return Math.abs(a - b) < 1e-10;
698
+ return approxEqual(a, b);
699
699
  if (Array.isArray(a) && Array.isArray(b)) {
700
700
  if (a.length !== b.length)
701
701
  return false;
@@ -795,9 +795,8 @@ function approxEqual(a, b, epsilon) {
795
795
  // Use relative error for larger values
796
796
  return diff / (absA + absB) < epsilon;
797
797
  }
798
- function approxZero(value, epsilon) {
799
- if (epsilon === void 0) { epsilon = EPSILON; }
800
- return Math.abs(value) < epsilon;
798
+ function approxZero(value) {
799
+ return Math.abs(value) < EPSILON;
801
800
  }
802
801
 
803
802
  // isArray not needed, use Array.isArary
@@ -2558,30 +2557,6 @@ var mathNormalExpression = {
2558
2557
  },
2559
2558
  paramCount: {},
2560
2559
  },
2561
- '~': {
2562
- evaluate: function (params, sourceCodeInfo) {
2563
- var _a;
2564
- var _b = __read(getNumberVectorOrMatrixOperation([params[0], params[1]], sourceCodeInfo), 2), operation = _b[0], operands = _b[1];
2565
- var eplsilon = (_a = params[2]) !== null && _a !== void 0 ? _a : 1e-10;
2566
- assertNumber(eplsilon, sourceCodeInfo, { positive: true, finite: true });
2567
- if (operation === 'number') {
2568
- var _c = __read(operands, 2), first = _c[0], second = _c[1];
2569
- return approxEqual(first, second, eplsilon);
2570
- }
2571
- else if (operation === 'vector') {
2572
- var firstVector = operands[0];
2573
- var secondVector_1 = operands[1];
2574
- return firstVector.every(function (val, i) { return approxEqual(val, secondVector_1[i], eplsilon); });
2575
- }
2576
- else {
2577
- var firstMatrix = operands[0];
2578
- var secondMatrix_1 = operands[1];
2579
- return firstMatrix.every(function (row, i) { return row.every(function (val, j) { return approxEqual(val, secondMatrix_1[i][j], eplsilon); }); });
2580
- }
2581
- },
2582
- paramCount: { min: 2, max: 3 },
2583
- aliases: ['≈'],
2584
- },
2585
2560
  'quot': {
2586
2561
  evaluate: function (params, sourceCodeInfo) {
2587
2562
  var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
@@ -2590,13 +2565,13 @@ var mathNormalExpression = {
2590
2565
  }
2591
2566
  else if (operation === 'vector') {
2592
2567
  var firstVector = operands[0];
2593
- var secondVector_2 = operands[1];
2594
- return firstVector.map(function (val, i) { return Math.trunc(val / secondVector_2[i]); });
2568
+ var secondVector_1 = operands[1];
2569
+ return firstVector.map(function (val, i) { return Math.trunc(val / secondVector_1[i]); });
2595
2570
  }
2596
2571
  else {
2597
2572
  var firstMatrix = operands[0];
2598
- var secondMatrix_2 = operands[1];
2599
- return firstMatrix.map(function (row, i) { return row.map(function (val, j) { return Math.trunc(val / secondMatrix_2[i][j]); }); });
2573
+ var secondMatrix_1 = operands[1];
2574
+ return firstMatrix.map(function (row, i) { return row.map(function (val, j) { return Math.trunc(val / secondMatrix_1[i][j]); }); });
2600
2575
  }
2601
2576
  },
2602
2577
  paramCount: 2,
@@ -2610,19 +2585,19 @@ var mathNormalExpression = {
2610
2585
  }
2611
2586
  else if (operation === 'vector') {
2612
2587
  var firstVector = operands[0];
2613
- var secondVector_3 = operands[1];
2588
+ var secondVector_2 = operands[1];
2614
2589
  return firstVector.map(function (dividend, i) {
2615
- var divisor = secondVector_3[i];
2590
+ var divisor = secondVector_2[i];
2616
2591
  var quotient = Math.floor(dividend / divisor);
2617
2592
  return dividend - divisor * quotient;
2618
2593
  });
2619
2594
  }
2620
2595
  else {
2621
2596
  var firstMatrix = operands[0];
2622
- var secondMatrix_3 = operands[1];
2597
+ var secondMatrix_2 = operands[1];
2623
2598
  return firstMatrix.map(function (row, i) { return row.map(function (val, j) {
2624
- var quotient = Math.floor(val / secondMatrix_3[i][j]);
2625
- return val - secondMatrix_3[i][j] * quotient;
2599
+ var quotient = Math.floor(val / secondMatrix_2[i][j]);
2600
+ return val - secondMatrix_2[i][j] * quotient;
2626
2601
  }); });
2627
2602
  }
2628
2603
  },
@@ -2636,13 +2611,13 @@ var mathNormalExpression = {
2636
2611
  }
2637
2612
  else if (operation === 'vector') {
2638
2613
  var firstVector = operands[0];
2639
- var secondVector_4 = operands[1];
2640
- return firstVector.map(function (dividend, i) { return dividend % secondVector_4[i]; });
2614
+ var secondVector_3 = operands[1];
2615
+ return firstVector.map(function (dividend, i) { return dividend % secondVector_3[i]; });
2641
2616
  }
2642
2617
  else {
2643
2618
  var firstMatrix = operands[0];
2644
- var secondMatrix_4 = operands[1];
2645
- return firstMatrix.map(function (row, i) { return row.map(function (dividend, j) { return dividend % secondMatrix_4[i][j]; }); });
2619
+ var secondMatrix_3 = operands[1];
2620
+ return firstMatrix.map(function (row, i) { return row.map(function (dividend, j) { return dividend % secondMatrix_3[i][j]; }); });
2646
2621
  }
2647
2622
  },
2648
2623
  paramCount: 2,
@@ -2692,13 +2667,13 @@ var mathNormalExpression = {
2692
2667
  }
2693
2668
  else if (operation === 'vector') {
2694
2669
  var firstVector = operands[0];
2695
- var secondVector_5 = operands[1];
2696
- return firstVector.map(function (base, i) { return Math.pow(base, secondVector_5[i]); });
2670
+ var secondVector_4 = operands[1];
2671
+ return firstVector.map(function (base, i) { return Math.pow(base, secondVector_4[i]); });
2697
2672
  }
2698
2673
  else {
2699
2674
  var firstMatrix = operands[0];
2700
- var secondMatrix_5 = operands[1];
2701
- return firstMatrix.map(function (row, i) { return row.map(function (base, j) { return Math.pow(base, secondMatrix_5[i][j]); }); });
2675
+ var secondMatrix_4 = operands[1];
2676
+ return firstMatrix.map(function (row, i) { return row.map(function (base, j) { return Math.pow(base, secondMatrix_4[i][j]); }); });
2702
2677
  }
2703
2678
  },
2704
2679
  paramCount: 2,
@@ -3110,6 +3085,40 @@ var mathNormalExpression = {
3110
3085
  },
3111
3086
  paramCount: 1,
3112
3087
  },
3088
+ 'to-rad': {
3089
+ evaluate: function (params, sourceCodeInfo) {
3090
+ var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
3091
+ if (operation === 'number') {
3092
+ return (operands[0] * Math.PI) / 180;
3093
+ }
3094
+ else if (operation === 'vector') {
3095
+ var vector = operands[0];
3096
+ return vector.map(function (val) { return (val * Math.PI) / 180; });
3097
+ }
3098
+ else {
3099
+ var matrix = operands[0];
3100
+ return matrix.map(function (row) { return row.map(function (val) { return (val * Math.PI) / 180; }); });
3101
+ }
3102
+ },
3103
+ paramCount: 1,
3104
+ },
3105
+ 'to-deg': {
3106
+ evaluate: function (params, sourceCodeInfo) {
3107
+ var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
3108
+ if (operation === 'number') {
3109
+ return (operands[0] * 180) / Math.PI;
3110
+ }
3111
+ else if (operation === 'vector') {
3112
+ var vector = operands[0];
3113
+ return vector.map(function (val) { return (val * 180) / Math.PI; });
3114
+ }
3115
+ else {
3116
+ var matrix = operands[0];
3117
+ return matrix.map(function (row) { return row.map(function (val) { return (val * 180) / Math.PI; }); });
3118
+ }
3119
+ },
3120
+ paramCount: 1,
3121
+ },
3113
3122
  };
3114
3123
 
3115
3124
  function isEqual(_a, sourceCodeInfo) {
@@ -3729,9 +3738,9 @@ var predicatesNormalExpression = {
3729
3738
  },
3730
3739
  'zero?': {
3731
3740
  evaluate: function (_a, sourceCodeInfo) {
3732
- var _b = __read(_a, 1), first = _b[0];
3733
- assertNumber(first, sourceCodeInfo, { finite: true });
3734
- return first === 0;
3741
+ var _b = __read(_a, 1), value = _b[0];
3742
+ assertNumber(value, sourceCodeInfo, { finite: true });
3743
+ return Math.abs(value) < EPSILON;
3735
3744
  },
3736
3745
  paramCount: 1,
3737
3746
  },
@@ -6577,6 +6586,10 @@ function scale(vector, scalar) {
6577
6586
  return vector.map(function (item) { return item * scalar; });
6578
6587
  }
6579
6588
 
6589
+ function length(vector) {
6590
+ return Math.sqrt(vector.reduce(function (acc, item) { return acc + Math.pow(item, 2); }, 0));
6591
+ }
6592
+
6580
6593
  var linearAlgebraNormalExpression = {
6581
6594
  'lin:rotate2d': {
6582
6595
  evaluate: function (_a, sourceCodeInfo) {
@@ -6901,7 +6914,7 @@ var linearAlgebraNormalExpression = {
6901
6914
  evaluate: function (_a, sourceCodeInfo) {
6902
6915
  var _b = __read(_a, 1), vector = _b[0];
6903
6916
  assertNonEmptyVector(vector, sourceCodeInfo);
6904
- return Math.sqrt(vector.reduce(function (acc, val) { return acc + val * val; }, 0));
6917
+ return length(vector);
6905
6918
  },
6906
6919
  paramCount: 1,
6907
6920
  aliases: ['lin:l2-norm', 'lin:length'],
@@ -7207,6 +7220,31 @@ var linearAlgebraNormalExpression = {
7207
7220
  },
7208
7221
  paramCount: 2,
7209
7222
  },
7223
+ 'lin:to-polar': {
7224
+ evaluate: function (_a, sourceCodeInfo) {
7225
+ var _b = __read(_a, 1), vector = _b[0];
7226
+ assert2dVector(vector, sourceCodeInfo);
7227
+ if (isZeroVector(vector)) {
7228
+ return [0, 0];
7229
+ }
7230
+ var r = Math.sqrt(Math.pow(vector[0], 2) + Math.pow(vector[1], 2));
7231
+ var theta = Math.atan2(vector[1], vector[0]);
7232
+ return [r, theta];
7233
+ },
7234
+ paramCount: 1,
7235
+ },
7236
+ 'lin:from-polar': {
7237
+ evaluate: function (_a, sourceCodeInfo) {
7238
+ var _b = __read(_a, 1), polar = _b[0];
7239
+ assert2dVector(polar, sourceCodeInfo);
7240
+ var _c = __read(polar, 2), r = _c[0], theta = _c[1];
7241
+ if (r === 0) {
7242
+ return [0, 0];
7243
+ }
7244
+ return [r * Math.cos(theta), r * Math.sin(theta)];
7245
+ },
7246
+ paramCount: 1,
7247
+ },
7210
7248
  };
7211
7249
 
7212
7250
  /**
@@ -12889,8 +12927,6 @@ var binaryOperators = [
12889
12927
  '=', // equal
12890
12928
  '!=', // not equal
12891
12929
  '≠', // not equal
12892
- '~', // approximate
12893
- '≈', // approximate
12894
12930
  '&', // bitwise AND
12895
12931
  'xor', // bitwise XOR
12896
12932
  '|', // bitwise OR
@@ -13533,8 +13569,6 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
13533
13569
  case '=': // equal
13534
13570
  case '!=': // not equal
13535
13571
  case '≠': // not equal
13536
- case '~': // approximate
13537
- case '≈': // approximate
13538
13572
  return 5;
13539
13573
  case '&': // bitwise AND
13540
13574
  case 'xor': // bitwise XOR
@@ -13588,8 +13622,6 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
13588
13622
  case '&':
13589
13623
  case 'xor':
13590
13624
  case '|':
13591
- case '~':
13592
- case '≈':
13593
13625
  case '|>':
13594
13626
  return createNamedNormalExpressionNode(symbolNode, [left, right], sourceCodeInfo);
13595
13627
  case '&&':
@@ -14975,7 +15007,6 @@ var api = {
14975
15007
  '-',
14976
15008
  '*',
14977
15009
  '/',
14978
- '~',
14979
15010
  'mod',
14980
15011
  'rem',
14981
15012
  'quot',
@@ -15007,6 +15038,8 @@ var api = {
15007
15038
  'asinh',
15008
15039
  'acosh',
15009
15040
  'atanh',
15041
+ 'to-rad',
15042
+ 'to-deg',
15010
15043
  ],
15011
15044
  functional: [
15012
15045
  '|>',
@@ -15279,6 +15312,8 @@ var api = {
15279
15312
  'lin:cross-correlation',
15280
15313
  'lin:rref',
15281
15314
  'lin:solve',
15315
+ 'lin:to-polar',
15316
+ 'lin:from-polar',
15282
15317
  ],
15283
15318
  numberTheory: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(getNumberTheorySequenceNames('abundant')), false), __read(getNumberTheorySequenceNames('bell')), false), __read(getNumberTheorySequenceNames('catalan')), false), __read(getNumberTheorySequenceNames('composite')), false), __read(getNumberTheorySequenceNames('factorial')), false), __read(getNumberTheorySequenceNames('fibonacci')), false), __read(getNumberTheorySequenceNames('geometric')), false), __read(getNumberTheorySequenceNames('golomb')), false), __read(getNumberTheorySequenceNames('happy')), false), __read(getNumberTheorySequenceNames('look-and-say')), false), __read(getNumberTheorySequenceNames('lucas')), false), __read(getNumberTheorySequenceNames('lucky')), false), __read(getNumberTheorySequenceNames('mersenne')), false), __read(getNumberTheorySequenceNames('padovan')), false), __read(getNumberTheorySequenceNames('partition')), false), __read(getNumberTheorySequenceNames('pell')), false), __read(getNumberTheorySequenceNames('perfect')), false), __read(getNumberTheorySequenceNames('perfect-cube')), false), __read(getNumberTheorySequenceNames('perfect-power')), false), __read(getNumberTheorySequenceNames('perfect-square')), false), __read(getNumberTheorySequenceNames('polygonal')), false), __read(getNumberTheorySequenceNames('prime')), false), __read(getNumberTheorySequenceNames('recaman')), false), __read(getNumberTheorySequenceNames('sylvester')), false), __read(getNumberTheorySequenceNames('thue-morse')), false), __read(getNumberTheorySequenceNames('tribonacci')), false), [
15284
15319
  'nth:collatz-seq',
@@ -16988,29 +17023,6 @@ var mathReference = {
16988
17023
  '[[1, 2, 3], [4, 5, 6]] / 2',
16989
17024
  ],
16990
17025
  },
16991
- '~': {
16992
- title: '~',
16993
- category: 'Math',
16994
- linkName: '-tilde',
16995
- returns: {
16996
- type: ['number', 'vector', 'matrix'],
16997
- },
16998
- args: __assign({}, mixedOperatorArgs),
16999
- variants: [
17000
- { argumentNames: ['a, b'] },
17001
- ],
17002
- description: 'The `~` checks for approximately equal values, returning `true` if the absolute difference between the two numbers is less than or equal to a small threshold (default: `1e-10`). It works on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it checks each element for approximate equality.',
17003
- examples: [
17004
- '~(0.1, 0.1)',
17005
- '~(0.1, 0.10000000000001)',
17006
- '~(0.1, 0.2)',
17007
- '~(0.1, 0.101, 0.1)',
17008
- '~([1, 2, 3], [1.00000000000001, 2.00000000000001, 3.00000000000001])',
17009
- '~([1, 2, 3], [1.1, 2.1, 3.1])',
17010
- '~([[1, 2, 3], [1, 2, 3]], [[1.01, 2.01, 3.01], [1.01, 2.01, 3.01]], 0.1)',
17011
- ],
17012
- aliases: ['≈'],
17013
- },
17014
17026
  'mod': {
17015
17027
  title: 'mod',
17016
17028
  category: 'Math',
@@ -17788,6 +17800,56 @@ var mathReference = {
17788
17800
  'atanh([[0.1, 0.2], [0.3, 0.4]])',
17789
17801
  ],
17790
17802
  },
17803
+ 'to-rad': {
17804
+ title: 'to-rad',
17805
+ category: 'Math',
17806
+ linkName: 'to-rad',
17807
+ returns: {
17808
+ type: ['number', 'vector', 'matrix'],
17809
+ },
17810
+ args: {
17811
+ x: {
17812
+ type: ['number', 'vector', 'matrix'],
17813
+ },
17814
+ },
17815
+ variants: [
17816
+ { argumentNames: ['x'] },
17817
+ ],
17818
+ description: 'The `to-rad` function converts an angle from degrees to radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',
17819
+ examples: [
17820
+ 'to-rad(0)',
17821
+ 'to-rad(90)',
17822
+ 'to-rad(180)',
17823
+ 'to-rad(360)',
17824
+ 'to-rad([0, 90, 180])',
17825
+ 'to-rad([[0, 90], [180, 360]])',
17826
+ ],
17827
+ },
17828
+ 'to-deg': {
17829
+ title: 'to-deg',
17830
+ category: 'Math',
17831
+ linkName: 'to-deg',
17832
+ returns: {
17833
+ type: ['number', 'vector', 'matrix'],
17834
+ },
17835
+ args: {
17836
+ x: {
17837
+ type: ['number', 'vector', 'matrix'],
17838
+ },
17839
+ },
17840
+ variants: [
17841
+ { argumentNames: ['x'] },
17842
+ ],
17843
+ description: 'The `to-deg` function converts an angle from radians to degrees, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',
17844
+ examples: [
17845
+ 'to-deg(0)',
17846
+ 'to-deg(PI)',
17847
+ 'to-deg(PI / 2)',
17848
+ 'to-deg(3 * PI / 2)',
17849
+ 'to-deg([0, PI, PI / 2])',
17850
+ 'to-deg([[0, PI], [PI / 2, 3 * PI / 2]])',
17851
+ ],
17852
+ },
17791
17853
  };
17792
17854
 
17793
17855
  var miscReference = {
@@ -24241,6 +24303,51 @@ var linAlgReference = {
24241
24303
  'lin:solve([[2, 3], [1, -1]], [8, 2])',
24242
24304
  ],
24243
24305
  },
24306
+ 'lin:to-polar': {
24307
+ title: 'lin:to-polar',
24308
+ category: 'Linear Algebra',
24309
+ description: 'Converts a 2D vector to polar coordinates.',
24310
+ linkName: 'lin-colon-to-polar',
24311
+ returns: {
24312
+ type: 'vector',
24313
+ },
24314
+ args: {
24315
+ vector: {
24316
+ type: 'vector',
24317
+ description: '2D Vector to convert.',
24318
+ },
24319
+ },
24320
+ variants: [
24321
+ { argumentNames: ['vector'] },
24322
+ ],
24323
+ examples: [
24324
+ 'lin:to-polar([1, 2])',
24325
+ 'lin:to-polar([3, 4])',
24326
+ ],
24327
+ },
24328
+ 'lin:from-polar': {
24329
+ title: 'lin:from-polar',
24330
+ category: 'Linear Algebra',
24331
+ description: 'Converts polar coordinates to a 2D vector.',
24332
+ linkName: 'lin-colon-from-polar',
24333
+ returns: {
24334
+ type: 'vector',
24335
+ },
24336
+ args: {
24337
+ polar: {
24338
+ type: 'vector',
24339
+ description: 'Polar coordinates to convert.',
24340
+ },
24341
+ },
24342
+ variants: [
24343
+ { argumentNames: ['polar'] },
24344
+ ],
24345
+ examples: [
24346
+ 'lin:from-polar([1, PI / 4])',
24347
+ 'lin:from-polar([1, 0])',
24348
+ 'lin:from-polar([1, -PI / 2])',
24349
+ ],
24350
+ },
24244
24351
  };
24245
24352
 
24246
24353
  var predicateReference = {