@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,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  import { Delimiter, EnvironmentParseHandler, ExpressionParseHandler, InfixParseHandler, LatexDictionary, LatexDictionaryEntry, LatexString, LatexToken, LibraryCategory, MatchfixParseHandler, PostfixParseHandler, Precedence, SerializeHandler } from '../public';
3
3
  export type CommonEntry = {
4
4
  /** Note: a name is required if a serialize handler is provided */
@@ -1,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
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
@@ -18,4 +18,4 @@ export declare function parseInvalidIdentifier(parser: Parser): Expression | nul
18
18
  * - `\mathrm{\alpha_{12}}` or
19
19
  * - `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}`
20
20
  */
21
- export declare function parseIdentifier(parser: Parser): string | null;
21
+ export declare function parseIdentifier(parser: Parser): MathJsonIdentifier | null;
@@ -1,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  import { ParseLatexOptions, LatexToken, Terminator, Parser, SymbolTable, SymbolType } from './public';
3
3
  import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
4
4
  /**
@@ -62,7 +62,7 @@ export declare class _Parser implements Parser {
62
62
  private _lastPeek;
63
63
  private _peekCounter;
64
64
  constructor(tokens: LatexToken[], dictionary: IndexedLatexDictionary, options: Readonly<ParseLatexOptions>);
65
- getIdentifierType(id: string): SymbolType;
65
+ getIdentifierType(id: MathJsonIdentifier): SymbolType;
66
66
  get peek(): LatexToken;
67
67
  nextToken(): LatexToken;
68
68
  get atEnd(): boolean;
@@ -129,19 +129,31 @@ export declare class _Parser implements Parser {
129
129
  match(token: LatexToken): boolean;
130
130
  matchAll(tokens: LatexToken[]): boolean;
131
131
  matchAny(tokens: LatexToken[]): LatexToken;
132
+ /**
133
+ * A Latex number can be a decimal, hex or octal number.
134
+ * It is used in some Latex commands, such as `\char`
135
+ *
136
+ * From TeX:8695 (scan_int):
137
+ * > An integer number can be preceded by any number of spaces and `+' or
138
+ * > `-' signs. Then comes either a decimal constant (i.e., radix 10), an
139
+ * > octal constant (i.e., radix 8, preceded by '), a hexadecimal constant
140
+ * > (radix 16, preceded by "), an alphabetic constant (preceded by `), or
141
+ * > an internal variable.
142
+ */
143
+ matchLatexNumber(isInteger?: boolean): null | number;
132
144
  matchChar(): string | null;
133
145
  /**
134
146
  *
135
147
  * If the next token matches the open delimiter, set a boundary with
136
148
  * the close token and return true.
137
149
  *
138
- * Note this method handles "shorthand" delimiters, i.e. '(' will match both
150
+ * This method handles prefixes like `\left` and `\bigl`.
151
+ *
152
+ * It also handles "shorthand" delimiters, i.e. '(' will match both
139
153
  * `(` and `\lparen`. If a shorthand is used for the open delimiter, the
140
154
  * corresponding shorthand will be used for the close delimiter.
141
155
  * See DELIMITER_SHORTHAND.
142
156
  *
143
- * It also handles prefixes like `\left` and `\bigl`.
144
- *
145
157
  */
146
158
  private matchDelimiter;
147
159
  parseGroup(): Expression | null;
@@ -185,18 +197,6 @@ export declare class _Parser implements Parser {
185
197
  * repeating decimals, etc...
186
198
  */
187
199
  parseNumber(): Expression | null;
188
- /**
189
- * A Latex number can be a decimal, hex or octal number.
190
- * It is used in some Latex commands, such as `\char`
191
- *
192
- * From TeX:8695 (scan_int):
193
- * > An integer number can be preceded by any number of spaces and `+' or
194
- * > `-' signs. Then comes either a decimal constant (i.e., radix 10), an
195
- * > octal constant (i.e., radix 8, preceded by '), a hexadecimal constant
196
- * > (radix 16, preceded by "), an alphabetic constant (preceded by `), or
197
- * > an internal variable.
198
- */
199
- matchLatexNumber(isInteger?: boolean): null | number;
200
200
  private parsePrefixOperator;
201
201
  private parseInfixOperator;
202
202
  /**
@@ -209,23 +209,13 @@ export declare class _Parser implements Parser {
209
209
  * (i.e. we interpret `\cos 2x + 1` as `\cos(2x) + 1`)
210
210
  *
211
211
  */
212
- parseArguments(kind?: 'enclosure' | 'implicit', until?: Readonly<Terminator>): Expression[] | null;
213
- /** If matches the normalized open delimiter, return the
214
- * expected closing delimiter.
215
- *
216
- * For example, if `delimiter` is `(`, it would match `\left\lparen` and
217
- * return `['\right', '\rparen']`, which can be matched with `matchAll()`
218
- *
219
- * If you need to match several tokens, use `matchAll()`
220
- *
221
- * @internal
222
- */
212
+ parseArguments(kind?: 'enclosure' | 'implicit', until?: Readonly<Terminator>): ReadonlyArray<Expression> | null;
223
213
  /**
224
214
  * An enclosure is an opening matchfix operator, an optional expression,
225
215
  * optionally followed multiple times by a separator and another expression,
226
216
  * and finally a closing matching operator.
227
217
  */
228
- private parseEnclosure;
218
+ parseEnclosure(): Expression | null;
229
219
  /**
230
220
  * A generic expression is used for dictionary entries that do
231
221
  * some complex (non-standard) parsing. This includes trig functions (to
@@ -299,8 +289,13 @@ export declare class _Parser implements Parser {
299
289
  */
300
290
  decorate(expr: Expression | null, start: number): Expression | null;
301
291
  error(code: string | [string, ...Expression[]], fromToken: number): Expression;
302
- private isFunctionHead;
303
- /** Return all defs of the specified kind */
292
+ private isFunctionOperator;
293
+ /** Return all defs of the specified kind.
294
+ * The defs at the end of the dictionary have priority, since they may
295
+ * override previous definitions. (For example, there is a core definition
296
+ * for matchfix[], which maps to a List, and a logic definition which
297
+ * matches to Boole. The logic definition should take precedence.)
298
+ */
304
299
  getDefs(kind: string): Iterable<IndexedLatexDictionaryEntry>;
305
300
  }
306
301
  export declare function parse(latex: string, dictionary: IndexedLatexDictionary, options: Readonly<ParseLatexOptions>): Expression | null;
@@ -1,9 +1,10 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
+ import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
2
3
  export type SymbolType = 'symbol' | 'function' | 'unknown';
3
4
  export type SymbolTable = {
4
5
  parent: SymbolTable | null;
5
6
  ids: {
6
- [id: string]: SymbolType;
7
+ [id: MathJsonIdentifier]: SymbolType;
7
8
  };
8
9
  };
9
10
  /**
@@ -28,7 +29,7 @@ export type LatexString = string;
28
29
  *
29
30
  * @category Latex Parsing and Serialization
30
31
  */
31
- export type Delimiter = ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor';
32
+ export type Delimiter = ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor' | '\\llbracket' | '\\rrbracket';
32
33
  /** @category Latex Parsing and Serialization */
33
34
  export type DelimiterScale = 'normal' | 'scaled' | 'big' | 'none';
34
35
  /**
@@ -185,7 +186,7 @@ export type LatexArgumentType = '{expression}' /** A required math mode expressi
185
186
  */
186
187
  export type Trigger = {
187
188
  latexTrigger?: LatexString | LatexToken[];
188
- identifierTrigger?: string;
189
+ identifierTrigger?: MathJsonIdentifier;
189
190
  };
190
191
  /**
191
192
  * Maps a string of LaTeX tokens to a function or symbol and vice-versa.
@@ -208,7 +209,7 @@ export type BaseEntry = {
208
209
  * entry. Otherwise, if the trigger of the entry matches the current
209
210
  * token, the `parse` handler is invoked.
210
211
  */
211
- name?: string;
212
+ name?: MathJsonIdentifier;
212
213
  /**
213
214
  * Transform an expression into a LaTeX string.
214
215
  * If no `serialize` handler is provided, the trigger is used.
@@ -304,7 +305,7 @@ export type PrefixEntry = BaseEntry & Trigger & {
304
305
  export type EnvironmentEntry = BaseEntry & {
305
306
  kind: 'environment';
306
307
  parse: EnvironmentParseHandler;
307
- identifierTrigger: string;
308
+ identifierTrigger: MathJsonIdentifier;
308
309
  };
309
310
  /**
310
311
  * @category Latex Parsing and Serialization
@@ -485,7 +486,7 @@ export type ParseLatexOptions = NumberFormat & {
485
486
  *
486
487
  * - `"unknown"`: the identifier is not recognized.
487
488
  */
488
- getIdentifierType: (identifier: string) => SymbolType;
489
+ getIdentifierType: (identifier: MathJsonIdentifier) => SymbolType;
489
490
  /** This handler is invoked when the parser encounters an unexpected token.
490
491
  *
491
492
  * The `lhs` argument is the left-hand side of the token, if any.
@@ -527,10 +528,10 @@ export type ParseLatexOptions = NumberFormat & {
527
528
  */
528
529
  export interface Parser {
529
530
  readonly options: Required<ParseLatexOptions>;
530
- getIdentifierType(id: string): SymbolType;
531
+ getIdentifierType(id: MathJsonIdentifier): SymbolType;
531
532
  pushSymbolTable(): void;
532
533
  popSymbolTable(): void;
533
- addSymbol(id: string, type: SymbolType): void;
534
+ addSymbol(id: MathJsonIdentifier, type: SymbolType): void;
534
535
  /** The index of the current token */
535
536
  index: number;
536
537
  /** True if the last token has been reached.
@@ -579,7 +580,7 @@ export interface Parser {
579
580
  * `\frac{1}{2}`.
580
581
  *
581
582
  * Return `null` if none was found
582
- * Return `['Sequence']` if an empty group `{}` was found
583
+ * Return `Nothing` if an empty group `{}` was found
583
584
  */
584
585
  parseGroup(): Expression | null;
585
586
  /**
@@ -603,6 +604,8 @@ export interface Parser {
603
604
  * Return `null` if none was found.
604
605
  */
605
606
  parseOptionalGroup(): Expression | null;
607
+ /** Parse an enclosure (open paren/close paren, etc..) and return the expression inside the enclosure */
608
+ parseEnclosure(): Expression | null;
606
609
  /**
607
610
  * Some LaTeX commands have arguments that are not interpreted as
608
611
  * expressions, but as strings. For example, `\begin{array}{ccc}` (both
@@ -645,7 +648,7 @@ export interface Parser {
645
648
  * Return an array of expressions, one for each argument, or `null` if no
646
649
  * argument was found.
647
650
  */
648
- parseArguments(kind?: 'implicit' | 'enclosure', until?: Terminator): Expression[] | null;
651
+ parseArguments(kind?: 'implicit' | 'enclosure', until?: Terminator): ReadonlyArray<Expression> | null;
649
652
  /**
650
653
  * Parse a postfix operator, such as `'` or `!`.
651
654
  *
@@ -728,7 +731,7 @@ export type SerializeLatexOptions = NumberSerializationFormat & {
728
731
  */
729
732
  invisibleMultiply: LatexString;
730
733
  /**
731
- * LaTeX string used to render mixed numbers e.g. in '1 3/4'.
734
+ * LaTeX string used to render [mixed numbers](https://en.wikipedia.org/wiki/Fraction#Mixed_numbers) e.g. '1 3/4'.
732
735
  *
733
736
  * Leave it empty to join the main number and the fraction, i.e. render it
734
737
  * as `1\frac{3}{4}`.
@@ -742,6 +745,8 @@ export type SerializeLatexOptions = NumberSerializationFormat & {
742
745
  /**
743
746
  * LaTeX string used to render an explicit multiply operator.
744
747
  *
748
+ * For example, `\times`, `\cdot`, etc...
749
+ *
745
750
  * Default: `\times`
746
751
  */
747
752
  multiply: LatexString;
@@ -768,10 +773,11 @@ export type SerializeLatexOptions = NumberSerializationFormat & {
768
773
  */
769
774
  export interface Serializer {
770
775
  readonly options: Required<SerializeLatexOptions>;
776
+ readonly dictionary: IndexedLatexDictionary;
771
777
  /** "depth" of the expression:
772
778
  * - 0 for the root
773
- * - 1 for the arguments of the root
774
- * - 2 for the arguments of the arguments of the root
779
+ * - 1 for a subexpression of the root
780
+ * - 2 for subexpressions of the subexpressions of the root
775
781
  * - etc...
776
782
  *
777
783
  * This allows the serialized LaTeX to vary depending on the depth of the
@@ -781,8 +787,8 @@ export interface Serializer {
781
787
  */
782
788
  level: number;
783
789
  /** Output a LaTeX string representing the expression */
784
- serialize: (expr: Expression | null) => string;
785
- serializeFunction(expr: Expression): LatexString;
790
+ serialize: (expr: Expression | null | undefined) => string;
791
+ serializeFunction(expr: Expression, def?: IndexedLatexDictionaryEntry): LatexString;
786
792
  serializeSymbol(expr: Expression): LatexString;
787
793
  /** Output `s` surrounded by delimiters.
788
794
  *
@@ -797,11 +803,11 @@ export interface Serializer {
797
803
  /** Add a group fence around the expression if it is
798
804
  * an operator of precedence less than or equal to `prec`.
799
805
  */
800
- wrap: (expr: Expression | null, prec?: number) => LatexString;
806
+ wrap: (expr: Expression | null | undefined, prec?: number) => LatexString;
801
807
  /** Add a group fence around the expression if it is
802
808
  * short (not a function)
803
809
  */
804
- wrapShort(expr: Expression | null): LatexString;
810
+ wrapShort(expr: Expression | null | undefined): LatexString;
805
811
  /** Styles */
806
812
  applyFunctionStyle: (expr: Expression, level: number) => DelimiterScale;
807
813
  groupStyle: (expr: Expression, level: number) => DelimiterScale;
@@ -1,8 +1,8 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  import { NumberSerializationFormat } from './public';
3
3
  /**
4
4
  * @param expr - A number, can be represented as a string
5
- * particularly useful for arbitrary precision numbers) or a number (-12.45)
5
+ * (particularly useful for arbitrary precision numbers) or a number (-12.45)
6
6
  * @return A textual representation of the number, formatted according to the
7
7
  * `options`
8
8
  */
@@ -1,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  import { DelimiterScale } from './public';
3
3
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): DelimiterScale;
4
4
  export declare function getGroupStyle(_expr: Expression, _level: number): DelimiterScale;
@@ -1,6 +1,6 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  import { LatexString, SerializeLatexOptions, DelimiterScale } from './public';
3
- import { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
3
+ import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
4
4
  export declare class Serializer {
5
5
  options: SerializeLatexOptions;
6
6
  readonly dictionary: IndexedLatexDictionary;
@@ -11,7 +11,7 @@ export declare class Serializer {
11
11
  * of precedence less than or equal to prec, wrap it in some parens.
12
12
  * @todo: don't wrap Abs, Floor, Ceil, Delimiter
13
13
  */
14
- wrap(expr: Expression | null, prec?: number): string;
14
+ wrap(expr: Expression | null | undefined, prec?: number): string;
15
15
  /**
16
16
  * If this is a "short" expression, wrap it.
17
17
  * Do not wrap identifiers, positive numbers or functions.
@@ -19,15 +19,12 @@ export declare class Serializer {
19
19
  * This is called by the serializer for power and division (i.e. "(a+1)/b")
20
20
  *
21
21
  */
22
- wrapShort(expr: Expression | null): string;
22
+ wrapShort(expr: Expression | null | undefined): string;
23
23
  wrapString(s: string, style: DelimiterScale, fence?: string): string;
24
24
  wrapArguments(expr: Expression): string;
25
25
  serializeSymbol(expr: Expression, def?: IndexedLatexDictionaryEntry): LatexString;
26
26
  serializeFunction(expr: Expression, def?: IndexedLatexDictionaryEntry): LatexString;
27
- serializeDictionary(dict: {
28
- [key: string]: Expression;
29
- }): string;
30
- serialize(expr: Expression | null): LatexString;
27
+ serialize(expr: Expression | null | undefined): LatexString;
31
28
  applyFunctionStyle(expr: Expression, level: number): DelimiterScale;
32
29
  groupStyle(expr: Expression, level: number): DelimiterScale;
33
30
  rootStyle(expr: Expression, level: number): 'radical' | 'quotient' | 'solidus';
@@ -1,4 +1,4 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
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,3 +1,5 @@
1
- /* 0.25.1 */
2
- export type CanonicalArithmeticFunctions = 'Add' | 'Negate' | 'Sqrt' | 'Multiply' | 'Divide' | 'Power' | 'Ln';
1
+ /* 0.26.2 */
2
+ import { BoxedExpression } from '../boxed-expression/public';
3
+ export type CanonicalArithmeticOperators = 'Add' | 'Negate' | 'Multiply' | 'Divide' | 'Power' | 'Sqrt' | 'Root' | 'Ln';
3
4
  export declare const ARITHMETIC_LIBRARY: IdentifierDefinitions[];
5
+ export declare function isPrime(expr: BoxedExpression): boolean | undefined;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const CALCULUS_LIBRARY: IdentifierDefinitions[];
@@ -1,3 +1,26 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const DEFAULT_LINSPACE_COUNT = 50;
3
3
  export declare const COLLECTIONS_LIBRARY: IdentifierDefinitions;
4
+ /**
5
+ * Normalize the arguments of range:
6
+ * - [from, to] -> [from, to, 1] if to > from, or [from, to, -1] if to < from
7
+ * - [x] -> [1, x]
8
+ * - arguments rounded to integers
9
+ *
10
+ */
11
+ export declare function range(expr: BoxedExpression): [lower: number, upper: number, step: number];
12
+ /** Return the last value in the range
13
+ * - could be less that lower if step is negative
14
+ * - could be less than upper if step is positive, for
15
+ * example `rangeLast([1, 6, 2])` = 5
16
+ */
17
+ export declare function rangeLast(r: [lower: number, upper: number, step: number]): number;
18
+ /**
19
+ * This function is used to reduce a collection of expressions to a single value. It
20
+ * iterates over the collection, applying the given function to each element and the
21
+ * accumulator. If the function returns `null`, the iteration is stopped and `undefined`
22
+ * is returned. Otherwise, the result of the function is used as the new accumulator.
23
+ * If the iteration completes, the final accumulator is returned.
24
+ */
25
+ export declare function reduceCollection<T>(collection: BoxedExpression, fn: (acc: T, next: BoxedExpression) => T | null, initial: T): T | undefined;
26
+ export declare function fromRange(start: number, end: number): number[];
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const COMPLEX_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const CONTROL_STRUCTURES_LIBRARY: IdentifierDefinitions[];
@@ -1,4 +1,2 @@
1
- /* 0.25.1 */
2
- import { BoxedExpression } from '../boxed-expression/public';
1
+ /* 0.26.2 */
3
2
  export declare const CORE_LIBRARY: IdentifierDefinitions[];
4
- export declare function canonicalInvisibleOperator(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression | null;
@@ -0,0 +1,4 @@
1
+ /* 0.26.2 */
2
+ export declare function canonicalInvisibleOperator(ops: ReadonlyArray<BoxedExpression>, { engine: ce }: {
3
+ engine: IComputeEngine;
4
+ }): BoxedExpression | null;
@@ -1,5 +1,5 @@
1
- /* 0.25.1 */
2
- import { FunctionDefinition, IComputeEngine, IdentifierDefinitions, SymbolDefinition } from '../public';
1
+ /* 0.26.2 */
2
+ import { IComputeEngine, IdentifierDefinitions } from '../public';
3
3
  export declare function getStandardLibrary(categories: LibraryCategory[] | LibraryCategory | 'all'): readonly IdentifierDefinitions[];
4
4
  export declare const LIBRARIES: {
5
5
  [category in LibraryCategory]?: IdentifierDefinitions | IdentifierDefinitions[];
@@ -15,5 +15,3 @@ export declare const LIBRARIES: {
15
15
  *
16
16
  */
17
17
  export declare function setIdentifierDefinitions(engine: IComputeEngine, table: IdentifierDefinitions): void;
18
- export declare function isSymbolDefinition(def: any): def is SymbolDefinition;
19
- export declare function isFunctionDefinition(def: any): def is FunctionDefinition;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const LINEAR_ALGEBRA_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,6 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const LOGIC_LIBRARY: IdentifierDefinitions;
3
+ export declare function simplifyLogicFunction(x: BoxedExpression): {
4
+ value: BoxedExpression;
5
+ because: string;
6
+ } | undefined;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const POLYNOMIALS_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare function randomExpression(level?: number): Expression;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const RELOP_LIBRARY: IdentifierDefinitions;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const SETS_LIBRARY: IdentifierDefinitions;
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const STATISTICS_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
2
  export declare const TRIGONOMETRY_LIBRARY: IdentifierDefinitions[];
@@ -1,51 +1,57 @@
1
- /* 0.25.1 */
1
+ /* 0.26.2 */
2
+ export type IndexingSet = {
3
+ index: string | undefined;
4
+ lower: number;
5
+ upper: number;
6
+ isFinite: boolean;
7
+ };
2
8
  /**
3
- * Assume the caller has setup a scope. The index
4
- * variable will be declared in that scope.
5
- *
6
- * @param indexingSet
7
-
8
9
  * IndexingSet is an expression describing an index variable
9
10
  * and a range of values for that variable.
10
11
  *
11
- * The MultiIndexingSet function takes an expression of the form
12
- * \sum_{i=1,j=1}^{10,10} x and returns an array of expressions
13
- * ["Sum","x",["Triple","i",1,10],["Triple","j",1,10]
14
- */
15
- export declare function MultiIndexingSet(indexingSet: BoxedExpression | undefined): ReadonlyArray<BoxedExpression> | undefined;
16
- /**
17
- * Assume the caller has setup a scope. The index
18
- * variable will be declared in that scope.
19
- *
20
- * @param indexingSet
21
-
22
- * IndexingSet is an expression describing an index variable
23
- * and a range of values for that variable.
24
- *
25
- * The SingleIndexingSet function takes an expression of the form
26
- * \sum_{i=1}^{10} x and returns an array of expressions
27
- * ["Sum","x",["Triple","i",1,10]
28
- */
29
- export declare function SingleIndexingSet(indexingSet: BoxedExpression | undefined): BoxedExpression | undefined;
30
- /**
31
- * IndexingSet is an expression describing an index variable
32
- * and a range of values for that variable.
12
+ * Note that when this function is called the indexing set is assumed to be canonical: 'Hold' has been handled, the indexing set is a tuple, and the bounds are canonical.
33
13
  *
34
14
  * This can take several valid forms:
35
15
  * - a symbol, e.g. `n`, the upper and lower bounds are assumed ot be infinity
36
- * - a tuple, e.g. `["Pair", "n", 1]` or `["Tuple", "n", 1, 10]` with one or two bounds
16
+ * - a tuple, e.g. `["Pair", "n", 1]` or `["Tuple", "n", 1, 10]` with one
17
+ * or two bounds
37
18
  *
38
- * The result is a normalized version that includes the
39
- * index, the lower and upper bounds of the range, and
40
- * a flag indicating whether the range is finite.
41
- * @param limits
19
+ * The result is a normalized version that includes the index, the lower and
20
+ * upper bounds of the range, and a flag indicating whether the range is finite.
21
+ * @param indexingSet
42
22
  * @returns
43
23
  */
44
- export declare function normalizeIndexingSet(limits: BoxedExpression | undefined): [
45
- index: string | undefined,
46
- lower: number,
47
- upper: number,
48
- isFinite: boolean
49
- ];
24
+ export declare function normalizeIndexingSet(indexingSet: BoxedExpression): IndexingSet;
25
+ export declare function normalizeIndexingSets(ops: ReadonlyArray<BoxedExpression>): IndexingSet[];
26
+ export declare function indexingSetCartestianProduct(indexingSets: IndexingSet[]): number[][];
27
+ /**
28
+ * Calculates the cartesian product of two arrays.
29
+ * ```ts
30
+ * // Example usage
31
+ * const array1 = [1, 2, 3];
32
+ * const array2 = ['a', 'b', 'c'];
33
+ * const result = cartesianProduct(array1, array2);
34
+ * console.log(result);
35
+ * // Output: [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c'], [3, 'a'], [3, 'b'], [3, 'c']]
36
+ * ```
37
+ * @param array1 - The first array.
38
+ * @param array2 - The second array.
39
+ * @returns The cartesian product as a 2D array.
40
+ */
50
41
  export declare function cartesianProduct(array1: number[], array2: number[]): number[][];
51
- export declare function range(start: number, end: number): number[];
42
+ export declare function canonicalIndexingSet(expr: BoxedExpression): BoxedExpression | undefined;
43
+ export declare function canonicalBigop(operator: string, body: BoxedExpression, indexingSets: BoxedExpression[]): BoxedExpression | null;
44
+ /**
45
+ * Process an expression of the form
46
+ * - ['Operator', body, ['Tuple', index1, lower, upper]]
47
+ * - ['Operator', body, ['Tuple', index1, lower, upper], ['Tuple', index2, lower, upper], ...]
48
+ * - ['Operator', body]
49
+ * - ['Operator', collection]
50
+ *
51
+ * `fn()` is the processing done on each element
52
+ */
53
+ /**
54
+ * Apply the function `fn` to the body of a big operator, according to the
55
+ * indexing sets.
56
+ */
57
+ export declare function reduceBigOp<T>(body: BoxedExpression, indexes: ReadonlyArray<BoxedExpression>, fn: (acc: T, x: BoxedExpression) => T | null, initial: T): T | undefined;
@@ -0,0 +1,59 @@
1
+ /* 0.26.2 */
2
+ import { NumericValue, NumericValueData } from './public';
3
+ import { ExactNumericValue } from './exact-numeric-value';
4
+ import { Expression } from '../../math-json/types';
5
+ import { SmallInteger } from '../numerics/numeric';
6
+ import { NumericType } from '../../common/type/types';
7
+ export type BigNumFactory = (value: Decimal.Value) => Decimal;
8
+ export declare class BigNumericValue extends NumericValue {
9
+ __brand: 'BigNumericValue';
10
+ decimal: Decimal;
11
+ im: number;
12
+ bignum: BigNumFactory;
13
+ constructor(value: number | Decimal | NumericValueData, bignum: BigNumFactory);
14
+ get type(): NumericType;
15
+ get isExact(): boolean;
16
+ get asExact(): ExactNumericValue | undefined;
17
+ toJSON(): Expression;
18
+ toString(): string;
19
+ clone(value: number | Decimal | NumericValueData): BigNumericValue;
20
+ private _makeExact;
21
+ get re(): number;
22
+ get bignumRe(): Decimal;
23
+ get numerator(): BigNumericValue;
24
+ get denominator(): ExactNumericValue;
25
+ get isNaN(): boolean;
26
+ get isPositiveInfinity(): boolean;
27
+ get isNegativeInfinity(): boolean;
28
+ get isComplexInfinity(): boolean;
29
+ get isZero(): boolean;
30
+ isZeroWithTolerance(tolerance: number | Decimal): boolean;
31
+ get isOne(): boolean;
32
+ get isNegativeOne(): boolean;
33
+ sgn(): -1 | 0 | 1 | undefined;
34
+ N(): NumericValue;
35
+ neg(): BigNumericValue;
36
+ inv(): BigNumericValue;
37
+ add(other: number | NumericValue): NumericValue;
38
+ sub(other: NumericValue): NumericValue;
39
+ mul(other: number | Decimal | NumericValue): NumericValue;
40
+ div(other: SmallInteger | NumericValue): NumericValue;
41
+ pow(exponent: number | NumericValue | {
42
+ re: number;
43
+ im: number;
44
+ }): NumericValue;
45
+ root(exp: number): NumericValue;
46
+ sqrt(): NumericValue;
47
+ gcd(other: NumericValue): NumericValue;
48
+ abs(): NumericValue;
49
+ ln(base?: number): NumericValue;
50
+ exp(): NumericValue;
51
+ floor(): NumericValue;
52
+ ceil(): NumericValue;
53
+ round(): NumericValue;
54
+ eq(other: number | NumericValue): boolean;
55
+ lt(other: number | NumericValue): boolean | undefined;
56
+ lte(other: number | NumericValue): boolean | undefined;
57
+ gt(other: number | NumericValue): boolean | undefined;
58
+ gte(other: number | NumericValue): boolean | undefined;
59
+ }