@cortex-js/compute-engine 0.10.0 → 0.11.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 (84) hide show
  1. package/dist/compute-engine.esm.js +2672 -3024
  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 +2 -2
  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 +9 -9
  9. package/dist/types/common/utils.d.ts +1 -1
  10. package/dist/types/compute-engine/assume.d.ts +1 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -2
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +32 -38
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -2
  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 +2 -2
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  27. package/dist/types/compute-engine/compute-engine.d.ts +16 -19
  28. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  29. package/dist/types/compute-engine/domain-utils.d.ts +2 -2
  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 +11 -11
  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 +1 -1
  43. package/dist/types/compute-engine/latex-syntax/public.d.ts +30 -30
  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 +1 -1
  46. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -2
  48. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  49. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  51. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  52. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
  53. package/dist/types/compute-engine/library/calculus.d.ts +2 -2
  54. package/dist/types/compute-engine/library/collections.d.ts +2 -2
  55. package/dist/types/compute-engine/library/core.d.ts +2 -2
  56. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  57. package/dist/types/compute-engine/library/library.d.ts +5 -5
  58. package/dist/types/compute-engine/library/logic.d.ts +2 -2
  59. package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
  60. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
  61. package/dist/types/compute-engine/library/sets.d.ts +2 -2
  62. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
  63. package/dist/types/compute-engine/library/utils.d.ts +3 -0
  64. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  65. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  66. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  67. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  68. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  69. package/dist/types/compute-engine/public.d.ts +90 -79
  70. package/dist/types/compute-engine/rules.d.ts +1 -1
  71. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  72. package/dist/types/compute-engine/solve.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  74. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  75. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  76. package/dist/types/compute-engine/symbolic/polynomials.d.ts +3 -3
  77. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  78. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  79. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  80. package/dist/types/compute-engine.d.ts +2 -2
  81. package/dist/types/math-json/math-json-format.d.ts +7 -7
  82. package/dist/types/math-json/utils.d.ts +1 -1
  83. package/dist/types/math-json.d.ts +2 -2
  84. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  * The most important classes are {@link ComputeEngine} and
3
3
  * {@link BoxedExpression}.
4
4
  *
@@ -13,11 +13,11 @@ import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../comm
13
13
  import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
14
14
  import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
15
15
  export * from './latex-syntax/public';
16
- export declare type Rational = [number, number] | [Decimal, Decimal];
16
+ export type Rational = [number, number] | [Decimal, Decimal];
17
17
  /**
18
18
  * Metadata that can be associated with a `BoxedExpression`
19
19
  */
20
- export declare type Metadata = {
20
+ export type Metadata = {
21
21
  latex?: string | undefined;
22
22
  wikidata?: string | undefined;
23
23
  };
@@ -35,9 +35,9 @@ export declare type Metadata = {
35
35
 
36
36
  </div>
37
37
  */
38
- export declare type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
38
+ export type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
39
39
  /** Options for `BoxedExpression.simplify()` */
40
- export declare type SimplifyOptions = EvaluateOptions & {
40
+ export type SimplifyOptions = EvaluateOptions & {
41
41
  recursive?: boolean;
42
42
  rules?: BoxedRuleSet;
43
43
  };
@@ -45,12 +45,12 @@ export declare type SimplifyOptions = EvaluateOptions & {
45
45
  *
46
46
  * @internal
47
47
  */
48
- export declare type EvaluateOptions = {};
48
+ export type EvaluateOptions = {};
49
49
  /** Options for `BoxedExpression.N()`
50
50
  * @internal
51
51
  */
52
- export declare type NOptions = {};
53
- export declare type ReplaceOptions = {
52
+ export type NOptions = {};
53
+ export type ReplaceOptions = {
54
54
  /** If `true`, apply replacement rules to all sub-expressions.
55
55
  * If `false`, only consider the top-level expression.
56
56
  *
@@ -82,16 +82,16 @@ export declare type ReplaceOptions = {
82
82
  * A substitution can also be considered a more constrained version of a
83
83
  * rule whose `lhs` is always a symbol.
84
84
  */
85
- export declare type Substitution = {
85
+ export type Substitution = {
86
86
  [symbol: string]: SemiBoxedExpression;
87
87
  };
88
- export declare type BoxedSubstitution = {
88
+ export type BoxedSubstitution = {
89
89
  [symbol: string]: BoxedExpression;
90
90
  };
91
91
  /** A LaTeX string starts and end with `$`, for example
92
92
  * `"$\frac{\pi}{2}$"`.
93
93
  */
94
- export declare type LatexString = string;
94
+ export type LatexString = string;
95
95
  /**
96
96
  * A rule describes how to modify an expressions that matches a `lhs` pattern
97
97
  * into a new expressions matching `rhs`.
@@ -112,7 +112,7 @@ export declare type LatexString = string;
112
112
  * - `__1` (`__a`, etc..) match a sequence of one or more expressions
113
113
  * - `___1` (`___a`, etc...) match a sequence of zero or more expressions
114
114
  */
115
- export declare type Rule = [
115
+ export type Rule = [
116
116
  lhs: LatexString | SemiBoxedExpression | Pattern,
117
117
  rhs: LatexString | SemiBoxedExpression,
118
118
  options?: {
@@ -120,18 +120,18 @@ export declare type Rule = [
120
120
  priority?: number;
121
121
  }
122
122
  ];
123
- export declare type BoxedRule = [
123
+ export type BoxedRule = [
124
124
  lhs: Pattern,
125
125
  rhs: BoxedExpression,
126
126
  priority: number,
127
127
  condition: undefined | ((wildcards: BoxedSubstitution) => boolean)
128
128
  ];
129
- export declare type BoxedRuleSet = Set<BoxedRule>;
130
- export declare type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
129
+ export type BoxedRuleSet = Set<BoxedRule>;
130
+ export type DomainCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
131
131
  /** A domain constructor is the head of a domain expression. */
132
- export declare type DomainConstructor = 'Error' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
133
- export declare type DomainLiteral = string;
134
- export declare type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['Error', T] | ['Error', T, T] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['Matrix', DomainExpression<T>, T, T] | ['SquareMatrix', DomainExpression<T>, T] | ['Vector', DomainExpression<T>, T] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Range'] | ['Range', T] | ['Range', T, T] | ['Range', T, T, T] | ['Interval', T, T] | ['Interval', ['Open', T], T] | ['Interval', T, ['Open', T]] | ['Interval', ['Open', T], ['Open', T]] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Function', ...DomainExpression<T>[]];
132
+ export type DomainConstructor = 'Error' | 'Matrix' | 'SquareMatrix' | 'Vector' | 'Function' | 'List' | 'Dictionary' | 'Tuple' | 'Range' | 'Interval' | 'Intersection' | 'Union' | 'Maybe' | 'Sequence' | 'Head' | 'Symbol' | 'Value' | 'Covariant' | 'Contravariant' | 'Bivariant' | 'Invariant';
133
+ export type DomainLiteral = string;
134
+ export type DomainExpression<T = SemiBoxedExpression> = DomainLiteral | [DomainConstructor, ...(string | T | DomainExpression<T>)[]] | ['Error', T] | ['Error', T, T] | ['Union', ...DomainExpression<T>[]] | ['Intersection', ...DomainExpression<T>[]] | ['Matrix', DomainExpression<T>, T, T] | ['SquareMatrix', DomainExpression<T>, T] | ['Vector', DomainExpression<T>, T] | ['List', DomainExpression<T>] | ['Dictionary', DomainExpression<T>] | ['Tuple', ...DomainExpression<T>[]] | ['Maybe', DomainExpression<T>] | ['Sequence', DomainExpression<T>] | ['Range'] | ['Range', T] | ['Range', T, T] | ['Range', T, T, T] | ['Interval', T, T] | ['Interval', ['Open', T], T] | ['Interval', T, ['Open', T]] | ['Interval', ['Open', T], ['Open', T]] | ['Value', T] | ['Head', string] | ['Symbol', string] | ['Covariant', DomainExpression<T>] | ['Contravariant', DomainExpression<T>] | ['Bivariant', DomainExpression<T>] | ['Invariant', DomainExpression<T>] | ['Function', ...DomainExpression<T>[]];
135
135
  export interface BoxedDomain extends BoxedExpression {
136
136
  is(s: BoxedDomain): boolean;
137
137
  /** True if a valid domain, and compatible with `dom` */
@@ -176,7 +176,7 @@ export interface BoxedDomain extends BoxedExpression {
176
176
  /**
177
177
  * Options to control the serialization to MathJSON when using `BoxedExpression.json`.
178
178
  */
179
- export declare type JsonSerializationOptions = {
179
+ export type JsonSerializationOptions = {
180
180
  /** A list of space separated function names that should be excluded from
181
181
  * the JSON output.
182
182
  *
@@ -987,8 +987,8 @@ export interface BoxedExpression {
987
987
  * This is convenient when creating new expressions from portions
988
988
  * of an existing `BoxedExpression` while avoiding unboxing and reboxing.
989
989
  */
990
- export declare type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
991
- export declare type PatternMatchOptions = {
990
+ export type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
991
+ export type PatternMatchOptions = {
992
992
  substitution?: BoxedSubstitution;
993
993
  recursive?: boolean;
994
994
  numericTolerance?: number;
@@ -1009,27 +1009,31 @@ export interface ExpressionMapInterface<U> {
1009
1009
  [Symbol.iterator](): IterableIterator<[BoxedExpression, U]>;
1010
1010
  }
1011
1011
  /**
1012
- * A symbol table contains definitions for symbols, functions and rules.
1012
+ * An ID table contains definitions for symbols and functions.
1013
+ *
1014
+ * The index of the table is an identifier, the name of the symbol or
1015
+ * function for this definition
1016
+ *
1017
+ * The name of a symbol or function is an arbitrary string of Unicode
1018
+ * characters, however the following conventions are recommended:
1019
+ *
1020
+ * - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
1021
+ * - The first character should be a letter: `/^[a-zA-Z]/`
1022
+ * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
1013
1023
  *
1014
1024
  */
1015
- export declare type SymbolTable = {
1016
- symbols?: SymbolDefinition[];
1017
- functions?: FunctionDefinition[];
1018
- simplifyRules?: BoxedRuleSet;
1025
+ export type IDTable = {
1026
+ [id: string]: SymbolDefinition | FunctionDefinition;
1019
1027
  };
1020
1028
  /**
1021
- * The entries of a `RuntimeSymbolTable` have been validated and
1029
+ * The entries of a `RuntimeIdentifierTable` have been validated and
1022
1030
  * optimized for faster evaluation.
1023
1031
  *
1024
1032
  * When a new scope is created with `pushScope()` or when creating a new
1025
- * engine instance, new instances of `RuntimeDictionary` are created as needed.
1033
+ * engine instance, new instances of `RuntimeIdentifierTable` are created
1034
+ * as needed.
1026
1035
  */
1027
- export declare type RuntimeSymbolTable = {
1028
- symbols: Map<string, BoxedSymbolDefinition>;
1029
- symbolWikidata: Map<string, BoxedSymbolDefinition>;
1030
- functions: Map<string, BoxedFunctionDefinition>;
1031
- functionWikidata: Map<string, BoxedFunctionDefinition>;
1032
- };
1036
+ export type RuntimeIdentifierTable = Map<string, BoxedSymbolDefinition | BoxedFunctionDefinition>;
1033
1037
  /**
1034
1038
  * A scope is a set of names in a dictionary that are bound (defined) in
1035
1039
  * a MathJSON expression.
@@ -1045,7 +1049,7 @@ export declare type RuntimeSymbolTable = {
1045
1049
  * where they are in an expression, they are not determined at runtime.
1046
1050
  *
1047
1051
  */
1048
- export declare type Scope = {
1052
+ export type Scope = {
1049
1053
  /** This handler is invoked when exiting this scope if there are any
1050
1054
  * warnings pending. */
1051
1055
  warn?: WarningSignalHandler;
@@ -1074,9 +1078,9 @@ export declare type Scope = {
1074
1078
  */
1075
1079
  iterationLimit?: number;
1076
1080
  };
1077
- export declare type RuntimeScope = Scope & {
1081
+ export type RuntimeScope = Scope & {
1078
1082
  parentScope?: RuntimeScope;
1079
- symbolTable?: RuntimeSymbolTable;
1083
+ idTable?: RuntimeIdentifierTable;
1080
1084
  assumptions: undefined | ExpressionMapInterface<boolean>;
1081
1085
  /** The location of the call site that created this scope */
1082
1086
  origin?: {
@@ -1089,18 +1093,7 @@ export declare type RuntimeScope = Scope & {
1089
1093
  /** Set when one or more warnings have been signaled in this scope */
1090
1094
  warnings?: WarningSignal[];
1091
1095
  };
1092
- export declare type BaseDefinition = {
1093
- /** The name of the symbol or function for this definition
1094
- *
1095
- * The name of a symbol or function is an arbitrary string of Unicode
1096
- * characters, however the following conventions are recommended:
1097
- *
1098
- * - Use only letters, digits and `-`: `/[a-zA-Z0-9-]+/`
1099
- * - The first character should be a letter: `/^[a-zA-Z]/`
1100
- * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
1101
- *
1102
- */
1103
- name: string;
1096
+ export type BaseDefinition = {
1104
1097
  /** A short (about 1 line) description. May contain Markdown. */
1105
1098
  description?: string | string[];
1106
1099
  /** A URL pointing to more information about this symbol or head. */
@@ -1133,7 +1126,7 @@ export interface BoxedBaseDefinition {
1133
1126
  * A function definition can have some flags to indicate specific
1134
1127
  * properties of the function.
1135
1128
  */
1136
- export declare type FunctionDefinitionFlags = {
1129
+ export type FunctionDefinitionFlags = {
1137
1130
  /** If `true`, the function is applied element by element to lists, matrices
1138
1131
  * (`["List"]` or `["Tuple"]` expressions) and equations (relational
1139
1132
  * operators).
@@ -1220,7 +1213,7 @@ export declare type FunctionDefinitionFlags = {
1220
1213
  /**
1221
1214
  *
1222
1215
  */
1223
- export declare type FunctionSignature = {
1216
+ export type FunctionSignature = {
1224
1217
  /** The domain of this signature, a domain compatible with the `Function`
1225
1218
  * domain) */
1226
1219
  domain?: BoxedDomain | DomainExpression;
@@ -1250,7 +1243,10 @@ export declare type FunctionSignature = {
1250
1243
  * arguments should be sorted in canonical order.
1251
1244
  *
1252
1245
  * The handler can make transformations based on the value of the arguments
1253
- * that are exact (i.e. `arg.isExact`).
1246
+ * that are exact and literal
1247
+ * (i.e. `arg.numericValue !== null && arg.isExact`).
1248
+ *
1249
+ * Values of symbols should not be substituted.
1254
1250
  *
1255
1251
  * The handler should not consider the value or any assumptions about any
1256
1252
  * of the arguments that are symbols or functions (i.e. `arg.isZero`,
@@ -1364,7 +1360,7 @@ export declare type FunctionSignature = {
1364
1360
  /** Return a compiled (optimized) expression. */
1365
1361
  compile?: (expr: BoxedExpression) => CompiledExpression;
1366
1362
  };
1367
- export declare type BoxedFunctionSignature = {
1363
+ export type BoxedFunctionSignature = {
1368
1364
  domain: BoxedDomain;
1369
1365
  codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null);
1370
1366
  canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
@@ -1379,7 +1375,7 @@ export declare type BoxedFunctionSignature = {
1379
1375
  * Definition record for a function.
1380
1376
  *
1381
1377
  */
1382
- export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
1378
+ export type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
1383
1379
  /**
1384
1380
  * A number used to order arguments.
1385
1381
  *
@@ -1414,7 +1410,7 @@ export declare type FunctionDefinition = BaseDefinition & Partial<FunctionDefini
1414
1410
  hold?: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1415
1411
  signature?: FunctionSignature;
1416
1412
  };
1417
- export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
1413
+ export type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefinitionFlags & {
1418
1414
  complexity: number;
1419
1415
  hold: 'none' | 'all' | 'first' | 'rest' | 'last' | 'most';
1420
1416
  signature: BoxedFunctionSignature;
@@ -1428,7 +1424,7 @@ export declare type BoxedFunctionDefinition = BoxedBaseDefinition & FunctionDefi
1428
1424
  * For example, it might be useful to override `algebraic = false`
1429
1425
  * for a transcendental number.
1430
1426
  */
1431
- export declare type SymbolFlags = {
1427
+ export type SymbolFlags = {
1432
1428
  number: boolean | undefined;
1433
1429
  integer: boolean | undefined;
1434
1430
  rational: boolean | undefined;
@@ -1454,42 +1450,61 @@ export declare type SymbolFlags = {
1454
1450
  prime: boolean | undefined;
1455
1451
  composite: boolean | undefined;
1456
1452
  };
1457
- export declare type SymbolDefinitionFlags = {
1453
+ export type SymbolAttributes = {
1458
1454
  /**
1459
- * If true the value of the symbol is constant.
1455
+ * If `true` the value of the symbol is constant. The value or domain of
1456
+ * symbols with this attribute set to `true` cannot be changed.
1457
+ *
1458
+ * If `false`, the symbol is a variable.
1460
1459
  *
1461
- * If false, the symbol is a variable.
1460
+ * **Default**: `false`
1462
1461
  */
1463
1462
  constant: boolean;
1464
1463
  /**
1465
- * If `false`, the value of the symbol is substituted during canonicalization
1466
- * or simplification.
1467
- *
1468
- * If true, the value is only replaced during a `ce.N()` or `ce.evaluate()`.
1469
- *
1470
- * **Default:** `true`
1471
- */
1472
- hold: boolean;
1464
+ * If the symbol has a value, it is held as indicated in the table below.
1465
+ * A green checkmark indicate that the symbol is substituted.
1466
+
1467
+ <div class=symbols-table>
1468
+
1469
+ | Operation | `"never"` | `"simplify"` | `"evaluate"` | `"N"` |
1470
+ | :--- | :----- |
1471
+ | `canonical()`| {% icon "circle-check" "green-700" %} | | | |
1472
+ | `simplify()` | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | | |
1473
+ | `evaluate()` | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | |
1474
+ | `"N()"` | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} | {% icon "circle-check" "green-700" %} |
1475
+
1476
+ </div>
1477
+
1478
+ * Some examples:
1479
+ * - `i` has `holdUntil: 'never'`
1480
+ * - `GoldenRatio` has `holdUntil: 'simplify'` (symbolic constant)
1481
+ * - `x` has `holdUntil: 'evaluate'` (variables)
1482
+ * - `Pi` has `holdUntil: 'N'` (special numeric constant)
1483
+ *
1484
+ * **Default:** `simplify`
1485
+ */
1486
+ holdUntil: 'never' | 'simplify' | 'evaluate' | 'N';
1473
1487
  };
1474
1488
  /**
1475
1489
  * A bound symbol (i.e. one with an associated definition) has either a domain
1476
1490
  * (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... domain = TranscendentalNumber)
1477
1491
  */
1478
- export declare type SymbolDefinition = BaseDefinition & Partial<SymbolFlags> & Partial<SymbolDefinitionFlags> & {
1492
+ export type SymbolDefinition = BaseDefinition & Partial<SymbolAttributes> & {
1493
+ domain?: string | BoxedDomain;
1479
1494
  /** `value` can be a function since for some constants, such as
1480
1495
  * `Pi`, the actual value depends on the `precision` setting of the
1481
1496
  * `ComputeEngine` */
1482
1497
  value?: LatexString | SemiBoxedExpression | ((ce: IComputeEngine) => SemiBoxedExpression | null);
1483
- domain?: string | BoxedDomain;
1498
+ flags?: Partial<SymbolFlags>;
1484
1499
  };
1485
- export interface BoxedSymbolDefinition extends BoxedBaseDefinition, Partial<SymbolFlags>, SymbolDefinitionFlags {
1500
+ export interface BoxedSymbolDefinition extends BoxedBaseDefinition, SymbolAttributes, Partial<SymbolFlags> {
1486
1501
  get value(): BoxedExpression | undefined;
1487
1502
  set value(val: SemiBoxedExpression | number | undefined);
1488
1503
  domain: BoxedDomain | undefined;
1489
1504
  at?: (index: string | number) => undefined | BoxedExpression;
1490
1505
  }
1491
- export declare type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
1492
- export declare type CompiledExpression = {
1506
+ export type AssumeResult = 'internal-error' | 'not-a-predicate' | 'contradiction' | 'tautology' | 'ok';
1507
+ export type CompiledExpression = {
1493
1508
  evaluate?: (scope: {
1494
1509
  [symbol: string]: BoxedExpression;
1495
1510
  }) => number | BoxedExpression;
@@ -1573,13 +1588,13 @@ export interface IComputeEngine {
1573
1588
  *
1574
1589
  * If a definition existed previously, it is replaced.
1575
1590
  */
1576
- defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
1591
+ defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
1577
1592
  /**
1578
1593
  * Associate a new definition to a function in the current context.
1579
1594
  *
1580
1595
  * If a definition existed previously, it is replaced.
1581
1596
  */
1582
- defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
1597
+ defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
1583
1598
  lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
1584
1599
  /** Return `undefined` if no definition exist for this `head` */
1585
1600
  lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
@@ -1715,11 +1730,7 @@ export interface IComputeEngine {
1715
1730
  /** {@inheritDoc JsonSerializationOptions} */
1716
1731
  get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
1717
1732
  set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
1718
- pushScope(options?: {
1719
- symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
1720
- assumptions?: (LatexString | Expression | BoxedExpression)[];
1721
- scope?: Partial<Scope>;
1722
- }): void;
1733
+ pushScope(symbolTable?: Readonly<IDTable> | Readonly<IDTable>[], scope?: Partial<Scope>): void;
1723
1734
  popScope(): void;
1724
1735
  /** Assign a value to an identifier in the current scope. Use `null` to reset the identifier to no value */
1725
1736
  set(identifiers: {
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  /**
3
3
  * Go through all the rules in the rule set, and for all the rules that match
4
4
  * return the rhs of the rule applied to `expr`.
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  /**
3
3
  * A set of simplification rules.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.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.10.0 */
1
+ /* 0.11.0 */
2
2
  /**
3
3
  * Return the expansion of ['Multiply', lhs, rhs]
4
4
  * - lhs = 'a + b', rhs = '2'
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  /**
3
3
  * Flatten the arguments.
4
4
  * If `expr` was canonical, the result it canonical.
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  /**
3
3
  * Distribute `Negate` (multiply by -1) if expr is a number literal, an
4
4
  * addition or another `Negate`.
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -12,8 +12,8 @@
12
12
  * If a coefficient does not apply (there are no corresponding term), it is `null`.
13
13
  *
14
14
  */
15
- export declare type UnivariateCoefficients = (null | BoxedExpression)[];
16
- export declare type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
15
+ export type UnivariateCoefficients = (null | BoxedExpression)[];
16
+ export type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
17
17
  /**
18
18
  * Return a list of coefficient of powers of `vars` in `poly`,
19
19
  * starting with power 0.
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  /**
3
3
  * Group terms in a product by common term.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  export declare class Sum {
3
3
  private engine;
4
4
  private _rational;
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { BoxedExpression, Rational } from '../public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  export { ComputeEngine } from './compute-engine/compute-engine';
3
- export declare const version = "0.10.0";
3
+ export declare const version = "0.11.0";
4
4
  export { getVars } from './compute-engine/boxed-expression/utils';
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.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;
@@ -78,19 +78,19 @@
78
78
  * - `1.(3)`
79
79
  * - `123456789123456789.123(4567)e999`
80
80
  */
81
- export declare type MathJsonNumber = {
81
+ export type MathJsonNumber = {
82
82
  num: 'NaN' | '-Infinity' | '+Infinity' | string;
83
83
  } & Attributes;
84
- export declare type MathJsonSymbol = {
84
+ export type MathJsonSymbol = {
85
85
  sym: string;
86
86
  } & Attributes;
87
- export declare type MathJsonString = {
87
+ export type MathJsonString = {
88
88
  str: string;
89
89
  } & Attributes;
90
- export declare type MathJsonFunction = {
90
+ export type MathJsonFunction = {
91
91
  fn: [Expression, ...Expression[]];
92
92
  } & Attributes;
93
- export declare type MathJsonDictionary = {
93
+ export type MathJsonDictionary = {
94
94
  dict: {
95
95
  [key: string]: Expression;
96
96
  };
@@ -102,4 +102,4 @@ export declare type MathJsonDictionary = {
102
102
  * The dictionary and function nodes can contain expressions themselves.
103
103
  *
104
104
  */
105
- export declare type Expression = number | string | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | [Expression, ...Expression[]];
105
+ export type Expression = number | string | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | [Expression, ...Expression[]];
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.0 */
2
2
  export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
3
3
  export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbol;
4
4
  export declare function isStringObject(expr: Expression | null): expr is MathJsonString;
@@ -1,4 +1,4 @@
1
- /* 0.10.0 */
1
+ /* 0.11.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
3
  export type { LatexToken, ParseHandler, SerializeHandler, LatexDictionaryEntry, LatexDictionary, ParseLatexOptions, SerializeLatexOptions, NumberFormattingOptions, } from './compute-engine/latex-syntax/public';
4
- export declare const version = "0.10.0";
4
+ export declare const version = "0.11.0";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.10.0",
2
+ "version": "0.11.0",
3
3
  "scripts": {
4
4
  "build": "bash ./scripts/build.sh",
5
5
  "clean": "bash ./scripts/clean.sh",