trunc () result

20 views
Skip to first unread message

swapnil sharma

unread,
Jan 11, 2017, 11:29:40 AM1/11/17
to sympy
trunc(2*x**3 + 3*x**2 + 5*x + 7, 3) gives result :  -x**3 - x + 1. is there some way to get coefficents positive 
instead of negative (i.e. here soln be like: 2*x**3+2*x+1)?

Kalevi Suominen

unread,
Jan 11, 2017, 1:21:37 PM1/11/17
to sympy


On Wednesday, January 11, 2017 at 6:29:40 PM UTC+2, swapnil sharma wrote:
trunc(2*x**3 + 3*x**2 + 5*x + 7, 3) gives result :  -x**3 - x + 1. is there some way to get coefficents positive 
instead of negative (i.e. here soln be like: 2*x**3+2*x+1)?

One possibility is to write  trunc(2*x**3 + 3*x**2 + 5*x + 7, 3, field=True) to avoid integer coefficients. Otherwise the current implementation will attempt to use representatives of least absolute value.
Message has been deleted

swapnil sharma

unread,
Jan 11, 2017, 2:00:57 PM1/11/17
to sympy
@Kalevi thanx for response.
Actually, I wanted to make a program to form extended euclidean representation of two polynomials(under a field ) so positive integral coefficents is necessary as far as I can see. setting field =True was not able to solve it. just out of curiosity, what effect does field =True parameter have?

Kalevi Suominen

unread,
Jan 11, 2017, 2:49:28 PM1/11/17
to sympy


On Wednesday, January 11, 2017 at 9:00:57 PM UTC+2, swapnil sharma wrote:
@Kalevi thanx for response.
Actually, I wanted to make a program to form extended euclidean representation of two polynomials(under a field ) so positive integral coefficents is necessary as far as I can see. setting field =True was not able to solve it. just out of curiosity, what effect does field =True parameter have?

By default, the coefficient domain will be the smallest domain containing the coefficients of the input polynomial expression. Setting field=True will force it to be the smallest field containing the coefficients, the field of rational numbers, in this case.
Reply all
Reply to author
Forward
0 new messages