Here's a different approach, which is more efficient, but poses its own 
challenges:

  sage: I = R.ideal(x^2)
  sage: Q = R.quo(I)
  sage: f = Q(x^3*y^3 + x^2*y^4 + x*y + x + y + 1)
  sage: f
  xbar*ybar + xbar + ybar + 1

So, the variables look different, and with reason. But:

  sage: %timeit g*g
  625 loops, best of 3: 3.4 µs per loop
  sage: %timeit f*f
  625 loops, best of 3: 30.5 µs per loop
  sage: %timeit g+g
  625 loops, best of 3: 2.39 µs per loop
  sage: %timeit f+f
  625 loops, best of 3: 27.2 µs per loop

Multiplication is faster than Simon's solution, but addition is (curiously) 
much slower.

regards
john perry

On Monday, June 3, 2013 7:12:34 PM UTC-5, Sam math wrote:
>
> I have a multivariate polynomial and want to keep only up to a certain 
> degree. I already know how to do this for the univariate case.
>
> For 1 variable, I'd do:
>
> R.<x> = PolynomialRing(QQ)
>
> f = x^4 + x^2 + x^3 + x + 1
>
> f = f + O(x^3)
>
> print f
>
> #output would be 1 + x + x^2... which is what I want.
>
> How do I do this for a multivariate polynomial? It says O(.) is not 
> defined...
>
> R.<x,y> = PolynomialRing(QQ)
>
> f = x^3*y^3 + x^2 * y^4 + x*y + x + y + 1
>
> How can I chop this polynomial up to a certain degree of x and y? I.e. I 
> want to keep up until the second degree of x only (regardless of y).
>
> I know one way I could go about this is to just redefine the polynomial by 
> looping through the first few coefficients, but I'm looking for a more 
> efficient/easier way.
>
> Thanks!
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to