Skip to content

Commit

Permalink
sagemathgh-39153: Mark several tests as random to avoid test failure
Browse files Browse the repository at this point in the history
    
This fails sometimes in e.g. https://github.com/sagemath/sage/actions/ru
ns/12388661556/job/34580166155?pr=39152#step:10:9714

Marking this as random looks reasonable because one of the test above
(specifying the exact embedding) is also marked as random, and if the
embedding is random then of course the element representation in terms
of the generator `a` should also be random.


More context:

* the first `# random` is added first in https://github.com/sagemath/sag
e/commit/37fc8e88689a0197c5513161b85b8bbadd5630ab#diff-
c63508ebde0716605e6cdac05e43c8945616c2245158d30ff5ae39936ff4d9a0R1892
* then the note that `number_field_elements_from_algebraics` is OS-
dependent ("32 versus 64 bit") is removed at https://github.com/sagemath
/sage/commit/61e4df9fabf9e06a21d75eb6320ab3179bc28096 for reasons I
can't figure out. (how to find out the discussion around a commit? it
was before trac to GitHub migration)

------

Should the entry in `/.github/workflows/ci-conda-known-test-
failures.json` be removed?

```
    "sage.rings.qqbar": {
        "failed": "unreported failure on macOS seen in https://github.co
m/sagemath/sage/actions/runs/9525536510/job/26259809272?pr=37998"
    },
```

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->


------


Other failing tests:

```
TESTS:

Number fields defined by non-monic and non-integral
polynomials are supported (:issue:`252`)::

    sage: K.<a> = NumberField(2*x^4 + 6*x^2 + 1/2)
    sage: K.optimized_subfields()
    [
    (Number Field in a0 with defining polynomial x, Ring morphism:
      From: Number Field in a0 with defining polynomial x
      To:   Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      Defn: 0 |--> 0, None),
    (Number Field in a1 with defining polynomial x^2 - 2*x + 2, Ring
morphism:
      From: Number Field in a1 with defining polynomial x^2 - 2*x + 2
      To:   Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      Defn: a1 |--> a^3 + 7/2*a + 1, None),
    (Number Field in a2 with defining polynomial x^2 - 2*x + 2, Ring
morphism:
      From: Number Field in a2 with defining polynomial x^2 - 2*x + 2
      To:   Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      Defn: a2 |--> -a^3 - 7/2*a + 1, None),
    (Number Field in a3 with defining polynomial x^2 - 2, Ring morphism:
      From: Number Field in a3 with defining polynomial x^2 - 2
      To:   Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      Defn: a3 |--> a^2 + 3/2, None),
    (Number Field in a4 with defining polynomial x^2 + 1, Ring morphism:
      From: Number Field in a4 with defining polynomial x^2 + 1
      To:   Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      Defn: a4 |--> a^3 + 7/2*a, None),
    (Number Field in a5 with defining polynomial x^2 + 2, Ring morphism:
      From: Number Field in a5 with defining polynomial x^2 + 2
      To:   Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      Defn: a5 |--> 2*a^3 + 5*a, None),
    (Number Field in a6 with defining polynomial x^4 + 1, Ring morphism:
      From: Number Field in a6 with defining polynomial x^4 + 1
      To:   Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      Defn: a6 |--> a^3 + 1/2*a^2 + 5/2*a + 3/4, Ring morphism:
      From: Number Field in a with defining polynomial 2*x^4 + 6*x^2 +
1/2
      To:   Number Field in a6 with defining polynomial x^4 + 1
      Defn: a |--> -1/2*a6^3 + a6^2 - 1/2*a6)
    ]
```

I look into what determines the ordering.
It uses `_subfields_helper` which uses either `f.polred(2)` or
`f.nfsubfields(degree)`,
and there's no sorting going on.

Conclusion: marking as `random sort order` is fine. In fact it doesn't
even say which subfields
should be returned exactly, and other tests in that function are marked
as `# random` anyway,
so marking as `# random` is fine.

------

```
2024-12-18T08:35:49.0399180Z File
"src/sage/rings/number_field/number_field.py", line 8777, in
sage.rings.number_field.number_field.NumberField_absolute.subfields
2024-12-18T08:35:49.0500510Z Failed example:
2024-12-18T08:35:49.0601390Z     K.subfields()
2024-12-18T08:35:49.0707380Z Expected:
2024-12-18T08:35:49.0829700Z     [
2024-12-18T08:35:49.1013090Z     (Number Field in a0 with defining
polynomial x, Ring morphism:
2024-12-18T08:35:49.1114120Z       From: Number Field in a0 with
defining polynomial x
2024-12-18T08:35:49.1215190Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.1319910Z       Defn: 0 |--> 0, None),
2024-12-18T08:35:49.1426370Z     (Number Field in a1 with defining
polynomial x^2 - 2, Ring morphism:
2024-12-18T08:35:49.1528730Z       From: Number Field in a1 with
defining polynomial x^2 - 2
2024-12-18T08:35:49.1631010Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.1659980Z       Defn: a1 |--> a^2 + 3/2, None),
2024-12-18T08:35:49.1761220Z     (Number Field in a2 with defining
polynomial x^2 + 4, Ring morphism:
2024-12-18T08:35:49.1862420Z       From: Number Field in a2 with
defining polynomial x^2 + 4
2024-12-18T08:35:49.1970640Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.2072220Z       Defn: a2 |--> 2*a^3 + 7*a, None),
2024-12-18T08:35:49.2173950Z     (Number Field in a3 with defining
polynomial x^2 + 2, Ring morphism:
2024-12-18T08:35:49.2275370Z       From: Number Field in a3 with
defining polynomial x^2 + 2
2024-12-18T08:35:49.2368240Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.2476650Z       Defn: a3 |--> 2*a^3 + 5*a, None),
2024-12-18T08:35:49.2570570Z     (Number Field in a4 with defining
polynomial x^4 + 1, Ring morphism:
2024-12-18T08:35:49.2672100Z       From: Number Field in a4 with
defining polynomial x^4 + 1
2024-12-18T08:35:49.2774030Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.2875400Z       Defn: a4 |--> a^3 + 1/2*a^2 + 5/2*a +
3/4, Ring morphism:
2024-12-18T08:35:49.2977450Z       From: Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.3080080Z       To:   Number Field in a4 with
defining polynomial x^4 + 1
2024-12-18T08:35:49.3179890Z       Defn: a |--> -1/2*a4^3 + a4^2 -
1/2*a4)
2024-12-18T08:35:49.3281410Z     ]
2024-12-18T08:35:49.3382370Z Got:
2024-12-18T08:35:49.3483260Z     [
2024-12-18T08:35:49.3584610Z     (Number Field in a0 with defining
polynomial x, Ring morphism:
2024-12-18T08:35:49.3643330Z       From: Number Field in a0 with
defining polynomial x
2024-12-18T08:35:49.3714430Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.3816090Z       Defn: 0 |--> 0, None),
2024-12-18T08:35:49.3923670Z     (Number Field in a1 with defining
polynomial x^2 - 2, Ring morphism:
2024-12-18T08:35:49.4037810Z       From: Number Field in a1 with
defining polynomial x^2 - 2
2024-12-18T08:35:49.4142230Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.4289560Z       Defn: a1 |--> -a^2 - 3/2, None),
2024-12-18T08:35:49.4391330Z     (Number Field in a2 with defining
polynomial x^2 + 4, Ring morphism:
2024-12-18T08:35:49.4492300Z       From: Number Field in a2 with
defining polynomial x^2 + 4
2024-12-18T08:35:49.4602960Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.4705310Z       Defn: a2 |--> -2*a^3 - 7*a, None),
2024-12-18T08:35:49.4793770Z     (Number Field in a3 with defining
polynomial x^2 + 2, Ring morphism:
2024-12-18T08:35:49.4794540Z       From: Number Field in a3 with
defining polynomial x^2 + 2
2024-12-18T08:35:49.4795030Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.4795830Z       Defn: a3 |--> 2*a^3 + 5*a, None),
2024-12-18T08:35:49.4796320Z     (Number Field in a4 with defining
polynomial x^4 + 1, Ring morphism:
2024-12-18T08:35:49.4796780Z       From: Number Field in a4 with
defining polynomial x^4 + 1
2024-12-18T08:35:49.4797230Z       To:   Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.4797760Z       Defn: a4 |--> a^3 - 1/2*a^2 + 5/2*a -
3/4, Ring morphism:
2024-12-18T08:35:49.4798180Z       From: Number Field in a with defining
polynomial 2*x^4 + 6*x^2 + 1/2
2024-12-18T08:35:49.4852940Z       To:   Number Field in a4 with
defining polynomial x^4 + 1
2024-12-18T08:35:49.4987040Z       Defn: a |--> -1/2*a4^3 - a4^2 -
1/2*a4)
2024-12-18T08:35:49.5088200Z     ]
```

Uses https://pari.math.u-
bordeaux.fr/dochtml/html/General_number_fields.html#se:nfsubfields
internally. It doesn't state any resulting sort order, so I just reorder
them (the discriminants are all distincts so it's fine).

Alternatively it looks like just doctest against the `set()` of it might
work.

------
    
URL: sagemath#39153
Reported by: user202729
Reviewer(s): Tobias Diez
  • Loading branch information
Release Manager committed Dec 23, 2024
2 parents c9dd1e8 + 8f58440 commit 3fd448a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
62 changes: 35 additions & 27 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -8661,7 +8661,7 @@ def optimized_subfields(self, degree=0, name=None, both_maps=True):
polynomials are supported (:issue:`252`)::
sage: K.<a> = NumberField(2*x^4 + 6*x^2 + 1/2)
sage: K.optimized_subfields()
sage: K.optimized_subfields() # random
[
(Number Field in a0 with defining polynomial x, Ring morphism:
From: Number Field in a0 with defining polynomial x
Expand Down Expand Up @@ -8773,32 +8773,40 @@ def subfields(self, degree=0, name=None):
polynomials are supported (:issue:`252`)::
sage: K.<a> = NumberField(2*x^4 + 6*x^2 + 1/2)
sage: K.subfields()
[
(Number Field in a0 with defining polynomial x, Ring morphism:
From: Number Field in a0 with defining polynomial x
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: 0 |--> 0, None),
(Number Field in a1 with defining polynomial x^2 - 2, Ring morphism:
From: Number Field in a1 with defining polynomial x^2 - 2
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a1 |--> a^2 + 3/2, None),
(Number Field in a2 with defining polynomial x^2 + 4, Ring morphism:
From: Number Field in a2 with defining polynomial x^2 + 4
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a2 |--> 2*a^3 + 7*a, None),
(Number Field in a3 with defining polynomial x^2 + 2, Ring morphism:
From: Number Field in a3 with defining polynomial x^2 + 2
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a3 |--> 2*a^3 + 5*a, None),
(Number Field in a4 with defining polynomial x^4 + 1, Ring morphism:
From: Number Field in a4 with defining polynomial x^4 + 1
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a4 |--> a^3 + 1/2*a^2 + 5/2*a + 3/4, Ring morphism:
From: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
To: Number Field in a4 with defining polynomial x^4 + 1
Defn: a |--> -1/2*a4^3 + a4^2 - 1/2*a4)
]
sage: sorted(K.subfields(), key=lambda x: x[0].discriminant())
[(Number Field in a3 with defining polynomial x^2 + 2,
Ring morphism:
From: Number Field in a3 with defining polynomial x^2 + 2
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a3 |--> 2*a^3 + 5*a,
None),
(Number Field in a2 with defining polynomial x^2 + 4,
Ring morphism:
From: Number Field in a2 with defining polynomial x^2 + 4
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a2 |--> 2*a^3 + 7*a,
None),
(Number Field in a0 with defining polynomial x,
Ring morphism:
From: Number Field in a0 with defining polynomial x
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: 0 |--> 0,
None),
(Number Field in a1 with defining polynomial x^2 - 2,
Ring morphism:
From: Number Field in a1 with defining polynomial x^2 - 2
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a1 |--> a^2 + 3/2,
None),
(Number Field in a4 with defining polynomial x^4 + 1,
Ring morphism:
From: Number Field in a4 with defining polynomial x^4 + 1
To: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
Defn: a4 |--> a^3 + 1/2*a^2 + 5/2*a + 3/4,
Ring morphism:
From: Number Field in a with defining polynomial 2*x^4 + 6*x^2 + 1/2
To: Number Field in a4 with defining polynomial x^4 + 1
Defn: a |--> -1/2*a4^3 + a4^2 - 1/2*a4)]
"""
return self._subfields_helper(degree=degree, name=name,
both_maps=True, optimize=False)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2711,7 +2711,7 @@ def number_field_elements_from_algebraics(numbers, minimal=False,
-1
sage: nfI^2
-1
sage: sum = nfrt2 + nfrt3 + nfI + nfz3; sum
sage: sum = nfrt2 + nfrt3 + nfI + nfz3; sum # random
a^5 + a^4 - a^3 + 2*a^2 - a - 1
sage: hom(sum)
2.646264369941973? + 1.866025403784439?*I
Expand Down

0 comments on commit 3fd448a

Please sign in to comment.