ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 25 Jun 2020 00:48:56 -0500Factoring 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 00:48:56 -0500https://ask.sagemath.org/question/52216/Factorization/Irreducibility of multivariate polynomials over function fieldshttps://ask.sagemath.org/question/51769/factorizationirreducibility-of-multivariate-polynomials-over-function-fields/I want to do this:
L.<t> = FunctionField(GF(5))
R.<x,y> = PolynomialRing(L)
p = x^2-t^2*y^2
p.factor()
As a result, I would like to get something like `(x+t*y)(x-t*y)` or `(x+t*y)(x+4*t*y)`.
But what I get is:
sage: L.<t> = FunctionField(GF(5))
/software/sagemath/9.0/SageMath/local/lib/python3.7/site-packages/sage/rings/function_field/ideal.py:2217: DeprecationWarning: invalid escape sequence \g
"""
sage: R.<x,y> = PolynomialRing(L)
sage: p = x^2-t^2*y^2
sage: p.factor()
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-5-f448610e9d77> in <module>()
----> 1 p.factor()
/software/sagemath/9.0/SageMath/local/lib/python3.7/site-packages/sage/rings/polynomial/multi_polynomial_element.py in factor(self, proof)
1842 proof = get_flag(subsystem="polynomial")
1843 if proof:
-> 1844 raise NotImplementedError("Provably correct factorization not implemented. Disable this error by wrapping your code in a `with proof.WithProof('polynomial', False):` block.")
1845
1846 R._singular_().set_ring()
NotImplementedError: Provably correct factorization not implemented. Disable this error by wrapping your code in a `with proof.WithProof('polynomial', False):` block.
However, this works, but (as already indicated in the parentheses) I get a wrong result:
sage: p.factor(false)
[(x + t*y, 1), (-x + t*y, 1)]
Unlike the univariate case, there is also no option to check whether the polynomial is irreducible, i.e. `p.is_irreducible()` doesn't exist.
ThrashFri, 05 Jun 2020 02:41:45 -0500https://ask.sagemath.org/question/51769/How to get the canonical prime factorization, with zero exponents toohttps://ask.sagemath.org/question/49302/how-to-get-the-canonical-prime-factorization-with-zero-exponents-too/Is it possible to get the 'canonical prime factorization', that means to get prime numbers with zero exponents too. <br>
*Example*: <br>
*I have:* `factor(45) = 3^2 * 5` <br>
*I need:* `factor(45) = 2^0 * 3^2 * 5`
F = factor(45)
print 'F = factor(45) = ', F
print 'F[0] =', F[0]
print 'F[1] =', F[1]
Out:
F = factor(45) = 3^2 * 5
F[0] = (3, 2)
F[1] = (5, 1)
geroyxWed, 01 Jan 2020 08:21:55 -0600https://ask.sagemath.org/question/49302/How sage checks the irreducibility of a polynomial?https://ask.sagemath.org/question/47951/how-sage-checks-the-irreducibility-of-a-polynomial/ Hi, given a polynomial we can check whether its irreducibility via `.is_irreducible()` command. I wonder how sage checks it so fast even though the polynomial has large degree with large coefficients?captainTue, 17 Sep 2019 18:19:57 -0500https://ask.sagemath.org/question/47951/Pretty print factorizations as fractionshttps://ask.sagemath.org/question/46864/pretty-print-factorizations-as-fractions/Hi all,
If I have an object whose factorization makes sense when expressed as a fraction, how do I get Sage to pretty print its factorization as a fraction instead of a product of factors? For example,
sage: R.<x> = PolynomialRing(QQ)
sage: f = (x - 1)^2 / (x + 1)
sage: f
(x^2 - 2*x + 1)/(x + 1)
sage: f.factor()
(x + 1)^-1 * (x - 1)^2
but ideally I would like some way to pretty print `f` as `(x - 1)^2/(x + 1)`.
Thanks,
Henryliu.henry.hlSat, 08 Jun 2019 09:31:28 -0500https://ask.sagemath.org/question/46864/Factorization of $f \in \mathbb{Q}[X]$ in field extension $\mathbb{Q}(\alpha)$.https://ask.sagemath.org/question/40374/factorization-of-f-in-mathbbqx-in-field-extension-mathbbqalpha/I'm given an irreducible polynomial $f \in \mathbb{Q}[X]$ of degree 5 and I want to determine its Galois group without using the predefined functions of sage. The method I want to follow takes a root $\alpha_1$ of $f$ and studies the factorization of $f$ in the field extension $\mathbb{Q}(\alpha_1)$.
I believe this is possible with other software. How can I do it with sage?
**Edit**
Apparently, Abstract Algebra: An Interactive Approach, Second Edition but they use InitDomain function which is not recognized by my notebook.
Apparently the book gives a CD where an interface between sage and gap is done. So probably the solution requires using gap commands.Rodrigo RayaSat, 30 Dec 2017 12:14:54 -0600https://ask.sagemath.org/question/40374/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 09:12:52 -0600https://ask.sagemath.org/question/40304/factorization on number fieldshttps://ask.sagemath.org/question/40124/factorization-on-number-fields/ I am trying to factor a division polynomial on a number field and I get the following error.
"PariError: inconsistent concatenation t_COL (16 elts) , t_VEC (8 elts)"
Could you please tell me how I can rectify it?
Thank you very much in advance!
Here is the code I am trying to compile:
K.<rho> = NumberField(x^16 - 7*x^12 + 48*x^8 - 7*x^4 + 1)
Kx.<x> = K[]
P = 2*x^24 - 220779/1250*x^22 + 10143441/15625*x^21 - 142856857143/25000000*x^20 + 131732868267/19531250*x^19 + 31020130846593/5000000000*x^18 + 13930920190065879/1562500000000*x^17 - 421500204770774287041/5000000000000000*x^16 - 31485474287738310861/976562500000000*x^15 + 2518173788725346513398533/6250000000000000000*x^14 - 582641643196535738602059/3125000000000000000*x^13 - 73639749524289565897523550321/125000000000000000000000*x^12 + 20820019744955833474743619767/48828125000000000000000*x^11 + 300689661910158431801904075908157/625000000000000000000000000*x^10 - 4454385478020717587635582204420833/7812500000000000000000000000*x^9 + 16361877508124295728413974125123451/400000000000000000000000000000*x^8 + 1573027301404166809168217933184311901/9765625000000000000000000000000*x^7 - 11987294796540068181333112421577867214431/125000000000000000000000000000000000*x^6 + 113700674422931989849194398791831231927941/1562500000000000000000000000000000000*x^5 - 168139864900386988616344904823569275391618007/2500000000000000000000000000000000000000*x^4 + 2632186130949079940307397635576696383706753/78125000000000000000000000000000000000*x^3 - 116064304293562967834364362386796558774110963539/12500000000000000000000000000000000000000000*x^2 + 206061630034967578571315740889755584982886782011/156250000000000000000000000000000000000000000*x - 30099620598750107945851944211328293200688722593391/500000000000000000000000000000000000000000000000
print P.parent()==Kx
print P.roots()sushiTue, 12 Dec 2017 10:28:25 -0600https://ask.sagemath.org/question/40124/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 11:17:56 -0600https://ask.sagemath.org/question/39772/Factorization sequence to enumerated sequence in Sagehttps://ask.sagemath.org/question/39678/factorization-sequence-to-enumerated-sequence-in-sage/I have the following Magma code that I want to rewrite in Sage:
Eltseq(Random(FiniteField(2^8)));
This basically produces the following result: `[ 0, 1, 0, 1, 1, 1, 0, 1 ]`. The function `Eltseq` is defined as this in the documentation (https://magma.maths.usyd.edu.au/magma/handbook/text/166):
> Given a factorization sequence f,
> create the enumerated sequence
> containing the same pairs of primes
> and exponents.
Any ideas how can I rewrite this line in Sage?whateverMon, 20 Nov 2017 12:22:19 -0600https://ask.sagemath.org/question/39678/Why can one not factor 0?https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/I was trying to understand the structure of (a-b), where "a" and "b" were two very large expressions. So I was doing things like (a-b).simplify_full().factor(). I discovered the following anomaly.
sage: var ('a', 'b') #Adequate for illustration
(a, b)
sage: (a-b); (a-b).factor()
a - b
a - b
sage: b=a #By chance, "a" and "b" were equivalent.
sage: (a-b); (a-b).factor()
0
Traceback (most recent call last):
...
ArithmeticError: factorization of 0 is not defined
I would have expected 0.factor() to give 0.
Richard_LWed, 11 Oct 2017 14:50:44 -0500https://ask.sagemath.org/question/39127/y-coordinate of a 4-torsion pointhttps://ask.sagemath.org/question/35410/y-coordinate-of-a-4-torsion-point/I want to find the `y`-coordinate of a 4-torsion point. I have the following code where I found the x-coordinate
E3=EllipticCurve([0,0,0,-3267,45630])
E=E3.division_polynomial(4);E
E.factor()
which gives
8*(x^4 + 30*x^3 - 18252*x^2 + 280530*x + 6465339)*(x^2 + 15*x - 3042)*(x^2 - 30*x + 2817)*(x - 15)
Then I factor $x^2 - 30x + 2817$ in $\mathbb{Q}(\sqrt{-2})$ and I got $[(-36\sqrt{-2} + 15, 1), (36\sqrt{-2} + 15, 1)]$ which is my x-coordinate. How to get the y-coordinate? If I denote $\sqrt{-2}=B$, then I have $x=15\pm 36B$. And I substitute it into my elliptic curve gives
B = var('B')
y2=x^3-3267*x+45630;y2
y=y2.subs({x:15+36*B});y
Y=y.simplify_full();Y
YY=Y.subs({B^2:-2});YY
YYY=YY.subs({B^3:-2*B});YYY
which equals to $y^2=186624B-116640$. How to get the y-coordinate. By trying an error multiple times (using PARI-gp) I manage to get y-coordinate as $y=27a^3-135a-108aB$ with $a^4-5a^2-32=0$ and $B^2=-2$. But i got this by trying an error comparing LHs and RHS equation. Not straight away from $y^2=186624B-116640$. I tried the following but it did not work :
K.<a> = NumberField(x^4 -5*x^2-32); K
f = K.factor(186624*B-116640); fShaThu, 03 Nov 2016 21:01:35 -0500https://ask.sagemath.org/question/35410/factor x^2 - 30*x + 2817 in sqrt(-2)https://ask.sagemath.org/question/35337/factor-x2-30x-2817-in-sqrt-2/ Is there a way I can use SAGE to factor my polynomial x^2 - 30*x + 2817 in sqrt(-2).ShaWed, 02 Nov 2016 00:47:32 -0500https://ask.sagemath.org/question/35337/Finding prime factorization of ideals in number ringshttps://ask.sagemath.org/question/35209/finding-prime-factorization-of-ideals-in-number-rings/Let $K$ be a number field and $O_K$ its ring of algebraic integers. Let $p\in\mathbb{Z}$ be a rational prime. I want to find the factorization of the ideal $pO_K$. What is the syntax for this ?
For clarity, I request you to demonstrate with an example (say $K=\mathbb{Q}(\sqrt{2}+i)$ and $p=2$ and $p=3$).nebuckandazzerFri, 21 Oct 2016 08:28:30 -0500https://ask.sagemath.org/question/35209/multivariate polynomial ring over complex numbershttps://ask.sagemath.org/question/34692/multivariate-polynomial-ring-over-complex-numbers/ I want to factorize bivariate polynomials over C. For single variable case we do this as follow:
R=CC[x]
x=R.gen()
f=x^2+1
f.factor()
How to do this for multivariate case ?nebuckandazzerFri, 02 Sep 2016 12:33:45 -0500https://ask.sagemath.org/question/34692/Large Integer Factorizationhttps://ask.sagemath.org/question/34125/large-integer-factorization/I am trying to factor a 520-bit integer in Sage. At some point, I get:
**Warning: MPQS: number too big to be factored with MPQS, giving up.**
But it seems to still be running. Is it continuing the factorization?VovaMon, 18 Jul 2016 07:47:59 -0500https://ask.sagemath.org/question/34125/List of prime factors with repetitionhttps://ask.sagemath.org/question/33493/list-of-prime-factors-with-repetition/Is there a simple command on Sage wich gives, in place of factor(720)= 2^4 * 3^2 * 5, the list [2, 2, 2, 2, 3, 3, 5] of prime factors with repetition?logomathSat, 21 May 2016 09:14:39 -0500https://ask.sagemath.org/question/33493/Factoring a polynomial over algebraic numbers?https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/ Actually, what I want is to be able to factor a polynomial over the quadratic closure of the rationals, so that I could factor `x^2-3` say, as `(x+sqrt(3)*(x-sqrt(3))`. I don't know enough about factoring algorithms to know whether this is easy or not, but is this at all possible in Sage?
I know I can build an extension field of the rationals by the use of an irreducible quadratic, but that just gives me access to one square root. So if I added `sqrt(3)` then I could factorize the example above, but not `x^2-5`. Is it possible to include all square roots - in other words, can Sage work with the the field of [constructible numbers](https://en.wikipedia.org/wiki/Constructible_number)?AlasdairThu, 21 Jan 2016 04:12:09 -0600https://ask.sagemath.org/question/32308/How to factor the coefficienthttps://ask.sagemath.org/question/30169/how-to-factor-the-coefficient/ I have the following code :
r,s,u= var('r s u')
U=u^4-A*u^2+17*B;U
eq1=U.subs({r:-21,s:324});eq1
factor(eq1)
which yields
(u^2 - 4281747124104997066155259836393062400)*(u^2 - 4281747146564836134743374782202380288)
My question : is there a code where I can factor the equation to yield something like this
(u^2 - 2^24*3^36*5^2*17*19^2*29*47^2*173)*(u^2 - 2^24*3^34*29*173*55229^2)
Because my aim is to look at the non-square numbers that appear in both factorization. In this case 29*173.ShaTue, 20 Oct 2015 23:25:47 -0500https://ask.sagemath.org/question/30169/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 14:14:40 -0600https://ask.sagemath.org/question/25560/why don't sage return exact value in some functionshttps://ask.sagemath.org/question/25514/why-dont-sage-return-exact-value-in-some-functions/ Look at the following code:
realpoly.<z> = PolynomialRing(RR)
factor(z^2-2)
it returns:
(z - 1.41421356237310) * (z + 1.41421356237310)
why don't sage return
(z-sqrt(2))*(z+sqrt(2))
and how can i make it to do that?Chong WangTue, 13 Jan 2015 21:31:08 -0600https://ask.sagemath.org/question/25514/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 02:00:21 -0500https://ask.sagemath.org/question/8155/Simplify expressionshttps://ask.sagemath.org/question/25180/simplify-expressions/Hi, I've got this long equation:
F_zr == (F_xc*p_fcx*p_rcy*p_rcz + c_N_x*p_fcx*p_rcx - c_N_y*p_fcx*p_rcy+ (p_fcx*p_rcx - p_rcx^2)*F_yc*p_rcz + c_N_z*p_rcx*p_rcz - (F_xc*p_rcx*p_rcy*p_rcz + c_N_x*p_rcx^2 - c_N_y*p_rcx*p_rcy +c_N_z*p_rcx*p_rcz)*cos(delta(t)) - (F_yc*p_rcx*p_rcy*p_rcz -c_N_z*p_rcy*p_rcz)*sin(delta(t)))/((p_fcx*p_rcx -p_rcx^2)*p_rcy*cos(delta(t)) - (p_fcx^2 - p_fcx*p_rcx)*p_rcy)
I tried doing simplify_full() but the output is not simple at all.
I read about using ._mathematica_().FullSimplify() but it says permission denied.
How can I really simplify it?
Thank you.
SilviaTue, 09 Dec 2014 10:45:56 -0600https://ask.sagemath.org/question/25180/factor() issue with second degre polynomeshttps://ask.sagemath.org/question/9339/factor-issue-with-second-degre-polynomes/Hello,
In a sagenb worksheet, I'am trying to factor two 2° polynomes R and H as follow:
from sage.misc.latex import pretty_print
x=var('x')
R(x)=9*(x-5)**2-4
f3=R.factor()
H(x)=2*(x+5)**2-4
f4=H.factor()
pretty_print('R(x)=',f3)
pretty_print('H(x)=',f4)
I get :
R(x)=(3x-17)(3x-13) as waited
but H(x)=2x**2+20x+46
I can develop the factorized H as:
test=(sqrt(2)*(x+5)-2)*(sqrt(2)*(x+5)+2)
pretty_print(test.radical_simplify())
which yields:
2x**2+20x+46
Is there a kind of "radical_factor()" ?
Thank you
jeanpatSat, 22 Sep 2012 04:20:31 -0500https://ask.sagemath.org/question/9339/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 03:25:29 -0500https://ask.sagemath.org/question/9132/out of core exact linear algebrahttps://ask.sagemath.org/question/8810/out-of-core-exact-linear-algebra/I'm trying to solve a large (17000x250000) sparse (density=0.01) system over the rationals. Are there any routines in Sage (or out) that could give the reduced row echelon form, or the null space?
Everything I've looked into either runs out of memory or isn't exact.tagitagiWed, 21 Mar 2012 11:21:05 -0500https://ask.sagemath.org/question/8810/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!bmTue, 25 Oct 2011 19:37:53 -0500https://ask.sagemath.org/question/8417/