@cortex-js/compute-engine 0.10.0 → 0.12.0

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 (86) hide show
  1. package/dist/compute-engine.esm.js +4720 -4832
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +2 -2
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +9 -9
  9. package/dist/types/common/utils.d.ts +1 -1
  10. package/dist/types/compute-engine/assume.d.ts +1 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -2
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +2 -2
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -2
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +32 -38
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -2
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +2 -2
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +8 -3
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +4 -3
  27. package/dist/types/compute-engine/compute-engine.d.ts +26 -46
  28. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  29. package/dist/types/compute-engine/domain-utils.d.ts +4 -4
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +11 -11
  41. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/public.d.ts +31 -31
  44. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -2
  45. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -2
  48. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  49. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  51. package/dist/types/compute-engine/library/arithmetic-power.d.ts +2 -4
  52. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
  53. package/dist/types/compute-engine/library/calculus.d.ts +2 -2
  54. package/dist/types/compute-engine/library/collections.d.ts +2 -2
  55. package/dist/types/compute-engine/library/core.d.ts +2 -2
  56. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  57. package/dist/types/compute-engine/library/library.d.ts +5 -5
  58. package/dist/types/compute-engine/library/logic.d.ts +2 -2
  59. package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
  60. package/dist/types/compute-engine/library/random-expression.d.ts +2 -0
  61. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
  62. package/dist/types/compute-engine/library/sets.d.ts +2 -2
  63. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
  64. package/dist/types/compute-engine/library/utils.d.ts +3 -0
  65. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +12 -0
  66. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -9
  67. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  68. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  69. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  70. package/dist/types/compute-engine/numerics/rationals.d.ts +10 -12
  71. package/dist/types/compute-engine/public.d.ts +111 -116
  72. package/dist/types/compute-engine/rules.d.ts +1 -1
  73. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  74. package/dist/types/compute-engine/solve.d.ts +1 -1
  75. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  76. package/dist/types/compute-engine/symbolic/flatten.d.ts +3 -2
  77. package/dist/types/compute-engine/symbolic/negate.d.ts +4 -6
  78. package/dist/types/compute-engine/symbolic/polynomials.d.ts +3 -3
  79. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  80. package/dist/types/compute-engine/symbolic/sum.d.ts +3 -2
  81. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  82. package/dist/types/compute-engine.d.ts +2 -3
  83. package/dist/types/math-json/math-json-format.d.ts +7 -7
  84. package/dist/types/math-json/utils.d.ts +2 -1
  85. package/dist/types/math-json.d.ts +2 -3
  86. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  * The most important classes are {@link ComputeEngine} and
3
3
  * {@link BoxedExpression}.
4
4
  *
@@ -9,15 +9,14 @@
9
9
  */
10
10
  import type { Decimal } from 'decimal.js';
11
11
  import type { Complex } from 'complex.js';
12
- import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../common/signals';
13
12
  import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
14
13
  import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
15
14
  export * from './latex-syntax/public';
16
- export declare type Rational = [number, number] | [Decimal, Decimal];
15
+ export type Rational = [number, number] | [bigint, bigint];
17
16
  /**
18
17
  * Metadata that can be associated with a `BoxedExpression`
19
18
  */
20
- export declare type Metadata = {
19
+ export type Metadata = {
21
20
  latex?: string | undefined;
22
21
  wikidata?: string | undefined;
23
22
  };
@@ -35,9 +34,9 @@ export declare type Metadata = {
35
34
 
36
35
  </div>
37
36
  */
38
- export declare type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
37
+ export type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
39
38
  /** Options for `BoxedExpression.simplify()` */
40
- export declare type SimplifyOptions = EvaluateOptions & {
39
+ export type SimplifyOptions = EvaluateOptions & {
41
40
  recursive?: boolean;
42
41
  rules?: BoxedRuleSet;
43
42
  };
@@ -45,12 +44,12 @@ export declare type SimplifyOptions = EvaluateOptions & {
45
44
  *
46
45
  * @internal
47
46
  */
48
- export declare type EvaluateOptions = {};
47
+ export type EvaluateOptions = {};
49
48
  /** Options for `BoxedExpression.N()`
50
49
  * @internal
51
50
  */
52
- export declare type NOptions = {};
53
- export declare type ReplaceOptions = {
51
+ export type NOptions = {};
52
+ export type ReplaceOptions = {
54
53
  /** If `true`, apply replacement rules to all sub-expressions.
55
54
  * If `false`, only consider the top-level expression.
56
55
  *
@@ -82,16 +81,14 @@ export declare type ReplaceOptions = {
82
81
  * A substitution can also be considered a more constrained version of a
83
82
  * rule whose `lhs` is always a symbol.
84
83
  */
85
- export declare type Substitution = {
86
- [symbol: string]: SemiBoxedExpression;
87
- };
88
- export declare type BoxedSubstitution = {
89
- [symbol: string]: BoxedExpression;
84
+ export type Substitution<T = SemiBoxedExpression> = {
85
+ [symbol: string]: T;
90
86
  };
87
+ export type BoxedSubstitution = Substitution<BoxedExpression>;
91
88
  /** A LaTeX string starts and end with `$`, for example
92
89
  * `"$\frac{\pi}{2}$"`.
93
90
  */
94
- export declare type LatexString = string;
91
+ export type LatexString = string;
95
92
  /**
96
93
  * A rule describes how to modify an expressions that matches a `lhs` pattern
97
94
  * into a new expressions matching `rhs`.
@@ -112,7 +109,7 @@ export declare type LatexString = string;
112
109
  * - `__1` (`__a`, etc..) match a sequence of one or more expressions
113
110
  * - `___1` (`___a`, etc...) match a sequence of zero or more expressions
114
111
  */
115
- export declare type Rule = [
112
+ export type Rule = [
116
113
  lhs: LatexString | SemiBoxedExpression | Pattern,
117
114
  rhs: LatexString | SemiBoxedExpression,
118
115
  options?: {
@@ -120,18 +117,18 @@ export declare type Rule = [
120
117
  priority?: number;
121
118
  }
122
119
  ];
123
- export declare type BoxedRule = [
120
+ export type BoxedRule = [
124
121
  lhs: Pattern,
125
122
  rhs: BoxedExpression,
126
123
  priority: number,
127
124
  condition: undefined | ((wildcards: BoxedSubstitution) => boolean)
128
125
  ];
129
- export declare type BoxedRuleSet = Set<BoxedRule>;
130
- export declare type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
126
+ export type BoxedRuleSet = Set<BoxedRule>;
127
+ export type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
131
128
  /** A domain constructor is the head of a domain expression. */
132
- export declare type DomainConstructor = 'Error' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
133
- export declare type DomainLiteral = string;
134
- export declare type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['Error', T] | ['Error', T, T] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['Matrix', DomainExpression<T>, T, T] | ['SquareMatrix', DomainExpression<T>, T] | ['Vector', DomainExpression<T>, T] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Range'] | ['Range', T] | ['Range', T, T] | ['Range', T, T, T] | ['Interval', T, T] | ['Interval', ['Open', T], T] | ['Interval', T, ['Open', T]] | ['Interval', ['Open', T], ['Open', T]] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Function', ...DomainExpression<T>[]];
129
+ export type DomainConstructor = 'Error' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
130
+ export type DomainLiteral = string;
131
+ export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['Error', T] | ['Error', T, T] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['Matrix', DomainExpression<T>, T, T] | ['SquareMatrix', DomainExpression<T>, T] | ['Vector', DomainExpression<T>, T] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Range'] | ['Range', T] | ['Range', T, T] | ['Range', T, T, T] | ['Interval', T, T] | ['Interval', ['Open', T], T] | ['Interval', T, ['Open', T]] | ['Interval', ['Open', T], ['Open', T]] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Function', ...DomainExpression<T>[]];
135
132
  export interface BoxedDomain extends BoxedExpression {
136
133
  is(s: BoxedDomain): boolean;
137
134
  /** True if a valid domain, and compatible with `dom` */
@@ -176,7 +173,7 @@ export interface BoxedDomain extends BoxedExpression {
176
173
  /**
177
174
  * Options to control the serialization to MathJSON when using `BoxedExpression.json`.
178
175
  */
179
- export declare type JsonSerializationOptions = {
176
+ export type JsonSerializationOptions = {
180
177
  /** A list of space separated function names that should be excluded from
181
178
  * the JSON output.
182
179
  *
@@ -352,7 +349,12 @@ export interface BoxedExpression {
352
349
  * **Note** applicable to canonical and non-canonical expressions.
353
350
  *
354
351
  */
355
- readonly symbols: BoxedExpression[];
352
+ readonly symbols: string[];
353
+ /**
354
+ * All the free variables in the expression, recursively,
355
+ * that is all the symbols with no value
356
+ */
357
+ readonly freeVars: string[];
356
358
  /** All the `["Error"]` subexpressions
357
359
  *
358
360
  * **Note** applicable to canonical and non-canonical expressions.
@@ -987,8 +989,8 @@ export interface BoxedExpression {
987
989
  * This is convenient when creating new expressions from portions
988
990
  * of an existing `BoxedExpression` while avoiding unboxing and reboxing.
989
991
  */
990
- export declare type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
991
- export declare type PatternMatchOptions = {
992
+ export type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
993
+ export type PatternMatchOptions = {
992
994
  substitution?: BoxedSubstitution;
993
995
  recursive?: boolean;
994
996
  numericTolerance?: number;
@@ -1009,27 +1011,31 @@ export interface ExpressionMapInterface<U> {
1009
1011
  [Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
1010
1012
  }
1011
1013
  /**
1012
- * A symbol table contains definitions for symbols, functions and rules.
1014
+ * An ID table contains definitions for symbols and functions.
1015
+ *
1016
+ * The index of the table is an identifier, the name of the symbol or
1017
+ * function for this definition
1018
+ *
1019
+ * The name of a symbol or function is an arbitrary string of Unicode
1020
+ * characters, however the following conventions are recommended:
1021
+ *
1022
+ * - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
1023
+ * - The first character should be a letter: `/^[a-zA-Z]/`
1024
+ * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
1013
1025
  *
1014
1026
  */
1015
- export declare type SymbolTable = {
1016
- symbols?: SymbolDefinition[];
1017
- functions?: FunctionDefinition[];
1018
- simplifyRules?: BoxedRuleSet;
1027
+ export type IdTable = {
1028
+ [id: string]: SymbolDefinition | FunctionDefinition;
1019
1029
  };
1020
1030
  /**
1021
- * The entries of a `RuntimeSymbolTable` have been validated and
1031
+ * The entries of a `RuntimeIdentifierTable` have been validated and
1022
1032
  * optimized for faster evaluation.
1023
1033
  *
1024
1034
  * When a new scope is created with `pushScope()` or when creating a new
1025
- * engine instance, new instances of `RuntimeDictionary` are created as needed.
1035
+ * engine instance, new instances of `RuntimeIdentifierTable` are created
1036
+ * as needed.
1026
1037
  */
1027
- export declare type RuntimeSymbolTable = {
1028
- symbols: Map<string, BoxedSymbolDefinition>;
1029
- symbolWikidata: Map<string, BoxedSymbolDefinition>;
1030
- functions: Map<string, BoxedFunctionDefinition>;
1031
- functionWikidata: Map<string, BoxedFunctionDefinition>;
1032
- };
1038
+ export type RuntimeIdentifierTable = Map<string, BoxedSymbolDefinition | BoxedFunctionDefinition>;
1033
1039
  /**
1034
1040
  * A scope is a set of names in a dictionary that are bound (defined) in
1035
1041
  * a MathJSON expression.
@@ -1045,38 +1051,35 @@ export declare type RuntimeSymbolTable = {
1045
1051
  * where they are in an expression, they are not determined at runtime.
1046
1052
  *
1047
1053
  */
1048
- export declare type Scope = {
1049
- /** This handler is invoked when exiting this scope if there are any
1050
- * warnings pending. */
1051
- warn?: WarningSignalHandler;
1054
+ export type Scope = {
1052
1055
  /** Signal `timeout` when the execution time for this scope is exceeded.
1053
1056
  * Time in seconds, default 2s.
1054
1057
  *
1055
1058
  * @experimental
1056
1059
  */
1057
- timeLimit?: number;
1060
+ timeLimit: number;
1058
1061
  /** Signal `out-of-memory` when the memory usage for this scope is exceeded.
1059
1062
  * Memory in Megabytes, default: 1Mb.
1060
1063
  *
1061
1064
  * @experimental
1062
1065
  */
1063
- memoryLimit?: number;
1066
+ memoryLimit: number;
1064
1067
  /** Signal `recursion-depth-exceeded` when the recursion depth for this
1065
1068
  * scope is exceeded.
1066
1069
  *
1067
1070
  * @experimental
1068
1071
  */
1069
- recursionLimit?: number;
1072
+ recursionLimit: number;
1070
1073
  /** Signal `iteration-limit-exceeded` when the iteration limit for this
1071
1074
  * scope is exceeded. Default: no limits.
1072
1075
  *
1073
1076
  * @experimental
1074
1077
  */
1075
- iterationLimit?: number;
1078
+ iterationLimit: number;
1076
1079
  };
1077
- export declare type RuntimeScope = Scope & {
1080
+ export type RuntimeScope = Scope & {
1078
1081
  parentScope?: RuntimeScope;
1079
- symbolTable?: RuntimeSymbolTable;
1082
+ idTable?: RuntimeIdentifierTable;
1080
1083
  assumptions: undefined | ExpressionMapInterface<boolean>;
1081
1084
  /** The location of the call site that created this scope */
1082
1085
  origin?: {
@@ -1086,21 +1089,8 @@ export declare type RuntimeScope = Scope & {
1086
1089
  };
1087
1090
  /** Free memory should not go below this level for execution to proceed */
1088
1091
  lowWaterMark?: number;
1089
- /** Set when one or more warnings have been signaled in this scope */
1090
- warnings?: WarningSignal[];
1091
1092
  };
1092
- export declare type BaseDefinition = {
1093
- /** The name of the symbol or function for this definition
1094
- *
1095
- * The name of a symbol or function is an arbitrary string of Unicode
1096
- * characters, however the following conventions are recommended:
1097
- *
1098
- * - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
1099
- * - The first character should be a letter: `/^[a-zA-Z]/`
1100
- * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
1101
- *
1102
- */
1103
- name: string;
1093
+ export type BaseDefinition = {
1104
1094
  /** A short (about 1 line) description. May contain Markdown. */
1105
1095
  description?: string | string[];
1106
1096
  /** A URL pointing to more information about this symbol or head. */
@@ -1133,7 +1123,7 @@ export interface BoxedBaseDefinition {
1133
1123
  * A function definition can have some flags to indicate specific
1134
1124
  * properties of the function.
1135
1125
  */
1136
- export declare type FunctionDefinitionFlags = {
1126
+ export type FunctionDefinitionFlags = {
1137
1127
  /** If `true`, the function is applied element by element to lists, matrices
1138
1128
  * (`["List"]` or `["Tuple"]` expressions) and equations (relational
1139
1129
  * operators).
@@ -1220,7 +1210,7 @@ export declare type FunctionDefinitionFlags = {
1220
1210
  /**
1221
1211
  *
1222
1212
  */
1223
- export declare type FunctionSignature = {
1213
+ export type FunctionSignature = {
1224
1214
  /** The domain of this signature, a domain compatible with the `Function`
1225
1215
  * domain) */
1226
1216
  domain?: BoxedDomain | DomainExpression;
@@ -1250,7 +1240,10 @@ export declare type FunctionSignature = {
1250
1240
  * arguments should be sorted in canonical order.
1251
1241
  *
1252
1242
  * The handler can make transformations based on the value of the arguments
1253
- * that are exact (i.e. `arg.isExact`).
1243
+ * that are exact and literal
1244
+ * (i.e. `arg.numericValue !== null && arg.isExact`).
1245
+ *
1246
+ * Values of symbols should not be substituted.
1254
1247
  *
1255
1248
  * The handler should not consider the value or any assumptions about any
1256
1249
  * of the arguments that are symbols or functions (i.e. `arg.isZero`,
@@ -1364,7 +1357,7 @@ export declare type FunctionSignature = {
1364
1357
  /** Return a compiled (optimized) expression. */
1365
1358
  compile?: (expr: BoxedExpression) => CompiledExpression;
1366
1359
  };
1367
- export declare type BoxedFunctionSignature = {
1360
+ export type BoxedFunctionSignature = {
1368
1361
  domain: BoxedDomain;
1369
1362
  codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null);
1370
1363
  canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
@@ -1379,7 +1372,7 @@ export declare type BoxedFunctionSignature = {
1379
1372
  * Definition record for a function.
1380
1373
  *
1381
1374
  */
1382
- export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
1375
+ export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
1383
1376
  /**
1384
1377
  * A number used to order arguments.
1385
1378
  *
@@ -1414,7 +1407,7 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
1414
1407
  hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1415
1408
  signature?: FunctionSignature;
1416
1409
  };
1417
- export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
1410
+ export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
1418
1411
  complexity: number;
1419
1412
  hold: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1420
1413
  signature: BoxedFunctionSignature;
@@ -1428,7 +1421,7 @@ export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefi
1428
1421
  * For example, it might be useful to override `algebraic = false`
1429
1422
  * for a transcendental number.
1430
1423
  */
1431
- export declare type SymbolFlags = {
1424
+ export type SymbolFlags = {
1432
1425
  number: boolean | undefined;
1433
1426
  integer: boolean | undefined;
1434
1427
  rational: boolean | undefined;
@@ -1454,42 +1447,61 @@ export declare type SymbolFlags = {
1454
1447
  prime: boolean | undefined;
1455
1448
  composite: boolean | undefined;
1456
1449
  };
1457
- export declare type SymbolDefinitionFlags = {
1450
+ export type SymbolAttributes = {
1458
1451
  /**
1459
- * If true the value of the symbol is constant.
1452
+ * If `true` the value of the symbol is constant. The value or domain of
1453
+ * symbols with this attribute set to `true` cannot be changed.
1460
1454
  *
1461
- * If false, the symbol is a variable.
1455
+ * If `false`, the symbol is a variable.
1456
+ *
1457
+ * **Default**: `false`
1462
1458
  */
1463
1459
  constant: boolean;
1464
1460
  /**
1465
- * If `false`, the value of the symbol is substituted during canonicalization
1466
- * or simplification.
1467
- *
1468
- * If true, the value is only replaced during a `ce.N()` or `ce.evaluate()`.
1469
- *
1470
- * **Default:** `true`
1471
- */
1472
- hold: boolean;
1461
+ * If the symbol has a value, it is held as indicated in the table below.
1462
+ * A green checkmark indicate that the symbol is substituted.
1463
+
1464
+ <div class=symbols-table>
1465
+
1466
+ | Operation | `"never"` | `"simplify"` | `"evaluate"` | `"N"` |
1467
+ | :--- | :----- |
1468
+ | `canonical()`| (X) | | | |
1469
+ | `simplify()` | (X) | (X) | | |
1470
+ | `evaluate()` | (X) | (X) | (X) | |
1471
+ | `"N()"` | (X) | (X) | (X) | (X) |
1472
+
1473
+ </div>
1474
+
1475
+ * Some examples:
1476
+ * - `i` has `holdUntil: 'never'`
1477
+ * - `GoldenRatio` has `holdUntil: 'simplify'` (symbolic constant)
1478
+ * - `x` has `holdUntil: 'evaluate'` (variables)
1479
+ * - `Pi` has `holdUntil: 'N'` (special numeric constant)
1480
+ *
1481
+ * **Default:** `simplify`
1482
+ */
1483
+ holdUntil: 'never' | 'simplify' | 'evaluate' | 'N';
1473
1484
  };
1474
1485
  /**
1475
1486
  * A bound symbol (i.e. one with an associated definition) has either a domain
1476
1487
  * (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumber)
1477
1488
  */
1478
- export declare type SymbolDefinition = BaseDefinition & Partial<SymbolFlags> & Partial<SymbolDefinitionFlags> & {
1489
+ export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
1490
+ domain?: string | BoxedDomain;
1479
1491
  /** `value` can be a function since for some constants, such as
1480
1492
  * `Pi`, the actual value depends on the `precision` setting of the
1481
1493
  * `ComputeEngine` */
1482
1494
  value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
1483
- domain?: string | BoxedDomain;
1495
+ flags?: Partial<SymbolFlags>;
1484
1496
  };
1485
- export interface BoxedSymbolDefinition extends BoxedBaseDefinition, Partial<SymbolFlags>, SymbolDefinitionFlags {
1497
+ export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttributes, Partial<SymbolFlags> {
1486
1498
  get value(): BoxedExpression | undefined;
1487
1499
  set value(val: SemiBoxedExpression | number | undefined);
1488
1500
  domain: BoxedDomain | undefined;
1489
1501
  at?: (index: string | number) => undefined | BoxedExpression;
1490
1502
  }
1491
- export declare type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
1492
- export declare type CompiledExpression = {
1503
+ export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
1504
+ export type CompiledExpression = {
1493
1505
  evaluate?: (scope: {
1494
1506
  [symbol: string]: BoxedExpression;
1495
1507
  }) => number | BoxedExpression;
@@ -1554,7 +1566,7 @@ export interface IComputeEngine {
1554
1566
  chop(n: Complex): Complex | 0;
1555
1567
  chop(n: number | Decimal | Complex): number | Decimal | Complex;
1556
1568
  /** @internal */
1557
- bignum: (a: Decimal.Value) => Decimal;
1569
+ bignum: (a: Decimal.Value | bigint) => Decimal;
1558
1570
  /** @internal */
1559
1571
  complex: (a: number | Complex, b?: number) => Complex;
1560
1572
  set precision(p: number | 'machine');
@@ -1573,13 +1585,13 @@ export interface IComputeEngine {
1573
1585
  *
1574
1586
  * If a definition existed previously, it is replaced.
1575
1587
  */
1576
- defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
1588
+ defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
1577
1589
  /**
1578
1590
  * Associate a new definition to a function in the current context.
1579
1591
  *
1580
1592
  * If a definition existed previously, it is replaced.
1581
1593
  */
1582
- defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
1594
+ defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
1583
1595
  lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
1584
1596
  /** Return `undefined` if no definition exist for this `head` */
1585
1597
  lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
@@ -1589,8 +1601,9 @@ export interface IComputeEngine {
1589
1601
  box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
1590
1602
  canonical?: boolean;
1591
1603
  }): BoxedExpression;
1604
+ canonical(xs: SemiBoxedExpression[]): BoxedExpression[];
1592
1605
  /** Return a boxed number */
1593
- number(value: number | string | MathJsonNumber | Decimal | Complex | [num: number, denom: number] | [num: Decimal, denom: Decimal], options?: {
1606
+ number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
1594
1607
  metadata?: Metadata;
1595
1608
  canonical?: boolean;
1596
1609
  }): BoxedExpression;
@@ -1652,23 +1665,23 @@ export interface IComputeEngine {
1652
1665
  *
1653
1666
  * The result is canonical.
1654
1667
  */
1655
- power(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
1668
+ pow(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
1656
1669
  sqrt(base: BoxedExpression, metadata?: Metadata): any;
1657
1670
  /** Shortcut for `this.fn("Divide", [1, expr])`
1658
1671
  *
1659
1672
  * The result is canonical.
1660
1673
  */
1661
- inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1674
+ inv(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1662
1675
  /** Shortcut for `this.fn("Negate", [expr])`
1663
1676
  *
1664
1677
  * The result is canonical.
1665
1678
  */
1666
- negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1679
+ neg(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1667
1680
  /** Shortcut for `this.fn("Divide", [num, denom])`
1668
1681
  *
1669
1682
  * The result is canonical.
1670
1683
  */
1671
- divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
1684
+ div(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
1672
1685
  /** Shortcut for `this.fn("Pair"...)`
1673
1686
  *
1674
1687
  * The result is canonical.
@@ -1715,20 +1728,12 @@ export interface IComputeEngine {
1715
1728
  /** {@inheritDoc JsonSerializationOptions} */
1716
1729
  get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
1717
1730
  set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
1718
- pushScope(options?: {
1719
- symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
1720
- assumptions?: (LatexString | Expression | BoxedExpression)[];
1721
- scope?: Partial<Scope>;
1722
- }): void;
1731
+ pushScope(identifiers?: Readonly<IdTable> | Readonly<IdTable>[], scope?: Partial<Scope>): void;
1723
1732
  popScope(): void;
1724
1733
  /** Assign a value to an identifier in the current scope. Use `null` to reset the identifier to no value */
1725
- set(identifiers: {
1726
- [identifier: string]: SemiBoxedExpression | null;
1727
- }): void;
1728
- /** Declare identifiers (specify their domain without necessarily assigning them a value in the current scope*/
1729
- let(identifiers: {
1730
- [identifier: string]: SymbolDefinition | FunctionDefinition;
1731
- }): void;
1734
+ set(identifiers: Substitution<SemiBoxedExpression | null | undefined>): void;
1735
+ /** Declare identifiers (specify their domain without necessarily assigning them a value in the current scope) */
1736
+ let(identifiers: IdTable): void;
1732
1737
  /**
1733
1738
  * Add an assumption.
1734
1739
  *
@@ -1751,16 +1756,6 @@ export interface IComputeEngine {
1751
1756
  forget(symbol?: string | string[]): void;
1752
1757
  get assumptions(): ExpressionMapInterface<boolean>;
1753
1758
  ask(pattern: LatexString | SemiBoxedExpression): BoxedSubstitution[];
1754
- /**
1755
- * When `condition` is false, signal.
1756
- *
1757
- * - `condition` - If `true`, do nothing. If `false`, signal.
1758
- *
1759
- * @experimental
1760
- */
1761
- assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): any;
1762
- signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
1763
- signal(sig: WarningSignal): void;
1764
1759
  /** @internal */
1765
1760
  shouldContinueExecution(): boolean;
1766
1761
  /** @internal */
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /**
3
3
  * Go through all the rules in the rule set, and for all the rules that match
4
4
  * return the rhs of the rule applied to `expr`.
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /**
3
3
  * A set of simplification rules.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  export declare const UNIVARIATE_ROOTS: Rule[];
3
3
  /**
4
4
  * Expression is a function of a single variable (`x`) or an Equality
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /**
3
3
  * Return the expansion of ['Multiply', lhs, rhs]
4
4
  * - lhs = 'a + b', rhs = '2'
@@ -1,8 +1,9 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /**
3
3
  * Flatten the arguments.
4
4
  * If `expr` was canonical, the result it canonical.
5
5
  */
6
6
  export declare function flatten(expr: BoxedExpression, head: string): BoxedExpression;
7
- export declare function flattenOps(ops: BoxedExpression[], head: string): BoxedExpression[] | null;
7
+ export declare function flattenOps(ops: BoxedExpression[], head: string): BoxedExpression[];
8
8
  export declare function flattenSequence(xs: BoxedExpression[]): BoxedExpression[];
9
+ export declare function canonical(xs: BoxedExpression[]): BoxedExpression[];
@@ -1,12 +1,10 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /**
3
3
  * Distribute `Negate` (multiply by -1) if expr is a number literal, an
4
- * addition or another `Negate`.
4
+ * addition or multiplication or another `Negate`.
5
5
  *
6
- * This is appropriate to call during a `canonical` chain.
7
- *
8
- * For more thorough distribution (including multiplication), see `distributeNegate`,
9
- * applicable during a `simplify` or `evaluate` chain.
6
+ * It is important to do all these to handle cases like
7
+ * `-3x` -> ["Negate, ["Multiply", 3, "x"]] -> ["Multiply, -3, x]
10
8
  */
11
9
  export declare function canonicalNegate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
12
10
  export declare function processNegate(_ce: IComputeEngine, x: BoxedExpression, _mode?: 'simplify' | 'evaluate' | 'N'): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -12,8 +12,8 @@
12
12
  * If a coefficient does not apply (there are no corresponding term), it is `null`.
13
13
  *
14
14
  */
15
- export declare type UnivariateCoefficients = (null | BoxedExpression)[];
16
- export declare type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
15
+ export type UnivariateCoefficients = (null | BoxedExpression)[];
16
+ export type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
17
17
  /**
18
18
  * Return a list of coefficient of powers of `vars` in `poly`,
19
19
  * starting with power 0.
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /**
3
3
  * Group terms in a product by common term.
4
4
  *
@@ -1,14 +1,15 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  export declare class Sum {
3
3
  private engine;
4
+ private _isCanonical;
4
5
  private _rational;
5
6
  private _imaginary;
6
7
  private _number;
7
8
  private _bignum;
8
9
  private _posInfinityCount;
9
10
  private _negInfinityCount;
11
+ private _naNCount;
10
12
  private _terms;
11
- private _isCanonical;
12
13
  constructor(ce: IComputeEngine, xs?: BoxedExpression[], options?: {
13
14
  canonical?: boolean;
14
15
  });
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { BoxedExpression, Rational } from '../public';
4
4
  /**
@@ -1,4 +1,3 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  export { ComputeEngine } from './compute-engine/compute-engine';
3
- export declare const version = "0.10.0";
4
- export { getVars } from './compute-engine/boxed-expression/utils';
3
+ export declare const version = "0.12.0";
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.12.0 */
2
2
  /** A human readable string to annotate this expression, since JSON does not
3
3
  * allow comments in its encoding */
4
4
  comment?: string;
@@ -78,19 +78,19 @@
78
78
  * - `1.(3)`
79
79
  * - `123456789123456789.123(4567)e999`
80
80
  */
81
- export declare type MathJsonNumber = {
81
+ export type MathJsonNumber = {
82
82
  num: 'NaN' | '-Infinity' | '+Infinity' | string;
83
83
  } & Attributes;
84
- export declare type MathJsonSymbol = {
84
+ export type MathJsonSymbol = {
85
85
  sym: string;
86
86
  } & Attributes;
87
- export declare type MathJsonString = {
87
+ export type MathJsonString = {
88
88
  str: string;
89
89
  } & Attributes;
90
- export declare type MathJsonFunction = {
90
+ export type MathJsonFunction = {
91
91
  fn: [Expression, ...Expression[]];
92
92
  } & Attributes;
93
- export declare type MathJsonDictionary = {
93
+ export type MathJsonDictionary = {
94
94
  dict: {
95
95
  [key: string]: Expression;
96
96
  };
@@ -102,4 +102,4 @@ export declare type MathJsonDictionary = {
102
102
  * The dictionary and function nodes can contain expressions themselves.
103
103
  *
104
104
  */
105
- export declare type Expression = number | string | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | [Expression, ...Expression[]];
105
+ export type Expression = number | string | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | [Expression, ...Expression[]];