ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 09 Jul 2012 20:07:22 -0500How to construct a polynomial from string?http://ask.sagemath.org/question/9144/how-to-construct-a-polynomial-from-string/Hi,
I can run the following (putting in a .sage file) successfully.
*R.<x> = QQ[]*
*f = x^3 - x^2 + x -1*
*p = x - 2*
*print f.quo_rem(p)*
But how about I have a string 'x^3 - x^2 + x -1', how can I construct f.
f = SR('x^3 - x^2 + x -1') is not working as there is no member function quo_rem for Expression.
Thanks.Mon, 09 Jul 2012 19:47:25 -0500http://ask.sagemath.org/question/9144/how-to-construct-a-polynomial-from-string/Answer by achrzesz for <p>Hi,</p>
<p>I can run the following (putting in a .sage file) successfully.</p>
<p><em>R.<x> = QQ[]</em></p>
<p><em>f = x^3 - x^2 + x -1</em></p>
<p><em>p = x - 2</em></p>
<p><em>print f.quo_rem(p)</em></p>
<p>But how about I have a string 'x^3 - x^2 + x -1', how can I construct f.</p>
<p>f = SR('x^3 - x^2 + x -1') is not working as there is no member function quo_rem for Expression.</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/9144/how-to-construct-a-polynomial-from-string/?answer=13812#post-id-13812 sage: R.<x> = QQ[]
sage: f = R('x^3 - x^2 + x -1')
sage: f.quo_rem(x-2)
(x^2 + x + 3, 5)
Mon, 09 Jul 2012 20:07:22 -0500http://ask.sagemath.org/question/9144/how-to-construct-a-polynomial-from-string/?answer=13812#post-id-13812