Ask Your Question
0

factor() issue with second degre polynomes

asked 2012-09-22 11:20:31 +0100

jeanpat gravatar image

Hello, In a sagenb worksheet, I'am trying to factor two 2° polynomes R and H as follow:

from sage.misc.latex import pretty_print
x=var('x')
R(x)=9*(x-5)**2-4
f3=R.factor()
H(x)=2*(x+5)**2-4
f4=H.factor()
pretty_print('R(x)=',f3)
pretty_print('H(x)=',f4)

I get :

R(x)=(3x-17)(3x-13) as waited
but H(x)=2x**2+20x+46

I can develop the factorized H as:

test=(sqrt(2)*(x+5)-2)*(sqrt(2)*(x+5)+2)
pretty_print(test.radical_simplify())

which yields:

2x**2+20x+46

Is there a kind of "radical_factor()" ? Thank you

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
2

answered 2012-09-22 16:18:52 +0100

achrzesz gravatar image

updated 2012-09-22 17:17:15 +0100

If p is a simple polynomial with variable x, then sometimes the following (too) simple function can work

def rad_factor(p):
    s=solve(p,x,multiplicities=True)
    z=zip(map(lambda x:x.rhs(),s[0]),s[1])
    return p.leading_coeff(x)*prod([(x-y[0])^y[1] for y in z])

Or using the suggestion by John Palmieri

def rad_factor(p):
    return p.leading_coeff(x)*(prod((x-_[0])^_[1] for _ in p.roots()))
edit flag offensive delete link more
2

answered 2012-09-22 16:40:56 +0100

updated 2012-09-22 18:44:08 +0100

If you don't know the roots, you can use H.roots(). For example:

sage: H=2*(x+5)**2-4
sage: H.roots()
[(-sqrt(2) - 5, 1), (sqrt(2) - 5, 1)]
sage: prod((x-_[0])^_[1] for _ in H.roots())
(x - sqrt(2) + 5)*(x + sqrt(2) + 5)

Note that this has leading coefficient 1, not 2, so it's not equal to H. This could be repaired by multiplying by

sage: H.simplify_full().leading_coefficient(x)
2
edit flag offensive delete link more

Comments

I propose a small modification prod((x-_[0])^_[1] for _ in H.roots())

achrzesz gravatar imageachrzesz ( 2012-09-22 16:49:30 +0100 )edit

achrzesz: that's a good idea. I'll edit my answer.

John Palmieri gravatar imageJohn Palmieri ( 2012-09-22 18:43:49 +0100 )edit
0

answered 2012-09-22 13:12:49 +0100

achrzesz gravatar image
sage: R.<x>=PolynomialRing(QQ[sqrt(2)],'x')
sage: R(2*x**2+20*x+46).factor()           
(2) * (x - sqrt2 + 5) * (x + sqrt2 + 5)
edit flag offensive delete link more

Comments

Thank you. So I have to know "before" that the roots contain a sqrt(2).

jeanpat gravatar imagejeanpat ( 2012-09-22 13:53:50 +0100 )edit

You can obtain such information from solve

achrzesz gravatar imageachrzesz ( 2012-09-22 13:56:32 +0100 )edit

Thank you again.

jeanpat gravatar imagejeanpat ( 2012-09-22 14:47:26 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-09-22 11:20:31 +0100

Seen: 522 times

Last updated: Sep 22 '12