|
| 1 | +/* 0.53.2 */import { Domain } from './domains'; |
| 2 | +export declare type FunctionDefinition = { |
| 3 | + /** |
| 4 | + * A short string indicating an entry in a wikibase. For example |
| 5 | + * `"Q167"` is the [wikidata entry](https://www.wikidata.org/wiki/Q167) |
| 6 | + * for the Pi constant. |
| 7 | + */ |
| 8 | + wikidata?: string; |
| 9 | + /** The domain of the result */ |
| 10 | + domain?: Domain; |
| 11 | + /** If true, the function will be automatically mapped to a list argument */ |
| 12 | + isListable?: boolean; |
| 13 | + /** If true, [f, [f, a], b] is equivalent to [f, a, b] */ |
| 14 | + isAssociative?: boolean; |
| 15 | + /** If true, [f, a, b] is equivalent to [f, b, a] */ |
| 16 | + isCommutative?: boolean; |
| 17 | + /** If true, [f, [f, a]] is equivalent to [f, a] */ |
| 18 | + isIdempotent?: boolean; |
| 19 | + /** If true, invoking the function wiht a given set of arguments will |
| 20 | + * always return the same value, i.e. 'sin()' is pure, 'random()' isn't. |
| 21 | + * This is used to cache the result of the function. |
| 22 | + */ |
| 23 | + isPure?: boolean; |
| 24 | + /** |
| 25 | + * - **'all'**: The arguments will not be evaluated and will be passed as is |
| 26 | + * - **'none'**: eval() is invoked for each argument. |
| 27 | + * The function will be passed the result of the evaluation |
| 28 | + * - **'first'**: The first argument is not evaluated, the others are |
| 29 | + * - **'rest'**: The first argument is evaluated, the others aren't |
| 30 | + */ |
| 31 | + hold?: 'none' | 'all' | 'first' | 'rest'; |
| 32 | + /** |
| 33 | + * Number of arguments, or minimum or minimum and maximum number of arguments. |
| 34 | + * |
| 35 | + * These are the arguments in the expr representation (i.e. ["f", 1, 2]) |
| 36 | + * and if `requiredLatexArg` is 0 (or undefined), these are also the expected |
| 37 | + * arguments in the latex stream, i.e. "f(1, 2)". |
| 38 | + * |
| 39 | + */ |
| 40 | + argCount?: number | [number] | [number, number]; |
| 41 | + argDomain?: Domain[]; |
| 42 | +}; |
| 43 | +export declare type SymbolDefinition = { |
| 44 | + /** |
| 45 | + * If true the value of the symbol is constant |
| 46 | + * If false, the symbol is a variable |
| 47 | + */ |
| 48 | + isConstant: boolean; |
| 49 | + /** |
| 50 | + * A short string indicating an entry in a wikibase. For example |
| 51 | + * `"Q167"` is the [wikidata entry](https://www.wikidata.org/wiki/Q167) |
| 52 | + * for the Pi constant. |
| 53 | + */ |
| 54 | + wikidata?: string; |
| 55 | + domain?: Domain; |
| 56 | + value?: Expression; |
| 57 | + unit?: Expression; |
| 58 | +}; |
| 59 | +/** |
| 60 | + * A dictionary maps a MathJSON name to a defition. |
| 61 | + * |
| 62 | + * A name can be a symbol name, as in the expression `"pi"`, |
| 63 | + * or the name of a function: "add" in the expression `["add", 2, 3]`. |
| 64 | + * |
| 65 | + * The name can be an arbitrary string of Unicode characters, however |
| 66 | + * the following conventions are recommended: |
| 67 | + * |
| 68 | + * - Use only letters, digits and `-`, and the first character should be |
| 69 | + * a letter: `/^[a-zA-Z][a-zA-Z0-9-]* /` |
| 70 | + * - Functions and symbols should start with a lowercase letter |
| 71 | + * - During parsing, camel-case names are converted to kebab-case, so that |
| 72 | + * `"polynomialFactor"` becomes `"polynomial-factor"` |
| 73 | + * |
| 74 | + */ |
| 75 | +export declare type Dictionary = { |
| 76 | + [name: string]: SymbolDefinition | FunctionDefinition; |
| 77 | +}; |
| 78 | +/** |
| 79 | + * * `unknown-symbol`: a symbol was encountered which does not have a |
| 80 | + * definition. |
| 81 | + * |
| 82 | + * * `unknown-operator`: a presumed operator was encountered which does not |
| 83 | + * have a definition. |
| 84 | + * |
| 85 | + * * `unknown-function`: a latex command was encountered which does not |
| 86 | + * have a definition. |
| 87 | + * |
| 88 | + * * `unbalanced-braces`: some latex braces (`{`, `}`) were not balanced |
| 89 | + * |
| 90 | + * * `unexpected-superscript`: a superscript was encountered in an unexpected |
| 91 | + * context, or no `powerFunction` was defined. By default, superscript can |
| 92 | + * be applied to numbers, symbols or expressions, but not to operators (e.g. |
| 93 | + * `2+^34`) or to punctuation. |
| 94 | + * |
| 95 | + * * `unexpected-subscript`: a subscript was encountered in an unexpected |
| 96 | + * context or no 'subscriptFunction` was defined. By default, subscripts |
| 97 | + * are not expected on numbers, operators or symbols. Some commands (e.g. `\sum`) |
| 98 | + * do expected a subscript. |
| 99 | + * |
| 100 | + * * `unexpected-sequence`: some adjacents elements were encountered ( for |
| 101 | + * example `xy`), but no `invisibleOperator` is defined, therefore the elements |
| 102 | + * can't be combined. The default `invisibleOperator` is `multiply`, but you |
| 103 | + * can also use `list`. |
| 104 | + * |
| 105 | + * * `expected-argument`: a Latex command that requires one or more argument |
| 106 | + * was encountered without the required arguments. |
| 107 | + * |
| 108 | + * * `expected-operand`: an operator was encountered without its required |
| 109 | + * operands. |
| 110 | + * |
| 111 | + * * `non-associative-operator`: an operator which is not associative was |
| 112 | + * encountered in an associative context, for example: 'a < b < c' (assuming |
| 113 | + * `<` is defined as non-associative) |
| 114 | + * |
| 115 | + * * `postfix-operator-requires-one-argument`: a postfix operator which requires |
| 116 | + * a single argument was encountered with no arguments or more than one argument |
| 117 | + * |
| 118 | + * * `prefix-operator-requires-one-argument`: a prefix operator which requires |
| 119 | + * a single argument was encountered with no arguments or more than one argument |
| 120 | + * |
| 121 | + */ |
| 122 | +export declare type ErrorCode = 'expected-argument' | 'unexpected-argument' | 'expected-operator' | 'expected-operand' | 'invalid-name' | 'unknown-symbol' | 'unknown-operator' | 'unknown-function' | 'unknown-command' | 'unbalanced-braces' | 'unbalanced-matchfix-operator' | 'unexpected-superscript' | 'unexpected-subscript' | 'unexpected-sequence' | 'non-associative-operator' | 'function-has-too-many-arguments' | 'function-has-too-few-arguments' | 'operator-requires-one-operand' | 'infix-operator-requires-two-operands' | 'prefix-operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'associative-function-has-too-few-arguments' | 'commutative-function-has-too-few-arguments' | 'listable-function-has-too-few-arguments' | 'hold-first-function-has-too-few-arguments' | 'hold-rest-function-has-too-few-arguments' | 'syntax-error'; |
| 123 | +export declare type Attributes = { |
| 124 | + /** A human readable string to annotate an expression, since JSON does not |
| 125 | + * allow comments in its encoding */ |
| 126 | + comment?: string; |
| 127 | + /** A human readable string that can be used to indicate a syntax error or |
| 128 | + *other problem when parsing or evaluating an expression. |
| 129 | + */ |
| 130 | + error?: string; |
| 131 | + /** A visual representation in LaTeX of the expression. This can be useful |
| 132 | + to preserve non-semantic details, for example parentheses in an expression |
| 133 | + or styling attributes */ |
| 134 | + latex?: string; |
| 135 | + /** |
| 136 | + * A short string indicating an entry in a wikibase. For example |
| 137 | + * `"Q167"` is the [wikidata entry](https://www.wikidata.org/wiki/Q167) |
| 138 | + * for the Pi constant. |
| 139 | + */ |
| 140 | + wikidata?: string; |
| 141 | + /** A base URL for the `wikidata` key. A full URL can be produced by |
| 142 | + concatenating this key with the `wikidata` key. This key applies to this |
| 143 | + node and all its children. The default value is |
| 144 | + "https://www.wikidata.org/wiki/" |
| 145 | + */ |
| 146 | + wikibase?: string; |
| 147 | + /** A short string indicating an entry in an OpenMath Content |
| 148 | + Dictionary. For example: `arith1/#abs`. */ |
| 149 | + openmathSymbol?: string; |
| 150 | + /** A base URL for an OpenMath content dictionary. This key applies to this |
| 151 | + node and all its children. The default value is |
| 152 | + "http://www.openmath.org/cd". |
| 153 | + */ |
| 154 | + openmathCd?: string; |
| 155 | +}; |
| 156 | +export declare type MathJsonBasicNumber = 'NaN' | '-Infinity' | '+Infinity' | string; |
| 157 | +export declare type MathJsonRealNumber = { |
| 158 | + num: MathJsonBasicNumber; |
| 159 | +} & Attributes; |
| 160 | +export declare type MathJsonSymbol = { |
| 161 | + sym: string; |
| 162 | +} & Attributes; |
| 163 | +export declare type MathJsonFunction = { |
| 164 | + fn: Expression[]; |
| 165 | +} & Attributes; |
| 166 | +export declare type Expression = MathJsonRealNumber | number | MathJsonSymbol | string | MathJsonFunction | (Expression | string | null)[]; |
| 167 | +/** |
| 168 | + * A given mathematical expression can be represented in multiple equivalent |
| 169 | + * ways as a MathJSON expression. `Form` is used to specify a |
| 170 | + * representation: |
| 171 | + * - **`'full'`**: only transformations applied are those necessary to make it |
| 172 | + * valid JSON (for example making sure that `Infinity` and `NaN` are |
| 173 | + * represented as strings) |
| 174 | + * - **`'flatten-associative'`**: associative functions are combined, e.g. |
| 175 | + * f(f(a, b), c) -> f(a, b, c) |
| 176 | + * - **`'sorted'`**: the arguments of commutative functions are sorted such that: |
| 177 | + * - numbers are first, sorted numerically |
| 178 | + * - complex numbers are next, sorted numerically by imaginary value |
| 179 | + * - symbols are next, sorted lexicographically |
| 180 | + * - `add` functions are next |
| 181 | + * - `multiply` functions are next |
| 182 | + * - `power` functions are next, sorted by their first argument, |
| 183 | + * then by their second argument |
| 184 | + * - other functions follow, sorted lexicographically |
| 185 | + * - **`'stripped-metadata'`**: any metadata associated with elements of the |
| 186 | + * expression is removed. |
| 187 | + * - *`'canonical-add'`**: `addition of 0 is simplified, associativity rules |
| 188 | + * are applied, unnecessary groups are moved, single argument 'add' are simplified |
| 189 | + * - *`'canonical-divide'`**: `divide` is replaced with `multiply` and `power', |
| 190 | + * division by 1 is simplified, |
| 191 | + * - *`'canonical-exp'`**: `exp` is replaced with `power` |
| 192 | + * - *`'canonical-multiply'`**: multiplication by 1 or -1 is simplified |
| 193 | + * - *`'canonical-power'`**: `power` with a first or second argument of 1 is |
| 194 | + * simplified |
| 195 | + * - *`'canonical-negate'`**: real or complex number is replaced by the |
| 196 | + * negative of that number. Negation of negation is simplified. |
| 197 | + * - *`'canonical-number'`**: complex numbers with no imaginary compnents are |
| 198 | + * simplified |
| 199 | + * - *`'canonical-root'`**: `root` is replaced with `power` |
| 200 | + * - *`'canonical-subtract'`**: `subtract` is replaced with `add` and `negate` |
| 201 | + * - **`'canonical'`**: the following transformations are performed, in this order: |
| 202 | + * - 'canonical-number', // -> simplify number |
| 203 | + * - 'canonical-exp', // -> power |
| 204 | + * - 'canonical-root', // -> power, divide |
| 205 | + * - 'canonical-subtract', // -> add, negate, multiply, |
| 206 | + * - 'canonical-divide', // -> multiply, power |
| 207 | + * - 'canonical-power', // simplify power |
| 208 | + * - 'canonical-multiply', // -> multiply, power |
| 209 | + * - 'canonical-negate', // simplify negate |
| 210 | + * - 'canonical-add', // simplify add |
| 211 | + * - 'flatten', // simplify associative, idempotent and groups |
| 212 | + * - 'sorted', |
| 213 | + * - 'full', |
| 214 | + */ |
| 215 | +export declare type Form = 'canonical' | 'canonical-add' | 'canonical-divide' | 'canonical-exp' | 'canonical-list' | 'canonical-multiply' | 'canonical-power' | 'canonical-negate' | 'canonical-number' | 'canonical-root' | 'canonical-subtract' | 'flatten' | 'full' | 'sorted' | 'stripped-metadata' | 'sum-product'; |
| 216 | +export declare type DictionaryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'complex' | 'combinatorics' | 'dimensions' | 'intervals' | 'linear-algebra' | 'lists' | 'logic' | 'numeric' | 'quantifiers' | 'physics' | 'polynomials' | 'relations' | 'sets' | 'statistics' | 'core' | 'transcendentals' | 'trigonometry' | 'rounding' | 'units'; |
| 217 | +/** |
| 218 | + * Return a dictionary suitable for the specified category, or `"all"` |
| 219 | + * for all categories (`"arithmetic"`, `"algebra"`, etc...). |
| 220 | + * |
| 221 | + * The dictionary defines how the symbols and function names in a MathJSON |
| 222 | + * expression should be interpreted, i.e. how to evaluate and manipulate them. |
| 223 | + * |
| 224 | + */ |
| 225 | +export declare function getDefaultDictionary(domain: DictionaryCategory | 'all'): Dictionary; |
|
0 commit comments