Difference between revisions of "Reduction rules for MathObject Formulas"
m (→The Reduction Rules and their Actions: Fix typo: x^1 = x (used to be x^1=0)) |
|||
(12 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | MathObjects reduces mathematical expressions according to a set of reduction rules. These control which expressions are reduced. |
||
+ | When substituting randomly chosen values into an expression, it is possible to obtain situations like <code>1 x^2 + -3 x + 0</code>, which do not look good when displayed as part of the text shown to a student. To help remedy this situation, the MathObjects library can reduce Formula objects according to a set of reduction rules that try to eliminate such visual problems. The main reduction rules are shown below. |
||
− | <!-- |
||
+ | Sometimes these rules don't improve the look of your formulas, however. In particular, many are designed to try to factor out negatives so that they can be canceled, but this does not always lead to better looking equations when the negatives ''don't'' cancel. For this reason, you can turn off individual reduction rules so that they will be skipped. See the [[Introduction to Contexts#Reduction Rules|Reduction Rules]] section of the [[Introduction to Contexts]] for details on how to control the reduction rules. |
||
− | table body generated with: |
||
− | grep -hr 'Parser::reduce' * | sort | |
||
− | perl -ne "/'(.*?)'/"' and print "| <code>$1</code> || \n|-\n"' |
||
− | --> |
||
− | {|border="1" |
||
+ | You can disable one or more reduction rules using a command like the following examples: |
||
− | ! Rule !! Reduction |
||
+ | |||
− | |- |
||
+ | Context()->noreduce('(-x)-y'); |
||
− | | <code>0><x</code> || <code>0</code> |
||
+ | Context()->noreduce('(-x)-y','(-x)+y'); |
||
− | |- |
||
+ | |||
− | | <code>0-x</code> || <code>-x</code> |
||
+ | It is possible for MathObject extensions to add more reduction rules for the MathObjects they define. See the documentation for the extensions you are using to see if that is the case. |
||
− | |- |
||
+ | |||
− | | <code>0/x</code> || <code>0</code> |
||
+ | === The Reduction Rules and their Actions === |
||
− | |- |
||
+ | |||
− | | <code>0.x</code> || <code>0</code> |
||
+ | {| class="wikitable" |
||
− | |- |
||
+ | ! style="padding:5px" | Rule !! style="padding:5px" | Reduction !! style="padding:5px" | Description |
||
− | | <code>0*x</code> || <code>0</code> |
||
+ | |||
− | |- |
||
+ | <!------------------------------------------------------------------------> |
||
− | | <code>0+x</code> || <code>x</code> |
||
+ | |- style="vertical-align:top" |
||
− | |- |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0+x</code> |
||
− | | <code>1^x</code> || <code>1</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
||
− | |- |
||
+ | | style="padding:5px" | Anything plus zero is itself. |
||
− | | <code>1*x</code> || <code>x</code> |
||
+ | |||
− | |- |
||
+ | <!------------------------------------------------------------------------> |
||
− | | <code>-a-bi</code> || <code>-(a+bi)</code> |
||
+ | |- style="vertical-align:top" |
||
− | |- |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x+0</code> |
||
− | | <code>fn*x</code> || <code>x*fn</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
||
− | |- |
||
+ | | style="padding:5px" | Anything plus zero is itself. |
||
− | | <code>-n</code> || <small>''If the number is negative, factor it out and try using that in the reductions of the parent objects.''</small> |
||
+ | |||
− | |- |
||
+ | <!------------------------------------------------------------------------> |
||
− | | <code>V_n</code> || <small>Select the <code>n</code>th item of <code>V</code>.</small> |
||
+ | |- style="vertical-align:top" |
||
− | |- |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0-x</code> |
||
− | | <code>x^0</code> || <code>1</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-x</code> |
||
− | |- |
||
+ | | style="padding:5px" | Subtracting from zero gives negative. |
||
− | | <code>x><0</code> || <code>0</code> |
||
+ | |||
− | |- |
||
+ | <!------------------------------------------------------------------------> |
||
− | | <code>x-0</code> || <code>x</code> |
||
+ | |- style="vertical-align:top" |
||
− | |- |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x-0</code> |
||
− | | <code>x.0</code> || <code>0</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
||
− | |- |
||
+ | | style="padding:5px" | Anything minus zero is itself. |
||
− | | <code>x*0</code> || <code>0</code> |
||
+ | |||
− | |- |
||
+ | <!------------------------------------------------------------------------> |
||
− | | <code>x+0</code> || <code>x</code> |
||
+ | |- style="vertical-align:top" |
||
− | |- |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0*x</code> |
||
− | | |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0</code> |
− | | |
+ | | style="padding:5px" | Zero times anything is zero (or zero vector, etc.). |
− | + | ||
− | + | <!------------------------------------------------------------------------> |
|
− | | |
+ | |- style="vertical-align:top" |
− | |- |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x*0</code> |
− | | |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0</code> |
− | | |
+ | | style="padding:5px" | Zero times anything is zero (or zero vector, etc.). |
− | + | ||
− | + | <!------------------------------------------------------------------------> |
|
− | | |
+ | |- style="vertical-align:top" |
− | |- |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>1*x</code> |
− | | |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
− | | |
+ | | style="padding:5px" | One times anything is itself. |
− | + | ||
− | + | <!------------------------------------------------------------------------> |
|
− | | |
+ | |- style="vertical-align:top" |
− | |- |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x*1</code> |
− | | |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
− | | |
+ | | style="padding:5px" | Anything times one is itself. |
− | + | ||
− | + | <!------------------------------------------------------------------------> |
|
− | | |
+ | |- style="vertical-align:top" |
− | |- |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x*n</code> |
− | | |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>n*x</code> |
− | | |
+ | | style="padding:5px" | Move constants to be in front of formulas. |
− | + | ||
− | + | <!------------------------------------------------------------------------> |
|
− | | |
+ | |- style="vertical-align:top" |
− | |- |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0/x</code> |
− | | |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0</code> |
− | | |
+ | | style="padding:5px" | Zero divided by anything is zero (since division by zero is already not allowed). |
− | + | ||
− | + | <!------------------------------------------------------------------------> |
|
− | | |
+ | |- style="vertical-align:top" |
− | |- |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x/1</code> |
− | | |
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
− | | |
+ | | style="padding:5px" | Anything over one is itself. |
− | + | ||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x^1</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
||
+ | | style="padding:5px" | Anything to the first power is itself. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x^0</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>1</code> |
||
+ | | style="padding:5px" | Anything to the zero power is one. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x^(-a)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>1/x^a</code> |
||
+ | | style="padding:5px" | Negative power is reciprocal. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>1^x</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>1</code> |
||
+ | | style="padding:5px" | One to any power is one. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0.x</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0</code> |
||
+ | | style="padding:5px" | Zero vector dot any vector is zero. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x.0</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0</code> |
||
+ | | style="padding:5px" | Any vector dot zero vector is zero. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" |<code>0><x</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" |<code>0</code> |
||
+ | | style="padding:5px" | Cross product with a zero vector produces a zero vector. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x><0</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>0</code> |
||
+ | | style="padding:5px" | Cross product with a zero vector produces a zero vector. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-n</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(n)</code> |
||
+ | | style="padding:5px" | Factor out negatives from real number constants. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-a-bi</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(a+bi)</code> |
||
+ | | style="padding:5px" | Factor out negatives from complex constants. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>(-x)+y</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>y-x</code> |
||
+ | | style="padding:5px" | Reverse order to remove initial negative. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x+(-y)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x-y</code> |
||
+ | | style="padding:5px" | Turn plus-a-negative into minus. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>(-x)-y</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x+y)</code> |
||
+ | | style="padding:5px" | Turn negative-minus-positive to negation of addition. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x-(-y)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x+y</code> |
||
+ | | style="padding:5px" | Turn minus-a-negative to addition. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>(-x)*y</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x*y)</code> |
||
+ | | style="padding:5px" | Factor negation out of multiplication. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x*(-y)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x*y)</code> |
||
+ | | style="padding:5px" | Factor negation out of multiplication. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>(-x)/y</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x/y)</code> |
||
+ | | style="padding:5px" | Factor negation out of division. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x/(-y)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x/y)</code> |
||
+ | | style="padding:5px" | Factor negation out of division. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>(-x).y</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x.y)</code> |
||
+ | | style="padding:5px" | Factor negative out of dot product. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x.(-y)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x.y)</code> |
||
+ | | style="padding:5px" | Factor negative out of dot product. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>(-x)><y</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x><y)</code> |
||
+ | | style="padding:5px" | Factor negative out of cross product. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x><(-y)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(x><y)</code> |
||
+ | | style="padding:5px" | Factor negative out of cross product. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-(-x)</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
||
+ | | style="padding:5px" | Cancel double negatives. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>+x</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x</code> |
||
+ | | style="padding:5px" | Remove unneeded unary plus. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-x=n</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x=-n</code> |
||
+ | | style="padding:5px" | Multiply equality by <math>-1</math> when equal to a constant. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>-x=-y</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x=y</code> |
||
+ | | style="padding:5px" | Multiply equality by <math>-1</math> when both sides are negative. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>fn*x</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>x*fn</code> |
||
+ | | style="padding:5px" | Move function calls to the right. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
+ | |- style="vertical-align:top" |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <code>V_n</code> |
||
+ | | style="padding:5px; white-space:nowrap; text-align:center" | <math>n</math>-th item of <code>V</code>. |
||
+ | | style="padding:5px" | Extract a coordinate from a vector or point. |
||
+ | |||
+ | <!------------------------------------------------------------------------> |
||
|} |
|} |
||
+ | |||
+ | <br> |
||
+ | |||
+ | [[Category:Contexts]] |
||
+ | [[Category:MathObjects]] |
||
+ | [[Category:Reference Tables]] |
Latest revision as of 17:17, 5 January 2021
When substituting randomly chosen values into an expression, it is possible to obtain situations like 1 x^2 + -3 x + 0
, which do not look good when displayed as part of the text shown to a student. To help remedy this situation, the MathObjects library can reduce Formula objects according to a set of reduction rules that try to eliminate such visual problems. The main reduction rules are shown below.
Sometimes these rules don't improve the look of your formulas, however. In particular, many are designed to try to factor out negatives so that they can be canceled, but this does not always lead to better looking equations when the negatives don't cancel. For this reason, you can turn off individual reduction rules so that they will be skipped. See the Reduction Rules section of the Introduction to Contexts for details on how to control the reduction rules.
You can disable one or more reduction rules using a command like the following examples:
Context()->noreduce('(-x)-y'); Context()->noreduce('(-x)-y','(-x)+y');
It is possible for MathObject extensions to add more reduction rules for the MathObjects they define. See the documentation for the extensions you are using to see if that is the case.
The Reduction Rules and their Actions
Rule | Reduction | Description |
---|---|---|
0+x
|
x
|
Anything plus zero is itself. |
x+0
|
x
|
Anything plus zero is itself. |
0-x
|
-x
|
Subtracting from zero gives negative. |
x-0
|
x
|
Anything minus zero is itself. |
0*x
|
0
|
Zero times anything is zero (or zero vector, etc.). |
x*0
|
0
|
Zero times anything is zero (or zero vector, etc.). |
1*x
|
x
|
One times anything is itself. |
x*1
|
x
|
Anything times one is itself. |
x*n
|
n*x
|
Move constants to be in front of formulas. |
0/x
|
0
|
Zero divided by anything is zero (since division by zero is already not allowed). |
x/1
|
x
|
Anything over one is itself. |
x^1
|
x
|
Anything to the first power is itself. |
x^0
|
1
|
Anything to the zero power is one. |
x^(-a)
|
1/x^a
|
Negative power is reciprocal. |
1^x
|
1
|
One to any power is one. |
0.x
|
0
|
Zero vector dot any vector is zero. |
x.0
|
0
|
Any vector dot zero vector is zero. |
0><x
|
0
|
Cross product with a zero vector produces a zero vector. |
x><0
|
0
|
Cross product with a zero vector produces a zero vector. |
-n
|
-(n)
|
Factor out negatives from real number constants. |
-a-bi
|
-(a+bi)
|
Factor out negatives from complex constants. |
(-x)+y
|
y-x
|
Reverse order to remove initial negative. |
x+(-y)
|
x-y
|
Turn plus-a-negative into minus. |
(-x)-y
|
-(x+y)
|
Turn negative-minus-positive to negation of addition. |
x-(-y)
|
x+y
|
Turn minus-a-negative to addition. |
(-x)*y
|
-(x*y)
|
Factor negation out of multiplication. |
x*(-y)
|
-(x*y)
|
Factor negation out of multiplication. |
(-x)/y
|
-(x/y)
|
Factor negation out of division. |
x/(-y)
|
-(x/y)
|
Factor negation out of division. |
(-x).y
|
-(x.y)
|
Factor negative out of dot product. |
x.(-y)
|
-(x.y)
|
Factor negative out of dot product. |
(-x)><y
|
-(x><y)
|
Factor negative out of cross product. |
x><(-y)
|
-(x><y)
|
Factor negative out of cross product. |
-(-x)
|
x
|
Cancel double negatives. |
+x
|
x
|
Remove unneeded unary plus. |
-x=n
|
x=-n
|
Multiply equality by [math]-1[/math] when equal to a constant. |
-x=-y
|
x=y
|
Multiply equality by [math]-1[/math] when both sides are negative. |
fn*x
|
x*fn
|
Move function calls to the right. |
V_n
|
[math]n[/math]-th item of V .
|
Extract a coordinate from a vector or point. |