 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Forcing Maple Output with Simplifying
| [MUG] Forcing Maple Output with Simplifying |
|
Author: Fraser Murray
Posted: Wed, 11 Dec 2002 12:40:12 +0000
|
>> From: Fraser Murray "fraser.murray"
I'm new to Maple and I'm trying to generate a number of MathML examples.
A number of these examples are simplified by Maple, eg a very simplistic
example:
MathML:-Export(3 * x + 4 * x);
gives the MathML output for 7x
Is there a way of forcing Maple to give me output for 3x + 4x?
Please include my address in any reply.
Many thanks in advance,
Fraser
|
| [MUG] Re: Forcing Maple Output with Simplifying |
|
Author: Maple User Group
Posted: Fri, 13 Dec 2002 16:53:33 -0500
|
>> From: Maple User Group "maple_gr"
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 12 Dec 2002 13:55:21 -0500 (EST)
From: Carl Devore "devore"
To: "maple-list"
Subject: Forcing Maple Output with Simplifying
On Wed, 11 Dec 2002, Fraser Murray wrote:
| MathML:-Export(3 * x + 4 * x);
| gives the MathML output for 7x
|
| Is there a way of forcing Maple to give me output for 3x + 4x?
MathML:-Export(3*convert(x, `local`) + 4*x);
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: Douglas Harder "dwharder"
Subject: Forcing Maple Output with Simplifying
To: "maple-list"
Date: Thu, 12 Dec 2002 14:42:22 -0500 (EST)
This cannot be done in Maple, as there is no inert +. If you want
to get the output you're looking for do this:
> MathML:-Export(3 * x + 4 * y);
and then you'll have to substitute the y for x in the output (it occurs
3 times.)
Since you're new to Maple, you might not want to look at this:
> MathML:-Export(3 * x + 4 * `tools/gensym`(x));
The gensym generates a new symbol which looks like x, but is not x.
Unfortunately, there is no easy way to export 3 + 4. The standard
Maple tricks don't work because the MathML which is generated
depends on the objects being integers.
Cheers,
Douglas
--
Douglas Wilhelm Harder -: 3- -.- =.- -: -3 .* =. -:- :- . -: .= -:- * -:- -.
Department of Electrical and Computer Engineering http://ece.uwaterloo.ca/
University of Waterloo http://cheetah.vlsi.uwaterloo.ca/~dwharder/
.___ DC 2703 519-885-1211 x7023 http://links.uwaterloo.ca/
\ ."""". .-----._____.-----._______.-----._____.-----._____.--
\____/ --10-- http://www.scg.uwaterloo.ca/ http://mapleapps.com/
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: L Bernardin "lb"
To: "''"
Subject: Forcing Maple Output with Simplifying
Date: Thu, 12 Dec 2002 16:45:13 -0500
You could try this:
> macro(F=`tools/gensym`);
F
> F("3")*F("x")+F("4")*F("x");
3 x + 4 x
> MathML[Export](%):
> XMLTools[Print](%);
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<semantics>
<mrow xref='id7'>
<mrow xref='id3'>
<mi xref='id1'>3</mi>
<mo>⁢</mo>
<mi xref='id2'>x</mi>
</mrow>
<mo>+</mo>
<mrow xref='id6'>
<mi xref='id4'>4</mi>
<mo>⁢</mo>
<mi xref='id5'>x</mi>
</mrow>
</mrow>
<annotation-xml encoding='MathML-Content'>
<apply id='id7'>
<plus/>
<apply id='id3'>
<times/>
<ci id='id1'>3</ci>
<ci id='id2'>x</ci>
</apply>
<apply id='id6'>
<times/>
<ci id='id4'>4</ci>
<ci id='id5'>x</ci>
</apply>
</apply>
</annotation-xml>
<annotation encoding='Maple'>`3`*x+`4`*x</annotation>
</semantics>
</math>
best regards
-Laurent
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 12 Dec 2002 15:02:11 -0800 (PST)
From: Robert Israel "israel"
To: "maple-list"
Subject: Forcing Maple Output with Simplifying
There's no way to get Maple to avoid automatic simplifications: 3*x+4*x
always becomes 7*x. However, for a case such as this you can get around
the problem by using a second variable that looks like x but is different:
> 3*x+4*`tools/gensym`(x);
3 x + 4 x
> MathML:-Export(%);
There are various other tricks that can be used to get around some of the
other automatic simplifications that Maple uses. For example, Maple
always changes x > y to y < x. If you want x > y, you could generate
the MathML for x < y but then substitute ">" for "<":
> StringTools[SubstituteAll](MathML:-Export(x<y), "<", ">");
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: "Greg Gamble" "gregg"
To: "maple-list" "fraser.murray"
Subject: Forcing Maple Output with Simplifying
Date: Fri, 13 Dec 2002 08:41:13 +0800
Dear Fraser,
Unfortunately, Maple will simplify its argument whatever you do here
... so MathML:-Export only ever sees 7 * x (uneval quotes (') don't
help). What I've done in a similar context is to make the two x s
look different to Maple (while being visually identical to a human);
this can be done by replacing one of the x s with `x ` (i.e. a single
symbol that is an x followed by a blank) e.g.
> MathML:-Export(3 * x + 4 * `x `);
"<math xmlns='http://www.w3.org/1998/Math/MathML'><semantics><mr\
ow xref='id7'><mrow xref='id3'><mn xref='id1'>3</mn><mo>&I\
nvisibleTimes;</mo><mi xref='id2'>x</mi></mrow><mo>+</mo><\
mrow xref='id6'><mn xref='id4'>4</mn><mo>⁢<\
/mo><mi xref='id5'>x </mi></mrow></mrow><annotation-xml en\
coding='MathML-Content'><apply id='id7'><plus/><apply id='\
id3'><times/><cn id='id1' type='integer'>3</cn><ci id='id2\
'>x</ci></apply><apply id='id6'><times/><cn id='id4' type=\
'integer'>4</cn><ci id='id5'>x </ci></apply></apply></anno\
tation-xml><annotation encoding='Maple'>3*x+4*`x `</annota\
tion></semantics></math>"
As you can see, the <annotation encoding> tag betrays the trick employed
to get what you want. You might find this trick useful for the one-off
expressions you encounter, but a mite tedious for a longer list of such
expressions (and perhaps a bit error-prone).
Hope you find this (a little bit) useful.
Regards,
Greg Gamble
// Greg Gamble, Dept. of Maths & Stats //
// Curtin University, Bentley WA 6102 //
// Mailto: "gregg" //
// WWW: http://www.maths.curtin.edu.au/~gregg //
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: "Dr Francis J. Wright" "F.J.Wright"
To: "fraser.murray"
Subject: Forcing Maple Output with Simplifying
Date: Fri, 13 Dec 2002 15:17:23 -0000
I don't think you will be able to persuade Maple to generate MathML for any
expression that you could not output directly within Maple. The best I can
suggest is to use this:
MathML:-Export(3 * x + `4` * x);
with backquotes around the 4 to make it into an identifier. The MathML
output is similar to what you want, but uses the identifier tags mi and ci
for the `4`. If you edit these by hand to become the number tags mn and cn
then you should end up with the MathML that you wanted. For completeness,
you might also want to remove the backquotes around the 4 in the Maple
encoding towards the end of the output string.
Francis
|
Previous by date: [MUG] Logplot to file, Emilio Sanchez
Next by date: [MUG] Two bugs in evalapply(), Helmut Kahovec
Previous thread: [MUG] soritng - bubble sort, Trevor Meanwell
Next thread: [MUG] Two bugs in evalapply(), Helmut Kahovec
|
|
|