@cortex-js/compute-engine 0.30.2 → 0.32.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 (143) hide show
  1. package/package.json +10 -10
  2. package/dist/compute-engine.esm.js +0 -38978
  3. package/dist/compute-engine.min.esm.js +0 -129
  4. package/dist/compute-engine.min.umd.js +0 -131
  5. package/dist/compute-engine.umd.js +0 -39003
  6. package/dist/math-json.esm.js +0 -116
  7. package/dist/math-json.min.esm.js +0 -116
  8. package/dist/math-json.min.umd.js +0 -4
  9. package/dist/math-json.umd.js +0 -141
  10. package/dist/types/common/ansi-codes.d.ts +0 -41
  11. package/dist/types/common/configuration-change.d.ts +0 -28
  12. package/dist/types/common/fuzzy-string-match.d.ts +0 -2
  13. package/dist/types/common/grapheme-splitter.d.ts +0 -15
  14. package/dist/types/common/interruptible.d.ts +0 -20
  15. package/dist/types/common/one-of.d.ts +0 -10
  16. package/dist/types/common/signals.d.ts +0 -96
  17. package/dist/types/common/type/boxed-type.d.ts +0 -30
  18. package/dist/types/common/type/parse.d.ts +0 -4
  19. package/dist/types/common/type/primitive.d.ts +0 -10
  20. package/dist/types/common/type/serialize.d.ts +0 -2
  21. package/dist/types/common/type/subtype.d.ts +0 -6
  22. package/dist/types/common/type/types.d.ts +0 -300
  23. package/dist/types/common/type/utils.d.ts +0 -36
  24. package/dist/types/common/utils.d.ts +0 -2
  25. package/dist/types/compute-engine/assume.d.ts +0 -26
  26. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +0 -165
  27. package/dist/types/compute-engine/boxed-expression/apply.d.ts +0 -5
  28. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +0 -16
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +0 -27
  30. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +0 -38
  31. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +0 -11
  32. package/dist/types/compute-engine/boxed-expression/box.d.ts +0 -47
  33. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -42
  34. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +0 -136
  35. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +0 -103
  36. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +0 -53
  37. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +0 -4
  38. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +0 -27
  39. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +0 -170
  40. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +0 -83
  41. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +0 -46
  42. package/dist/types/compute-engine/boxed-expression/cache.d.ts +0 -7
  43. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +0 -5
  44. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +0 -2
  45. package/dist/types/compute-engine/boxed-expression/compare.d.ts +0 -13
  46. package/dist/types/compute-engine/boxed-expression/expand.d.ts +0 -20
  47. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +0 -12
  48. package/dist/types/compute-engine/boxed-expression/factor.d.ts +0 -10
  49. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +0 -25
  50. package/dist/types/compute-engine/boxed-expression/hold.d.ts +0 -10
  51. package/dist/types/compute-engine/boxed-expression/match.d.ts +0 -12
  52. package/dist/types/compute-engine/boxed-expression/negate.d.ts +0 -11
  53. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +0 -34
  54. package/dist/types/compute-engine/boxed-expression/order.d.ts +0 -71
  55. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +0 -48
  56. package/dist/types/compute-engine/boxed-expression/product.d.ts +0 -66
  57. package/dist/types/compute-engine/boxed-expression/rules.d.ts +0 -129
  58. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +0 -3
  59. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +0 -46
  60. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +0 -6
  61. package/dist/types/compute-engine/boxed-expression/solve.d.ts +0 -20
  62. package/dist/types/compute-engine/boxed-expression/terms.d.ts +0 -10
  63. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +0 -9
  64. package/dist/types/compute-engine/boxed-expression/utils.d.ts +0 -54
  65. package/dist/types/compute-engine/boxed-expression/validate.d.ts +0 -49
  66. package/dist/types/compute-engine/collection-utils.d.ts +0 -35
  67. package/dist/types/compute-engine/compile.d.ts +0 -80
  68. package/dist/types/compute-engine/cost-function.d.ts +0 -13
  69. package/dist/types/compute-engine/function-utils.d.ts +0 -120
  70. package/dist/types/compute-engine/global-types.d.ts +0 -2872
  71. package/dist/types/compute-engine/index.d.ts +0 -657
  72. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +0 -2
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +0 -2
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +0 -2
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +0 -2
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +0 -27
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +0 -2
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +0 -2
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +0 -2
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +0 -2
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +0 -2
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +0 -2
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +0 -3
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +0 -2
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +0 -88
  86. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +0 -21
  87. package/dist/types/compute-engine/latex-syntax/parse.d.ts +0 -303
  88. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +0 -29
  89. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +0 -10
  90. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +0 -37
  91. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +0 -18
  92. package/dist/types/compute-engine/latex-syntax/types.d.ts +0 -845
  93. package/dist/types/compute-engine/latex-syntax/utils.d.ts +0 -5
  94. package/dist/types/compute-engine/library/arithmetic.d.ts +0 -4
  95. package/dist/types/compute-engine/library/calculus.d.ts +0 -2
  96. package/dist/types/compute-engine/library/collections.d.ts +0 -27
  97. package/dist/types/compute-engine/library/combinatorics.d.ts +0 -2
  98. package/dist/types/compute-engine/library/complex.d.ts +0 -2
  99. package/dist/types/compute-engine/library/control-structures.d.ts +0 -2
  100. package/dist/types/compute-engine/library/core.d.ts +0 -2
  101. package/dist/types/compute-engine/library/invisible-operator.d.ts +0 -4
  102. package/dist/types/compute-engine/library/library.d.ts +0 -17
  103. package/dist/types/compute-engine/library/linear-algebra.d.ts +0 -2
  104. package/dist/types/compute-engine/library/logic.d.ts +0 -6
  105. package/dist/types/compute-engine/library/number-theory.d.ts +0 -2
  106. package/dist/types/compute-engine/library/polynomials.d.ts +0 -2
  107. package/dist/types/compute-engine/library/random-expression.d.ts +0 -2
  108. package/dist/types/compute-engine/library/relational-operator.d.ts +0 -2
  109. package/dist/types/compute-engine/library/sets.d.ts +0 -2
  110. package/dist/types/compute-engine/library/statistics.d.ts +0 -2
  111. package/dist/types/compute-engine/library/trigonometry.d.ts +0 -2
  112. package/dist/types/compute-engine/library/utils.d.ts +0 -77
  113. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +0 -57
  114. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +0 -75
  115. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +0 -56
  116. package/dist/types/compute-engine/numeric-value/types.d.ts +0 -116
  117. package/dist/types/compute-engine/numerics/bigint.d.ts +0 -2
  118. package/dist/types/compute-engine/numerics/expression.d.ts +0 -4
  119. package/dist/types/compute-engine/numerics/interval.d.ts +0 -12
  120. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +0 -4
  121. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +0 -18
  122. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +0 -9
  123. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +0 -3
  124. package/dist/types/compute-engine/numerics/numeric.d.ts +0 -60
  125. package/dist/types/compute-engine/numerics/primes.d.ts +0 -7
  126. package/dist/types/compute-engine/numerics/rationals.d.ts +0 -43
  127. package/dist/types/compute-engine/numerics/richardson.d.ts +0 -80
  128. package/dist/types/compute-engine/numerics/special-functions.d.ts +0 -28
  129. package/dist/types/compute-engine/numerics/statistics.d.ts +0 -24
  130. package/dist/types/compute-engine/numerics/strings.d.ts +0 -2
  131. package/dist/types/compute-engine/numerics/types.d.ts +0 -30
  132. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +0 -3
  133. package/dist/types/compute-engine/symbolic/derivative.d.ts +0 -18
  134. package/dist/types/compute-engine/symbolic/distribute.d.ts +0 -5
  135. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +0 -27
  136. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +0 -128
  137. package/dist/types/compute-engine/tensor/tensors.d.ts +0 -93
  138. package/dist/types/compute-engine/types.d.ts +0 -8
  139. package/dist/types/compute-engine.d.ts +0 -3
  140. package/dist/types/math-json/symbols.d.ts +0 -11
  141. package/dist/types/math-json/types.d.ts +0 -120
  142. package/dist/types/math-json/utils.d.ts +0 -81
  143. package/dist/types/math-json.d.ts +0 -3
@@ -1,54 +0,0 @@
1
- /* 0.30.2 */
2
- import { Type } from '../../common/type/types';
3
- import { NumericValue } from '../numeric-value/types';
4
- export declare function isDictionary(expr: any | null | undefined): expr is DictionaryInterface;
5
- export declare function isBoxedExpression(x: unknown): x is BoxedExpression;
6
- /**
7
- * For any numeric result, if `bignumPreferred()` is true, calculate using
8
- * bignums. If `bignumPreferred()` is false, calculate using machine numbers
9
- */
10
- export declare function bignumPreferred(ce: ComputeEngine): boolean;
11
- export declare function hashCode(s: string): number;
12
- export declare function normalizedUnknownsForSolve(syms: string | Iterable<string> | BoxedExpression | Iterable<BoxedExpression> | null | undefined): string[];
13
- /** Return the local variables in the expression.
14
- *
15
- * A local variable is a symbol that is declared with a `Declare`
16
- * expression in a `Block` expression.
17
- *
18
- */
19
- export declare function getLocalVariables(expr: BoxedExpression): string[];
20
- export declare function domainToType(expr: BoxedExpression): Type;
21
- /**
22
- * Return the angle in the range [0, 2π) that is equivalent to the given angle.
23
- *
24
- * @param x
25
- * @returns
26
- */
27
- export declare function canonicalAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
28
- /**
29
- * Return a multiple of the imaginary unit, e.g.
30
- * - 'ImaginaryUnit' -> 1
31
- * - ['Negate', 'ImaginaryUnit'] -> -1
32
- * - ['Negate', ['Multiply', 3, 'ImaginaryUnit']] -> -3
33
- * - ['Multiply', 5, 'ImaginaryUnit'] -> 5
34
- * - ['Multiply', 'ImaginaryUnit', 5] -> 5
35
- * - ['Divide', 'ImaginaryUnit', 2] -> 0.5
36
- *
37
- */
38
- export declare function getImaginaryFactor(expr: number | BoxedExpression): BoxedExpression | undefined;
39
- /**
40
- * `true` if expr is a number with imaginary part 1 and real part 0, or a symbol with a definition
41
- * matching this. Does not bind expr if a symbol.
42
- *
43
- * @export
44
- * @param expr
45
- * @returns
46
- */
47
- export declare function isImaginaryUnit(expr: BoxedExpression): boolean;
48
- export declare function getPiTerm(expr: BoxedExpression): [k: NumericValue, t: NumericValue];
49
- export declare function isValidOperatorDef(def: any): def is Partial<OperatorDefinition>;
50
- export declare function isValidValueDef(def: any): def is Partial<ValueDefinition>;
51
- export declare function isValueDef(def: BoxedDefinition | undefined): def is TaggedValueDefinition;
52
- export declare function isOperatorDef(def: BoxedDefinition | undefined): def is TaggedOperatorDefinition;
53
- export declare function updateDef(ce: ComputeEngine, name: string, def: BoxedDefinition, newDef: Partial<OperatorDefinition> | BoxedOperatorDefinition | Partial<ValueDefinition> | BoxedValueDefinition): void;
54
- export declare function placeholderDef(ce: ComputeEngine, name: string): BoxedDefinition;
@@ -1,49 +0,0 @@
1
- /* 0.30.2 */
2
- import type { BoxedExpression, ComputeEngine } from '../global-types';
3
- /**
4
- * Check that the number of arguments is as expected.
5
- *
6
- * Converts the arguments to canonical, and flattens the sequence.
7
- */
8
- export declare function checkArity(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, count: number): ReadonlyArray<BoxedExpression>;
9
- /**
10
- * Validation of arguments is normally done by checking the signature of the
11
- * function vs the arguments of the expression. However, we have a fastpath
12
- * for some common operations (add, multiply, power, neg, etc...) that bypasses
13
- * the regular checks. This is its replacements.
14
- *
15
- * Since all those fastpath functions are numeric (i.e. have numeric arguments
16
- * and a numeric result), we do a simple numeric check of all arguments, and
17
- * verify we have the number of expected arguments.
18
- *
19
- * We also assume that the function is threadable.
20
- *
21
- * The arguments are made canonical.
22
- *
23
- * Flattens sequence expressions.
24
- */
25
- export declare function checkNumericArgs(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, options?: number | {
26
- count?: number;
27
- flatten?: string;
28
- }): ReadonlyArray<BoxedExpression>;
29
- /**
30
- * Check that an argument is of the expected type.
31
- *
32
- * Converts the arguments to canonical
33
- */
34
- export declare function checkType(ce: ComputeEngine, arg: BoxedExpression | undefined | null, type: Type | undefined): BoxedExpression;
35
- export declare function checkTypes(ce: ComputeEngine, args: ReadonlyArray<BoxedExpression>, types: Type[]): ReadonlyArray<BoxedExpression>;
36
- /**
37
- * Check that the argument is pure.
38
- */
39
- export declare function checkPure(ce: ComputeEngine, arg: BoxedExpression | BoxedExpression | undefined | null): BoxedExpression;
40
- /**
41
- *
42
- * If the arguments match the parameters, return null.
43
- *
44
- * Otherwise return a list of expressions indicating the mismatched
45
- * arguments.
46
- *
47
- */
48
- export declare function validateArguments(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, signature: Type, lazy?: boolean, threadable?: boolean): ReadonlyArray<BoxedExpression> | null;
49
- export declare function spellCheckMessage(expr: BoxedExpression): string;
@@ -1,35 +0,0 @@
1
- /* 0.30.2 */
2
- /** If a collection has fewer than this many elements, eagerly evaluate it.
3
- *
4
- * For example, evaluate the Union of two sets with 10 elements each will
5
- * result in a set with 20 elements.
6
- *
7
- * If the sum of the sizes of the two sets is greater than
8
- * `MAX_SIZE_EAGER_COLLECTION`, the result is a Union expression
9
- *
10
- */
11
- export declare const MAX_SIZE_EAGER_COLLECTION = 100;
12
- export declare function isFiniteIndexedCollection(col: BoxedExpression): boolean;
13
- export declare function repeat(value: BoxedExpression, count?: number): Iterator<BoxedExpression>;
14
- /**
15
- * Zips together multiple collections into a single iterator.
16
- *
17
- * Example:
18
- * ```typescript
19
- * const a = ce.box(['List', 1, 2, 3]);
20
- * const b = ce.box(['List', 4, 5, 6]);
21
- * const zipped = zip([a, b]);
22
- * for (const [x, y] of zipped) {
23
- * console.log(x, y); // 1 4, 2 5, 3 6
24
- * }
25
- * ```
26
- */
27
- export declare function zip(items: ReadonlyArray<BoxedExpression>): Iterator<BoxedExpression[]>;
28
- /**
29
- * Default collection handlers suitable for collections that store their
30
- * elements as operands.
31
- *
32
- * This is the case for List, Tuple, etc.
33
- */
34
- export declare function basicIndexedCollectionHandlers(): CollectionHandlers;
35
- export declare function defaultCollectionHandlers(def: undefined | CollectionHandlers): CollectionHandlers | undefined;
@@ -1,80 +0,0 @@
1
- /* 0.30.2 */
2
- import { BoxedExpression, JSSource } from './global-types';
3
- import { chop, factorial, gcd, lcm, limit } from './numerics/numeric';
4
- import { gamma, gammaln } from './numerics/special-functions';
5
- import { interquartileRange, kurtosis, mean, median, mode, populationStandardDeviation, populationVariance, quartiles, skewness, standardDeviation, variance } from './numerics/statistics';
6
- export type CompiledOperators = Record<MathJsonSymbol, [
7
- op: string,
8
- prec: number
9
- ]>;
10
- export type CompiledFunction = string | ((args: ReadonlyArray<BoxedExpression>, compile: (expr: BoxedExpression) => JSSource, target: CompileTarget) => JSSource);
11
- export type CompiledFunctions = {
12
- [id: MathJsonSymbol]: CompiledFunction;
13
- };
14
- export type CompileTarget = {
15
- operators?: (op: MathJsonSymbol) => [op: string, prec: number] | undefined;
16
- functions?: (id: MathJsonSymbol) => CompiledFunction | undefined;
17
- var: (id: MathJsonSymbol) => string | undefined;
18
- string: (str: string) => string;
19
- number: (n: number) => string;
20
- ws: (s?: string) => string;
21
- preamble: string;
22
- indent: number;
23
- };
24
- /** This is an extension of the Function class that allows us to pass
25
- * a custom scope for "global" functions. */
26
- export declare class ComputeEngineFunction extends Function {
27
- SYS: {
28
- chop: typeof chop;
29
- factorial: typeof factorial;
30
- gamma: typeof gamma;
31
- gcd: typeof gcd;
32
- integrate: (f: any, a: any, b: any) => number;
33
- lcm: typeof lcm;
34
- lngamma: typeof gammaln;
35
- limit: typeof limit;
36
- mean: typeof mean;
37
- median: typeof median;
38
- variance: typeof variance;
39
- populationVariance: typeof populationVariance;
40
- standardDeviation: typeof standardDeviation;
41
- populationStandardDeviation: typeof populationStandardDeviation;
42
- kurtosis: typeof kurtosis;
43
- skewness: typeof skewness;
44
- mode: typeof mode;
45
- quartiles: typeof quartiles;
46
- interquartileRange: typeof interquartileRange;
47
- };
48
- constructor(body: string, preamble?: string);
49
- }
50
- export declare class ComputeEngineFunctionLiteral extends Function {
51
- SYS: {
52
- chop: typeof chop;
53
- factorial: typeof factorial;
54
- gamma: typeof gamma;
55
- gcd: typeof gcd;
56
- integrate: (f: any, a: any, b: any) => number;
57
- lcm: typeof lcm;
58
- lngamma: typeof gammaln;
59
- limit: typeof limit;
60
- mean: typeof mean;
61
- median: typeof median;
62
- variance: typeof variance;
63
- populationVariance: typeof populationVariance;
64
- standardDeviation: typeof standardDeviation;
65
- populationStandardDeviation: typeof populationStandardDeviation;
66
- kurtosis: typeof kurtosis;
67
- skewness: typeof skewness;
68
- mode: typeof mode;
69
- quartiles: typeof quartiles;
70
- interquartileRange: typeof interquartileRange;
71
- };
72
- constructor(body: string, args: string[]);
73
- }
74
- export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): ((...args: any[]) => any) & {
75
- isCompiled: true;
76
- };
77
- export declare function compileToJavaScript(expr: BoxedExpression, functions?: Record<MathJsonSymbol, JSSource | Function>, vars?: Record<MathJsonSymbol, JSSource>, imports?: unknown[], preamble?: string): ((...args: any[]) => any) & {
78
- isCompiled: true;
79
- };
80
- export declare function compile(expr: BoxedExpression | undefined, target: CompileTarget, prec?: number): JSSource;
@@ -1,13 +0,0 @@
1
- /* 0.30.2 */
2
- /**
3
- * The default cost function, used to determine if a new expression is simpler
4
- * than the old one.
5
- *
6
- * To change the cost function used by the engine, set the
7
- * `ce.costFunction` property of the engine or pass a custom cost function
8
- * to the `simplify` function.
9
- *
10
- */
11
- export declare function costFunction(expr: BoxedExpression): number;
12
- export declare function leafCount(expr: BoxedExpression): number;
13
- export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,120 +0,0 @@
1
- /* 0.30.2 */
2
- import type { BoxedDefinition, BoxedExpression, ComputeEngine, Scope } from './global-types';
3
- /***
4
- * ### THEORY OF OPERATIONS
5
- *
6
- * The body of a `["Function"]` expression is a `["Block"]` expression,
7
- * which is scoped. The function arguments are declared in that scope as well.
8
- *
9
- * Some expressions with anonymous parameters (e.g. `["Add", "_", 1]`)
10
- * are rewritten to a `["Function"]` expression with anonymous parameters
11
- * (e.g. `["Function", ["Block", ["Add", "_", 1]], "_"]`).
12
- *
13
- *
14
- * #### DURING BOXING (in makeLambda())
15
- *
16
- * During the boxing/canonicalization phase of a function
17
- * (`["Function"]` expression or operator of expression):
18
- *
19
- * 1/ If not a `["Function"]` expression, the expression is rewritten
20
- * to a `["Function"]` expression with anonymous parameters
21
- * 2/ A new scope is created
22
- * 3/ The function parameters are declared in the scope
23
- * 4/ The function body is boxed in the context of the scope and the scope
24
- * is associated with the function
25
- *
26
- *
27
- * #### DURING EVALUATION (executing the result of makeLambda())
28
- *
29
- * 1/ The arguments are evaluated in the current scope
30
- * 2/ The context is swapped to the function scope
31
- * 3/ The function parameters are set to the value of the arguments
32
- * 4/ The function body is evaluated in the context of the function scope
33
- * 5/ The context is swapped back to the current scope
34
- * 6/ The result of the function body is returned
35
- *
36
- */
37
- /**
38
- * From an expression, return a predicate function, which can be used to filter.
39
- */
40
- export declare function predicate(_expr: BoxedExpression): (...args: BoxedExpression[]) => boolean;
41
- /**
42
- * From an expression, create an ordering function, which can be used to sort.
43
- */
44
- export declare function order(_expr: BoxedExpression): (a: BoxedExpression, b: BoxedExpression) => -1 | 0 | 1;
45
- /**
46
- * Given an expression, rewrite it to a symbol or canonical Function form.
47
- *
48
- * - symbol (no change):
49
- * "Sin"
50
- * -> "Sin"
51
- *
52
- * - built-in function:
53
- * ["BuiltinFunction", "Sin"]
54
- * -> "Sin"
55
- *
56
- * - parenthesized expression:
57
- * ["Delimiter", ["Add", "_", 1], "'()'"]
58
- * -> ["Function", ["Block", ["Add", "_", 1]], "_"]
59
- *
60
- * - explicit parameters (adding a block to serve as a scope for the arguments):
61
- * ["Function", ["Add", "x", 1], "x"]
62
- * -> ["Function", ["Block", ["Add", "x", 1]], "x"]
63
- *
64
- *
65
- * - single anonymous parameters:
66
- * ["Add", "_", 1]
67
- * -> ["Function", ["Block", ["Add", "_", 1]], "_"]
68
- *
69
- * - multiple anonymous parameters:
70
- * ["Add", "_1", "_2"]
71
- * -> ["Function", ["Block", ["Add", "_1", "_2"]], "_1", "_2"]
72
- *
73
- *
74
- */
75
- export declare function canonicalFunctionLiteral(expr: BoxedExpression | undefined): BoxedExpression | undefined;
76
- /** Assuming that ops has the following form:
77
- * - body
78
- * - ...params
79
- * return a canonical function literal (["Function", body, ...params]) where
80
- * body is potentially wrapped in a Block expression and the arguments are
81
- * declared in the scope of the body.
82
- */
83
- export declare function canonicalFunctionLiteralArguments(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression | undefined;
84
- /**
85
- * Apply arguments to an expression which is either:
86
- * - a `["Function"]` expression
87
- * - the symbol for a function, e.g. `Sin`.
88
- */
89
- export declare function apply(fn: BoxedExpression, args: ReadonlyArray<BoxedExpression>): BoxedExpression;
90
- /**
91
- * Return a lambda function, assuming a scoped environment has been
92
- * created and there is a single numeric argument
93
- */
94
- export declare function makeLambdaN1(expr: BoxedExpression): ((arg: number) => number) | undefined;
95
- /**
96
- * Given an expression such as:
97
- * - ["Function", ["Add", 1, "x"], "x"]
98
- * - ["Function", ["Divide", "_", 2]]
99
- * - ["Multiply, "_", 3]
100
- * - ["Add, "_1", "_2"]
101
- * - "Sin"
102
- *
103
- * return a JS function that can be called with arguments.
104
- */
105
- export declare function applicable(fn: BoxedExpression): (xs: ReadonlyArray<BoxedExpression>) => BoxedExpression | undefined;
106
- /**
107
- * Use `applicableN1()` when the function is known to be a function with a
108
- * single real argument that returns a real value.
109
- *
110
- * Unlike `apply()`, `applicableN1()` returns a function that can be called
111
- * with an argument.
112
- *
113
- */
114
- export declare function applicableN1(fn: BoxedExpression): (x: number) => number;
115
- /**
116
- * Given a string like "f(x,y)" return, ["f", ["x", "y"]]
117
- */
118
- export declare function parseFunctionSignature(s: string): [id: string, args: string[] | undefined];
119
- /** Lookup a definition matching a symbol in a lexical scope chain */
120
- export declare function lookup(id: MathJsonSymbol, scope: Scope): undefined | BoxedDefinition;