amy has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I've been trying to run a perl script to operate Maple. I have this weird problem. Whenever I have a polynomial with powers (for example, x^2 + 3x^3), Maple prints it as-

 2     3
x  + 3x
on two different lines. And when I read it using my script, I get,  2   3 and x + 3x on two seperate lines. :(

Is there anyway I can get around this? Any help would be really great!

Thanks

Edit by tye: Preserve formatting

Retitled by davido.

Replies are listed 'Best First'.
Re: Problem with reading values from Maple
by Zaxo (Archbishop) on Jan 10, 2005 at 05:19 UTC

    I don't know Maple, but the ancestral MACSYMA prints powers and rationals in a 2-d format like that. In maxima that is controlled by a global variable, DISPLAY2D, which is set TRUE by default. Setting that false gives output on a single line, which would be much easier to parse or translate in Perl.

    Maple probably has a similar flag, check your docs.

    Added: Here's bit of a maxima session to demonstrate,

    (%i99) display2d; (%o99) TRUE (%i100) x^2+3*x^3; 3 2 (%o100) 3 x + x (%i101) display2d:false; (%o101) FALSE (%i102) %o100; (%o102) 3*x^3+x^2 (%i103)

    After Compline,
    Zaxo

Re: Problem with reading values from Maple
by Errto (Vicar) on Jan 12, 2005 at 04:56 UTC
    Note to those voting on consideration: I reconsidered this node because the orignal title was "Problem with Reading Values." If you read the node you will see, I think, that adding the word "Maple" to the title was appropriate, but changing the word "Reading" to "Sending" was not, as it substantially changed the OPs meaning and is also plainly wrong. Thanks.
Re: Problem with reading values from Maple
by archen (Pilgrim) on Jan 10, 2005 at 18:15 UTC
    I'm not sure I have a solution, but this might be something to consider. First of all you read lines two at a time. If you have a digit at position 'x', then the corresponding variable is on the next line at 'x - 1'. You could then re-write the expression to x^2 format (using a script to translate before getting to your script). I'm not sure if that's going to work if you're using a pipe though.

    There are some hangups to consider. If there are no powers, is there a blank line? Probably not. Assuming that powers can also be expressions, then you probably need to look at where the first column starts.

    Hope that might have helped in some way.