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.Mon, 04 Jun 2018 21:57:09 +0200convert charpoly()-generated characteristic polynom to symbolic expressionhttps://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/A characteristic polynom that is generated by the procedure charpoly() has the type:
> sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class.
How can I convert it to one of type 'symbolic expression' without doing 'copy and paste'?
Sun, 03 Jun 2018 19:33:33 +0200https://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/Answer by bekalph for <p>A characteristic polynom that is generated by the procedure charpoly() has the type:</p>
<blockquote>
<p>sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class.</p>
</blockquote>
<p>How can I convert it to one of type 'symbolic expression' without doing 'copy and paste'?</p>
https://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/?answer=42502#post-id-42502 I just found that characteristic polynomals of matrices can also be converted to SR by substituting one of their symbols with subs.Mon, 04 Jun 2018 21:57:09 +0200https://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/?answer=42502#post-id-42502Answer by Sébastien for <p>A characteristic polynom that is generated by the procedure charpoly() has the type:</p>
<blockquote>
<p>sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class.</p>
</blockquote>
<p>How can I convert it to one of type 'symbolic expression' without doing 'copy and paste'?</p>
https://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/?answer=42489#post-id-42489You can use the
sage: SR
Symbolic Ring
to convert the expression you get:
sage: m = random_matrix(ZZ, 3, 3)
sage: p = m.charpoly()
sage: type(p)
<type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>
sage: SR(p)
x^3 + 2*x^2 - 8*x + 5
sage: type(_)
<type 'sage.symbolic.expression.Expression'>
Make sure you really need the symbolic ring. In many cases, you can get what you want more efficiently without converting to symbolic ring.
Mon, 04 Jun 2018 08:26:24 +0200https://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/?answer=42489#post-id-42489Comment by bekalph for <p>You can use the</p>
<pre><code>sage: SR
Symbolic Ring
</code></pre>
<p>to convert the expression you get:</p>
<pre><code>sage: m = random_matrix(ZZ, 3, 3)
sage: p = m.charpoly()
sage: type(p)
<type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>
sage: SR(p)
x^3 + 2*x^2 - 8*x + 5
sage: type(_)
<type 'sage.symbolic.expression.Expression'>
</code></pre>
<p>Make sure you really need the symbolic ring. In many cases, you can get what you want more efficiently without converting to symbolic ring.</p>
https://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/?comment=42501#post-id-42501Thank you very much for the hint.
I need the conversion to SR in order to simplify the expression
with canonicalize_radical() or with factor(). This seems not be possible if I apply them on the unconverted expression (unimplemented error or attribute error).
I just found that characteristic polynomals of matrices can also be converted to SR by substituting one of their symbols with subs.Mon, 04 Jun 2018 20:51:16 +0200https://ask.sagemath.org/question/42486/convert-charpoly-generated-characteristic-polynom-to-symbolic-expression/?comment=42501#post-id-42501