Closed GoogleCodeExporter closed 8 years ago
Markus,
I think that equation manipulation capabilities can be added to MathPiper by
using
pattern matching rules like the ones included in the first fold below. The
easiest
way to play with these rules in inside of MathRider. In order to do this the
following two folds need to be saved in a file which has a .mrw extension so
that
MathRider knows that it is a worksheet file.
The first fold is used to define the rules and the second fold is used to test
the
rules. For now, start each rule with 900 #. The code to the left of a <--
operator
(not including 900 #) is a pattern that is used for matching and the code to the
right of the <-- operator is the result that is returned if the pattern is
matched.
In the pattern matching side of <--, any variable which starts with an underline
(like _x) is a pattern variable and it will match a wide-range of symbols that
fit
into the overall pattern. These pattern variables are then used as normal
variables
without the underline on the right side of the <-- operator.
The best way to get a feel for how these rules work is to just play with them a
bit
and see what effects they produce when they are tested.
Feel free to edit these rules and add to them to suit your needs and then we
can add
them to the MathPiper system if they solve the problem.
%mathpiper
/*
Press <shift><enter> in this fold to enter (or reenter) these
rules into the system. Feel free to add to these rules
as desired.
*/
900 # (_x == _y)*_z <-- x*z == y*z;
900 # _z*(_x == _y) <-- z*x == z*y;
900 # (_x == _y)/_z <-- x/z == y/z;
900 # (_x == _y) + _z <-- x + z == y + z;
900 # (_x == _y) - _z <-- x - z == y - z;
900 # (_x == _y)^_z <-- x^z == y^z;
900 # Sqrt(_x == _y) <-- Sqrt(x) == Sqrt(y);
900 # Sin(_x == _y) <-- Sin(x) == Sin(y);
%/mathpiper
%output,preserve="false"
Result: True
. %/output
%mathpiper,title=""
/*
Execute this fold to test the rules that have been added to the
system in the above fold. Add additional tests as needed.
Also, the MathPiper tab at the bottom of the application contains
the MathPiper console. The MathPiper console can also be used
to test the above rules.
*/
Echo(3*(x == y));
Echo((x == y)/3);
Echo((2*v/k == y)/3);
Echo( Sin(a == b) );
Echo( (a == b)^2 );
Echo( Sqrt(a == b) );
Echo( (3*x + 4 == 7) - 4 );
%/mathpiper
%output,preserve="false"
Result: True
Side Effects:
3*x==3*y
x/3==y/3
(2*v)/(3*k)==y/3
Sin(a)==Sin(b)
a^2==b^2
Sqrt(a)==Sqrt(b)
3*x==3
. %/output
Original comment by ted.ko...@gmail.com
on 17 Dec 2009 at 7:35
In GeoGebra I'm now using the following rules to init MathPiper in
GeoGebraCAS.initMyMathPiperFunctions(). Note that I added Simplify() for all
arithmetic equation manipulations (see bottom) because of Issue 14. Thus, if you
decide to make the changes proposed in Isse 14, I will like to remove those
Simplify() calls here.
// Rules for equation manipulation
// allow certain commands for equations
ggbMathPiper.evaluate("Simplify(_x == _y) <-- Simplify(x) == Simplify(y);");
ggbMathPiper.evaluate("Factor(_x == _y) <-- Factor(x) == Factor(y);");
ggbMathPiper.evaluate("Expand(_x == _y) <-- Expand(x) == Expand(y);");
ggbMathPiper.evaluate("ExpandBrackets(_x == _y) <-- ExpandBrackets(x) ==
ExpandBrackets(y);");
ggbMathPiper.evaluate("Sqrt(_x == _y) <-- Sqrt(x) == Sqrt(y);");
ggbMathPiper.evaluate("Exp(_x == _y) <-- Exp(x) == Exp(y);");
ggbMathPiper.evaluate("Ln(_x == _y) <-- Ln(x) == Ln(y);");
// arithmetic for equations
ggbMathPiper.evaluate("(_x == _y) + _z <-- Simplify(x + z == y + z);");
ggbMathPiper.evaluate("_z + (_x == _y) <-- Simplify(z + x == z + y);");
ggbMathPiper.evaluate("(_x == _y) - _z <-- Simplify(x - z == y - z);");
ggbMathPiper.evaluate("_z - (_x == _y) <-- Simplify(z - x == z - y);");
ggbMathPiper.evaluate("(_x == _y) * _z <-- Simplify(x * z == y * z);");
ggbMathPiper.evaluate("_z * (_x == _y) <-- Simplify(z * x == z * y);");
ggbMathPiper.evaluate("(_x == _y) / _z <-- Simplify(x / z == y / z);");
ggbMathPiper.evaluate("_z / (_x == _y) <-- Simplify(z / x == z / y);");
ggbMathPiper.evaluate("(_x == _y) ^ _z <-- Simplify(x ^ z == y ^ z);");
ggbMathPiper.evaluate("_z ^ (_x == _y) <-- Simplify(z ^ x == z ^ y);");
Original comment by mho...@gmail.com
on 11 Jan 2010 at 6:10
My teachers want a way to do something like
In> CheckInput( (x + 2 == 4) + 5 )
Result: x + 2 + 5 == 4 + 5
where the addition should not be evaluated in the result. Essentially, this is
similar to Hold() but only after applying one step. Is there any way that I
could do
this with rules? I played around a lot, but couldn't get anything working.
Thanks for
any hints in advance!
Original comment by mho...@gmail.com
on 8 Mar 2010 at 2:19
Trying to have MathPiper selectively not evaluate parts of an expression is very
challenging and often not feasible. In this case, a work-around is to use a
symbolic
variable (like bb) to represent the numeric value being applied to both sides
of the
equation, then use Subst to replace all occurrences of bb with 5 in the
resulting
expression:
In> aa := (x + 2 == 4) + bb
Result: x+bb+2==bb+4
In> Subst(bb,5) aa
Result: x+5+2==5+4
Will this work for you?
Original comment by ted.ko...@gmail.com
on 9 Mar 2010 at 6:45
Original comment by ted.ko...@gmail.com
on 7 May 2011 at 9:07
Most of these issues are for a very old version of MathPiper.
Original comment by ted.ko...@gmail.com
on 5 Nov 2013 at 8:55
Original issue reported on code.google.com by
ted.ko...@gmail.com
on 15 Dec 2009 at 2:32