Many mathematical expressions include "dummy variables," also called "bound
variables." For example,
- indexed sums, products, unions, and intersections throughout mathematics
- set-builder notation, e.g.,
- existentially and universally quantified expressions, such as
. expressions from computer science, as in
We say that such expressions "bind" the dummy/bound variable, and we have two types of them in Lurch: BindingExpressions and BindingEnvironments. In order to factor the common attributes out of those two classes, we implement the notion of binding as what some languages call an "interface," here. We place it in the BindingInterface namespace, and it can be added to any class by calling the addTo() function.
Each of the example types of expressions given above include not only a body
in which a variable is bound, but also an operator applied to that body. For
example, in
Consequently, when encoding something like
new Application(
new LurchSymbol( '⋃' ),
new BindingExpression(
new LurchSymbol( 'i' ),
new Application(
new LurchSymbol( 'subscript' ),
new LurchSymbol( 'A' ),
new LurchSymbol( 'i' )
)
)
)
Bindings were inspired by a structure of the same name defined in the OpenMath Standard, but the reader is not expected to read that standard; we define in this documentation our version of what a binding is, both for Expressions and Environments.
A binding is defined by a sequence of
- The first
children will be the sequence of bound variables. There must be at least one bound variable, so we have that . Each bound variable must be a Symbol. You can use allAreSymbols() to help verify the requirement. - The last child is called the body(). This is what "sits inside" the binding, such as the integrand in an integral, the summand in a summation, the inner statement in a quantification, etc. Although it is most commonly an Expression, it does not have to be; a binding with an Expression body is a BindingExpression and a binding with an Environment body is a BindingEnvironment. Binding environments are typically subproofs that begin with the declaration of one or more arbitrary variables, which act as bound within that subproof.
The API provided in this namespace can be added to any class by calling the addTo() function on the class's prototype. Then all the functions documented below will be available in members of that class.
Members
addTo
Document function here
Source
allAreSymbols
Document function here
Source
binds
Does this binding bind a specific symbol? You can provide the symbol to this function (in any of the formats documented below) and this function will do a search and return true if it finds such a symbol among this binding's bound symbols, and false if not.
If the parameter is omitted, then this function simply returns the constant true, indicating that it is a binding type of MathConcept, that is, it has the capacity to bind Symbols.
Source
body
As documented at the top of this page, the body of a binding is the last child of the MathConcept, which will either be an Expression or Environment, depending on the type of binding. This function returns that body.
See
Source
boundSymbolNames
This function behaves exactly like boundSymbols(), but instead of returning actual Symbol instances, it returns only their names, as strings, in the same order.
See
Source
boundSymbols
As documented at the top of this page, the bound symbols in a binding are all the children except the last, and they should be all instances of the Symbol class. This function returns those children in an array, in the same order they appear as children of this object. The actual children are returned, not copies, and they are Symbol instances, not just their names as strings.
Just in case the client has manipulated this object since construction time,
thus causing one of its initial children to be something other than a
Symbol, this function filters its return list to include only
instances of the Symbol class. Note that this routine does
not need to provide any guarantees in such a case, because the client has
invalidated its structure as a binding. However, in such a case, for a
MathConcept with