oscar-system / Oscar.jl

A comprehensive open source computer algebra system for computations in algebra, geometry, and number theory.
https://www.oscar-system.org
Other
345 stars 126 forks source link

Finite field constructors should add sanity checks #1491

Closed Krastanov closed 8 months ago

Krastanov commented 2 years ago

Describe the bug roots on a Polynomial over finite field raises an error if the polynomial has a root at 0

To Reproduce

using Oscar
𝔽q , unit = FiniteField(ZZ(4),1)
p, x = PolynomialRing(𝔽q, "x")
roots(x+1) # works fine
roots(x) # works fine
roots(x*(x+1)) # error
roots(x^2+x) # error

The errors look like

Exception (fq_inv).  Zero is not invertible.
ERROR: Problem in the Flint-Subsystem
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] flint_abort()
   @ Nemo ~/.julia/packages/Nemo/CAQZ6/src/Nemo.jl:97
 [3] _factor(x::fq_poly)
   @ Nemo ~/.julia/packages/Nemo/CAQZ6/src/flint/fq_poly.jl:616
 [4] factor
   @ ~/.julia/packages/Nemo/CAQZ6/src/flint/fq_poly.jl:607 [inlined]
 [5] #factor#748
   @ ~/.julia/packages/Hecke/WPhuW/src/Misc/Integer.jl:721 [inlined]
 [6] factor
   @ ~/.julia/packages/Hecke/WPhuW/src/Misc/Integer.jl:721 [inlined]
 [7] roots(f::fq_poly)
   @ Hecke ~/.julia/packages/Hecke/WPhuW/src/Misc/Poly.jl:649
 [8] top-level scope
   @ ~/Documents/ScratchSpace/clifford/ldpc.jl:137

Expected behavior roots(x^2+x) should return fq[0,3] (note, 3=-1 for the field in question, but this happens for other fields too)

System (please complete the following information):

OSCAR version 0.10.0
  combining:
    AbstractAlgebra.jl   v0.26.0
    GAP.jl               v0.8.1
    Hecke.jl             v0.14.10
    Nemo.jl              v0.31.1
    Polymake.jl          v0.8.0
    Singular.jl          v0.10.2
  building on:
    Antic_jll               v0.200.501+0
    Arb_jll                 v200.2200.0+0
    Calcium_jll             v0.400.102+0
    FLINT_jll               v200.800.500+0
    GAP_jll                 v400.1192.2+1
    Singular_jll            v403.1.300+0
    libpolymake_julia_jll   v0.8.0+2
    libsingular_julia_jll   v0.23.1+0
    msolve_jll              v0.2.3+1
    polymake_jll            v400.600.0+0
See `]st -m` for a full list of dependencies.

Julia Version 1.9.0-DEV.998
Commit e1739aa42a1 (2022-07-18 10:27 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 1700 Eight-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.5 (ORCJIT, znver1)
  Threads: 8 on 16 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8
Official https://julialang.org/ release

Additional context

I am trying to play with algebraic tori and Cayley graphs over PSL_2(F_q). I have little understanding of that field of math, so maybe I am doing something wrong. I am following section 5 of "Existence and Explicit Constructions of q + 1 Regular Ramanujan Graphs for Every Prime Power q" by Morgenstern, where I need to enumerate the roots of certain polynomials of Fq. If there is a trivial way to do that with Oscar, do point me to it :D

thofma commented 2 years ago

Thanks for the report. I will have a look.

Krastanov commented 2 years ago

The problem pops up in is_irreducible too:

    p = 2
    l = 4
    q = p^l
    𝔽q , unit = FiniteField(ZZ(q),1)
    R𝔽q, x = PolynomialRing(𝔽q, "x")
julia> roots(2*x^2 + 11*x + 10)
fq[]

julia> is_irreducible(2*x^2 + 11*x + 10)
Exception (fq_inv).  Zero is not invertible.
ERROR: Problem in the Flint-Subsystem

Probably not surprising, but wanted to mention it just in case.

tthsqe12 commented 2 years ago

Finite fields are created with the arguments (p,l), not the arguments (p^l,1)

Krastanov commented 2 years ago

Indeed, I just discovered that was the problem.

Is this still a bug though? If the correct way to create the field is FiniteField(2,5), then why is FiniteField(ZZ(2^5), 1) even working? Does FiniteField(ZZ(2^5), 1) have any meaning or is it just an omission of input sanitation?

tthsqe12 commented 2 years ago

FF(4,1) is clearly not working (eventually). We don't throw an error sooner because primality checking is off in the FF constructor.

Krastanov commented 2 years ago

In that case I believe I should close this issue. Feel free to reopen it as an "add input sanitation" enhancement request if that makes sense.

thofma commented 2 years ago

We definitely should do the input check (with an optional check parameter to turn it off).

fingolfin commented 8 months ago

We now do this (I think thanks to @thofma ):

julia> finite_field(4,1)
ERROR: Characteristic must be prime