OrderAs
OrderAs
OrderAs[ expr, template ] puts the terms of an expression in the same order as in a template expression.
Usages
OrderAs[ expr, template ]
OrderAs[ expr, template ] reorders the terms (or factors, or list elements) of expr so that terms that also occur in template come in the same order as in template. Terms of expr that do not occur in template are placed where template has its first term that is not in expr. You typically use this when expr is derived from a student's answer (template), so that the result looks familiar to the student.
| Example | in | out |
|---|---|---|
3q and p follow the order of the template; 2b takes the place of 3a. |
OrderAs[ 2b+p+3q, 3q+p+3a ] |
3q+p+2b |
p matches; 3q takes the place of the first unmatched term. |
OrderAs[ p+3q, 3q^2+p+2q ] |
3q+p |
| Factors of a product. | OrderAs[ a*b*c, c*a ] |
c a b |
| Elements of a list. | OrderAs[ {1, 2, 3}, {3, 1} ] |
{3, 1, 2} |
Details
- Different operations: if
exprandtemplateare not the same kind of expression,expris returned unchanged:OrderAs[ a+b, a*b ]givesa+b. - Subtraction: an expression with a minus sign, such as
3q^2+p-2q, is a subtraction, not a sum.OrderAs[ p+3q, 3q^2+p-2q ]therefore returnsp+3qunchanged. - Not an expression with terms:
OrderAs[ 5, 3+5 ]gives5.