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.Thu, 25 Jun 2020 07:48:56 +0200Factoring a symbolic polynomialhttps://ask.sagemath.org/question/52216/factoring-a-symbolic-polynomial/The following code:
llambda, mu = var('λ, μ')
uVars = list(var(', '.join([f'u{n}' for n in range(1, 3 + 1)])))
aVars = list(var(', '.join([f'a{n}' for n in range(1, 3 + 1)])))
U = Matrix([[0, -uVars[2], uVars[1]],
[uVars[2], 0, -uVars[0]],
[-uVars[1], uVars[0], 0]])
a = Matrix([[aVars[0], 0, 0],
[0, aVars[1], 0],
[0, 0, aVars[2]]])
I = matrix.identity(3)
L = a*llambda + U
# Characteristic polynomial
charPoly = det((L - mu*I))
factor(charPoly)
computes a characteristic polynomial and yields:
a1*a2*a3*λ^3 - a1*a2*λ^2*μ - a1*a3*λ^2*μ - a2*a3*λ^2*μ
+ a1*u1^2*λ + a2*u2^2*λ + a3*u3^2*λ + a1*λ*μ^2
+ a2*λ*μ^2 + a3*λ*μ^2 - u1^2*μ - u2^2*μ - u3^2*μ - μ^3
However, this is not the simplification I desire. I want this:
$$(a_1\lambda - \mu)(a_2\lambda - \mu)(a_3\lambda - \mu)
- (u_1^2 + u_2^2 + u_3^2)\mu + (a_1 \mu_1^2 + a_2 u_2^2
+ a_3 u_3^2)\lambda$$
Is there a way to obtain that sort of factorization?NaltThu, 25 Jun 2020 07:48:56 +0200https://ask.sagemath.org/question/52216/Factor a quadratic in a quartic polynomialhttps://ask.sagemath.org/question/40304/factor-a-quadratic-in-a-quartic-polynomial/Hi, I have done this calculation using a very tedious way and have checked that it is correct. Can I possibly perform this using Sage only.
I have a polynomial :
D=M^2-(A/(2*p^4))*M+(B/(16*p^4))
where
A=18*p^{10} - 54*p^9 + 59*p^8 + 130*p^7 - 209*p^6 - 98*p^5 + 407*p^4 + 362*p^3 + 49*p^2 - 16*p + 8
and
B=9*( p + 1 )^2*(p^4 - 2*p^3 + 2*p^2 + 2*p + 1)*(4*p^8 - 52*p^7 + 373*p^6 + 68*p^5 - 445*p^4 + 72*p^3 + 163*p^2 - 48*p+ 9).
I have checked using multiple software that the factorization of D using the quartic in $p$
`v^2= p^4-2*p^3+5*p^2+8*p+4` gives
`[M-((A+2*F*v)/(4*p^4))]*[M-((A-2*F*v)/(4*p^4))]` where
`F=9*p^8-18*p^7-7*p^6+45*p^5-21*p^4-74*p^3-18*p^2+6*p-2`.
Can someone help me obtain the same result by using Sage only. Thank you.ShaTue, 26 Dec 2017 16:12:52 +0100https://ask.sagemath.org/question/40304/Factoring polynomials with symbolic expressionshttps://ask.sagemath.org/question/39772/factoring-polynomials-with-symbolic-expressions/ This question is about writing some code that factors a desired polynomial within $\mathbb{Q}$, $\mathbb{R}$ and $\mathbb{C}$ for educational purposes.
So far, I have the following code:
@interact
def _(p = input_box(default=x^5 + x^4 - 8*x^3 + 11*x^2 - 15*x + 2, label = 'P(x) = ')):
q.<x> = PolynomialRing(QQ, 'x')
r.<x> = PolynomialRing(RR, 'x')
c.<x> = PolynomialRing(CC, 'x')
a.<x> = PolynomialRing(AA, 'x')
qp = PolynomialRing(QQ, 'x')(p)
print(factor(qp))
rp = r(p)
print(factor(rp))
cp = c(p)
print(factor(cp))
ap = a(p)
print(factor(ap))
whose output is
(x - 2) * (x^4 + 3*x^3 - 2*x^2 + 7*x - 1)
(x - 2.00000000000000) * (x - 0.147637797932293) * (x + 3.96552349222940) * (x^2 - 0.817885694297105*x + 1.70805524786870)
(x - 2.00000000000000) * (x - 0.408942847148552 - 1.24129810909174*I) * (x - 0.408942847148552 + 1.24129810909174*I) * (x - 0.147637797932293) * (x + 3.96552349222940)
(x - 2.000000000000000?) * (x - 0.1476377979322930?) * (x + 3.965523492229398?) * (x^2 - 0.8178856942971048?*x + 1.708055247868697?)
The factorization is perfect, but I would like the output to be symbolic whenever possible (ie. written with radicals instead of decimals). I know about the use of the ring 'AA' and that the numbers ending with '?' may be translated into symbolic, but I do not know the smartest way to do this.
Which would be the smartest way to achieve this goal? In the same way, ideas to improve the previous code are also welcomejepstraFri, 24 Nov 2017 18:17:56 +0100https://ask.sagemath.org/question/39772/Solving polynomial equations with arbitrary coefficientshttps://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/ This is my first time with Sage and no where on the documentation do I see how to solve a polynomial equation (say a quadratic) with arbitrary complex coefficients. Say I want to solve "x^2 - 7ax + (5+2I)" for x when a \in \mathbb{C}.
How does this happen?
----------
I tried declaring "a" as a complex number using var('a', domain = CC) but that too didn't work.
I am using ".factor()" to factorize. PhoenixMon, 19 Jan 2015 21:14:40 +0100https://ask.sagemath.org/question/25560/Factoring bivariate polynomials w.r.t. a single variablehttps://ask.sagemath.org/question/8155/factoring-bivariate-polynomials-wrt-a-single-variable/the function **factor()** works in this fashion:
sage: x, y = PolynomialRing(GF(17), 2, ['x','y']).gens()
sage: f = 9*y^6 - 9*x^2*y^5 - 18*x^3*y^4 - 9*x^5*y^4 + 9*x^6*y^2 + 9*x^7*y^3 + 18*x^8*y^2 - 9*x^11
sage: f.factor()
(-9) * (x^5 - y^2) * (x^6 - 2*x^3*y^2 - x^2*y^3 + y^4)
Is there a possibility to factorize a bivariate polynomial in x,y with respect to a single variable only (e.g. y) and get the answer in the form of **(y - f(x))** as factors? HarryThu, 09 Jun 2011 09:00:21 +0200https://ask.sagemath.org/question/8155/Polynomial: find the common factorhttps://ask.sagemath.org/question/9132/polynomial-find-the-common-factor/Hello, assuming I have a polynomial like this:
sage: var('y, x')
(y, x)
sage: y = x^2 + 6*x^3 + 3*x^4
When I use collect_common_factors(), I get:
(3*x^2 + 6*x + 1)*x^2
Now, is there a way to know which are the common_factors collected?
In this case, I'm expecting this output:
x^2
Thank you everyone!alexanaWed, 04 Jul 2012 10:25:29 +0200https://ask.sagemath.org/question/9132/Factorization of non-commutative Laurent polynomialshttps://ask.sagemath.org/question/8417/factorization-of-non-commutative-laurent-polynomials/Hi, can Sage factorize non-commutative Laurent polynomials in several variables?
By those polynomials I mean elements in the group algebra Z[F(n)], where Z is the integers and F(n) is the free group on n letters.
(The case with Z/2- instead of Z-coefficients would also be interesting.)
Thank you!bmWed, 26 Oct 2011 02:37:53 +0200https://ask.sagemath.org/question/8417/