@cortex-js/compute-engine 0.16.0 → 0.18.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 (101) hide show
  1. package/README.md +1 -1
  2. package/dist/compute-engine.esm.js +4235 -3949
  3. package/dist/compute-engine.js +4235 -3949
  4. package/dist/compute-engine.min.esm.js +50 -27363
  5. package/dist/compute-engine.min.js +22 -27346
  6. package/dist/math-json.esm.js +2 -2
  7. package/dist/math-json.js +2 -2
  8. package/dist/math-json.min.esm.js +2 -2
  9. package/dist/math-json.min.js +2 -281
  10. package/dist/types/common/ansi-codes.d.ts +1 -1
  11. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  12. package/dist/types/common/signals.d.ts +1 -1
  13. package/dist/types/common/utils.d.ts +1 -1
  14. package/dist/types/compute-engine/assume.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +7 -8
  16. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +7 -7
  18. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +13 -25
  19. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -2
  20. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +6 -6
  21. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +4 -3
  22. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
  23. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +3 -3
  25. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +11 -11
  26. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
  29. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  30. package/dist/types/compute-engine/boxed-expression/validate.d.ts +32 -12
  31. package/dist/types/compute-engine/compile.d.ts +22 -2
  32. package/dist/types/compute-engine/compute-engine.d.ts +28 -38
  33. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  34. package/dist/types/compute-engine/domain-utils.d.ts +4 -6
  35. package/dist/types/compute-engine/function-utils.d.ts +41 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/public.d.ts +36 -23
  53. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  56. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  57. package/dist/types/compute-engine/library/arithmetic-add.d.ts +2 -2
  58. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  59. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  60. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  61. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
  62. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  63. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  64. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  65. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  66. package/dist/types/compute-engine/library/core.d.ts +1 -1
  67. package/dist/types/compute-engine/library/domains.d.ts +3 -2
  68. package/dist/types/compute-engine/library/library.d.ts +4 -2
  69. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  70. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  71. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  72. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  73. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  74. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  75. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  76. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  77. package/dist/types/compute-engine/library/utils.d.ts +1 -3
  78. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  79. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  80. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  81. package/dist/types/compute-engine/numerics/numeric.d.ts +10 -2
  82. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  83. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  84. package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
  85. package/dist/types/compute-engine/public.d.ts +91 -113
  86. package/dist/types/compute-engine/rules.d.ts +1 -1
  87. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  88. package/dist/types/compute-engine/solve.d.ts +1 -1
  89. package/dist/types/compute-engine/symbolic/derivative.d.ts +16 -2
  90. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  91. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -2
  92. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  93. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  96. package/dist/types/compute-engine/symbolic/utils.d.ts +5 -3
  97. package/dist/types/compute-engine.d.ts +2 -2
  98. package/dist/types/math-json/math-json-format.d.ts +4 -3
  99. package/dist/types/math-json/utils.d.ts +1 -1
  100. package/dist/types/math-json.d.ts +2 -2
  101. package/package.json +9 -1
@@ -1,8 +1,8 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
+ import { Decimal } from 'decimal.js';
3
+ import { Expression } from '../../math-json/math-json-format';
2
4
  import { _BoxedExpression } from './abstract-boxed-expression';
3
5
  import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, DomainExpression, BoxedSubstitution } from '../public';
4
- import Complex from 'complex.js';
5
- import Decimal from 'decimal.js';
6
6
  /**
7
7
  * BoxedSymbol
8
8
  *
@@ -18,7 +18,7 @@ import Decimal from 'decimal.js';
18
18
  */
19
19
  export declare class BoxedSymbol extends _BoxedExpression {
20
20
  private _scope;
21
- protected _name: string;
21
+ protected _id: string;
22
22
  private _hash;
23
23
  private _def;
24
24
  constructor(ce: IComputeEngine, name: string, options?: {
@@ -27,11 +27,15 @@ export declare class BoxedSymbol extends _BoxedExpression {
27
27
  def?: BoxedSymbolDefinition | BoxedFunctionDefinition;
28
28
  });
29
29
  get hash(): number;
30
- unbind(): void;
31
30
  get isPure(): boolean;
32
31
  get json(): Expression;
33
32
  get scope(): RuntimeScope | null;
34
33
  get isConstant(): boolean;
34
+ /**
35
+ * Associate a definition with this symbol
36
+ */
37
+ bind(): void;
38
+ reset(): void;
35
39
  get isCanonical(): boolean;
36
40
  set isCanonical(val: boolean);
37
41
  get canonical(): BoxedExpression;
@@ -49,14 +53,10 @@ export declare class BoxedSymbol extends _BoxedExpression {
49
53
  * f(x) => x:integer narrowed from integer to real
50
54
  */
51
55
  infer(domain: BoxedDomain): boolean;
52
- /**
53
- * Associate a definition with this symbol, if one is not already available
54
- */
55
- bind(scope?: RuntimeScope | null): void;
56
56
  get value(): BoxedExpression | undefined;
57
57
  set value(value: boolean | string | Decimal | Complex | [num: number, denom: number] | BoxedExpression | number | undefined);
58
- get domain(): BoxedDomain;
59
- set domain(inDomain: BoxedExpression | DomainExpression | BoxedDomain);
58
+ get domain(): BoxedDomain | undefined;
59
+ set domain(inDomain: DomainExpression | BoxedDomain);
60
60
  get sgn(): -1 | 0 | 1 | undefined | null;
61
61
  has(x: string | string[]): boolean;
62
62
  isSame(rhs: BoxedExpression): boolean;
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,5 +1,5 @@
1
- /* 0.16.0 */
2
- import Decimal from 'decimal.js';
1
+ /* 0.18.0 */
2
+ import { Decimal } from 'decimal.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, IComputeEngine, Metadata, Rational } from '../public';
5
5
  /**
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, IComputeEngine } from '../public';
4
4
  export declare function isLatexString(s: unknown): s is string;
@@ -1,19 +1,39 @@
1
- /* 0.16.0 */
2
- export declare function validateArgumentCount(ce: IComputeEngine, ops: BoxedExpression[], count: number): BoxedExpression[];
1
+ /* 0.18.0 */
2
+ /**
3
+ * Check that the number of arguments is as expected.
4
+ *
5
+ * Converts the arguments to canonical, and flattens the sequence.
6
+ */
7
+ export declare function checkArity(ce: IComputeEngine, ops: BoxedExpression[], count: number): BoxedExpression[];
3
8
  /**
4
9
  * Validation of arguments is normally done by checking the signature of the
5
10
  * function vs the arguments of the expression. However, we have a fastpath
6
11
  * for some common operations (add, multiply, power, neg, etc...) that bypasses
7
- * the regular checks. This is its replacements. Since all those fastpath
8
- * functions are numeric (i.e. have numeric arguments and return a numeric
9
- * value), we do a simple numeric check of all arguments, and verify we have
10
- * the number of expected arguments.
12
+ * the regular checks. This is its replacements.
13
+ *
14
+ * Since all those fastpath functions are numeric (i.e. have numeric arguments
15
+ * and a numeric result), we do a simple numeric check of all arguments, and
16
+ * verify we have the number of expected arguments.
17
+ *
18
+ * Converts the arguments to canonical, and flattens the sequence.
11
19
  */
12
- export declare function validateNumericArgs(ce: IComputeEngine, ops: BoxedExpression[], count?: number): BoxedExpression[];
13
- /** Return `null` if the `ops` match the sig. Otherwise, return an array
14
- * of expressions indicating the mismatched arguments.
20
+ export declare function checkNumericArgs(ce: IComputeEngine, ops: BoxedExpression[], options?: number | {
21
+ count?: number;
22
+ flatten?: boolean | string;
23
+ }): BoxedExpression[];
24
+ /**
25
+ * Check that an argument is of the expected domain.
26
+ *
27
+ * Converts the arguments to canonical
28
+ */
29
+ export declare function checkArg(ce: IComputeEngine, arg: BoxedExpression | undefined | null, dom: BoxedDomain | DomainLiteral | undefined): BoxedExpression;
30
+ export declare function checkArgs(ce: IComputeEngine, args: BoxedExpression[], doms: (BoxedDomain | DomainLiteral)[]): BoxedExpression[];
31
+ /**
32
+ *
33
+ * If the arguments match the parameters, return null.
34
+ *
35
+ * Otherwise return a list of expressions indicating the mismatched
36
+ * arguments.
15
37
  *
16
38
  */
17
- export declare function validateSignature(sig: BoxedDomain, ops: BoxedExpression[], codomain?: BoxedExpression): BoxedExpression[] | null;
18
- export declare function validateArgument(ce: IComputeEngine, arg: BoxedExpression | undefined, dom: BoxedDomain | DomainLiteral | undefined): BoxedExpression;
19
- export declare function validateArguments(ce: IComputeEngine, args: BoxedExpression[], doms: (BoxedDomain | DomainLiteral)[]): BoxedExpression[];
39
+ export declare function adjustArguments(ce: IComputeEngine, ops: BoxedExpression[], hold: Hold, params: BoxedDomain[], optParams: BoxedDomain[], restParam: BoxedDomain | null): BoxedExpression[] | null;
@@ -1,10 +1,30 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
+ import { BoxedExpression } from './public';
2
3
  export type CompiledType = boolean | number | string | object;
4
+ type JSSource = string;
5
+ export type CompiledOperators = Record<MathJsonIdentifier, [
6
+ op: string,
7
+ prec: number
8
+ ]>;
9
+ export type CompiledFunctions = {
10
+ [id: MathJsonIdentifier]: string | ((args: BoxedExpression[], compile: (expr: BoxedExpression) => JSSource) => JSSource);
11
+ };
12
+ export type CompileTarget = {
13
+ operators?: (op: MathJsonIdentifier) => [op: string, prec: number];
14
+ functions?: (id: MathJsonIdentifier) => string | ((...args: CompiledType[]) => string);
15
+ var: (id: MathJsonIdentifier) => string | undefined;
16
+ string: (str: string) => string;
17
+ number: (n: number) => string;
18
+ ws: (s?: string) => string;
19
+ indent: number;
20
+ };
3
21
  /** This is an extension of the Function class that allows us to pass
4
22
  * a custom scope for "global" functions. */
5
23
  export declare class ComputeEngineFunction extends Function {
6
24
  private sys;
7
25
  constructor(body: any);
8
26
  }
27
+ export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
9
28
  export declare function compileToJavascript(expr: BoxedExpression): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
10
- export declare function compile(expr: BoxedExpression, freeVars?: string[], prec?: number): string;
29
+ export declare function compile(expr: BoxedExpression, target: CompileTarget, prec?: number): JSSource;
30
+ export {};
@@ -1,8 +1,8 @@
1
- /* 0.16.0 */
2
- import { Complex } from 'complex.js';
1
+ /* 0.18.0 */
2
+ import { Decimal } from 'decimal.js';
3
3
  import { Expression, MathJsonNumber } from '../math-json/math-json-format';
4
4
  import type { LibraryCategory, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
5
- import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution, AssignValue } from './public';
5
+ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution, AssignValue, DomainLiteral } from './public';
6
6
  /**
7
7
  *
8
8
  * To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
@@ -23,24 +23,25 @@ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefi
23
23
  * ```
24
24
  */
25
25
  export declare class ComputeEngine implements IComputeEngine {
26
- /** @internal */
27
- readonly _ZERO: BoxedExpression;
28
- /** @internal */
29
- readonly _ONE: BoxedExpression;
30
- /** @internal */
31
- readonly _HALF: BoxedExpression;
32
- /** @internal */
33
- readonly _NEGATIVE_ONE: BoxedExpression;
34
- /** @internal */
35
- readonly _I: BoxedExpression;
36
- /** @internal */
37
- readonly _NAN: BoxedExpression;
38
- /** @internal */
39
- readonly _POSITIVE_INFINITY: BoxedExpression;
40
- /** @internal */
41
- readonly _NEGATIVE_INFINITY: BoxedExpression;
42
- /** @internal */
43
- readonly _COMPLEX_INFINITY: BoxedExpression;
26
+ readonly Anything: BoxedDomain;
27
+ readonly Void: BoxedDomain;
28
+ readonly Strings: BoxedDomain;
29
+ readonly Booleans: BoxedDomain;
30
+ readonly Numbers: BoxedDomain;
31
+ readonly True: BoxedExpression;
32
+ readonly False: BoxedExpression;
33
+ readonly Pi: BoxedExpression;
34
+ readonly E: BoxedExpression;
35
+ readonly Nothing: BoxedExpression;
36
+ readonly Zero: BoxedExpression;
37
+ readonly One: BoxedExpression;
38
+ readonly Half: BoxedExpression;
39
+ readonly NegativeOne: BoxedExpression;
40
+ readonly I: BoxedExpression;
41
+ readonly NaN: BoxedExpression;
42
+ readonly PositiveInfinity: BoxedExpression;
43
+ readonly NegativeInfinity: BoxedExpression;
44
+ readonly ComplexInfinity: BoxedExpression;
44
45
  /** @internal */
45
46
  _BIGNUM_NAN: Decimal;
46
47
  /** @internal */
@@ -145,16 +146,12 @@ export declare class ComputeEngine implements IComputeEngine {
145
146
  * @param options.tolerance If the absolute value of the difference of two
146
147
  * numbers is less than `tolerance`, they are considered equal. Used by
147
148
  * `chop()` as well.
148
- *
149
- * @param options.defaultDomain If an unknown symbol is encountered, assume
150
- * this is its domain. **Default** `ExtendedRealNumbers`
151
149
  */
152
150
  constructor(options?: {
153
151
  numericMode?: NumericMode;
154
152
  numericPrecision?: number;
155
153
  ids?: readonly IdentifierDefinitions[];
156
154
  tolerance?: number;
157
- defaultDomain?: string;
158
155
  });
159
156
  get latexDictionary(): readonly LatexDictionaryEntry[];
160
157
  set latexDictionary(dic: readonly LatexDictionaryEntry[]);
@@ -194,16 +191,6 @@ export declare class ComputeEngine implements IComputeEngine {
194
191
  get iterationLimit(): number;
195
192
  /** @experimental */
196
193
  get recursionLimit(): number;
197
- /**
198
- * If an unknown symbol is encountered, assume it should
199
- * be a variable in this domain.
200
- *
201
- * If set to `null`, unknown symbols will trigger an error.
202
- *
203
- * **Default:** `"ExtendedRealNumbers"`
204
- */
205
- get defaultDomain(): BoxedDomain | null;
206
- set defaultDomain(domain: BoxedDomain | string | null);
207
194
  /**
208
195
  * Values smaller than the tolerance are considered to be zero for the
209
196
  * purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
@@ -263,8 +250,10 @@ export declare class ComputeEngine implements IComputeEngine {
263
250
  */
264
251
  popScope(): IComputeEngine;
265
252
  swapScope(scope: RuntimeScope | null): RuntimeScope | null;
253
+ resetContext(): void;
266
254
  _printScope(options?: {
267
255
  details?: boolean;
256
+ maxDepth?: number;
268
257
  }, scope?: RuntimeScope | null, depth?: number): RuntimeScope | null;
269
258
  /**
270
259
  * Declare one or more identifiers:
@@ -272,9 +261,9 @@ export declare class ComputeEngine implements IComputeEngine {
272
261
  * associate an identifier with a definition, at minimum a domain, optionally
273
262
  * a value and some other flags.
274
263
  */
275
- declare(id: string, def: DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
264
+ declare(id: string, def: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
276
265
  declare(identifiers: {
277
- [id: string]: DomainExpression | SymbolDefinition | FunctionDefinition;
266
+ [id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
278
267
  }): IComputeEngine;
279
268
  /**
280
269
  * Assign a value to one or more identifiers.
@@ -322,6 +311,7 @@ export declare class ComputeEngine implements IComputeEngine {
322
311
  /** @internal */
323
312
  _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
324
313
  error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
314
+ domainError(expectedDomain: BoxedDomain | DomainLiteral, actualDomain: undefined | BoxedDomain, where?: SemiBoxedExpression): BoxedExpression;
325
315
  hold(expr: SemiBoxedExpression): BoxedExpression;
326
316
  add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
327
317
  neg(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
@@ -337,7 +327,7 @@ export declare class ComputeEngine implements IComputeEngine {
337
327
  metadata?: Metadata;
338
328
  canonical?: boolean;
339
329
  }): BoxedExpression;
340
- domain(domain: BoxedExpression | DomainExpression | BoxedDomain, metadata?: Metadata): BoxedDomain;
330
+ domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
341
331
  number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
342
332
  canonical?: boolean;
343
333
  metadata?: Metadata;
@@ -1,3 +1,3 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,9 +1,7 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { Decimal } from 'decimal.js';
3
- import { DomainLiteral, Rational, SemiBoxedExpression } from './public';
4
- /** Quickly determine the numeric domain of a number or constant
5
- * For the symbols, this is a hard-coded optimization that doesn't rely on the
6
- * dictionaries. The regular path is in `internalDomain()`
3
+ import { DomainLiteral, Rational } from './public';
4
+ /**
5
+ * Determine the numeric domain of a number.
7
6
  */
8
7
  export declare function inferNumericDomain(value: number | Decimal | Complex | Rational): DomainLiteral;
9
- export declare function inferDomain(expr: SemiBoxedExpression): DomainLiteral;
@@ -1,4 +1,44 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
+ /***
3
+ * ## THEORY OF OPERATIONS
4
+ *
5
+ * A `["Function"]` expression has its own scope.
6
+ * This scope includes the parameters and local variables.
7
+ *
8
+ * Some expressions with anonymous parameters (e.g. `["Add", "_", 1]`)
9
+ * are rewritten to a `["Function"]` expression with anonymous parameters
10
+ * (e.g. `["Function", ["Add", "_", 1], "_"]`).
11
+ *
12
+ * The **body** of a `["Function"]` expression may have its own scope
13
+ * (for example if it's a `["Block"]` expression) or may not have a scope
14
+ * at all (if it's a number, i.e. `["Function", 1]`). the function body may
15
+ * be a number, a symbol or (more commonly) an function expression.
16
+ *
17
+ *
18
+ * ### DURING BOXING (in makeLambda())
19
+ *
20
+ * During the boxing/canonicalization phase of a function
21
+ * (`["Function"]` expression or head expression):
22
+ *
23
+ * 1/ If not a `["Function"]` expression, the expression is rewritten
24
+ * to a `["Function"]` expression with anonymous parameters
25
+ * 2/ A new scope is created
26
+ * 3/ The function parameters are declared in the scope
27
+ * 4/ The function body is boxed in the context of the scope and the scope
28
+ * is associated with the function
29
+ *
30
+ *
31
+ * ### DURING EVALUATION (executing the result of makeLambda())
32
+ *
33
+ * 1/ The arguments are evaluated in the current scope
34
+ * 2/ The context is swapped to the function scope
35
+ * 3/ The values of all the ids in this scope are reset
36
+ * 4/ The parameters are set to the value of the arguments
37
+ * 5/ The function body is evaluated in the context of the function scope
38
+ * 6/ The context is swapped back to the current scope
39
+ * 7/ The result of the function body is returned
40
+ *
41
+ */
2
42
  /**
3
43
  * From an expression, create an iterator that can be used
4
44
  * to enumerate values.
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_COMPLEX: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_STATISTICS: LatexDictionary;
@@ -1,3 +1,3 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const SYMBOLS: [string, string, number][];
3
3
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { WarningSignal } from '../../../common/signals';
3
3
  export type CommonEntry = {
4
4
  /** Note: a name is required if a serialize handler is provided */
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { Serializer } from './serializer';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { WarningSignalHandler } from '../../common/signals';
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { Parser } from './public';
3
3
  /** For error handling, if we have a identifier prefix, assume
4
4
  * the identifier is invalid (it would have been captured by
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
3
3
  import { IComputeEngine } from '../public';
4
4
  import { Expression } from '../../math-json/math-json-format';
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import type { IComputeEngine } from '../public';
4
4
  /**
@@ -29,23 +29,27 @@ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collectio
29
29
  * For example, in `1 + 2 * 3`, the `*` operator has a **higher** precedence
30
30
  * than the `+` operator, so it is applied first.
31
31
  *
32
- * The precendence range from 0 to 1000. The larger the number, the higher the
32
+ * The precedence range from 0 to 1000. The larger the number, the higher the
33
33
  * precedence, the more "binding" the operator is.
34
34
  *
35
35
  * Here are some rough ranges for the precedence:
36
36
  *
37
- * - 800: prefix and postfix operators,
38
- * e.g. `\lnot`, `!`, `'`, `\degree`, `++`, etc...
39
- * - 700: some relational operators: `<`
40
- * - 600: some binary operators: `\div`
37
+ * - 800: prefix and postfix operators: `\lnot` etc...
38
+ * - `POSTFIX_PRECEDENCE` = 810: `!`, `'`
39
+ * - 700: some arithmetic operators
40
+ * - `EXPONENTIATION_PRECEDENCE` = 700: `^`
41
+ * - 600: some binary operators
42
+ * - `DIVISION_PRECEDENCE` = 600: `\div`
41
43
  * - 500: not used
42
44
  * - 400: not used
43
45
  * - 300: some logic and arithmetic operators:
44
46
  * `\land`, `\lor`, `\times`, etc...
47
+ * - `MULTIPLICATION_PRECEDENCE` = 390: `\times`
45
48
  * - 200: arithmetic operators, inequalities:
46
- * `+`, `-`, `=`, `<`, etc...
47
- * - 260: `=`
48
- * - 245: `\lt`, `\gt`
49
+ * - `ADDITION_PRECEDENCE` = 275: `+` `-`
50
+ * - `ARROW_PRECEDENCE` = 270: `\to` `\rightarrow`
51
+ * - `ASSIGNMENT_PRECEDENCE` = 260: `:=`
52
+ * - `COMPARISON_PRECEDENCE` = 245: `\lt` `\gt`
49
53
  * - 241: `\leq`
50
54
  * - 100: not used
51
55
  * - 0: `,`, `;`, etc...
@@ -53,7 +57,7 @@ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collectio
53
57
  * Some constants are defined below for common precedence values.
54
58
  *
55
59
  *
56
- * Note: MathML defines some operator precendence, but it has some
60
+ * Note: MathML defines some operator precedence, but it has some
57
61
  * issues and inconsistencies. However, whenever possible we adopted the
58
62
  * MathML precedence. See https://www.w3.org/TR/2009/WD-MathML3-20090924/appendixc.html
59
63
  *
@@ -61,14 +65,14 @@ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collectio
61
65
  * here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence
62
66
  */
63
67
  export type Precedence = number;
64
- export declare const COMPARISON_PRECEDENCE = 245;
65
- export declare const ASSIGNMENT_PRECEDENCE = 260;
66
- export declare const ARROW_PRECEDENCE = 270;
67
- export declare const ADDITION_PRECEDENCE = 275;
68
- export declare const MULTIPLICATION_PRECEDENCE = 390;
69
- export declare const DIVISION_PRECEDENCE = 600;
70
- export declare const EXPONENTIATION_PRECEDENCE = 700;
71
- export declare const POSTFIX_PRECEDENCE = 810;
68
+ export declare const COMPARISON_PRECEDENCE: Precedence;
69
+ export declare const ASSIGNMENT_PRECEDENCE: Precedence;
70
+ export declare const ARROW_PRECEDENCE: Precedence;
71
+ export declare const ADDITION_PRECEDENCE: Precedence;
72
+ export declare const MULTIPLICATION_PRECEDENCE: Precedence;
73
+ export declare const DIVISION_PRECEDENCE: Precedence;
74
+ export declare const EXPONENTIATION_PRECEDENCE: Precedence;
75
+ export declare const POSTFIX_PRECEDENCE: Precedence;
72
76
  /**
73
77
  * This indicates a condition under which parsing should stop:
74
78
  * - an operator of a precedence higher than specified has been encountered
@@ -297,14 +301,23 @@ export type ParseLatexOptions = {
297
301
  */
298
302
  parseArgumentsOfUnknownLatexCommands: boolean;
299
303
  /**
300
- * When a number is encountered, parse it.
304
+ * When parsing a decimal number (e.g. `3.1415`):
301
305
  *
302
- * Otherwise, return each token making up the number (minus sign, digits,
303
- * decimal marker, etc...).
306
+ * - `"auto"` or `"decimal"`: if a decimal number parse it as an approximate
307
+ * decimal number with a whole part and a fractional part
308
+ * - `"rational"`: if a decimal number, parse it as an exact rational number
309
+ * with a numerator and a denominator. If not a decimal number, parse
310
+ * it as a regular number.
311
+ * - `"never"`: do not parse numbers, instead return each token making up
312
+ * the number (minus sign, digits, decimal marker, etc...).
313
+ *
314
+ * Note: if the number includes repeating digits (e.g. `1.33(333)`),
315
+ * it will be parsed as a decimal number even if this setting is `"rational"`.
316
+ *
317
+ * **Default**: `"auto"`
304
318
  *
305
- * **Default**: `true`
306
319
  */
307
- parseNumbers: boolean;
320
+ parseNumbers: 'auto' | 'rational' | 'decimal' | 'never';
308
321
  /**
309
322
  * This handler is invoked when the parser encounters an identifier
310
323
  * that does not have a corresponding entry in the dictionary.
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { NumberFormattingOptions } from './public';
3
3
  export declare function serializeNumber(expr: Expression | null, options: NumberFormattingOptions): string;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
3
3
  export declare function getGroupStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
4
4
  export declare function getRootStyle(_expr: Expression | null, level: number): 'radical' | 'quotient' | 'solidus';
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  import { WarningSignalHandler } from '../../common/signals';
3
3
  import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
4
4
  import { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  * ## Reference
3
3
  * TeX source code:
4
4
  * {@link http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web | Tex.web}
@@ -1,10 +1,10 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  /** The canonical form of `Add`:
3
3
  * - removes `0`
4
4
  * - capture complex numbers (a + ib or ai +b)
5
5
  * */
6
6
  export declare function canonicalAdd(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
7
- export declare function domainAdd(_ce: IComputeEngine, args: BoxedDomain[]): BoxedDomain | null;
7
+ export declare function domainAdd(_ce: IComputeEngine, args: (undefined | BoxedDomain)[]): BoxedDomain | null | undefined;
8
8
  export declare function simplifyAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression;
9
9
  export declare function evalAdd(ce: IComputeEngine, ops: BoxedExpression[], mode?: 'N' | 'evaluate'): BoxedExpression;
10
10
  export declare function canonicalSummation(ce: IComputeEngine, body: BoxedExpression, range: BoxedExpression | undefined): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  /**
3
3
  * Canonical form of 'Divide' (and 'Rational')
4
4
  * - remove denominator of 1
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  /** The canonical form of `Multiply`:
3
3
  * - remove `1`
4
4
  * - combine literal integers and rationals
@@ -1,4 +1,4 @@
1
- /* 0.16.0 */
1
+ /* 0.18.0 */
2
2
  /**
3
3
  *
4
4
  */