@cortex-js/compute-engine 0.4.0 → 0.4.3
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.
- package/README.md +2 -2
- package/dist/compute-engine.esm.js +22846 -16608
- package/dist/compute-engine.js +23518 -17282
- package/dist/compute-engine.min.esm.js +2 -7
- package/dist/compute-engine.min.js +2 -7
- package/dist/math-json.esm.js +4337 -10529
- package/dist/math-json.js +4354 -10532
- package/dist/math-json.min.esm.js +2 -7
- package/dist/math-json.min.js +2 -7
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +90 -0
- package/dist/types/compute-engine/assume.d.ts +21 -0
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
- package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +93 -0
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
- package/dist/types/compute-engine/boxed-expression/order.d.ts +52 -0
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
- package/dist/types/compute-engine/compute-engine.d.ts +252 -0
- package/dist/types/compute-engine/cost-function.d.ts +3 -0
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
- package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
- package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
- package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
- package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
- package/dist/types/compute-engine/dictionary/collections.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/core.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/dictionary.d.ts +26 -0
- package/dist/types/compute-engine/dictionary/logic.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/sets.d.ts +2 -0
- package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -0
- package/dist/types/compute-engine/domain-utils.d.ts +30 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
- package/dist/types/compute-engine/latex-syntax/public.d.ts +550 -0
- package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +2 -3
- package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +43 -0
- package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
- package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
- package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
- package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
- package/dist/types/compute-engine/public.d.ts +1076 -434
- package/dist/types/compute-engine/rules.d.ts +18 -0
- package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
- package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
- package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
- package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
- package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
- package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
- package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
- package/dist/types/compute-engine.d.ts +3 -0
- package/dist/types/math-json/math-json-format.d.ts +101 -0
- package/dist/types/math-json/utils.d.ts +97 -0
- package/dist/types/math-json.d.ts +5 -3
- package/package.json +39 -36
- package/dist/types/common/utils.d.ts +0 -153
- package/dist/types/compute-engine/expression-map.d.ts +0 -11
- package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
- package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
- package/dist/types/compute-engine/numeric.d.ts +0 -21
- package/dist/types/compute-engine/patterns.d.ts +0 -22
- package/dist/types/compute-engine/predicates.d.ts +0 -42
- package/dist/types/compute-engine/utils.d.ts +0 -15
- package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
- package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
- package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
- package/dist/types/latex-syntax/definitions.d.ts +0 -40
- package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
- package/dist/types/latex-syntax/parse.d.ts +0 -138
- package/dist/types/latex-syntax/public.d.ts +0 -455
- package/dist/types/latex-syntax/serializer.d.ts +0 -26
- package/dist/types/latex-syntax/utils.d.ts +0 -10
- package/dist/types/public.d.ts +0 -163
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
export declare function boxRules(ce: IComputeEngine, rs: Iterable<Rule>): BoxedRuleSet;
|
|
3
|
+
/**
|
|
4
|
+
* Apply the rules in the ruleset and return a modified expression.
|
|
5
|
+
*
|
|
6
|
+
* If no rule applied, return `null`.
|
|
7
|
+
*/
|
|
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.4.3 */
|
|
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.4.3 */
|
|
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.4.3 */
|
|
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.4.3 */
|
|
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.4.3 */
|
|
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.4.3 */
|
|
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.4.3 */
|
|
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.4.3 */
|
|
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];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* 0.4.3 */
|
|
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.4.3 */
|
|
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,5 @@
|
|
|
1
|
-
/* 0.4.
|
|
2
|
-
export { LatexSyntax
|
|
3
|
-
export
|
|
1
|
+
/* 0.4.3 */
|
|
2
|
+
export { LatexSyntax } from './compute-engine/latex-syntax/latex-syntax';
|
|
3
|
+
export type { Attributes, Expression, MathJsonNumber, MathJsonSymbol, MathJsonString, MathJsonFunction, MathJsonDictionary, } from './math-json/math-json-format';
|
|
4
|
+
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';
|
|
5
|
+
export declare const version = "0.4.3";
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.4.
|
|
2
|
+
"version": "0.4.3",
|
|
3
3
|
"scripts": {
|
|
4
4
|
"build": "bash ./scripts/build.sh",
|
|
5
5
|
"clean": "bash ./scripts/clean.sh",
|
|
6
6
|
"coverage": "bash ./scripts/test.sh coverage",
|
|
7
7
|
"dist": "bash ./scripts/build.sh production; bash ./scripts/test.sh",
|
|
8
8
|
"lint": "eslint --fix src/",
|
|
9
|
-
"postinstall": "bash ./scripts/postinstall.sh",
|
|
10
9
|
"prepare": "bash ./scripts/build.sh production",
|
|
11
10
|
"start": "bash ./scripts/start.sh",
|
|
12
11
|
"snapshot": "bash ./scripts/test.sh snapshot",
|
|
@@ -14,7 +13,8 @@
|
|
|
14
13
|
"test": "bash ./scripts/test.sh"
|
|
15
14
|
},
|
|
16
15
|
"name": "@cortex-js/compute-engine",
|
|
17
|
-
"description": "
|
|
16
|
+
"description": "Symbolic computing and numeric evaluations for JavaScript and Node.js",
|
|
17
|
+
"homepage": "https://cortexjs.io/compute-engine/",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/cortex-js/compute-engine.git"
|
|
@@ -26,60 +26,63 @@
|
|
|
26
26
|
"keywords": [
|
|
27
27
|
"math",
|
|
28
28
|
"JSON",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
29
|
+
"mathjs",
|
|
30
|
+
"mathematica",
|
|
31
|
+
"maple",
|
|
32
|
+
"algebra",
|
|
33
|
+
"symbolic computing",
|
|
34
|
+
"scientific computing",
|
|
35
|
+
"sympy"
|
|
34
36
|
],
|
|
35
37
|
"license": "MIT",
|
|
36
38
|
"files": [
|
|
37
39
|
"/dist"
|
|
38
40
|
],
|
|
39
|
-
"main": "./dist/
|
|
40
|
-
"module": "./
|
|
41
|
-
"types": "./dist/types/
|
|
41
|
+
"main": "./dist/compute-engine.min.js",
|
|
42
|
+
"module": "./dist/compute-engine.min.esm.js",
|
|
43
|
+
"types": "./dist/types/compute-engine.d.ts",
|
|
42
44
|
"engines": {
|
|
43
45
|
"npm": ">=6.14.8",
|
|
44
46
|
"node": ">=12.0.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"@cortex-js/prettier-config": "^1.1.
|
|
48
|
-
"@
|
|
49
|
-
"@rollup/plugin-
|
|
50
|
-
"@
|
|
51
|
-
"@types/
|
|
52
|
-
"@
|
|
53
|
-
"@typescript-eslint/
|
|
54
|
-
"@typescript-eslint/
|
|
55
|
-
"
|
|
56
|
-
"
|
|
49
|
+
"@cortex-js/prettier-config": "^1.1.1",
|
|
50
|
+
"@jest/console": "^27.5.1",
|
|
51
|
+
"@rollup/plugin-commonjs": "^21.0.2",
|
|
52
|
+
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
53
|
+
"@types/jest": "^27.4.1",
|
|
54
|
+
"@types/node": "^17.0.21",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.12.1",
|
|
56
|
+
"@typescript-eslint/parser": "^5.12.1",
|
|
57
|
+
"@typescript-eslint/typescript-estree": "^5.12.1",
|
|
58
|
+
"chalk": "^5.0.0",
|
|
59
|
+
"check-node-version": "^4.2.1",
|
|
57
60
|
"child_process": "^1.0.2",
|
|
58
|
-
"chokidar": "^3.5.
|
|
59
|
-
"eslint": "^
|
|
60
|
-
"eslint-config-prettier": "^8.
|
|
61
|
-
"eslint-plugin-import": "^2.
|
|
62
|
-
"eslint-plugin-no-unsanitized": "^
|
|
63
|
-
"eslint-plugin-prettier": "^
|
|
61
|
+
"chokidar": "^3.5.3",
|
|
62
|
+
"eslint": "^8.9.0",
|
|
63
|
+
"eslint-config-prettier": "^8.4.0",
|
|
64
|
+
"eslint-plugin-import": "^2.25.4",
|
|
65
|
+
"eslint-plugin-no-unsanitized": "^4.0.1",
|
|
66
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
64
67
|
"estrella": "^1.4.1",
|
|
65
|
-
"http-server": "^
|
|
66
|
-
"jest": "^27.
|
|
68
|
+
"http-server": "^14.1.0",
|
|
69
|
+
"jest": "^27.5.1",
|
|
67
70
|
"jest-silent-reporter": "^0.5.0",
|
|
68
|
-
"open": "^8.
|
|
69
|
-
"prettier": "^2.
|
|
70
|
-
"rollup": "^2.
|
|
71
|
+
"open": "^8.4.0",
|
|
72
|
+
"prettier": "^2.5.1",
|
|
73
|
+
"rollup": "^2.68.0",
|
|
71
74
|
"rollup-plugin-copy": "^3.4.0",
|
|
72
75
|
"rollup-plugin-eslint": "^7.0.0",
|
|
73
76
|
"rollup-plugin-terser": "^7.0.2",
|
|
74
77
|
"rollup-plugin-typescript2": "latest",
|
|
75
78
|
"serve-http": "^1.0.6",
|
|
76
|
-
"ts-jest": "^27.
|
|
77
|
-
"typescript": "^4.
|
|
79
|
+
"ts-jest": "^27.1.3",
|
|
80
|
+
"typescript": "^4.5.5",
|
|
78
81
|
"update-notifier": "^5.1.0"
|
|
79
82
|
},
|
|
80
83
|
"prettier": "@cortex-js/prettier-config",
|
|
81
84
|
"dependencies": {
|
|
82
|
-
"complex.js": "^2.0.
|
|
83
|
-
"decimal.js": "^10.
|
|
85
|
+
"complex.js": "^2.0.15",
|
|
86
|
+
"decimal.js": "^10.3.1"
|
|
84
87
|
}
|
|
85
88
|
}
|