ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 13 Oct 2017 15:38:57 -0500Why 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.
Wed, 11 Oct 2017 14:50:44 -0500https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/Comment by Richard_L for <p>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. </p>
<pre><code> 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
</code></pre>
<p>I would have expected 0.factor() to give 0.</p>
https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39157#post-id-39157Thanks. In future I will bracket this pattern with a conditional to avoid the Traceback.Fri, 13 Oct 2017 15:38:57 -0500https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39157#post-id-39157Comment by John Palmieri for <p>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. </p>
<pre><code> 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
</code></pre>
<p>I would have expected 0.factor() to give 0.</p>
https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39155#post-id-39155It's not dumped into the integer ring, but rather converted to a polynomial with rational coefficients (line 10812 in symbolic/expression.pyx). This polynomial happens to be zero, and Sage code declares that the zero polynomial cannot be factored. (Note that if you try `(a-b+6).factor()`, the answer will be 6, not 2*3: the factorization is done over QQ.)Fri, 13 Oct 2017 12:46:59 -0500https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39155#post-id-39155Comment by Richard_L for <p>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. </p>
<pre><code> 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
</code></pre>
<p>I would have expected 0.factor() to give 0.</p>
https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39147#post-id-39147My surprise arises from working in the symbolic ring and being unexpectedly dumped into the integer ring, thereby triggering and error. Annoying.Thu, 12 Oct 2017 16:29:55 -0500https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39147#post-id-39147Comment by dan_fulea for <p>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. </p>
<pre><code> 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
</code></pre>
<p>I would have expected 0.factor() to give 0.</p>
https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39129#post-id-39129A closer look at `0.factor??` shows that this case should not occur:
INPUT:
- ``n`` - an nonzero integer
From my point of view, the implementer was blessed to translate "factorization" as "**prime** factor decomposition". (With recorded unit.) And zero is not a prime. Note that a factorization object is more complicated, for instance:
sage: f = (-12).factor()
sage: f.__dict__
{'_Factorization__cr': False,
'_Factorization__unit': -1,
'_Factorization__universe': Integer Ring,
'_Factorization__x': [(2, 2), (3, 1)]}
sage: print f
-1 * 2^2 * 3
so there is a difference between the "printed factorization" and the "factorization object" with the above hidden dictionary representation.Wed, 11 Oct 2017 16:26:55 -0500https://ask.sagemath.org/question/39127/why-can-one-not-factor-0/?comment=39129#post-id-39129