Opened 18 months ago
Last modified 4 weeks ago
#28786 new defect
Better warn users against creating finite field with modulus not a polynomial
Reported by: | dimpase | Owned by: | |
---|---|---|---|
Priority: | critical | Milestone: | sage-9.4 |
Component: | finite rings | Keywords: | |
Cc: | slelievre | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
Before this ticket:
sage: K.<a> = GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1) sage: x = a^9 sage: K.<a> = GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1) Traceback (most recent call last): ... ValueError: the degree of the modulus does not equal the degree of the field
Initial report.
Run the following fragment twice in the same Sage session.
sage: K.<a> = GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1) sage: x = a^9 sage: y = a^21 sage: z = 1/x sage: v = vector([y^i for i in range(7)]) sage: S = matrix([[(z^i)^j for j in range(7)] for i in range(7)]) sage: w = S*v sage: w
The 1st run succeeds, the 2nd and later runs produce
ValueError Traceback (most recent call last) <ipython-input-7-e412ac7787ee> in <module>() ----> 1 K = GF(Integer(2)**Integer(6), modulus=x**Integer(6) + x**Integer(4) + x**Integer(3) + x + Integer(1), names=('a',)); (a,) = K._first_ngens(1) 2 x = a**Integer(9) 3 y = a**Integer(21) 4 z = Integer(1)/x 5 v = vector([y^i for i in range(Integer(7))]) /mnt/opt/Sage/sage-dev/local/lib/python3.7/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2162)() 365 False 366 """ --> 367 key, kwds = self.create_key_and_extra_args(*args, **kwds) 368 version = self.get_version(sage_version) 369 return self.get_object(version, key, kwds) /mnt/opt/Sage/sage-dev/local/lib/python3.7/site-packages/sage/rings/finite_rings/finite_field_constructor.py in create_key_and_extra_args(self, order, name, modulus, names, impl, proof, check_irreducible, prefix, repr, elem_cache, **kwds) 583 584 if modulus.degree() != n: --> 585 raise ValueError("the degree of the modulus does not equal the degree of the field") 586 if check_irreducible and not modulus.is_irreducible(): 587 raise ValueError("finite field modulus must be irreducible but it is not") ValueError: the degree of the modulus does not equal the degree of the field
Note that this does not happen if modulus is not given.
This is a variable name clash. Somehow, using 'x' for modulus creates a problem.
If I instead define K
as
sage: T.<xx> = GF(2)[] sage: K.<a> = GF(2^6, modulus=xx^6 + xx^4 + xx^3 + xx + 1)
then everything works as expected.
Change History (8)
comment:1 Changed 18 months ago by
- Description modified (diff)
comment:2 Changed 18 months ago by
comment:3 follow-up: ↓ 7 Changed 18 months ago by
I don't think this is a bug. On the first run, you're taking advantage of the fact that x
is predefined as a symbolic variable (and indeed, it's the only such variable). The constructor for finite fields can take elements of the symbolic ring, though polynomials are better. On the second, you've redefined x
.
The error is triggered by just the following lines:
K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1) x = a^9 K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)
Perhaps a better error message in the case that modulus is a finite field element would be appropriate.
comment:4 Changed 16 months ago by
- Milestone changed from sage-9.0 to sage-9.1
Ticket retargeted after milestone closed
comment:5 Changed 12 months ago by
- Milestone changed from sage-9.1 to sage-9.2
comment:6 Changed 7 months ago by
- Milestone changed from sage-9.2 to sage-9.3
comment:7 in reply to: ↑ 3 Changed 7 weeks ago by
- Cc slelievre added
- Description modified (diff)
- Summary changed from breakage in finite field with explicit modulus to Better warn users against creating finite field with modulus not a polynomial
Replying to roed:
I don't think this is a bug. [...]
The error is triggered by just the following lines:
K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1) x = a^9 K.<a>=GF(2^6, modulus=x^6 + x^4 + x^3 + x + 1)Perhaps a better error message in the case that modulus is a finite field element would be appropriate.
I agree. This ticket could do one or both of the following:
- include a cautionary example in the docstring
for
FiniteField
(akaGF
) (I recommend that)
- make the error message more helpful, such as: "check that the polynomial variable used in the modulus was indeed a polynomial variable, and not redefined to be a field element for instance" (maybe not needed if the docstring has a cautionary example)
comment:8 Changed 4 weeks ago by
- Milestone changed from sage-9.3 to sage-9.4
Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review.
perhaps making it imposible to use a symbolic variable to define modulus will do the trick. Indeed, if I do
then the error goes away.
Strangely,
x
is the only symbolic variable that is accepted this way. Trying to use a symbolic variable with a different name does not workDoes GF2X do something too smart with
x
?