Skip to content

Commit 117cfdf

Browse files
committed
doc
1 parent d0bad6c commit 117cfdf

File tree

1 file changed

+84
-31
lines changed

1 file changed

+84
-31
lines changed

src/api.md

+84-31
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ as per the floating point format standard IEEE-754.
321321
Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
322322
number).
323323

324+
If this expression is a symbol, this lookup also causes binding to a definition.
325+
324326
</MemberCard>
325327

326328
<a id="boxedexpression_isinfinity" name="boxedexpression_isinfinity"></a>
@@ -333,7 +335,9 @@ number).
333335
readonly isInfinity: boolean;
334336
```
335337

336-
The numeric value of this expression is `±Infinity` or Complex Infinity
338+
The numeric value of this expression is `±Infinity` or ComplexInfinity.
339+
340+
If this is a symbol, causes it to be bound to a definition.
337341

338342
</MemberCard>
339343

@@ -347,7 +351,7 @@ The numeric value of this expression is `±Infinity` or Complex Infinity
347351
readonly isFinite: boolean;
348352
```
349353

350-
This expression is a number, but not `±Infinity`, 'ComplexInfinity` or
354+
This expression is a number, but not `±Infinity`, `ComplexInfinity` or
351355
`NaN`
352356

353357
</MemberCard>
@@ -526,6 +530,9 @@ If a symbol, this does take assumptions into account, that is `this.sgn`
526530
will return `positive` if the symbol is assumed to be positive
527531
(using `ce.assume()`).
528532

533+
For a symbol also, requires that the symbol be bound with its definition (i.e. canonical);
534+
otherwise, will return `undefined`.
535+
529536
</MemberCard>
530537

531538
<a id="boxedexpression_ispositive" name="boxedexpression_ispositive"></a>
@@ -895,7 +902,7 @@ If false, the value of the expression may change, if the
895902
value of other expression changes or for other reasons.
896903
897904
If `this.isPure` is `false`, `this.value` is undefined. Call
898-
`this.evaluate()` to determine the value of the expression instead.
905+
`this.evaluate()` (or '*this.N()*') to determine the value of the expression instead.
899906
900907
As an example, the `Random` function is not pure.
901908
@@ -915,15 +922,18 @@ Applicable to canonical and non-canonical expressions.
915922
readonly isConstant: boolean;
916923
```
917924
918-
True if the the value of the expression does not depend on the value of
919-
any other expression.
925+
`True` if this expression's value remains constant.
926+
927+
If *true* and a function, implies that it is *pure*, and also that all of its arguments are
928+
constant.
920929
921-
For example, a number literal, a symbol with a constant value.
930+
Number literals, symbols with constant values, and numeric functions with constant
931+
subexpressions may all be considered *constant*, i.e.:
922932
- `2` is constant
923933
- `Pi` is constant
924934
- `["Add", "Pi", 2]` is constant
925-
- `x` is not constant
926-
- `["Add", "x", 2]` is not constant
935+
- `x` is inconstant: unless declared with a constant value.
936+
- `["Add", "x", 2]` is either constant or inconstant, depending on whether `x` is constant.
927937
928938
</MemberCard>
929939
@@ -1494,7 +1504,8 @@ For symbols and functions, a definition associated with the
14941504
definition.
14951505
14961506
:::info[Note]
1497-
`undefined` if not a canonical expression.
1507+
For a symbol, always binds - potentially creating - a definition. For `BoxedFunctions`, will
1508+
return `undefined` if not canonical.
14981509
:::
14991510
15001511
</MemberCard>
@@ -1529,6 +1540,8 @@ readonly symbolDefinition: BoxedSymbolDefinition;
15291540
15301541
For symbols, a definition associated with the expression.
15311542
1543+
Bind the expression to a definition, if not already bound.
1544+
15321545
Return `undefined` if not a symbol
15331546
15341547
</MemberCard>
@@ -1770,14 +1783,21 @@ Return a JavaScript primitive representing the value of this expression.
17701783
17711784
Equivalent to `expr.N().valueOf()`.
17721785
1773-
Only the value of variables can be changed (symbols that are not
1774-
constants).
1786+
For functions, will only return non-undefined (i.e., compute the value) if the function is pure.
17751787
1776-
Throws a runtime error if a constant.
1788+
For symbols, the current behaviour also considers *non-constant* values, including those weakly
1789+
assigned via symbol assumptions.
17771790
1778-
:::info[Note]
1779-
If non-canonical, does nothing
1780-
:::
1791+
**note**: this property is not guaranteed to remain constant, potentially differing across
1792+
subsequent calls if a symbol (non-constant), or an *inconstant* pure function.
1793+
1794+
Set the value of this expression (applicable only to `BoxedSymbol`).
1795+
1796+
Will throw a runtime error if either not a BoxedSymbol, or if a symbol expression which is
1797+
non-variable/constant.
1798+
1799+
Setting the value of a symbol results in the forgetting of all assumptions about it in the
1800+
current scope.
17811801
17821802
</MemberCard>
17831803
@@ -1815,6 +1835,7 @@ If a symbol the type of the value of the symbol.
18151835
If not valid, return `"error"`.
18161836
If non-canonical, return `undefined`.
18171837
If the type is not known, return `"unknown"`.
1838+
If a symbol with a 'function' definition, returns the 'signature' type.
18181839
:::
18191840
18201841
</MemberCard>
@@ -1829,7 +1850,10 @@ If the type is not known, return `"unknown"`.
18291850
isCollection: boolean;
18301851
```
18311852
1832-
Return true if the expression is a collection: a list, a vector, a matrix, a map, a tuple, etc...
1853+
Return true if the expression is a collection: a list, a vector, a matrix, a map, a tuple,
1854+
etc...
1855+
1856+
For symbols, this check involves binding to a definition, if not already canonical.
18331857
18341858
</MemberCard>
18351859
@@ -2571,7 +2595,8 @@ it was provided.
25712595
25722596
- `InvisibleOperator`: replace use of the `InvisibleOperator` with
25732597
another operation, such as multiplication (i.e. `2x` or function
2574-
application (`f(x)`).
2598+
application (`f(x)`). Also replaces ['InvisibleOperator', real, imaginary] instances with
2599+
complex (imaginary) numbers.
25752600
- `Number`: replace all numeric values with their
25762601
canonical representation, for example, reduce
25772602
rationals and replace complex numbers with no imaginary part with a real number.
@@ -2783,6 +2808,8 @@ type Rule =
27832808
| RuleConditionFunction;
27842809
useVariations: boolean;
27852810
id: string;
2811+
onBeforeMatch: (rule, expr) => void;
2812+
onMatch: (rule, expr, replace) => void;
27862813
};
27872814
```
27882815
@@ -2838,6 +2865,8 @@ type BoxedRule = {
28382865
condition: undefined | RuleConditionFunction;
28392866
useVariations: boolean;
28402867
id: string;
2868+
onBeforeMatch: (rule, expr) => void;
2869+
onMatch: (rule, expr, replace) => void;
28412870
};
28422871
```
28432872

@@ -3140,7 +3169,8 @@ optional value:
31403169
```ts
31413170
type FunctionDefinition = BaseDefinition & Partial<FunctionDefinitionFlags> & {
31423171
signature: | Type
3143-
| TypeString;
3172+
| TypeString
3173+
| BoxedType;
31443174
type: (ops, options) =>
31453175
| Type
31463176
| TypeString
@@ -3168,7 +3198,8 @@ Definition record for a function.
31683198
```ts
31693199
optional signature:
31703200
| Type
3171-
| TypeString;
3201+
| TypeString
3202+
| BoxedType;
31723203
```
31733204
31743205
The function signature.
@@ -4303,35 +4334,57 @@ This indicates a condition under which parsing should stop:
43034334

43044335
</MemberCard>
43054336

4306-
<a id="expressionparsehandler" name="expressionparsehandler"></a>
4337+
<a id="parsehandler" name="parsehandler"></a>
43074338

43084339
<MemberCard>
43094340

4310-
### ExpressionParseHandler()
4341+
### ParseHandler
43114342

43124343
```ts
4313-
type ExpressionParseHandler = (parser, until?) => Expression | null;
4344+
type ParseHandler =
4345+
| ExpressionParseHandler
4346+
| SymbolParseHandler
4347+
| FunctionParseHandler
4348+
| EnvironmentParseHandler
4349+
| PostfixParseHandler
4350+
| InfixParseHandler
4351+
| MatchfixParseHandler;
43144352
```
43154353

4316-
Custom parsing handler.
4354+
**Custom parsing handler.**
43174355

4318-
When invoked the parser points right after the LaTeX fragment that triggered
4319-
this parsing handler.
4356+
When this handler is invoked the parser points right after the LaTeX
4357+
fragment that triggered it.
43204358

4321-
The parser should be moved, by calling `parser.nextToken()` for
4322-
every consumed token.
4359+
Tokens can be consumed with `parser.nextToken()` and other parser methods
4360+
such as `parser.parseGroup()`, `parser.parseOptionalGroup()`, etc...
43234361

43244362
If it was in an infix or postfix context, `lhs` will represent the
43254363
left-hand side argument. In a prefix or matchfix context, `lhs` is `null`.
43264364

4327-
In a superfix (^) or subfix (_) context (that is if the first token of the
4328-
trigger is `^` or `_`), lhs is `["Superscript", lhs, rhs]`
4365+
In a superfix (`^`) or subfix (`_`) context (that is if the first token of
4366+
the trigger is `^` or `_`), `lhs` is `["Superscript", lhs, rhs]`
43294367
and `["Subscript", lhs, rhs]`, respectively.
43304368

4331-
The handler should return `null` if the expression could not be parsed
4332-
(didn't match the syntax that was expected). The matching expression
4369+
The handler should return `null` if the tokens could not be parsed
4370+
(didn't match the syntax that was expected), or the matching expression
43334371
otherwise.
43344372

4373+
If the tokens were parsed but should be ignored, the handler should
4374+
return `Nothing`.
4375+
4376+
</MemberCard>
4377+
4378+
<a id="expressionparsehandler" name="expressionparsehandler"></a>
4379+
4380+
<MemberCard>
4381+
4382+
### ExpressionParseHandler()
4383+
4384+
```ts
4385+
type ExpressionParseHandler = (parser, until?) => Expression | null;
4386+
```
4387+
43354388
</MemberCard>
43364389

43374390
<a id="prefixparsehandler" name="prefixparsehandler"></a>

0 commit comments

Comments
 (0)