Jump to navigation

Namespace: rules

Numbas.jme.rules

Members

(static) displayFlags

Flags used to control the behaviour of JME display functions. Values are undefined so they can be overridden.

Source:

(static) extend_options

Override or extend a matchTree options object with new values.

Source:

(static) getTerms

Given a tree representing a series of terms t1 t2 t3 ..., return the terms as a list.

Source:

(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
Source:

(static) patternParser

A parser for JME patterns. Adds pattern-matching operators to the standard parser.

Source:

(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>
Source:

(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
Source:

(static) specialMatchNames :function

Special JME names used in pattern-matching.

Type:
Properties:
Name Type Description
"?" function
$n function
$v function
$z function
Source:

(static) specialMatchOps :function

Special JME operators used in pattern-matching.

Type:
Properties:
Name Type Description
"`?" function
"`*" function
"`+" function
"`|" function
"`:" function
"`+-" function
"`*/" function
"`!" function
"`&" function
"`where" function
"`@" function
Source:

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
Source:

(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
Source:

(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
Source:

(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
  • ignored_start_terms is terms at the start that weren't used in the match, ignored_end_terms is any other terms that weren't used, and result[i] is a list of indices of terms in the input that were matched against pattern term i.
Source:

(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>
Source:

(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 commutative, associative, and allowOtherTerms all true, and using Numbas.jme.builtinScope.

Returns:
Type Description
boolean | Numbas.jme.rules.jme_pattern_match
  • false if no match, otherwise a dictionary of subtrees matched to variable names.
Source:

(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
  • false if no match, otherwise a dictionary of subtrees matched to variable names.
Source:

(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
Source:

(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
Source:

Type Definitions

findSequenceMatch_options

Type:
Properties:
Name Type Description
allowOtherTerms boolean

If true, terms that don't match any term in the pattern can be ignored.

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.

Source:

getTerms_options

Type:
Properties:
Name Type Description
commutative boolean

Should the operator be considered as commutative, for the purposes of matching ops with opposites? If yes, a>c will produce terms c and a when op='<'.

associative boolean

Should the operator be considered as associative? If yes, (a+b)+c will produce three terms a,b and c. If no, it will produce two terms, (a+b) and c.

strictInverse boolean

If false, a-b will be interpreted as a+(-b) when finding additive terms.

Source:

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

Type:
Properties:
Name Type Description
commutative boolean

Should the commutativity of operations be used? If false, terms must appear in the same order as in the pattern.

associative boolean

Should the associativity of operations be used? If true, all terms in nested applications of associative ops are gathered together before comparing.

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 false, every term in the expression must match a term in the pattern.

strictInverse boolean

If false, a-b will be interpreted as a+(-b) when finding additive terms.

scope Numbas.jme.Scope

A JME scope in which to evaluate conditions.

Source:

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.

Source:
See:

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.

Source:

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.

Source: