[sage-support] Re: Factorization class
Dear Tim, On Dec 3, 7:15 am, Tim Lahey [EMAIL PROTECTED] wrote: snip No, because I want instead of something like [(x-2,2),(x-3,3)] I'd like [(x-2)^2,(x-3)^3] You may do this: Start with a factorization of something: sage: f=factor(16200) sage: f 2^3 * 3^4 * 5^2 for X in f means that X runs over the pairs (2,3), (3,4), (5,2). And out of such pairs you can construct a factorization for each prime power, i.e.: sage: [Factorization([X]) for X in f] [2^3, 3^4, 5^2] Is this what you wanted? Best regards, Simon --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Factorization class
On Dec 3, 2008, at 4:50 AM, Simon King wrote: Dear Tim, On Dec 3, 7:15 am, Tim Lahey [EMAIL PROTECTED] wrote: snip No, because I want instead of something like [(x-2,2),(x-3,3)] I'd like [(x-2)^2,(x-3)^3] You may do this: Start with a factorization of something: sage: f=factor(16200) sage: f 2^3 * 3^4 * 5^2 for X in f means that X runs over the pairs (2,3), (3,4), (5,2). And out of such pairs you can construct a factorization for each prime power, i.e.: sage: [Factorization([X]) for X in f] [2^3, 3^4, 5^2] Is this what you wanted? Yes, and it's what someone else told me earlier in this thread. However, in the case of polynomials one has to be careful that it isn't expanded when raising to the power. Thanks, Tim. --- Tim Lahey PhD Candidate, Systems Design Engineering University of Waterloo http://www.linkedin.com/in/timlahey smime.p7s Description: S/MIME cryptographic signature
[sage-support] Re: Factorization class
Dear Tim, On Dec 3, 10:57 am, Tim Lahey [EMAIL PROTECTED] wrote: -- snip -- Yes, and it's what someone else told me earlier in this thread. Where? I only found your own suggestion [(i^j).factor() for i,j in f]. But this is likely not a good idea, because * i^j is computed (may take time), * the result is factorized (may take even more time), and * eventually only yields what you already knew, namely i and j. However, in the case of polynomials one has to be careful that it isn't expanded when raising to the power. No. It works the same way. sage: R.x = ZZ[] sage: f = x**10-1 sage: F = (f^2).factor() ; F (x - 1)^2 * (x + 1)^2 * (x^4 - x^3 + x^2 - x + 1)^2 * (x^4 + x^3 + x^2 + x + 1)^2 sage: [Factorization([X]) for X in F] [(x - 1)^2, (x + 1)^2, (x^4 - x^3 + x^2 - x + 1)^2, (x^4 + x^3 + x^2 + x + 1)^2] You see the difference? Your suggestion was to compute X[0]^X[1] and then to apply factorization to it. My suggestion was to simply *define* (not compute!!) the factorization. Cheers, Simon --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Factorization class
Dear Tim, perhaps the following is a better explanation. In the above situation, for X in F yields a list of pairs (x-1,2), (x +1,2) etc. In particular, X is not a polynomial. It is a pair, formed by a polynomial and a number. Hence, I am *not* applying a function called Factorization to some polynomial. Factorization is the constructor for an object of type class 'sage.structure.factorization.Factorization'. It takes as input a list of pairs. Factorization does *not* try to factorize the input any further! So, if you feed it with a reducible polynomial, it simply swallows it: sage: Factorization([(x^2+2*x+1,3)]) (x^2 + 2*x + 1)^3 And when I define Factorization([X]), the output is guaranteed to coincide with (X[0]^X[1]).factor(), by construction of X. Yours, Simon --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Factorization class
Does this help? sage: n=factorial(30) sage: [Factorization([pe]) for pe in n.factor()] [2^26, 3^14, 5^7, 7^4, 11^2, 13^2, 17, 19, 23, 29] sage: x = polygen(GF(3)) sage: f = cyclotomic_polynomial(120)(x) sage: [Factorization([pe]) for pe in f.factor()] [(x^4 + x^2 + x + 1)^2, (x^4 + x^2 + 2*x + 1)^2, (x^4 + x^3 + x^2 + 1)^2, (x^4 + 2*x^3 + x^2 + 1)^2] John Cremona On Dec 3, 9:57 am, Tim Lahey [EMAIL PROTECTED] wrote: On Dec 3, 2008, at 4:50 AM, Simon King wrote: Dear Tim, On Dec 3, 7:15 am, Tim Lahey [EMAIL PROTECTED] wrote: snip No, because I want instead of something like [(x-2,2),(x-3,3)] I'd like [(x-2)^2,(x-3)^3] You may do this: Start with a factorization of something: sage: f=factor(16200) sage: f 2^3 * 3^4 * 5^2 for X in f means that X runs over the pairs (2,3), (3,4), (5,2). And out of such pairs you can construct a factorization for each prime power, i.e.: sage: [Factorization([X]) for X in f] [2^3, 3^4, 5^2] Is this what you wanted? Yes, and it's what someone else told me earlier in this thread. However, in the case of polynomials one has to be careful that it isn't expanded when raising to the power. Thanks, Tim. --- Tim Lahey PhD Candidate, Systems Design Engineering University of Waterloohttp://www.linkedin.com/in/timlahey smime.p7s 3KViewDownload --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Factorization class
Ah, I think I see what you're doing. Thanks for the explanation. Cheers, Tim. On Dec 3, 2008, at 6:04 AM, Simon King wrote: Dear Tim, perhaps the following is a better explanation. In the above situation, for X in F yields a list of pairs (x-1,2), (x +1,2) etc. In particular, X is not a polynomial. It is a pair, formed by a polynomial and a number. Hence, I am *not* applying a function called Factorization to some polynomial. Factorization is the constructor for an object of type class 'sage.structure.factorization.Factorization'. It takes as input a list of pairs. Factorization does *not* try to factorize the input any further! So, if you feed it with a reducible polynomial, it simply swallows it: sage: Factorization([(x^2+2*x+1,3)]) (x^2 + 2*x + 1)^3 And when I define Factorization([X]), the output is guaranteed to coincide with (X[0]^X[1]).factor(), by construction of X. Yours, Simon smime.p7s Description: S/MIME cryptographic signature
[sage-support] Re: Factorization class
Tim Lahey wrote: Hi, Does the Factorization class not have a routine to return just a list of the factors? Basically, something like the value function but instead of multiplying them, puts each term into a list? I ask because the output of a squarefree_decomposition is a factorization and I'd like to use those factors in a partial fraction expansion. I suppose I could do, l = [] j = 0 while (j = len(c)): l.append((c[j][0])**(c[j][1])) j = j + 1 if c is the factorization object, but I would think that something like that would be part of the class. An easier way: sage: f=factor(16200) sage: f 2^3 * 3^4 * 5^2 sage: [i^j for i,j in f] [8, 81, 25] Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Factorization class
On Dec 3, 2008, at 12:18 AM, Jason Grout wrote: An easier way: sage: f=factor(16200) sage: f 2^3 * 3^4 * 5^2 sage: [i^j for i,j in f] [8, 81, 25] Thanks. That works, but Sage automatically expands things so you need to do, [(i^j).factor() for i,j in f] To ensure that each polynomial term is shown factorized. That solves one of my problems. Unfortunately, the partial fraction routine for polynomials doesn't take arguments as to terms to do the expansion over. Cheers, Tim. --- Tim Lahey PhD Candidate, Systems Design Engineering University of Waterloo http://www.linkedin.com/in/timlahey smime.p7s Description: S/MIME cryptographic signature
[sage-support] Re: Factorization class
Thanks. That works, but Sage automatically expands things so you need to do, [(i^j).factor() for i,j in f] To ensure that each polynomial term is shown factorized. Do you want a list of pairs of the form (p,e) for each term in the factorization of f? (That's actually how the factorization is stored internally, so there's definitely no need to call back into factor to do this.) Is this what you'd want? sage: R.x = ZZ[] sage: f = x**10-1 sage: F = f.factor() ; F (x - 1) * (x + 1) * (x^4 - x^3 + x^2 - x + 1) * (x^4 + x^3 + x^2 + x + 1) sage: list(F) [(x - 1, 1), (x + 1, 1), (x^4 - x^3 + x^2 - x + 1, 1), (x^4 + x^3 + x^2 + x + 1, 1)] I know you also wanted a nice way to move between symbolic expressions and polynomials (or, alternately, a partial fraction decomposition on fraction fields of polynomial rings that seems to act consistently). I agree that all of these should exist -- but in the interim, here's an easy way to move from polynomials to symbolic expressions: sage: R.x = ZZ[] sage: f = x**10-1 sage: y = var('y',ns=1) sage: type(f) type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' sage: f(y) y^10 - 1 sage: type(f(y)) type 'sage.symbolic.expression.Expression' Maybe some of that is useful ... -cc --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Factorization class
On Dec 3, 2008, at 1:03 AM, Craig Citro wrote: Thanks. That works, but Sage automatically expands things so you need to do, [(i^j).factor() for i,j in f] To ensure that each polynomial term is shown factorized. Do you want a list of pairs of the form (p,e) for each term in the factorization of f? (That's actually how the factorization is stored internally, so there's definitely no need to call back into factor to do this.) Is this what you'd want? sage: R.x = ZZ[] sage: f = x**10-1 sage: F = f.factor() ; F (x - 1) * (x + 1) * (x^4 - x^3 + x^2 - x + 1) * (x^4 + x^3 + x^2 + x + 1) sage: list(F) [(x - 1, 1), (x + 1, 1), (x^4 - x^3 + x^2 - x + 1, 1), (x^4 + x^3 + x^2 + x + 1, 1)] No, because I want instead of something like [(x-2,2),(x-3,3)] I'd like [(x-2)^2,(x-3)^3] because I'd like to use these as input to a partial fraction expansion routine (which unfortunately, you can't do right now). What I'm doing is working through Manuel Bronstein's symbolic integration book. In it, he builds up the tools necessary to do integration and these are part of it. I know you also wanted a nice way to move between symbolic expressions and polynomials (or, alternately, a partial fraction decomposition on fraction fields of polynomial rings that seems to act consistently). I agree that all of these should exist -- but in the interim, here's an easy way to move from polynomials to symbolic expressions: sage: R.x = ZZ[] sage: f = x**10-1 sage: y = var('y',ns=1) sage: type(f) type 'sage .rings .polynomial .polynomial_integer_dense_flint.Polynomial_integer_dense_flint' sage: f(y) y^10 - 1 sage: type(f(y)) type 'sage.symbolic.expression.Expression' Maybe some of that is useful ... Oh, that is useful. Thanks. I wonder about going the reverse direction. Cheers, Tim. --- Tim Lahey PhD Candidate, Systems Design Engineering University of Waterloo http://www.linkedin.com/in/timlahey smime.p7s Description: S/MIME cryptographic signature