@cortex-js/compute-engine 0.20.2 → 0.22.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/README.md +6 -3
- package/dist/compute-engine.esm.js +6744 -4603
- package/dist/compute-engine.js +6744 -4603
- package/dist/compute-engine.min.esm.js +10 -10
- package/dist/compute-engine.min.js +10 -10
- 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 +1 -1
- 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 +4 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +3 -3
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +11 -3
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- 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 +2 -1
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +69 -0
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -0
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +8 -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/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +270 -33
- 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/function-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-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +2 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.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-inequalities.d.ts → definitions-relational-operators.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 +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/public.d.ts +5 -2
- 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 +3 -3
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +3 -3
- 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/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +2 -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/linear-algebra.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/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +5 -5
- 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 +3 -3
- 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/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +68 -286
- package/dist/types/compute-engine/rules.d.ts +9 -13
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +2 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +2 -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/tensor-fields.d.ts +168 -0
- package/dist/types/compute-engine/symbolic/tensors.d.ts +103 -0
- 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 +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.22.0 */
|
|
2
2
|
* The most important classes are {@link ComputeEngine} and
|
|
3
3
|
* {@link BoxedExpression}.
|
|
4
4
|
*
|
|
@@ -91,40 +91,39 @@ export type BoxedSubstitution = Substitution<BoxedExpression>;
|
|
|
91
91
|
* `"$\frac{\pi}{2}$"`.
|
|
92
92
|
*/
|
|
93
93
|
export type LatexString = string;
|
|
94
|
+
export type PatternReplaceFunction = (expr: BoxedExpression, wildcards: BoxedSubstitution) => BoxedExpression;
|
|
95
|
+
export type PatternConditionFunction = (wildcards: BoxedSubstitution, ce: IComputeEngine) => boolean;
|
|
94
96
|
/**
|
|
95
|
-
* A rule describes how to modify an expressions that matches a `
|
|
96
|
-
* into a new
|
|
97
|
+
* A rule describes how to modify an expressions that matches a pattern `match`
|
|
98
|
+
* into a new expression `replace`.
|
|
97
99
|
*
|
|
98
100
|
* `x-1` \( \to \) `1-x`
|
|
99
101
|
* `(x+1)(x-1)` \( \to \) `x^2-1
|
|
100
102
|
*
|
|
101
|
-
* The `
|
|
103
|
+
* The `match` pattern can be expressed as a LaTeX string or a MathJSON expression.
|
|
102
104
|
*
|
|
103
|
-
* Unbound variables (`x`, but not `Pi`) are matched structurally with a
|
|
104
|
-
* a target expression, then the expression is rewritten as the `rhs`, with
|
|
105
|
-
* the corresponding unbound variables in the `rhs` replaced by their values
|
|
106
|
-
* in the `lhs.
|
|
107
105
|
*
|
|
108
|
-
*
|
|
106
|
+
* Anonymous wildcards (`_`) will match any
|
|
107
|
+
* expression. Named wildcards (`_x`, `_a`, etc...) will match any expression
|
|
108
|
+
* and bind the expression to the wildcard name.
|
|
109
109
|
*
|
|
110
|
-
* In addition
|
|
111
|
-
*
|
|
112
|
-
* - `___1` (`___a`, etc...) match a sequence of zero or more expressions
|
|
110
|
+
* In addition the sequence wildcard (`__1`, `__a`, etc...) will match a sequence
|
|
111
|
+
* of one or more expressions, and bind the sequence to the wildcard name.
|
|
113
112
|
*/
|
|
114
|
-
export type Rule =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
priority: number
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
export type Rule = {
|
|
114
|
+
match: LatexString | SemiBoxedExpression | Pattern;
|
|
115
|
+
replace: LatexString | SemiBoxedExpression | PatternReplaceFunction;
|
|
116
|
+
condition?: LatexString | PatternConditionFunction;
|
|
117
|
+
priority?: number;
|
|
118
|
+
id?: string;
|
|
119
|
+
};
|
|
120
|
+
export type BoxedRule = {
|
|
121
|
+
match: Pattern;
|
|
122
|
+
replace: BoxedExpression | PatternReplaceFunction;
|
|
123
|
+
condition: undefined | PatternConditionFunction;
|
|
124
|
+
priority: number;
|
|
125
|
+
id?: string;
|
|
126
|
+
};
|
|
128
127
|
export type BoxedRuleSet = Set<BoxedRule>;
|
|
129
128
|
export type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
|
|
130
129
|
/** A domain constructor is the head of a domain expression. */
|
|
@@ -189,6 +188,7 @@ export type JsonSerializationOptions = {
|
|
|
189
188
|
*/
|
|
190
189
|
precision: 'auto' | 'max' | number;
|
|
191
190
|
};
|
|
191
|
+
export type CanonicalForm = 'InvisibleOperator' | 'Number' | 'Multiply' | 'Add' | 'Power' | 'Divide' | 'Flatten' | 'Order';
|
|
192
192
|
/**
|
|
193
193
|
* ## THEORY OF OPERATIONS
|
|
194
194
|
*
|
|
@@ -207,6 +207,8 @@ export interface BoxedExpression {
|
|
|
207
207
|
/** The Compute Engine associated with this expression provides
|
|
208
208
|
* a context in which to interpret it, such as definition of symbols
|
|
209
209
|
* and functions.
|
|
210
|
+
*
|
|
211
|
+
* {@link ComputeEngine} is the class that implements IComputeEngine.
|
|
210
212
|
*/
|
|
211
213
|
readonly engine: IComputeEngine;
|
|
212
214
|
/** From `Object.valueOf()`, return a primitive value for the expression.
|
|
@@ -231,6 +233,12 @@ export interface BoxedExpression {
|
|
|
231
233
|
* @category Primitive Methods
|
|
232
234
|
*/
|
|
233
235
|
toString(): string;
|
|
236
|
+
/**
|
|
237
|
+
* Output to the console a string representation of the expression.
|
|
238
|
+
*
|
|
239
|
+
* @category Primitive Methods
|
|
240
|
+
*/
|
|
241
|
+
print(): void;
|
|
234
242
|
/** Similar to`expr.valueOf()` but includes a hint.
|
|
235
243
|
* @category Primitive Methods
|
|
236
244
|
*/
|
|
@@ -588,10 +596,22 @@ export interface BoxedExpression {
|
|
|
588
596
|
* Note it is possible for `numericValue` to be `null`, and for `isNotZero`
|
|
589
597
|
* to be true. For example, when a symbol has been defined with an assumption.
|
|
590
598
|
*
|
|
599
|
+
* Conversely, `isNumber` may be true even if `numericValue` is `null`,
|
|
600
|
+
* example the symbol `Pi` return true for `isNumber` but `numericValue` is
|
|
601
|
+
* `null`. It's value can be accessed with `.value.numericValue`
|
|
602
|
+
*
|
|
591
603
|
* @category Numeric Expression
|
|
592
604
|
*
|
|
593
605
|
*/
|
|
594
606
|
readonly numericValue: number | Decimal | Complex | Rational | null;
|
|
607
|
+
/** The shape describes the axis of the expression.
|
|
608
|
+
* When the expression is a scalar (number), the shape is `[]`.
|
|
609
|
+
* When the expression is a vector, the shape is `[n]`.
|
|
610
|
+
* When the expression is a matrix, the shape is `[n, m]`.
|
|
611
|
+
*/
|
|
612
|
+
readonly shape: number[];
|
|
613
|
+
/** Return 0 for a scalar, 1 for a vector, 2 for a matrix, > 2 for a multidimensional matrix. It's the length of `expr.shape` */
|
|
614
|
+
readonly rank: number;
|
|
595
615
|
/**
|
|
596
616
|
* Return the following, depending on the value of this expression:
|
|
597
617
|
*
|
|
@@ -974,6 +994,14 @@ export interface BoxedExpression {
|
|
|
974
994
|
* of an existing `BoxedExpression` while avoiding unboxing and reboxing.
|
|
975
995
|
*/
|
|
976
996
|
export type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
|
|
997
|
+
/**
|
|
998
|
+
* Control how a pattern is matched to an expression.
|
|
999
|
+
*
|
|
1000
|
+
* - `substitution`: if present, assumes these values for the named wildcards, and ensure that subsequent occurence of the same wildcard have the same value.
|
|
1001
|
+
* - `recursive`: if true, match recursively, otherwise match only the top level.
|
|
1002
|
+
* - `numericTolerance`: if present, the tolerance for numeric comparison.
|
|
1003
|
+
* - `exact`: if true, only match expressions that are structurally identical. If false, match expressions that are structurally identical or equivalent. For example, when false, `["Add", '_a', 2]` matches `2`, with a value of `_a` of `0`. If true, the expression does not match.
|
|
1004
|
+
*/
|
|
977
1005
|
export type PatternMatchOptions = {
|
|
978
1006
|
substitution?: BoxedSubstitution;
|
|
979
1007
|
recursive?: boolean;
|
|
@@ -1560,6 +1588,7 @@ export interface ComputeEngineStats {
|
|
|
1560
1588
|
highwaterMark: number;
|
|
1561
1589
|
}
|
|
1562
1590
|
export type AssignValue = boolean | number | string | Decimal | Complex | LatexString | SemiBoxedExpression | ((ce: any, args: any) => BoxedExpression) | undefined;
|
|
1591
|
+
export type ArrayValue = boolean | number | string | Decimal | Complex | BoxedExpression | undefined;
|
|
1563
1592
|
/** @internal */
|
|
1564
1593
|
export interface IComputeEngine {
|
|
1565
1594
|
latexDictionary: readonly LatexDictionaryEntry[];
|
|
@@ -1615,174 +1644,38 @@ export interface IComputeEngine {
|
|
|
1615
1644
|
chop(n: Decimal): Decimal | 0;
|
|
1616
1645
|
chop(n: Complex): Complex | 0;
|
|
1617
1646
|
chop(n: number | Decimal | Complex): number | Decimal | Complex;
|
|
1618
|
-
/** Create an arbitrary precision number.
|
|
1619
|
-
*
|
|
1620
|
-
* The return value is an object with methods to perform arithmetic
|
|
1621
|
-
* operations:
|
|
1622
|
-
* - `toNumber()`: convert to a JavaScript `number` with potential loss of precision
|
|
1623
|
-
* - `add()`
|
|
1624
|
-
* - `sub()`
|
|
1625
|
-
* - `neg()` (unary minus)
|
|
1626
|
-
* - `mul()`
|
|
1627
|
-
* - `div()`
|
|
1628
|
-
* - `pow()`
|
|
1629
|
-
* - `sqrt()` (square root)
|
|
1630
|
-
* - `cbrt()` (cube root)
|
|
1631
|
-
* - `exp()` (e^x)
|
|
1632
|
-
* - `log()`
|
|
1633
|
-
* - `ln()` (natural logarithm)
|
|
1634
|
-
* - `mod()`
|
|
1635
|
-
|
|
1636
|
-
* - `abs()`
|
|
1637
|
-
* - `ceil()`
|
|
1638
|
-
* - `floor()`
|
|
1639
|
-
* - `round()`
|
|
1640
|
-
|
|
1641
|
-
* - `equals()`
|
|
1642
|
-
* - `gt()`
|
|
1643
|
-
* - `gte()`
|
|
1644
|
-
* - `lt()`
|
|
1645
|
-
* - `lte()`
|
|
1646
|
-
*
|
|
1647
|
-
* - `cos()`
|
|
1648
|
-
* - `sin()`
|
|
1649
|
-
* - `tanh()`
|
|
1650
|
-
* - `acos()`
|
|
1651
|
-
* - `asin()`
|
|
1652
|
-
* - `atan()`
|
|
1653
|
-
* - `cosh()`
|
|
1654
|
-
* - `sinh()`
|
|
1655
|
-
* - `acosh()`
|
|
1656
|
-
* - `asinh()`
|
|
1657
|
-
* - `atanh()`
|
|
1658
|
-
*
|
|
1659
|
-
* - `isFinite()`
|
|
1660
|
-
* - `isInteger()`
|
|
1661
|
-
* - `isNaN()`
|
|
1662
|
-
* - `isNegative()`
|
|
1663
|
-
* - `isPositive()`
|
|
1664
|
-
* - `isZero()`
|
|
1665
|
-
* - `sign()` (1, 0 or -1)
|
|
1666
|
-
*
|
|
1667
|
-
*/
|
|
1668
1647
|
bignum: (a: Decimal.Value | bigint) => Decimal;
|
|
1669
|
-
/** Create a complex number.
|
|
1670
|
-
* The return value is an object with methods to perform arithmetic
|
|
1671
|
-
* operations:
|
|
1672
|
-
* - `re` (real part, as a JavaScript `number`)
|
|
1673
|
-
* - `im` (imaginary part, as a JavaScript `number`)
|
|
1674
|
-
* - `add()`
|
|
1675
|
-
* - `sub()`
|
|
1676
|
-
* - `neg()` (unary minus)
|
|
1677
|
-
* - `mul()`
|
|
1678
|
-
* - `div()`
|
|
1679
|
-
* - `pow()`
|
|
1680
|
-
* - `sqrt()` (square root)
|
|
1681
|
-
* - `exp()` (e^x)
|
|
1682
|
-
* - `log()`
|
|
1683
|
-
* - `ln()` (natural logarithm)
|
|
1684
|
-
* - `mod()`
|
|
1685
|
-
|
|
1686
|
-
* - `abs()`
|
|
1687
|
-
* - `ceil()`
|
|
1688
|
-
* - `floor()`
|
|
1689
|
-
* - `round()`
|
|
1690
|
-
|
|
1691
|
-
* - `arg()` the angle of the complex number
|
|
1692
|
-
* - `inverse()` the inverse of the complex number 1/z
|
|
1693
|
-
* - `conjugate()` the conjugate of the complex number
|
|
1694
|
-
|
|
1695
|
-
* - `equals()`
|
|
1696
|
-
*
|
|
1697
|
-
* - `cos()`
|
|
1698
|
-
* - `sin()`
|
|
1699
|
-
* - `tanh()`
|
|
1700
|
-
* - `acos()`
|
|
1701
|
-
* - `asin()`
|
|
1702
|
-
* - `atan()`
|
|
1703
|
-
* - `cosh()`
|
|
1704
|
-
* - `sinh()`
|
|
1705
|
-
* - `acosh()`
|
|
1706
|
-
* - `asinh()`
|
|
1707
|
-
* - `atanh()`
|
|
1708
|
-
*
|
|
1709
|
-
* - `isFinite()`
|
|
1710
|
-
* - `isNaN()`
|
|
1711
|
-
* - `isZero()`
|
|
1712
|
-
* - `sign()` (1, 0 or -1)
|
|
1713
|
-
*/
|
|
1714
1648
|
complex: (a: number | Complex, b?: number) => Complex;
|
|
1715
1649
|
isBignum(a: unknown): a is Decimal;
|
|
1716
1650
|
isComplex(a: unknown): a is Complex;
|
|
1717
1651
|
set precision(p: number | 'machine');
|
|
1718
1652
|
get precision(): number;
|
|
1719
1653
|
costFunction: (expr: BoxedExpression) => number;
|
|
1720
|
-
/** In strict mode (the default) the Compute Engine performs
|
|
1721
|
-
* validation of domains and signature and may report errors.
|
|
1722
|
-
*
|
|
1723
|
-
* When strict mode is off, results may be incorrect or generate JavaScript
|
|
1724
|
-
* errors if the input is not valid.
|
|
1725
|
-
*
|
|
1726
|
-
*/
|
|
1727
1654
|
strict: boolean;
|
|
1728
|
-
/**
|
|
1729
|
-
* Associate a new definition to a symbol in the current context.
|
|
1730
|
-
*
|
|
1731
|
-
* If a definition existed previously, it is replaced.
|
|
1732
|
-
*
|
|
1733
|
-
*
|
|
1734
|
-
* For internal use. Use `ce.declare()` instead.
|
|
1735
|
-
*
|
|
1736
|
-
* @internal
|
|
1737
|
-
*/
|
|
1738
1655
|
defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
|
|
1739
|
-
/**
|
|
1740
|
-
* Associate a new definition to a function in the current context.
|
|
1741
|
-
*
|
|
1742
|
-
* If a definition existed previously, it is replaced.
|
|
1743
|
-
*
|
|
1744
|
-
* For internal use. Use `ce.declare()` instead.
|
|
1745
|
-
*
|
|
1746
|
-
* @internal
|
|
1747
|
-
*/
|
|
1748
1656
|
defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
|
|
1749
1657
|
lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
|
|
1750
|
-
/** Return `undefined` if no definition exist for this `head` */
|
|
1751
1658
|
lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
|
|
1752
|
-
/**
|
|
1753
|
-
* Return a boxed expression from the input.
|
|
1754
|
-
*/
|
|
1755
1659
|
box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
|
|
1756
|
-
canonical?: boolean;
|
|
1660
|
+
canonical?: boolean | CanonicalForm | CanonicalForm[];
|
|
1757
1661
|
}): BoxedExpression;
|
|
1758
1662
|
canonical(xs: SemiBoxedExpression[]): BoxedExpression[];
|
|
1759
|
-
/** Return a boxed number */
|
|
1760
1663
|
number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
|
|
1761
1664
|
metadata?: Metadata;
|
|
1762
1665
|
canonical?: boolean;
|
|
1763
1666
|
}): BoxedExpression;
|
|
1764
|
-
/** Return a canonical boxed symbol */
|
|
1765
1667
|
symbol(sym: string, options?: {
|
|
1766
1668
|
metadata?: Metadata;
|
|
1767
1669
|
canonical?: boolean;
|
|
1768
1670
|
}): BoxedExpression;
|
|
1769
|
-
/** Return a canonical boxed string */
|
|
1770
1671
|
string(s: string, metadata?: Metadata): BoxedExpression;
|
|
1771
|
-
/** Return a canonical boxed domain.
|
|
1772
|
-
*
|
|
1773
|
-
* If the domain is invalid, may return an `["Error"]` expression
|
|
1774
|
-
*
|
|
1775
|
-
*/
|
|
1776
1672
|
domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
|
|
1777
1673
|
/**
|
|
1778
|
-
*
|
|
1779
|
-
*
|
|
1780
|
-
* Note that the result may not be a function, or may have a different
|
|
1781
|
-
* `head` than the one specified.
|
|
1782
|
-
*
|
|
1783
|
-
* For example:
|
|
1784
|
-
* `ce.fn("Rational", [ce.number(1), ce.number(2)]))` \( \to \) `ce.number([1,2])`
|
|
1674
|
+
* Create a boxed function expression.
|
|
1785
1675
|
*
|
|
1676
|
+
* @param head
|
|
1677
|
+
* @param ops
|
|
1678
|
+
* @param options
|
|
1786
1679
|
*/
|
|
1787
1680
|
fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], options?: {
|
|
1788
1681
|
canonical: boolean;
|
|
@@ -1796,128 +1689,46 @@ export interface IComputeEngine {
|
|
|
1796
1689
|
* The result is canonical, but the caller has to ensure that all the
|
|
1797
1690
|
* conditions are met (i.e. `ops` properly normalized and sorted, all
|
|
1798
1691
|
* `ops` canonical, etc..) so that the result is actually canonical.
|
|
1799
|
-
*/
|
|
1800
|
-
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1801
|
-
/** Shortcut for `this.fn("Error"...)`.
|
|
1802
1692
|
*
|
|
1803
|
-
*
|
|
1693
|
+
* @internal
|
|
1804
1694
|
*/
|
|
1695
|
+
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1805
1696
|
error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
|
|
1806
1697
|
domainError(expectedDomain: BoxedDomain | DomainLiteral, actualDomain: undefined | BoxedDomain, where?: SemiBoxedExpression): BoxedExpression;
|
|
1807
|
-
/**
|
|
1808
|
-
* Add a`["Hold"]` wrapper to `expr.
|
|
1809
|
-
*/
|
|
1810
1698
|
hold(expr: SemiBoxedExpression): BoxedExpression;
|
|
1811
|
-
/** Shortcut for `this.fn("Add"...)`.
|
|
1812
|
-
*
|
|
1813
|
-
* The result is canonical.
|
|
1814
|
-
*/
|
|
1815
1699
|
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1816
|
-
/** Shortcut for `this.fn("Multiply"...)`
|
|
1817
|
-
*
|
|
1818
|
-
* The result is canonical.
|
|
1819
|
-
*/
|
|
1820
1700
|
mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1821
|
-
/** Shortcut for `this.fn("Power"...)`
|
|
1822
|
-
*
|
|
1823
|
-
* The result is canonical.
|
|
1824
|
-
*/
|
|
1825
1701
|
pow(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1826
|
-
|
|
1827
|
-
*
|
|
1828
|
-
* The result is canonical.
|
|
1829
|
-
*/
|
|
1830
|
-
sqrt(base: BoxedExpression, metadata?: Metadata): any;
|
|
1831
|
-
/** Shortcut for `this.fn("Divide", [1, expr])`
|
|
1832
|
-
*
|
|
1833
|
-
* The result is canonical.
|
|
1834
|
-
*/
|
|
1702
|
+
sqrt(base: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1835
1703
|
inv(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1836
|
-
/** Shortcut for `this.fn("Negate", [expr])`
|
|
1837
|
-
*
|
|
1838
|
-
* The result is canonical.
|
|
1839
|
-
*/
|
|
1840
1704
|
neg(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1841
|
-
/** Shortcut for `this.fn("Divide", [num, denom])`
|
|
1842
|
-
*
|
|
1843
|
-
* The result is canonical.
|
|
1844
|
-
*/
|
|
1845
1705
|
div(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1846
|
-
/** Shortcut for `this.fn("Pair"...)`
|
|
1847
|
-
*
|
|
1848
|
-
* The result is canonical.
|
|
1849
|
-
*/
|
|
1850
1706
|
pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1851
|
-
|
|
1852
|
-
*
|
|
1853
|
-
* The result is canonical.
|
|
1854
|
-
*/
|
|
1707
|
+
tuple(elements: number[], metadata?: Metadata): BoxedExpression;
|
|
1855
1708
|
tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
1709
|
+
array(elements: ArrayValue[] | ArrayValue[][], metadata?: Metadata): BoxedExpression;
|
|
1856
1710
|
rules(rules: Rule[]): BoxedRuleSet;
|
|
1857
1711
|
pattern(expr: LatexString | SemiBoxedExpression): Pattern;
|
|
1858
|
-
/**
|
|
1859
|
-
* Parse a string of LaTeX and return a corresponding `BoxedExpression`.
|
|
1860
|
-
*
|
|
1861
|
-
* The result may not be canonical.
|
|
1862
|
-
*
|
|
1863
|
-
*/
|
|
1864
1712
|
parse(s: LatexString | string, options?: {
|
|
1865
|
-
canonical?: boolean;
|
|
1713
|
+
canonical?: boolean | CanonicalForm | CanonicalForm[];
|
|
1866
1714
|
}): BoxedExpression;
|
|
1867
1715
|
parse(s: null, options?: {
|
|
1868
|
-
canonical?: boolean;
|
|
1716
|
+
canonical?: boolean | CanonicalForm | CanonicalForm[];
|
|
1869
1717
|
}): null;
|
|
1870
1718
|
parse(s: LatexString | string | null, options?: {
|
|
1871
|
-
canonical?: boolean;
|
|
1719
|
+
canonical?: boolean | CanonicalForm | CanonicalForm[];
|
|
1872
1720
|
}): null | BoxedExpression;
|
|
1873
|
-
/** Serialize a `BoxedExpression` or a `MathJSON` expression to
|
|
1874
|
-
* a LaTeX string
|
|
1875
|
-
*/
|
|
1876
1721
|
serialize(expr: SemiBoxedExpression, options?: {
|
|
1877
1722
|
canonical?: boolean;
|
|
1878
1723
|
}): LatexString;
|
|
1879
|
-
/**
|
|
1880
|
-
* Options to control the serialization of MathJSON expression to LaTeX
|
|
1881
|
-
* when using `this.latex` or `this.engine.serialize()`.
|
|
1882
|
-
*
|
|
1883
|
-
*
|
|
1884
|
-
* {@inheritDoc NumberFormattingOptions}
|
|
1885
|
-
* {@inheritDoc ParseLatexOptions}
|
|
1886
|
-
* {@inheritDoc SerializeLatexOptions}
|
|
1887
|
-
*
|
|
1888
|
-
*/
|
|
1889
1724
|
get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
1890
1725
|
set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
|
|
1891
|
-
/** {@inheritDoc JsonSerializationOptions} */
|
|
1892
1726
|
get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
|
|
1893
1727
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
1894
|
-
/** Create a new scope on top of the scope stack, and set it as current */
|
|
1895
1728
|
pushScope(scope?: Partial<Scope>): IComputeEngine;
|
|
1896
|
-
/** Remove the most recent scope from the scope stack, and set its
|
|
1897
|
-
* parent scope as current. */
|
|
1898
1729
|
popScope(): IComputeEngine;
|
|
1899
|
-
/** Set the current scope, return the previous scope. */
|
|
1900
1730
|
swapScope(scope: RuntimeScope | null): RuntimeScope | null;
|
|
1901
|
-
/**
|
|
1902
|
-
* Reset the value of any identifiers that have been assigned a value
|
|
1903
|
-
* in the current scope.
|
|
1904
|
-
* @internal */
|
|
1905
1731
|
resetContext(): void;
|
|
1906
|
-
/** Assign a value to an identifier in the current scope.
|
|
1907
|
-
* Use `undefined` to reset the identifier to no value.
|
|
1908
|
-
*
|
|
1909
|
-
* The identifier should be a valid MathJSON identifier
|
|
1910
|
-
* not a LaTeX string.
|
|
1911
|
-
*
|
|
1912
|
-
* The identifier can take the form "f(x, y") to create a function
|
|
1913
|
-
* with two parameters, "x" and "y".
|
|
1914
|
-
*
|
|
1915
|
-
* If the id was not previously declared, an automatic declaration
|
|
1916
|
-
* is done. The domain of the identifier is inferred from the value.
|
|
1917
|
-
* To more precisely define the domain of the identifier, use `ce.declare()`
|
|
1918
|
-
* instead, which allows you to specify the domain, value and other
|
|
1919
|
-
* attributes of the identifier.
|
|
1920
|
-
*/
|
|
1921
1732
|
assign(ids: {
|
|
1922
1733
|
[id: string]: AssignValue;
|
|
1923
1734
|
}): IComputeEngine;
|
|
@@ -1925,18 +1736,6 @@ export interface IComputeEngine {
|
|
|
1925
1736
|
assign(arg1: string | {
|
|
1926
1737
|
[id: string]: AssignValue;
|
|
1927
1738
|
}, arg2?: AssignValue): IComputeEngine;
|
|
1928
|
-
/**
|
|
1929
|
-
* Declare an identifier: specify their domain, and other attributes,
|
|
1930
|
-
* including optionally a value.
|
|
1931
|
-
*
|
|
1932
|
-
* Once the domain of an identifier has been declared, it cannot be changed.
|
|
1933
|
-
* The domain information is used to calculate the canonical form of
|
|
1934
|
-
* expressions and ensure they are valid. If the domain could be changed
|
|
1935
|
-
* after the fact, previously valid expressions could become invalid.
|
|
1936
|
-
*
|
|
1937
|
-
* Use the `Anyting` domain for a very generic domain.
|
|
1938
|
-
*
|
|
1939
|
-
*/
|
|
1940
1739
|
declare(identifiers: {
|
|
1941
1740
|
[id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
|
|
1942
1741
|
}): IComputeEngine;
|
|
@@ -1944,27 +1743,10 @@ export interface IComputeEngine {
|
|
|
1944
1743
|
declare(arg1: string | {
|
|
1945
1744
|
[id: string]: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition;
|
|
1946
1745
|
}, arg2?: BoxedDomain | DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
|
|
1947
|
-
/**
|
|
1948
|
-
* Add an assumption.
|
|
1949
|
-
*
|
|
1950
|
-
* Note that the assumption is put into canonical form before being added.
|
|
1951
|
-
*
|
|
1952
|
-
* @param symbol - The symbol to make an assumption about
|
|
1953
|
-
*
|
|
1954
|
-
* Returns:
|
|
1955
|
-
* - `contradiction` if the new assumption is incompatible with previous
|
|
1956
|
-
* ones.
|
|
1957
|
-
* - `tautology` if the new assumption is redundant with previous ones.
|
|
1958
|
-
* - `ok` if the assumption was successfully added to the assumption set.
|
|
1959
|
-
*
|
|
1960
|
-
*
|
|
1961
|
-
*/
|
|
1962
1746
|
assume(predicate: SemiBoxedExpression): AssumeResult;
|
|
1963
|
-
/** Remove all assumptions about one or more symbols */
|
|
1964
1747
|
forget(symbol?: string | string[]): void;
|
|
1965
1748
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
1966
1749
|
ask(pattern: SemiBoxedExpression): BoxedSubstitution[];
|
|
1967
|
-
/** Using the current assumptions, answer a query. */
|
|
1968
1750
|
verify(query: SemiBoxedExpression): boolean;
|
|
1969
1751
|
/** @internal */
|
|
1970
1752
|
shouldContinueExecution(): boolean;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.22.0 */
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* For each rules in the rule set that match, return the `replace` of the rule
|
|
4
|
+
*
|
|
5
5
|
* @param rules
|
|
6
6
|
*/
|
|
7
7
|
export declare function matchRules(expr: BoxedExpression, rules: BoxedRuleSet, sub: BoxedSubstitution): BoxedExpression[];
|
|
8
|
+
/**
|
|
9
|
+
* Create a boxed rule set from a non-boxed rule set
|
|
10
|
+
* @param ce
|
|
11
|
+
* @param rs
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
8
14
|
export declare function boxRules(ce: IComputeEngine, rs: Iterable<Rule>): BoxedRuleSet;
|
|
9
15
|
/**
|
|
10
16
|
* Apply the rules in the ruleset and return a modified expression.
|
|
@@ -12,13 +18,3 @@ export declare function boxRules(ce: IComputeEngine, rs: Iterable<Rule>): BoxedR
|
|
|
12
18
|
* If no rule applied, return `null`.
|
|
13
19
|
*/
|
|
14
20
|
export declare function replace(expr: BoxedExpression, ruleSet: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
|
|
15
|
-
/**
|
|
16
|
-
* Substitute some symbols with an expression.
|
|
17
|
-
*
|
|
18
|
-
* This is applied recursively to all subexpressions.
|
|
19
|
-
*
|
|
20
|
-
* While `replace()` applies a rule which may include expressions in
|
|
21
|
-
* its `lhs` to an expression, `substitute` is a specialized version
|
|
22
|
-
* that only apply rules that have a `lhs` made of a symbol.
|
|
23
|
-
*/
|
|
24
|
-
export declare function getWildcardName(s: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.22.0 */
|
|
2
2
|
export declare const UNIVARIATE_ROOTS: Rule[];
|
|
3
3
|
/**
|
|
4
4
|
* Expression is a function of a single variable (`x`) or an Equality
|
|
@@ -15,3 +15,4 @@ export declare function findUnivariateRoots(expr: BoxedExpression, x: string): B
|
|
|
15
15
|
* `2x < 4` => `x < 2`
|
|
16
16
|
*/
|
|
17
17
|
export declare function univariateSolve(expr: BoxedExpression, x: string): SemiBoxedExpression[] | null;
|
|
18
|
+
export declare const HARMONIZATION_RULES: Rule[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.22.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,6 +1,7 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.22.0 */
|
|
2
2
|
/**
|
|
3
3
|
* Flatten the arguments.
|
|
4
4
|
*/
|
|
5
5
|
export declare function flattenOps(ops: BoxedExpression[], head: string): BoxedExpression[];
|
|
6
6
|
export declare function flattenSequence(xs: BoxedExpression[]): BoxedExpression[];
|
|
7
|
+
export declare function flattenDelimiter(ce: IComputeEngine, body: undefined | BoxedExpression): BoxedExpression;
|