@cortex-js/compute-engine 0.29.1 → 0.30.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 (150) hide show
  1. package/dist/compute-engine.esm.js +28319 -24614
  2. package/dist/compute-engine.min.esm.js +70 -68
  3. package/dist/compute-engine.min.umd.js +131 -0
  4. package/dist/{compute-engine.cjs → compute-engine.umd.js} +29615 -25910
  5. package/dist/math-json.esm.js +22 -294
  6. package/dist/math-json.min.esm.js +22 -294
  7. package/dist/math-json.min.umd.js +4 -0
  8. package/dist/math-json.umd.js +141 -0
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +28 -0
  11. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +1 -1
  14. package/dist/types/common/one-of.d.ts +1 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/boxed-type.d.ts +20 -4
  17. package/dist/types/common/type/parse.d.ts +4 -4
  18. package/dist/types/common/type/primitive.d.ts +3 -2
  19. package/dist/types/common/type/serialize.d.ts +1 -1
  20. package/dist/types/common/type/subtype.d.ts +1 -1
  21. package/dist/types/common/type/types.d.ts +91 -25
  22. package/dist/types/common/type/utils.d.ts +2 -1
  23. package/dist/types/common/utils.d.ts +1 -1
  24. package/dist/types/compute-engine/assume.d.ts +2 -2
  25. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +72 -73
  26. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +2 -2
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +19 -1
  30. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/box.d.ts +6 -6
  32. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +42 -0
  33. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +48 -27
  34. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +17 -5
  35. package/dist/types/compute-engine/boxed-expression/{boxed-function-definition.d.ts → boxed-operator-definition.d.ts} +12 -12
  36. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +7 -8
  38. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +91 -52
  39. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +22 -25
  40. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
  41. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
  43. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -2
  44. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/hold.d.ts +2 -2
  50. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +30 -3
  53. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/product.d.ts +2 -2
  56. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +41 -1
  59. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/solve.d.ts +3 -1
  61. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/utils.d.ts +23 -23
  64. package/dist/types/compute-engine/boxed-expression/validate.d.ts +2 -1
  65. package/dist/types/compute-engine/collection-utils.d.ts +22 -57
  66. package/dist/types/compute-engine/compile.d.ts +61 -10
  67. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  68. package/dist/types/compute-engine/function-utils.d.ts +46 -29
  69. package/dist/types/compute-engine/global-types.d.ts +1432 -893
  70. package/dist/types/compute-engine/index.d.ts +154 -124
  71. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  72. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +3 -3
  85. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  86. package/dist/types/compute-engine/latex-syntax/parse.d.ts +14 -12
  87. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  88. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  89. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  90. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/types.d.ts +51 -39
  92. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  93. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
  94. package/dist/types/compute-engine/library/calculus.d.ts +2 -2
  95. package/dist/types/compute-engine/library/collections.d.ts +3 -3
  96. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  97. package/dist/types/compute-engine/library/complex.d.ts +2 -2
  98. package/dist/types/compute-engine/library/control-structures.d.ts +2 -2
  99. package/dist/types/compute-engine/library/core.d.ts +2 -2
  100. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  101. package/dist/types/compute-engine/library/library.d.ts +5 -5
  102. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -2
  103. package/dist/types/compute-engine/library/logic.d.ts +2 -2
  104. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  105. package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
  106. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  107. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
  108. package/dist/types/compute-engine/library/sets.d.ts +2 -2
  109. package/dist/types/compute-engine/library/statistics.d.ts +2 -2
  110. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
  111. package/dist/types/compute-engine/library/utils.d.ts +24 -2
  112. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +3 -4
  113. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +3 -3
  114. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +3 -4
  115. package/dist/types/compute-engine/numeric-value/types.d.ts +7 -5
  116. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  117. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  118. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  119. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -19
  120. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  121. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -1
  124. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  125. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  129. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  130. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  131. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  132. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -4
  133. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  134. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  135. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +5 -46
  136. package/dist/types/compute-engine/tensor/tensors.d.ts +4 -14
  137. package/dist/types/compute-engine/types.d.ts +1 -4
  138. package/dist/types/compute-engine.d.ts +1 -1
  139. package/dist/types/math-json/symbols.d.ts +11 -0
  140. package/dist/types/math-json/types.d.ts +19 -11
  141. package/dist/types/math-json/utils.d.ts +18 -9
  142. package/dist/types/math-json.d.ts +2 -2
  143. package/package.json +9 -11
  144. package/dist/compute-engine.min.cjs +0 -129
  145. package/dist/math-json.cjs +0 -413
  146. package/dist/math-json.min.cjs +0 -6
  147. package/dist/types/common/json5.d.ts +0 -3
  148. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +0 -64
  149. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +0 -21
  150. package/dist/types/math-json/identifiers.d.ts +0 -11
@@ -1,6 +1,8 @@
1
- /* 0.29.1 */
2
- import { ParseLatexOptions, LatexToken, Terminator, Parser, SymbolTable, SymbolType } from './types';
1
+ /* 0.30.0 */
2
+ import { ParseLatexOptions, LatexToken, Terminator, Parser, SymbolTable } from './types';
3
3
  import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
4
+ import { BoxedType } from '../../common/type/boxed-type';
5
+ import { TypeString } from '../types';
4
6
  /**
5
7
  * ## THEORY OF OPERATIONS
6
8
  *
@@ -17,7 +19,7 @@ import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixE
17
19
  * a function to interpret the expression as a function application.
18
20
  *
19
21
  * The parser uses the current state of the compute engine, and any
20
- * identifier that may have been declared, to determine the correct
22
+ * symbol that may have been declared, to determine the correct
21
23
  * interpretation.
22
24
  *
23
25
  * Some constructs declare variables or functions while parsing. For example,
@@ -25,9 +27,9 @@ import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixE
25
27
  *
26
28
  * The parser keeps track of the parsing state with a stack of symbol tables.
27
29
  *
28
- * In addition, the handler `getIdentifierType()` is called when the parser
29
- * encounters an unknown identifier. This handler can be used to declare the
30
- * identifier, or to return `unknown` if the identifier is not known.
30
+ * In addition, the handler `getSymbolType()` is called when the parser
31
+ * encounters an unknown symbol. This handler can be used to declare the
32
+ * symbol, or to return `unknown` if the symbol is not known.
31
33
  *
32
34
  * Some functions affect the state of the parser:
33
35
  * - `Declare`, `Assign` modify the symbol table
@@ -42,7 +44,7 @@ export declare class _Parser implements Parser {
42
44
  symbolTable: SymbolTable;
43
45
  pushSymbolTable(): void;
44
46
  popSymbolTable(): void;
45
- addSymbol(id: string, type: SymbolType): void;
47
+ addSymbol(id: string, type: BoxedType | TypeString): void;
46
48
  get index(): number;
47
49
  set index(val: number);
48
50
  private _tokens;
@@ -62,7 +64,7 @@ export declare class _Parser implements Parser {
62
64
  private _lastPeek;
63
65
  private _peekCounter;
64
66
  constructor(tokens: LatexToken[], dictionary: IndexedLatexDictionary, options: Readonly<ParseLatexOptions>);
65
- getIdentifierType(id: MathJsonIdentifier): SymbolType;
67
+ getSymbolType(id: MathJsonSymbol): BoxedType;
66
68
  get peek(): LatexToken;
67
69
  nextToken(): LatexToken;
68
70
  get atEnd(): boolean;
@@ -140,8 +142,8 @@ export declare class _Parser implements Parser {
140
142
  * > (radix 16, preceded by "), an alphabetic constant (preceded by `), or
141
143
  * > an internal variable.
142
144
  */
143
- matchLatexNumber(isInteger?: boolean): null | number;
144
- matchChar(): string | null;
145
+ parseLatexNumber(isInteger?: boolean): null | number;
146
+ parseChar(): string | null;
145
147
  /**
146
148
  *
147
149
  * If the next token matches the open delimiter, set a boundary with
@@ -167,7 +169,7 @@ export declare class _Parser implements Parser {
167
169
  * and empty cells are also indicated with `Nothing`.
168
170
  */
169
171
  parseTabular(): null | Expression[][];
170
- /** Match a string used as a LaTeX identifier, for example an environment
172
+ /** Match a string used as a LaTeX symbol, for example an environment
171
173
  * name.
172
174
  * Not suitable for general purpose text, e.g. argument of a `\text{}
173
175
  * command. See `matchChar()` instead.
@@ -224,7 +226,7 @@ export declare class _Parser implements Parser {
224
226
  */
225
227
  private parseGenericExpression;
226
228
  /**
227
- * A function is an identifier followed by postfix operators
229
+ * A function is an symbol followed by postfix operators
228
230
  * (`\prime`...) and some arguments.
229
231
  */
230
232
  private parseFunction;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { NumberSerializationFormat } from './types';
3
3
  /**
4
4
  * @param expr - A number, can be represented as a string
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { DelimiterScale } from './types';
3
3
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): DelimiterScale;
4
4
  export declare function getGroupStyle(_expr: Expression, _level: number): DelimiterScale;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { LatexString, SerializeLatexOptions, DelimiterScale } from './types';
3
3
  import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
4
4
  export declare class Serializer {
@@ -14,7 +14,7 @@ export declare class Serializer {
14
14
  wrap(expr: Expression | null | undefined, prec?: number): string;
15
15
  /**
16
16
  * If this is a "short" expression, wrap it.
17
- * Do not wrap identifiers, positive numbers or functions.
17
+ * Do not wrap symbols, positive numbers or functions.
18
18
  *
19
19
  * This is called by the serializer for power and division (i.e. "(a+1)/b")
20
20
  *
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.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,11 +1,11 @@
1
- /* 0.29.1 */
2
- import type { Expression, MathJsonIdentifier } from '../../math-json/types';
1
+ /* 0.30.0 */
2
+ import type { Expression, MathJsonSymbol } from '../../math-json/types';
3
+ import { BoxedType, TypeString } from '../types';
3
4
  import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
4
- export type SymbolType = 'symbol' | 'function' | 'unknown';
5
5
  export type SymbolTable = {
6
6
  parent: SymbolTable | null;
7
7
  ids: {
8
- [id: MathJsonIdentifier]: SymbolType;
8
+ [id: MathJsonSymbol]: BoxedType;
9
9
  };
10
10
  };
11
11
  /**
@@ -30,13 +30,13 @@ export type LatexString = string;
30
30
  *
31
31
  * @category Latex Parsing and Serialization
32
32
  */
33
- export type Delimiter = ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor' | '\\llbracket' | '\\rrbracket';
33
+ export type Delimiter = '.' | ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor' | '\\llbracket' | '\\rrbracket';
34
34
  /** @category Latex Parsing and Serialization */
35
35
  export type DelimiterScale = 'normal' | 'scaled' | 'big' | 'none';
36
36
  /**
37
37
  * @category Latex Parsing and Serialization
38
38
  */
39
- export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'control-structures' | 'combinatorics' | 'complex' | 'core' | 'data-structures' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'styling' | 'symbols' | 'trigonometry' | 'units';
39
+ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'control-structures' | 'combinatorics' | 'complex' | 'core' | 'data-structures' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'number-theory' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'styling' | 'symbols' | 'trigonometry' | 'units';
40
40
  /**
41
41
  *
42
42
  * :::info[THEORY OF OPERATIONS]
@@ -119,25 +119,32 @@ export type Terminator = {
119
119
  condition?: (parser: Parser) => boolean;
120
120
  };
121
121
  /**
122
- * Custom parsing handler.
122
+ * **Custom parsing handler.**
123
123
  *
124
- * When invoked the parser points right after the LaTeX fragment that triggered
125
- * this parsing handler.
124
+ * When this handler is invoked the parser points right after the LaTeX
125
+ * fragment that triggered it.
126
126
  *
127
- * The parser should be moved, by calling `parser.nextToken()` for
128
- * every consumed token.
127
+ * Tokens can be consumed with `parser.nextToken()` and other parser methods
128
+ * such as `parser.parseGroup()`, `parser.parseOptionalGroup()`, etc...
129
129
  *
130
130
  * If it was in an infix or postfix context, `lhs` will represent the
131
131
  * left-hand side argument. In a prefix or matchfix context, `lhs` is `null`.
132
132
  *
133
- * In a superfix (^) or subfix (_) context (that is if the first token of the
134
- * trigger is `^` or `_`), lhs is `["Superscript", lhs, rhs]`
133
+ * In a superfix (`^`) or subfix (`_`) context (that is if the first token of
134
+ * the trigger is `^` or `_`), `lhs` is `["Superscript", lhs, rhs]`
135
135
  * and `["Subscript", lhs, rhs]`, respectively.
136
136
  *
137
- * The handler should return `null` if the expression could not be parsed
138
- * (didn't match the syntax that was expected). The matching expression
137
+ * The handler should return `null` if the tokens could not be parsed
138
+ * (didn't match the syntax that was expected), or the matching expression
139
139
  * otherwise.
140
140
  *
141
+ * If the tokens were parsed but should be ignored, the handler should
142
+ * return `Nothing`.
143
+ *
144
+ * @category Latex Parsing and Serialization
145
+ */
146
+ export type ParseHandler = ExpressionParseHandler | SymbolParseHandler | FunctionParseHandler | EnvironmentParseHandler | PostfixParseHandler | InfixParseHandler | MatchfixParseHandler;
147
+ /**
141
148
  * @category Latex Parsing and Serialization
142
149
  */
143
150
  export type ExpressionParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
@@ -179,9 +186,9 @@ export type LatexArgumentType = '{expression}' /** A required math mode expressi
179
186
  * If the trigger matches, the `parse` handler is called, if available.
180
187
  *
181
188
  * The trigger can be specified either as a LaTeX string (`latexTrigger`) or
182
- * as an identifier (`identifierTrigger`). An identifier match several
183
- * LaTeEx expressions that are equivalent, for example `\operatorname{gcd}` or
184
- * `\mathbin{gcd}`, match the `"gcd"` identifier
189
+ * as an symbol (`symbolTrigger`). A symbol match several
190
+ * LaTeX expressions that are equivalent, for example `\operatorname{gcd}` or
191
+ * `\mathbin{gcd}`, match the `"gcd"` symbol
185
192
  *
186
193
  * `matchfix` operators use `openTrigger` and `closeTrigger` instead.
187
194
  *
@@ -189,7 +196,7 @@ export type LatexArgumentType = '{expression}' /** A required math mode expressi
189
196
  */
190
197
  export type Trigger = {
191
198
  latexTrigger?: LatexString | LatexToken[];
192
- identifierTrigger?: MathJsonIdentifier;
199
+ symbolTrigger?: MathJsonSymbol;
193
200
  };
194
201
  /**
195
202
  * Maps a string of LaTeX tokens to a function or symbol and vice-versa.
@@ -197,7 +204,7 @@ export type Trigger = {
197
204
  */
198
205
  export type BaseEntry = {
199
206
  /**
200
- * Map a MathJSON identifier to this entry.
207
+ * Map a MathJSON symbol to this entry.
201
208
  *
202
209
  * Each entry should have at least a `name` or a `parse` handler.
203
210
  *
@@ -212,7 +219,7 @@ export type BaseEntry = {
212
219
  * entry. Otherwise, if the trigger of the entry matches the current
213
220
  * token, the `parse` handler is invoked.
214
221
  */
215
- name?: MathJsonIdentifier;
222
+ name?: MathJsonSymbol;
216
223
  /**
217
224
  * Transform an expression into a LaTeX string.
218
225
  * If no `serialize` handler is provided, the trigger is used.
@@ -308,7 +315,7 @@ export type PrefixEntry = BaseEntry & Trigger & {
308
315
  export type EnvironmentEntry = BaseEntry & {
309
316
  kind: 'environment';
310
317
  parse: EnvironmentParseHandler;
311
- identifierTrigger: MathJsonIdentifier;
318
+ symbolTrigger: MathJsonSymbol;
312
319
  };
313
320
  /**
314
321
  * @category Latex Parsing and Serialization
@@ -320,7 +327,7 @@ export type SymbolEntry = BaseEntry & Trigger & {
320
327
  parse: Expression | SymbolParseHandler;
321
328
  };
322
329
  /**
323
- * A function is an identifier followed by:
330
+ * A function is a symbol followed by:
324
331
  * - some postfix operators such as `\prime`
325
332
  * - an optional list of arguments in an enclosure (parentheses)
326
333
  *
@@ -479,21 +486,13 @@ export type ParseLatexOptions = NumberFormat & {
479
486
  */
480
487
  parseNumbers: 'auto' | 'rational' | 'decimal' | 'never';
481
488
  /**
482
- * This handler is invoked when the parser encounters an identifier
489
+ * This handler is invoked when the parser encounters a
483
490
  * that has not yet been declared.
484
491
  *
485
- * The `identifier` argument is a [valid identifier](/math-json/#identifiers).
492
+ * The `symbol` argument is a [valid symbol](/math-json/#symbols).
486
493
  *
487
- * The handler can return:
488
- *
489
- * - `"variable"`: the identifier is a variable
490
- * - `"function"`: the identifier is a function name. If an apply
491
- * function operator (typically, parentheses) follow, they will be parsed
492
- * as arguments to the function.
493
- *
494
- * - `"unknown"`: the identifier is not recognized.
495
494
  */
496
- getIdentifierType: (identifier: MathJsonIdentifier) => SymbolType;
495
+ getSymbolType: (symbol: MathJsonSymbol) => BoxedType;
497
496
  /** This handler is invoked when the parser encounters an unexpected token.
498
497
  *
499
498
  * The `lhs` argument is the left-hand side of the token, if any.
@@ -535,10 +534,10 @@ export type ParseLatexOptions = NumberFormat & {
535
534
  */
536
535
  export interface Parser {
537
536
  readonly options: Required<ParseLatexOptions>;
538
- getIdentifierType(id: MathJsonIdentifier): SymbolType;
537
+ getSymbolType(id: MathJsonSymbol): BoxedType;
539
538
  pushSymbolTable(): void;
540
539
  popSymbolTable(): void;
541
- addSymbol(id: MathJsonIdentifier, type: SymbolType): void;
540
+ addSymbol(id: MathJsonSymbol, type: BoxedType | TypeString): void;
542
541
  /** The index of the current token */
543
542
  index: number;
544
543
  /** True if the last token has been reached.
@@ -580,7 +579,7 @@ export interface Parser {
580
579
  * This includes plain characters (e.g. 'a', '+'...), characters
581
580
  * defined in hex (^^ and ^^^^), the `\char` and `\unicode` command.
582
581
  */
583
- matchChar(): string | null;
582
+ parseChar(): string | null;
584
583
  /**
585
584
  * Parse an expression in a LaTeX group enclosed in curly brackets `{}`.
586
585
  * These are often used as arguments to LaTeX commands, for example
@@ -631,9 +630,9 @@ export interface Parser {
631
630
  parseStringGroup(optional?: boolean): string | null;
632
631
  /**
633
632
  * A symbol can be:
634
- * - a single-letter identifier: `x`
633
+ * - a single-letter symbol: `x`
635
634
  * - a single LaTeX command: `\pi`
636
- * - a multi-letter identifier: `\operatorname{speed}`
635
+ * - a multi-letter symbol: `\operatorname{speed}`
637
636
  */
638
637
  parseSymbol(until?: Partial<Terminator>): Expression | null;
639
638
  /**
@@ -727,6 +726,19 @@ export type SerializeLatexOptions = NumberSerializationFormat & {
727
726
  *
728
727
  */
729
728
  prettify: boolean;
729
+ /**
730
+ * Controls the materialization of the lazy collections.
731
+ *
732
+ * - If `true`, lazy collections are materialized, i.e. it is rendered as a
733
+ * LaTeX expression with all its elements.
734
+ * - If `false`, the expression is not materialized, i.e. it is
735
+ * rendered as a LaTeX command with its arguments.
736
+ * - If a number is provided, it is the maximum number of elements
737
+ * that will be materialized.
738
+ * - If a pair of numbers is provided, it is the number of elements
739
+ * of the head and the tail that will be materialized, respectively.
740
+ */
741
+ materialization: boolean | number | [number, number];
730
742
  /**
731
743
  * LaTeX string used to render an invisible multiply, e.g. in '2x'.
732
744
  *
@@ -0,0 +1,5 @@
1
+ /* 0.30.0 */
2
+ export declare function asLatexString(s: unknown): string | null;
3
+ export declare function isRelationalOperator(name: string | undefined): boolean;
4
+ export declare function isInequalityOperator(operator: string | undefined): boolean;
5
+ export declare function isEquationOperator(operator: string | undefined): boolean;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export type CanonicalArithmeticOperators = 'Add' | 'Negate' | 'Multiply' | 'Divide' | 'Power' | 'Sqrt' | 'Root' | 'Ln';
3
- export declare const ARITHMETIC_LIBRARY: IdentifierDefinitions[];
3
+ export declare const ARITHMETIC_LIBRARY: SymbolDefinitions[];
4
4
  export declare function isPrime(expr: BoxedExpression): boolean | undefined;
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const CALCULUS_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const CALCULUS_LIBRARY: SymbolDefinitions[];
@@ -1,6 +1,6 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export declare const DEFAULT_LINSPACE_COUNT = 50;
3
- export declare const COLLECTIONS_LIBRARY: IdentifierDefinitions;
3
+ export declare const COLLECTIONS_LIBRARY: SymbolDefinitions;
4
4
  /**
5
5
  * Normalize the arguments of range:
6
6
  * - [from, to] -> [from, to, 1] if to > from, or [from, to, -1] if to < from
@@ -24,4 +24,4 @@ export declare function rangeLast(r: [lower: number, upper: number, step: number
24
24
  */
25
25
  export declare function reduceCollection<T>(collection: BoxedExpression, fn: (acc: T, next: BoxedExpression) => T | null, initial: T): Generator<T | undefined>;
26
26
  export declare function fromRange(start: number, end: number): number[];
27
- export declare function canonicalDictionary(engine: ComputeEngine, dict: BoxedExpression): BoxedExpression;
27
+ export declare function sortedIndices(expr: BoxedExpression, fn?: BoxedExpression | undefined): number[] | undefined;
@@ -0,0 +1,2 @@
1
+ /* 0.30.0 */
2
+ export declare const COMBINATORICS_LIBRARY: SymbolDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const COMPLEX_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const COMPLEX_LIBRARY: SymbolDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const CONTROL_STRUCTURES_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const CONTROL_STRUCTURES_LIBRARY: SymbolDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const CORE_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const CORE_LIBRARY: SymbolDefinitions[];
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export declare function canonicalInvisibleOperator(ops: ReadonlyArray<BoxedExpression>, { engine: ce }: {
3
3
  engine: ComputeEngine;
4
4
  }): BoxedExpression | null;
@@ -1,8 +1,8 @@
1
- /* 0.29.1 */
2
- import type { IdentifierDefinitions, ComputeEngine } from '../global-types';
3
- export declare function getStandardLibrary(categories: LibraryCategory[] | LibraryCategory | 'all'): readonly IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ import type { SymbolDefinitions, ComputeEngine } from '../global-types';
3
+ export declare function getStandardLibrary(categories: LibraryCategory[] | LibraryCategory | 'all'): readonly SymbolDefinitions[];
4
4
  export declare const LIBRARIES: {
5
- [category in LibraryCategory]?: IdentifierDefinitions | IdentifierDefinitions[];
5
+ [category in LibraryCategory]?: SymbolDefinitions | SymbolDefinitions[];
6
6
  };
7
7
  /**
8
8
  * Set the symbol table of the current context (`engine.context`) to `table`
@@ -14,4 +14,4 @@ export declare const LIBRARIES: {
14
14
  * or function name that has not yet been added to the symbol table.
15
15
  *
16
16
  */
17
- export declare function setIdentifierDefinitions(engine: ComputeEngine, table: IdentifierDefinitions): void;
17
+ export declare function setSymbolDefinitions(engine: ComputeEngine, table: SymbolDefinitions): void;
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const LINEAR_ALGEBRA_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const LINEAR_ALGEBRA_LIBRARY: SymbolDefinitions[];
@@ -1,5 +1,5 @@
1
- /* 0.29.1 */
2
- export declare const LOGIC_LIBRARY: IdentifierDefinitions;
1
+ /* 0.30.0 */
2
+ export declare const LOGIC_LIBRARY: SymbolDefinitions;
3
3
  export declare function simplifyLogicFunction(x: BoxedExpression): {
4
4
  value: BoxedExpression;
5
5
  because: string;
@@ -0,0 +1,2 @@
1
+ /* 0.30.0 */
2
+ export declare const NUMBER_THEORY_LIBRARY: SymbolDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const POLYNOMIALS_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const POLYNOMIALS_LIBRARY: SymbolDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export declare function randomExpression(level?: number): Expression;
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const RELOP_LIBRARY: IdentifierDefinitions;
1
+ /* 0.30.0 */
2
+ export declare const RELOP_LIBRARY: SymbolDefinitions;
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const SETS_LIBRARY: IdentifierDefinitions;
1
+ /* 0.30.0 */
2
+ export declare const SETS_LIBRARY: SymbolDefinitions;
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const STATISTICS_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const STATISTICS_LIBRARY: SymbolDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare const TRIGONOMETRY_LIBRARY: IdentifierDefinitions[];
1
+ /* 0.30.0 */
2
+ export declare const TRIGONOMETRY_LIBRARY: SymbolDefinitions[];
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export type IndexingSet = {
3
3
  index: string | undefined;
4
4
  lower: number;
@@ -39,8 +39,30 @@ export declare function indexingSetCartesianProduct(indexingSets: IndexingSet[])
39
39
  * @returns The cartesian product as a 2D array.
40
40
  */
41
41
  export declare function cartesianProduct(array1: number[], array2: number[]): number[][];
42
+ /** Given a sequence of arguments, return an array of Limits:
43
+ *
44
+ * - ["Range", 1, 10] -> ["Limits", "Unknown", 1, 10]
45
+ * - 1, 10 -> ["Limits", "Nothing", 1, 10]
46
+ * - [Tuple, "x", 1, 10] -> ["Limits", "x", 1, 10]
47
+ *
48
+ */
49
+ export declare function canonicalLimitsSequence(ops: ReadonlyArray<BoxedExpression>, options: {
50
+ engine: ComputeEngine;
51
+ }): BoxedExpression[];
52
+ export declare function canonicalLimits(ops: ReadonlyArray<BoxedExpression>, { engine: ce }: {
53
+ engine: ComputeEngine;
54
+ }): BoxedExpression | null;
55
+ /** Return a limit/indexing set in canonical form as a `Limits` expression
56
+ * with:
57
+ * - `index` (a symbol), `Nothing` if none is present
58
+ * - `lower` (a number), `Nothing` if none is present
59
+ * - `upper` (a number), `Nothing` if none is present
60
+ *
61
+ * Assume we are in the context of a big operator
62
+ * (i.e. `pushScope()` has been called)
63
+ */
42
64
  export declare function canonicalIndexingSet(expr: BoxedExpression): BoxedExpression | undefined;
43
- export declare function canonicalBigop(operator: string, body: BoxedExpression, indexingSets: BoxedExpression[]): BoxedExpression | null;
65
+ export declare function canonicalBigop(bigOp: string, body: BoxedExpression, indexingSets: BoxedExpression[], scope: Scope | undefined): BoxedExpression | null;
44
66
  /**
45
67
  * Process an expression of the form
46
68
  * - ['Operator', body, ['Tuple', index1, lower, upper]]
@@ -1,16 +1,15 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { BigNumFactory, NumericValue, NumericValueData } from './types';
3
3
  import { ExactNumericValue } from './exact-numeric-value';
4
4
  import { Expression } from '../../math-json/types';
5
5
  import { SmallInteger } from '../numerics/types';
6
- import { NumericType } from '../../common/type/types';
6
+ import { NumericPrimitiveType } from '../../common/type/types';
7
7
  export declare class BigNumericValue extends NumericValue {
8
8
  __brand: 'BigNumericValue';
9
9
  decimal: Decimal;
10
- im: number;
11
10
  bignum: BigNumFactory;
12
11
  constructor(value: number | Decimal | NumericValueData, bignum: BigNumFactory);
13
- get type(): NumericType;
12
+ get type(): NumericPrimitiveType;
14
13
  get isExact(): boolean;
15
14
  get asExact(): ExactNumericValue | undefined;
16
15
  toJSON(): Expression;
@@ -1,8 +1,8 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { Rational, SmallInteger } from '../numerics/types';
3
3
  import { BigNumFactory, ExactNumericValueData, NumericValue, NumericValueFactory } from './types';
4
4
  import { Expression } from '../../math-json/types';
5
- import { NumericType } from '../../common/type/types';
5
+ import { NumericPrimitiveType } from '../../common/type/types';
6
6
  /**
7
7
  * An ExactNumericValue is the sum of a Gaussian imaginary and the product of
8
8
  * a rational number and a square root:
@@ -25,7 +25,7 @@ export declare class ExactNumericValue extends NumericValue {
25
25
  * - radical is an integer
26
26
  */
27
27
  constructor(value: number | bigint | ExactNumericValueData, factory: NumericValueFactory, bignum: BigNumFactory);
28
- get type(): NumericType;
28
+ get type(): NumericPrimitiveType;
29
29
  get isExact(): boolean;
30
30
  get asExact(): NumericValue | undefined;
31
31
  toJSON(): Expression;
@@ -1,16 +1,15 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { BigNumFactory, NumericValue, NumericValueData } from './types';
3
3
  import type { Expression } from '../../math-json/types';
4
4
  import type { SmallInteger } from '../numerics/types';
5
- import { NumericType } from '../../common/type/types';
5
+ import { NumericPrimitiveType } from '../../common/type/types';
6
6
  export declare class MachineNumericValue extends NumericValue {
7
7
  __brand: 'MachineNumericValue';
8
8
  decimal: number;
9
- im: number;
10
9
  bignum: BigNumFactory;
11
10
  constructor(value: number | Decimal | NumericValueData, bignum: BigNumFactory);
12
11
  private _makeExact;
13
- get type(): NumericType;
12
+ get type(): NumericPrimitiveType;
14
13
  get isExact(): boolean;
15
14
  get asExact(): NumericValue | undefined;
16
15
  toJSON(): Expression;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  *
3
3
  * ## THEORY OF OPERATIONS
4
4
  *
@@ -25,7 +25,7 @@
25
25
  */
26
26
  import { Decimal } from 'decimal.js';
27
27
  import type { Rational, SmallInteger } from '../numerics/types';
28
- import { NumericType } from '../../common/type/types';
28
+ import { NumericPrimitiveType } from '../../common/type/types';
29
29
  export type BigNumFactory = (value: Decimal.Value) => Decimal;
30
30
  /** The value is equal to `(decimal * rational * sqrt(radical)) + im * i`
31
31
  * @category Numerics */
@@ -42,7 +42,7 @@ export type NumericValueData = {
42
42
  export type NumericValueFactory = (data: number | Decimal | NumericValueData) => NumericValue;
43
43
  /** @category Numerics */
44
44
  export declare abstract class NumericValue {
45
- abstract get type(): NumericType;
45
+ abstract get type(): NumericPrimitiveType;
46
46
  /** True if numeric value is the product of a rational and the square root of an integer.
47
47
  *
48
48
  * This includes: 3/4√5, -2, √2, etc...
@@ -65,7 +65,7 @@ export declare abstract class NumericValue {
65
65
  *
66
66
  * Can be negative, zero or positive.
67
67
  */
68
- readonly im: number;
68
+ im: number;
69
69
  get bignumIm(): Decimal | undefined;
70
70
  abstract get numerator(): NumericValue;
71
71
  abstract get denominator(): NumericValue;
@@ -79,6 +79,7 @@ export declare abstract class NumericValue {
79
79
  abstract get isNegativeOne(): boolean;
80
80
  /** The sign of complex numbers is undefined */
81
81
  abstract sgn(): -1 | 0 | 1 | undefined;
82
+ /** Return a non-exact representation of the numeric value */
82
83
  abstract N(): NumericValue;
83
84
  abstract neg(): NumericValue;
84
85
  abstract inv(): NumericValue;
@@ -104,7 +105,8 @@ export declare abstract class NumericValue {
104
105
  abstract lte(other: number | NumericValue): boolean | undefined;
105
106
  abstract gt(other: number | NumericValue): boolean | undefined;
106
107
  abstract gte(other: number | NumericValue): boolean | undefined;
107
- /** Object.valueOf(): returns a primitive value */
108
+ /** Object.valueOf(): returns a primitive value, preferably a JavaScript
109
+ * number over a string, even if at the expense of precision */
108
110
  valueOf(): number | string;
109
111
  /** Object.toPrimitive() */
110
112
  [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export declare function bigint(a: Decimal | number | bigint | string): bigint | null;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export declare function bigintValue(expr: Expression | null | undefined): bigint | null;
3
3
  /** Output a shorthand if possible */
4
4
  export declare function numberToExpression(num: number | bigint, fractionalDigits?: string | number): Expression;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  /** An interval is a continuous set of real numbers */
3
3
  export type Interval = {
4
4
  start: number;