Pregunta

Say I have a super long polynomial of multiple variables. far too long to display on-screen, or print out, so collect http://www.maplesoft.com/support/help/Maple/view.aspx?path=collect is unlikely to help. I would like to tell maple to display only terms that contain a specific variable to one select power. I am sure there must be a simple way to do this. And no, I haven't looked into this extensively. feel free to just provide a link to the answer, if it already exists online.

thank's...

¿Fue útil?

Solución

If you care about speed -- perhaps because you need to do similar queries for other powers, of possibly other variables -- then consider using the coeff command. Eg, for polynomial f, the terms with x^2 could be obtained with the command,

x^2*coeff(f,x,2);

For a trivariate dense polynomial of about 1000000 terms as in the following example, the coeff command is several hundred times faster in Maple 16 and 17 than is the has command approach as shown below.

restart:
f:=expand(randpoly(x,degree=100,dense)
          *randpoly(y,degree=100,dense)
          *randpoly(z,degree=100,dense)):

nops(f); # number of terms
                         990000

sol1:=CodeTools:-Usage( select(has,f,x^2) ):
  memory used=105.36MiB, alloc change=58.22MiB, cpu time=842.00ms, real time=843.00ms

sol2:=CodeTools:-Usage( x^2*coeff(f,x,2) ):
  memory used=156.84KiB, alloc change=0 bytes, cpu time=0ns, real time=4.00ms

expand(sol1-sol2);
                           0

# Check that the timing difference was not just due to the order in which
# the two approaches were done, by a simple repeat.
CodeTools:-Usage( select(has,f,x^2) ):
  memory used=105.30MiB, alloc change=23.11MiB, cpu time=733.00ms, real time=691.00ms
CodeTools:-Usage( x^2*coeff(f,x,2) ):
  memory used=156.81KiB, alloc change=0 bytes, cpu time=0ns, real time=3.00ms

That was all done in Maple 17 64bit on Windows 7, and timings are pretty similar in Maple 16. This is in stark contrast to Maple 15 and earlier, where the coeff approach is about 3 times slower than that has approach. Those improvements relate to major work done in handling polynomial structures in Maple 16 and 17. See here and here.

Otros consejos

Let's say that you want to see all terms of polynomial poly with x^2. Then do select(has, poly, x^2);

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top