@cortex-js/compute-engine 0.13.0 → 0.15.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 (94) hide show
  1. package/dist/compute-engine.esm.js +2017 -1101
  2. package/dist/compute-engine.js +2017 -1101
  3. package/dist/compute-engine.min.esm.js +2017 -1101
  4. package/dist/compute-engine.min.js +2017 -1101
  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 +11 -8
  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-complex.d.ts +2 -0
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +32 -17
  46. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +4 -2
  47. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +12 -6
  48. package/dist/types/compute-engine/latex-syntax/parse.d.ts +66 -20
  49. package/dist/types/compute-engine/latex-syntax/public.d.ts +95 -48
  50. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +8 -10
  53. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  54. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -2
  55. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  56. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  57. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  58. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  59. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  60. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  61. package/dist/types/compute-engine/library/complex.d.ts +2 -0
  62. package/dist/types/compute-engine/library/core.d.ts +1 -1
  63. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  64. package/dist/types/compute-engine/library/library.d.ts +1 -1
  65. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  66. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  67. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  68. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  69. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  70. package/dist/types/compute-engine/library/statistics.d.ts +2 -0
  71. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  72. package/dist/types/compute-engine/library/utils.d.ts +2 -1
  73. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  74. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  75. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  76. package/dist/types/compute-engine/numerics/numeric.d.ts +2 -1
  77. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  78. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  79. package/dist/types/compute-engine/public.d.ts +4 -1
  80. package/dist/types/compute-engine/rules.d.ts +1 -1
  81. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  82. package/dist/types/compute-engine/solve.d.ts +1 -1
  83. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  84. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  85. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  86. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  87. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  88. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  89. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  90. package/dist/types/compute-engine.d.ts +2 -2
  91. package/dist/types/math-json/math-json-format.d.ts +1 -1
  92. package/dist/types/math-json/utils.d.ts +6 -1
  93. package/dist/types/math-json.d.ts +2 -2
  94. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.13.0 */
1
+ /** CortexJS Compute Engine 0.15.0 */
2
2
 
3
3
  // src/math-json/utils.ts
4
4
  function isSymbolObject(expr) {
@@ -239,7 +239,7 @@ function mapArgs(expr, fn) {
239
239
  }
240
240
 
241
241
  // src/math-json.ts
242
- var version = "0.13.0";
242
+ var version = "0.15.0";
243
243
  export {
244
244
  applyRecursively,
245
245
  dictionary as getDictionary,
package/dist/math-json.js CHANGED
@@ -1,4 +1,4 @@
1
- /** CortexJS MathJSON 0.13.0 */
1
+ /** CortexJS MathJSON 0.15.0 */
2
2
  (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
3
3
  var MathJson = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -277,7 +277,7 @@ var MathJson = (() => {
277
277
  }
278
278
 
279
279
  // src/math-json.ts
280
- var version = "0.13.0";
280
+ var version = "0.15.0";
281
281
  return __toCommonJS(math_json_exports);
282
282
  })();
283
283
  Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.13.0 */
1
+ /** CortexJS Compute Engine 0.15.0 */
2
2
 
3
3
  // src/math-json/utils.ts
4
4
  function isSymbolObject(expr) {
@@ -239,7 +239,7 @@ function mapArgs(expr, fn) {
239
239
  }
240
240
 
241
241
  // src/math-json.ts
242
- var version = "0.13.0";
242
+ var version = "0.15.0";
243
243
  export {
244
244
  applyRecursively,
245
245
  dictionary as getDictionary,
@@ -1,4 +1,4 @@
1
- /** CortexJS MathJSON 0.13.0 */
1
+ /** CortexJS MathJSON 0.15.0 */
2
2
  (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
3
3
  var MathJson = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -277,7 +277,7 @@ var MathJson = (() => {
277
277
  }
278
278
 
279
279
  // src/math-json.ts
280
- var version = "0.13.0";
280
+ var version = "0.15.0";
281
281
  return __toCommonJS(math_json_exports);
282
282
  })();
283
283
  Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  /**
3
3
  * Return a string or an array of graphemes.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export type SignalCode = RuntimeSignalCode | ('invalid-name' | 'expected-predicate' | 'expected-symbol' | 'operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'prefix-operator-requires-one-operand' | 'unbalanced-symbols' | 'expected-argument' | 'unexpected-command' | 'cyclic-definition' | 'invalid-supersets' | 'expected-supersets' | 'unknown-domain' | 'duplicate-wikidata' | 'invalid-dictionary-entry' | 'syntax-error');
3
3
  export type SignalMessage = SignalCode | [SignalCode, ...any[]];
4
4
  export type SignalOrigin = {
@@ -1 +1 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  /**
3
3
  * Add an assumption, in the form of a predicate, for example:
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, BoxedFunctionDefinition, BoxedRuleSet, BoxedSymbolDefinition, BoxedDomain, EvaluateOptions, IComputeEngine, LatexString, Metadata, NOptions, PatternMatchOptions, SemiBoxedExpression, SimplifyOptions, Substitution, RuntimeScope, DomainCompatibility, DomainLiteral, BoxedBaseDefinition, Rational, BoxedSubstitution } from '../public';
@@ -118,5 +118,7 @@ export declare abstract class AbstractBoxedExpression implements BoxedExpression
118
118
  simplify(_options?: SimplifyOptions): BoxedExpression;
119
119
  evaluate(options?: EvaluateOptions): BoxedExpression;
120
120
  N(_options?: NOptions): BoxedExpression;
121
- compile(): ((args: Record<string, number>) => number) | undefined;
121
+ compile(to?: string, options?: {
122
+ optimize: ('simplify' | 'evaluate')[];
123
+ }): ((args: Record<string, any>) => any | undefined) | undefined;
122
124
  }
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { IComputeEngine, SemiBoxedExpression, BoxedExpression, Metadata, Rational } from '../public';
4
4
  import { MathJsonNumber } from '../../math-json/math-json-format';
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { BoxedExpression, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, ReplaceOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, BoxedSubstitution } from '../public';
3
3
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { BoxedDomain, BoxedExpression, BoxedSubstitution, DomainCompatibility, DomainConstructor, DomainExpression, DomainLiteral, IComputeEngine, Metadata, PatternMatchOptions } from '../public';
3
3
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
4
4
  /**
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare function makeFunctionDefinition(engine: IComputeEngine, name: string, def: FunctionDefinition | BoxedFunctionDefinition): BoxedFunctionDefinition;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedSubstitution, EvaluateOptions } from '../public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOptions, Rational, SimplifyOptions, BoxedSubstitution } from '../public';
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, BoxedSubstitution, BoxedDomain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOptions, SemiBoxedExpression, Substitution } from '../public';
4
4
  export declare class BoxedPattern extends AbstractBoxedExpression implements Pattern {
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOptions, BoxedSubstitution } from '../public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  /**
3
3
  * THEORY OF OPERATIONS
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, DomainExpression, BoxedSubstitution } from '../public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, IComputeEngine, Metadata, Rational } from '../public';
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, IComputeEngine } from '../public';
4
4
  export declare function isLatexString(s: unknown): s is string;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare function validateArgumentCount(ce: IComputeEngine, ops: BoxedExpression[], count: number): BoxedExpression[];
3
3
  /**
4
4
  * Validation of arguments is normally done by checking the signature of the
@@ -1,3 +1,10 @@
1
- /* 0.13.0 */
2
- export declare function compileToJavascript(expr: BoxedExpression): ((_: Record<string, number>) => number) | undefined;
1
+ /* 0.15.0 */
2
+ export type CompiledType = boolean | number | string | object;
3
+ /** This is an extension of the Function class that allows us to pass
4
+ * a custom scope for "global" functions. */
5
+ export declare class ComputeEngineFunction extends Function {
6
+ private sys;
7
+ constructor(body: any);
8
+ }
9
+ export declare function compileToJavascript(expr: BoxedExpression): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
3
10
  export declare function compile(expr: BoxedExpression, freeVars?: string[], prec?: number): string;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression, MathJsonNumber } from '../math-json/math-json-format';
4
4
  import type { LibraryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
@@ -140,14 +140,15 @@ export declare class ComputeEngine implements IComputeEngine {
140
140
  * perform calculations using arbitrary precision floating point numbers.
141
141
  * Use `"auto"` or `"complex"` to allow calculations on complex numbers.
142
142
  *
143
- * @param options.numericPrecision Specific how many digits of precision for the
144
- * numeric calculations. Default is 100.
143
+ * @param options.numericPrecision Specific how many digits of precision
144
+ * for the numeric calculations. Default is 100.
145
145
  *
146
- * @param options.tolerance If the absolute value of the difference of two numbers
147
- * is less than `tolerance`, they are considered equal. Used by `chop()` as well.
146
+ * @param options.tolerance If the absolute value of the difference of two
147
+ * numbers is less than `tolerance`, they are considered equal. Used by
148
+ * `chop()` as well.
148
149
  *
149
- * @param options.defaultDomain If an unknown symbol is encountered, assume it should
150
- * be a variable in this domain. **Default** `ExtendedRealNumber`
150
+ * @param options.defaultDomain If an unknown symbol is encountered, assume
151
+ * this is its domain. **Default** `ExtendedRealNumber`
151
152
  */
152
153
  constructor(options?: {
153
154
  numericMode?: NumericMode;
@@ -318,7 +319,9 @@ export declare class ComputeEngine implements IComputeEngine {
318
319
  parse(latex: LatexString | string | null, options?: {
319
320
  canonical?: boolean;
320
321
  }): null | BoxedExpression;
321
- serialize(x: Expression | BoxedExpression): string;
322
+ serialize(x: Expression | BoxedExpression, options?: {
323
+ canonical?: boolean;
324
+ }): string;
322
325
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
323
326
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
324
327
  get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
@@ -1,3 +1,3 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedExpression, Rational } from './public';
4
4
  /** Quickly determine the numeric domain of a number or constant
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.15.0 */
2
+ export declare const DEFINITIONS_COMPLEX: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.15.0 */
2
+ export declare const DEFINITIONS_STATISTICS: LatexDictionary;
@@ -1,3 +1,3 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const SYMBOLS: [string, string, number][];
3
3
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,18 +1,28 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { WarningSignal } from '../../../common/signals';
3
3
  export type CommonEntry = {
4
+ /** Note: a name is required if a serialize handler is provided */
4
5
  name?: string;
5
- serialize: SerializeHandler | LatexString;
6
+ serialize?: SerializeHandler;
7
+ /** Note: not all kinds have a latexTrigger or identifierTrigger.
8
+ * For example, matchfix operators use openDelimiter/closeDelimiter
9
+ */
10
+ latexTrigger?: LatexString;
11
+ identifierTrigger?: string;
6
12
  };
7
13
  export type IndexedSymbolEntry = CommonEntry & {
8
14
  kind: 'symbol';
9
- precedence: number;
15
+ precedence: Precedence;
10
16
  parse: ExpressionParseHandler;
11
17
  };
18
+ /** @internal */
19
+ export declare function isIndexedSymbolEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedSymbolEntry;
12
20
  export type IndexedExpressionEntry = CommonEntry & {
13
21
  kind: 'expression';
14
22
  parse: ExpressionParseHandler;
15
23
  };
24
+ /** @internal */
25
+ export declare function isIndexedExpressionEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedExpressionEntry;
16
26
  /**
17
27
  * A function has the following form:
18
28
  * - a prefix such as `\mathrm` or `\operatorname`
@@ -26,44 +36,49 @@ export type IndexedFunctionEntry = CommonEntry & {
26
36
  kind: 'function';
27
37
  parse: ExpressionParseHandler;
28
38
  };
39
+ /** @internal */
40
+ export declare function isIndexedFunctionEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedFunctionEntry;
29
41
  export type IndexedMatchfixEntry = CommonEntry & {
30
42
  kind: 'matchfix';
31
43
  openDelimiter: Delimiter | LatexToken[];
32
44
  closeDelimiter: Delimiter | LatexToken[];
33
45
  parse: MatchfixParseHandler;
34
46
  };
47
+ /** @internal */
48
+ export declare function isIndexedMatchfixEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedMatchfixEntry;
35
49
  export type IndexedInfixEntry = CommonEntry & {
36
50
  kind: 'infix';
37
51
  associativity: 'right' | 'left' | 'non' | 'both';
38
- precedence: number;
52
+ precedence: Precedence;
39
53
  parse: InfixParseHandler;
40
54
  };
55
+ /** @internal */
56
+ export declare function isIndexedInfixdEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedInfixEntry;
41
57
  export type IndexedPrefixEntry = CommonEntry & {
42
58
  kind: 'prefix';
43
- precedence: number;
59
+ precedence: Precedence;
44
60
  parse: ExpressionParseHandler;
45
61
  };
62
+ /** @internal */
63
+ export declare function isIndexedPrefixedEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedPostfixEntry;
46
64
  export type IndexedPostfixEntry = CommonEntry & {
47
65
  kind: 'postfix';
48
- precedence: number;
66
+ precedence: Precedence;
49
67
  parse: PostfixParseHandler;
50
68
  };
51
- export type EnvironmentEntry = CommonEntry & {
69
+ /** @internal */
70
+ export declare function isIndexedPostfixEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedPostfixEntry;
71
+ export type IndexedEnvironmentEntry = CommonEntry & {
52
72
  kind: 'environment';
53
73
  parse: EnvironmentParseHandler;
54
74
  };
55
- export type IndexedLatexDictionaryEntry = IndexedExpressionEntry | IndexedFunctionEntry | IndexedSymbolEntry | IndexedMatchfixEntry | IndexedInfixEntry | IndexedPrefixEntry | IndexedPostfixEntry | EnvironmentEntry;
75
+ /** @internal */
76
+ export declare function isIndexedEnvironmentEntry(entry: IndexedLatexDictionaryEntry): entry is IndexedEnvironmentEntry;
77
+ export type IndexedLatexDictionaryEntry = IndexedExpressionEntry | IndexedFunctionEntry | IndexedSymbolEntry | IndexedMatchfixEntry | IndexedInfixEntry | IndexedPrefixEntry | IndexedPostfixEntry | IndexedEnvironmentEntry;
56
78
  export type IndexedLatexDictionary = {
79
+ ids: Map<string, IndexedLatexDictionaryEntry>;
57
80
  lookahead: number;
58
- name: Map<string, IndexedLatexDictionaryEntry>;
59
- expression: (Map<LatexString, IndexedExpressionEntry[]> | null)[];
60
- symbol: (Map<LatexString, IndexedSymbolEntry[]> | null)[];
61
- prefix: (Map<LatexString, IndexedPrefixEntry[]> | null)[];
62
- infix: (Map<LatexString, IndexedInfixEntry[]> | null)[];
63
- postfix: (Map<LatexString, IndexedPostfixEntry[]> | null)[];
64
- matchfix: IndexedMatchfixEntry[];
65
- function: Map<string, IndexedFunctionEntry[]>;
66
- environment: Map<string, EnvironmentEntry>;
81
+ defs: IndexedLatexDictionaryEntry[];
67
82
  };
68
83
  export declare function indexLatexDictionary(dic: readonly Partial<LatexDictionaryEntry>[], onError: (sig: WarningSignal) => void): IndexedLatexDictionary;
69
84
  export declare const DEFAULT_LATEX_DICTIONARY: {
@@ -1,4 +1,4 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Serializer } from './serializer';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { WarningSignalHandler } from '../../common/signals';
@@ -21,6 +21,8 @@ export declare class LatexSyntax {
21
21
  updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>): void;
22
22
  static getDictionary(category?: LibraryCategory | 'all'): Readonly<LatexDictionary>;
23
23
  parse(latex: LatexString): Expression;
24
- serialize(expr: Expression): LatexString;
24
+ serialize(expr: Expression, options?: {
25
+ canonical?: boolean;
26
+ }): LatexString;
25
27
  get serializer(): Serializer;
26
28
  }
@@ -1,15 +1,21 @@
1
- /* 0.13.0 */
1
+ /* 0.15.0 */
2
2
  import { Parser } from './public';
3
3
  /** For error handling, if we have a identifier prefix, assume
4
4
  * the identifier is invalid (it would have been captured by
5
5
  * `mathIdentifier()` otherwise) and return an error expression */
6
6
  export declare function parseInvalidIdentifier(parser: Parser): Expression | null;
7
7
  /**
8
- * Match an identifier. It can be:
8
+ * Match an identifier.
9
+ *
10
+ * It can be:
9
11
  * - a sequence of emojis: `👍🏻👍🏻👍🏻`
10
- * - a single-letter identifier: `a`
12
+ * - a single-letter: `a`
11
13
  * - some LaTeX commands: `\alpha`
12
- * - a multi-letter identifier with a prefix: `\mathrm{speed}`
13
- * - an identifier with modifiers: `\mathrm{\alpha_{12}}` or `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}`
14
+ * - a multi-letter id with a prefix: `\operatorname{speed}`
15
+ * - an id with multiple prefixes:
16
+ * `\mathbin{\mathsf{T}}`
17
+ * - an id with modifiers:
18
+ * - `\mathrm{\alpha_{12}}` or
19
+ * - `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}`
14
20
  */
15
- export declare function matchIdentifier(parser: Parser): string | null;
21
+ export declare function parseIdentifier(parser: Parser): string | null;
@@ -1,5 +1,5 @@
1
- /* 0.13.0 */
2
- import { IndexedLatexDictionary, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry } from './dictionary/definitions';
1
+ /* 0.15.0 */
2
+ import { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
3
3
  import { IComputeEngine } from '../public';
4
4
  import { Expression } from '../../math-json/math-json-format';
5
5
  export declare const DEFAULT_LATEX_NUMBER_OPTIONS: NumberFormattingOptions;
@@ -36,8 +36,11 @@ export declare class _Parser implements Parser {
36
36
  * - the `t.condition` function returns true
37
37
  * Note: the `minPrec` condition is not checked. It should be checked separately.
38
38
  */
39
- atTerminator(t?: Partial<Terminator>): boolean;
40
- /** True if the current token matches any of the boundaries we are waiting for */
39
+ atTerminator(t?: Readonly<Terminator>): boolean;
40
+ /**
41
+ * True if the current token matches any of the boundaries we are
42
+ * waiting for.
43
+ */
41
44
  get atBoundary(): boolean;
42
45
  addBoundary(boundary: LatexToken[]): void;
43
46
  removeBoundary(): void;
@@ -59,15 +62,23 @@ export declare class _Parser implements Parser {
59
62
  * `[empty, '\\sqrt', '\\sqrt{', '\\sqrt{2', '\\sqrt{2}']`
60
63
  *
61
64
  */
62
- lookAhead(): string[];
63
- /** Return all the definitions that potentially match the tokens ahead */
64
- peekDefinitions(kind: 'expression'): [IndexedExpressionEntry, number][] | null;
65
- peekDefinitions(kind: 'function'): [FunctionEntry, number][] | null;
66
- peekDefinitions(kind: 'symbol'): [IndexedSymbolEntry, number][] | null;
67
- peekDefinitions(kind: 'postfix'): [IndexedPostfixEntry, number][] | null;
68
- peekDefinitions(kind: 'infix'): [IndexedInfixEntry, number][] | null;
69
- peekDefinitions(kind: 'prefix'): [IndexedPrefixEntry, number][] | null;
70
- peekDefinitions(kind: 'operator'): [IndexedInfixEntry | IndexedPrefixEntry | IndexedPostfixEntry, number][] | null;
65
+ lookAhead(): [count: number, tokens: string][];
66
+ /** Return all the definitions that match the tokens ahead
67
+ *
68
+ * The return value is an array of pairs `[def, n]` where `def` is the
69
+ * definition that matches the tokens ahead, and `n` is the number of tokens
70
+ * that matched.
71
+ *
72
+ * Note the 'operator' kind matches both infix, prefix and postfix operators.
73
+ *
74
+ */
75
+ peekDefinitions(kind: 'expression'): [IndexedExpressionEntry, number][];
76
+ peekDefinitions(kind: 'function'): [IndexedFunctionEntry, number][];
77
+ peekDefinitions(kind: 'symbol'): [IndexedSymbolEntry, number][];
78
+ peekDefinitions(kind: 'postfix'): [IndexedPostfixEntry, number][];
79
+ peekDefinitions(kind: 'infix'): [IndexedInfixEntry, number][];
80
+ peekDefinitions(kind: 'prefix'): [IndexedPrefixEntry, number][];
81
+ peekDefinitions(kind: 'operator'): [IndexedInfixEntry | IndexedPrefixEntry | IndexedPostfixEntry, number][];
71
82
  /** Skip strictly `<space>` tokens.
72
83
  * To also skip `{}` see `skipSpace()`.
73
84
  * To skip visual space (e.g. `\,`) see `skipVisualSpace()`.
@@ -83,6 +94,40 @@ export declare class _Parser implements Parser {
83
94
  matchAll(tokens: LatexToken[]): boolean;
84
95
  matchAny(tokens: LatexToken[]): LatexToken;
85
96
  matchChar(): string | null;
97
+ /** If the next token matches the open delimiter, set a boundary with
98
+ * the close token and return true.
99
+ *
100
+ * Note this method handles generic delimiters, i.e. '(' will math both
101
+ * '(', '\left(', '\bigl(', etc...
102
+ *
103
+ * Note that the definitions for matchfix may need to include synonyms
104
+ * for example:
105
+ *
106
+ * {
107
+ * openDelimiter: '(',
108
+ * closeDelimiter: ')'
109
+ * }
110
+ *
111
+ * and
112
+ *
113
+ * {
114
+ * openDelimiter: '\\lparen',
115
+ * closeDelimiter: '\\rparen'
116
+ * }
117
+ *
118
+ * For:
119
+ * - '[': '\\lbrack' and '\\['
120
+ * - ']': '\\rbrack' and '\\]'
121
+ * - '{': '\\lbrace' and '\\}'
122
+ * - '}': '\\rbrace' and '\\}'
123
+ * - '<': '\\langle'
124
+ * - '>': '\\rangle'
125
+ * - '|': '\\vert'
126
+ * - '||': '\\Vert'
127
+ * - '|': '\\lvert' and '\\rvert'
128
+ * - '||': '\\lVert' and '\\rVert'
129
+ */
130
+ private matchDelimiter;
86
131
  parseGroup(): Expression | null;
87
132
  parseToken(): Expression | null;
88
133
  parseOptionalGroup(): Expression | null;
@@ -135,10 +180,7 @@ export declare class _Parser implements Parser {
135
180
  * (i.e. we interpret `\cos 2x + 1` as `\cos(2x) + 1`)
136
181
  *
137
182
  */
138
- parseArguments(kind?: 'enclosure' | 'implicit', until?: Terminator): Expression[] | null;
139
- /** A prime suffix is a sequence of `'`, `\prime` or `\doubleprime`
140
- * after a function or in a superscript.
141
- */
183
+ parseArguments(kind?: 'enclosure' | 'implicit', until?: Readonly<Terminator>): Expression[] | null;
142
184
  /** If matches the normalized open delimiter, return the
143
185
  * expected closing delimiter.
144
186
  *
@@ -146,6 +188,8 @@ export declare class _Parser implements Parser {
146
188
  * return `['\right', '\rparen']`, which can be matched with `matchAll()`
147
189
  *
148
190
  * If you need to match several tokens, use `matchAll()`
191
+ *
192
+ * @internal
149
193
  */
150
194
  private matchOpenDelimiter;
151
195
  /** For error handling, when there is potentially a mismatched delimiter.
@@ -176,7 +220,7 @@ export declare class _Parser implements Parser {
176
220
  * (`\prime`...) and some arguments.
177
221
  */
178
222
  private parseFunction;
179
- parseSymbol(until?: Partial<Terminator>): Expression | null;
223
+ parseSymbol(until?: Readonly<Terminator>): Expression | null;
180
224
  /**
181
225
  * Parse a sequence superfix/subfix operator, e.g. `^{*}`
182
226
  *
@@ -189,7 +233,7 @@ export declare class _Parser implements Parser {
189
233
  *
190
234
  */
191
235
  private parseSupsub;
192
- parsePostfixOperator(lhs: Expression | null, until?: Partial<Terminator>): Expression | null;
236
+ parsePostfixOperator(lhs: Expression | null, until?: Readonly<Terminator>): Expression | null;
193
237
  /** Match a string used as a LaTeX identifier, for example an environment
194
238
  * name.
195
239
  * Not suitable for general purpose text, e.g. argument of a `\text{}
@@ -252,11 +296,13 @@ export declare class _Parser implements Parser {
252
296
  * Stop when an operator of precedence less than `until.minPrec`
253
297
  * is encountered
254
298
  */
255
- parseExpression(until?: Partial<Terminator>): Expression | null;
299
+ parseExpression(until?: Readonly<Terminator>): Expression | null;
256
300
  /**
257
301
  * Add LaTeX or other requested metadata to the expression
258
302
  */
259
303
  decorate(expr: Expression | null, start: number): Expression | null;
260
304
  error(code: string | [string, ...Expression[]], fromToken: number): Expression;
261
305
  private isFunctionHead;
306
+ /** Return all defs of the specified kind */
307
+ getDefs(kind: string): Iterable<IndexedLatexDictionaryEntry>;
262
308
  }