@cortex-js/compute-engine 0.22.0 → 0.23.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.
Files changed (108) hide show
  1. package/dist/compute-engine.esm.js +7550 -6908
  2. package/dist/compute-engine.js +7549 -6907
  3. package/dist/compute-engine.min.esm.js +10 -10
  4. package/dist/compute-engine.min.js +10 -10
  5. package/dist/math-json.esm.js +12 -11
  6. package/dist/math-json.js +12 -11
  7. package/dist/math-json.min.esm.js +12 -11
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +1 -1
  12. package/dist/types/common/utils.d.ts +1 -1
  13. package/dist/types/compute-engine/assume.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +11 -10
  15. package/dist/types/compute-engine/boxed-expression/box.d.ts +2 -2
  16. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +2 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +2 -2
  26. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  30. package/dist/types/compute-engine/boxed-expression/utils.d.ts +16 -51
  31. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  32. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  33. package/dist/types/compute-engine/compile.d.ts +1 -1
  34. package/dist/types/compute-engine/compute-engine.d.ts +41 -39
  35. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  36. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  37. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +4 -2
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +2 -1
  52. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/public.d.ts +13 -6
  56. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  57. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +4 -3
  58. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +6 -6
  59. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  60. package/dist/types/compute-engine/library/arithmetic-add.d.ts +13 -3
  61. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +2 -1
  62. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +6 -8
  63. package/dist/types/compute-engine/library/arithmetic-power.d.ts +3 -1
  64. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  65. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  66. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  67. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  68. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  69. package/dist/types/compute-engine/library/core.d.ts +1 -1
  70. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  71. package/dist/types/compute-engine/library/library.d.ts +1 -1
  72. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  73. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  74. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  75. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  76. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  77. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  78. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  79. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  80. package/dist/types/compute-engine/library/utils.d.ts +24 -2
  81. package/dist/types/compute-engine/numerics/factor.d.ts +27 -0
  82. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +3 -1
  83. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  84. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  85. package/dist/types/compute-engine/numerics/numeric.d.ts +8 -1
  86. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  87. package/dist/types/compute-engine/numerics/rationals.d.ts +8 -22
  88. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  89. package/dist/types/compute-engine/numerics/terms.d.ts +14 -0
  90. package/dist/types/compute-engine/public.d.ts +45 -37
  91. package/dist/types/compute-engine/rules.d.ts +1 -1
  92. package/dist/types/compute-engine/simplify-rules.d.ts +11 -1
  93. package/dist/types/compute-engine/solve.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/expand.d.ts +5 -1
  96. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  97. package/dist/types/compute-engine/symbolic/negate.d.ts +3 -2
  98. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  99. package/dist/types/compute-engine/symbolic/product.d.ts +8 -3
  100. package/dist/types/compute-engine/symbolic/tensor-fields.d.ts +1 -1
  101. package/dist/types/compute-engine/symbolic/tensors.d.ts +1 -1
  102. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  103. package/dist/types/compute-engine.d.ts +2 -2
  104. package/dist/types/math-json/math-json-format.d.ts +1 -1
  105. package/dist/types/math-json/utils.d.ts +1 -1
  106. package/dist/types/math-json.d.ts +2 -2
  107. package/package.json +1 -1
  108. package/dist/types/compute-engine/symbolic/sum.d.ts +0 -33
@@ -1,4 +1,6 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
+ import { Expression } from '../../math-json.js';
3
+ export declare function bigintValue(expr: Expression | null | undefined): bigint | null;
2
4
  export declare function bigint(a: Decimal | number | bigint | string): bigint;
3
5
  export declare function gcd(a: bigint, b: bigint): bigint;
4
6
  export declare function lcm(a: bigint, b: bigint): bigint;
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  import { IComputeEngine } from '../public';
3
3
  export declare function gcd(a: Decimal, b: Decimal): Decimal;
4
4
  export declare function lcm(a: Decimal, b: Decimal): Decimal;
@@ -1,3 +1,3 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  export declare function gamma(c: Complex): Complex;
3
3
  export declare function gammaln(c: Complex): Complex;
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedExpression } from '../public';
4
4
  export declare const MACHINE_PRECISION_BITS = 53;
@@ -109,3 +109,10 @@ export declare function monteCarloEstimate(f: (x: number) => number, a: number,
109
109
  export declare function limit(f: (x: number) => number, x: number, dir?: number): number;
110
110
  export declare function fromRoman(roman: string): [result: number, rest: string];
111
111
  export declare function fromDigits(s: string, baseInput?: string | number): [result: number, rest: string];
112
+ /**
113
+ *
114
+ * @param lhs
115
+ * @param rhs
116
+ * @returns the sign (-1, 0, 1) of the difference between `lhs` and `rhs`
117
+ */
118
+ export declare function signDiff(lhs: BoxedExpression, rhs: BoxedExpression, tolerance?: number): -1 | 0 | 1 | undefined;
@@ -1,2 +1,2 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  export declare function isPrime(n: number): boolean | undefined;
@@ -1,9 +1,10 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  export declare function isRational(x: any | null): x is Rational;
3
3
  export declare function isMachineRational(x: any | null): x is [number, number];
4
4
  export declare function isBigRational(x: any | null): x is [bigint, bigint];
5
5
  export declare function isRationalZero(x: Rational): boolean;
6
6
  export declare function isRationalOne(x: Rational): boolean;
7
+ export declare function isRationalInteger(x: Rational): boolean;
7
8
  export declare function isRationalNegativeOne(x: Rational): boolean;
8
9
  export declare function machineNumerator(x: Rational): number;
9
10
  export declare function machineDenominator(x: Rational): number;
@@ -17,7 +18,7 @@ export declare function inverse(x: Rational): Rational;
17
18
  export declare function asRational(expr: BoxedExpression): Rational | undefined;
18
19
  /**
19
20
  * Add a literal numeric value to a rational.
20
- * If the rational is a bignum, this is a hint to do the calculation in bignum
21
+ * If the rational is a bigint, this is a hint to do the calculation in bigint
21
22
  * (no need to check `bignumPreferred()`).
22
23
  * @param lhs
23
24
  * @param rhs
@@ -25,30 +26,15 @@ export declare function asRational(expr: BoxedExpression): Rational | undefined;
25
26
  */
26
27
  export declare function add(lhs: Rational, rhs: BoxedExpression | Rational): Rational;
27
28
  export declare function mul(lhs: Rational, rhs: BoxedExpression | Rational): Rational;
29
+ export declare function div(lhs: Rational, rhs: Rational): Rational;
28
30
  export declare function pow(r: Rational, exp: number): Rational;
31
+ export declare function sqrt(r: Rational): Rational | undefined;
29
32
  export declare function reducedRational(r: [number, number]): [number, number];
30
33
  export declare function reducedRational(r: [bigint, bigint]): [bigint, bigint];
31
34
  export declare function reducedRational(r: Rational): Rational;
32
35
  /** Return a rational approximation of x */
33
36
  export declare function rationalize(x: number): [n: number, d: number] | number;
34
- /**
35
- * Attempt to factor a rational coefficient `c` and a `rest` out of a
36
- * canonical expression `expr` such that `ce.mul(c, rest)` is equal to `expr`.
37
- *
38
- * Attempts to make `rest` a positive value (i.e. pulls out negative sign).
39
- *
40
- *
41
- * ['Multiply', 2, 'x', 3, 'a', ['Sqrt', 5]]
42
- * -> [[6, 1], ['Multiply', 'x', 'a', ['Sqrt', 5]]]
43
- *
44
- * ['Divide', ['Multiply', 2, 'x'], ['Multiply', 3, 'y', 'a']]
45
- * -> [[2, 3], ['Divide', 'x', ['Multiply, 'y', 'a']]]
46
- */
47
- export declare function asCoefficient(expr: BoxedExpression): [coef: Rational, rest: BoxedExpression];
48
- /**
49
- *
50
- * @param lhs
51
- * @param rhs
52
- * @returns the sign (-1, 0, 1) of the difference between `lhs` and `rhs`
37
+ /** Return [factor, root] such that factor * sqrt(root) = n
38
+ * when factor and root are rationals
53
39
  */
54
- export declare function signDiff(lhs: BoxedExpression, rhs: BoxedExpression, tolerance?: number): -1 | 0 | 1 | undefined;
40
+ export declare function reduceRationalSquareRoot(n: Rational): [factor: Rational, root: Rational];
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
 
3
3
  Translated from https://github.com/JuliaMath/Richardson.jl/blob/master/src/Richardson.jl
4
4
 
@@ -0,0 +1,14 @@
1
+ /* 0.23.0 */
2
+ export declare class Terms {
3
+ private engine;
4
+ private terms;
5
+ constructor(ce: IComputeEngine, terms: BoxedExpression[]);
6
+ sub(term: BoxedExpression): void;
7
+ add(term2: BoxedExpression, coef2?: Rational): void;
8
+ find(term: BoxedExpression): number;
9
+ /** If `exact` is true, keep exact numbers */
10
+ reduceNumbers({ exact }?: {
11
+ exact: boolean;
12
+ }): void;
13
+ asExpression(): BoxedExpression;
14
+ }
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  * The most important classes are {@link ComputeEngine} and
3
3
  * {@link BoxedExpression}.
4
4
  *
@@ -434,6 +434,11 @@ export interface BoxedExpression {
434
434
  * An exact value is not further transformed when evaluated. To get an
435
435
  * approximate evaluation of an exact value, use `.N()`.
436
436
  *
437
+ * Exact numbers are:
438
+ * - rationals (including integers)
439
+ * - complex numbers with integer real and imaginary parts (Gaussian integers)
440
+ * - square root of rationals
441
+ *
437
442
  * Non-exact values includes:
438
443
  * - numbers with a fractional part
439
444
  * - complex numbers with a real or imaginary fractional part
@@ -1645,21 +1650,29 @@ export interface IComputeEngine {
1645
1650
  chop(n: Complex): Complex | 0;
1646
1651
  chop(n: number | Decimal | Complex): number | Decimal | Complex;
1647
1652
  bignum: (a: Decimal.Value | bigint) => Decimal;
1648
- complex: (a: number | Complex, b?: number) => Complex;
1649
1653
  isBignum(a: unknown): a is Decimal;
1654
+ complex: (a: number | Complex, b?: number) => Complex;
1650
1655
  isComplex(a: unknown): a is Complex;
1651
1656
  set precision(p: number | 'machine');
1652
1657
  get precision(): number;
1653
1658
  costFunction: (expr: BoxedExpression) => number;
1659
+ /** In strict mode the compute engine performs additional checks,
1660
+ * for example to ensure the correct number and domain of arguments. These
1661
+ * checks may impact performance.
1662
+ */
1654
1663
  strict: boolean;
1655
- defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
1656
- defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
1657
- lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
1658
- lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
1664
+ /** Return a canonical version of an array of semi-boxed-expressions. */
1665
+ canonical(xs: SemiBoxedExpression[]): BoxedExpression[];
1666
+ /** Return as boxed expression from a number, string or semiboxed expression.
1667
+ * Calls `function()`, `number()` or `symbol()` as appropriate.
1668
+ */
1659
1669
  box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
1660
1670
  canonical?: boolean | CanonicalForm | CanonicalForm[];
1661
1671
  }): BoxedExpression;
1662
- canonical(xs: SemiBoxedExpression[]): BoxedExpression[];
1672
+ function(head: string | BoxedExpression, ops: SemiBoxedExpression[], options?: {
1673
+ metadata?: Metadata;
1674
+ canonical?: boolean;
1675
+ }): BoxedExpression;
1663
1676
  number(value: number | bigint | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
1664
1677
  metadata?: Metadata;
1665
1678
  canonical?: boolean;
@@ -1670,45 +1683,35 @@ export interface IComputeEngine {
1670
1683
  }): BoxedExpression;
1671
1684
  string(s: string, metadata?: Metadata): BoxedExpression;
1672
1685
  domain(domain: BoxedDomain | DomainExpression, metadata?: Metadata): BoxedDomain;
1673
- /**
1674
- * Create a boxed function expression.
1675
- *
1676
- * @param head
1677
- * @param ops
1678
- * @param options
1679
- */
1680
- fn(head: string | SemiBoxedExpression, ops: SemiBoxedExpression[], options?: {
1681
- canonical: boolean;
1682
- }): BoxedExpression;
1683
- /**
1684
- * This is a primitive to create a boxed function. It doesn't perform
1685
- * any checks or normalization on its arguments.
1686
- *
1687
- * In general, consider using `ce.fn()` or `ce.box()` instead.
1688
- *
1689
- * The result is canonical, but the caller has to ensure that all the
1690
- * conditions are met (i.e. `ops` properly normalized and sorted, all
1691
- * `ops` canonical, etc..) so that the result is actually canonical.
1692
- *
1693
- * @internal
1694
- */
1695
- _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1696
1686
  error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
1697
1687
  domainError(expectedDomain: BoxedDomain | DomainLiteral, actualDomain: undefined | BoxedDomain, where?: SemiBoxedExpression): BoxedExpression;
1698
1688
  hold(expr: SemiBoxedExpression): BoxedExpression;
1699
- add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1700
- mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1701
- pow(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
1702
- sqrt(base: BoxedExpression, metadata?: Metadata): BoxedExpression;
1703
- inv(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1704
- neg(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
1705
- div(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
1689
+ add(...ops: BoxedExpression[]): BoxedExpression;
1690
+ mul(...ops: BoxedExpression[]): BoxedExpression;
1691
+ pow(base: BoxedExpression, exponent: number | Rational | BoxedExpression): BoxedExpression;
1692
+ sqrt(base: BoxedExpression): BoxedExpression;
1693
+ inv(expr: BoxedExpression): BoxedExpression;
1694
+ neg(expr: BoxedExpression): BoxedExpression;
1695
+ div(num: BoxedExpression, denom: BoxedExpression): BoxedExpression;
1706
1696
  pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
1707
1697
  tuple(elements: number[], metadata?: Metadata): BoxedExpression;
1708
1698
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1709
1699
  array(elements: ArrayValue[] | ArrayValue[][], metadata?: Metadata): BoxedExpression;
1710
1700
  rules(rules: Rule[]): BoxedRuleSet;
1711
1701
  pattern(expr: LatexString | SemiBoxedExpression): Pattern;
1702
+ /**
1703
+ * This is a primitive to create a boxed function.
1704
+ *
1705
+ * In general, consider using `ce.box()` or `canonicalXXX()` instead.
1706
+ *
1707
+ * The caller must ensure that the arguments are in canonical form:
1708
+ * - arguments are `canonical()`
1709
+ * - arguments are sorted
1710
+ * - arguments are flattened and desequenced
1711
+ *
1712
+ * @internal
1713
+ */
1714
+ _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
1712
1715
  parse(s: LatexString | string, options?: {
1713
1716
  canonical?: boolean | CanonicalForm | CanonicalForm[];
1714
1717
  }): BoxedExpression;
@@ -1729,6 +1732,10 @@ export interface IComputeEngine {
1729
1732
  popScope(): IComputeEngine;
1730
1733
  swapScope(scope: RuntimeScope | null): RuntimeScope | null;
1731
1734
  resetContext(): void;
1735
+ defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
1736
+ lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
1737
+ defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
1738
+ lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
1732
1739
  assign(ids: {
1733
1740
  [id: string]: AssignValue;
1734
1741
  }): IComputeEngine;
@@ -1754,6 +1761,7 @@ export interface IComputeEngine {
1754
1761
  checkContinueExecution(): void;
1755
1762
  /** @internal */
1756
1763
  cache<T>(name: string, build: () => T, purge?: (T: any) => T | undefined): T;
1764
+ /** @internal */
1757
1765
  readonly stats: ComputeEngineStats;
1758
1766
  /** @internal */
1759
1767
  reset(): void;
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  /**
3
3
  * For each rules in the rule set that match, return the `replace` of the rule
4
4
  *
@@ -1,4 +1,14 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
+ /**
3
+ * @todo: a set to "tidy" an expression. Different from a canonical form, but
4
+ * inline with the user's expectations.
5
+ *
6
+ * Example:
7
+ *
8
+ * - a^n * a^m -> a^(n+m)
9
+ * - a / √b -> (a * √b) / b
10
+ *
11
+ */
2
12
  /**
3
13
  * A set of simplification rules.
4
14
  *
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.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
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  /**
3
3
  *
4
4
  * @param fn The function to differentiate, a `["Function"]` expression or
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.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.
@@ -9,6 +9,10 @@ export declare function distribute(expr: BoxedExpression[]): BoxedExpression;
9
9
  * -> 'a^3 + 3a^2b + 3ab^2 + b^3'
10
10
  */
11
11
  export declare function expandMultinomial(expr: BoxedExpression): BoxedExpression | null;
12
+ /** Expand all
13
+ * Recursive expand of all terms in the expression
14
+ */
15
+ export declare function expandAll(expr: BoxedExpression): BoxedExpression | null;
12
16
  /** Apply the distributive law if the expression is a product of sums.
13
17
  * For example, a(b + c) = ab + ac
14
18
  * Expand the expression if it is a power of a sum.
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  /**
3
3
  * Flatten the arguments.
4
4
  */
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  /**
3
3
  * Distribute `Negate` (multiply by -1) if expr is a number literal, an
4
4
  * addition or multiplication or another `Negate`.
@@ -6,5 +6,6 @@
6
6
  * It is important to do all these to handle cases like
7
7
  * `-3x` -> ["Negate, ["Multiply", 3, "x"]] -> ["Multiply, -3, x]
8
8
  */
9
- export declare function canonicalNegate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
9
+ export declare function evalNegate(expr: BoxedExpression): BoxedExpression;
10
+ export declare function canonicalNegate(expr: BoxedExpression): BoxedExpression;
10
11
  export declare function processNegate(_ce: IComputeEngine, x: BoxedExpression, _mode?: 'simplify' | 'evaluate' | 'N'): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  /**
3
3
  * Group terms in a product by common term.
4
4
  *
@@ -21,10 +21,11 @@ export declare class Product {
21
21
  };
22
22
  engine: IComputeEngine;
23
23
  private _sign;
24
- private _rational;
24
+ private _number;
25
25
  private _complex;
26
26
  private _bignum;
27
- private _number;
27
+ private _rational;
28
+ private _rationalSqrt;
28
29
  private _terms;
29
30
  private _hasInfinity;
30
31
  private _hasZero;
@@ -40,6 +41,10 @@ export declare class Product {
40
41
  * Otherwise, terms and their exponent are tallied.
41
42
  */
42
43
  addTerm(term: BoxedExpression): void;
44
+ /** Return all ther terms with an exponent of 1 and
45
+ * the square root of rationals (which technically have an
46
+ * exponent of 1/2, but are considered as degree 1 terms)
47
+ */
43
48
  unitTerms(mode: 'rational' | 'expression' | 'numeric'): {
44
49
  exponent: Rational;
45
50
  terms: BoxedExpression[];
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  import { BoxedExpression, IComputeEngine } from '../public';
3
3
  export type DataTypeMap = {
4
4
  float64: number;
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  import { DataTypeMap, TensorDataType, TensorField } from './tensor-fields';
3
3
  export interface TensorData<DT extends keyof DataTypeMap = 'float64'> {
4
4
  dtype: DT;
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedExpression, Hold, Rational } from '../public';
4
4
  /**
@@ -1,3 +1,3 @@
1
- /* 0.22.0 */
2
- export declare const version = "0.22.0";
1
+ /* 0.23.0 */
2
+ export declare const version = "0.23.0";
3
3
  export { ComputeEngine } from './compute-engine/compute-engine';
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.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;
@@ -1,4 +1,4 @@
1
- /* 0.22.0 */
1
+ /* 0.23.0 */
2
2
  export declare const MISSING: Expression;
3
3
  export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumber;
4
4
  export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
@@ -1,3 +1,3 @@
1
- /* 0.22.0 */
1
+ /* 0.23.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
- export declare const version = "0.22.0";
3
+ export declare const version = "0.23.0";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.22.0",
2
+ "version": "0.23.0",
3
3
  "scripts": {
4
4
  "build": "bash ./scripts/build.sh",
5
5
  "clean": "bash ./scripts/clean.sh",
@@ -1,33 +0,0 @@
1
- /* 0.22.0 */
2
- export declare class Sum {
3
- private engine;
4
- private _isCanonical;
5
- private _rational;
6
- private _imaginary;
7
- private _number;
8
- private _bignum;
9
- private _posInfinityCount;
10
- private _negInfinityCount;
11
- private _naNCount;
12
- private _terms;
13
- constructor(ce: IComputeEngine, xs?: BoxedExpression[], options?: {
14
- canonical?: boolean;
15
- });
16
- get isEmpty(): boolean;
17
- /**
18
- * Add a term to the sum.
19
- *
20
- * A term is a rational coefficient and an expression.
21
- * Optionally, the term is multiplied by the constant `c` before being added.
22
- *
23
- * If the sum already has this term, the coefficient is added
24
- * to the previous one. Otherwise, a new entry is added.
25
- *
26
- * E.g. "2x + x + 1/5 y"
27
- * -> [['x', [3, 1]], ['y', [1, 5]]]
28
- */
29
- addTerm(term: BoxedExpression, c?: Rational): void;
30
- toString(): string;
31
- terms(mode: 'expression' | 'numeric'): BoxedExpression[];
32
- asExpression(mode: 'expression' | 'numeric'): BoxedExpression;
33
- }