Joe Riel

8216 Reputation

22 Badges

15 years, 124 days

MaplePrimes Activity

These are questions asked by Joe Riel

I would like to split a polynomial into even and odd terms. Has this capability been provided in a package? PolynomialTools seems the obvious choice, but doesn't do this. Here's one approach
SplitPolynomialEvenOdd := proc(poly::polynom(anything,v), v)
description "return the even and odd parts of a polynomial in v";
local p;
    p := collect(poly,v);
    if p::`+` then
        return selectremove(t -> degree(t,v)::even, p);
    elif degree(p,v)::even then
        return (p,0);
        return (0,p);
    end if;
end proc:

SplitPolynomialEvenOdd(x^2 + 3*x + 1, x);
What is an efficient, robust, way to extract an integer coefficient from a single term? My first thought was using lcoeff, however, it doesn't work if the term contains constants (say Pi) or floats. Currently I'm using patmatch,
icoeff := proc(t)
local k,x,kx;
  return `if`(patmatch(t, k::'nonunit'(integer)*x::anything,kx)
end proc:
map(icoeff, [0, 1, -3.0, -3, -0.,  3.0*Pi, 4*Pi, -12/5*I]);
                           [0, 1, 1, -3, 1, 1, 4, 1]
What is the proper method for converting an extended numeric with a zero imaginary component to a real? It should leave the complex part alone if it is not zero. That is, somefunc(1.0 + 0.*I); 1.0 somefunc(1.0 + 1.*I); 1.0 + 1.*I I can write my own procedure, but there must be standard way (somefunc) to do this. Searching the help browser didn't help. Thanks.
I'm trying to trap the exception generated when the member operator (:-) is used with a variable that is not a module. I thought the following would work:
    catch "`NotAModule` does not evaluate to a module":
        print("it worked")
        print("it failed");
    end try
end proc();
                                  "it failed"

                 "`NotAModule` does not evaluate to a module"
Any ideas how to fix this? The generated exception string should match the first catch statement.
I've looked at Alec Mihailov's interesting web page describing how to use the Microsoft assembler (MASM) to create a DLL that can be called by a Maple procedure. I'm attempting to rewrite the code using the GNU assembler (as) and have a few questions. Page 331, section 6.2 of the Maple 10 Advanced Programming Guide states that, to create a DLL, "the external library functions must be compiled by using the _stdcall calling convention, which is the default under UNIX but must be specified when using most Windows compilers." This leaves me somewhat confused. My limited understanding is that the stdcall calling convention has two effects:
1 2 3 4 Page 3 of 4