@cortex-js/compute-engine 0.13.0 → 0.14.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 (90) hide show
  1. package/dist/compute-engine.esm.js +1304 -987
  2. package/dist/compute-engine.js +1304 -987
  3. package/dist/compute-engine.min.esm.js +1304 -987
  4. package/dist/compute-engine.min.js +1304 -987
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  10. package/dist/types/common/signals.d.ts +1 -1
  11. package/dist/types/common/utils.d.ts +1 -1
  12. package/dist/types/compute-engine/assume.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +4 -2
  14. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  29. package/dist/types/compute-engine/compile.d.ts +9 -2
  30. package/dist/types/compute-engine/compute-engine.d.ts +8 -7
  31. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  32. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +32 -17
  44. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +12 -6
  46. package/dist/types/compute-engine/latex-syntax/parse.d.ts +30 -20
  47. package/dist/types/compute-engine/latex-syntax/public.d.ts +90 -47
  48. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +4 -9
  51. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  52. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -2
  53. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  54. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  55. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  56. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  57. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  58. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  59. package/dist/types/compute-engine/library/core.d.ts +1 -1
  60. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  61. package/dist/types/compute-engine/library/library.d.ts +1 -1
  62. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  63. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  64. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  65. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  66. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  67. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  68. package/dist/types/compute-engine/library/utils.d.ts +2 -1
  69. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  70. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  71. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  72. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  73. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  74. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  75. package/dist/types/compute-engine/public.d.ts +4 -1
  76. package/dist/types/compute-engine/rules.d.ts +1 -1
  77. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  78. package/dist/types/compute-engine/solve.d.ts +1 -1
  79. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  80. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  81. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  82. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  83. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  84. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  85. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  86. package/dist/types/compute-engine.d.ts +2 -2
  87. package/dist/types/math-json/math-json-format.d.ts +1 -1
  88. package/dist/types/math-json/utils.d.ts +5 -1
  89. package/dist/types/math-json.d.ts +2 -2
  90. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import type { IComputeEngine } from '../public';
4
4
  /**
@@ -19,6 +19,42 @@ export type LatexString = string;
19
19
  */
20
20
  export type Delimiter = ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor';
21
21
  export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'control-structures' | 'combinatorics' | 'core' | 'data-structures' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'styling' | 'symbols' | 'trigonometry' | 'units';
22
+ /** Theory of operations:
23
+ *
24
+ * The precedence of an operator is a number that indicates the order in which
25
+ * operators are applied. For example, in `1 + 2 * 3`, the `*` operator has
26
+ * a higher precedence than the `+` operator, so it is applied first.
27
+ *
28
+ * The precendence range from 0 to 1000. The higher the number, the higher the
29
+ * precedence, the more "binding" the operator is.
30
+ *
31
+ * Here are some rough ranges for the precedence:
32
+ *
33
+ * - 800: prefix and postfix operators,
34
+ * e.g. `\lnot`, `!`, `'`, `\degree`, `++`, etc...
35
+ * - 700: some relational operators: `<`
36
+ * - 600: some binary operators: `\div`
37
+ * - 500: not used
38
+ * - 400: not used
39
+ * - 300: some logic and arithmetic operators:
40
+ * `\land`, `\lor`, `\times`, etc...
41
+ * - 200: arithmetic operators, inequalities:
42
+ * `+`, `-`, `=`, `<`, etc...
43
+ * - 260: `=`
44
+ * - 245: `\lt`, `\gt`
45
+ * - 241: `\leq`
46
+ * - 100: not used
47
+ * - 0: `,`, `;`, etc...
48
+ *
49
+ *
50
+ * Note: MathML defines some operator precendence, but it has some
51
+ * issues and inconsistencies. However, whenever possible we adopted the
52
+ * MathML precedence. See https://www.w3.org/TR/2009/WD-MathML3-20090924/appendixc.html
53
+ *
54
+ * For reference, the JavaScript operator precedence is documented
55
+ * here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence
56
+ */
57
+ export type Precedence = number;
22
58
  /**
23
59
  * This indicates a condition under which parsing should stop:
24
60
  * - an operator of a precedence higher than specified has been encountered
@@ -26,7 +62,7 @@ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collectio
26
62
  * - or if a condition is provided, the condition returns true;
27
63
  */
28
64
  export type Terminator = {
29
- minPrec: number;
65
+ minPrec: Precedence;
30
66
  condition?: (parser: Parser) => boolean;
31
67
  };
32
68
  /**
@@ -50,15 +86,33 @@ export type Terminator = {
50
86
  * otherwise.
51
87
  *
52
88
  */
53
- export type ExpressionParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
54
- export type PrefixParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
55
- export type SymbolParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
56
- export type FunctionParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
57
- export type EnvironmentParseHandler = (parser: Parser, reqArgs: Expression[], optArgs: Expression[]) => Expression | null;
58
- export type PostfixParseHandler = (parser: Parser, lhs: Expression, until?: Terminator) => Expression | null;
59
- export type InfixParseHandler = (parser: Parser, lhs: Expression, until: Terminator) => Expression | null;
89
+ export type ExpressionParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
90
+ export type PrefixParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
91
+ export type SymbolParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
92
+ export type FunctionParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
93
+ export type EnvironmentParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
94
+ export type PostfixParseHandler = (parser: Parser, lhs: Expression, until?: Readonly<Terminator>) => Expression | null;
95
+ export type InfixParseHandler = (parser: Parser, lhs: Expression, until: Readonly<Terminator>) => Expression | null;
60
96
  export type MatchfixParseHandler = (parser: Parser, body: Expression) => Expression | null;
61
97
  export type LatexArgumentType = '{expression}' /** A required math mode expression */ | '[expression]' /** An optional math mode expression */ | '{text}' /** A required expression in text mode */ | '[text]' /** An optional expression in text mode */ | '{unit}' /** A required unit expression, e.g. `3em` */ | '[unit]' /** An optional unit expression, e.g. `3em` */ | '{glue}' /** A required glue expression, e.g. `25 mu plus 3em ` */ | '[glue]' /** An optional glue expression, e.g. `25 mu plus 3em ` */ | '{string}' /** A required text string, terminated by a non-literal token */ | '[string]' /** An optional text string, terminated by a non-literal token */ | '{color}' /** A required color expression, e.g. `red` or `#00ff00` */ | '[color]'; /** An optional color expression, e.g. `red` or `#00ff00` */
98
+ /**
99
+ * The trigger is the set of tokens that will make this record eligible to
100
+ * parse the stream and generate an expression. If the trigger matches,
101
+ * the `parse` handler is called, if available.
102
+ *
103
+ * The trigger can be specified either as a LaTeX string (`latexTrigger`) or
104
+ * as an identifier (`identifierTrigger`), which can be wrapped in a LaTeX
105
+ * command, for example `\operatorname{mod}` or `\mathbin{gcd}`, with `"gcd"`
106
+ * being the `identifierTrigger`.
107
+ *
108
+ *
109
+ * `matchfix` operators use `openDelimiter` and `closeDelimiter` instead.
110
+ *
111
+ */
112
+ export type Trigger = {
113
+ latexTrigger?: LatexString | LatexToken[];
114
+ identifierTrigger?: string;
115
+ };
62
116
  /**
63
117
  * Maps a string of LaTeX tokens to a function or symbol and vice-versa.
64
118
  *
@@ -79,41 +133,34 @@ export type BaseEntry = {
79
133
  * token, the `parse` handler is invoked.
80
134
  */
81
135
  name?: string;
82
- /**
83
- * The trigger is the set of tokens that will make this record eligible for
84
- * attempting to parse the stream and generate an expression. After the
85
- * trigger matches, the `parse` handler is called, if available.
86
- *
87
- * `matchfix` operators use `openDelimiter` and `closeDelimiter` instead.
88
- *
89
- */
90
- trigger?: LatexString | LatexToken[];
91
136
  /**
92
137
  * Transform an expression into a LaTeX string.
93
138
  * If no `serialize` handler is provided, the `trigger` property is used
94
139
  */
95
140
  serialize?: LatexString | SerializeHandler;
96
- parse?: Expression | ExpressionParseHandler;
97
141
  };
98
- export type ExpressionEntry = Omit<BaseEntry, 'parse'> & {
142
+ export type DefaultEntry = BaseEntry & Trigger & {
143
+ parse: Expression | ExpressionParseHandler;
144
+ };
145
+ export type ExpressionEntry = BaseEntry & Trigger & {
99
146
  kind: 'expression';
100
147
  parse: Expression | ExpressionParseHandler;
101
148
  };
102
- export type MatchfixEntry = Omit<BaseEntry, 'parse'> & {
149
+ export type MatchfixEntry = BaseEntry & {
103
150
  kind: 'matchfix';
104
151
  /**
105
152
  * If `kind` is `'matchfix'`: the `closeDelimiter` and `openDelimiter`
106
153
  * property are required
107
154
  */
108
- openDelimiter?: Delimiter | LatexToken[];
109
- closeDelimiter?: Delimiter | LatexToken[];
155
+ openTrigger?: Delimiter | LatexToken[];
156
+ closeTrigger?: Delimiter | LatexToken[];
110
157
  /** When invoked, the parser is pointing after the close delimiter.
111
158
  * The argument of the handler is the body, i.e. the content between
112
159
  * the open delimiter and the close delimiter.
113
160
  */
114
161
  parse?: MatchfixParseHandler;
115
162
  };
116
- export type InfixEntry = Omit<BaseEntry, 'parse'> & {
163
+ export type InfixEntry = BaseEntry & Trigger & {
117
164
  /**
118
165
  * Infix position, with an operand before and an operand after: `a ⊛ b`.
119
166
  *
@@ -131,60 +178,58 @@ export type InfixEntry = Omit<BaseEntry, 'parse'> & {
131
178
  *
132
179
  */
133
180
  associativity?: 'right' | 'left' | 'non' | 'both';
134
- precedence?: number;
181
+ precedence?: Precedence;
135
182
  parse?: string | InfixParseHandler;
136
183
  };
137
- export type PostfixEntry = Omit<BaseEntry, 'parse'> & {
184
+ export type PostfixEntry = BaseEntry & Trigger & {
138
185
  /**
139
186
  * Postfix position, with an operand before: `a ⊛`
140
187
  *
141
188
  * Example: `!`.
142
189
  */
143
190
  kind: 'postfix';
144
- precedence?: number;
191
+ precedence?: Precedence;
145
192
  parse?: PostfixParseHandler;
146
193
  };
147
- export type PrefixEntry = Omit<BaseEntry, 'parse'> & {
194
+ export type PrefixEntry = BaseEntry & Trigger & {
148
195
  /**
149
196
  * Prefix position, with an operand after: `⊛ a`
150
197
  *
151
198
  * Example: `-`, `\not`.
152
199
  */
153
200
  kind: 'prefix';
154
- precedence: number;
201
+ precedence: Precedence;
155
202
  parse?: PrefixParseHandler;
156
203
  };
157
204
  /**
158
205
  * A LaTeX dictionary entry for an environment, that is a LaTeX
159
206
  * construct using `\begin{...}...\end{...}`.
160
207
  */
161
- export type EnvironmentEntry = Omit<BaseEntry, 'parse'> & {
208
+ export type EnvironmentEntry = BaseEntry & {
162
209
  kind: 'environment';
163
210
  parse: EnvironmentParseHandler;
211
+ identifierTrigger: string;
164
212
  };
165
- export type SymbolEntry = Omit<BaseEntry, 'parse'> & {
213
+ export type SymbolEntry = BaseEntry & Trigger & {
166
214
  kind: 'symbol';
167
215
  /** Used for appropriate wrapping (i.e. when to surround it with parens) */
168
- precedence?: number;
216
+ precedence?: Precedence;
169
217
  parse: Expression | SymbolParseHandler;
170
218
  };
171
219
  /**
172
- * A function has the following form:
173
- * - a prefix such as `\mathrm` or `\operatorname`
174
- * - a trigger string, such as `gcd`
220
+ * A function is an identifier followed by:
175
221
  * - some postfix operators such as `\prime`
176
222
  * - an optional list of arguments in an enclosure (parentheses)
177
223
  *
178
224
  * For more complex situations, for example implicit arguments or
179
225
  * inverse functions postfix (i.e. ^{-1}), use a custom parse handler with a
180
- * base entry.
226
+ * entry of kind `expression`.
181
227
  */
182
- export type FunctionEntry = Omit<BaseEntry, 'parse'> & {
228
+ export type FunctionEntry = BaseEntry & Trigger & {
183
229
  kind: 'function';
184
- trigger: string;
185
230
  parse?: Expression | FunctionParseHandler;
186
231
  };
187
- export type LatexDictionaryEntry = BaseEntry | ExpressionEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | SymbolEntry | FunctionEntry | EnvironmentEntry;
232
+ export type LatexDictionaryEntry = DefaultEntry | ExpressionEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | SymbolEntry | FunctionEntry | EnvironmentEntry;
188
233
  /** @internal */
189
234
  export declare function isExpressionEntry(entry: LatexDictionaryEntry): entry is ExpressionEntry;
190
235
  /** @internal */
@@ -201,7 +246,7 @@ export declare function isPrefixEntry(entry: LatexDictionaryEntry): entry is Pre
201
246
  export declare function isPostfixEntry(entry: LatexDictionaryEntry): entry is PostfixEntry;
202
247
  /** @internal */
203
248
  export declare function isEnvironmentEntry(entry: LatexDictionaryEntry): entry is EnvironmentEntry;
204
- export type LatexDictionary = LatexDictionaryEntry[];
249
+ export type LatexDictionary = Array<object>;
205
250
  export type ParseLatexOptions = {
206
251
  /**
207
252
  * This function is invoked when a number is followed by a symbol,
@@ -339,7 +384,7 @@ export type NumberFormattingOptions = {
339
384
  *
340
385
  * If you change it to another value, be aware that this may lead to
341
386
  * unexpected results. For example, if changing it to `,` the expression
342
- * `\mathrm{Hypot}(1,2)` will parse as `["Hypot", 1.2]` rather than
387
+ * `\operatorname{Hypot}(1,2)` will parse as `["Hypot", 1.2]` rather than
343
388
  * `["Hypot", 1, 2]`.
344
389
  *
345
390
  * **Default**: `"\\,"` (thin space, 3/18mu) (Resolution 7 of the 1948 CGPM)
@@ -431,6 +476,8 @@ export interface Serializer {
431
476
  logicStyle: (expr: Expression, level: number) => 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
432
477
  powerStyle: (expr: Expression, level: number) => 'root' | 'solidus' | 'quotient';
433
478
  numericSetStyle: (expr: Expression, level: number) => 'compact' | 'regular' | 'interval' | 'set-builder';
479
+ serializeFunction(expr: Expression): LatexString;
480
+ serializeSymbol(expr: Expression): LatexString;
434
481
  }
435
482
  export type SerializeHandler = (serializer: Serializer, expr: Expression) => string;
436
483
  export interface Parser {
@@ -450,10 +497,6 @@ export interface Parser {
450
497
  readonly peek: LatexToken;
451
498
  /** Return the next token and advance the index */
452
499
  nextToken(): LatexToken;
453
- /** Return an array of string corresponding to tokens ahead.
454
- * The index is unchanged.
455
- */
456
- lookAhead(): string[];
457
500
  /** Return a string representation of the expression
458
501
  between `start` and `end` (default: the whole expression) */
459
502
  latex(start: number, end?: number): string;
@@ -490,7 +533,7 @@ export interface Parser {
490
533
  * tokens (i.e. without braces), for example `^2`, `\sqrt3` or `\frac12`
491
534
  *
492
535
  * This argument will usually be a single token, but can be a sequence of
493
- * tokens (e.g. `\sqrt\frac12` or `\sqrt\mathrm{speed}`).
536
+ * tokens (e.g. `\sqrt\frac12` or `\sqrt\operatorname{speed}`).
494
537
  *
495
538
  * The following tokens are excluded from consideration in order to fail
496
539
  * early when encountering a likely syntax error, for example `x^(2)`
@@ -523,7 +566,7 @@ export interface Parser {
523
566
  * A symbol can be:
524
567
  * - a single-letter identifier: `x`
525
568
  * - a single LaTeX command: `\pi`
526
- * - a multi-letter identifier: `\mathrm{speed}`
569
+ * - a multi-letter identifier: `\operatorname{speed}`
527
570
  */
528
571
  parseSymbol(until?: Partial<Terminator>): Expression | null;
529
572
  /**
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.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.13.0 */
1
+ /* 0.14.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,7 +1,7 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  import { WarningSignalHandler } from '../../common/signals';
3
3
  import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
4
- import { IndexedLatexDictionary, IndexedSymbolEntry, IndexedFunctionEntry } from './dictionary/definitions';
4
+ import { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
5
5
  export declare class Serializer {
6
6
  readonly onError: WarningSignalHandler;
7
7
  options: NumberFormattingOptions & SerializeLatexOptions;
@@ -25,8 +25,8 @@ export declare class Serializer {
25
25
  wrapShort(expr: Expression | null): string;
26
26
  wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none', fence?: string): string;
27
27
  wrapArguments(expr: Expression): string;
28
- serializeSymbol(expr: Expression, def?: IndexedSymbolEntry | IndexedFunctionEntry): string;
29
- serializeFunction(expr: Expression, def?: IndexedFunctionEntry | IndexedSymbolEntry): string;
28
+ serializeSymbol(expr: Expression, def?: IndexedLatexDictionaryEntry): LatexString;
29
+ serializeFunction(expr: Expression, def?: IndexedLatexDictionaryEntry): LatexString;
30
30
  serializeDictionary(dict: {
31
31
  [key: string]: Expression;
32
32
  }): string;
@@ -40,8 +40,3 @@ export declare class Serializer {
40
40
  numericSetStyle(expr: Expression, level: number): 'compact' | 'regular' | 'interval' | 'set-builder';
41
41
  }
42
42
  export declare function appendLatex(src: string, s: string): string;
43
- /**
44
- * Replace '#1', '#2' in the LaTeX template stings with the corresponding
45
- * values from `replacement`, in a LaTeX syntax safe manner (i.e. inserting spaces when needed)
46
- */
47
- export declare function replaceLatex(template: string, replacement: string[]): string;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.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,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /** The canonical form of `Add`:
3
3
  * - removes `0`
4
4
  * - capture complex numbers (a + ib or ai +b)
@@ -9,4 +9,3 @@ export declare function simplifyAdd(ce: IComputeEngine, args: 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;
11
11
  export declare function evalSummation(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression, mode: 'simplify' | 'N' | 'evaluate'): BoxedExpression | undefined;
12
- export declare function normalizeLimits(range: BoxedExpression): [index: string, lower: number, upper: number, isFinite: boolean];
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  * Canonical form of 'Divide' (and 'Rational')
4
4
  * - remove denominator of 1
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.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.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  *
4
4
  */
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const ARITHMETIC_LIBRARY: IdTable[];
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const CALCULUS_LIBRARY: IdTable[];
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const COLLECTIONS_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const CORE_LIBRARY: IdTable[];
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const DOMAIN_CONSTRUCTORS: string[];
3
3
  export declare const DOMAIN_ALIAS: {
4
4
  NumericFunction: (string | string[])[];
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  import { IComputeEngine, IdTable } from '../public';
3
3
  export declare function getStandardLibrary(categories: LibraryCategory[] | LibraryCategory | 'all'): Readonly<IdTable>[];
4
4
  export declare const LIBRARIES: {
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const LOGIC_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const POLYNOMIALS_LIBRARY: IdTable[];
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare function randomExpression(level?: number): Expression;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const RELOP_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const SETS_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const TRIGONOMETRY_LIBRARY: IdTable[];
@@ -1,3 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare function isSymbolDefinition(def: BoxedSymbolDefinition | BoxedFunctionDefinition | SymbolDefinition | FunctionDefinition | undefined | null): def is BoxedSymbolDefinition;
3
3
  export declare function isFunctionDefinition(def: BoxedSymbolDefinition | BoxedFunctionDefinition | SymbolDefinition | FunctionDefinition | undefined | null): def is BoxedFunctionDefinition;
4
+ export declare function normalizeLimits(range: BoxedExpression): [index: string, lower: number, upper: number, isFinite: boolean];
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare function bigint(a: Decimal | number | bigint | string): bigint;
3
3
  export declare function gcd(a: bigint, b: bigint): bigint;
4
4
  export declare function lcm(a: bigint, b: bigint): bigint;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  import { IComputeEngine } from '../public';
3
3
  export declare function gcd(a: Decimal, b: Decimal): Decimal;
4
4
  export declare function lcm(a: Decimal, b: Decimal): Decimal;
@@ -1,3 +1,3 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare function gamma(c: Complex): Complex;
3
3
  export declare function lngamma(c: Complex): Complex;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { BoxedExpression } from '../public';
4
4
  export declare const MACHINE_PRECISION_BITS = 53;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare function isPrime(n: number): boolean | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare function isRational(x: any | null): x is Rational;
3
3
  export declare function isMachineRational(x: any | null): x is [number, number];
4
4
  export declare function isBigRational(x: any | null): x is [bigint, bigint];
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  * The most important classes are {@link ComputeEngine} and
3
3
  * {@link BoxedExpression}.
4
4
  *
@@ -863,6 +863,9 @@ export interface BoxedExpression {
863
863
  * The result is in canonical form.
864
864
  */
865
865
  N(options?: NOptions): BoxedExpression;
866
+ compile(to?: 'javascript', options?: {
867
+ optimize: ('simplify' | 'evaluate')[];
868
+ }): ((args: Record<string, any>) => any | undefined) | undefined;
866
869
  solve(vars: Iterable<string>): null | BoxedExpression[];
867
870
  /**
868
871
  * Synonym for `evaluate()`. If the expression is pure, the value may be
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  * Go through all the rules in the rule set, and for all the rules that match
4
4
  * return the rhs of the rule applied to `expr`.
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  * A set of simplification rules.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const UNIVARIATE_ROOTS: Rule[];
3
3
  /**
4
4
  * Expression is a function of a single variable (`x`) or an Equality
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare function distribute(expr: BoxedExpression[]): BoxedExpression;
3
3
  /** Use the multinomial theorem (https://en.wikipedia.org/wiki/Multinomial_theorem) to expand the expression.
4
4
  * The expression must be a power of a sum of terms.
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  * Flatten the arguments.
4
4
  * If `expr` was canonical, the result it canonical.
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  * Distribute `Negate` (multiply by -1) if expr is a number literal, an
4
4
  * addition or multiplication or another `Negate`.
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /**
3
3
  * Group terms in a product by common term.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare class Sum {
3
3
  private engine;
4
4
  private _isCanonical;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { BoxedExpression, Rational } from '../public';
4
4
  /**
@@ -1,3 +1,3 @@
1
- /* 0.13.0 */
2
- export declare const version = "0.13.0";
1
+ /* 0.14.0 */
2
+ export declare const version = "0.14.0";
3
3
  export { ComputeEngine } from './compute-engine/compute-engine';
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  /** A human readable string to annotate this expression, since JSON does not
3
3
  * allow comments in its encoding */
4
4
  comment?: string;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export declare const MISSING: Expression;
3
3
  export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumber;
4
4
  export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
@@ -42,6 +42,10 @@ export declare function symbol(expr: Expression | null | undefined): string | nu
42
42
  export declare function isListLike(expr: Expression | null): boolean;
43
43
  export declare function isMatrixLike(expr: Expression | null): boolean;
44
44
  export declare function dictionary(expr: Expression | null): null | Record<string, Expression>;
45
+ /**
46
+ * CAUTION: `machineValue()` will return a truncated value if the number
47
+ * has a precision outside of the machine range.
48
+ */
45
49
  export declare function machineValue(expr: Expression | null | undefined): number | null;
46
50
  /**
47
51
  * Return a rational (numer over denom) representation of the expression,
@@ -1,3 +1,3 @@
1
- /* 0.13.0 */
1
+ /* 0.14.0 */
2
2
  export { isSymbolObject, isStringObject, isFunctionObject, isDictionaryObject, stringValue as getStringValue, head, headName, symbol, applyRecursively, mapArgs, op, nops, dictionary as getDictionary, } from './math-json/utils';
3
- export declare const version = "0.13.0";
3
+ export declare const version = "0.14.0";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.13.0",
2
+ "version": "0.14.0",
3
3
  "scripts": {
4
4
  "build": "bash ./scripts/build.sh",
5
5
  "clean": "bash ./scripts/clean.sh",