@cortex-js/compute-engine 0.4.2 → 0.5.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 (132) hide show
  1. package/README.md +4 -5
  2. package/dist/compute-engine.esm.js +16755 -10484
  3. package/dist/compute-engine.min.esm.js +2 -7
  4. package/dist/compute-engine.min.js +2 -7
  5. package/dist/math-json.esm.js +148 -12472
  6. package/dist/math-json.min.esm.js +2 -7
  7. package/dist/math-json.min.js +2 -7
  8. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  9. package/dist/types/common/signals.d.ts +90 -0
  10. package/dist/types/compute-engine/assume.d.ts +21 -6
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +95 -0
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +53 -0
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
  26. package/dist/types/compute-engine/compute-engine.d.ts +284 -99
  27. package/dist/types/compute-engine/cost-function.d.ts +3 -0
  28. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
  29. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
  30. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
  31. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
  32. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
  33. package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
  34. package/dist/types/compute-engine/dictionary/core.d.ts +2 -2
  35. package/dist/types/compute-engine/dictionary/dictionary.d.ts +18 -11
  36. package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
  37. package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
  38. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
  39. package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
  40. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -2
  41. package/dist/types/compute-engine/domain-utils.d.ts +30 -0
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
  53. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
  54. package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
  55. package/dist/types/compute-engine/latex-syntax/public.d.ts +576 -0
  56. package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +4 -5
  57. package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
  58. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +41 -0
  59. package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
  60. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  61. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
  62. package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
  63. package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
  64. package/dist/types/compute-engine/public.d.ts +1416 -447
  65. package/dist/types/compute-engine/rules.d.ts +16 -6
  66. package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
  67. package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
  68. package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
  69. package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
  70. package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
  71. package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
  72. package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
  73. package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
  74. package/dist/types/compute-engine.d.ts +3 -5
  75. package/dist/types/math-json/math-json-format.d.ts +101 -0
  76. package/dist/types/math-json/utils.d.ts +97 -0
  77. package/dist/types/math-json.d.ts +4 -3
  78. package/package.json +29 -28
  79. package/dist/compute-engine.js +0 -17296
  80. package/dist/cortex.esm.js +0 -20989
  81. package/dist/cortex.js +0 -21011
  82. package/dist/cortex.min.esm.js +0 -7
  83. package/dist/cortex.min.js +0 -7
  84. package/dist/math-json.js +0 -12517
  85. package/dist/types/common/debug.d.ts +0 -28
  86. package/dist/types/common/utils.d.ts +0 -153
  87. package/dist/types/compute-engine/canonical-forms.d.ts +0 -74
  88. package/dist/types/compute-engine/dictionary/domains.d.ts +0 -26
  89. package/dist/types/compute-engine/dictionary/utils.d.ts +0 -5
  90. package/dist/types/compute-engine/domains.d.ts +0 -4
  91. package/dist/types/compute-engine/evaluate.d.ts +0 -13
  92. package/dist/types/compute-engine/expression-map.d.ts +0 -11
  93. package/dist/types/compute-engine/internal-compute-engine.d.ts +0 -108
  94. package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
  95. package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
  96. package/dist/types/compute-engine/numeric.d.ts +0 -21
  97. package/dist/types/compute-engine/numerical-eval.d.ts +0 -5
  98. package/dist/types/compute-engine/order.d.ts +0 -18
  99. package/dist/types/compute-engine/patterns.d.ts +0 -22
  100. package/dist/types/compute-engine/predicates.d.ts +0 -42
  101. package/dist/types/compute-engine/simplify.d.ts +0 -6
  102. package/dist/types/compute-engine/utils.d.ts +0 -15
  103. package/dist/types/cortex/formatter.d.ts +0 -165
  104. package/dist/types/cortex/parse-cortex.d.ts +0 -5
  105. package/dist/types/cortex/reserved-words.d.ts +0 -1
  106. package/dist/types/cortex/serialize-cortex.d.ts +0 -14
  107. package/dist/types/cortex.d.ts +0 -8
  108. package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
  109. package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
  110. package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
  111. package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
  112. package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
  113. package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
  114. package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
  115. package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
  116. package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
  117. package/dist/types/latex-syntax/definitions.d.ts +0 -40
  118. package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
  119. package/dist/types/latex-syntax/parse.d.ts +0 -138
  120. package/dist/types/latex-syntax/public.d.ts +0 -456
  121. package/dist/types/latex-syntax/serializer.d.ts +0 -26
  122. package/dist/types/latex-syntax/utils.d.ts +0 -10
  123. package/dist/types/point-free-parser/characters.d.ts +0 -25
  124. package/dist/types/point-free-parser/combinators.d.ts +0 -46
  125. package/dist/types/point-free-parser/core-combinators.d.ts +0 -78
  126. package/dist/types/point-free-parser/grammar.d.ts +0 -12
  127. package/dist/types/point-free-parser/identifier-parsers.d.ts +0 -7
  128. package/dist/types/point-free-parser/numeric-parsers.d.ts +0 -8
  129. package/dist/types/point-free-parser/parsers.d.ts +0 -130
  130. package/dist/types/point-free-parser/string-parsers.d.ts +0 -29
  131. package/dist/types/point-free-parser/whitespace-parsers.d.ts +0 -17
  132. package/dist/types/public.d.ts +0 -163
@@ -1,8 +1,18 @@
1
- /* 0.4.2 */
2
- import { ComputeEngine, Numeric, Rule, RuleSet } from './public';
3
- export declare function rules<T extends number = Numeric>(ce: ComputeEngine<T>, rs: Iterable<Rule>): RuleSet;
4
- export declare function applyRule<T extends number = Numeric>(ce: ComputeEngine<T>, [lhs, rhs, condition]: Rule<T>, expr: Expression<T>): Expression<T> | null;
1
+ /* 0.5.0 */
2
+ export declare function boxRules(ce: IComputeEngine, rs: Iterable<Rule>): BoxedRuleSet;
5
3
  /**
6
- * Repeatedely apply rules in the ruleset until no rules apply
4
+ * Apply the rules in the ruleset and return a modified expression.
5
+ *
6
+ * If no rule applied, return `null`.
7
7
  */
8
- export declare function replace<T extends number = Numeric>(ce: ComputeEngine, rules: RuleSet, expr: Expression<T>): Expression<T> | null;
8
+ export declare function replace(expr: BoxedExpression, ruleSet: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
9
+ /**
10
+ * Substitute some symbols with an expression.
11
+ *
12
+ * This is applied recursively to all subexpressions.
13
+ *
14
+ * While `replace()` applies a rule which may include expressions in
15
+ * its `lhs` to an expression, `substitute` is a specialized version
16
+ * that only apply rules that have a `lhs` made of a symbol.
17
+ */
18
+ export declare function getWildcardName(s: string): string;
@@ -0,0 +1,17 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * A set of simplification rules.
4
+ *
5
+ * The rules are expressed as
6
+ *
7
+ * `[lhs, rhs, condition]`
8
+ *
9
+ * where `lhs` is rewritten as `rhs` if `condition` is true.
10
+ *
11
+ * `lhs` and `rhs` can be either an Expression or a LaTeX string.
12
+ *
13
+ * If using an Expression, the expression is *not* canonicalized before being
14
+ * used. Therefore in some cases using Expression, while more verbose,
15
+ * may be necessary as the expression could be simplified by the canonicalization.
16
+ */
17
+ export declare const SIMPLIFY_RULES: Rule[];
@@ -0,0 +1,11 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * Return the expansion of ['Multiply', lhs, rhs]
4
+ * - lhs = 'a + b', rhs = '2'
5
+ * -> '2a + 2b'
6
+ * - lhs = 'a + b', rhs = 'a + c'
7
+ * -> 'a^2 + ac + ab + bc'
8
+ */
9
+ export declare function expand2(lhs: BoxedExpression, rhs: BoxedExpression): BoxedExpression;
10
+ export declare function expandN(expr: BoxedExpression, n: number): BoxedExpression;
11
+ export declare function expand(expr: BoxedExpression): BoxedExpression;
@@ -0,0 +1,7 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * Flatten the arguments.
4
+ * If `expr` was canonical, the result it canonical.
5
+ */
6
+ export declare function flatten(expr: BoxedExpression, head: string): BoxedExpression;
7
+ export declare function flattenOps(ops: BoxedExpression[], head: string): BoxedExpression[] | null;
@@ -0,0 +1,12 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * Distribute `Negate` (multiply by -1) if expr is a number literal, an
4
+ * addition or another `Negate`.
5
+ *
6
+ * This is appropriate to call during a `canonical` chain.
7
+ *
8
+ * For more thorough distribution (including multiplication), see `distributeNegate`,
9
+ * applicable during a `simplify` or `evaluate` chain.
10
+ */
11
+ export declare function canonicalNegate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
12
+ export declare function processNegate(_ce: IComputeEngine, x: BoxedExpression, _mode?: 'simplify' | 'evaluate' | 'N'): BoxedExpression;
@@ -0,0 +1,52 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * Coefficient of a univariate (single variable) polynomial.
4
+ *
5
+ * The first element is a constant.
6
+ * The second element is the coefficient of the variable.
7
+ * The third element is the coefficient of the variable squared.
8
+ * ...etc
9
+ *
10
+ * `3x^3 + 5x + √5 + 2` -> ['√5 + 2', 5, null, 3]
11
+ *
12
+ * If a coefficient does not apply (there are no corresponding term), it is `null`.
13
+ *
14
+ */
15
+ export declare type UnivariateCoefficients = (null | BoxedExpression)[];
16
+ export declare type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
17
+ /**
18
+ * Return a list of coefficient of powers of `vars` in `poly`,
19
+ * starting with power 0.
20
+ *
21
+ * If `poly` is not a polynomial, return `null`.
22
+ */
23
+ export declare function coefficients(poly: BoxedExpression, vars: string): UnivariateCoefficients | null;
24
+ export declare function coefficients(poly: BoxedExpression, vars: string[]): MultivariateCoefficients | null;
25
+ /**
26
+ * Return a polynomial expression of `vars` with coefficient
27
+ * of powers `coefs`.
28
+ *
29
+ * `poly === polynomial(coefficients(poly), getVars(poly))`
30
+ *
31
+ */
32
+ export declare function polynomial(coefs: UnivariateCoefficients, vars: string): SemiBoxedExpression;
33
+ export declare function polynomial(coefs: MultivariateCoefficients, vars: string[]): SemiBoxedExpression;
34
+ /**
35
+ * The total degree of an expression is the sum of the
36
+ * of the positive integer degrees of the factors in the expression:
37
+ *
38
+ * `3√2x^5y^3` -> 8 (5 + 3)
39
+ */
40
+ export declare function totalDegree(expr: BoxedExpression): number;
41
+ /**
42
+ * The max degree of an expression is the largest positive integer degree
43
+ * in the factors of the expression
44
+ *
45
+ * `3√2x^5y^3` -> 5
46
+ *
47
+ */
48
+ export declare function maxDegree(expr: BoxedExpression): number;
49
+ /**
50
+ * Return a lexicographic key of the expression
51
+ */
52
+ export declare function lex(expr: BoxedExpression): string;
@@ -0,0 +1,45 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * Group terms in a product by common term.
4
+ *
5
+ * All the terms should be canonical.
6
+ * - the arguments should have been flattened for `Multiply`
7
+ *
8
+ * - any argument of power been factored out, i.e.
9
+ * (ab)^2 -> a^2 b^2
10
+ * *
11
+ * 3 + √5 + √(x+1) + x^2 + (a+b)^2 + d
12
+ * -> [ [[3, "d"], [1, 1]],
13
+ * [[5, "x+1"], [1, 2]],
14
+ * [[x, "a+b"], [2, 1]]
15
+ * ]
16
+ *
17
+ */
18
+ export declare class Product {
19
+ engine: IComputeEngine;
20
+ private _terms;
21
+ private _literal;
22
+ private _hasInfinity;
23
+ private _hasZero;
24
+ constructor(ce: IComputeEngine, xs?: BoxedExpression[]);
25
+ get isEmpty(): boolean;
26
+ /**
27
+ * Add a term to the product.
28
+ * If the term is a literal rational, it is added to `this._literal`.
29
+ * Otherwise, if the term is already in the product, its degree is modified
30
+ * as appropriate.
31
+ */
32
+ addTerm(term: BoxedExpression): void;
33
+ /** The terms of the product, grouped by degrees */
34
+ groupedByDegrees(options?: {
35
+ splitRational: boolean;
36
+ }): {
37
+ exponent: [exponentNumer: number, exponentDenom: number];
38
+ terms: BoxedExpression[];
39
+ }[];
40
+ terms(): BoxedExpression[];
41
+ /** The product, expressed as a numerator and denominator */
42
+ asNumeratorDenominator(): [BoxedExpression, BoxedExpression];
43
+ asExpression(): BoxedExpression;
44
+ asRationalExpression(): BoxedExpression;
45
+ }
@@ -0,0 +1,25 @@
1
+ /* 0.5.0 */
2
+ export declare class Sum {
3
+ private engine;
4
+ private _literal;
5
+ private _imaginary;
6
+ private _posInfinityCount;
7
+ private _negInfinityCount;
8
+ private _terms;
9
+ constructor(engine: IComputeEngine, terms?: BoxedExpression[]);
10
+ get isEmpty(): boolean;
11
+ /**
12
+ * Add a new term to the sum.
13
+ * A term is a rational coefficient and an expression.
14
+ * Optinally, the term is multiplied by the constant `c` before beind added.
15
+ *
16
+ * If the sum already has this term, the coefficient is added
17
+ * to the previous one. Otherwise, a new entry is added.
18
+ *
19
+ * E.g. "2x + x + 1/5 y"
20
+ * -> [['x', [3, 1]], ['y', [1, 5]]]
21
+ */
22
+ addTerm(term: BoxedExpression, c?: [number, number]): void;
23
+ terms(): BoxedExpression[];
24
+ asExpression(): BoxedExpression;
25
+ }
@@ -0,0 +1,47 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * If expression is a product or a division, collect all the terms with a
4
+ * negative exponents in the denominator, and all the terms
5
+ * with a positive exponent (or no exponent) in the numerator, and put the
6
+ * numerator and denominators of all the terms that are a division (or a rational)
7
+ * into separate numerator/denominator
8
+ */
9
+ export declare function numeratorDenominator(expr: BoxedExpression): [SemiBoxedExpression[], SemiBoxedExpression[]];
10
+ /**
11
+ * Attempt to factor a rational coefficient `c` and a `rest` out of a
12
+ * canonical expression `expr` such that `ce.mul(c, rest)` is equal to `expr`.
13
+ *
14
+ * Attempts to make `rest` a positive value (i.e. pulls out negative sign).
15
+ *
16
+ *
17
+ * ['Multiply', 2, 'x', 3, 'a', ['Sqrt', 5]]
18
+ * -> [[6, 1], ['Multiply', 'x', 'a', ['Sqrt', 5]]]
19
+ *
20
+ * ['Divide', ['Multiply', 2, 'x'], ['Multiply', 3, 'y', 'a']]
21
+ * -> [[2, 3], ['Divide', 'x', ['Multiply, 'y', 'a']]]
22
+ */
23
+ export declare function asCoefficient(expr: BoxedExpression): [coef: [numer: number, denom: number], rest: BoxedExpression];
24
+ /**
25
+ * Return a rational coef and constant such that `coef * mod + constant = expr`
26
+ */
27
+ export declare function multiple(expr: BoxedExpression, mod: BoxedExpression): [coef: [number, number], constant: BoxedExpression];
28
+ /**
29
+ * Return a coef, term and constant such that:
30
+ *
31
+ * `coef * term + constant = expr`
32
+ *
33
+ * Return null if no `coef`/`constant` can be found.
34
+ */
35
+ export declare function linear(expr: BoxedExpression): null | {
36
+ coef: [number, number];
37
+ term: BoxedExpression;
38
+ constant: [number, number];
39
+ };
40
+ /**
41
+ * Apply the operator `op` to the left-hand-side and right-hand-side
42
+ * expression. Applies the associativity rule specified by the definition,
43
+ * i.e. 'op(a, op(b, c))` -> `op(a, b, c)`, etc...
44
+ *
45
+ */
46
+ export declare function applyAssociativeOperator(op: string, lhs: BoxedExpression, rhs: BoxedExpression, associativity?: 'right' | 'left' | 'non' | 'both'): BoxedExpression;
47
+ export declare function makePositive(expr: BoxedExpression): [sign: number, expr: BoxedExpression];
@@ -1,5 +1,3 @@
1
- /* 0.4.2 */
2
- export { LatexSyntax, parse, serialize } from './math-json';
3
- export { ComputeEngine, format, evaluate, } from './compute-engine/compute-engine';
4
- export { match, substitute } from './compute-engine/patterns';
5
- export declare const version = "0.4.2";
1
+ /* 0.5.0 */
2
+ export { ComputeEngine } from './compute-engine/compute-engine';
3
+ export declare const version = "0.5.0";
@@ -0,0 +1,101 @@
1
+ /* 0.5.0 */
2
+ /** A human readable string to annotate an expression, since JSON does not
3
+ * allow comments in its encoding */
4
+ comment?: string;
5
+ /** A Markdown-encoded string providing documentation about this expression.
6
+ */
7
+ documentation?: string;
8
+ /** A human readable string to indicate a syntax error or
9
+ * other problem when parsing or evaluating an expression.
10
+ */
11
+ error?: string;
12
+ /** A visual representation in LaTeX of the expression.
13
+ *
14
+ * This can be useful to preserve non-semantic details, for example
15
+ * parentheses in an expression or styling attributes
16
+ */
17
+ latex?: string;
18
+ /**
19
+ * A short string indicating an entry in a wikibase.
20
+ *
21
+ * For example
22
+ * `"Q167"` is the [wikidata entry](https://www.wikidata.org/wiki/Q167)
23
+ * for the `Pi` constant.
24
+ */
25
+ wikidata?: string;
26
+ /** A base URL for the `wikidata` key.
27
+ *
28
+ * A full URL can be produced by concatenating this key with the `wikidata`
29
+ * key. This key applies to this node and all its children.
30
+ *
31
+ * The default value is "https://www.wikidata.org/wiki/"
32
+ */
33
+ wikibase?: string;
34
+ /** A short string indicating an entry in an OpenMath Content Dictionary.
35
+ *
36
+ * For example: `arith1/#abs`.
37
+ *
38
+ */
39
+ openmathSymbol?: string;
40
+ /** A base URL for an OpenMath content dictionary. This key applies to this
41
+ * node and all its children.
42
+ *
43
+ * The default value is "http://www.openmath.org/cd".
44
+ */
45
+ openmathCd?: string;
46
+ /** A url to the source of this expression.
47
+ */
48
+ sourceUrl?: string;
49
+ /** The source from which this expression was generated.
50
+ *
51
+ * It could be a LaTeX expression, or some other source language
52
+ */
53
+ sourceContent?: string;
54
+ /**
55
+ * A character offset in `sourceContent` or `sourceUrl` from which this
56
+ * expression was generated
57
+ */
58
+ sourceOffsets?: [start: number, end: number];
59
+ };
60
+ /**
61
+ * A MathJSON numeric quantity.
62
+ *
63
+ * The string is made of:
64
+ * - an optional `-` minus sign
65
+ * - a string of decimal digits
66
+ * - an optional fraction part (a `.` decimal point followed by decimal digits)
67
+ * - an optional exponent part (a `e` or `E` exponent marker followed by an
68
+ * optional `-` minus sign, followed by a string of digits).
69
+ * - an optional format suffix:
70
+ * - `n` to indicate the number is a BigInt
71
+ * - `d` to indicate the number is an arbitrary precision Decimal number
72
+ * and may contain more digits or exponents with a greater magnitude than
73
+ * can be represented with a 64-bit floating point number.
74
+ *
75
+ * For example: `-12.34`, `0.234e-56`, `123454e9999d`.
76
+ */
77
+ export declare type MathJsonNumber = {
78
+ num: 'NaN' | '-Infinity' | '+Infinity' | string;
79
+ } & Attributes;
80
+ export declare type MathJsonSymbol = {
81
+ sym: string;
82
+ } & Attributes;
83
+ export declare type MathJsonString = {
84
+ str: string;
85
+ } & Attributes;
86
+ export declare type MathJsonFunction = {
87
+ fn: [Expression, ...Expression[]];
88
+ } & Attributes;
89
+ export declare type MathJsonDictionary = {
90
+ dict: {
91
+ [key: string]: Expression;
92
+ };
93
+ } & Attributes;
94
+ /**
95
+ * A MathJSON expression is a recursive data structure.
96
+ *
97
+ * The leaf nodes of an expression are numbers, strings and symbols.
98
+ * The dictionary and function nodes can contain expressions themselves.
99
+ *
100
+ */
101
+ export declare type Expression = number | MathJsonNumber | MathJsonString | MathJsonSymbol | string | MathJsonFunction | MathJsonDictionary | [Expression, ...Expression[]];
@@ -0,0 +1,97 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * These constants are the 'primitive' functions and constants that are used
4
+ * for some basic manipulations such as parsing, and transforming to canonical
5
+ * form.
6
+ *
7
+ */
8
+ export declare const IDENTITY = "Identity";
9
+ export declare const LIST = "List";
10
+ export declare const ADD = "Add";
11
+ export declare const DERIVATIVE = "Derivative";
12
+ export declare const DIVIDE = "Divide";
13
+ export declare const EXP = "Exp";
14
+ export declare const MULTIPLY = "Multiply";
15
+ export declare const NEGATE = "Negate";
16
+ export declare const POWER = "Power";
17
+ export declare const PRIME = "Prime";
18
+ export declare const ROOT = "Root";
19
+ export declare const SQRT = "Sqrt";
20
+ export declare const SUBTRACT = "Subtract";
21
+ export declare const COMPLEX_INFINITY = "ComplexInfinity";
22
+ export declare const PI = "Pi";
23
+ export declare const EXPONENTIAL_E = "ExponentialE";
24
+ export declare const IMAGINARY_UNIT = "ImaginaryUnit";
25
+ export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
26
+ export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbol;
27
+ export declare function isStringObject(expr: Expression | null): expr is MathJsonString;
28
+ export declare function isFunctionObject(expr: Expression | null): expr is MathJsonFunction;
29
+ export declare function isDictionaryObject(expr: Expression): expr is MathJsonNumber;
30
+ /**
31
+ * True if the expression is a number, a symbol or a string
32
+ * (i.e. not a function and not a dictionary)
33
+ */
34
+ export declare function isAtomic(expr: Expression | null): boolean;
35
+ /** If expr is a string literal, return it.
36
+ *
37
+ * A string literal is a JSON string that begins and ends with
38
+ * **U+0027 APOSTROPHE** : **`'`** or an object literal with a `str` key.
39
+ */
40
+ export declare function stringValue(expr: Expression | null): string | null;
41
+ /**
42
+ * The head of a function can be a string or an expression.
43
+ *
44
+ * Return `null` if the expression is not a function.
45
+ *
46
+ * Examples:
47
+ * * `["Negate", 5]` -> `"Negate"`
48
+ * * `[["Prime", "f"], "x"]` -> `["Prime", "f"]`
49
+ */
50
+ export declare function head(expr: Expression | null): Expression | null;
51
+ /** Return the head of an expression, only if it's a string */
52
+ export declare function headName(expr: Expression | null): string;
53
+ export declare function op(expr: Expression | null, n: number): Expression | null;
54
+ export declare function nops(expr: Expression): number;
55
+ export declare function symbol(expr: Expression | null): string | null;
56
+ export declare function machineValue(expr: Expression | null): number | null;
57
+ /**
58
+ * Return a rational (numer over denom) representation of the expression,
59
+ * if possible, `[null, null]` otherwise.
60
+ *
61
+ * The expression can be:
62
+ * - Some symbols: "ThreeQuarte", "Half"...
63
+ * - ["Power", d, -1]
64
+ * - ["Power", n, 1]
65
+ * - ["Divide", n, d]
66
+ *
67
+ * The denominator is always > 0.
68
+ */
69
+ export declare function rationalValue(expr: Expression): [number, number] | [null, null];
70
+ /**
71
+ * Return all the elements but the first one, i.e. the arguments of a
72
+ * function.
73
+ */
74
+ export declare function tail(expr: Expression | null): Expression[];
75
+ export declare function applyRecursively(expr: Expression, fn: (x: Expression) => Expression): Expression;
76
+ /**
77
+ * Apply a function to the arguments of a function and return an array of T
78
+ */
79
+ export declare function mapArgs<T>(expr: Expression, fn: (x: Expression) => T): T[];
80
+ export declare function dictionary(expr: Expression): {
81
+ [key: string]: Expression;
82
+ } | null;
83
+ /**
84
+ * Return num as a number if it's a valid JSON number (that is
85
+ * a valid JavaScript number but not NaN or +/-Infinity) or
86
+ * as a string otherwise
87
+ */
88
+ export declare function asValidJSONNumber(num: string): string | number;
89
+ /**
90
+ * Apply the operator `op` to the left-hand-side and right-hand-side
91
+ * expression. Applies the associativity rule specified by the definition,
92
+ * i.e. 'op(a, op(b, c))` -> `op(a, b, c)`, etc...
93
+ *
94
+ */
95
+ export declare function applyAssociativeOperator(op: string, lhs: Expression, rhs: Expression, associativity?: 'right' | 'left' | 'non' | 'both'): Expression;
96
+ export declare function getSequence(expr: Expression | null): Expression[] | null;
97
+ export declare function isValidSymbolName(s: string): boolean;
@@ -1,3 +1,4 @@
1
- /* 0.4.2 */
2
- export { LatexSyntax, parse, serialize } from './latex-syntax/latex-syntax';
3
- export declare const version = "0.4.2";
1
+ /* 0.5.0 */
2
+ export { isAtomic, isSymbolObject, isStringObject, isFunctionObject, isDictionaryObject, stringValue as getStringValue, head, headName, symbol, tail, applyRecursively, mapArgs, op, nops, dictionary as getDictionary, asValidJSONNumber, } from './math-json/utils';
3
+ export type { LatexToken, ParseHandler, SerializeHandler, LatexDictionaryEntry, LatexDictionary, ParseLatexOptions, SerializeLatexOptions, NumberFormattingOptions, } from './compute-engine/latex-syntax/public';
4
+ export declare const version = "0.5.0";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.2",
2
+ "version": "0.5.0",
3
3
  "scripts": {
4
4
  "build": "bash ./scripts/build.sh",
5
5
  "clean": "bash ./scripts/clean.sh",
@@ -42,46 +42,47 @@
42
42
  "module": "./dist/compute-engine.min.esm.js",
43
43
  "types": "./dist/types/compute-engine.d.ts",
44
44
  "engines": {
45
- "npm": ">=6.14.8",
46
- "node": ">=12.0.0"
45
+ "npm": ">=8.5.0",
46
+ "node": ">=16.14.2"
47
47
  },
48
48
  "devDependencies": {
49
- "@cortex-js/prettier-config": "^1.1.0",
50
- "@rollup/plugin-commonjs": "^19.0.0",
51
- "@rollup/plugin-node-resolve": "^13.0.0",
52
- "@types/jest": "^26.0.23",
53
- "@types/node": "^15.12.2",
54
- "@typescript-eslint/eslint-plugin": "^4.27.0",
55
- "@typescript-eslint/parser": "^4.27.0",
56
- "@typescript-eslint/typescript-estree": "^4.27.0",
57
- "chalk": "^4.1.1",
58
- "check-node-version": "^4.1.0",
49
+ "@cortex-js/prettier-config": "^1.1.1",
50
+ "@jest/console": "^27.5.1",
51
+ "@rollup/plugin-commonjs": "^21.0.3",
52
+ "@rollup/plugin-node-resolve": "^13.1.3",
53
+ "@types/jest": "^27.4.1",
54
+ "@types/node": "^17.0.23",
55
+ "@typescript-eslint/eslint-plugin": "^5.17.0",
56
+ "@typescript-eslint/parser": "^5.17.0",
57
+ "@typescript-eslint/typescript-estree": "^5.17.0",
58
+ "chalk": "^5.0.1",
59
+ "check-node-version": "^4.2.1",
59
60
  "child_process": "^1.0.2",
60
- "chokidar": "^3.5.2",
61
- "eslint": "^7.28.0",
62
- "eslint-config-prettier": "^8.3.0",
63
- "eslint-plugin-import": "^2.23.4",
64
- "eslint-plugin-no-unsanitized": "^3.1.5",
65
- "eslint-plugin-prettier": "^3.4.0",
61
+ "chokidar": "^3.5.3",
62
+ "eslint": "^8.12.0",
63
+ "eslint-config-prettier": "^8.5.0",
64
+ "eslint-plugin-import": "^2.25.4",
65
+ "eslint-plugin-no-unsanitized": "^4.0.1",
66
+ "eslint-plugin-prettier": "^4.0.0",
66
67
  "estrella": "^1.4.1",
67
- "http-server": "^0.12.3",
68
- "jest": "^27.0.4",
68
+ "http-server": "^14.1.0",
69
+ "jest": "^27.5.1",
69
70
  "jest-silent-reporter": "^0.5.0",
70
- "open": "^8.2.0",
71
- "prettier": "^2.3.1",
72
- "rollup": "^2.52.1",
71
+ "open": "^8.4.0",
72
+ "prettier": "^2.6.1",
73
+ "rollup": "^2.70.1",
73
74
  "rollup-plugin-copy": "^3.4.0",
74
75
  "rollup-plugin-eslint": "^7.0.0",
75
76
  "rollup-plugin-terser": "^7.0.2",
76
77
  "rollup-plugin-typescript2": "latest",
77
78
  "serve-http": "^1.0.6",
78
- "ts-jest": "^27.0.3",
79
- "typescript": "^4.3.3",
79
+ "ts-jest": "^27.1.4",
80
+ "typescript": "^4.6.3",
80
81
  "update-notifier": "^5.1.0"
81
82
  },
82
83
  "prettier": "@cortex-js/prettier-config",
83
84
  "dependencies": {
84
- "complex.js": "^2.0.13",
85
- "decimal.js": "^10.2.1"
85
+ "complex.js": "^2.1.0",
86
+ "decimal.js": "^10.3.1"
86
87
  }
87
88
  }