@cortex-js/compute-engine 0.12.3 → 0.12.5
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/dist/compute-engine.esm.js +24382 -28195
- package/dist/compute-engine.js +24557 -0
- package/dist/compute-engine.min.esm.js +24540 -2
- package/dist/compute-engine.min.js +24553 -2
- package/dist/math-json.esm.js +256 -185
- package/dist/math-json.js +283 -0
- package/dist/math-json.min.esm.js +258 -2
- package/dist/math-json.min.js +283 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -2
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +4 -3
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +4 -3
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +25 -16
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +15 -0
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +31 -34
- package/dist/types/compute-engine/latex-syntax/public.d.ts +63 -66
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +10 -6
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -2
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +2 -2
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/domains.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +17 -8
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +18 -10
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +4 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +2 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +4 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +5 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.5 */
|
|
2
2
|
* The most important classes are {@link ComputeEngine} and
|
|
3
3
|
* {@link BoxedExpression}.
|
|
4
4
|
*
|
|
@@ -36,7 +36,7 @@ export type Metadata = {
|
|
|
36
36
|
*/
|
|
37
37
|
export type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
|
|
38
38
|
/** Options for `BoxedExpression.simplify()` */
|
|
39
|
-
export type SimplifyOptions =
|
|
39
|
+
export type SimplifyOptions = {
|
|
40
40
|
recursive?: boolean;
|
|
41
41
|
rules?: BoxedRuleSet;
|
|
42
42
|
};
|
|
@@ -126,9 +126,9 @@ export type BoxedRule = [
|
|
|
126
126
|
export type BoxedRuleSet = Set<BoxedRule>;
|
|
127
127
|
export type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
|
|
128
128
|
/** A domain constructor is the head of a domain expression. */
|
|
129
|
-
export type DomainConstructor = '
|
|
129
|
+
export type DomainConstructor = 'InvalidDomain' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
|
|
130
130
|
export type DomainLiteral = string;
|
|
131
|
-
export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['
|
|
131
|
+
export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['InvalidDomain', T] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['Matrix', DomainExpression<T>, T, T] | ['SquareMatrix', DomainExpression<T>, T] | ['Vector', DomainExpression<T>, T] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Range'] | ['Range', T] | ['Range', T, T] | ['Range', T, T, T] | ['Interval', T, T] | ['Interval', ['Open', T], T] | ['Interval', T, ['Open', T]] | ['Interval', ['Open', T], ['Open', T]] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Function', ...DomainExpression<T>[]];
|
|
132
132
|
export interface BoxedDomain extends BoxedExpression {
|
|
133
133
|
is(s: BoxedDomain): boolean;
|
|
134
134
|
/** True if a valid domain, and compatible with `dom` */
|
|
@@ -284,6 +284,9 @@ export interface BoxedExpression {
|
|
|
284
284
|
*
|
|
285
285
|
*/
|
|
286
286
|
readonly json: Expression;
|
|
287
|
+
/** For debugging, the raw MathJSON representation of this expression without decanonicalization.
|
|
288
|
+
* @internal */
|
|
289
|
+
readonly rawJson: Expression;
|
|
287
290
|
/**
|
|
288
291
|
* The scope in which this expression has been defined.
|
|
289
292
|
* Is null when the expression is not canonical.
|
|
@@ -841,7 +844,9 @@ export interface BoxedExpression {
|
|
|
841
844
|
* The result is in canonical form.
|
|
842
845
|
*
|
|
843
846
|
*/
|
|
844
|
-
evaluate(
|
|
847
|
+
evaluate(ids?: {
|
|
848
|
+
[id: string]: SemiBoxedExpression | null | undefined;
|
|
849
|
+
}): BoxedExpression;
|
|
845
850
|
/** Return a numeric approximation of the canonical form of this expression.
|
|
846
851
|
*
|
|
847
852
|
* Any necessary calculations, including on decimal numbers (non-integers),
|
|
@@ -1481,7 +1486,7 @@ export type SymbolAttributes = {
|
|
|
1481
1486
|
* - `x` has `holdUntil: 'evaluate'` (variables)
|
|
1482
1487
|
* - `Pi` has `holdUntil: 'N'` (special numeric constant)
|
|
1483
1488
|
*
|
|
1484
|
-
* **Default:** `
|
|
1489
|
+
* **Default:** `evaluate`
|
|
1485
1490
|
*/
|
|
1486
1491
|
holdUntil: 'never' | 'simplify' | 'evaluate' | 'N';
|
|
1487
1492
|
};
|
|
@@ -1633,7 +1638,9 @@ export interface IComputeEngine {
|
|
|
1633
1638
|
* `ce.fn("Rational", [ce.number(1), ce.number(2)]))` \( \to \) `ce.number([1,2])`
|
|
1634
1639
|
*
|
|
1635
1640
|
*/
|
|
1636
|
-
fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[],
|
|
1641
|
+
fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], options?: {
|
|
1642
|
+
canonical: boolean;
|
|
1643
|
+
}): BoxedExpression;
|
|
1637
1644
|
/**
|
|
1638
1645
|
* This is a primitive to create a boxed function. It doesn't perform
|
|
1639
1646
|
* any checks or normalization on its arguments.
|
|
@@ -1734,7 +1741,9 @@ export interface IComputeEngine {
|
|
|
1734
1741
|
pushScope(identifiers?: Readonly<IdTable> | Readonly<IdTable>[], scope?: Partial<Scope>): void;
|
|
1735
1742
|
popScope(): void;
|
|
1736
1743
|
/** Assign a value to an identifier in the current scope. Use `null` to reset the identifier to no value */
|
|
1737
|
-
set(
|
|
1744
|
+
set(ids: {
|
|
1745
|
+
[id: string]: SemiBoxedExpression | null | undefined;
|
|
1746
|
+
}): void;
|
|
1738
1747
|
/** Declare identifiers (specify their domain without necessarily assigning them a value in the current scope) */
|
|
1739
1748
|
let(identifiers: IdTable): void;
|
|
1740
1749
|
/**
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
/* 0.12.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
1
|
+
/* 0.12.5 */
|
|
2
|
+
export declare function distribute(expr: BoxedExpression[]): BoxedExpression;
|
|
3
|
+
/** Use the multinomial theorem (https://en.wikipedia.org/wiki/Multinomial_theorem) to expand the expression.
|
|
4
|
+
* The expression must be a power of a sum of terms.
|
|
5
|
+
* The power must be a positive integer.
|
|
6
|
+
* - expr = '(a + b)^2'
|
|
7
|
+
* -> 'a^2 + 2ab + b^2'
|
|
8
|
+
* - expr = '(a + b)^3'
|
|
9
|
+
* -> 'a^3 + 3a^2b + 3ab^2 + b^3'
|
|
8
10
|
*/
|
|
9
|
-
export declare function
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
export declare function expandMultinomial(expr: BoxedExpression): BoxedExpression | null;
|
|
12
|
+
/** Apply the distributive law if the expression is a product of sums.
|
|
13
|
+
* For example, a(b + c) = ab + ac
|
|
14
|
+
* Expand the expression if it is a power of a sum.
|
|
15
|
+
* Expand the terms of the expression if it is a sum or negate.
|
|
16
|
+
* If the expression is a fraction, expand the numerator.
|
|
17
|
+
* Return null if the expression cannot be expanded.
|
|
18
|
+
*/
|
|
19
|
+
export declare function expand(expr: BoxedExpression | undefined): BoxedExpression | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.5 */
|
|
2
2
|
/**
|
|
3
3
|
* Group terms in a product by common term.
|
|
4
4
|
*
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
18
|
export declare class Product {
|
|
19
|
+
readonly options?: {
|
|
20
|
+
canonical?: boolean;
|
|
21
|
+
};
|
|
19
22
|
engine: IComputeEngine;
|
|
20
23
|
private _sign;
|
|
21
24
|
private _rational;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.5 */
|
|
2
2
|
export declare class Sum {
|
|
3
3
|
private engine;
|
|
4
4
|
private _isCanonical;
|
|
@@ -27,6 +27,7 @@ export declare class Sum {
|
|
|
27
27
|
* -> [['x', [3, 1]], ['y', [1, 5]]]
|
|
28
28
|
*/
|
|
29
29
|
addTerm(term: BoxedExpression, c?: Rational): void;
|
|
30
|
+
toString(): string;
|
|
30
31
|
terms(mode: 'expression' | 'numeric'): BoxedExpression[];
|
|
31
32
|
asExpression(mode: 'expression' | 'numeric'): BoxedExpression;
|
|
32
33
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* 0.12.
|
|
2
|
-
export declare const version = "0.12.
|
|
1
|
+
/* 0.12.5 */
|
|
2
|
+
export declare const version = "0.12.5";
|
|
3
3
|
export { ComputeEngine } from './compute-engine/compute-engine';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.5 */
|
|
2
|
+
export declare const MISSING: Expression;
|
|
2
3
|
export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumber;
|
|
3
4
|
export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
|
|
4
5
|
export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbol;
|
|
@@ -6,6 +7,8 @@ export declare function isStringObject(expr: Expression | null): expr is MathJso
|
|
|
6
7
|
export declare function isFunctionObject(expr: Expression | null): expr is MathJsonFunction;
|
|
7
8
|
export declare function isDictionaryObject(expr: Expression): expr is MathJsonNumber;
|
|
8
9
|
export declare function isValidIdentifier(s: string): boolean;
|
|
10
|
+
export declare const ONLY_EMOJIS: RegExp;
|
|
11
|
+
export declare function validateIdentifier(s: unknown): 'valid' | 'not-a-string' | 'empty-string' | 'expected-nfc' | 'unexpected-mixed-emoji' | 'unexpected-bidi-marker' | 'unexpected-script' | 'invalid-first-char' | 'invalid-char';
|
|
9
12
|
/** If expr is a string literal, return it.
|
|
10
13
|
*
|
|
11
14
|
* A string literal is a JSON string that begins and ends with
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.5 */
|
|
2
2
|
export { isSymbolObject, isStringObject, isFunctionObject, isDictionaryObject, stringValue as getStringValue, head, headName, symbol, applyRecursively, mapArgs, op, nops, dictionary as getDictionary, } from './math-json/utils';
|
|
3
|
-
export declare const version = "0.12.
|
|
3
|
+
export declare const version = "0.12.5";
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.12.
|
|
2
|
+
"version": "0.12.5",
|
|
3
3
|
"scripts": {
|
|
4
4
|
"build": "bash ./scripts/build.sh",
|
|
5
5
|
"clean": "bash ./scripts/clean.sh",
|
|
@@ -48,35 +48,26 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@cortex-js/prettier-config": "^1.1.1",
|
|
50
50
|
"@jest/console": "^29.0.3",
|
|
51
|
-
"@rollup/plugin-commonjs": "^22.0.2",
|
|
52
|
-
"@rollup/plugin-node-resolve": "^14.0.1",
|
|
53
51
|
"@types/jest": "^29.0.0",
|
|
54
|
-
"@types/node": "^
|
|
52
|
+
"@types/node": "^20.3.2",
|
|
55
53
|
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
56
54
|
"@typescript-eslint/parser": "^5.36.2",
|
|
57
55
|
"@typescript-eslint/typescript-estree": "^5.36.2",
|
|
58
56
|
"chalk": "^5.0.1",
|
|
59
57
|
"check-node-version": "^4.2.1",
|
|
60
|
-
"
|
|
61
|
-
"chokidar": "^3.5.3",
|
|
58
|
+
"esbuild": "^0.18.10",
|
|
62
59
|
"eslint": "^8.23.0",
|
|
63
60
|
"eslint-config-prettier": "^8.5.0",
|
|
64
61
|
"eslint-plugin-import": "^2.26.0",
|
|
65
62
|
"eslint-plugin-no-unsanitized": "^4.0.1",
|
|
66
63
|
"eslint-plugin-prettier": "^4.2.1",
|
|
67
|
-
"estrella": "^1.4.1",
|
|
68
64
|
"jest": "^29.0.3",
|
|
69
65
|
"jest-silent-reporter": "^0.5.0",
|
|
70
|
-
"open": "^
|
|
66
|
+
"open": "^9.1.0",
|
|
71
67
|
"prettier": "^2.7.1",
|
|
72
|
-
"rollup": "^2.79.0",
|
|
73
|
-
"rollup-plugin-copy": "^3.4.0",
|
|
74
|
-
"rollup-plugin-eslint": "^7.0.0",
|
|
75
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
76
|
-
"rollup-plugin-typescript2": "latest",
|
|
77
68
|
"serve-http": "^1.0.7",
|
|
78
69
|
"ts-jest": "^29.0.0",
|
|
79
|
-
"typescript": "^
|
|
70
|
+
"typescript": "^5.1.5",
|
|
80
71
|
"update-notifier": "^6.0.2"
|
|
81
72
|
},
|
|
82
73
|
"prettier": "@cortex-js/prettier-config",
|