@cortex-js/compute-engine 0.12.2 → 0.12.4
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 +24348 -28196
- package/dist/compute-engine.js +24523 -0
- package/dist/compute-engine.min.esm.js +24506 -2
- package/dist/compute-engine.min.js +24519 -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 +3 -2
- 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 +1 -2
- 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 +28 -33
- package/dist/types/compute-engine/latex-syntax/public.d.ts +62 -65
- 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 -7
- 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.4 */
|
|
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` */
|
|
@@ -247,7 +247,10 @@ export interface BoxedExpression {
|
|
|
247
247
|
* @category Primitive Methods
|
|
248
248
|
*/
|
|
249
249
|
valueOf(): number | string | boolean;
|
|
250
|
-
/** From `Object.toString()`, return a
|
|
250
|
+
/** From `Object.toString()`, return a string representation of the
|
|
251
|
+
* expression. This string is suitable to be output to the console
|
|
252
|
+
* for debugging, for example. To get a LaTeX representation of the
|
|
253
|
+
* expression, use `expr.latex`.
|
|
251
254
|
*
|
|
252
255
|
* Used when coercing a `BoxedExpression` to a `String`.
|
|
253
256
|
*
|
|
@@ -281,6 +284,9 @@ export interface BoxedExpression {
|
|
|
281
284
|
*
|
|
282
285
|
*/
|
|
283
286
|
readonly json: Expression;
|
|
287
|
+
/** For debugging, the raw MathJSON representation of this expression without decanonicalization.
|
|
288
|
+
* @internal */
|
|
289
|
+
readonly rawJson: Expression;
|
|
284
290
|
/**
|
|
285
291
|
* The scope in which this expression has been defined.
|
|
286
292
|
* Is null when the expression is not canonical.
|
|
@@ -838,7 +844,9 @@ export interface BoxedExpression {
|
|
|
838
844
|
* The result is in canonical form.
|
|
839
845
|
*
|
|
840
846
|
*/
|
|
841
|
-
evaluate(
|
|
847
|
+
evaluate(ids?: {
|
|
848
|
+
[id: string]: SemiBoxedExpression | null | undefined;
|
|
849
|
+
}): BoxedExpression;
|
|
842
850
|
/** Return a numeric approximation of the canonical form of this expression.
|
|
843
851
|
*
|
|
844
852
|
* Any necessary calculations, including on decimal numbers (non-integers),
|
|
@@ -1731,7 +1739,9 @@ export interface IComputeEngine {
|
|
|
1731
1739
|
pushScope(identifiers?: Readonly<IdTable> | Readonly<IdTable>[], scope?: Partial<Scope>): void;
|
|
1732
1740
|
popScope(): void;
|
|
1733
1741
|
/** Assign a value to an identifier in the current scope. Use `null` to reset the identifier to no value */
|
|
1734
|
-
set(
|
|
1742
|
+
set(ids: {
|
|
1743
|
+
[id: string]: SemiBoxedExpression | null | undefined;
|
|
1744
|
+
}): void;
|
|
1735
1745
|
/** Declare identifiers (specify their domain without necessarily assigning them a value in the current scope) */
|
|
1736
1746
|
let(identifiers: IdTable): void;
|
|
1737
1747
|
/**
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
/* 0.12.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
1
|
+
/* 0.12.4 */
|
|
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.4 */
|
|
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.4 */
|
|
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.4 */
|
|
2
|
+
export declare const version = "0.12.4";
|
|
3
3
|
export { ComputeEngine } from './compute-engine/compute-engine';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
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.4 */
|
|
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.4";
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.12.
|
|
2
|
+
"version": "0.12.4",
|
|
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",
|