If you look at the source code (line 400 of sage/structure/ factorization.py) you can see how Sage compares a Factorization object with something else:
(1) If the other thing is not a Factorization it will give false; else (2) it compares the expansions of both (i.e. multiplies them out & then compares); else (3) compares the factorizations term by term. You are suggestion that when a Factorization is compared with something which is not a Factorization, the Factorization is first multiplied out and then the result is compared with the other thing. That has some merits that I can see, and would be easy to implement. But of course, if this was implemented then in both your examples expand(fac_f)==f would return True. You could always use p.is_irreducible instead! John Cremona On Feb 27, 1:56 am, Nathaniel Troutman <[email protected]> wrote: > I'm new to sage and was introduced to it this semester in my > Cryptography course as being a python friendly alternative to Pari/GP. > So playing around with it I was factoring polynomials over GF(2) and > trying to make a quick function to generate random polynomials and > return if they were reducible, without me actually visually inspecting > the factorization. For the sake of giving an example I'll just define > a couple of polynomials: > > sage: R.<x> = PolynomialRing(GF(2)) > sage: p = x^30 + x^21 + 1 > sage: q = x^30 + x^14 + 1 > sage: fac_p = factor(p); fac_p > x^30 + x^21 + 1 > sage: fac_q = factor(q); fac_q > (x^15 + x^7 + 1)^2 > > Now here is the interesting bit: > > sage: fac_q == q # should return False > False > sage: fac_p == p # would expect True > False > > What!? But p is irreducible, its factorization should be itself. After > much digging around and thinking about things from a programmers > perspective rather than a mathematics perspective the idea that > factorizations are lists of factors and why comparing a factorization > to a polynomial doesn't work. However, I would contend that the > comparison does in fact make intuitive sense. So, perhaps comparison > testing for Factorizations and Polynomials should be a bit more > "intelligent" or at least provide some easy way of comparing them in > the intuitive sense of compare. After all this does work: > > sage: fac_p[0][0] == p > True > > And that would only hold true (as far as I know) if the polynomial was > irreducible. -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
