diff --git a/.gitignore b/.gitignore index de729c50b..f1f3455b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /docs/build/ Manifest.toml .DS_Store + +FLINT-3.2.0-rc1/ diff --git a/Project.toml b/Project.toml index 69722ccf0..ee7a11859 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" FLINT_jll = "e134572f-a0d5-539d-bddf-3cad8db41a82" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" RandomExtensions = "fb686558-2515-59ef-acaa-46db3789a887" SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" @@ -14,9 +15,10 @@ TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" [compat] AbstractAlgebra = "0.44.2" -FLINT_jll = "^300.100.100" +FLINT_jll = "~300.100.301" # should be "~300.200.0" Libdl = "1.6" LinearAlgebra = "1.6" +MacroTools = "0.5.15" Random = "1.6" RandomExtensions = "0.4.2" SHA = "~1.6, ~1.7, 0.7" diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl new file mode 100644 index 000000000..d6071d78d --- /dev/null +++ b/etc/FlintCTypes_template.jl @@ -0,0 +1,58 @@ +############################################################################### +# +# Flint C types +# +############################################################################### + +module FlintC + +using ..Nemo: @flintstruct, FlintStruct + +# +# FLINT configuration and global definitions +# + +const ulong = UInt +const slong = Int + +WORD(n) = Int(n) +UWORD(n) = UInt(n) + +const FLINT_BITS = UInt == UInt64 ? 64 : 32 + + +@include_c_header("flint.h") + +@include_c_header("limb_types.h") + +@include_c_header("nmod_types.h") + +@include_c_header("fmpz_types.h") + +@include_c_header("fmpq_types.h") + +@include_c_header("fmpz_mod_types.h") + +@include_c_header("fq_nmod_types.h") + +@include_c_header("fq_zech_types.h") + +@include_c_header("fq_types.h") + +@include_c_header("gr_types.h") + +@include_c_header("fq_default.h") + +@include_c_header("fq_default_mat.h") + +@include_c_header("fq_default_poly.h") + +@include_c_header("fq_default_poly_factor.h") + +@include_c_header("padic_types.h") + +@include_c_header("n_poly_types.h") + +@include_c_header("mpoly_types.h") + +end # module FlintC diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl new file mode 100644 index 000000000..7f65125a0 --- /dev/null +++ b/etc/generate_FLINT_structs.jl @@ -0,0 +1,189 @@ +VERSION >= v"1.9" || error("This script requires Julia 1.7 or later") + +function expand_templates(input, flintdir) + matches = eachmatch(r"^@include_c_header\(\"([A-Za-z_.]+)\"\)$"m, input) + substitutions = Pair{String,String}[] + for m in matches + filename = m.captures[1] + @info "Including header \"$filename\"" + template_key = "@include_c_header(\"$filename\")" + + # Read the file + content = open(joinpath(flintdir, filename)) do headerfile + read(headerfile, String) + end + # Convert to julia + translated_content = c2julia(content) + # Build the substitution value + template_val = + "###############################################################################\n" * + "# begin $filename\n\n" * + strip(translated_content) * + "\n\n# end $filename\n" * + "###############################################################################\n" + push!(substitutions, template_key => template_val) + end + return replace(input, substitutions...) +end + +const regex_typedef_struct_fields_name = r"^typedef struct\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m +const regex_typedef_struct_fields_refname = r"^typedef struct\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+)\[1\];"m +const regex_struct_structname_fields = r"^struct *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*;"m +const regex_struct_structname = r"^struct *([A-Za-z0-9_]+);"m +const regex_typedef_struct_structname_fields_name = r"^typedef struct *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m + +const regex_typedef_enum_values_name = r"^typedef enum\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m +const regex_enum_enumname_values = r"^enum *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*;"m +const regex_typedef_enum_enumname_values_name = r"^typedef enum *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m + +const regex_typedef_union_values_name = r"^typedef union\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m +const regex_union_unionname_values = r"^union *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*;"m +const regex_typedef_union_unionname_values_name = r"^typedef union *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m + +function convert_struct(str::AbstractString) + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ + regex_typedef_struct_fields_name => s"@flintstruct struct \2\1end", # whole typedef struct construct + regex_struct_structname_fields => s"@flintstruct struct struct_\1\2end", # whole struct construct + regex_struct_structname => s"@flintstruct struct struct_\1 end", # whole struct construct without fields + regex_typedef_struct_fields_refname => s"@flintstruct struct struct_\2\1end\nconst \2 = Tuple{struct_\2}", # whole typedef struct singleton array construct + regex_typedef_struct_structname_fields_name => s"@flintstruct struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1", + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1", + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1\n \6::\1", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}", # pointer field (one to five declared on one line) + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}\n \6::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{Ptr{\1}}", # double pointer field + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+)\[([A-Za-z0-9_]+)\];"m => s" \2::NTuple{\3, \1}", # fixed len array field + r"^ +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s" \1::Ptr{Cvoid}", # function pointer field + r"^ +struct *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::struct_\1", # struct field (without typedef) + r"^ +enum *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::enum_\1", # enum field (without typedef) + ] + for substitution in substitutions + str = replace(str, substitution) + end + return str +end + +function convert_enum(str::AbstractString) + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ + regex_typedef_enum_values_name => s"@enum \2 begin\1end", # whole typedef enum construct + regex_enum_enumname_values => s"@enum enum_\1 begin\2end", # whole enum construct + regex_typedef_enum_enumname_values_name => s"@enum \3 begin\2end\nconst enum_\1 = \3", # whole typedef enum construct with two names + r"^ +([A-Za-z0-9_]+),?"m => s" \1", # simple enum values + ] + for substitution in substitutions + str = replace(str, substitution) + end + return str +end + +function convert_union(str::AbstractString) + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ + regex_typedef_union_values_name => s"struct \2\n uniondata::NTuple{maximum(sizeof, (\1 )), UInt8}\nend", # whole typedef union construct + regex_union_unionname_values => s"struct union_\1\n uniondata::NTuple{maximum(sizeof, (\2 )), UInt8}\nend", # whole union construct + regex_typedef_union_unionname_values_name => s"struct \3\n uniondata::NTuple{maximum(sizeof, (\2 )), UInt8}\nend\nconst union_\1 = \3", # whole typedef union construct with two names + r"^ +([a-z_]+) +([A-Za-z0-9_]+);"m => s" \1,", + ] + for substitution in substitutions + str = replace(str, substitution) + end + return str +end + +function c2julia(str::String) + preprocessing = Pair{Regex,String}[ + r"^//(.*)$"m => "", # remove line comment + r"/\*(.*?)\*/"s => "", # remove block comment + r" const " => " ", # remove all `const` + r"\bvoid\b" => "Cvoid", # replace `void` C type + r"\bunsigned int\b" => "Cuint", # replace `unsigned int` C type + r"\bint\b" => "Cint", # replace `int` C type + r"\bunsigned char\b" => "Cuchar", # replace `unsigned char` C type + r"\bchar\b" => "Cchar", # replace `char` C type + r"\bdouble\b" => "Cdouble", # replace `double` C type + ] + for substitution in preprocessing + str = replace(str, substitution) + end + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ + regex_typedef_struct_fields_name => convert_struct, # whole typedef struct construct + regex_typedef_struct_fields_refname => convert_struct, # whole typedef struct singleton array construct + regex_struct_structname_fields => convert_struct, # whole struct construct + regex_struct_structname => convert_struct, # whole struct construct without fields + regex_typedef_struct_structname_fields_name => convert_struct, # whole typedef struct construct with two names + regex_typedef_enum_values_name => convert_enum, # whole typedef enum construct + regex_enum_enumname_values => convert_enum, # whole enum construct + regex_typedef_enum_enumname_values_name => convert_enum, # whole typedef enum construct with two names + regex_typedef_union_values_name => convert_union, # whole typedef union construct + regex_union_unionname_values => convert_union, # whole union construct + regex_typedef_union_unionname_values_name => convert_union, # whole typedef union construct with two names + r"^typedef +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = \1", # simple typedef + r"^typedef +([A-Za-z_]+) *\* *([A-Za-z_]+);"m => s"const \2 = Ptr{\1}", # pointer typedef + r"^typedef +([A-Za-z_]+) +([A-Za-z_]+)\[1\];"m => s"const \2 = Tuple{\1}", # singleton array typedef + r"^typedef +struct +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = struct_\1", # struct typedef + r"^typedef +enum +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = enum_\1", # enum typedef + r"^typedef +union +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = union_\1", # union typedef + r"^typedef +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s"const \1 = Ptr{Cvoid}", # function pointer typedef + r"^#define +([A-Za-z_]+) +(\d+) *$"m => s"const \1 = \2", # defines of integer constants + r"^#define +([A-Za-z_]+) +\(([A-Za-z0-9+*() ]+)\) *$"m => s"const \1 = \2", # defines of more complex constants + ] + combined_regex = Regex(join(map(re -> re.pattern, first.(substitutions)), "|"), "m") + output = join( + map(m -> replace(m.match, substitutions...), eachmatch(combined_regex, str)), "\n\n" + ) + output = replace(output, r"\h*\n" => "\n") # remove trailing whitespace + return output +end + +file_header_notice(FLINT_jll_version) = """ +# Most of this file is generated from FLINT's header files. +# Do not edit manually, only the corresponding `etc/*_template.jl` file should be edited. + +# This file was generated using FLINT_jll v$(FLINT_jll_version). + +""" + +################################################################################ +# +# Main script +# +################################################################################ + +function expand_template_file( + infile::String, outfile::String, flintpath::String, file_header::String +) + @info "Expanding file" infile outfile + open(outfile, "w") do io + write(io, file_header) + write( + io, expand_templates(read(infile, String), joinpath(flintpath, "include", "flint")) + ) + end +end + +function main() + flintpath = FLINT_jll.find_artifact_dir() + flintversion = pkgversion(FLINT_jll) + @info "Found FLINT" flintpath flintversion + + infile = joinpath(nemopath, "etc", "FlintCTypes_template.jl") + outfile = joinpath(nemopath, "src", "flint", "FlintCTypes.jl") + expand_template_file(infile, outfile, flintpath, file_header_notice(flintversion)) +end + +const nemopath = dirname(dirname(@__FILE__)) + +@info "Setting up environment" +using Pkg +ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0 +Pkg.activate(; temp=true) +Pkg.develop(PackageSpec(; path=nemopath)) +Pkg.add("FLINT_jll") # version is fixed by Nemo.jl in the line above +using FLINT_jll + +main() diff --git a/src/Nemo.jl b/src/Nemo.jl index 4b3fef149..611b6ae25 100644 --- a/src/Nemo.jl +++ b/src/Nemo.jl @@ -1,3 +1,5 @@ +# Note to self: Remember to remove the Overrides.toml once FLINT 3.2.0 is released. + @doc raw""" Nemo is a computer algebra package for the Julia programming language, maintained by William Hart, Tommy Hofmann, Claus Fieker and Fredrik Johansson with additional code by Oleksandr Motsak and other contributors. diff --git a/src/flint/FlintCHelpers.jl b/src/flint/FlintCHelpers.jl new file mode 100644 index 000000000..10fcb285e --- /dev/null +++ b/src/flint/FlintCHelpers.jl @@ -0,0 +1,26 @@ +import MacroTools + +abstract type FlintStruct end + +function Base.getproperty(val::FlintStruct, name::Symbol) + if fieldtype(typeof(val), name) <: Tuple{T} where T # unwrap singleton tuples + return only(getfield(val, name)) + else + getfield(val, name) + end +end + +macro flintstruct(structdef::Expr) + structprops = MacroTools.splitstructdef(structdef) + @assert !structprops[:mutable] + @assert isempty(structprops[:params]) + @assert structprops[:supertype] == :Any + + @show structprops + + structprops[:supertype] = :(FlintStruct) + + return esc(quote + $(MacroTools.combinestructdef(structprops)) + end) +end diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl new file mode 100644 index 000000000..db2c09602 --- /dev/null +++ b/src/flint/FlintCTypes.jl @@ -0,0 +1,1108 @@ +# Most of this file is generated from FLINT's header files. +# Do not edit manually, only the corresponding `etc/*_template.jl` file should be edited. + +# This file was generated using FLINT_jll v300.100.301+0. + +############################################################################### +# +# Flint C types +# +############################################################################### + +module FlintC + +using ..Nemo: @flintstruct, FlintStruct + +# +# FLINT configuration and global definitions +# + +const ulong = UInt +const slong = Int + +WORD(n) = Int(n) +UWORD(n) = UInt(n) + +const FLINT_BITS = UInt == UInt64 ? 64 : 32 + + +############################################################################### +# begin flint.h + +const __FLINT_VERSION = 3 + +const __FLINT_VERSION_MINOR = 2 + +const __FLINT_VERSION_PATCHLEVEL = 0 + +@flintstruct struct struct___FLINT_FILE end + +const FLINT_FILE = struct___FLINT_FILE + +const flint_bitcnt_t = ulong + +const nn_ptr = Ptr{ulong} + +const nn_srcptr = Ptr{ulong} + +const flint_cleanup_function_t = Ptr{Cvoid} + +const thread_pool_handle = Cint + +@flintstruct struct flint_rand_struct + __gmp_state::Ptr{Cvoid} + __randval::ulong + __randval2::ulong +end + +const flint_rand_t = Tuple{flint_rand_struct} + +@enum flint_err_t begin + FLINT_ERROR + FLINT_OVERFLOW + FLINT_IMPINV + FLINT_DOMERR + FLINT_DIVZERO + FLINT_EXPOF + FLINT_INEXACT + FLINT_TEST_FAIL +end + +@flintstruct struct nmod_t + n::ulong + ninv::ulong + norm::flint_bitcnt_t +end + +const fmpz = slong + +const fmpz_t = Tuple{fmpz} + +@flintstruct struct fmpq + num::fmpz + den::fmpz +end + +const fmpq_t = Tuple{fmpq} + +const MPZ_MIN_ALLOC = 2 + +# end flint.h +############################################################################### + + +############################################################################### +# begin limb_types.h + +const FLINT_MAX_FACTORS_IN_LIMB = 15 + +@flintstruct struct n_factor_t + num::Cint + exp::NTuple{FLINT_MAX_FACTORS_IN_LIMB, Cint} + p::NTuple{FLINT_MAX_FACTORS_IN_LIMB, ulong} +end + +@flintstruct struct n_primes_struct + small_i::slong + small_num::slong + small_primes::Ptr{Cuint} + + sieve_a::ulong + sieve_b::ulong + sieve_i::slong + sieve_num::slong + sieve::Ptr{Cchar} +end + +const n_primes_t = Tuple{n_primes_struct} + +# end limb_types.h +############################################################################### + + +############################################################################### +# begin nmod_types.h + +@flintstruct struct nmod_mat_struct + entries::Ptr{ulong} + r::slong + c::slong + rows::Ptr{Ptr{ulong}} + mod::nmod_t +end + +const nmod_mat_t = Tuple{nmod_mat_struct} + +@flintstruct struct nmod_poly_struct + coeffs::nn_ptr + alloc::slong + length::slong + mod::nmod_t +end + +const nmod_poly_t = Tuple{nmod_poly_struct} + +@flintstruct struct nmod_poly_factor_struct + p::Ptr{nmod_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const nmod_poly_factor_t = Tuple{nmod_poly_factor_struct} + +@flintstruct struct nmod_poly_mat_struct + entries::Ptr{nmod_poly_struct} + r::slong + c::slong + rows::Ptr{Ptr{nmod_poly_struct}} + modulus::ulong +end + +const nmod_poly_mat_t = Tuple{nmod_poly_mat_struct} + +@flintstruct struct nmod_mpoly_struct + coeffs::Ptr{ulong} + exps::Ptr{ulong} + length::slong + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong +end + +const nmod_mpoly_t = Tuple{nmod_mpoly_struct} + +@flintstruct struct nmod_mpoly_factor_struct + constant::ulong + poly::Ptr{nmod_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const nmod_mpoly_factor_t = Tuple{nmod_mpoly_factor_struct} + +# end nmod_types.h +############################################################################### + + +############################################################################### +# begin fmpz_types.h + +@flintstruct struct zz_struct + alloc::Cint + size::Cint + ptr::nn_ptr +end + +const zz_ptr = Ptr{zz_struct} + +const zz_srcptr = Ptr{zz_struct} + +@flintstruct struct fmpz_factor_struct + sign::Cint + p::Ptr{fmpz} + exp::Ptr{ulong} + alloc::slong + num::slong +end + +const fmpz_factor_t = Tuple{fmpz_factor_struct} + +@flintstruct struct fmpz_preinvn_struct + dinv::nn_ptr + n::slong + norm::flint_bitcnt_t +end + +const fmpz_preinvn_t = Tuple{fmpz_preinvn_struct} + +@flintstruct struct fmpz_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong +end + +const fmpz_poly_t = Tuple{fmpz_poly_struct} + +@flintstruct struct fmpz_poly_factor_struct + c::fmpz + p::Ptr{fmpz_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fmpz_poly_factor_t = Tuple{fmpz_poly_factor_struct} + +@flintstruct struct fmpz_mat_struct + entries::Ptr{fmpz} + r::slong + c::slong + rows::Ptr{Ptr{fmpz}} +end + +const fmpz_mat_t = Tuple{fmpz_mat_struct} + +@flintstruct struct fmpz_poly_mat_struct + entries::Ptr{fmpz_poly_struct} + r::slong + c::slong + rows::Ptr{Ptr{fmpz_poly_struct}} +end + +const fmpz_poly_mat_t = Tuple{fmpz_poly_mat_struct} + +@flintstruct struct fmpz_mpoly_struct + coeffs::Ptr{fmpz} + exps::Ptr{ulong} + alloc::slong + length::slong + bits::flint_bitcnt_t +end + +const fmpz_mpoly_t = Tuple{fmpz_mpoly_struct} + +@flintstruct struct fmpz_mpoly_factor_struct + constant::fmpz_t + constant_den::fmpz_t + poly::Ptr{fmpz_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const fmpz_mpoly_factor_t = Tuple{fmpz_mpoly_factor_struct} + +@flintstruct struct fmpz_poly_q_struct + num::Ptr{fmpz_poly_struct} + den::Ptr{fmpz_poly_struct} +end + +const fmpz_poly_q_t = Tuple{fmpz_poly_q_struct} + +@flintstruct struct fmpz_mpoly_q_struct + num::fmpz_mpoly_struct + den::fmpz_mpoly_struct +end + +const fmpz_mpoly_q_t = Tuple{fmpz_mpoly_q_struct} + +@flintstruct struct fmpzi_struct + a::fmpz + b::fmpz +end + +const fmpzi_t = Tuple{fmpzi_struct} + +# end fmpz_types.h +############################################################################### + + +############################################################################### +# begin fmpq_types.h + +@flintstruct struct fmpq_mat_struct + entries::Ptr{fmpq} + r::slong + c::slong + rows::Ptr{Ptr{fmpq}} +end + +const fmpq_mat_t = Tuple{fmpq_mat_struct} + +@flintstruct struct fmpq_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong + den::fmpz_t +end + +const fmpq_poly_t = Tuple{fmpq_poly_struct} + +@flintstruct struct fmpq_mpoly_struct + content::fmpq_t + zpoly::fmpz_mpoly_t +end + +const fmpq_mpoly_t = Tuple{fmpq_mpoly_struct} + +@flintstruct struct fmpq_mpoly_factor_struct + constant::fmpq_t + poly::Ptr{fmpq_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const fmpq_mpoly_factor_t = Tuple{fmpq_mpoly_factor_struct} + +# end fmpq_types.h +############################################################################### + + +############################################################################### +# begin fmpz_mod_types.h + +@flintstruct struct fmpz_mod_ctx_struct + n::fmpz_t + add_fxn::Ptr{Cvoid} + sub_fxn::Ptr{Cvoid} + mul_fxn::Ptr{Cvoid} + mod::nmod_t + n_limbs::NTuple{3, ulong} + ninv_limbs::NTuple{3, ulong} + ninv_huge::Ptr{fmpz_preinvn_struct} +end +const struct_fmpz_mod_ctx = fmpz_mod_ctx_struct + +const fmpz_mod_ctx_t = Tuple{fmpz_mod_ctx_struct} + +const fmpz_mod_mat_struct = fmpz_mat_struct + +const fmpz_mod_mat_t = Tuple{fmpz_mod_mat_struct} + +@flintstruct struct fmpz_mod_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong +end + +const fmpz_mod_poly_t = Tuple{fmpz_mod_poly_struct} + +@flintstruct struct fmpz_mod_poly_factor_struct + poly::Ptr{fmpz_mod_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fmpz_mod_poly_factor_t = Tuple{fmpz_mod_poly_factor_struct} + +@flintstruct struct fmpz_mod_mpoly_struct + coeffs::Ptr{fmpz} + exps::Ptr{ulong} + length::slong + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong +end + +const fmpz_mod_mpoly_t = Tuple{fmpz_mod_mpoly_struct} + +@flintstruct struct fmpz_mod_mpoly_factor_struct + constant::fmpz_t + poly::Ptr{fmpz_mod_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const fmpz_mod_mpoly_factor_t = Tuple{fmpz_mod_mpoly_factor_struct} + +# end fmpz_mod_types.h +############################################################################### + + +############################################################################### +# begin fq_nmod_types.h + +const fq_nmod_t = nmod_poly_t + +const fq_nmod_struct = nmod_poly_struct + +@flintstruct struct fq_nmod_ctx_struct + mod::nmod_t + + sparse_modulus::Cint + is_conway::Cint + + a::Ptr{ulong} + j::Ptr{slong} + len::slong + + modulus::nmod_poly_t + inv::nmod_poly_t + + var::Ptr{Cchar} +end + +const fq_nmod_ctx_t = Tuple{fq_nmod_ctx_struct} + +@flintstruct struct fq_nmod_mat_struct + entries::Ptr{fq_nmod_struct} + r::slong + c::slong + rows::Ptr{Ptr{fq_nmod_struct}} +end + +const fq_nmod_mat_t = Tuple{fq_nmod_mat_struct} + +@flintstruct struct fq_nmod_poly_struct + coeffs::Ptr{fq_nmod_struct} + alloc::slong + length::slong +end + +const fq_nmod_poly_t = Tuple{fq_nmod_poly_struct} + +@flintstruct struct fq_nmod_poly_factor_struct + poly::Ptr{fq_nmod_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fq_nmod_poly_factor_t = Tuple{fq_nmod_poly_factor_struct} + +@flintstruct struct fq_nmod_mpoly_struct + coeffs::Ptr{ulong} + exps::Ptr{ulong} + length::slong + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong +end + +const fq_nmod_mpoly_t = Tuple{fq_nmod_mpoly_struct} + +# end fq_nmod_types.h +############################################################################### + + +############################################################################### +# begin fq_zech_types.h + +@flintstruct struct fq_zech_struct + value::ulong +end + +const fq_zech_t = Tuple{fq_zech_struct} + +@flintstruct struct fq_zech_ctx_struct + qm1::ulong + qm1o2::ulong + qm1opm1::ulong + p::ulong + ppre::Cdouble + prime_root::ulong + zech_log_table::Ptr{ulong} + prime_field_table::Ptr{ulong} + eval_table::Ptr{ulong} + + fq_nmod_ctx::Ptr{fq_nmod_ctx_struct} + owns_fq_nmod_ctx::Cint + is_conway::Cint +end + +const fq_zech_ctx_t = Tuple{fq_zech_ctx_struct} + +@flintstruct struct fq_zech_mat_struct + entries::Ptr{fq_zech_struct} + r::slong + c::slong + rows::Ptr{Ptr{fq_zech_struct}} +end + +const fq_zech_mat_t = Tuple{fq_zech_mat_struct} + +@flintstruct struct fq_zech_poly_struct + coeffs::Ptr{fq_zech_struct} + alloc::slong + length::slong +end + +const fq_zech_poly_t = Tuple{fq_zech_poly_struct} + +@flintstruct struct fq_zech_poly_factor_struct + poly::Ptr{fq_zech_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fq_zech_poly_factor_t = Tuple{fq_zech_poly_factor_struct} + +# end fq_zech_types.h +############################################################################### + + +############################################################################### +# begin fq_types.h + +const fq_t = fmpz_poly_t + +const fq_struct = fmpz_poly_struct + +@flintstruct struct fq_ctx_struct + ctxp::fmpz_mod_ctx_t + + sparse_modulus::Cint + is_conway::Cint + + a::Ptr{fmpz} + j::Ptr{slong} + len::slong + + modulus::fmpz_mod_poly_t + inv::fmpz_mod_poly_t + + var::Ptr{Cchar} +end + +const fq_ctx_t = Tuple{fq_ctx_struct} + +@flintstruct struct fq_mat_struct + entries::Ptr{fq_struct} + r::slong + c::slong + rows::Ptr{Ptr{fq_struct}} +end + +const fq_mat_t = Tuple{fq_mat_struct} + +@flintstruct struct fq_poly_struct + coeffs::Ptr{fq_struct} + alloc::slong + length::slong +end + +const fq_poly_t = Tuple{fq_poly_struct} + +@flintstruct struct fq_poly_factor_struct + poly::Ptr{fq_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fq_poly_factor_t = Tuple{fq_poly_factor_struct} + +# end fq_types.h +############################################################################### + + +############################################################################### +# begin gr_types.h + +const GR_SUCCESS = 0 + +const GR_DOMAIN = 1 + +const GR_UNABLE = 2 + +const GR_TEST_FAIL = 4 + +@enum truth_t begin + T_TRUE + T_FALSE + T_UNKNOWN +end + +@flintstruct struct gr_stream_struct + fp::Ptr{FLINT_FILE} + s::Ptr{Cchar} + len::slong + alloc::slong +end + +const gr_stream_t = Tuple{gr_stream_struct} + +const gr_funcptr = Ptr{Cvoid} + +const GR_CTX_STRUCT_DATA_BYTES = 6 * sizeof(ulong) + +@flintstruct struct gr_ctx_struct + data::NTuple{GR_CTX_STRUCT_DATA_BYTES, Cchar} + which_ring::ulong + sizeof_elem::slong + methods::Ptr{gr_funcptr} + size_limit::ulong +end + +const gr_ctx_t = Tuple{gr_ctx_struct} + +const gr_ptr = Ptr{Cvoid} + +const gr_srcptr = Ptr{Cvoid} + +const gr_ctx_ptr = Ptr{Cvoid} + +@flintstruct struct gr_vec_struct + entries::gr_ptr + alloc::slong + length::slong +end + +const gr_vec_t = Tuple{gr_vec_struct} + +@flintstruct struct gr_mat_struct + entries::gr_ptr + r::slong + c::slong + rows::Ptr{gr_ptr} +end + +const gr_mat_t = Tuple{gr_mat_struct} + +@flintstruct struct gr_poly_struct + coeffs::gr_ptr + alloc::slong + length::slong +end + +const gr_poly_t = Tuple{gr_poly_struct} + +# end gr_types.h +############################################################################### + + +############################################################################### +# begin fq_default.h + +const FQ_DEFAULT_FQ_ZECH = 1 + +const FQ_DEFAULT_FQ_NMOD = 2 + +const FQ_DEFAULT_FQ = 3 + +const FQ_DEFAULT_NMOD = 4 + +const FQ_DEFAULT_FMPZ_MOD = 5 + +struct fq_default_struct + uniondata::NTuple{maximum(sizeof, ( + fq_t, + fq_nmod_t, + fq_zech_t, + ulong, + fmpz_t, + )), UInt8} +end +const union_fq_default_struct = fq_default_struct + +const fq_default_t = Tuple{fq_default_struct} + +const fq_default_ctx_struct = gr_ctx_struct + +const fq_default_ctx_t = Tuple{fq_default_ctx_struct} + +@flintstruct struct _gr_fmpz_mod_ctx_struct + ctx::Ptr{fmpz_mod_ctx_struct} + is_prime::truth_t + a::fmpz +end + +@flintstruct struct _gr_nmod_ctx_struct + nmod::nmod_t + a::ulong +end + +# end fq_default.h +############################################################################### + + +############################################################################### +# begin fq_default_mat.h + +struct fq_default_mat_struct + uniondata::NTuple{maximum(sizeof, ( + fq_mat_t, + fq_nmod_mat_t, + fq_zech_mat_t, + nmod_mat_t, + fmpz_mod_mat_t, + )), UInt8} +end +const union_fq_default_mat_struct = fq_default_mat_struct + +const fq_default_mat_t = Tuple{fq_default_mat_struct} + +# end fq_default_mat.h +############################################################################### + + +############################################################################### +# begin fq_default_poly.h + +struct fq_default_poly_struct + uniondata::NTuple{maximum(sizeof, ( + fq_poly_t, + fq_nmod_poly_t, + fq_zech_poly_t, + nmod_poly_t, + fmpz_mod_poly_t, + )), UInt8} +end +const union_fq_default_poly_struct = fq_default_poly_struct + +const fq_default_poly_t = Tuple{fq_default_poly_struct} + +# end fq_default_poly.h +############################################################################### + + +############################################################################### +# begin fq_default_poly_factor.h + +struct fq_default_poly_factor_struct + uniondata::NTuple{maximum(sizeof, ( + fq_poly_factor_t, + fq_nmod_poly_factor_t, + fq_zech_poly_factor_t, + nmod_poly_factor_t, + fmpz_mod_poly_factor_t, + )), UInt8} +end +const union_fq_default_poly_factor_struct = fq_default_poly_factor_struct + +const fq_default_poly_factor_t = Tuple{fq_default_poly_factor_struct} + +# end fq_default_poly_factor.h +############################################################################### + + +############################################################################### +# begin padic_types.h + +@flintstruct struct padic_struct + u::fmpz + v::slong + N::slong +end + +const padic_t = Tuple{padic_struct} + +@enum enum_padic_print_mode begin + PADIC_TERSE + PADIC_SERIES + PADIC_VAL_UNIT +end + +@flintstruct struct padic_ctx_struct + p::fmpz_t + pinv::Cdouble + pow::Ptr{fmpz} + min::slong + max::slong + mode::enum_padic_print_mode +end + +const padic_ctx_t = Tuple{padic_ctx_struct} + +@flintstruct struct padic_inv_struct + n::slong + pow::Ptr{fmpz} +end + +const padic_inv_t = Tuple{padic_inv_struct} + +@flintstruct struct padic_mat_struct + mat::fmpz_mat_struct + val::slong + N::slong +end + +const padic_mat_t = Tuple{padic_mat_struct} + +@flintstruct struct padic_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong + val::slong + N::slong +end + +const padic_poly_t = Tuple{padic_poly_struct} + +# end padic_types.h +############################################################################### + + +############################################################################### +# begin n_poly_types.h + +@flintstruct struct n_poly_struct + coeffs::Ptr{ulong} + alloc::slong + length::slong +end + +const n_poly_t = Tuple{n_poly_struct} + +const n_fq_poly_struct = n_poly_struct + +const n_fq_poly_t = n_poly_t + +@flintstruct struct n_bpoly_struct + coeffs::Ptr{n_poly_struct} + alloc::slong + length::slong +end + +const n_bpoly_t = Tuple{n_bpoly_struct} + +const n_fq_bpoly_struct = n_bpoly_struct + +const n_fq_bpoly_t = n_bpoly_t + +@flintstruct struct n_tpoly_struct + coeffs::Ptr{n_bpoly_struct} + alloc::slong + length::slong +end + +const n_tpoly_t = Tuple{n_tpoly_struct} + +const n_fq_tpoly_struct = n_tpoly_struct + +const n_fq_tpoly_t = n_tpoly_t + +@flintstruct struct n_polyu_struct + exps::Ptr{ulong} + coeffs::Ptr{ulong} + length::slong + alloc::slong +end + +const n_polyu_t = Tuple{n_polyu_struct} + +const n_fq_polyu_struct = n_polyu_struct + +const n_fq_polyu_t = n_polyu_t + +@flintstruct struct n_polyun_struct + coeffs::Ptr{n_poly_struct} + exps::Ptr{ulong} + length::slong + alloc::slong +end + +const n_polyun_t = Tuple{n_polyun_struct} + +const n_fq_polyun_struct = n_polyun_struct + +const n_fq_polyun_t = n_polyun_t + +@flintstruct struct n_poly_stack_struct + array::Ptr{Ptr{n_poly_struct}} + alloc::slong + top::slong +end + +const n_poly_stack_t = Tuple{n_poly_stack_struct} + +@flintstruct struct n_bpoly_stack_struct + array::Ptr{Ptr{n_bpoly_struct}} + alloc::slong + top::slong +end + +const n_bpoly_stack_t = Tuple{n_bpoly_stack_struct} + +@flintstruct struct n_poly_bpoly_stack_struct + poly_stack::n_poly_stack_t + bpoly_stack::n_bpoly_stack_t +end + +const n_poly_bpoly_stack_t = Tuple{n_poly_bpoly_stack_struct} + +@flintstruct struct nmod_eval_interp_struct + M::Ptr{ulong} + T::Ptr{ulong} + Q::Ptr{ulong} + array::Ptr{ulong} + alloc::slong + d::slong + radix::slong + w::ulong +end + +const nmod_eval_interp_t = Tuple{nmod_eval_interp_struct} + +# end n_poly_types.h +############################################################################### + + +############################################################################### +# begin mpoly_types.h + +const MPOLY_MIN_BITS = UWORD(8) + +@enum ordering_t begin + ORD_LEX + ORD_DEGLEX + ORD_DEGREVLEX +end + +const MPOLY_NUM_ORDERINGS = 3 + +@flintstruct struct mpoly_ctx_struct + nvars::slong + nfields::slong + ord::ordering_t + deg::Cint + rev::Cint + lut_words_per_exp::NTuple{FLINT_BITS, slong} + lut_fix_bits::NTuple{FLINT_BITS, Cuchar} +end + +const mpoly_ctx_t = Tuple{mpoly_ctx_struct} + +@flintstruct struct nmod_mpoly_ctx_struct + minfo::mpoly_ctx_t + mod::nmod_t +end + +const nmod_mpoly_ctx_t = Tuple{nmod_mpoly_ctx_struct} + +@flintstruct struct fmpz_mpoly_ctx_struct + minfo::mpoly_ctx_t +end + +const fmpz_mpoly_ctx_t = Tuple{fmpz_mpoly_ctx_struct} + +@flintstruct struct fmpq_mpoly_ctx_struct + zctx::fmpz_mpoly_ctx_t +end + +const fmpq_mpoly_ctx_t = Tuple{fmpq_mpoly_ctx_struct} + +@flintstruct struct fmpz_mod_mpoly_ctx_struct + minfo::mpoly_ctx_t + ffinfo::fmpz_mod_ctx_t +end + +const fmpz_mod_mpoly_ctx_t = Tuple{fmpz_mod_mpoly_ctx_struct} + +@flintstruct struct fq_nmod_mpoly_ctx_struct + minfo::mpoly_ctx_t + fqctx::fq_nmod_ctx_t +end + +const fq_nmod_mpoly_ctx_t = Tuple{fq_nmod_mpoly_ctx_struct} + +@flintstruct struct struct_mpoly_void_ring_t + elem_size::slong + ctx::Ptr{Cvoid} + init::Ptr{Cvoid} + clear::Ptr{Cvoid} + is_zero::Ptr{Cvoid} + zero::Ptr{Cvoid} + one::Ptr{Cvoid} + set_fmpz::Ptr{Cvoid} + set::Ptr{Cvoid} + swap::Ptr{Cvoid} + neg::Ptr{Cvoid} + add::Ptr{Cvoid} + sub::Ptr{Cvoid} + mul_fmpz::Ptr{Cvoid} + mul::Ptr{Cvoid} + divexact::Ptr{Cvoid} + divides::Ptr{Cvoid} + pow_fmpz::Ptr{Cvoid} + length::Ptr{Cvoid} +end +const mpoly_void_ring_t = Tuple{struct_mpoly_void_ring_t} + +@flintstruct struct mpoly_gcd_info_struct + Amax_exp::Ptr{ulong} + Amin_exp::Ptr{ulong} + Astride::Ptr{ulong} + Adeflate_deg::Ptr{slong} + Alead_count::Ptr{slong} + Atail_count::Ptr{slong} + + Bmax_exp::Ptr{ulong} + Bmin_exp::Ptr{ulong} + Bstride::Ptr{ulong} + Bdeflate_deg::Ptr{slong} + Blead_count::Ptr{slong} + Btail_count::Ptr{slong} + + Gmin_exp::Ptr{ulong} + Abarmin_exp::Ptr{ulong} + Bbarmin_exp::Ptr{ulong} + Gstride::Ptr{ulong} + Gterm_count_est::Ptr{slong} + Gdeflate_deg_bound::Ptr{slong} + + Gbits::flint_bitcnt_t + Abarbits::flint_bitcnt_t + Bbarbits::flint_bitcnt_t + + mvars::slong + Adeflate_tdeg::slong + Bdeflate_tdeg::slong + + Adensity::Cdouble + Bdensity::Cdouble + + hensel_time::Cdouble + brown_time::Cdouble + zippel_time::Cdouble + zippel2_time::Cdouble + hensel_perm::Ptr{slong} + brown_perm::Ptr{slong} + zippel_perm::Ptr{slong} + zippel2_perm::Ptr{slong} + can_use::Cuint + Gdeflate_deg_bounds_are_nice::Cint + + data::Ptr{Cchar} +end + +const mpoly_gcd_info_t = Tuple{mpoly_gcd_info_struct} + +@flintstruct struct mpoly_compression_struct + mvars::slong + nvars::slong + exps::Ptr{slong} + exps_alloc::slong + rest::Ptr{slong} + rest_alloc::slong + umat::Ptr{slong} + deltas::Ptr{slong} + degs::Ptr{slong} + is_trivial::Cint + is_perm::Cint + is_irred::Cint +end + +const mpoly_compression_t = Tuple{mpoly_compression_struct} + +@flintstruct struct nmod_mpolyn_struct + coeffs::Ptr{n_poly_struct} + exps::Ptr{ulong} + alloc::slong + length::slong + bits::slong +end + +const nmod_mpolyn_t = Tuple{nmod_mpolyn_struct} + +@flintstruct struct nmod_mpolyun_struct + coeffs::Ptr{nmod_mpolyn_struct} + exps::Ptr{ulong} + alloc::slong + length::slong + bits::flint_bitcnt_t +end + +const nmod_mpolyun_t = Tuple{nmod_mpolyun_struct} + +@enum nmod_gcds_ret_t begin + nmod_gcds_success + nmod_gcds_form_main_degree_too_high + nmod_gcds_form_wrong + nmod_gcds_no_solution + nmod_gcds_scales_not_found + nmod_gcds_eval_point_not_found + nmod_gcds_eval_gcd_deg_too_high +end + +# end mpoly_types.h +############################################################################### + + +end # module FlintC diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index fbc972a79..2c0b4ab33 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -4,6 +4,9 @@ # ############################################################################### +include("FlintCHelpers.jl") +include("FlintCTypes.jl") + const _err_dim_negative = ErrorException("Dimensions must be non-negative") ###############################################################################