@cortex-js/compute-engine 0.25.1 → 0.26.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 (153) hide show
  1. package/README.md +5 -8
  2. package/dist/compute-engine.esm.js +26338 -22472
  3. package/dist/compute-engine.js +26348 -22470
  4. package/dist/compute-engine.min.esm.js +89 -23
  5. package/dist/compute-engine.min.js +89 -23
  6. package/dist/math-json.esm.js +22 -139
  7. package/dist/math-json.js +22 -139
  8. package/dist/math-json.min.esm.js +22 -139
  9. package/dist/math-json.min.js +2 -2
  10. package/dist/types/common/ansi-codes.d.ts +30 -4
  11. package/dist/types/common/buffer.d.ts +9 -0
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/one-of.d.ts +9 -0
  14. package/dist/types/common/signals.d.ts +1 -1
  15. package/dist/types/common/styled-text.d.ts +28 -0
  16. package/dist/types/common/suggest.d.ts +1 -0
  17. package/dist/types/common/syntax-highlighter.d.ts +40 -0
  18. package/dist/types/common/terminal.d.ts +19 -0
  19. package/dist/types/common/type/parse.d.ts +4 -0
  20. package/dist/types/common/type/primitive.d.ts +8 -0
  21. package/dist/types/common/type/serialize.d.ts +2 -0
  22. package/dist/types/common/type/subtype.d.ts +6 -0
  23. package/dist/types/common/type/types.d.ts +249 -0
  24. package/dist/types/common/type/utils.d.ts +39 -0
  25. package/dist/types/common/utils.d.ts +2 -1
  26. package/dist/types/compute-engine/assume.d.ts +13 -13
  27. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +71 -47
  28. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -0
  30. package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +12 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +16 -0
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +20 -0
  33. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  34. package/dist/types/compute-engine/boxed-expression/box.d.ts +13 -71
  35. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +31 -13
  36. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +66 -45
  37. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +42 -37
  38. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
  39. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +13 -9
  40. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +34 -66
  41. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +63 -41
  42. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +44 -27
  43. package/dist/types/compute-engine/boxed-expression/cache.d.ts +6 -0
  44. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  46. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  47. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -6
  49. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  50. package/dist/types/compute-engine/boxed-expression/hold.d.ts +9 -0
  51. package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -4
  52. package/dist/types/compute-engine/{symbolic → boxed-expression}/negate.d.ts +4 -4
  53. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +5 -39
  54. package/dist/types/compute-engine/boxed-expression/order.d.ts +26 -14
  55. package/dist/types/compute-engine/{symbolic → boxed-expression}/polynomials.d.ts +11 -15
  56. package/dist/types/compute-engine/{symbolic → boxed-expression}/product.d.ts +18 -24
  57. package/dist/types/compute-engine/boxed-expression/public.d.ts +911 -634
  58. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  59. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
  60. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +6 -0
  61. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  62. package/dist/types/compute-engine/{solve.d.ts → boxed-expression/solve.d.ts} +5 -5
  63. package/dist/types/compute-engine/{symbolic → boxed-expression}/tensor-fields.d.ts +3 -3
  64. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  65. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +10 -0
  66. package/dist/types/compute-engine/boxed-expression/utils.d.ts +22 -16
  67. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -7
  68. package/dist/types/compute-engine/collection-utils.d.ts +24 -2
  69. package/dist/types/compute-engine/compile.d.ts +3 -3
  70. package/dist/types/compute-engine/compute-engine.d.ts +132 -165
  71. package/dist/types/compute-engine/cost-function.d.ts +11 -1
  72. package/dist/types/compute-engine/function-utils.d.ts +5 -5
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  87. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
  88. package/dist/types/compute-engine/latex-syntax/parse.d.ts +26 -31
  89. package/dist/types/compute-engine/latex-syntax/public.d.ts +24 -18
  90. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
  91. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -8
  93. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  94. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -2
  95. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  96. package/dist/types/compute-engine/library/collections.d.ts +24 -1
  97. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  98. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  99. package/dist/types/compute-engine/library/core.d.ts +1 -3
  100. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  101. package/dist/types/compute-engine/library/library.d.ts +2 -4
  102. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  103. package/dist/types/compute-engine/library/logic.d.ts +5 -1
  104. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  105. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  106. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  107. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  108. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  109. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  110. package/dist/types/compute-engine/library/utils.d.ts +46 -40
  111. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +59 -0
  112. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +77 -0
  113. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +58 -0
  114. package/dist/types/compute-engine/numeric-value/public.d.ts +110 -0
  115. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  116. package/dist/types/compute-engine/numerics/bignum.d.ts +12 -0
  117. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  118. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  119. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +19 -0
  120. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +4 -14
  121. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +6 -9
  122. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -59
  124. package/dist/types/compute-engine/numerics/primes.d.ts +3 -3
  125. package/dist/types/compute-engine/numerics/rationals.d.ts +29 -13
  126. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  128. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  129. package/dist/types/compute-engine/public.d.ts +8 -4
  130. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -2
  131. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  132. package/dist/types/compute-engine/{simplify-rules.d.ts → symbolic/simplify-rules.d.ts} +1 -1
  133. package/dist/types/compute-engine/{symbolic → tensor}/tensors.d.ts +3 -3
  134. package/dist/types/compute-engine.d.ts +4 -2
  135. package/dist/types/math-json/identifiers.d.ts +11 -0
  136. package/dist/types/math-json/{math-json-format.d.ts → types.d.ts} +4 -9
  137. package/dist/types/math-json/utils.d.ts +15 -23
  138. package/dist/types/math-json.d.ts +3 -3
  139. package/package.json +3 -3
  140. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -48
  141. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +0 -40
  142. package/dist/types/compute-engine/boxed-expression/coefficient-field.d.ts +0 -56
  143. package/dist/types/compute-engine/domain-utils.d.ts +0 -19
  144. package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
  145. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -16
  146. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
  147. package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
  148. package/dist/types/compute-engine/library/domains.d.ts +0 -16
  149. package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
  150. package/dist/types/compute-engine/rules.d.ts +0 -20
  151. package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
  152. package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
  153. package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
@@ -1,3 +1,5 @@
1
- /* 0.25.1 */
2
- export declare const version = "0.25.1";
1
+ /* 0.26.2 */
2
+ export declare const version = "0.26.2";
3
3
  export { ComputeEngine } from './compute-engine/compute-engine';
4
+ export { terminal } from './common/terminal';
5
+ export { highlightCodeSpan, highlightCodeBlock, } from './common/syntax-highlighter';
@@ -0,0 +1,11 @@
1
+ /* 0.26.2 */
2
+ * Return true if the string is a valid identifier.
3
+ *
4
+ * Check for identifiers matching a profile of [Unicode UAX31](https://unicode.org/reports/tr31/)
5
+ *
6
+ * See https://cortexjs.io/math-json/#identifiers for a full definition of the
7
+ * profile.
8
+ */
9
+ export declare function isValidIdentifier(s: string): boolean;
10
+ export declare const EMOJIS: RegExp;
11
+ export declare function validateIdentifier(s: unknown): 'valid' | 'not-a-string' | 'empty-string' | 'expected-nfc' | 'unexpected-mixed-emoji' | 'unexpected-bidi-marker' | 'unexpected-script' | 'invalid-first-char' | 'invalid-char';
@@ -1,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  /** @category MathJSON */
3
3
  export type Attributes = {
4
4
  /** A human readable string to annotate this expression, since JSON does not
@@ -96,14 +96,9 @@ export type MathJsonString = {
96
96
  } & Attributes;
97
97
  /** @category MathJSON */
98
98
  export type MathJsonFunction = {
99
- fn: [MathJsonIdentifier | MathJsonFunction, ...Expression[]];
100
- } & Attributes;
101
- /** @category MathJSON */
102
- export type MathJsonDictionary = {
103
- dict: {
104
- [key: string]: Expression;
105
- };
99
+ fn: [MathJsonIdentifier, ...Expression[]];
106
100
  } & Attributes;
101
+ export type ExpressionObject = MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction;
107
102
  /**
108
103
  * A MathJSON expression is a recursive data structure.
109
104
  *
@@ -112,4 +107,4 @@ export type MathJsonDictionary = {
112
107
  *
113
108
  * @category MathJSON
114
109
  */
115
- export type Expression = number | MathJsonIdentifier | string | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | [MathJsonIdentifier | MathJsonFunction, ...Expression[]];
110
+ export type Expression = ExpressionObject | number | MathJsonIdentifier | string | readonly [MathJsonIdentifier, ...Expression[]];
@@ -1,14 +1,10 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const MISSING: Expression;
3
3
  export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumber;
4
4
  export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
5
5
  export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbol;
6
6
  export declare function isStringObject(expr: Expression | null): expr is MathJsonString;
7
7
  export declare function isFunctionObject(expr: Expression | null): expr is MathJsonFunction;
8
- export declare function isDictionaryObject(expr: Expression): expr is MathJsonNumber;
9
- export declare function isValidIdentifier(s: string): boolean;
10
- export declare const ONLY_EMOJIS: RegExp;
11
- export declare function validateIdentifier(s: unknown): 'valid' | 'not-a-string' | 'empty-string' | 'expected-nfc' | 'unexpected-mixed-emoji' | 'unexpected-bidi-marker' | 'unexpected-script' | 'invalid-first-char' | 'invalid-char';
12
8
  /** If expr is a string literal, return it.
13
9
  *
14
10
  * A string literal is a JSON string that begins and ends with
@@ -17,30 +13,26 @@ export declare function validateIdentifier(s: unknown): 'valid' | 'not-a-string'
17
13
  export declare function stringValue(expr: Expression | null | undefined): string | null;
18
14
  export declare function stripText(expr: Expression | null | undefined): Expression | null;
19
15
  /**
20
- * The head of a function can be an identifier or an expression.
16
+ * The operator of a function is an identifier
21
17
  *
22
- * Return `null` if the expression is not a function.
18
+ * Return an empty string if the expression is not a function.
23
19
  *
24
20
  * Examples:
25
21
  * * `["Negate", 5]` -> `"Negate"`
26
- * * `[["Prime", "f"], "x"]` -> `["Prime", "f"]`
27
22
  */
28
- export declare function head(expr: Expression | null | undefined): Expression | null;
29
- /** Return the head of an expression, only if it's a string */
30
- export declare function headName(expr: Expression | null): string;
23
+ export declare function operator(expr: Expression | null | undefined): MathJsonIdentifier;
31
24
  /**
32
- * Return all the elements but the first one, i.e. the arguments of a
33
- * function.
25
+ * Return the arguments of a function, or an empty array if not a function
26
+ * or no arguments.
34
27
  */
35
- export declare function ops(expr: Expression | null | undefined): Expression[] | null;
36
- /** Return the nth argument of a function expression */
37
- export declare function op(expr: Expression | null | undefined, n: number): Expression | null;
38
- export declare function op1(expr: Expression | null | undefined): Expression | null;
39
- export declare function op2(expr: Expression | null | undefined): Expression | null;
28
+ export declare function operands(expr: Expression | null | undefined): ReadonlyArray<Expression>;
29
+ /** Return the nth operand of a function expression */
30
+ export declare function operand(expr: Expression | null, n: 1 | 2 | 3): Expression | null;
40
31
  export declare function nops(expr: Expression | null | undefined): number;
41
- export declare function unhold(expr: Expression | null | undefined): Expression | null;
32
+ export declare function unhold(expr: Expression | null): Expression | null;
42
33
  export declare function symbol(expr: Expression | null | undefined): string | null;
43
34
  export declare function dictionary(expr: Expression | null): null | Record<string, Expression>;
35
+ export declare function dictionaryFrom(dict: Record<string, Expression>): Expression;
44
36
  /**
45
37
  * CAUTION: `machineValue()` will return a truncated value if the number
46
38
  * has a precision outside of the machine range.
@@ -59,7 +51,6 @@ export declare function machineValue(expr: Expression | null | undefined): numbe
59
51
  * The denominator is always > 0.
60
52
  */
61
53
  export declare function rationalValue(expr: Expression | undefined | null): [number, number] | null;
62
- export declare function applyRecursively<T extends Expression = Expression>(expr: T, fn: (x: T) => T): Expression;
63
54
  export declare function subs(expr: Expression, s: {
64
55
  [symbol: string]: Expression;
65
56
  }): Expression;
@@ -73,8 +64,9 @@ export declare function mapArgs<T>(expr: Expression, fn: (x: Expression) => T):
73
64
  */
74
65
  export declare function foldAssociativeOperator(op: string, lhs: Expression, rhs: Expression): Expression;
75
66
  /** Return the elements of a sequence, or null if the expression is not a sequence. The sequence can be optionally enclosed by a`["Delimiter"]` expression */
76
- export declare function getSequence(expr: Expression | null): Expression[] | null;
77
- export declare function isEmptySequence(expr: Expression | null): boolean;
78
- export declare function missingIfEmpty(expr: Expression | null): Expression;
67
+ export declare function getSequence(expr: Expression | null | undefined): ReadonlyArray<Expression> | null;
68
+ /** `Nothing` or the empty sequence (`["Sequence"]`) */
69
+ export declare function isEmptySequence(expr: Expression | null | undefined): expr is null | undefined;
70
+ export declare function missingIfEmpty(expr: Expression | null | undefined): Expression;
79
71
  /** The number of leaves (atomic expressions) in the expression */
80
72
  export declare function countLeaves(expr: Expression | null): number;
@@ -1,3 +1,3 @@
1
- /* 0.25.1 */
2
- export { isSymbolObject, isStringObject, isFunctionObject, isDictionaryObject, stringValue as getStringValue, head, headName, symbol, applyRecursively, mapArgs, op, nops, dictionary as getDictionary, } from './math-json/utils';
3
- export declare const version = "0.25.1";
1
+ /* 0.26.2 */
2
+ export { isSymbolObject, isStringObject, isFunctionObject, stringValue as getStringValue, operator, operand, symbol, mapArgs, dictionary as getDictionary, } from './math-json/utils';
3
+ export declare const version = "0.26.2";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.25.1",
2
+ "version": "0.26.2",
3
3
  "scripts": {
4
4
  "doc": "bash ./scripts/doc.sh",
5
5
  "build": "bash ./scripts/build.sh",
@@ -66,7 +66,7 @@
66
66
  "chalk": "^5.3.0",
67
67
  "check-node-version": "^4.2.1",
68
68
  "concat-md": "^0.5.1",
69
- "esbuild": "^0.21.5",
69
+ "esbuild": "^0.24.0",
70
70
  "eslint": "^8.56.0",
71
71
  "eslint-config-prettier": "^9.0.0",
72
72
  "eslint-plugin-import": "^2.28.1",
@@ -88,7 +88,7 @@
88
88
  },
89
89
  "prettier": "@cortex-js/prettier-config",
90
90
  "dependencies": {
91
- "complex.js": "^2.1.1",
91
+ "complex-esm": "^2.1.1-esm1",
92
92
  "decimal.js": "^10.4.3"
93
93
  }
94
94
  }
@@ -1,48 +0,0 @@
1
- /* 0.25.1 */
2
- import Decimal from 'decimal.js';
3
- import { Expression } from '../../math-json/math-json-format';
4
- import { BoxedExpression, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, ReplaceOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, BoxedSubstitution, Rule, CanonicalOptions } from './public';
5
- import { _BoxedExpression } from './abstract-boxed-expression';
6
- /**
7
- * BoxedDictionary
8
- *
9
- * @noInheritDoc
10
- */
11
- export declare class BoxedDictionary extends _BoxedExpression {
12
- private _value;
13
- private _isCanonical;
14
- constructor(ce: IComputeEngine, dict: {
15
- [key: string]: SemiBoxedExpression;
16
- } | Map<string, BoxedExpression>, options?: {
17
- canonical?: CanonicalOptions;
18
- metadata?: Metadata;
19
- });
20
- bind(): void;
21
- reset(): undefined;
22
- get hash(): number;
23
- get complexity(): number;
24
- get head(): 'Dictionary';
25
- get isPure(): boolean;
26
- getKey(key: string): BoxedExpression | undefined;
27
- hasKey(key: string): boolean;
28
- get keys(): IterableIterator<string>;
29
- get keysCount(): number;
30
- has(x: string | string[]): boolean;
31
- get domain(): BoxedDomain;
32
- get json(): Expression;
33
- /** Structural equality */
34
- isSame(rhs: BoxedExpression): boolean;
35
- match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
36
- /** Mathematical equality */
37
- isEqual(rhs: BoxedExpression): boolean;
38
- evaluate(_options?: EvaluateOptions): BoxedExpression;
39
- get isCanonical(): boolean;
40
- set isCanonical(val: boolean);
41
- get canonical(): BoxedExpression;
42
- simplify(_options?: SimplifyOptions): BoxedExpression;
43
- N(_options?: NOptions): BoxedExpression;
44
- replace(rules: BoxedRuleSet | Rule | Rule[], options?: ReplaceOptions): null | BoxedExpression;
45
- subs(sub: Substitution, options?: {
46
- canonical?: CanonicalOptions;
47
- }): BoxedExpression;
48
- }
@@ -1,40 +0,0 @@
1
- /* 0.25.1 */
2
- import Decimal from 'decimal.js';
3
- import { Expression } from '../../math-json/math-json-format';
4
- import { BoxedDomain, BoxedSubstitution, DomainCompatibility, DomainConstructor, DomainExpression, DomainLiteral, IComputeEngine, Metadata, PatternMatchOptions } from '../public';
5
- import { _BoxedExpression } from './abstract-boxed-expression';
6
- import { BoxedExpression, SemiBoxedExpression } from './public';
7
- /**
8
- * A `_BoxedDomain` is a wrapper around a boxed, canonical, domain
9
- * expression.
10
- *
11
- * It could be an invalid domain, in which case `isValid` is `false`.
12
- *
13
- * @noInheritDoc
14
- */
15
- export declare class _BoxedDomain extends _BoxedExpression implements BoxedDomain {
16
- private _hash;
17
- readonly base: DomainLiteral;
18
- readonly ctor: DomainConstructor | null;
19
- readonly params: DomainExpression<Expression>[];
20
- constructor(ce: IComputeEngine, dom: DomainExpression, metadata?: Metadata);
21
- /** Boxed domains are always canonical. */
22
- get isCanonical(): boolean;
23
- get canonical(): _BoxedDomain;
24
- get isValid(): boolean;
25
- get json(): Expression;
26
- get hash(): number;
27
- isCompatible(dom: BoxedDomain | DomainLiteral, compatibility?: DomainCompatibility): boolean;
28
- isEqual(rhs: BoxedExpression): boolean;
29
- isSame(rhs: BoxedExpression): boolean;
30
- match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
31
- get head(): string;
32
- get domain(): BoxedDomain;
33
- get isFunction(): boolean;
34
- get isNumeric(): boolean;
35
- }
36
- /** Validate that `expr` is a Domain */
37
- export declare function isDomain(expr: Expression | BoxedExpression | BoxedDomain | DomainExpression): expr is BoxedDomain | DomainExpression;
38
- /** Return the ancestor domain (Least Upper Bound) that is shared by both `a` and `b` */
39
- export declare function widen(a: BoxedDomain | undefined | null, b: BoxedDomain | undefined | null): BoxedDomain | undefined;
40
- export declare function narrow(a: BoxedDomain | undefined, b: BoxedDomain | undefined): BoxedDomain;
@@ -1,56 +0,0 @@
1
- /* 0.25.1 */
2
- *
3
- * ## THEORY OF OPERATIONS
4
- *
5
- * In order to preserve exact results, some numeric operations are performed
6
- * on "coefficients" which represent a product of a rational number,
7
- * an algebraic numbers and the square root of an integer.
8
- *
9
- * A field is defined on these coefficients.
10
- *
11
- *
12
- */
13
- import { Rational } from '../numerics/rationals';
14
- import { BoxedExpression } from './public';
15
- export interface CoefficientData {
16
- float: number;
17
- rational: Rational;
18
- sqrt: number;
19
- }
20
- export declare class Coefficient implements CoefficientData {
21
- static zero: Coefficient;
22
- static one: Coefficient;
23
- /**
24
- * Attempt to factor a numeric coefficient `c` and a `rest` out of a
25
- * canonical expression `expr` such that `ce.mul(c, rest)` is equal to `expr`.
26
- *
27
- * Attempts to make `rest` a positive value (i.e. pulls out negative sign).
28
- *
29
- * For example:
30
- *
31
- * ['Multiply', 2, 'x', 3, 'a']
32
- * -> [6, ['Multiply', 'x', 'a']]
33
- *
34
- * ['Divide', ['Multiply', 2, 'x'], ['Multiply', 3, 'y', 'a']]
35
- * -> [['Rational', 2, 3], ['Divide', 'x', ['Multiply, 'y', 'a']]]
36
- */
37
- static fromExpression(expr: BoxedExpression): [coef: Coefficient, rest: BoxedExpression];
38
- float: number;
39
- rational: Rational;
40
- sqrt: number;
41
- constructor(value?: number | Partial<CoefficientData>);
42
- asFloat(): number;
43
- asRational(): Rational;
44
- normalize(): void;
45
- get isZero(): boolean;
46
- get isOne(): boolean;
47
- get sign(): number;
48
- neg(): Coefficient;
49
- inv(): Coefficient;
50
- mul(other: Partial<CoefficientData> | number | Rational): Coefficient;
51
- pow(exponent: number): Coefficient;
52
- div(other: Partial<CoefficientData> | number | Rational): Coefficient;
53
- add(other: Partial<CoefficientData> | number | Rational): Coefficient;
54
- sub(other: Partial<CoefficientData> | number | Rational): Coefficient;
55
- eq(other: Coefficient): boolean;
56
- }
@@ -1,19 +0,0 @@
1
- /* 0.25.1 */
2
- import { Decimal } from 'decimal.js';
3
- import { Rational } from './numerics/rationals';
4
- import type { BoxedDomain, BoxedFunctionSignature, DomainLiteral, FunctionSignature, IComputeEngine } from './public';
5
- /**
6
- * Determine the numeric domain of a number.
7
- */
8
- export declare function inferNumericDomain(value: number | Decimal | Complex | Rational): DomainLiteral;
9
- /**
10
- * Extract the parts of a function domain.
11
- */
12
- export declare function functionDomain(dom: BoxedDomain): [
13
- params: BoxedDomain[],
14
- optParams: BoxedDomain[],
15
- restParam: BoxedDomain | undefined,
16
- result: BoxedDomain
17
- ];
18
- export declare function domainToSignature(dom: BoxedDomain): Partial<FunctionSignature>;
19
- export declare function signatureToDomain(ce: IComputeEngine, sig: BoxedFunctionSignature): BoxedDomain;
@@ -1,21 +0,0 @@
1
- /* 0.25.1 */
2
- /** The canonical form of `Add`:
3
- * - removes `0`
4
- * - capture complex numbers (a + ib or ai +b)
5
- * */
6
- export declare function canonicalAdd(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
7
- export declare function domainAdd(_ce: IComputeEngine, args: (undefined | BoxedDomain)[]): BoxedDomain | null | undefined;
8
- export declare function simplifyAdd(ce: IComputeEngine, args: ReadonlyArray<BoxedExpression>): BoxedExpression;
9
- export declare function evalAdd(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>, mode?: 'N' | 'evaluate'): BoxedExpression;
10
- export declare function canonicalSummation(ce: IComputeEngine, body: BoxedExpression, indexingSet: BoxedExpression | undefined): BoxedExpression | null;
11
- export declare function evalSummation(ce: IComputeEngine, summationEquation: ReadonlyArray<BoxedExpression>, mode: 'simplify' | 'N' | 'evaluate'): BoxedExpression | undefined;
12
- /**
13
- * Return a multiple of the imaginary unit, e.g.
14
- * - 'ImaginaryUnit' -> 1
15
- * - ['Negate', 'ImaginaryUnit'] -> -1
16
- * - ['Negate', ['Multiply', 3, 'ImaginaryUnit']] -> -3
17
- * - ['Multiply', 5, 'ImaginaryUnit'] -> 5
18
- * - ['Multiply', 'ImaginaryUnit', 5] -> 5
19
- * - ['Divide', 'ImaginaryUnit', 2] -> 0.5
20
- */
21
- export declare function getImaginaryCoef(expr: BoxedExpression): number;
@@ -1,16 +0,0 @@
1
- /* 0.25.1 */
2
- /**
3
- * Canonical form of 'Divide' (and 'Rational')
4
- * - remove denominator of 1
5
- * - simplify the signs
6
- * - factor out negate (make the numerator and denominator positive)
7
- * - if numerator and denominator are integer literals, return a rational number
8
- * or Rational experssion
9
- */
10
- export declare function canonicalDivide(ce: IComputeEngine, op1: BoxedExpression, op2: BoxedExpression): BoxedExpression;
11
- /**
12
- * Simplify form of 'Divide' (and 'Rational')
13
- */
14
- export declare function simplifyDivide(ce: IComputeEngine, op1: BoxedExpression, op2: BoxedExpression): BoxedExpression | undefined;
15
- export declare function evalDivide(ce: IComputeEngine, op1: BoxedExpression, op2: BoxedExpression): BoxedExpression;
16
- export declare function evalNDivide(ce: IComputeEngine, op1: BoxedExpression, op2: BoxedExpression): BoxedExpression;
@@ -1,16 +0,0 @@
1
- /* 0.25.1 */
2
- /** The canonical form of `Multiply`:
3
- * - remove `1`
4
- * - simplify the signs:
5
- * - i.e. `-y \times -x` -> `x \times y`
6
- * - `2 \times -x` -> `-2 \times x`
7
- * - arguments are sorted
8
- * - complex numbers promoted (['Multiply', 2, 'ImaginaryUnit'] -> 2i)
9
- *
10
- * The ops must be canonical, the result is canonical.
11
- */
12
- export declare function canonicalMultiply(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
13
- export declare function simplifyMultiply(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
14
- export declare function evalMultiply(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>, mode?: 'N' | 'evaluate'): BoxedExpression;
15
- export declare function canonicalProduct(ce: IComputeEngine, body: BoxedExpression | undefined, indexingSet: BoxedExpression | undefined): BoxedExpression | null;
16
- export declare function evalMultiplication(ce: IComputeEngine, summationEquation: ReadonlyArray<BoxedExpression>, mode: 'simplify' | 'N' | 'evaluate'): BoxedExpression | undefined;
@@ -1,11 +0,0 @@
1
- /* 0.25.1 */
2
- import { BoxedExpression, IComputeEngine, Metadata } from '../public';
3
- /**
4
- *
5
- */
6
- export declare function canonicalPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, metadata?: Metadata): BoxedExpression;
7
- export declare function square(ce: IComputeEngine, base: BoxedExpression): BoxedExpression;
8
- export declare function processPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
9
- export declare function processSqrt(ce: IComputeEngine, base: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
10
- export declare function isSqrt(expr: BoxedExpression): boolean;
11
- export declare function asRationalSqrt(expr: BoxedExpression): Rational | null;
@@ -1,16 +0,0 @@
1
- /* 0.25.1 */
2
- export declare const DOMAIN_CONSTRUCTORS: string[];
3
- export declare const DOMAIN_ALIAS: {
4
- Functions: (string | string[])[];
5
- NumericFunctions: (string | string[])[];
6
- RealFunctions: (string | string[])[];
7
- LogicOperators: (string | string[])[];
8
- Predicates: (string | string[])[];
9
- RelationalOperators: string[];
10
- };
11
- export declare function isDomainLiteral(s: string | null): s is DomainLiteral;
12
- export declare function isSubdomainLiteral(lhs: string, rhs: string): boolean;
13
- /** Return all the domain literals that are an ancestor of `dom`
14
- */
15
- export declare function ancestors(dom: DomainLiteral): DomainLiteral[];
16
- export declare function domainSetsLibrary(): IdentifierDefinitions;
@@ -1,17 +0,0 @@
1
- /* 0.25.1 */
2
- import { Rational } from './rationals';
3
- export declare class Terms {
4
- private engine;
5
- private terms;
6
- constructor(ce: IComputeEngine, terms: ReadonlyArray<BoxedExpression>);
7
- sub(term: BoxedExpression): void;
8
- add(term2: BoxedExpression, coef2?: Rational): void;
9
- find(term: BoxedExpression): number;
10
- /** If `exact` is true, keep exact numbers */
11
- reduceNumbers({ exact }: {
12
- exact: boolean;
13
- }): void;
14
- asExpression(options: {
15
- exact: boolean;
16
- }): BoxedExpression;
17
- }
@@ -1,20 +0,0 @@
1
- /* 0.25.1 */
2
- /**
3
- * For each rules in the rule set that match, return the `replace` of the rule
4
- *
5
- * @param rules
6
- */
7
- export declare function matchRules(expr: BoxedExpression, rules: BoxedRuleSet, sub: BoxedSubstitution): BoxedExpression[];
8
- /**
9
- * Create a boxed rule set from a non-boxed rule set
10
- * @param ce
11
- * @param rs
12
- * @returns
13
- */
14
- export declare function boxRules(ce: IComputeEngine, rs: Iterable<Rule>): BoxedRuleSet;
15
- /**
16
- * Apply the rules in the ruleset and return a modified expression.
17
- *
18
- * If no rule applied, return `null`.
19
- */
20
- export declare function replace(expr: BoxedExpression, ruleSet: BoxedRuleSet | Rule | Rule[], options?: ReplaceOptions): BoxedExpression | null;
@@ -1,23 +0,0 @@
1
- /* 0.25.1 */
2
- export declare function distribute(expr: ReadonlyArray<BoxedExpression>): BoxedExpression;
3
- /** Use the multinomial theorem (https://en.wikipedia.org/wiki/Multinomial_theorem) to expand the expression.
4
- * The expression must be a power of a sum of terms.
5
- * The power must be a positive integer.
6
- * - expr = '(a + b)^2'
7
- * -> 'a^2 + 2ab + b^2'
8
- * - expr = '(a + b)^3'
9
- * -> 'a^3 + 3a^2b + 3ab^2 + b^3'
10
- */
11
- export declare function expandMultinomial(expr: BoxedExpression): BoxedExpression | null;
12
- /** Expand all
13
- * Recursive expand of all terms in the expression
14
- */
15
- export declare function expandAll(expr: BoxedExpression): BoxedExpression | null;
16
- /** Apply the distributive law if the expression is a product of sums.
17
- * For example, a(b + c) = ab + ac
18
- * Expand the expression if it is a power of a sum.
19
- * Expand the terms of the expression if it is a sum or negate.
20
- * If the expression is a fraction, expand the numerator.
21
- * Return null if the expression cannot be expanded.
22
- */
23
- export declare function expand(expr: BoxedExpression | undefined): BoxedExpression | null;
@@ -1,9 +0,0 @@
1
- /* 0.25.1 */
2
- /**
3
- * Flatten the arguments.
4
- */
5
- export declare function flattenOps(ops: ReadonlyArray<BoxedExpression>, head: string): ReadonlyArray<BoxedExpression>;
6
- /**
7
- * @todo: this function should probably not be recursive. As it, it is semi-recursive.
8
- */
9
- export declare function flattenSequence(xs: ReadonlyArray<BoxedExpression>): ReadonlyArray<BoxedExpression>;
@@ -1,22 +0,0 @@
1
- /* 0.25.1 */
2
- import { Decimal } from 'decimal.js';
3
- import { Rational } from '../numerics/rationals';
4
- import { BoxedExpression, Hold, IComputeEngine, SemiBoxedExpression } from '../public';
5
- /**
6
- * Return a rational coef and constant such that `coef * mod + constant = expr`
7
- */
8
- /**
9
- * Return a coef, term and constant such that:
10
- *
11
- * `coef * term + constant = expr`
12
- *
13
- * Return null if no `coef`/`constant` can be found.
14
- */
15
- export declare function makePositive(expr: BoxedExpression): [sign: number, expr: BoxedExpression];
16
- export declare function apply(expr: BoxedExpression, fn: (x: number) => number | Complex, bigFn?: (x: Decimal) => Decimal | Complex | number, complexFn?: (x: Complex) => number | Complex): number | Decimal | Complex;
17
- export declare function applyN(expr: BoxedExpression, fn: (x: number) => number | Complex, bigFn?: (x: Decimal) => Decimal | Complex | number, complexFn?: (x: Complex) => number | Complex): BoxedExpression | undefined;
18
- export declare function apply2(expr1: BoxedExpression, expr2: BoxedExpression, fn: (x1: number, x2: number) => number | Complex | Rational, bigFn?: (x1: Decimal, x2: Decimal) => Decimal | Complex | Rational | number, complexFn?: (x1: Complex, x2: number | Complex) => Complex | number): number | Decimal | Complex | Rational;
19
- export declare function apply2N(expr1: BoxedExpression, expr2: BoxedExpression, fn: (x1: number, x2: number) => number | Complex | Rational, bigFn?: (x1: Decimal, x2: Decimal) => Decimal | Complex | number | Rational, complexFn?: (x1: Complex, x2: number | Complex) => Complex | number): BoxedExpression | undefined;
20
- export declare function shouldHold(skip: Hold, count: number, index: number): boolean;
21
- export declare function semiCanonical(ce: IComputeEngine, xs: ReadonlyArray<SemiBoxedExpression>): ReadonlyArray<BoxedExpression>;
22
- export declare function canonical(xs: ReadonlyArray<BoxedExpression>): ReadonlyArray<BoxedExpression>;