@cortex-js/compute-engine 0.15.0 → 0.16.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 +3246 -1703
- package/dist/compute-engine.js +3246 -1703
- package/dist/compute-engine.min.esm.js +3246 -1705
- package/dist/compute-engine.min.js +3246 -1705
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/ansi-codes.d.ts +15 -0
- 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 +2 -2
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +9 -12
- package/dist/types/compute-engine/boxed-expression/box.d.ts +8 -3
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +6 -6
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +27 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +7 -19
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +11 -10
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +17 -11
- 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 +30 -9
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +55 -23
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +4 -19
- package/dist/types/compute-engine/function-utils.d.ts +84 -0
- 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-complex.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-statistics.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 +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse-identifier.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 +19 -5
- 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 +1 -1
- 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 +3 -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/complex.d.ts +2 -2
- package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
- package/dist/types/compute-engine/library/core.d.ts +2 -2
- package/dist/types/compute-engine/library/domains.d.ts +7 -8
- package/dist/types/compute-engine/library/library.d.ts +5 -5
- package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
- 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/random-expression.d.ts +1 -1
- 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/statistics.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 -3
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +3 -2
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +2 -2
- package/dist/types/compute-engine/numerics/numeric.d.ts +60 -2
- 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 +205 -91
- 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/derivative.d.ts +6 -0
- 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 +1 -1
- 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 +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +23 -21
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.16.0 */
|
|
2
2
|
* The most important classes are {@link ComputeEngine} and
|
|
3
3
|
* {@link BoxedExpression}.
|
|
4
4
|
*
|
|
@@ -126,17 +126,18 @@ 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 = 'InvalidDomain' | '
|
|
129
|
+
export type DomainConstructor = 'InvalidDomain' | 'Functions' | 'List' | 'Dictionary' | 'Tuple' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
|
|
130
130
|
export type DomainLiteral = string;
|
|
131
|
-
export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [
|
|
131
|
+
export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | ['InvalidDomain', string] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Functions', ...DomainExpression<T>[]];
|
|
132
132
|
export interface BoxedDomain extends BoxedExpression {
|
|
133
133
|
is(s: BoxedDomain): boolean;
|
|
134
|
-
/** True if a valid domain, and compatible with `dom`
|
|
134
|
+
/** True if a valid domain, and compatible with `dom`
|
|
135
|
+
* kind is 'covariant' by default, i.e. `this <: dom`
|
|
136
|
+
*/
|
|
135
137
|
isCompatible(dom: BoxedDomain | DomainLiteral, kind?: DomainCompatibility): boolean;
|
|
136
138
|
get literal(): string | null;
|
|
137
139
|
get ctor(): DomainConstructor | null;
|
|
138
140
|
get domainArgs(): (DomainExpression<BoxedExpression> | BoxedExpression | string)[] | null;
|
|
139
|
-
get domainArg1(): string | BoxedExpression | DomainExpression<BoxedExpression> | null;
|
|
140
141
|
get codomain(): BoxedDomain | null;
|
|
141
142
|
get canonical(): BoxedDomain;
|
|
142
143
|
get json(): Expression;
|
|
@@ -216,7 +217,7 @@ export type JsonSerializationOptions = {
|
|
|
216
217
|
precision: 'auto' | 'max' | number;
|
|
217
218
|
};
|
|
218
219
|
/**
|
|
219
|
-
*
|
|
220
|
+
* ## THEORY OF OPERATIONS
|
|
220
221
|
*
|
|
221
222
|
* The `BoxedExpression` interface includes most of the member functions
|
|
222
223
|
* applicable to any kind of expression, for example `get symbol()` or
|
|
@@ -350,17 +351,29 @@ export interface BoxedExpression {
|
|
|
350
351
|
*
|
|
351
352
|
*/
|
|
352
353
|
readonly subexpressions: BoxedExpression[];
|
|
353
|
-
/**
|
|
354
|
+
/**
|
|
355
|
+
*
|
|
356
|
+
* All the symbols in the expression, recursively
|
|
354
357
|
*
|
|
355
358
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
356
359
|
*
|
|
357
360
|
*/
|
|
358
361
|
readonly symbols: string[];
|
|
359
362
|
/**
|
|
360
|
-
* All the
|
|
361
|
-
*
|
|
363
|
+
* All the identifiers used in the expression that do not have a value
|
|
364
|
+
* associated with them, i.e. they are declared but not defined.
|
|
362
365
|
*/
|
|
363
|
-
readonly
|
|
366
|
+
readonly unknowns: string[];
|
|
367
|
+
/**
|
|
368
|
+
*
|
|
369
|
+
* All the identifiers (symbols and functions) in the expression that are a
|
|
370
|
+
* free variable.
|
|
371
|
+
*
|
|
372
|
+
* A free variable is an identifier that is used in a function but is not a
|
|
373
|
+
* local variable or a parameter of that function.
|
|
374
|
+
*
|
|
375
|
+
*/
|
|
376
|
+
readonly freeVariables: string[];
|
|
364
377
|
/** All the `["Error"]` subexpressions
|
|
365
378
|
*
|
|
366
379
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
@@ -462,8 +475,6 @@ export interface BoxedExpression {
|
|
|
462
475
|
* **Note** applicable to canonical and non-canonical expressions.
|
|
463
476
|
*/
|
|
464
477
|
readonly isPure: boolean;
|
|
465
|
-
/** True if the expression is a free variable, that is a symbol with no value */
|
|
466
|
-
readonly isFree: boolean;
|
|
467
478
|
/** True if the expression is a constant, that is a symbol with an immutable value */
|
|
468
479
|
readonly isConstant: boolean;
|
|
469
480
|
/**
|
|
@@ -722,12 +733,9 @@ export interface BoxedExpression {
|
|
|
722
733
|
/** Wikidata identifier.
|
|
723
734
|
*
|
|
724
735
|
* **Note** `undefined` if not a canonical expression.
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
736
|
*/
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
/** An optional short description if the symbol or function head.
|
|
737
|
+
readonly wikidata: string | undefined;
|
|
738
|
+
/** An optional short description if a symbol or function expression.
|
|
731
739
|
*
|
|
732
740
|
* May include markdown. Each string is a paragraph.
|
|
733
741
|
*
|
|
@@ -736,7 +744,7 @@ export interface BoxedExpression {
|
|
|
736
744
|
*/
|
|
737
745
|
readonly description: undefined | string[];
|
|
738
746
|
/** An optional URL pointing to more information about the symbol or
|
|
739
|
-
* function head
|
|
747
|
+
* function head.
|
|
740
748
|
*
|
|
741
749
|
* **Note** `undefined` if not a canonical expression.
|
|
742
750
|
*
|
|
@@ -750,13 +758,13 @@ export interface BoxedExpression {
|
|
|
750
758
|
readonly complexity: number | undefined;
|
|
751
759
|
/**
|
|
752
760
|
* For symbols and functions, a possible definition associated with the
|
|
753
|
-
* expression. `
|
|
761
|
+
* expression. `baseDefinition` is the base class of symbol and function
|
|
754
762
|
* definition.
|
|
755
763
|
*
|
|
756
764
|
* **Note** `undefined` if not a canonical expression.
|
|
757
765
|
*
|
|
758
766
|
*/
|
|
759
|
-
readonly
|
|
767
|
+
readonly baseDefinition: BoxedBaseDefinition | undefined;
|
|
760
768
|
/**
|
|
761
769
|
* For functions, a possible definition associated with the expression.
|
|
762
770
|
*
|
|
@@ -772,27 +780,31 @@ export interface BoxedExpression {
|
|
|
772
780
|
*/
|
|
773
781
|
readonly symbolDefinition: BoxedSymbolDefinition | undefined;
|
|
774
782
|
/**
|
|
775
|
-
* The domain of this expression, without accounting for any inferred domain
|
|
776
|
-
* or `ce.defaultDomain`. If no domain has been explicitly set via assignment
|
|
777
|
-
* or via an `.assume()` directive, the `expr.explicitDomain` is `undefined`.
|
|
778
783
|
*
|
|
779
|
-
*
|
|
784
|
+
* Infer the domain of this expression.
|
|
780
785
|
*
|
|
781
|
-
*
|
|
786
|
+
* If the domain of this expression is already known, return `false`.
|
|
782
787
|
*
|
|
783
|
-
*
|
|
788
|
+
* If the domain was not set, set it to the inferred domain, return `true`
|
|
789
|
+
* If the domain was previously inferred, adjust it by widening it,
|
|
790
|
+
* return `true
|
|
784
791
|
*
|
|
792
|
+
* @internal
|
|
785
793
|
*/
|
|
786
|
-
|
|
794
|
+
infer(domain: BoxedDomain): boolean;
|
|
787
795
|
/**
|
|
788
796
|
* Update the definition associated with this expression, taking
|
|
789
797
|
* into account the specified scope.
|
|
790
798
|
*
|
|
799
|
+
* If no scope is specified, the scope of when the expression was boxed is used.
|
|
800
|
+
*
|
|
801
|
+
* If the scope is `null`, the definition is removed.
|
|
802
|
+
*
|
|
791
803
|
* **Note**: applicable only to canonical expressions
|
|
792
804
|
*
|
|
793
805
|
* @internal
|
|
794
806
|
*/
|
|
795
|
-
bind(scope
|
|
807
|
+
bind(scope?: RuntimeScope | null): void;
|
|
796
808
|
/**
|
|
797
809
|
*
|
|
798
810
|
* @internal
|
|
@@ -844,9 +856,7 @@ export interface BoxedExpression {
|
|
|
844
856
|
* The result is in canonical form.
|
|
845
857
|
*
|
|
846
858
|
*/
|
|
847
|
-
evaluate(
|
|
848
|
-
[id: string]: SemiBoxedExpression | null | undefined;
|
|
849
|
-
}): BoxedExpression;
|
|
859
|
+
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
850
860
|
/** Return a numeric approximation of the canonical form of this expression.
|
|
851
861
|
*
|
|
852
862
|
* Any necessary calculations, including on decimal numbers (non-integers),
|
|
@@ -877,9 +887,12 @@ export interface BoxedExpression {
|
|
|
877
887
|
* **Note**: If non-canonical, return the value of its canonical counterpart
|
|
878
888
|
*/
|
|
879
889
|
get value(): BoxedExpression | undefined;
|
|
880
|
-
/**
|
|
890
|
+
/**
|
|
891
|
+
* Only the value of variables can be changed (symbols that are not
|
|
881
892
|
* constants).
|
|
882
893
|
*
|
|
894
|
+
* Throws a runtime error if a constant.
|
|
895
|
+
*
|
|
883
896
|
* **Note**: If non-canonical, does nothing.
|
|
884
897
|
*
|
|
885
898
|
*/
|
|
@@ -1020,33 +1033,32 @@ export interface ExpressionMapInterface<U> {
|
|
|
1020
1033
|
delete(expr: BoxedExpression): void;
|
|
1021
1034
|
clear(): void;
|
|
1022
1035
|
[Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
|
|
1036
|
+
entries(): IterableIterator<[BoxedExpression, U]>;
|
|
1023
1037
|
}
|
|
1024
1038
|
/**
|
|
1025
|
-
*
|
|
1039
|
+
* A table mapping identifiers to their definition.
|
|
1026
1040
|
*
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1041
|
+
* Identifiers should be valid MathJSON identifiers. In addition, the
|
|
1042
|
+
* following rules are recommended:
|
|
1029
1043
|
*
|
|
1030
|
-
*
|
|
1031
|
-
* characters, however the following conventions are recommended:
|
|
1032
|
-
*
|
|
1033
|
-
* - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
|
|
1044
|
+
* - Use only latin letters, digits and `-`: `/[a-zA-Z0-9-]+/`
|
|
1034
1045
|
* - The first character should be a letter: `/^[a-zA-Z]/`
|
|
1035
1046
|
* - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
|
|
1036
1047
|
*
|
|
1048
|
+
* If a semi boxed expression
|
|
1049
|
+
*
|
|
1037
1050
|
*/
|
|
1038
|
-
export type
|
|
1039
|
-
|
|
1040
|
-
|
|
1051
|
+
export type IdentifierDefinition = SymbolDefinition | FunctionDefinition | SemiBoxedExpression;
|
|
1052
|
+
export type IdentifierDefinitions = Readonly<{
|
|
1053
|
+
[id: string]: IdentifierDefinition;
|
|
1054
|
+
}>;
|
|
1041
1055
|
/**
|
|
1042
|
-
* The entries
|
|
1043
|
-
* optimized for faster evaluation.
|
|
1056
|
+
* The entries have been validated and optimized for faster evaluation.
|
|
1044
1057
|
*
|
|
1045
1058
|
* When a new scope is created with `pushScope()` or when creating a new
|
|
1046
|
-
* engine instance, new instances of
|
|
1047
|
-
* as needed.
|
|
1059
|
+
* engine instance, new instances of this type are created as needed.
|
|
1048
1060
|
*/
|
|
1049
|
-
export type
|
|
1061
|
+
export type RuntimeIdentifierDefinitions = Map<string, BoxedSymbolDefinition | BoxedFunctionDefinition>;
|
|
1050
1062
|
/**
|
|
1051
1063
|
* A scope is a set of names in a dictionary that are bound (defined) in
|
|
1052
1064
|
* a MathJSON expression.
|
|
@@ -1064,13 +1076,15 @@ export type RuntimeIdentifierTable = Map<string, BoxedSymbolDefinition | BoxedFu
|
|
|
1064
1076
|
*/
|
|
1065
1077
|
export type Scope = {
|
|
1066
1078
|
/** Signal `timeout` when the execution time for this scope is exceeded.
|
|
1079
|
+
*
|
|
1067
1080
|
* Time in seconds, default 2s.
|
|
1068
1081
|
*
|
|
1069
1082
|
* @experimental
|
|
1070
1083
|
*/
|
|
1071
1084
|
timeLimit: number;
|
|
1072
1085
|
/** Signal `out-of-memory` when the memory usage for this scope is exceeded.
|
|
1073
|
-
*
|
|
1086
|
+
*
|
|
1087
|
+
* Memory is in Megabytes, default: 1Mb.
|
|
1074
1088
|
*
|
|
1075
1089
|
* @experimental
|
|
1076
1090
|
*/
|
|
@@ -1081,8 +1095,8 @@ export type Scope = {
|
|
|
1081
1095
|
* @experimental
|
|
1082
1096
|
*/
|
|
1083
1097
|
recursionLimit: number;
|
|
1084
|
-
/** Signal `iteration-limit-exceeded` when the iteration limit
|
|
1085
|
-
*
|
|
1098
|
+
/** Signal `iteration-limit-exceeded` when the iteration limit
|
|
1099
|
+
* in a loop is exceeded. Default: no limits.
|
|
1086
1100
|
*
|
|
1087
1101
|
* @experimental
|
|
1088
1102
|
*/
|
|
@@ -1090,16 +1104,8 @@ export type Scope = {
|
|
|
1090
1104
|
};
|
|
1091
1105
|
export type RuntimeScope = Scope & {
|
|
1092
1106
|
parentScope?: RuntimeScope;
|
|
1093
|
-
|
|
1107
|
+
ids?: RuntimeIdentifierDefinitions;
|
|
1094
1108
|
assumptions: undefined | ExpressionMapInterface<boolean>;
|
|
1095
|
-
/** The location of the call site that created this scope */
|
|
1096
|
-
origin?: {
|
|
1097
|
-
name?: string;
|
|
1098
|
-
line?: number;
|
|
1099
|
-
column?: number;
|
|
1100
|
-
};
|
|
1101
|
-
/** Free memory should not go below this level for execution to proceed */
|
|
1102
|
-
lowWaterMark?: number;
|
|
1103
1109
|
};
|
|
1104
1110
|
export type BaseDefinition = {
|
|
1105
1111
|
/** A short (about 1 line) description. May contain Markdown. */
|
|
@@ -1240,8 +1246,8 @@ export type FunctionSignature = {
|
|
|
1240
1246
|
* If a required argument is missing, it should be indicated with a
|
|
1241
1247
|
* `["Error", "'missing"]` expression. If more arguments than expected
|
|
1242
1248
|
* are present, this should be indicated with a `unexpected-argument` error.
|
|
1243
|
-
* If the domain of an argument is not compatible, it should be indicated
|
|
1244
|
-
* a `incompatible-domain` error.
|
|
1249
|
+
* If the domain of an argument is not compatible, it should be indicated
|
|
1250
|
+
* with a `incompatible-domain` error.
|
|
1245
1251
|
*
|
|
1246
1252
|
* `["Sequence"]` expressions are not folded and need to be handled
|
|
1247
1253
|
* explicitly.
|
|
@@ -1254,7 +1260,8 @@ export type FunctionSignature = {
|
|
|
1254
1260
|
* that are exact and literal
|
|
1255
1261
|
* (i.e. `arg.numericValue !== null && arg.isExact`).
|
|
1256
1262
|
*
|
|
1257
|
-
* Values of symbols should not be substituted
|
|
1263
|
+
* Values of symbols should not be substituted, unless they have
|
|
1264
|
+
* a `holdUntil` attribute of `"never"`.
|
|
1258
1265
|
*
|
|
1259
1266
|
* The handler should not consider the value or any assumptions about any
|
|
1260
1267
|
* of the arguments that are symbols or functions (i.e. `arg.isZero`,
|
|
@@ -1284,6 +1291,9 @@ export type FunctionSignature = {
|
|
|
1284
1291
|
* as calculations involving decimal numbers (non-integers). Making exact
|
|
1285
1292
|
* calculations on integers or rationals is OK.
|
|
1286
1293
|
*
|
|
1294
|
+
* Do not reduce constants with a `holdUntil` attribute of `"N"`
|
|
1295
|
+
* or `"evaluate"`.
|
|
1296
|
+
*
|
|
1287
1297
|
* This handler should not have any side-effects: do not modify
|
|
1288
1298
|
* the environment of the `ComputeEngine` instance, do not perform I/O,
|
|
1289
1299
|
* do not do calculations that depend on random values.
|
|
@@ -1294,10 +1304,10 @@ export type FunctionSignature = {
|
|
|
1294
1304
|
*/
|
|
1295
1305
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1296
1306
|
/**
|
|
1297
|
-
* Evaluate
|
|
1307
|
+
* Evaluate a function expression.
|
|
1298
1308
|
*
|
|
1299
|
-
* The arguments have been
|
|
1300
|
-
*
|
|
1309
|
+
* The arguments have been evaluated, except the arguments to which a
|
|
1310
|
+
* `hold` applied.
|
|
1301
1311
|
*
|
|
1302
1312
|
* It is not necessary to further simplify or evaluate the arguments.
|
|
1303
1313
|
*
|
|
@@ -1310,7 +1320,7 @@ export type FunctionSignature = {
|
|
|
1310
1320
|
* - do not reduce rational numbers to decimal (floating point approximation)
|
|
1311
1321
|
* - do not down convert bignums to machine numbers
|
|
1312
1322
|
* - do not reduce square roots of rational numbers
|
|
1313
|
-
* - do not reduce constants with a `
|
|
1323
|
+
* - do not reduce constants with a `holdUntil` attribute of `"N"`
|
|
1314
1324
|
*
|
|
1315
1325
|
* If the expression cannot be evaluated, due to the values, domains, or
|
|
1316
1326
|
* assumptions about its arguments, for example, return `undefined` or
|
|
@@ -1337,19 +1347,19 @@ export type FunctionSignature = {
|
|
|
1337
1347
|
* evaluation, but a literal argument is out of range or
|
|
1338
1348
|
* not of the expected type.
|
|
1339
1349
|
*
|
|
1350
|
+
* Use the value of `ce.numericMode` to determine how to perform
|
|
1351
|
+
* the numeric evaluation.
|
|
1352
|
+
*
|
|
1340
1353
|
* Note that regardless of the current value of `ce.numericMode`, the
|
|
1341
1354
|
* arguments may be boxed numbers representing machine numbers, bignum
|
|
1342
1355
|
* numbers, complex numbers, rationals or big rationals.
|
|
1343
1356
|
*
|
|
1344
|
-
* Use the value of `ce.numericMode` to determine how to perform
|
|
1345
|
-
* the numeric evaluation.
|
|
1346
|
-
*
|
|
1347
1357
|
* If the numeric mode does not allow complex numbers (the
|
|
1348
1358
|
* `engine.numericMode` is not `"complex"` or `"auto"`) and the result of
|
|
1349
1359
|
* the evaluation would be a complex number, return `NaN` instead.
|
|
1350
1360
|
*
|
|
1351
|
-
* If `ce.numericMode` is `"bignum"` or `"auto"` the evaluation should
|
|
1352
|
-
* using bignums.
|
|
1361
|
+
* If `ce.numericMode` is `"bignum"` or `"auto"` the evaluation should
|
|
1362
|
+
* be done using bignums.
|
|
1353
1363
|
*
|
|
1354
1364
|
* Otherwise, `ce.numericMode` is `"machine", the evaluation should be
|
|
1355
1365
|
* performed using machine numbers.
|
|
@@ -1373,17 +1383,68 @@ export type BoxedFunctionSignature = {
|
|
|
1373
1383
|
codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null);
|
|
1374
1384
|
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
|
|
1375
1385
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1376
|
-
evaluate?:
|
|
1386
|
+
evaluate?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1377
1387
|
N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1378
1388
|
evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1379
1389
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
1380
1390
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1381
1391
|
};
|
|
1392
|
+
/**
|
|
1393
|
+
* The handlers are the primitive operations that can be performed on
|
|
1394
|
+
* collections.
|
|
1395
|
+
*
|
|
1396
|
+
* There are two types of collections:
|
|
1397
|
+
* - finite collections, such as lists, tuples, sets, matrices, etc...
|
|
1398
|
+
* The `size()` handler of finite collections returns the number of elements
|
|
1399
|
+
* - infinite collections, such as sequences, ranges, etc...
|
|
1400
|
+
* The `size()` handler of infinite collections returns `Infinity`
|
|
1401
|
+
* Infinite collections are not indexable, they have no `at()` handler.
|
|
1402
|
+
*
|
|
1403
|
+
*/
|
|
1404
|
+
export type CollectionHandlers = {
|
|
1405
|
+
/** Return an iterator
|
|
1406
|
+
* - start is optional and is a 1-based index.
|
|
1407
|
+
* - if start is not specified, start from index 1
|
|
1408
|
+
* - count is optional and is the number of elements to return
|
|
1409
|
+
* - if count is not specified or negative, return all the elements from start to the end
|
|
1410
|
+
*
|
|
1411
|
+
* If there is a `keys()` handler, there is no `iterator()` handler.
|
|
1412
|
+
*/
|
|
1413
|
+
iterator: (expr: BoxedExpression, start?: number, count?: number) => Iterator<BoxedExpression, undefined>;
|
|
1414
|
+
/** Return the element at the specified index.
|
|
1415
|
+
* The first element is `at(1)`, the last element is `at(-1)`.
|
|
1416
|
+
* If the index is <0, return the element at index `size() + index + 1`.
|
|
1417
|
+
* The index can also be a string for example for dictionaries.
|
|
1418
|
+
* If the index is invalid, return `undefined`.
|
|
1419
|
+
*/
|
|
1420
|
+
at: (expr: BoxedExpression, index: number | string) => undefined | BoxedExpression;
|
|
1421
|
+
/** Return the number of elements in the collection.
|
|
1422
|
+
* An empty collection has a size of 0.
|
|
1423
|
+
*/
|
|
1424
|
+
size: (expr: BoxedExpression) => number;
|
|
1425
|
+
/**
|
|
1426
|
+
* If the collection is indexed by strings, return the valid values
|
|
1427
|
+
* for the index.
|
|
1428
|
+
*/
|
|
1429
|
+
keys: (expr: BoxedExpression) => undefined | Iterator<string>;
|
|
1430
|
+
/**
|
|
1431
|
+
* Return the index of the first element that matches the target expression.
|
|
1432
|
+
* The comparison is done using the `target.isEqual()` method.
|
|
1433
|
+
* If the expression is not found, return `undefined`.
|
|
1434
|
+
* If the expression is found, return the index, 1-based.
|
|
1435
|
+
* If the expression is found multiple times, return the index of the first
|
|
1436
|
+
* match.
|
|
1437
|
+
*
|
|
1438
|
+
* From is the starting index for the search. If negative, start from the end
|
|
1439
|
+
* and search backwards.
|
|
1440
|
+
*/
|
|
1441
|
+
indexOf: (expr: BoxedExpression, target: BoxedExpression, from?: number) => number | string | undefined;
|
|
1442
|
+
};
|
|
1382
1443
|
/**
|
|
1383
1444
|
* Definition record for a function.
|
|
1384
1445
|
*
|
|
1385
1446
|
*/
|
|
1386
|
-
export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
|
|
1447
|
+
export type FunctionDefinition = BaseDefinition & Partial<CollectionHandlers> & Partial<FunctionDefinitionFlags> & {
|
|
1387
1448
|
/**
|
|
1388
1449
|
* A number used to order arguments.
|
|
1389
1450
|
*
|
|
@@ -1416,9 +1477,9 @@ export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlag
|
|
|
1416
1477
|
* **Default**: `"none"`
|
|
1417
1478
|
*/
|
|
1418
1479
|
hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
1419
|
-
signature
|
|
1480
|
+
signature: FunctionSignature;
|
|
1420
1481
|
};
|
|
1421
|
-
export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
|
|
1482
|
+
export type BoxedFunctionDefinition = BoxedBaseDefinition & Partial<CollectionHandlers> & FunctionDefinitionFlags & {
|
|
1422
1483
|
complexity: number;
|
|
1423
1484
|
hold: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
|
|
1424
1485
|
signature: BoxedFunctionSignature;
|
|
@@ -1495,13 +1556,18 @@ export type SymbolAttributes = {
|
|
|
1495
1556
|
};
|
|
1496
1557
|
/**
|
|
1497
1558
|
* A bound symbol (i.e. one with an associated definition) has either a domain
|
|
1498
|
-
* (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain =
|
|
1559
|
+
* (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumbers)
|
|
1499
1560
|
*/
|
|
1500
1561
|
export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
|
|
1501
1562
|
domain?: string | BoxedDomain;
|
|
1502
|
-
/**
|
|
1563
|
+
/** If true, the domain is inferred, and could be adjusted later
|
|
1564
|
+
* as more information becomes available or if the symbol is explicitly
|
|
1565
|
+
* declared.
|
|
1566
|
+
*/
|
|
1567
|
+
inferred?: boolean;
|
|
1568
|
+
/** `value` can be a JS function since for some constants, such as
|
|
1503
1569
|
* `Pi`, the actual value depends on the `precision` setting of the
|
|
1504
|
-
* `ComputeEngine` */
|
|
1570
|
+
* `ComputeEngine` and possible other environment settings */
|
|
1505
1571
|
value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
|
|
1506
1572
|
flags?: Partial<SymbolFlags>;
|
|
1507
1573
|
};
|
|
@@ -1509,7 +1575,7 @@ export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttrib
|
|
|
1509
1575
|
get value(): BoxedExpression | undefined;
|
|
1510
1576
|
set value(val: SemiBoxedExpression | number | undefined);
|
|
1511
1577
|
domain: BoxedDomain | undefined;
|
|
1512
|
-
|
|
1578
|
+
inferredDomain: boolean;
|
|
1513
1579
|
}
|
|
1514
1580
|
export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
|
|
1515
1581
|
export type CompiledExpression = {
|
|
@@ -1522,6 +1588,7 @@ export interface ComputeEngineStats {
|
|
|
1522
1588
|
expressions: null | Set<BoxedExpression>;
|
|
1523
1589
|
highwaterMark: number;
|
|
1524
1590
|
}
|
|
1591
|
+
export type AssignValue = boolean | number | string | Decimal | Complex | LatexString | SemiBoxedExpression | ((ce: any, args: any) => BoxedExpression) | undefined;
|
|
1525
1592
|
/** @internal */
|
|
1526
1593
|
export interface IComputeEngine {
|
|
1527
1594
|
latexDictionary: readonly LatexDictionaryEntry[];
|
|
@@ -1691,12 +1758,21 @@ export interface IComputeEngine {
|
|
|
1691
1758
|
* Associate a new definition to a symbol in the current context.
|
|
1692
1759
|
*
|
|
1693
1760
|
* If a definition existed previously, it is replaced.
|
|
1761
|
+
*
|
|
1762
|
+
*
|
|
1763
|
+
* For internal use. Use `ce.declare()` instead.
|
|
1764
|
+
*
|
|
1765
|
+
* @internal
|
|
1694
1766
|
*/
|
|
1695
1767
|
defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
|
|
1696
1768
|
/**
|
|
1697
1769
|
* Associate a new definition to a function in the current context.
|
|
1698
1770
|
*
|
|
1699
1771
|
* If a definition existed previously, it is replaced.
|
|
1772
|
+
*
|
|
1773
|
+
* For internal use. Use `ce.declare()` instead.
|
|
1774
|
+
*
|
|
1775
|
+
* @internal
|
|
1700
1776
|
*/
|
|
1701
1777
|
defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
|
|
1702
1778
|
lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
|
|
@@ -1837,14 +1913,54 @@ export interface IComputeEngine {
|
|
|
1837
1913
|
/** {@inheritDoc JsonSerializationOptions} */
|
|
1838
1914
|
get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
|
|
1839
1915
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
/**
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1916
|
+
/** Create a new scope on top of the scope stack, and set it as current */
|
|
1917
|
+
pushScope(scope?: Partial<Scope>): IComputeEngine;
|
|
1918
|
+
/** Remove the most recent scope from the scope stack, and set its
|
|
1919
|
+
* parent scope as current. */
|
|
1920
|
+
popScope(): IComputeEngine;
|
|
1921
|
+
/** Set the current scope, return the previous scope. */
|
|
1922
|
+
swapScope(scope: RuntimeScope | null): RuntimeScope | null;
|
|
1923
|
+
/** Assign a value to an identifier in the current scope.
|
|
1924
|
+
* Use `undefined` to reset the identifier to no value.
|
|
1925
|
+
*
|
|
1926
|
+
* The identifier should be a valid MathJSON identifier
|
|
1927
|
+
* not a LaTeX string.
|
|
1928
|
+
*
|
|
1929
|
+
* The identifier can take the form "f(x, y") to create a function
|
|
1930
|
+
* with two parameters, "x" and "y".
|
|
1931
|
+
*
|
|
1932
|
+
* If the id was not previously declared, an automatic declaration
|
|
1933
|
+
* is done. The domain of the identifier is inferred from the value.
|
|
1934
|
+
* To more precisely define the domain of the identifier, use `ce.declare()`
|
|
1935
|
+
* instead, which allows you to specify the domain, value and other
|
|
1936
|
+
* attributes of the identifier.
|
|
1937
|
+
*/
|
|
1938
|
+
assign(ids: {
|
|
1939
|
+
[id: string]: AssignValue;
|
|
1940
|
+
}): IComputeEngine;
|
|
1941
|
+
assign(id: string, value: AssignValue): IComputeEngine;
|
|
1942
|
+
assign(arg1: string | {
|
|
1943
|
+
[id: string]: AssignValue;
|
|
1944
|
+
}, arg2?: AssignValue): IComputeEngine;
|
|
1945
|
+
/**
|
|
1946
|
+
* Declare an identifier: specify their domain, and other attributes,
|
|
1947
|
+
* including optionally a value.
|
|
1948
|
+
*
|
|
1949
|
+
* Once the domain of an identifier has been declared, it cannot be changed.
|
|
1950
|
+
* The domain information is used to calculate the canonical form of
|
|
1951
|
+
* expressions and ensure they are valid. If the domain could be changed
|
|
1952
|
+
* after the fact, previously valid expressions could become invalid.
|
|
1953
|
+
*
|
|
1954
|
+
* Use the `Anyting` domain for a very generic domain.
|
|
1955
|
+
*
|
|
1956
|
+
*/
|
|
1957
|
+
declare(identifiers: {
|
|
1958
|
+
[id: string]: DomainExpression | SymbolDefinition | FunctionDefinition;
|
|
1959
|
+
}): IComputeEngine;
|
|
1960
|
+
declare(id: string, def: DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
|
|
1961
|
+
declare(arg1: string | {
|
|
1962
|
+
[id: string]: DomainExpression | SymbolDefinition | FunctionDefinition;
|
|
1963
|
+
}, arg2?: DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
|
|
1848
1964
|
/**
|
|
1849
1965
|
* Add an assumption.
|
|
1850
1966
|
*
|
|
@@ -1860,13 +1976,11 @@ export interface IComputeEngine {
|
|
|
1860
1976
|
*
|
|
1861
1977
|
*
|
|
1862
1978
|
*/
|
|
1863
|
-
assume(
|
|
1864
|
-
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
1865
|
-
assume(arg1: LatexString | SemiBoxedExpression, arg2?: BoxedExpression): AssumeResult;
|
|
1979
|
+
assume(predicate: SemiBoxedExpression): AssumeResult;
|
|
1866
1980
|
/** Remove all assumptions about one or more symbols */
|
|
1867
1981
|
forget(symbol?: string | string[]): void;
|
|
1868
1982
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
1869
|
-
ask(pattern:
|
|
1983
|
+
ask(pattern: SemiBoxedExpression): BoxedSubstitution[];
|
|
1870
1984
|
/** @internal */
|
|
1871
1985
|
shouldContinueExecution(): boolean;
|
|
1872
1986
|
/** @internal */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.16.0 */
|
|
2
2
|
export declare function distribute(expr: BoxedExpression[]): BoxedExpression;
|
|
3
3
|
/** Use the multinomial theorem (https://en.wikipedia.org/wiki/Multinomial_theorem) to expand the expression.
|
|
4
4
|
* The expression must be a power of a sum of terms.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
export declare const version = "0.
|
|
1
|
+
/* 0.16.0 */
|
|
2
|
+
export declare const version = "0.16.0";
|
|
3
3
|
export { ComputeEngine } from './compute-engine/compute-engine';
|