match - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

match

pattern matching

 Calling Sequence match(expr = pattern, v, 's') match(expr = pattern, {v1, v2, ..., vN}, 's')

Parameters

 expr - expression of type algebraic to be matched pattern - pattern (also of type algebraic) to match v - name of the main variable 's' - name of the return argument {v1, v2, ..., vN} - names of the main variables

Description

 • The match(expr = pattern, v, 's') calling sequence returns true if it can match expr to pattern for some values of the variables (excluding the main variable, v). Otherwise, it returns false.
 • The match(expr = pattern, {v1, v2, ..., vN}, 's') calling sequence returns true if it can match expr to pattern for some values of the variables (excluding the main variables, {v1, v2, ..., vN}). Otherwise, it returns false.
 Note: In the multiple main variable case, the pattern specified must be a polynomial in all, or all but one of, the main variables. That is, type(pattern, polynom(anything, vI)) must be true for (N - 1) values of I in the range 1, 2, ..., N. Otherwise, the match command returns false.
 • If the match is successful, s is assigned a substitution set such that $\mathrm{subs}\left(s,\mathrm{pattern}\right)=\mathrm{expr}$.
 • The main variables must be matched exactly in the pattern. In other words, the main variables cannot be substituted for any value.
 • The match command attempts to compute expressions to satisfy the pattern, as opposed to the typematch command that matches the form of the objects.

Examples

 > $\mathrm{match}\left(\frac{\mathrm{ln}\left(k\right)}{{k}^{\frac{1}{2}}}=A{\mathrm{ln}\left(k\right)}^{P}{k}^{Q},k,'s'\right)$
 ${\mathrm{true}}$ (1)
 > $s$
 $\left\{{A}{=}{1}{,}{P}{=}{1}{,}{Q}{=}{-}\frac{{1}}{{2}}\right\}$ (2)
 > $\mathrm{match}\left(5{x}^{2}-3x+zx+y=a{\left(x+b\right)}^{2}+c,x,'s'\right)$
 ${\mathrm{true}}$ (3)
 > $s$
 $\left\{{a}{=}{5}{,}{b}{=}\frac{{z}}{{10}}{-}\frac{{3}}{{10}}{,}{c}{=}{-}\frac{{1}}{{20}}{}{{z}}^{{2}}{+}{y}{+}\frac{{3}}{{10}}{}{z}{-}\frac{{9}}{{20}}\right\}$ (4)

In the multiple main variable case, if the pattern is not a polynomial in (all but one of) the main variables, the match command always returns false.

 > $\mathrm{match}\left(\mathrm{sin}\left(x+y\right)=\mathrm{sin}\left(ax+y\right),\left\{x,y\right\},'s'\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{match}\left(5{x}^{2}-3x+zx+y=a{\left(x+b\right)}^{2}+cxz+d,\left\{x,z\right\},'s'\right)$
 ${\mathrm{true}}$ (6)
 > $s$
 $\left\{{a}{=}{5}{,}{b}{=}{-}\frac{{3}}{{10}}{,}{c}{=}{1}{,}{d}{=}{y}{-}\frac{{9}}{{20}}\right\}$ (7)
 > $\mathrm{match}\left(5{x}^{2}-3x+zx+y=a{\left(x+b\right)}^{2}+fx-cxz+dy,\left\{x,y,z\right\},'s'\right)$
 ${\mathrm{true}}$ (8)
 > $s$
 $\left\{{a}{=}{5}{,}{b}{=}{0}{,}{c}{=}{-1}{,}{d}{=}{1}{,}{f}{=}{-3}\right\}$ (9)

The pattern is polynomial in one of the two main variables, and suitable values can be found for all non-main variables in the following example.

 > $\mathrm{match}\left(\mathrm{sin}\left(x\right)+4y=\mathrm{sin}\left(ax\right)+by,\left\{x,y\right\},'s'\right)$
 ${\mathrm{true}}$ (10)
 > $s$
 $\left\{{a}{=}{1}{,}{b}{=}{4}\right\}$ (11)

Take care that the pattern (containing the variables to be matched) appears on the right hand side of the first argument to match.

 > $\mathrm{match}\left(2x+3=ax+b,x,'s'\right)$
 ${\mathrm{true}}$ (12)
 > $\mathrm{match}\left(ax+b=2x+3,x,'s'\right)$
 ${\mathrm{false}}$ (13)

 See Also