ReferencematchesPattern

<matchesPattern>

Boolean condition that tests whether input matches a math pattern

<matchesPattern> is an Evaluation component that returns the boolean value of true or false depending on whether the enclosed math (often a referenced <mathInput/>) conforms to the specified pattern template.

Attributes and Properties

Attributes for <matchesPattern>

Other (19)
allowedErrorInNumbers

number. Default value: 0. Maximum allowed numeric error when comparing numbers.

allowedErrorIsAbsolute

boolean. Default value: false. Whether allowedErrorInNumbers is interpreted as an absolute (rather than relative) tolerance.

allowImplicitIdentities

boolean. Default value: false. Whether to allow implicit identity transformations when matching.

allowPermutations

boolean. Default value: true. Whether to allow permutations of operands when matching.

caseInsensitiveMatch

boolean. Default value: false. Whether text comparisons ignore letter case.

excludeMatches

mathList. Patterns whose matches are excluded.

expandOnCompare

boolean. Default value: false. Whether to expand math expressions before comparing.

includeErrorInNumberExponents

boolean. Default value: false. Whether the allowed numeric error also applies to numbers in exponents.

matchBlanks

boolean. Default value: false. Whether unfilled blanks in a math expression count as a match.

matchByExactPositions

boolean. Default value: false. Whether to match list values by exact position rather than by content.

matchExpressionWithBlanks

boolean. Default value: false. Whether to allow expressions with blanks to match.

numPeriodicSetMatchesRequired

integer. Default value: 3. Number of consecutive elements of a periodic set required to count as a match.

numSignErrorsMatched

number. Default value: 0. Maximum number of sign errors that still count as a match.

pattern

math. Math expression pattern to match against.

requireNumericMatches

boolean. Default value: false. Whether numeric placeholders must match numbers.

requireVariableMatches

boolean. Default value: false. Whether variable placeholders must match variables.

simplifyOnCompare

keyword. Level of simplification applied to math expressions before comparing.

ValueDescription
none (default)No simplification is applied before comparing.
fullFully simplify both expressions before comparing.
numbersSimplify numeric subexpressions only, leaving symbolic structure intact.
numbersPreserveOrderLike numbers, but does not reorder commutative operands.
normalizeOrderReorder commutative operands into a canonical form without simplifying values.
symbolicEquality

boolean. Default value: false. Whether children compared via this boolean use symbolic equality.

unorderedCompare

boolean. Default value: false. Whether order is ignored when comparing list-like values.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <matchesPattern name="m">

Other (26)
$m.allowedErrorInNumbers

number. Maximum allowed numeric error when comparing numbers.

$m.allowedErrorIsAbsolute

boolean. Whether allowedErrorInNumbers is interpreted as an absolute (rather than relative) tolerance.

$m.allowImplicitIdentities

boolean. Whether to allow implicit identity transformations when matching.

$m.allowPermutations

boolean. Whether to allow permutations of operands when matching.

$m.caseInsensitiveMatch

boolean. Whether text comparisons ignore letter case.

$m.disabled

boolean. Whether this component is disabled and cannot be interacted with.

$m.excludeMatches

mathList. Patterns whose matches are excluded.

$m.expandOnCompare

boolean. Whether to expand math expressions before comparing.

$m.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$m.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$m.hidden

boolean. Whether this component is hidden from the rendered output.

$m.includeErrorInNumberExponents

boolean. Whether the allowed numeric error also applies to numbers in exponents.

$m.matchBlanks

boolean. Whether unfilled blanks in a math expression count as a match.

$m.matchByExactPositions

boolean. Whether to match list values by exact position rather than by content.

$m.matchExpressionWithBlanks

boolean. Whether to allow expressions with blanks to match.

$m.numMatches

number. The number of matches found.

$m.numPeriodicSetMatchesRequired

integer. Number of consecutive elements of a periodic set required to count as a match.

$m.numSignErrorsMatched

number. Maximum number of sign errors that still count as a match.

$m.patternMatches

[ math ]. The list of matched sub-expressions.

$m.requireNumericMatches

boolean. Whether numeric placeholders must match numbers.

$m.requireVariableMatches

boolean. Whether variable placeholders must match variables.

$m.simplifyOnCompare

text. Level of simplification applied to math expressions before comparing.

$m.symbolicEquality

boolean. Whether children compared via this boolean use symbolic equality.

$m.text

text. The boolean rendered as a text string ("true" or "false").

$m.unorderedCompare

boolean. Whether order is ignored when comparing list-like values.

$m.value

boolean. Whether the input matches the pattern.

Common to all components (4)
$m.doenetML

text. The DoenetML source code that produced this component.

$m.hide

boolean. Whether to hide this component from the rendered output.

$m.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$m.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: Default case

The <matchesPattern> component is used to check that the user has supplied an equation in the requested format. The pattern attribute is required. If used without additional attributes as shown above, a rather liberal comparison occurs.

  • there must be two operands on one side, and none on the other
  • one side must contain only yy (RHS or LHS are acceptable)
  • the operands may be + or -

These requirements may be tightened, if desired, by applying additional attributes to <matchesPattern>.

Example: Match a specific form of linear equation

In this example, the following conditions must be met:

  • a yy by itself on one side, and an xx on the other, and no other variables can be present
  • the xx value must have a numerical coefficient, or no coefficient
  • switching the order of terms on the right-hand side is acceptable

The attribute requireNumericMatches ensures that the user only enters numerical coefficients into the ( ) spaces (rather than an x, for example.). Multiple <award> conditions are used to ensure that the case where xx does not have a coefficient are allowed.