Members
(static) displayFlags
Flags used to control the behaviour of JME display functions.
Values are undefined
so they can be overridden.
(static) extend_options
Override or extend a matchTree options object with new values.
(static) getTerms
Given a tree representing a series of terms t1
(static) number_conditions :function
Conditions for the $n
rule.
Type:
Properties:
Name | Type | Description |
---|---|---|
complex |
function | |
imaginary |
function | |
real |
function | |
positive |
function | |
nonnegative |
function | |
negative |
function | |
integer |
function | |
decimal |
function | |
rational |
function | |
nonzero |
function | |
nonone |
function |
(static) patternParser
A parser for JME patterns. Adds pattern-matching operators to the standard parser.
(static) simplificationRules :Array.<Numbas.jme.rules.Rule>
Built-in simplification rules.
Type:
Properties:
Name | Type | Description |
---|---|---|
basic |
Array.<Numbas.jme.rules.Rule> | |
collectComplex |
Array.<Numbas.jme.rules.Rule> | |
unitFactor |
Array.<Numbas.jme.rules.Rule> | |
unitPower |
Array.<Numbas.jme.rules.Rule> | |
unitDenominator |
Array.<Numbas.jme.rules.Rule> | |
zeroFactor |
Array.<Numbas.jme.rules.Rule> | |
zeroTerm |
Array.<Numbas.jme.rules.Rule> | |
zeroPower |
Array.<Numbas.jme.rules.Rule> | |
powerPower |
Array.<Numbas.jme.rules.Rule> | |
noLeadingMinus |
Array.<Numbas.jme.rules.Rule> | |
collectNumbers |
Array.<Numbas.jme.rules.Rule> | |
simplifyFractions |
Array.<Numbas.jme.rules.Rule> | |
zeroBase |
Array.<Numbas.jme.rules.Rule> | |
constantsFirst |
Array.<Numbas.jme.rules.Rule> | |
sqrtProduct |
Array.<Numbas.jme.rules.Rule> | |
sqrtDivision |
Array.<Numbas.jme.rules.Rule> | |
sqrtSquare |
Array.<Numbas.jme.rules.Rule> | |
trig |
Array.<Numbas.jme.rules.Rule> | |
otherNumbers |
Array.<Numbas.jme.rules.Rule> | |
cancelTerms |
Array.<Numbas.jme.rules.Rule> | |
cancelFactors |
Array.<Numbas.jme.rules.Rule> | |
collectLikeFractions |
Array.<Numbas.jme.rules.Rule> |
(static) specialMatchFunctions :function
Special JME functions used in pattern-matching.
Type:
Properties:
Name | Type | Description |
---|---|---|
m_uses |
function | |
m_exactly |
function | |
m_commutative |
function | |
m_noncommutative |
function | |
m_associative |
function | |
m_nonassociative |
function | |
m_strictinverse |
function | |
m_gather |
function | |
m_nogather |
function | |
m_type |
function | |
m_func |
function | |
m_op |
function | |
m_anywhere |
function |
(static) specialMatchNames :function
Special JME names used in pattern-matching.
Type:
Properties:
Name | Type | Description |
---|---|---|
"?" |
function | |
$n |
function | |
$v |
function | |
$z |
function |
Methods
(static) applyPostReplacement(tree, options) → {Numbas.jme.tree}
Apply operations specified in the result of a tree transformation: eval(x)
is replaced with the result of evaluating x
.
Parameters:
Name | Type | Description |
---|---|---|
tree |
Numbas.jme.tree | |
options |
Numbas.jme.rules.matchTree_options |
Returns:
Type | Description |
---|---|
Numbas.jme.tree |
(static) collectRuleset(set, scopeSets) → {Numbas.jme.rules.Ruleset}
Collect a ruleset together from a list of ruleset names, or rulesets.
Parameters:
Name | Type | Description |
---|---|---|
set |
string | Array.<(string|Numbas.jme.rules.Ruleset)> | A comma-separated string of ruleset names, or an array of names/Ruleset objects. |
scopeSets |
Object.<Numbas.jme.rules.Ruleset> | Dictionary of rulesets defined in the current scope. |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.Ruleset |
(static) compileRules(rules, name) → {Numbas.jme.rules.Ruleset}
Compile an array of rules (in the form [pattern,conditions[],result]
to Numbas.jme.rules.Rule
objects.
Parameters:
Name | Type | Description |
---|---|---|
rules |
Array | |
name |
string | a name for this group of rules |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.Ruleset |
(static) findSequenceMatch(pattern, input, options) → {object}
Match a sequence of terms against a given pattern sequence of terms. Try to find an assignment of input terms to the pattern, satisfying the quantifier for each term in the pattern. The match is greedy - input terms will match earlier pattern terms in preference to later ones.
Parameters:
Name | Type | Description |
---|---|---|
pattern |
Array.<Numbas.jme.rules.term> | |
input |
Array.<Numbas.jme.rules.term> | |
options |
Numbas.jme.rules.findSequenceMatch_options |
Returns:
Type | Description |
---|---|
object |
|
(static) matchAllTree(ruleTree, exprTree, options) → {Array.<Numbas.jme.rules.jme_pattern_match>}
Find all matches for the rule, anywhere within the given expression.
Parameters:
Name | Type | Description |
---|---|---|
ruleTree |
Numbas.jme.tree | The pattern to match. |
exprTree |
Numbas.jme.tree | The syntax tree to test. |
options |
Numbas.jme.rules.matchTree_options |
Returns:
Type | Description |
---|---|
Array.<Numbas.jme.rules.jme_pattern_match> |
(static) matchExpression(pattern, expr, options) → {boolean|Numbas.jme.rules.jme_pattern_match}
Match expression against a pattern. Wrapper for Numbas.jme.rules.matchTree
.
Parameters:
Name | Type | Description |
---|---|---|
pattern |
JME | |
expr |
JME | |
options |
Numbas.jme.rules.matchTree_options | Default is |
Returns:
Type | Description |
---|---|
boolean | Numbas.jme.rules.jme_pattern_match |
|
(static) matchTree(ruleTree, exprTree, options) → {boolean|Numbas.jme.rules.jme_pattern_match}
Recursively check whether exprTree
matches ruleTree
. Variables in ruleTree
match any subtree.
Parameters:
Name | Type | Description |
---|---|---|
ruleTree |
Numbas.jme.tree | |
exprTree |
Numbas.jme.tree | |
options |
Numbas.jme.rules.matchTree_options | Options specifying the behaviour of the matching algorithm. |
Returns:
Type | Description |
---|---|
boolean | Numbas.jme.rules.jme_pattern_match |
|
(static) transform(ruleTree, resultTree, exprTree, options) → {Numbas.jme.rules.transform_result}
Replace one expression with another, if it matches the given rule.
Parameters:
Name | Type | Description |
---|---|---|
ruleTree |
Numbas.jme.tree | The rule to test against. |
resultTree |
Numbas.jme.tree | The tree to output, with named groups from the rule substituted in. |
exprTree |
Numbas.jme.tree | The expression to be tested. |
options |
Numbas.jme.rules.matchTree_options | Options for the match. |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.transform_result |
(static) transformAll(ruleTree, resultTree, exprTree, options) → {Numbas.jme.rules.transform_result}
Replace anything matching the rule with the given result, at any position in the given expression.
Parameters:
Name | Type | Description |
---|---|---|
ruleTree |
Numbas.jme.tree | The rule to test against. |
resultTree |
Numbas.jme.tree | The tree to output, with named groups from the rule substituted in. |
exprTree |
Numbas.jme.tree | The expression to be tested. |
options |
Numbas.jme.rules.matchTree_options | Options for the match. |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.transform_result |
Type Definitions
findSequenceMatch_options
Options for Numbas.jme.rules.findSequenceMatch
.
Type:
Properties:
Name | Type | Description |
---|---|---|
allowOtherTerms |
boolean | If |
commutative |
boolean | Can the input terms be considered in any order? |
constraintFn |
function | Function to test if the current set of matches satisfies constraints. |
checkFn |
function | Function to test if an input term matches a given pattern term. |
getTerms_options
Options for Numbas.jme.rules.getTerms
.
Type:
Properties:
Name | Type | Description |
---|---|---|
commutative |
boolean | Should the operator be considered as commutative, for the purposes of matching ops with opposites? If yes, |
associative |
boolean | Should the operator be considered as associative? If yes, |
strictInverse |
boolean | If |
jme_pattern_match
A dictionary representing the results of a successful JME pattern match. Maps variable names to trees.
Type:
- Source:
- See:
-
- {Numbas.jme.rules#matchTree}
matchTree_options
Options for Numbas.jme.rules.matchTree
.
Type:
Properties:
Name | Type | Description |
---|---|---|
commutative |
boolean | Should the commutativity of operations be used? If |
associative |
boolean | Should the associativity of operations be used? If |
allowOtherTerms |
boolean | When matching an associative op, if the expression contains terms that don't match any of the pattern, should they be ignored? If |
strictInverse |
boolean | If |
scope |
Numbas.jme.Scope | A JME scope in which to evaluate conditions. |
ruleset_flags
Flags used in JME simplification rulesets
Type:
Properties:
Name | Type | Description |
---|---|---|
fractionnumbers |
boolean | Show all numbers as fractions? |
rowvector |
boolean | Display vectors as a horizontal list of components? |
alwaystimes |
boolean | Always show the multiplication symbol between multiplicands? |
mixedfractions |
boolean | Show top-heavy fractions as mixed fractions, e.g. 3 3/4? |
flatfractions |
boolean | Display fractions horizontally? |
barematrices |
boolean | Render matrices without wrapping them in parentheses. |
timesdot |
boolean | Use a dot for the multiplication symbol instead of a cross? |
timesspace |
boolean | Use a space for the multiplication symbol instead of a cross? |
noscientificnumbers |
boolean | Numbers are never rendered in scientific notation. |
term
Information to do with a term found in an expression by Numbas.jme.rules.getTerms
.
Type:
Properties:
Name | Type | Description |
---|---|---|
term |
Numbas.jme.tree | |
names |
Array.<string> | Names captured by this term. |
equalnames |
Array.<string> | Identified names captured by this term. |
quantifier |
string | Code describing how many times the term can appear, if it's a pattern term. |
min |
number | The minimum number of times the term must appear. |
max |
number | The maximum number of times the term can appear. |
defaultValue |
Numbas.jme.tree | A value to use if this term is missing. |
transform_result
Object returned by Numbas.jme.rules.transform
.
Type:
Properties:
Name | Type | Description |
---|---|---|
changed |
boolean | Is the result expression different to the input expression? |
expression |
Numbas.jme.tree | The result expression. |