ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 10 Jul 2012 03:07:22 +0200How to construct a polynomial from string?https://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.Tue, 10 Jul 2012 02:47:25 +0200https://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>
https://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)
Tue, 10 Jul 2012 03:07:22 +0200https://ask.sagemath.org/question/9144/how-to-construct-a-polynomial-from-string/?answer=13812#post-id-13812