@cortex-js/compute-engine 0.7.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 +8291 -7307
  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 +67 -68
  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 +45 -36
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +22 -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 +6 -6
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +21 -15
  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 +9 -9
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +18 -0
  27. package/dist/types/compute-engine/compute-engine.d.ts +65 -35
  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 +622 -506
  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,15 +1,15 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
- import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOption, BoxedDomain, BoxedLambdaExpression, RuntimeScope } from '../public';
3
+ import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedSubstitution } from '../public';
4
4
  /**
5
5
  * BoxedFunction
6
6
  */
7
7
  export declare class BoxedFunction extends AbstractBoxedExpression {
8
8
  private _scope;
9
- private _head;
10
- private _ops;
9
+ private readonly _head;
10
+ private readonly _ops;
11
+ private _canonical;
11
12
  private _def;
12
- private _isCanonical;
13
13
  private _isPure;
14
14
  /** The domain of the value of the function applied to its arguments */
15
15
  private _codomain;
@@ -19,27 +19,45 @@ export declare class BoxedFunction extends AbstractBoxedExpression {
19
19
  private _value;
20
20
  private _numericValue;
21
21
  private _hash;
22
- constructor(ce: IComputeEngine, head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata);
22
+ constructor(ce: IComputeEngine, head: string | BoxedExpression, ops: BoxedExpression[], options?: {
23
+ metadata?: Metadata;
24
+ canonical?: boolean;
25
+ def?: BoxedFunctionDefinition;
26
+ });
23
27
  get hash(): number;
24
- unbind(): void;
25
- get wikidata(): string;
26
- get description(): string[];
27
- get url(): string;
28
- get complexity(): number;
29
- get head(): string | BoxedExpression;
30
- get value(): BoxedExpression | undefined;
31
- get numericValue(): BoxedExpression | undefined;
32
- get isPure(): boolean;
28
+ get isCanonical(): boolean;
29
+ set isCanonical(val: boolean);
33
30
  get isLiteral(): boolean;
34
- get isValid(): boolean;
31
+ get isPure(): boolean;
32
+ get json(): Expression;
33
+ get scope(): RuntimeScope | null;
34
+ get head(): string | BoxedExpression;
35
35
  get ops(): BoxedExpression[];
36
36
  get nops(): number;
37
37
  get op1(): BoxedExpression;
38
38
  get op2(): BoxedExpression;
39
39
  get op3(): BoxedExpression;
40
+ get isValid(): boolean;
41
+ get canonical(): BoxedExpression;
42
+ map<T = BoxedExpression>(fn: (x: BoxedExpression) => T): IterableIterator<T>;
43
+ subs(sub: Substitution, options?: {
44
+ canonical?: boolean;
45
+ }): BoxedExpression;
46
+ replace(rules: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
47
+ has(x: string | string[]): boolean;
48
+ /** `isSame` is structural/symbolic equality */
49
+ isSame(rhs: BoxedExpression): boolean;
50
+ match(rhs: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
51
+ unbind(): void;
52
+ get wikidata(): string | undefined;
53
+ get description(): string[] | undefined;
54
+ get url(): string | undefined;
55
+ get complexity(): number | undefined;
40
56
  get functionDefinition(): BoxedFunctionDefinition | undefined;
41
- bind(scope: RuntimeScope | null): void;
42
- get domain(): BoxedDomain;
57
+ bind(_scope: RuntimeScope | null): void;
58
+ get value(): BoxedExpression | undefined;
59
+ /** `isEqual` is mathematical equality */
60
+ isEqual(rhs: BoxedExpression): boolean;
43
61
  isLess(rhs: BoxedExpression): boolean | undefined;
44
62
  isLessEqual(rhs: BoxedExpression): boolean | undefined;
45
63
  isGreater(rhs: BoxedExpression): boolean | undefined;
@@ -60,27 +78,19 @@ export declare class BoxedFunction extends AbstractBoxedExpression {
60
78
  get isExtendedReal(): boolean | undefined;
61
79
  get isComplex(): boolean | undefined;
62
80
  get isImaginary(): boolean | undefined;
63
- get json(): Expression;
64
- has(x: string | string[]): boolean;
65
- /** `isSame` is structural/symbolic equality */
66
- isSame(rhs: BoxedExpression): boolean;
67
- match(rhs: BoxedExpression, options?: PatternMatchOption): Substitution | null;
68
- /** `isEqual` is mathematical equality */
69
- isEqual(rhs: BoxedExpression): boolean;
70
81
  get sgn(): -1 | 0 | 1 | undefined | null;
71
- map<T = BoxedExpression>(fn: (x: BoxedExpression) => T): IterableIterator<T>;
72
- get isCanonical(): boolean;
73
- set isCanonical(val: boolean);
74
- apply(fn: (x: BoxedExpression) => SemiBoxedExpression, head?: string): BoxedExpression;
75
- get canonical(): BoxedExpression;
82
+ get domain(): BoxedDomain;
76
83
  simplify(options?: SimplifyOptions): BoxedExpression;
77
84
  evaluate(options?: EvaluateOptions): BoxedExpression;
78
85
  N(options?: NOptions): BoxedExpression;
79
- solve(_vars: Iterable<string>): null | BoxedExpression[];
80
- replace(rules: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
81
- subs(sub: Substitution): BoxedExpression;
86
+ solve(vars: string[]): null | BoxedExpression[];
82
87
  }
83
- export declare function lambda(ce: IComputeEngine, fn: BoxedLambdaExpression, args: BoxedExpression[]): BoxedExpression;
88
+ export declare function makeCanonicalFunction(ce: IComputeEngine, head: string | BoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
89
+ /** Apply arguments to an expression. If the expression is a lambda expression
90
+ * it's wildcard arguments are substituted before being evaluated. Otherwise
91
+ * the expression is just evaluated.
92
+ */
93
+ export declare function apply(fn: BoxedExpression, args: BoxedExpression[]): BoxedExpression;
84
94
  /** Apply the function `f` to elements of `xs`, except to the elements
85
95
  * described by `skip`:
86
96
  * - `all`: don't apply f to any elements
@@ -94,5 +104,4 @@ export declare function lambda(ce: IComputeEngine, fn: BoxedLambdaExpression, ar
94
104
  *
95
105
  * If `f` returns `null`, the element is not added to the result
96
106
  */
97
- export declare function holdMap(head: string, xs: BoxedExpression[], skip: 'all' | 'none' | 'first' | 'rest' | 'last' | 'most', associative: boolean, f: (x: BoxedExpression) => BoxedExpression | null): BoxedExpression[];
98
- export declare function canonicalHoldMap(head: string, xs: BoxedExpression[], skip: 'all' | 'none' | 'first' | 'rest' | 'last' | 'most', associative: boolean): BoxedExpression[];
107
+ export declare function holdMap(xs: BoxedExpression[], skip: 'all' | 'none' | 'first' | 'rest' | 'last' | 'most', associativeHead: string, f: (x: BoxedExpression) => BoxedExpression | null): BoxedExpression[];
@@ -1,47 +1,50 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
- import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOption, SimplifyOptions, Substitution } from '../public';
4
+ import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOptions, Rational, SimplifyOptions, BoxedSubstitution } from '../public';
5
5
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
6
6
  /**
7
7
  * BoxedNumber
8
8
  */
9
9
  export declare class BoxedNumber extends AbstractBoxedExpression {
10
- protected readonly _value: number | Decimal | Complex | [numer: number, denom: number];
10
+ protected readonly _value: number | Decimal | Complex | Rational;
11
11
  private _domain;
12
- private _head;
13
12
  private _hash;
14
13
  protected _isCanonical: boolean;
15
14
  /**
16
15
  * By the time the constructor is called, the `value` should have been
17
- * screened for cases where it's a well-known value (0, NaN, +Infinity, etc...)
18
- * or non-normal (complex number with im = 0, rational with denom = 1, etc...)
19
- * This is done in `ce.boxNumber()`. In general, use `ce.boxNumber()` rather
20
- * than calling the constructor directly.
16
+ * screened for cases where it's a well-known value (0, NaN, +Infinity,
17
+ * etc...) or non-normal (complex number with im = 0, rational with
18
+ * denom = 1, etc...).
19
+ *
20
+ * This is done in `ce.number()`. In general, use `ce.number()` rather
21
+ * than calling this constructor directly.
22
+ *
23
+ * We may store as a machine number if a Decimal is passed that is in machine
24
+ * range
21
25
  */
22
- constructor(ce: IComputeEngine, value: string | number | Decimal | Complex | [numer: number, denom: number], metadata?: Metadata);
26
+ constructor(ce: IComputeEngine, value: number | Decimal | Complex | Rational, options?: {
27
+ metadata?: Metadata;
28
+ canonical?: boolean;
29
+ });
23
30
  get hash(): number;
24
31
  get head(): string;
25
32
  get isPure(): boolean;
26
33
  get isLiteral(): boolean;
34
+ get isExact(): boolean;
27
35
  get isCanonical(): boolean;
28
36
  set isCanonical(val: boolean);
29
- get numericValue(): BoxedExpression | undefined;
30
- get machineValue(): number | null;
31
- get decimalValue(): Decimal | null;
32
- get complexValue(): Complex | null;
33
- get rationalValue(): [numer: number, denom: number] | [null, null];
34
- get asFloat(): number | null;
35
- get asSmallInteger(): number | null;
36
- get asRational(): [number, number] | [null, null];
37
+ get complexity(): number;
38
+ get value(): BoxedExpression;
39
+ get numericValue(): number | Decimal | Complex | Rational | null;
37
40
  get domain(): BoxedDomain;
38
41
  get json(): Expression;
39
42
  get sgn(): -1 | 0 | 1 | undefined | null;
40
43
  isSame(rhs: BoxedExpression): boolean;
41
44
  isEqual(rhs: BoxedExpression): boolean;
42
- match(rhs: BoxedExpression, options?: PatternMatchOption): Substitution | null;
45
+ match(rhs: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
43
46
  /** Compare this with another BoxedNumber.
44
- * `rhs` must be a BoxedNumber. Use `isEqualWithTolerance(rhs.numericValue)`
47
+ * `rhs` must be a BoxedNumber. Use `isEqualWithTolerance(rhs.N())`
45
48
  * if necessary.
46
49
  */
47
50
  isEqualWithTolerance(rhs: BoxedExpression, tolerance: number): boolean;
@@ -1,9 +1,8 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
- import { BoxedExpression, BoxedSubstitution, BoxedDomain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOption, SemiBoxedExpression, Substitution } from '../public';
3
+ import { BoxedExpression, BoxedSubstitution, BoxedDomain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOptions, SemiBoxedExpression, Substitution } from '../public';
4
4
  export declare class BoxedPattern extends AbstractBoxedExpression implements Pattern {
5
5
  _pattern: BoxedExpression;
6
- _canonicalPattern: BoxedExpression | undefined;
7
6
  constructor(ce: IComputeEngine, pattern: LatexString | SemiBoxedExpression, metadata?: Metadata);
8
7
  get hash(): number;
9
8
  unbind(): void;
@@ -14,8 +13,10 @@ export declare class BoxedPattern extends AbstractBoxedExpression implements Pat
14
13
  set isCanonical(_val: boolean);
15
14
  isSame(rhs: BoxedExpression): boolean;
16
15
  isEqual(rhs: BoxedExpression): boolean;
17
- match(expr: BoxedExpression, options?: PatternMatchOption): BoxedSubstitution | null;
18
- test(expr: BoxedExpression, options?: PatternMatchOption): boolean;
19
- count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOption): number;
20
- subs(sub: Substitution): BoxedPattern;
16
+ match(expr: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
17
+ test(expr: BoxedExpression, options?: PatternMatchOptions): boolean;
18
+ count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOptions): number;
19
+ subs(sub: Substitution, options?: {
20
+ canonical: boolean;
21
+ }): BoxedExpression;
21
22
  }
@@ -1,6 +1,6 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
- import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOption, Substitution } from '../public';
3
+ import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOptions, BoxedSubstitution } from '../public';
4
4
  /**
5
5
  * BoxedString
6
6
  */
@@ -19,5 +19,5 @@ export declare class BoxedString extends AbstractBoxedExpression {
19
19
  get string(): string;
20
20
  isEqual(rhs: BoxedExpression): boolean;
21
21
  isSame(rhs: BoxedExpression): boolean;
22
- match(rhs: BoxedExpression, _options?: PatternMatchOption): Substitution | null;
22
+ match(rhs: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
23
23
  }
@@ -1,14 +1,15 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  export declare function domainToFlags(dom: BoxedDomain | undefined | null): Partial<SymbolFlags>;
3
3
  export declare class BoxedSymbolDefinitionImpl implements BoxedSymbolDefinition {
4
+ readonly name: string;
5
+ private _def;
6
+ private _value;
7
+ private _domain;
8
+ private _inferedDomain;
4
9
  private _engine;
5
10
  readonly scope: RuntimeScope | undefined;
6
- private _value;
7
- readonly name: string;
8
11
  wikidata?: string;
9
12
  description?: string | string[];
10
- private _domain;
11
- private _inferedDomain;
12
13
  private _number;
13
14
  private _integer;
14
15
  private _rational;
@@ -37,7 +38,6 @@ export declare class BoxedSymbolDefinitionImpl implements BoxedSymbolDefinition
37
38
  at?: (index: string | number) => undefined | BoxedExpression;
38
39
  readonly constant: boolean;
39
40
  readonly hold: boolean;
40
- private _def;
41
41
  prototype?: BoxedFunctionDefinition;
42
42
  self?: unknown;
43
43
  constructor(ce: IComputeEngine, def: SymbolDefinition);
@@ -1,6 +1,6 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
- import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOption, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition } from '../public';
3
+ import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, DomainExpression, BoxedSubstitution } from '../public';
4
4
  /**
5
5
  * BoxedSymbol
6
6
  *
@@ -19,19 +19,24 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
19
19
  protected _name: string;
20
20
  private _hash;
21
21
  private _def;
22
- constructor(ce: IComputeEngine, name: string, metadata?: Metadata);
22
+ constructor(ce: IComputeEngine, name: string, options?: {
23
+ metadata?: Metadata;
24
+ canonical?: boolean;
25
+ });
23
26
  get hash(): number;
24
- unbind(): undefined;
27
+ unbind(): void;
25
28
  get isPure(): boolean;
29
+ get json(): Expression;
30
+ get scope(): RuntimeScope | null;
26
31
  /** A free variable either has no definition, or it has a definition, but no value */
27
32
  get isFree(): boolean;
28
33
  get isConstant(): boolean;
29
34
  get isCanonical(): boolean;
30
- set isCanonical(_va: boolean);
35
+ set isCanonical(val: boolean);
31
36
  get canonical(): BoxedExpression;
32
- get wikidata(): string;
33
- get description(): string[];
34
- get url(): string;
37
+ get wikidata(): string | undefined;
38
+ get description(): string[] | undefined;
39
+ get url(): string | undefined;
35
40
  get complexity(): number;
36
41
  get head(): string;
37
42
  get symbol(): string;
@@ -43,15 +48,13 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
43
48
  bind(scope: RuntimeScope | null): void;
44
49
  get value(): BoxedExpression | undefined;
45
50
  set value(value: BoxedExpression | number | undefined);
46
- get numericValue(): BoxedExpression | undefined;
47
51
  get domain(): BoxedDomain;
48
- set domain(d: BoxedDomain);
49
- get explicitDomain(): BoxedDomain | null;
50
- get json(): Expression;
52
+ set domain(inDomain: BoxedExpression | DomainExpression | BoxedDomain);
53
+ get explicitDomain(): BoxedDomain | undefined;
51
54
  get sgn(): -1 | 0 | 1 | undefined | null;
52
55
  has(x: string | string[]): boolean;
53
56
  isSame(rhs: BoxedExpression): boolean;
54
- match(rhs: BoxedExpression, _options?: PatternMatchOption): Substitution | null;
57
+ match(rhs: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
55
58
  isEqual(rhs: BoxedExpression): boolean;
56
59
  isLess(rhs: BoxedExpression): boolean | undefined;
57
60
  isLessEqual(rhs: BoxedExpression): boolean | undefined;
@@ -81,8 +84,11 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
81
84
  get isComplex(): boolean | undefined;
82
85
  get isImaginary(): boolean | undefined;
83
86
  simplify(options?: SimplifyOptions): BoxedExpression;
84
- evaluate(options?: EvaluateOptions): BoxedExpression;
87
+ evaluate(_options?: EvaluateOptions): BoxedExpression;
85
88
  N(options?: NOptions): BoxedExpression;
86
89
  replace(rules: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
87
- subs(sub: Substitution): BoxedExpression;
90
+ subs(sub: Substitution, options?: {
91
+ canonical: boolean;
92
+ }): BoxedExpression;
88
93
  }
94
+ export declare function makeCanonicalSymbol(ce: IComputeEngine, name: string): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  export declare type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,7 +1,7 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
- import { BoxedExpression, IComputeEngine, Metadata } from '../public';
4
+ import { BoxedExpression, IComputeEngine, Metadata, Rational } from '../public';
5
5
  /**
6
6
  * The canonical version of `serializeJsonFunction()` applies
7
7
  * additional transformations to "reverse" some of the effects
@@ -12,4 +12,4 @@ export declare function serializeJsonCanonicalFunction(ce: IComputeEngine, head:
12
12
  export declare function serializeJsonFunction(ce: IComputeEngine, head: string | BoxedExpression, args: BoxedExpression[], metadata?: Metadata): Expression;
13
13
  export declare function serializeJsonString(ce: IComputeEngine, s: string): Expression;
14
14
  export declare function serializeJsonSymbol(ce: IComputeEngine, sym: string, metadata?: Metadata): Expression;
15
- export declare function serializeJsonNumber(ce: IComputeEngine, value: number | Decimal | Complex | [number, number], metadata?: Metadata): Expression;
15
+ export declare function serializeJsonNumber(ce: IComputeEngine, value: number | Decimal | Complex | Rational, metadata?: Metadata): Expression;
@@ -1,4 +1,4 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, IComputeEngine } from '../public';
4
4
  export declare function isLatexString(s: unknown): s is string;
@@ -20,13 +20,12 @@ export declare function getVars(expr: BoxedExpression): string[];
20
20
  export declare function getSymbols(expr: BoxedExpression, set: Set<string>): Set<string>;
21
21
  export declare function getSubexpressions(expr: BoxedExpression, head: string): BoxedExpression[];
22
22
  /**
23
- * For any numeric result, or when boxing numbers,
24
- * if `preferDecimal` is true, create them as Decimal number
25
- * if `preferDecimal` is false, create them as machine number
23
+ * For any numeric result, if `bignumPreferred()` is true, calculate using
24
+ * bignums. If `bignumPreferred()` is false, calculate using machine numbers
26
25
  */
27
- export declare function preferDecimal(ce: IComputeEngine): boolean;
28
- /** If result of a numeric evaluation is a complex number,
29
- * return `NaN` if `ce.useComplex` is false
26
+ export declare function bignumPreferred(ce: IComputeEngine): boolean;
27
+ /** When result of a numeric evaluation is a complex number,
28
+ * return `NaN` if not `complexallowed()`
30
29
  */
31
30
  export declare function complexAllowed(ce: IComputeEngine): boolean;
32
31
  /**
@@ -49,6 +48,7 @@ export declare function getListLike(expr: BoxedExpression): BoxedExpression[];
49
48
  * If `expr` is a number, return it as a Decimal (it might be
50
49
  * in the machine value range or not). Use `isInMachineRange()` to check.
51
50
  *
52
- * Use this instead of `machineValue()` when possible, as `machineValue` will truncate decimal numbers to machine numbers
51
+ * Use this instead of `machineValue()` when possible, as `machineValue` will
52
+ * truncate bignums to machine numbers
53
53
  */
54
- export declare function decimalValue(ce: IComputeEngine, expr: Expression | null | undefined): Decimal | null;
54
+ export declare function bignumValue(ce: IComputeEngine, expr: Expression | null | undefined): Decimal | null;
@@ -0,0 +1,18 @@
1
+ /* 0.9.0 */
2
+ export declare function validateArgumentCount(ce: IComputeEngine, ops: BoxedExpression[], count: number): BoxedExpression[];
3
+ /**
4
+ * Validation of arguments is normally done by checking the signature of the
5
+ * function vs the arguments of the expression. However, we have a fastpath
6
+ * for some common operations (add, multiply, power, neg, etc...) that bypasses
7
+ * the regular checks. This is its replacements. Since all those fastpath
8
+ * functions are numeric (i.e. have numeric arguments and return a numeric
9
+ * value), we do a simple numeric check of all arguments, and verify we have
10
+ * the number of expected arguments.
11
+ */
12
+ export declare function validateNumericArgs(ce: IComputeEngine, ops: SemiBoxedExpression[], count?: number): BoxedExpression[];
13
+ /** Return `null` if the `ops` match the sig. Otherwise, return an array
14
+ * of expressions indicating the mismatched arguments.
15
+ *
16
+ */
17
+ export declare function validateSignature(sig: BoxedDomain, ops: BoxedExpression[], codomain?: BoxedExpression): BoxedExpression[] | null;
18
+ export declare function validateArgument(ce: IComputeEngine, arg: BoxedExpression | undefined, expect: DomainExpression<BoxedExpression> | undefined): BoxedExpression;
@@ -1,10 +1,9 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression, MathJsonNumber } from '../math-json/math-json-format';
4
4
  import { SignalMessage, WarningSignal } from '../common/signals';
5
5
  import type { LibraryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
6
- import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, SymbolTable, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, Substitution, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, BoxedLambdaExpression, FunctionDefinition } from './public';
7
- import { BoxedFunction } from './boxed-expression/boxed-function';
6
+ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, SymbolTable, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution } from './public';
8
7
  /**
9
8
  *
10
9
  * To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
@@ -30,8 +29,6 @@ export declare class ComputeEngine implements IComputeEngine {
30
29
  /** @internal */
31
30
  readonly _ONE: BoxedExpression;
32
31
  /** @internal */
33
- readonly _TWO: BoxedExpression;
34
- /** @internal */
35
32
  readonly _HALF: BoxedExpression;
36
33
  /** @internal */
37
34
  readonly _NEGATIVE_ONE: BoxedExpression;
@@ -46,19 +43,19 @@ export declare class ComputeEngine implements IComputeEngine {
46
43
  /** @internal */
47
44
  readonly _COMPLEX_INFINITY: BoxedExpression;
48
45
  /** @internal */
49
- _DECIMAL_NAN: Decimal;
46
+ _BIGNUM_NAN: Decimal;
50
47
  /** @internal */
51
- _DECIMAL_ZERO: Decimal;
48
+ _BIGNUM_ZERO: Decimal;
52
49
  /** @internal */
53
- _DECIMAL_ONE: Decimal;
50
+ _BIGNUM_ONE: Decimal;
54
51
  /** @internal */
55
- _DECIMAL_TWO: Decimal;
52
+ _BIGNUM_TWO: Decimal;
56
53
  /** @internal */
57
- _DECIMAL_HALF: Decimal;
54
+ _BIGNUM_HALF: Decimal;
58
55
  /** @internal */
59
- _DECIMAL_PI: Decimal;
56
+ _BIGNUM_PI: Decimal;
60
57
  /** @internal */
61
- _DECIMAL_NEGATIVE_ONE: Decimal;
58
+ _BIGNUM_NEGATIVE_ONE: Decimal;
62
59
  /** @internal */
63
60
  private _precision;
64
61
  /** @internal */
@@ -68,7 +65,7 @@ export declare class ComputeEngine implements IComputeEngine {
68
65
  /** @internal */
69
66
  private _tolerance;
70
67
  /** @internal */
71
- private _decimalTolerance;
68
+ private _bignumTolerance;
72
69
  /** @internal */
73
70
  private _cache;
74
71
  /** @internal */
@@ -77,6 +74,14 @@ export declare class ComputeEngine implements IComputeEngine {
77
74
  private _cost?;
78
75
  /** @internal */
79
76
  private _jsonSerializationOptions;
77
+ /**
78
+ * During certain operations (serializing to LaTeX, constructing error
79
+ * messages) we need to use a "raw" JSON serialization without any customization. Setting the `_useRawJsonSerializationOptions` will bypass
80
+ * the `_jsonSerializationOptions` and use `_rawJsonSerializationOptions`
81
+ * instead
82
+ * @internal */
83
+ private _useRawJsonSerializationOptions;
84
+ private _rawJsonSerializationOptions;
80
85
  /** The domain of unknown symbols. If `null` unknown symbols do not have a
81
86
  * definition automatically associated with them.
82
87
  *
@@ -128,9 +133,10 @@ export declare class ComputeEngine implements IComputeEngine {
128
133
  * be the `'core'` dictionary which include some basic definitions such
129
134
  * as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
130
135
  *
131
- * @param options.numericMode The default mode is `auto`. Use `machine` to only
132
- * use 64-bit float, use `decimal` to always use arbitrary precision floating
133
- * point numbers or `complex` for complex numbers.
136
+ * @param options.numericMode The default mode is `"auto"`. Use `"machine"`
137
+ * to perform numeric calculations using 64-bit floats. Use `"bignum"` to
138
+ * perform calculations using arbitrary precision floating point numbers.
139
+ * Use `"auto"` or `"complex"` to allow calculations on complex numbers.
134
140
  *
135
141
  * @param options.numericPrecision Specific how many digits of precision for the
136
142
  * numeric calculations. Default is 100.
@@ -164,13 +170,15 @@ export declare class ComputeEngine implements IComputeEngine {
164
170
  _unregister(_expr: BoxedExpression): void;
165
171
  get stats(): ComputeEngineStats;
166
172
  /** @internal */
167
- _decimal: Decimal.Constructor;
168
- /** The precision, or number of significant digits, for numeric calculations
169
- * such as when calling `ce.N()`.
173
+ _bignum: Decimal.Constructor;
174
+ /** The precision, or number of significant digits, of numeric
175
+ * calculations when the numeric mode is `"auto"` or `"bignum"`.
170
176
  *
171
- * To make calculations using more digits, at the cost of expended memory
177
+ * To make calculations using more digits, at the cost of expanded memory
172
178
  * usage and slower computations, set the `precision` higher.
173
179
  *
180
+ * If the numeric mode is not `"auto"` or `"bignum"`, it is set to `"auto"`.
181
+ *
174
182
  * Trigonometric operations are accurate for precision up to 1,000.
175
183
  *
176
184
  */
@@ -202,7 +210,7 @@ export declare class ComputeEngine implements IComputeEngine {
202
210
  get tolerance(): number;
203
211
  set tolerance(val: number);
204
212
  /** @internal */
205
- decimal(a: Decimal.Value): Decimal;
213
+ bignum(a: Decimal.Value): Decimal;
206
214
  /** @internal */
207
215
  complex(a: number | Complex, b?: number): Complex;
208
216
  /** Replace a number that is close to 0 with the exact integer 0.
@@ -231,7 +239,7 @@ export declare class ComputeEngine implements IComputeEngine {
231
239
  * of the argument or the codomain. However, it is useful during parsing
232
240
  * to differentiate between symbols that might represent a function application, e.g. `f` vs `x`.
233
241
  */
234
- lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
242
+ lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
235
243
  /**
236
244
  * Add (or replace) a definition for a symbol in the current scope.
237
245
  */
@@ -253,6 +261,12 @@ export declare class ComputeEngine implements IComputeEngine {
253
261
  /** Remove the topmost scope from the scope stack.
254
262
  */
255
263
  popScope(): void;
264
+ set(identifiers: {
265
+ [identifier: string]: SemiBoxedExpression;
266
+ }): void;
267
+ let(identifiers: {
268
+ [identifier: string]: SymbolDefinition | FunctionDefinition;
269
+ }): void;
256
270
  get assumptions(): ExpressionMapInterface<boolean>;
257
271
  /**
258
272
  * Return false if the execution should stop.
@@ -281,35 +295,51 @@ export declare class ComputeEngine implements IComputeEngine {
281
295
  signal(sig: WarningSignal): void;
282
296
  /** @internal */
283
297
  cache<T>(cacheName: string, build: () => T, purge: (T: any) => T | undefined): T;
284
- box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
298
+ box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
299
+ canonical?: boolean;
300
+ }): BoxedExpression;
285
301
  fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
286
302
  /** @internal */
287
- _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedFunction;
303
+ _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
288
304
  error(message: ['invalid-domain', ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedDomain;
289
305
  error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
306
+ hold(expr: SemiBoxedExpression): BoxedExpression;
290
307
  add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
291
- mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
292
- power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
293
- inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
294
308
  negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
309
+ mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
295
310
  divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
311
+ sqrt(base: BoxedExpression, metadata?: Metadata): BoxedExpression;
312
+ power(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
313
+ inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
296
314
  pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
297
315
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
298
316
  string(s: string, metadata?: Metadata): BoxedExpression;
299
- symbol(name: string, metadata?: Metadata): BoxedExpression;
317
+ symbol(name: string, options?: {
318
+ metadata?: Metadata;
319
+ canonical?: boolean;
320
+ }): BoxedExpression;
300
321
  domain(domain: BoxedExpression | DomainExpression | BoxedDomain, metadata?: Metadata): BoxedDomain;
301
- lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
302
- number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
322
+ number(value: number | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
323
+ canonical?: boolean;
324
+ metadata?: Metadata;
325
+ }): BoxedExpression;
303
326
  rules(rules: Rule[]): BoxedRuleSet;
304
327
  pattern(expr: LatexString | SemiBoxedExpression): Pattern;
305
- parse(latex: LatexString | string): BoxedExpression;
306
- parse(s: null): null;
307
- parse(latex: LatexString | string | null): null | BoxedExpression;
328
+ parse(latex: LatexString | string, options?: {
329
+ canonical?: boolean;
330
+ }): BoxedExpression;
331
+ parse(s: null, options?: {
332
+ canonical?: boolean;
333
+ }): null;
334
+ parse(latex: LatexString | string | null, options?: {
335
+ canonical?: boolean;
336
+ }): null | BoxedExpression;
308
337
  serialize(x: Expression | BoxedExpression): string;
309
338
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
310
339
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
311
- get jsonSerializationOptions(): JsonSerializationOptions;
340
+ get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
312
341
  set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
342
+ rawJson(expr: BoxedExpression): Expression;
313
343
  /**
314
344
  * Return a list of all the assumptions that match a pattern.
315
345
  *
@@ -319,7 +349,7 @@ export declare class ComputeEngine implements IComputeEngine {
319
349
  * // -> [{'val': 0}]
320
350
  * ```
321
351
  */
322
- ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
352
+ ask(pattern: LatexString | SemiBoxedExpression): BoxedSubstitution[];
323
353
  infer(symbol: BoxedExpression | string, _domain: BoxedDomain | DomainExpression): AssumeResult;
324
354
  assume(symbol: LatexString | SemiBoxedExpression, domainValue: BoxedDomain | DomainExpression | Expression | BoxedExpression): AssumeResult;
325
355
  assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
@@ -1,3 +1,3 @@
1
- /* 0.7.0 */
1
+ /* 0.9.0 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;