@cortex-js/compute-engine 0.9.0 → 0.11.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.
- package/dist/compute-engine.esm.js +3016 -3218
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +9 -9
- 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 +1 -2
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -2
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -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 -2
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +33 -40
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +2 -2
- 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 +18 -20
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +2 -2
- 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 +1 -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 +11 -11
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/public.d.ts +30 -30
- 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 +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -2
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
- package/dist/types/compute-engine/library/calculus.d.ts +2 -2
- package/dist/types/compute-engine/library/collections.d.ts +2 -2
- package/dist/types/compute-engine/library/core.d.ts +2 -2
- package/dist/types/compute-engine/library/domains.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +5 -5
- package/dist/types/compute-engine/library/logic.d.ts +2 -2
- package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
- package/dist/types/compute-engine/library/sets.d.ts +2 -2
- package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
- package/dist/types/compute-engine/library/utils.d.ts +3 -0
- 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 +101 -92
- 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 +1 -1
- 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 +3 -3
- package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +1 -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 +7 -7
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.11.0 */
|
|
2
2
|
* The most important classes are {@link ComputeEngine} and
|
|
3
3
|
* {@link BoxedExpression}.
|
|
4
4
|
*
|
|
@@ -13,11 +13,11 @@ import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../comm
|
|
|
13
13
|
import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
|
|
14
14
|
import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
15
15
|
export * from './latex-syntax/public';
|
|
16
|
-
export
|
|
16
|
+
export type Rational = [number, number] | [Decimal, Decimal];
|
|
17
17
|
/**
|
|
18
18
|
* Metadata that can be associated with a `BoxedExpression`
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
20
|
+
export type Metadata = {
|
|
21
21
|
latex?: string | undefined;
|
|
22
22
|
wikidata?: string | undefined;
|
|
23
23
|
};
|
|
@@ -35,9 +35,9 @@ export declare type Metadata = {
|
|
|
35
35
|
|
|
36
36
|
</div>
|
|
37
37
|
*/
|
|
38
|
-
export
|
|
38
|
+
export type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
|
|
39
39
|
/** Options for `BoxedExpression.simplify()` */
|
|
40
|
-
export
|
|
40
|
+
export type SimplifyOptions = EvaluateOptions & {
|
|
41
41
|
recursive?: boolean;
|
|
42
42
|
rules?: BoxedRuleSet;
|
|
43
43
|
};
|
|
@@ -45,12 +45,12 @@ export declare type SimplifyOptions = EvaluateOptions & {
|
|
|
45
45
|
*
|
|
46
46
|
* @internal
|
|
47
47
|
*/
|
|
48
|
-
export
|
|
48
|
+
export type EvaluateOptions = {};
|
|
49
49
|
/** Options for `BoxedExpression.N()`
|
|
50
50
|
* @internal
|
|
51
51
|
*/
|
|
52
|
-
export
|
|
53
|
-
export
|
|
52
|
+
export type NOptions = {};
|
|
53
|
+
export type ReplaceOptions = {
|
|
54
54
|
/** If `true`, apply replacement rules to all sub-expressions.
|
|
55
55
|
* If `false`, only consider the top-level expression.
|
|
56
56
|
*
|
|
@@ -82,16 +82,16 @@ export declare type ReplaceOptions = {
|
|
|
82
82
|
* A substitution can also be considered a more constrained version of a
|
|
83
83
|
* rule whose `lhs` is always a symbol.
|
|
84
84
|
*/
|
|
85
|
-
export
|
|
85
|
+
export type Substitution = {
|
|
86
86
|
[symbol: string]: SemiBoxedExpression;
|
|
87
87
|
};
|
|
88
|
-
export
|
|
88
|
+
export type BoxedSubstitution = {
|
|
89
89
|
[symbol: string]: BoxedExpression;
|
|
90
90
|
};
|
|
91
91
|
/** A LaTeX string starts and end with `$`, for example
|
|
92
92
|
* `"$\frac{\pi}{2}$"`.
|
|
93
93
|
*/
|
|
94
|
-
export
|
|
94
|
+
export type LatexString = string;
|
|
95
95
|
/**
|
|
96
96
|
* A rule describes how to modify an expressions that matches a `lhs` pattern
|
|
97
97
|
* into a new expressions matching `rhs`.
|
|
@@ -112,7 +112,7 @@ export declare type LatexString = string;
|
|
|
112
112
|
* - `__1` (`__a`, etc..) match a sequence of one or more expressions
|
|
113
113
|
* - `___1` (`___a`, etc...) match a sequence of zero or more expressions
|
|
114
114
|
*/
|
|
115
|
-
export
|
|
115
|
+
export type Rule = [
|
|
116
116
|
lhs: LatexString | SemiBoxedExpression | Pattern,
|
|
117
117
|
rhs: LatexString | SemiBoxedExpression,
|
|
118
118
|
options?: {
|
|
@@ -120,18 +120,18 @@ export declare type Rule = [
|
|
|
120
120
|
priority?: number;
|
|
121
121
|
}
|
|
122
122
|
];
|
|
123
|
-
export
|
|
123
|
+
export type BoxedRule = [
|
|
124
124
|
lhs: Pattern,
|
|
125
125
|
rhs: BoxedExpression,
|
|
126
126
|
priority: number,
|
|
127
127
|
condition: undefined | ((wildcards: BoxedSubstitution) => boolean)
|
|
128
128
|
];
|
|
129
|
-
export
|
|
130
|
-
export
|
|
129
|
+
export type BoxedRuleSet = Set<BoxedRule>;
|
|
130
|
+
export type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
|
|
131
131
|
/** A domain constructor is the head of a domain expression. */
|
|
132
|
-
export
|
|
133
|
-
export
|
|
134
|
-
export
|
|
132
|
+
export type DomainConstructor = 'Error' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
|
|
133
|
+
export type DomainLiteral = string;
|
|
134
|
+
export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['Error', T] | ['Error', T, 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>[]];
|
|
135
135
|
export interface BoxedDomain extends BoxedExpression {
|
|
136
136
|
is(s: BoxedDomain): boolean;
|
|
137
137
|
/** True if a valid domain, and compatible with `dom` */
|
|
@@ -176,7 +176,7 @@ export interface BoxedDomain extends BoxedExpression {
|
|
|
176
176
|
/**
|
|
177
177
|
* Options to control the serialization to MathJSON when using `BoxedExpression.json`.
|
|
178
178
|
*/
|
|
179
|
-
export
|
|
179
|
+
export type JsonSerializationOptions = {
|
|
180
180
|
/** A list of space separated function names that should be excluded from
|
|
181
181
|
* the JSON output.
|
|
182
182
|
*
|
|
@@ -431,16 +431,6 @@ export interface BoxedExpression {
|
|
|
431
431
|
*
|
|
432
432
|
*/
|
|
433
433
|
readonly isValid: boolean;
|
|
434
|
-
/**
|
|
435
|
-
* If `true`, this expression represents a value that was not calculated
|
|
436
|
-
* and that does not reference another expression.
|
|
437
|
-
*
|
|
438
|
-
* This means the expression is either a number, a string or a dictionary.
|
|
439
|
-
* Functions and symbols are not literals.
|
|
440
|
-
*
|
|
441
|
-
* **Note** applicable to canonical and non-canonical expressions.
|
|
442
|
-
*/
|
|
443
|
-
readonly isLiteral: boolean;
|
|
444
434
|
/**
|
|
445
435
|
* An exact value is not further transformed when evaluated. To get an
|
|
446
436
|
* approximate evaluation of an exact value, use `.N()`.
|
|
@@ -997,8 +987,8 @@ export interface BoxedExpression {
|
|
|
997
987
|
* This is convenient when creating new expressions from portions
|
|
998
988
|
* of an existing `BoxedExpression` while avoiding unboxing and reboxing.
|
|
999
989
|
*/
|
|
1000
|
-
export
|
|
1001
|
-
export
|
|
990
|
+
export type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
|
|
991
|
+
export type PatternMatchOptions = {
|
|
1002
992
|
substitution?: BoxedSubstitution;
|
|
1003
993
|
recursive?: boolean;
|
|
1004
994
|
numericTolerance?: number;
|
|
@@ -1019,27 +1009,31 @@ export interface ExpressionMapInterface<U> {
|
|
|
1019
1009
|
[Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
|
|
1020
1010
|
}
|
|
1021
1011
|
/**
|
|
1022
|
-
*
|
|
1012
|
+
* An ID table contains definitions for symbols and functions.
|
|
1013
|
+
*
|
|
1014
|
+
* The index of the table is an identifier, the name of the symbol or
|
|
1015
|
+
* function for this definition
|
|
1016
|
+
*
|
|
1017
|
+
* The name of a symbol or function is an arbitrary string of Unicode
|
|
1018
|
+
* characters, however the following conventions are recommended:
|
|
1019
|
+
*
|
|
1020
|
+
* - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
|
|
1021
|
+
* - The first character should be a letter: `/^[a-zA-Z]/`
|
|
1022
|
+
* - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
|
|
1023
1023
|
*
|
|
1024
1024
|
*/
|
|
1025
|
-
export
|
|
1026
|
-
|
|
1027
|
-
functions?: FunctionDefinition[];
|
|
1028
|
-
simplifyRules?: BoxedRuleSet;
|
|
1025
|
+
export type IDTable = {
|
|
1026
|
+
[id: string]: SymbolDefinition | FunctionDefinition;
|
|
1029
1027
|
};
|
|
1030
1028
|
/**
|
|
1031
|
-
* The entries of a `
|
|
1029
|
+
* The entries of a `RuntimeIdentifierTable` have been validated and
|
|
1032
1030
|
* optimized for faster evaluation.
|
|
1033
1031
|
*
|
|
1034
1032
|
* When a new scope is created with `pushScope()` or when creating a new
|
|
1035
|
-
* engine instance, new instances of `
|
|
1033
|
+
* engine instance, new instances of `RuntimeIdentifierTable` are created
|
|
1034
|
+
* as needed.
|
|
1036
1035
|
*/
|
|
1037
|
-
export
|
|
1038
|
-
symbols: Map<string, BoxedSymbolDefinition>;
|
|
1039
|
-
symbolWikidata: Map<string, BoxedSymbolDefinition>;
|
|
1040
|
-
functions: Map<string, BoxedFunctionDefinition>;
|
|
1041
|
-
functionWikidata: Map<string, BoxedFunctionDefinition>;
|
|
1042
|
-
};
|
|
1036
|
+
export type RuntimeIdentifierTable = Map<string, BoxedSymbolDefinition | BoxedFunctionDefinition>;
|
|
1043
1037
|
/**
|
|
1044
1038
|
* A scope is a set of names in a dictionary that are bound (defined) in
|
|
1045
1039
|
* a MathJSON expression.
|
|
@@ -1055,7 +1049,7 @@ export declare type RuntimeSymbolTable = {
|
|
|
1055
1049
|
* where they are in an expression, they are not determined at runtime.
|
|
1056
1050
|
*
|
|
1057
1051
|
*/
|
|
1058
|
-
export
|
|
1052
|
+
export type Scope = {
|
|
1059
1053
|
/** This handler is invoked when exiting this scope if there are any
|
|
1060
1054
|
* warnings pending. */
|
|
1061
1055
|
warn?: WarningSignalHandler;
|
|
@@ -1084,9 +1078,9 @@ export declare type Scope = {
|
|
|
1084
1078
|
*/
|
|
1085
1079
|
iterationLimit?: number;
|
|
1086
1080
|
};
|
|
1087
|
-
export
|
|
1081
|
+
export type RuntimeScope = Scope & {
|
|
1088
1082
|
parentScope?: RuntimeScope;
|
|
1089
|
-
|
|
1083
|
+
idTable?: RuntimeIdentifierTable;
|
|
1090
1084
|
assumptions: undefined | ExpressionMapInterface<boolean>;
|
|
1091
1085
|
/** The location of the call site that created this scope */
|
|
1092
1086
|
origin?: {
|
|
@@ -1099,18 +1093,7 @@ export declare type RuntimeScope = Scope & {
|
|
|
1099
1093
|
/** Set when one or more warnings have been signaled in this scope */
|
|
1100
1094
|
warnings?: WarningSignal[];
|
|
1101
1095
|
};
|
|
1102
|
-
export
|
|
1103
|
-
/** The name of the symbol or function for this definition
|
|
1104
|
-
*
|
|
1105
|
-
* The name of a symbol or function is an arbitrary string of Unicode
|
|
1106
|
-
* characters, however the following conventions are recommended:
|
|
1107
|
-
*
|
|
1108
|
-
* - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
|
|
1109
|
-
* - The first character should be a letter: `/^[a-zA-Z]/`
|
|
1110
|
-
* - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
|
|
1111
|
-
*
|
|
1112
|
-
*/
|
|
1113
|
-
name: string;
|
|
1096
|
+
export type BaseDefinition = {
|
|
1114
1097
|
/** A short (about 1 line) description. May contain Markdown. */
|
|
1115
1098
|
description?: string | string[];
|
|
1116
1099
|
/** A URL pointing to more information about this symbol or head. */
|
|
@@ -1143,7 +1126,7 @@ export interface BoxedBaseDefinition {
|
|
|
1143
1126
|
* A function definition can have some flags to indicate specific
|
|
1144
1127
|
* properties of the function.
|
|
1145
1128
|
*/
|
|
1146
|
-
export
|
|
1129
|
+
export type FunctionDefinitionFlags = {
|
|
1147
1130
|
/** If `true`, the function is applied element by element to lists, matrices
|
|
1148
1131
|
* (`["List"]` or `["Tuple"]` expressions) and equations (relational
|
|
1149
1132
|
* operators).
|
|
@@ -1230,7 +1213,7 @@ export declare type FunctionDefinitionFlags = {
|
|
|
1230
1213
|
/**
|
|
1231
1214
|
*
|
|
1232
1215
|
*/
|
|
1233
|
-
export
|
|
1216
|
+
export type FunctionSignature = {
|
|
1234
1217
|
/** The domain of this signature, a domain compatible with the `Function`
|
|
1235
1218
|
* domain) */
|
|
1236
1219
|
domain?: BoxedDomain | DomainExpression;
|
|
@@ -1260,7 +1243,10 @@ export declare type FunctionSignature = {
|
|
|
1260
1243
|
* arguments should be sorted in canonical order.
|
|
1261
1244
|
*
|
|
1262
1245
|
* The handler can make transformations based on the value of the arguments
|
|
1263
|
-
* that are exact
|
|
1246
|
+
* that are exact and literal
|
|
1247
|
+
* (i.e. `arg.numericValue !== null && arg.isExact`).
|
|
1248
|
+
*
|
|
1249
|
+
* Values of symbols should not be substituted.
|
|
1264
1250
|
*
|
|
1265
1251
|
* The handler should not consider the value or any assumptions about any
|
|
1266
1252
|
* of the arguments that are symbols or functions (i.e. `arg.isZero`,
|
|
@@ -1374,7 +1360,7 @@ export declare type FunctionSignature = {
|
|
|
1374
1360
|
/** Return a compiled (optimized) expression. */
|
|
1375
1361
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1376
1362
|
};
|
|
1377
|
-
export
|
|
1363
|
+
export type BoxedFunctionSignature = {
|
|
1378
1364
|
domain: BoxedDomain;
|
|
1379
1365
|
codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null);
|
|
1380
1366
|
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
|
|
@@ -1389,7 +1375,7 @@ export declare type BoxedFunctionSignature = {
|
|
|
1389
1375
|
* Definition record for a function.
|
|
1390
1376
|
*
|
|
1391
1377
|
*/
|
|
1392
|
-
export
|
|
1378
|
+
export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
|
|
1393
1379
|
/**
|
|
1394
1380
|
* A number used to order arguments.
|
|
1395
1381
|
*
|
|
@@ -1424,7 +1410,7 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
|
|
|
1424
1410
|
hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
1425
1411
|
signature?: FunctionSignature;
|
|
1426
1412
|
};
|
|
1427
|
-
export
|
|
1413
|
+
export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
|
|
1428
1414
|
complexity: number;
|
|
1429
1415
|
hold: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
1430
1416
|
signature: BoxedFunctionSignature;
|
|
@@ -1438,7 +1424,7 @@ export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefi
|
|
|
1438
1424
|
* For example, it might be useful to override `algebraic = false`
|
|
1439
1425
|
* for a transcendental number.
|
|
1440
1426
|
*/
|
|
1441
|
-
export
|
|
1427
|
+
export type SymbolFlags = {
|
|
1442
1428
|
number: boolean | undefined;
|
|
1443
1429
|
integer: boolean | undefined;
|
|
1444
1430
|
rational: boolean | undefined;
|
|
@@ -1464,42 +1450,61 @@ export declare type SymbolFlags = {
|
|
|
1464
1450
|
prime: boolean | undefined;
|
|
1465
1451
|
composite: boolean | undefined;
|
|
1466
1452
|
};
|
|
1467
|
-
export
|
|
1453
|
+
export type SymbolAttributes = {
|
|
1468
1454
|
/**
|
|
1469
|
-
* If true the value of the symbol is constant.
|
|
1455
|
+
* If `true` the value of the symbol is constant. The value or domain of
|
|
1456
|
+
* symbols with this attribute set to `true` cannot be changed.
|
|
1457
|
+
*
|
|
1458
|
+
* If `false`, the symbol is a variable.
|
|
1470
1459
|
*
|
|
1471
|
-
*
|
|
1460
|
+
* **Default**: `false`
|
|
1472
1461
|
*/
|
|
1473
1462
|
constant: boolean;
|
|
1474
1463
|
/**
|
|
1475
|
-
* If
|
|
1476
|
-
*
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1464
|
+
* If the symbol has a value, it is held as indicated in the table below.
|
|
1465
|
+
* A green checkmark indicate that the symbol is substituted.
|
|
1466
|
+
|
|
1467
|
+
<div class=symbols-table>
|
|
1468
|
+
|
|
1469
|
+
| Operation | `"never"` | `"simplify"` | `"evaluate"` | `"N"` |
|
|
1470
|
+
| :--- | :----- |
|
|
1471
|
+
| `canonical()`| {% icon "circle-check" "green-700" %} | | | |
|
|
1472
|
+
| `simplify()` | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | | |
|
|
1473
|
+
| `evaluate()` | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | |
|
|
1474
|
+
| `"N()"` | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} |
|
|
1475
|
+
|
|
1476
|
+
</div>
|
|
1477
|
+
|
|
1478
|
+
* Some examples:
|
|
1479
|
+
* - `i` has `holdUntil: 'never'`
|
|
1480
|
+
* - `GoldenRatio` has `holdUntil: 'simplify'` (symbolic constant)
|
|
1481
|
+
* - `x` has `holdUntil: 'evaluate'` (variables)
|
|
1482
|
+
* - `Pi` has `holdUntil: 'N'` (special numeric constant)
|
|
1483
|
+
*
|
|
1484
|
+
* **Default:** `simplify`
|
|
1485
|
+
*/
|
|
1486
|
+
holdUntil: 'never' | 'simplify' | 'evaluate' | 'N';
|
|
1483
1487
|
};
|
|
1484
1488
|
/**
|
|
1485
1489
|
* A bound symbol (i.e. one with an associated definition) has either a domain
|
|
1486
1490
|
* (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumber)
|
|
1487
1491
|
*/
|
|
1488
|
-
export
|
|
1492
|
+
export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
|
|
1493
|
+
domain?: string | BoxedDomain;
|
|
1489
1494
|
/** `value` can be a function since for some constants, such as
|
|
1490
1495
|
* `Pi`, the actual value depends on the `precision` setting of the
|
|
1491
1496
|
* `ComputeEngine` */
|
|
1492
1497
|
value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
|
|
1493
|
-
|
|
1498
|
+
flags?: Partial<SymbolFlags>;
|
|
1494
1499
|
};
|
|
1495
|
-
export interface BoxedSymbolDefinition extends BoxedBaseDefinition, Partial<SymbolFlags
|
|
1500
|
+
export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttributes, Partial<SymbolFlags> {
|
|
1496
1501
|
get value(): BoxedExpression | undefined;
|
|
1497
|
-
set value(val:
|
|
1502
|
+
set value(val: SemiBoxedExpression | number | undefined);
|
|
1498
1503
|
domain: BoxedDomain | undefined;
|
|
1499
1504
|
at?: (index: string | number) => undefined | BoxedExpression;
|
|
1500
1505
|
}
|
|
1501
|
-
export
|
|
1502
|
-
export
|
|
1506
|
+
export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
|
|
1507
|
+
export type CompiledExpression = {
|
|
1503
1508
|
evaluate?: (scope: {
|
|
1504
1509
|
[symbol: string]: BoxedExpression;
|
|
1505
1510
|
}) => number | BoxedExpression;
|
|
@@ -1570,18 +1575,26 @@ export interface IComputeEngine {
|
|
|
1570
1575
|
set precision(p: number | 'machine');
|
|
1571
1576
|
get precision(): number;
|
|
1572
1577
|
costFunction: (expr: BoxedExpression) => number;
|
|
1578
|
+
/** In strict mode (the default) the Compute Engine performs
|
|
1579
|
+
* validation of domains and signature and may report errors.
|
|
1580
|
+
*
|
|
1581
|
+
* When strict mode is off, results may be incorrect or generate JavaScript
|
|
1582
|
+
* errors if the input is not valid.
|
|
1583
|
+
*
|
|
1584
|
+
*/
|
|
1585
|
+
strict: boolean;
|
|
1573
1586
|
/**
|
|
1574
1587
|
* Associate a new definition to a symbol in the current context.
|
|
1575
1588
|
*
|
|
1576
1589
|
* If a definition existed previously, it is replaced.
|
|
1577
1590
|
*/
|
|
1578
|
-
defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
|
|
1591
|
+
defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
|
|
1579
1592
|
/**
|
|
1580
1593
|
* Associate a new definition to a function in the current context.
|
|
1581
1594
|
*
|
|
1582
1595
|
* If a definition existed previously, it is replaced.
|
|
1583
1596
|
*/
|
|
1584
|
-
defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
|
|
1597
|
+
defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
|
|
1585
1598
|
lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
|
|
1586
1599
|
/** Return `undefined` if no definition exist for this `head` */
|
|
1587
1600
|
lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
|
|
@@ -1717,15 +1730,11 @@ export interface IComputeEngine {
|
|
|
1717
1730
|
/** {@inheritDoc JsonSerializationOptions} */
|
|
1718
1731
|
get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
|
|
1719
1732
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
1720
|
-
pushScope(
|
|
1721
|
-
symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
|
|
1722
|
-
assumptions?: (LatexString | Expression | BoxedExpression)[];
|
|
1723
|
-
scope?: Partial<Scope>;
|
|
1724
|
-
}): void;
|
|
1733
|
+
pushScope(symbolTable?: Readonly<IDTable> | Readonly<IDTable>[], scope?: Partial<Scope>): void;
|
|
1725
1734
|
popScope(): void;
|
|
1726
|
-
/** Assign a value to an identifier in the current scope */
|
|
1735
|
+
/** Assign a value to an identifier in the current scope. Use `null` to reset the identifier to no value */
|
|
1727
1736
|
set(identifiers: {
|
|
1728
|
-
[identifier: string]: SemiBoxedExpression;
|
|
1737
|
+
[identifier: string]: SemiBoxedExpression | null;
|
|
1729
1738
|
}): void;
|
|
1730
1739
|
/** Declare identifiers (specify their domain without necessarily assigning them a value in the current scope*/
|
|
1731
1740
|
let(identifiers: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.11.0 */
|
|
2
2
|
/**
|
|
3
3
|
* Coefficient of a univariate (single variable) polynomial.
|
|
4
4
|
*
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* If a coefficient does not apply (there are no corresponding term), it is `null`.
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
16
|
-
export
|
|
15
|
+
export type UnivariateCoefficients = (null | BoxedExpression)[];
|
|
16
|
+
export type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
|
|
17
17
|
/**
|
|
18
18
|
* Return a list of coefficient of powers of `vars` in `poly`,
|
|
19
19
|
* starting with power 0.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.11.0 */
|
|
2
2
|
/** A human readable string to annotate this expression, since JSON does not
|
|
3
3
|
* allow comments in its encoding */
|
|
4
4
|
comment?: string;
|
|
@@ -78,19 +78,19 @@
|
|
|
78
78
|
* - `1.(3)`
|
|
79
79
|
* - `123456789123456789.123(4567)e999`
|
|
80
80
|
*/
|
|
81
|
-
export
|
|
81
|
+
export type MathJsonNumber = {
|
|
82
82
|
num: 'NaN' | '-Infinity' | '+Infinity' | string;
|
|
83
83
|
} & Attributes;
|
|
84
|
-
export
|
|
84
|
+
export type MathJsonSymbol = {
|
|
85
85
|
sym: string;
|
|
86
86
|
} & Attributes;
|
|
87
|
-
export
|
|
87
|
+
export type MathJsonString = {
|
|
88
88
|
str: string;
|
|
89
89
|
} & Attributes;
|
|
90
|
-
export
|
|
90
|
+
export type MathJsonFunction = {
|
|
91
91
|
fn: [Expression, ...Expression[]];
|
|
92
92
|
} & Attributes;
|
|
93
|
-
export
|
|
93
|
+
export type MathJsonDictionary = {
|
|
94
94
|
dict: {
|
|
95
95
|
[key: string]: Expression;
|
|
96
96
|
};
|
|
@@ -102,4 +102,4 @@ export declare type MathJsonDictionary = {
|
|
|
102
102
|
* The dictionary and function nodes can contain expressions themselves.
|
|
103
103
|
*
|
|
104
104
|
*/
|
|
105
|
-
export
|
|
105
|
+
export type Expression = number | string | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | [Expression, ...Expression[]];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.11.0 */
|
|
2
2
|
export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
|
|
3
3
|
export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbol;
|
|
4
4
|
export declare function isStringObject(expr: Expression | null): expr is MathJsonString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.11.0 */
|
|
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
3
|
export type { LatexToken, ParseHandler, SerializeHandler, LatexDictionaryEntry, LatexDictionary, ParseLatexOptions, SerializeLatexOptions, NumberFormattingOptions, } from './compute-engine/latex-syntax/public';
|
|
4
|
-
export declare const version = "0.
|
|
4
|
+
export declare const version = "0.11.0";
|
package/package.json
CHANGED