@cortex-js/compute-engine 0.8.0 → 0.9.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 (83) hide show
  1. package/dist/compute-engine.esm.js +7800 -6891
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +41 -88
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -5
  9. package/dist/types/common/utils.d.ts +1 -0
  10. package/dist/types/compute-engine/assume.d.ts +6 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +10 -14
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +74 -16
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +10 -5
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -4
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +16 -14
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +20 -19
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +8 -7
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +18 -12
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -3
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +7 -7
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +18 -0
  27. package/dist/types/compute-engine/compute-engine.d.ts +64 -33
  28. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  29. package/dist/types/compute-engine/domain-utils.d.ts +2 -8
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -9
  43. package/dist/types/compute-engine/latex-syntax/public.d.ts +14 -6
  44. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
  46. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  47. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  48. package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -3
  49. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +5 -6
  51. package/dist/types/compute-engine/library/arithmetic-power.d.ts +3 -2
  52. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  53. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  54. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  55. package/dist/types/compute-engine/library/core.d.ts +1 -1
  56. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  57. package/dist/types/compute-engine/library/library.d.ts +1 -1
  58. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  59. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  60. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  61. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  62. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  63. package/dist/types/compute-engine/numerics/{numeric-decimal.d.ts → numeric-bignum.d.ts} +10 -6
  64. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  65. package/dist/types/compute-engine/numerics/numeric.d.ts +10 -6
  66. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  67. package/dist/types/compute-engine/numerics/rationals.d.ts +56 -0
  68. package/dist/types/compute-engine/public.d.ts +200 -247
  69. package/dist/types/compute-engine/rules.d.ts +7 -1
  70. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  71. package/dist/types/compute-engine/solve.d.ts +17 -0
  72. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/flatten.d.ts +2 -1
  74. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  75. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  76. package/dist/types/compute-engine/symbolic/product.d.ts +30 -12
  77. package/dist/types/compute-engine/symbolic/sum.d.ts +13 -7
  78. package/dist/types/compute-engine/symbolic/utils.d.ts +7 -29
  79. package/dist/types/compute-engine.d.ts +2 -2
  80. package/dist/types/math-json/math-json-format.d.ts +2 -2
  81. package/dist/types/math-json/utils.d.ts +11 -41
  82. package/dist/types/math-json.d.ts +3 -3
  83. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { IndexedLatexDictionary, InfixEntry, PostfixEntry, PrefixEntry, SymbolEntry } from './dictionary/definitions';
3
3
  import { IComputeEngine } from '../public';
4
4
  import { Expression } from '../../math-json/math-json-format';
@@ -67,11 +67,17 @@ export declare class _Parser implements Parser {
67
67
  peekDefinitions(kind: 'infix'): [InfixEntry, number][] | null;
68
68
  peekDefinitions(kind: 'prefix'): [PrefixEntry, number][] | null;
69
69
  peekDefinitions(kind: 'operator'): [InfixEntry | PrefixEntry | PostfixEntry, number][] | null;
70
+ /** Skip strictly `<space>` tokens.
71
+ * To also skip `{}` see `skipSpace()`.
72
+ * To skip visual space (e.g. `\,`) see `skipVisualSpace()`.
73
+ */
70
74
  skipSpaceTokens(): void;
71
- /** While parsing in math mode, skip applicable spaces.
72
- * Do not use to skip spaces e.g. while parsing a string. See `skipSpaceTokens()` instead.
75
+ /** While parsing in math mode, skip applicable spaces, which includes `{}`.
76
+ * Do not use to skip spaces while parsing a string. See `skipSpaceTokens()`
77
+ * instead.
73
78
  */
74
79
  skipSpace(): boolean;
80
+ skipVisualSpace(): void;
75
81
  matchChar(): string | null;
76
82
  matchColor(_background?: boolean): string | null;
77
83
  matchLatexDimension(): string | null;
@@ -109,6 +115,13 @@ export declare class _Parser implements Parser {
109
115
  * (i.e. we interpret `\cos 2x + 1` as `\cos(2x) + 1`)
110
116
  */
111
117
  matchArguments(kind: undefined | '' | 'enclosure' | 'implicit'): Expression[] | null;
118
+ /**
119
+ * A function can be followed by the following suffixes:
120
+ * - a `\prime`, `\doubleprime`, `'`, `(n)` to indicate a derivative
121
+ * - a subscript to indicate an argument
122
+ * - an argument, optionally inside an enclosure
123
+ */
124
+ matchFunctionSuffix(): Expression | null;
112
125
  /** If matches the normalized open delimiter, return the
113
126
  * expected closing delimiter.
114
127
  *
@@ -119,6 +132,11 @@ export declare class _Parser implements Parser {
119
132
  */
120
133
  matchOpenDelimiter(openDelim: Delimiter, closeDelim: Delimiter): LatexToken[] | null;
121
134
  matchMiddleDelimiter(delimiter: '|' | ':' | LatexToken): boolean;
135
+ /** For error handling, when there is potentially a mismatched delimiter.
136
+ * Return a LaTeX fragment of the expected closing delimiter
137
+ */
138
+ matchEnclosureOpen(): string | null;
139
+ matchEnclosureClose(): string | null;
122
140
  /**
123
141
  * An enclosure is an opening matchfix operator, an optional expression,
124
142
  * optionally followed multiple times by a separator and another expression,
@@ -126,15 +144,13 @@ export declare class _Parser implements Parser {
126
144
  */
127
145
  matchEnclosure(): Expression | null;
128
146
  /**
129
- * Match a single variable name. It can be:
147
+ * Match an identifier. It can be:
130
148
  * - a symbol
131
149
  * - a simple multi-letter identifier: `\mathrm{speed}`
132
- * - a complex multi-letter identifier: `\alpha_12` or `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}`
150
+ * - a complex multi-letter identifier: `\mathrm{\alpha_{12}}` or `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}`
133
151
  * - a command: `\alpha` @todo
134
- * - a complex name such as `\alpha_12` or `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}` (see serializer.ts) @todo:
135
- * @todo: matchSymbol should use matchIdentifier
136
152
  */
137
- matchIdentifier(): string | null;
153
+ matchIdentifier(): string | Expression | null;
138
154
  /**
139
155
  * A function is a function identifier followed by arguments
140
156
  * - a function with explicit arguments `f(x)`
@@ -151,7 +167,7 @@ export declare class _Parser implements Parser {
151
167
  */
152
168
  matchSymbol(): Expression | null;
153
169
  matchOptionalLatexArgument(): Expression | null;
154
- matchRequiredLatexArgument(): Expression | null;
170
+ matchRequiredLatexArgument(excluding?: string[]): Expression | null;
155
171
  matchSupsub(lhs: Expression | null): Expression | null;
156
172
  matchPostfix(lhs: Expression | null): Expression | null;
157
173
  /** Match a string used as a LaTeX identifier, for example an environment
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import type { IComputeEngine } from '../public';
4
4
  /**
@@ -255,7 +255,7 @@ export declare type ParseLatexOptions = {
255
255
  * When a number is encountered, parse it.
256
256
  *
257
257
  * Otherwise, return each token making up the number (minus sign, digits,
258
- * decimal separator, etc...).
258
+ * decimal marker, etc...).
259
259
  *
260
260
  * **Default**: `true`
261
261
  */
@@ -276,7 +276,7 @@ export declare type ParseLatexOptions = {
276
276
  *
277
277
  * - `error`, an error condition is raised.
278
278
  */
279
- parseUnknownSymbol: (symbol: string, parser: Parser) => 'symbol' | 'function' | 'unknown';
279
+ parseUnknownIdentifier: (symbol: string, parser: Parser) => 'symbol' | 'function' | 'unknown';
280
280
  /**
281
281
  * If true, the expression will be decorated with the LaTeX
282
282
  * fragments corresponding to each elements of the expression.
@@ -364,7 +364,7 @@ export declare type NumberFormattingOptions = {
364
364
  truncationMarker: LatexString;
365
365
  beginRepeatingDigits: LatexString;
366
366
  endRepeatingDigits: LatexString;
367
- imaginaryNumber: LatexString;
367
+ imaginaryUnit: LatexString;
368
368
  avoidExponentsInRange: [negativeExponent: number, positiveExponent: number];
369
369
  };
370
370
  /**
@@ -512,18 +512,26 @@ export interface Parser {
512
512
  /**
513
513
  * Match a required LaTeX argument:
514
514
  * - either enclosed in `{}`
515
- * - or a single token.
515
+ * - or a single token (except if token is in `excluding`)
516
+ *
517
+ * The `excluding` option is useful to fail early when encountering a likely
518
+ * syntax error, for example `x^(2)` (instead of `x^{2}`). With `(` in the list
519
+ * of excluded tokens, the match will fail and the error can be recovered.
520
+ *
521
+ * If none is provided, `excluding` is `!"#$%&(),/;:?@[]`|~", `\left` and `\bigl`
522
+ *
516
523
  *
517
524
  * Return null if no argument was found
518
525
  * Return `['Sequence']` if an empty argument `{}` was found
519
526
  */
520
- matchRequiredLatexArgument(): Expression | null;
527
+ matchRequiredLatexArgument(excluding?: string[]): Expression | null;
521
528
  /**
522
529
  * - 'enclosure' : will look for an argument inside an enclosure (an open/close fence)
523
530
  * - 'implicit': either an expression inside a pair of `()`, or just a primary
524
531
  * (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
525
532
  */
526
533
  matchArguments(kind: '' | 'implicit' | 'enclosure'): Expression[] | null;
534
+ matchStringArgument(): string | null;
527
535
  /** If matches the normalized open delimiter, returns the
528
536
  * expected closing delimiter.
529
537
  *
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { NumberFormattingOptions } from './public';
3
3
  export declare function serializeNumber(expr: Expression | null, options: NumberFormattingOptions): string;
4
4
  export declare function serializeEngineeringNotationNumber(value: number, options: NumberFormattingOptions): string;
@@ -1,8 +1,8 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
3
3
  export declare function getGroupStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
4
4
  export declare function getRootStyle(_expr: Expression | null, level: number): 'radical' | 'quotient' | 'solidus';
5
- export declare function getFractionStyle(_expr: Expression, level: number): 'quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
5
+ export declare function getFractionStyle(expr: Expression, level: number): 'quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
6
6
  export declare function getLogicStyle(_expr: Expression, _level: number): 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
7
7
  export declare function getPowerStyle(_expr: Expression, _level: number): 'root' | 'solidus' | 'quotient';
8
8
  export declare function getNumericSetStyle(_expr: Expression, _level: number): 'compact' | 'regular' | 'interval' | 'set-builder';
@@ -1,7 +1,7 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
+ import { WarningSignalHandler } from '../../common/signals';
2
3
  import { NumberFormattingOptions, LatexString, SerializeLatexOptions, FunctionEntry } from './public';
3
4
  import { IndexedLatexDictionary, SymbolEntry } from './dictionary/definitions';
4
- import { WarningSignalHandler } from '../../common/signals';
5
5
  export declare class Serializer {
6
6
  readonly onError: WarningSignalHandler;
7
7
  options: NumberFormattingOptions & SerializeLatexOptions;
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  * ## Reference
3
3
  * TeX source code:
4
4
  * {@link http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web | Tex.web}
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  /** The canonical form of `Add`:
3
3
  * - removes `0`
4
4
  * - capture complex numbers (a + ib or ai +b)
@@ -6,6 +6,6 @@
6
6
  export declare function canonicalAdd(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
7
7
  export declare function domainAdd(_ce: IComputeEngine, args: BoxedDomain[]): BoxedDomain | null;
8
8
  export declare function simplifyAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression | undefined;
9
- export declare function evalAdd(ce: IComputeEngine, args: BoxedExpression[], mode?: 'N' | 'eval'): BoxedExpression;
10
- export declare function canonicalSummation(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression | undefined): BoxedExpression;
9
+ export declare function evalAdd(ce: IComputeEngine, ops: BoxedExpression[], mode?: 'N' | 'evaluate'): BoxedExpression;
10
+ export declare function canonicalSummation(ce: IComputeEngine, body: BoxedExpression, range: BoxedExpression | undefined): BoxedExpression;
11
11
  export declare function evalSummation(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression, mode: 'simplify' | 'N' | 'evaluate'): BoxedExpression | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  /**
3
3
  * Canonical form of 'Divide' (and 'Rational')
4
4
  * - remove denominator of 1
@@ -1,19 +1,18 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  /** The canonical form of `Multiply`:
3
3
  * - remove `1`
4
- * - combine literal small integers and rationals
4
+ * - combine literal integers and rationals
5
5
  * - any arg is literal 0 -> return 0
6
- * - simplify signs
7
6
  * - combine terms with same base
8
7
  * `a a^3` -> `a^4`
9
8
  * - simplify the signs:
10
- * - i.e. `-2 \times -3` -> `2 \times 3`
9
+ * - i.e. `-y \times -x` -> `x \times y`
11
10
  * - `2 \times -x` -> `-2 \times x`
12
11
  *
13
12
  * The ops must be canonical, the result is canonical.
14
13
  */
15
14
  export declare function canonicalMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
16
- export declare function simplifyMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression | undefined;
15
+ export declare function simplifyMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
17
16
  export declare function evalMultiply(ce: IComputeEngine, ops: BoxedExpression[], mode?: 'N' | 'evaluate'): BoxedExpression | undefined;
18
- export declare function canonicalMultiplication(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression | undefined): BoxedExpression;
17
+ export declare function canonicalMultiplication(ce: IComputeEngine, body: BoxedExpression | undefined, range: BoxedExpression | undefined): BoxedExpression;
19
18
  export declare function evalMultiplication(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
@@ -1,9 +1,10 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  /**
3
3
  *
4
4
  * Return `null` if there is no canonicalization necessary and the result is
5
5
  * simply `ce._fn('Power', [base, exponent])`
6
6
  */
7
- export declare function canonicalPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, metadata?: Metadata): BoxedExpression | null;
7
+ export declare function canonicalPower(ce: IComputeEngine, base: BoxedExpression | undefined, exponent: BoxedExpression | undefined, metadata?: Metadata): BoxedExpression | null;
8
8
  export declare function square(ce: IComputeEngine, base: BoxedExpression): BoxedExpression;
9
9
  export declare function processPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
10
+ export declare function processSqrt(ce: IComputeEngine, base: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const ARITHMETIC_LIBRARY: SymbolTable[];
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const CALCULUS_LIBRARY: SymbolTable[];
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const COLLECTIONS_LIBRARY: SymbolTable;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const CORE_LIBRARY: SymbolTable[];
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DOMAIN_CONSTRUCTORS: string[];
3
3
  export declare const DOMAIN_ALIAS: {
4
4
  NumericFunction: (string | string[])[];
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { IComputeEngine, SymbolTable } from '../public';
3
3
  export declare function getStandardLibrary(categories: LibraryCategory[] | LibraryCategory | 'all'): Readonly<SymbolTable>[];
4
4
  export declare const LIBRARIES: {
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const LOGIC_LIBRARY: SymbolTable;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const POLYNOMIALS_LIBRARY: SymbolTable[];
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const RELOP_LIBRARY: SymbolTable;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const SETS_LIBRARY: SymbolTable;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const TRIGONOMETRY_LIBRARY: SymbolTable[];
@@ -1,16 +1,20 @@
1
- /* 0.8.0 */
1
+ /* 0.9.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;
5
- export declare function reducedRational([a, b]: [Decimal, Decimal]): [
6
- Decimal,
7
- Decimal
8
- ];
5
+ export declare function primeFactors(ce: IComputeEngine, n: Decimal): Map<Decimal, number>;
6
+ /** Return `[factor, root]` such that
7
+ * pow(n, 1/exponent) = factor * pow(root, 1/exponent)
8
+ *
9
+ * factorPower(75, 2) -> [5, 3] = 5^2 * 3
10
+ *
11
+ */
12
+ export declare function factorPower(ce: IComputeEngine, n: Decimal, exponent: number): [factor: Decimal, root: Decimal];
9
13
  export declare function factorial(ce: IComputeEngine, n: Decimal): Decimal;
10
14
  export declare function lngamma(ce: IComputeEngine, z: Decimal): Decimal;
11
15
  export declare function gamma(ce: IComputeEngine, z: Decimal): Decimal;
12
16
  /**
13
- * If the exponent of the decimal number is in the range of the exponents
17
+ * If the exponent of the bignum is in the range of the exponents
14
18
  * for machine numbers,return true.
15
19
  */
16
20
  export declare function isInMachineRange(d: Decimal): boolean;
@@ -1,3 +1,3 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare function gamma(c: Complex): Complex;
3
3
  export declare function lngamma(c: Complex): Complex;
@@ -1,4 +1,7 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
+ import Decimal from 'decimal.js';
3
+ import { BoxedExpression } from '../public';
4
+ export declare const MACHINE_PRECISION_BITS = 53;
2
5
  export declare const MACHINE_PRECISION: number;
3
6
  export declare const MACHINE_TOLERANCE_BITS = 7;
4
7
  export declare const MACHINE_TOLERANCE: number;
@@ -25,13 +28,14 @@ export declare function primeFactors(n: number): {
25
28
  */
26
29
  export declare function factorPower(n: number, exponent: number): [factor: number, root: number];
27
30
  export declare function gcd(a: number, b: number): number;
28
- export declare function rationalGcd([a, b]: [number, number], [c, d]: [number, number]): [number, number];
29
31
  export declare function lcm(a: number, b: number): number;
30
- export declare function rationalLcm([a, b]: [number, number], [c, d]: [number, number]): [number, number];
31
- export declare function reducedRational([a, b]: [number, number]): [number, number];
32
32
  export declare function factorial(n: number): number;
33
33
  export declare function lngamma(z: number): number;
34
34
  export declare function gamma(z: number): number;
35
35
  export declare function fromDigits(s: string, base?: number): [value: number, rest: string];
36
- /** Return a rational approximation of x */
37
- export declare function rationalize(x: number): [n: number, d: number] | number;
36
+ export declare function asFloat(expr: BoxedExpression): number | null;
37
+ export declare function asBignum(expr: BoxedExpression): Decimal | null;
38
+ export declare function asSmallInteger(expr: BoxedExpression): number | null;
39
+ export declare function chop(n: number, tolerance: number): number;
40
+ export declare function chop(n: Decimal, tolerance: number): 0 | Decimal;
41
+ export declare function chop(n: Complex, tolerance: number): 0 | Complex;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare function isPrime(n: number): boolean | undefined;
@@ -0,0 +1,56 @@
1
+ /* 0.9.0 */
2
+ import Decimal from 'decimal.js';
3
+ export declare function isRational(x: any | null): x is Rational;
4
+ export declare function isMachineRational(x: any | null): x is [number, number];
5
+ export declare function isBigRational(x: any | null): x is [Decimal, Decimal];
6
+ export declare function isRationalZero(x: Rational): boolean;
7
+ export declare function isRationalOne(x: Rational): boolean;
8
+ export declare function isRationalNegativeOne(x: Rational): boolean;
9
+ export declare function machineNumerator(x: Rational): number;
10
+ export declare function machineDenominator(x: Rational): number;
11
+ export declare function isNeg(lhs: Rational): boolean;
12
+ export declare function neg(lhs: [number, number]): [number, number];
13
+ export declare function neg(lhs: [Decimal, Decimal]): [Decimal, Decimal];
14
+ export declare function neg(lhs: Rational): Rational;
15
+ export declare function inverse(lhs: [number, number]): [number, number];
16
+ export declare function inverse(lhs: [Decimal, Decimal]): [Decimal, Decimal];
17
+ export declare function inverse(lhs: Rational): Rational;
18
+ export declare function asRational(expr: BoxedExpression): Rational | undefined;
19
+ export declare function asMachineRational(r: Rational): [number, number];
20
+ /**
21
+ * Add a literal numeric value to a rational.
22
+ * If the rational is a bignum, this is a hint to do the calculation in bignum
23
+ * (no need to check `bignumPreferred()`).
24
+ * @param lhs
25
+ * @param rhs
26
+ * @returns
27
+ */
28
+ export declare function add(lhs: Rational, rhs: BoxedExpression | Rational): Rational;
29
+ export declare function mul(lhs: Rational, rhs: BoxedExpression | Rational): Rational;
30
+ export declare function pow(r: Rational, exp: number): Rational;
31
+ export declare function reducedRational(r: [number, number]): [number, number];
32
+ export declare function reducedRational(r: [Decimal, Decimal]): [Decimal, Decimal];
33
+ export declare function reducedRational(r: Rational): Rational;
34
+ /** Return a rational approximation of x */
35
+ export declare function rationalize(x: number): [n: number, d: number] | number;
36
+ /**
37
+ * Attempt to factor a rational coefficient `c` and a `rest` out of a
38
+ * canonical expression `expr` such that `ce.mul(c, rest)` is equal to `expr`.
39
+ *
40
+ * Attempts to make `rest` a positive value (i.e. pulls out negative sign).
41
+ *
42
+ *
43
+ * ['Multiply', 2, 'x', 3, 'a', ['Sqrt', 5]]
44
+ * -> [[6, 1], ['Multiply', 'x', 'a', ['Sqrt', 5]]]
45
+ *
46
+ * ['Divide', ['Multiply', 2, 'x'], ['Multiply', 3, 'y', 'a']]
47
+ * -> [[2, 3], ['Divide', 'x', ['Multiply, 'y', 'a']]]
48
+ */
49
+ export declare function asCoefficient(expr: BoxedExpression): [coef: Rational, rest: BoxedExpression];
50
+ /**
51
+ *
52
+ * @param lhs
53
+ * @param rhs
54
+ * @returns the sign (-1, 0, 1) of the difference between `lhs` and `rhs`
55
+ */
56
+ export declare function signDiff(lhs: BoxedExpression, rhs: BoxedExpression, tolerance?: number): -1 | 0 | 1 | undefined;