Sage: Ticket #25836: in PrincipalIdealDomains() and in UniqueFactorizationDomains() give wrong answers
https://trac.sagemath.org/ticket/25836
<p>
One of the tests in <code>src/sage/categories/principal_ideal_domains.py</code> (lines 80-83) is testing that the following ring is not a UFD
</p>
<div class="wiki-code"><div class="code"><pre>sage<span class="p">:</span> K <span class="o">=</span> QuadraticField<span class="p">(</span><span class="mi">5</span><span class="p">)</span>
sage<span class="p">:</span> O <span class="o">=</span> K<span class="o">.</span>maximal_order<span class="p">()</span>
sage<span class="p">:</span> O <span class="ow">in</span> UniqueFactorizationDomains<span class="p">()</span>
<span class="bp">False</span>
</pre></div></div><p>
However, trying rings of integers of number fields, which are UFDs or PIDs still gives false as an answer.
</p>
<div class="wiki-code"><div class="code"><pre>sage<span class="p">:</span> K <span class="o">=</span> QuadraticField<span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
sage<span class="p">:</span> O <span class="o">=</span> K<span class="o">.</span>maximal_order<span class="p">()</span>
sage<span class="p">:</span> O <span class="ow">in</span> UniqueFactorizationDomains<span class="p">()</span>
<span class="bp">False</span>
sage<span class="p">:</span> O <span class="ow">in</span> PrincipalIdealDomains<span class="p">()</span>
<span class="bp">False</span>
</pre></div></div>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/25836
Trac 1.1.6nbruinWed, 11 Jul 2018 22:25:59 GMT
https://trac.sagemath.org/ticket/25836#comment:1
https://trac.sagemath.org/ticket/25836#comment:1
<p>
That's an interesting example, since the integer ring of <code>Q(\sqrt(5))</code> is actually a UFD and a PID.
</p>
<p>
Looking at the code of <code>UniqueFactorizationDomains().__contains__</code> one can see that any non-trivial functionality should go into O.is_unique_factorization_domain(). In this case the implementation could be <code>return self.class_number() == 1</code>. However, such a method isn't there, so you're seeing a true/false based on the stored categorical info, and integer rings are not categorically UFDs.
</p>
<p>
There may be bad ramifications from answering <code>UniqueFactorizationDomains().__contains__</code> via a probably very expensive class group computation, so there might be good practical reasons why a more functional <code>is_unique_factorization_domain</code> method isn't provided.
</p>
<p>
In any case, it may be worth changing the example to <code>K=QuadraticField(-5)</code> or so. It looks a bit silly to use a mathematically UFD in a setting to illustrate non-UFD behaviour.
</p>
<p>
I also don't see how <code>PolynomialRing(O,'x')</code> can be a PID: the ideal <code>(7,x)</code> is really not principal. Were these doctests written by a non-mathematician?
</p>
Ticket