From 0f79ab91d6ac675a08e0c4ec9ae25c72b60ddb07 Mon Sep 17 00:00:00 2001 From: pogudingleb Date: Sun, 21 Jan 2024 12:36:57 +0100 Subject: [PATCH] fixing Nemo and AA depreciation warnings --- benchmarking/IdentifiableFunctions/param.jl | 22 +++---- ext/ModelingToolkitExt.jl | 4 +- src/ODE.jl | 68 +++++++++++---------- src/ODEexport.jl | 4 +- src/RationalFunctionFields/IdealMQS.jl | 12 ++-- src/StructuralIdentifiability.jl | 6 +- src/discrete.jl | 16 ++--- src/elimination.jl | 19 +++--- src/global_identifiability.jl | 18 +++--- src/identifiable_functions.jl | 6 +- src/io_equation.jl | 17 ++++-- src/lincomp.jl | 20 +++--- src/local_identifiability.jl | 16 ++--- src/parametrizations.jl | 11 ++-- src/pb_representation.jl | 22 +++---- src/power_series_utils.jl | 40 ++++++------ src/primality_check.jl | 18 +++--- src/states.jl | 10 +-- src/submodels.jl | 58 +++++++++--------- src/util.jl | 49 ++++++++------- src/wronskian.jl | 11 ++-- test/RationalFunctionFields/normalforms.jl | 2 +- test/check_field_membership.jl | 2 +- test/check_primality_zerodim.jl | 2 +- test/common_ring.jl | 4 +- test/constructive_membership.jl | 12 ++-- test/diff_sequence_solution.jl | 4 +- test/differentiate_output.jl | 16 ++--- test/diffreduction.jl | 8 +-- test/extract_coefficients.jl | 14 ++--- test/find_leader.jl | 2 +- test/io_cases.jl | 6 +- test/lc_univariate.jl | 2 +- test/linear_compartment.jl | 2 +- test/local_identifiability_me.jl | 17 +++--- test/monomial_compress.jl | 2 +- test/ode_ps_solution.jl | 12 ++-- test/paradigm_shift.jl | 5 +- test/parent_ring_change.jl | 12 ++-- test/pseudodivision.jl | 2 +- test/sequence_solution.jl | 4 +- 41 files changed, 302 insertions(+), 275 deletions(-) diff --git a/benchmarking/IdentifiableFunctions/param.jl b/benchmarking/IdentifiableFunctions/param.jl index 44b2f54fa..1a4fd93f5 100644 --- a/benchmarking/IdentifiableFunctions/param.jl +++ b/benchmarking/IdentifiableFunctions/param.jl @@ -31,7 +31,7 @@ function check_constructive_field_membership(generators::AbstractVector, to_be_r $(join(map(x -> string(x[1]) * " -> " * string(x[2]), zip(fracs_gen, tag_strings)), "\t\n")) """ var_strings = vcat(sat_string, map(string, gens(ring)), tag_strings) - ring_tag, xs_tag = PolynomialRing(K, var_strings, ordering = Nemo.ordering(ring)) + ring_tag, xs_tag = polynomial_ring(K, var_strings, ordering = Nemo.ordering(ring)) orig_vars = xs_tag[2:(nvars(ring) + 1)] tag_vars = xs_tag[(nvars(ring) + 2):end] sat_var = xs_tag[1] @@ -121,12 +121,12 @@ rem_tags, tag_to_gen = check_constructive_field_membership(fracs_generators, to_ #= ┌ Info: │ rem_tags = -│ 3-element Vector{AbstractAlgebra.Generic.Frac{fmpq_mpoly}}: +│ 3-element Vector{AbstractAlgebra.Generic.Frac{QQMPolyRingElem}}: │ T1^2 │ -5*T1 + T2 │ T2//T1^10 │ tag_to_gen = -│ Dict{fmpq_mpoly, AbstractAlgebra.Generic.Frac{fmpq_mpoly}} with 2 entries: +│ Dict{QQMPolyRingElem, AbstractAlgebra.Generic.Frac{QQMPolyRingElem}} with 2 entries: │ T1 => a^2 └ T2 => (a + b)//b =# @@ -205,10 +205,10 @@ new_vector_field, new_outputs, new_vars = │ Dict{Any, Any} with 1 entry: │ T1 => 2*T1 + T2 │ new_outputs = -│ Dict{fmpq_mpoly, AbstractAlgebra.Generic.Frac{fmpq_mpoly}} with 1 entry: +│ Dict{QQMPolyRingElem, AbstractAlgebra.Generic.Frac{QQMPolyRingElem}} with 1 entry: │ y => T1 │ new_vars = -│ Dict{fmpq_mpoly, AbstractAlgebra.Generic.Frac{fmpq_mpoly}} with 2 entries: +│ Dict{QQMPolyRingElem, AbstractAlgebra.Generic.Frac{QQMPolyRingElem}} with 2 entries: │ T2 => a + b └ T1 => x2 + x1 =# @@ -230,7 +230,7 @@ id_funcs = StructuralIdentifiability.find_identifiable_functions( #= ┌ Info: │ id_funcs = -│ 2-element Vector{AbstractAlgebra.Generic.Frac{fmpq_mpoly}}: +│ 2-element Vector{AbstractAlgebra.Generic.Frac{QQMPolyRingElem}}: │ x2*x1 └ a + b =# @@ -246,10 +246,10 @@ new_vector_field, new_outputs, new_vars = reparametrize_with_respect_to(ode, new │ Dict{Any, Any} with 1 entry: │ T1 => T1*T2 │ new_outputs = -│ Dict{fmpq_mpoly, AbstractAlgebra.Generic.Frac{fmpq_mpoly}} with 1 entry: +│ Dict{QQMPolyRingElem, AbstractAlgebra.Generic.Frac{QQMPolyRingElem}} with 1 entry: │ y => T1 │ new_vars = -│ Dict{fmpq_mpoly, AbstractAlgebra.Generic.Frac{fmpq_mpoly}} with 2 entries: +│ Dict{QQMPolyRingElem, AbstractAlgebra.Generic.Frac{QQMPolyRingElem}} with 2 entries: │ T2 => a + b └ T1 => x2*x1 =# @@ -271,7 +271,7 @@ id_funcs = StructuralIdentifiability.find_identifiable_functions( #= ┌ Info: │ id_funcs = -│ 5-element Vector{AbstractAlgebra.Generic.Frac{fmpq_mpoly}}: +│ 5-element Vector{AbstractAlgebra.Generic.Frac{QQMPolyRingElem}}: │ x2*x1 │ a*b │ x2 + x1 @@ -292,10 +292,10 @@ new_vector_field, new_iutputs, new_vars = reparametrize_with_respect_to(ode, new │ T2 => T2*T4 │ T3 => -1//2*T1*T4^2 + 2*T1*T5 + 1//2*T3*T4 │ new_outputs = -│ Dict{fmpq_mpoly, AbstractAlgebra.Generic.Frac{fmpq_mpoly}} with 1 entry: +│ Dict{QQMPolyRingElem, AbstractAlgebra.Generic.Frac{QQMPolyRingElem}} with 1 entry: │ y => T1 │ new_vars = -│ Dict{fmpq_mpoly, AbstractAlgebra.Generic.Frac{fmpq_mpoly}} with 5 entries: +│ Dict{QQMPolyRingElem, AbstractAlgebra.Generic.Frac{QQMPolyRingElem}} with 5 entries: │ T1 => x2 + x1 │ T2 => x2*x1 │ T3 => a*x2 - a*x1 - b*x2 + b*x1 diff --git a/ext/ModelingToolkitExt.jl b/ext/ModelingToolkitExt.jl index aefe97aa6..0e1a00026 100644 --- a/ext/ModelingToolkitExt.jl +++ b/ext/ModelingToolkitExt.jl @@ -166,7 +166,7 @@ function __mtk_to_si( de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{<:Tuple{String, <:SymbolicUtils.BasicSymbolic}}, ) - polytype = StructuralIdentifiability.Nemo.fmpq_mpoly + polytype = StructuralIdentifiability.Nemo.QQMPolyRingElem fractype = StructuralIdentifiability.Nemo.Generic.Frac{polytype} diff_eqs = filter(eq -> !(ModelingToolkit.isoutput(eq.lhs)), ModelingToolkit.equations(de)) @@ -197,7 +197,7 @@ function __mtk_to_si( input_symbols = vcat(state_vars, inputs, params) generators = vcat(string.(input_symbols), [e[1] for e in measured_quantities]) generators = map(g -> replace(g, "(t)" => ""), generators) - R, gens_ = Nemo.PolynomialRing(Nemo.QQ, generators) + R, gens_ = Nemo.polynomial_ring(Nemo.QQ, generators) y_vars = Vector{polytype}([str_to_var(e[1], R) for e in measured_quantities]) symb2gens = Dict(input_symbols .=> gens_[1:length(input_symbols)]) diff --git a/src/ODE.jl b/src/ODE.jl index 1113a204f..83ba44ae2 100644 --- a/src/ODE.jl +++ b/src/ODE.jl @@ -20,7 +20,7 @@ struct ODE{P} # P is the type of polynomials in the rhs of the ODE system x_eqs::Dict{P, <:Union{P, Generic.Frac{P}}}, y_eqs::Dict{P, <:Union{P, Generic.Frac{P}}}, inputs::Array{P, 1}, - ) where {P <: MPolyElem{<:FieldElem}} + ) where {P <: MPolyRingElem{<:FieldElem}} # Initialize ODE # x_eqs is a dictionary x_i => f_i(x, u, params) # y_eqs is a dictionary y_i => g_i(x, u, params) @@ -40,7 +40,7 @@ struct ODE{P} # P is the type of polynomials in the rhs of the ODE system x_eqs::Dict{P, <:Union{P, Generic.Frac{P}}}, y_eqs::Dict{P, <:Union{P, Generic.Frac{P}}}, inputs::Array{P, 1}, - ) where {P <: MPolyElem{<:FieldElem}} + ) where {P <: MPolyRingElem{<:FieldElem}} x_vars = collect(keys(x_eqs)) y_vars = collect(keys(y_eqs)) return ODE{P}(x_vars, y_vars, x_eqs, y_eqs, inputs) @@ -53,10 +53,13 @@ end #------------------------------------------------------------------------------ -function add_outputs(ode::ODE{P}, extra_y::Dict{String, <:RingElem}) where {P <: MPolyElem} +function add_outputs( + ode::ODE{P}, + extra_y::Dict{String, <:RingElem}, +) where {P <: MPolyRingElem} new_var_names = vcat(collect(map(var_to_str, gens(ode.poly_ring))), collect(keys(extra_y))) - new_ring, new_vars = Nemo.PolynomialRing(base_ring(ode.poly_ring), new_var_names) + new_ring, new_vars = Nemo.polynomial_ring(base_ring(ode.poly_ring), new_var_names) new_x = Array{P, 1}([parent_ring_change(x, new_ring) for x in ode.x_vars]) new_x_eqs = Dict{P, Union{P, Generic.Frac{P}}}( @@ -94,10 +97,10 @@ Output: function set_parameter_values( ode::ODE{P}, param_values::Dict{P, T}, -) where {T <: FieldElem, P <: MPolyElem{T}} +) where {T <: FieldElem, P <: MPolyRingElem{T}} new_vars = map(var_to_str, [v for v in gens(ode.poly_ring) if !(v in keys(param_values))]) - small_ring, small_vars = Nemo.PolynomialRing(base_ring(ode.poly_ring), new_vars) + small_ring, small_vars = Nemo.polynomial_ring(base_ring(ode.poly_ring), new_vars) eval_dict = Dict(str_to_var(v, ode.poly_ring) => str_to_var(v, small_ring) for v in new_vars) merge!(eval_dict, Dict(p => small_ring(val) for (p, val) in param_values)) @@ -130,8 +133,8 @@ end function set_parameter_values( ode::ODE{P}, param_values::Dict{P, <:Number}, -) where {P <: MPolyElem} - new_values = Dict{P, fmpq}(x => _to_rational(v) for (x, v) in param_values) +) where {P <: MPolyRingElem} + new_values = Dict{P, QQFieldElem}(x => _to_rational(v) for (x, v) in param_values) return set_parameter_values(ode, new_values) end @@ -156,11 +159,11 @@ function power_series_solution( initial_conditions::Dict{P, T}, input_values::Dict{P, Array{T, 1}}, prec::Int, -) where {T <: FieldElem, P <: MPolyElem{T}} +) where {T <: FieldElem, P <: MPolyRingElem{T}} new_varnames = map(var_to_str, vcat(ode.x_vars, ode.u_vars)) append!(new_varnames, map(v -> var_to_str(v) * "_dot", ode.x_vars)) - new_ring, new_vars = Nemo.PolynomialRing(base_ring(ode.poly_ring), new_varnames) + new_ring, new_vars = Nemo.polynomial_ring(base_ring(ode.poly_ring), new_varnames) equations = Array{P, 1}() evaluation = Dict(k => new_ring(v) for (k, v) in param_values) for v in vcat(ode.x_vars, ode.u_vars) @@ -196,7 +199,7 @@ function power_series_solution( initial_conditions::Dict{P, Int}, input_values::Dict{P, Array{Int, 1}}, prec::Int, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} bring = base_ring(ode.poly_ring) return power_series_solution( ode, @@ -213,7 +216,7 @@ end Reduces a polynomial/rational function over Q modulo p """ -function _reduce_mod_p(poly::fmpq_mpoly, p::Int) +function _reduce_mod_p(poly::QQMPolyRingElem, p::Int) den = denominator(poly) num = change_base_ring(Nemo.ZZ, den * poly) if Nemo.Native.GF(p)(den) == 0 @@ -222,7 +225,7 @@ function _reduce_mod_p(poly::fmpq_mpoly, p::Int) return change_base_ring(Nemo.Native.GF(p), num) * (1 // Nemo.Native.GF(p)(den)) end -function _reduce_mod_p(rat::Generic.Frac{fmpq_mpoly}, p::Int) +function _reduce_mod_p(rat::Generic.Frac{QQMPolyRingElem}, p::Int) num, den = map(poly -> _reduce_mod_p(poly, p), [numerator(rat), denominator(rat)]) if den == 0 throw(Base.ArgumentError("Prime $p divides the denominator of $rat")) @@ -238,9 +241,9 @@ end Input: ode is an ODE over QQ, p is a prime number Output: the reduction mod p, throws an exception if p divides one of the denominators """ -function reduce_ode_mod_p(ode::ODE{<:MPolyElem{Nemo.fmpq}}, p::Int) +function reduce_ode_mod_p(ode::ODE{<:MPolyRingElem{Nemo.QQFieldElem}}, p::Int) new_ring, new_vars = - Nemo.PolynomialRing(Nemo.Native.GF(p), map(var_to_str, gens(ode.poly_ring))) + Nemo.polynomial_ring(Nemo.Native.GF(p), map(var_to_str, gens(ode.poly_ring))) new_type = typeof(new_vars[1]) new_inputs = map(u -> switch_ring(u, new_ring), ode.u_vars) new_x = map(x -> switch_ring(x, new_ring), ode.x_vars) @@ -375,7 +378,7 @@ macro ODEmodel(ex::Expr...) R = gensym() vars_aux = gensym() exp_ring = :( - ($R, $vars_aux) = StructuralIdentifiability.Nemo.PolynomialRing( + ($R, $vars_aux) = StructuralIdentifiability.Nemo.polynomial_ring( StructuralIdentifiability.Nemo.QQ, map(string, $all_symb_with_t), ) @@ -385,8 +388,10 @@ macro ODEmodel(ex::Expr...) # setting x_vars and y_vars in the right order vx = gensym() vy = gensym() - x_var_expr = :($vx = Vector{StructuralIdentifiability.Nemo.fmpq_mpoly}([$(x_vars...)])) - y_var_expr = :($vy = Vector{StructuralIdentifiability.Nemo.fmpq_mpoly}([$(y_vars...)])) + x_var_expr = + :($vx = Vector{StructuralIdentifiability.Nemo.QQMPolyRingElem}([$(x_vars...)])) + y_var_expr = + :($vy = Vector{StructuralIdentifiability.Nemo.QQMPolyRingElem}([$(y_vars...)])) # preparing equations equations = map(macrohelper_clean, equations) @@ -394,22 +399,22 @@ macro ODEmodel(ex::Expr...) y_dict = gensym() x_dict_create_expr = :( $x_dict = Dict{ - StructuralIdentifiability.Nemo.fmpq_mpoly, + StructuralIdentifiability.Nemo.QQMPolyRingElem, Union{ - StructuralIdentifiability.Nemo.fmpq_mpoly, + StructuralIdentifiability.Nemo.QQMPolyRingElem, StructuralIdentifiability.AbstractAlgebra.Generic.Frac{ - StructuralIdentifiability.Nemo.fmpq_mpoly, + StructuralIdentifiability.Nemo.QQMPolyRingElem, }, }, }() ) y_dict_create_expr = :( $y_dict = Dict{ - StructuralIdentifiability.Nemo.fmpq_mpoly, + StructuralIdentifiability.Nemo.QQMPolyRingElem, Union{ - StructuralIdentifiability.Nemo.fmpq_mpoly, + StructuralIdentifiability.Nemo.QQMPolyRingElem, StructuralIdentifiability.AbstractAlgebra.Generic.Frac{ - StructuralIdentifiability.Nemo.fmpq_mpoly, + StructuralIdentifiability.Nemo.QQMPolyRingElem, }, }, }() @@ -472,13 +477,14 @@ macro ODEmodel(ex::Expr...) ), ] # creating the ode object - ode_expr = :(StructuralIdentifiability.ODE{StructuralIdentifiability.Nemo.fmpq_mpoly}( - $vx, - $vy, - $x_dict, - $y_dict, - Array{StructuralIdentifiability.Nemo.fmpq_mpoly}([$(u_vars...)]), - )) + ode_expr = + :(StructuralIdentifiability.ODE{StructuralIdentifiability.Nemo.QQMPolyRingElem}( + $vx, + $vy, + $x_dict, + $y_dict, + Array{StructuralIdentifiability.Nemo.QQMPolyRingElem}([$(u_vars...)]), + )) result = Expr( :block, diff --git a/src/ODEexport.jl b/src/ODEexport.jl index aa4f8d63d..c74898476 100644 --- a/src/ODEexport.jl +++ b/src/ODEexport.jl @@ -10,7 +10,7 @@ function print_for_maple(ode::ODE, package = :SIAN) varstr = Dict(x => var_to_str(x) * "(t)" for x in vcat(ode.x_vars, ode.u_vars, ode.y_vars)) merge!(varstr, Dict(p => var_to_str(p) for p in ode.parameters)) - R_print, vars_print = Nemo.PolynomialRing( + R_print, vars_print = Nemo.polynomial_ring( base_ring(ode.poly_ring), [varstr[v] for v in gens(ode.poly_ring)], ) @@ -189,7 +189,7 @@ function print_for_COMBOS(ode::ODE) merge!(varstr, Dict(u => "u" * string(ind) for (ind, u) in enumerate(ode.u_vars))) merge!(varstr, Dict(y => "y" * string(ind) for (ind, y) in enumerate(ode.y_vars))) merge!(varstr, Dict(p => var_to_str(p) for p in ode.parameters)) - R_print, vars_print = Nemo.PolynomialRing( + R_print, vars_print = Nemo.polynomial_ring( base_ring(ode.poly_ring), [varstr[v] for v in gens(ode.poly_ring)], ) diff --git a/src/RationalFunctionFields/IdealMQS.jl b/src/RationalFunctionFields/IdealMQS.jl index 6d8ddb81c..519254fa7 100644 --- a/src/RationalFunctionFields/IdealMQS.jl +++ b/src/RationalFunctionFields/IdealMQS.jl @@ -100,7 +100,7 @@ mutable struct IdealMQS{T} <: AbstractBlackboxIdeal end varnames = append_at_index(ystrs, sat_var_index, sat_varname) @debug "Saturating variable is $sat_varname, index is $sat_var_index" - R_sat, v_sat = Nemo.PolynomialRing(K, varnames, ordering = ordering) + R_sat, v_sat = Nemo.polynomial_ring(K, varnames, ordering = ordering) # Saturation t_sat = v_sat[sat_var_index] den_lcm_orig = den_lcm @@ -144,7 +144,7 @@ mutable struct IdealMQS{T} <: AbstractBlackboxIdeal push!(nums_qq, num) end end - parent_ring_param, _ = PolynomialRing(ring, varnames, ordering = ordering) + parent_ring_param, _ = polynomial_ring(ring, varnames, ordering = ordering) @debug "Constructed MQS ideal in $R_sat with $(length(nums_qq) + 1) elements" @assert length(pivots_indices) == length(dens_indices) == length(dens_qq) @assert length(pivots_indices) == length(funcs_den_nums) @@ -202,7 +202,7 @@ function fractionfree_generators_raw(mqs::IdealMQS) end # NOTE: new variables go first! big_ring, big_vars = - PolynomialRing(K, vcat(new_varnames, old_varnames), ordering = :lex) + polynomial_ring(K, vcat(new_varnames, old_varnames), ordering = :lex) @info "$(mqs.sat_var_index) $(varnames) $ring_params $(parent(mqs.sat_qq))" nums_qq, dens_qq, sat_qq = mqs.nums_qq, mqs.dens_qq, mqs.sat_qq nums_y = map(num -> parent_ring_change(num, big_ring, matching = :byindex), nums_qq) @@ -229,7 +229,7 @@ end function ParamPunPam.reduce_mod_p!( mqs::IdealMQS, ff::Field, -) where {Field <: Union{Nemo.GaloisField, Nemo.GaloisFmpzField}} +) where {Field <: Union{Nemo.GaloisField, Nemo.FpField}} @debug "Reducing MQS ideal modulo $(ff)" # If there is a reduction modulo this field already, if haskey(mqs.cached_nums_gf, ff) @@ -251,7 +251,7 @@ function ParamPunPam.specialize_mod_p( mqs::IdealMQS, point::Vector{T}; saturated = true, -) where {T <: Union{gfp_elem, gfp_fmpz_elem}} +) where {T <: Union{fpFieldElem, gfp_fmpz_elem}} K_1 = parent(first(point)) @debug "Evaluating MQS ideal over $K_1 at $point" @assert haskey(mqs.cached_nums_gf, K_1) @@ -283,7 +283,7 @@ function ParamPunPam.specialize_mod_p( return polys end -function specialize(mqs::IdealMQS, point::Vector{Nemo.fmpq}; saturated = true) +function specialize(mqs::IdealMQS, point::Vector{Nemo.QQFieldElem}; saturated = true) @debug "Evaluating MQS ideal over QQ at $point" nums_qq, dens_qq, sat_qq = mqs.nums_qq, mqs.dens_qq, mqs.sat_qq dens_indices = mqs.dens_indices diff --git a/src/StructuralIdentifiability.jl b/src/StructuralIdentifiability.jl index 6ef80d5b0..2793ce16d 100644 --- a/src/StructuralIdentifiability.jl +++ b/src/StructuralIdentifiability.jl @@ -99,7 +99,7 @@ function assess_identifiability( funcs_to_check = Vector(), prob_threshold::Float64 = 0.99, loglevel = Logging.Info, -) where {P <: MPolyElem{fmpq}} +) where {P <: MPolyRingElem{QQFieldElem}} restart_logging(loglevel = loglevel) reset_timings() with_logger(_si_logger[]) do @@ -115,7 +115,7 @@ function _assess_identifiability( ode::ODE{P}; funcs_to_check = Vector(), prob_threshold::Float64 = 0.99, -) where {P <: MPolyElem{fmpq}} +) where {P <: MPolyRingElem{QQFieldElem}} p_glob = 1 - (1 - prob_threshold) * 0.9 p_loc = 1 - (1 - prob_threshold) * 0.1 @@ -124,7 +124,7 @@ function _assess_identifiability( end @info "Assessing local identifiability" - trbasis = Array{fmpq_mpoly, 1}() + trbasis = Array{QQMPolyRingElem, 1}() runtime = @elapsed local_result = _assess_local_identifiability( ode, funcs_to_check = funcs_to_check, diff --git a/src/discrete.jl b/src/discrete.jl index 7cb92ea31..3c2db3dc5 100644 --- a/src/discrete.jl +++ b/src/discrete.jl @@ -18,7 +18,7 @@ function sequence_solution( initial_conditions::Dict{P, T}, input_values::Dict{P, Array{T, 1}}, num_terms::Int, -) where {T <: FieldElem, P <: MPolyElem{T}} +) where {T <: FieldElem, P <: MPolyRingElem{T}} result = Dict(x => [initial_conditions[x]] for x in dds.x_vars) for i in 2:num_terms eval_dict = merge( @@ -41,7 +41,7 @@ function sequence_solution( initial_conditions::Dict{P, Int}, input_values::Dict{P, Array{Int, 1}}, num_terms::Int, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} bring = base_ring(dds.poly_ring) return sequence_solution( dds, @@ -71,7 +71,7 @@ function differentiate_sequence_solution( ic::Dict{P, T}, inputs::Dict{P, Array{T, 1}}, num_terms::Int, -) where {T <: Generic.FieldElem, P <: MPolyElem{T}} +) where {T <: Generic.FieldElem, P <: MPolyRingElem{T}} @debug "Computing the power series solution of the system" seq_sol = sequence_solution(dds, params, ic, inputs, num_terms) generalized_params = vcat(dds.x_vars, dds.parameters) @@ -125,7 +125,7 @@ function differentiate_sequence_output( ic::Dict{P, T}, inputs::Dict{P, Array{T, 1}}, num_terms::Int, -) where {T <: Generic.FieldElem, P <: MPolyElem{T}} +) where {T <: Generic.FieldElem, P <: MPolyRingElem{T}} @debug "Computing partial derivatives of the solution" seq_sol, sol_diff = differentiate_sequence_solution(dds, params, ic, inputs, num_terms) @@ -178,7 +178,7 @@ function _degree_with_common_denom(polys) end """ - _assess_local_identifiability_discrete_aux(dds::ODE{P}, funcs_to_check::Array{<: Any, 1}, known_ic, prob_threshold::Float64=0.99) where P <: MPolyElem{Nemo.fmpq} + _assess_local_identifiability_discrete_aux(dds::ODE{P}, funcs_to_check::Array{<: Any, 1}, known_ic, prob_threshold::Float64=0.99) where P <: MPolyRingElem{Nemo.QQFieldElem} Checks the local identifiability/observability of the functions in `funcs_to_check` treating `dds` as a discrete-time system with **shift** instead of derivative in the right-hand side. @@ -193,7 +193,7 @@ function _assess_local_identifiability_discrete_aux( funcs_to_check::Array{<:Any, 1}, known_ic = :none, prob_threshold::Float64 = 0.99, -) where {P <: MPolyElem{Nemo.fmpq}} +) where {P <: MPolyRingElem{Nemo.QQFieldElem}} bring = base_ring(dds.poly_ring) @debug "Extending the model" @@ -228,8 +228,8 @@ function _assess_local_identifiability_discrete_aux( # Parameter values are the same across all the replicas params_vals = Dict(p => bring(rand(1:D)) for p in dds_ext.parameters) ic = Dict(x => bring(rand(1:D)) for x in dds_ext.x_vars) - # TODO: parametric type instead of fmpq - inputs = Dict{P, Array{fmpq, 1}}( + # TODO: parametric type instead of QQFieldElem + inputs = Dict{P, Array{QQFieldElem, 1}}( u => [bring(rand(1:D)) for i in 1:prec] for u in dds_ext.u_vars ) diff --git a/src/elimination.jl b/src/elimination.jl index 6798889e9..24978ca1b 100644 --- a/src/elimination.jl +++ b/src/elimination.jl @@ -58,7 +58,7 @@ Inputs: Output: - `M::MatrixElem` - The Bezout matrix """ -function Bezout_matrix(f::P, g::P, var_elim::P) where {P <: MPolyElem} +function Bezout_matrix(f::P, g::P, var_elim::P) where {P <: MPolyRingElem} parent_ring = parent(f) deg_f = Nemo.degree(f, var_elim) deg_g = Nemo.degree(g, var_elim) @@ -91,7 +91,7 @@ Inputs: Output: - `M::MatrixElem` - The Sylvester matrix """ -function Sylvester_matrix(f::P, g::P, var_elim::P) where {P <: MPolyElem} +function Sylvester_matrix(f::P, g::P, var_elim::P) where {P <: MPolyRingElem} parent_ring = parent(f) deg_f = Nemo.degree(f, var_elim) deg_g = Nemo.degree(g, var_elim) @@ -124,9 +124,9 @@ Input: Output: - `M::MatrixElem` - Simplified matrix -- `extra_factors::Vector{AbstractAlgebra.MPolyElem}` - array of GCDs eliminated from `M`. +- `extra_factors::Vector{AbstractAlgebra.MPolyRingElem}` - array of GCDs eliminated from `M`. """ -function simplify_matrix(M::MatElem{P}) where {P <: MPolyElem} +function simplify_matrix(M::MatElem{P}) where {P <: MPolyRingElem} """ An auxiliary function taking a list of coordinates of cells and dividing them by their gcd. @@ -188,7 +188,10 @@ mutable struct ODEPointGenerator{P} <: PointGenerator{P} cached_points::Array{Dict{P, <:FieldElem}, 1} number_type::Type - function ODEPointGenerator{P}(ode::ODE{P}, big_ring::MPolyRing) where {P <: MPolyElem} + function ODEPointGenerator{P}( + ode::ODE{P}, + big_ring::MPolyRing, + ) where {P <: MPolyRingElem} prec = length(ode.x_vars) + 1 number_type = typeof(one(base_ring(big_ring))) return new(ode, big_ring, prec, Array{Dict{P, number_type}}[], number_type) @@ -200,7 +203,7 @@ end function Base.iterate( gpg::ODEPointGenerator{P}, i::Int = 1, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} if i > length(gpg.cached_points) @debug "Generating new point on the variety" sample_max = i * 50 @@ -273,7 +276,7 @@ Output: function choose( polys::Array{P, 1}, generic_point_generator, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} vars = gens(parent(polys[1])) for p in generic_point_generator # get accounts for the fact that the big ring may contain some auxiliary variables, e.g. rand_proj_var @@ -307,7 +310,7 @@ Output: g::P, var_elim::P, generic_point_generator, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} # Linear comb while f != 0 && g != 0 if Nemo.degree(f, var_elim) > Nemo.degree(g, var_elim) diff --git a/src/global_identifiability.jl b/src/global_identifiability.jl index 984747e3b..da93e6d74 100644 --- a/src/global_identifiability.jl +++ b/src/global_identifiability.jl @@ -17,14 +17,14 @@ are identifiable functions containing or not the state variables ode::ODE{P}, known::Array{P, 1}, with_states::Bool, -) where {P <: MPolyElem{fmpq}} +) where {P <: MPolyRingElem{QQFieldElem}} coeff_lists = Dict(:with_states => Array{Array{P, 1}, 1}(), :no_states => Array{Array{P, 1}, 1}()) varnames = [var_to_str(p) for p in ode.parameters] if with_states append!(varnames, map(var_to_str, ode.x_vars)) end - bring, _ = Nemo.PolynomialRing(base_ring(ode.poly_ring), varnames) + bring, _ = Nemo.polynomial_ring(base_ring(ode.poly_ring), varnames) if with_states @debug "Computing Lie derivatives" @@ -67,7 +67,7 @@ are identifiable functions containing or not the state variables if with_states new_vars = vcat(new_vars, ode.x_vars) end - new_ring, _ = PolynomialRing(Nemo.QQ, map(Symbol, new_vars)) + new_ring, _ = polynomial_ring(Nemo.QQ, map(Symbol, new_vars)) new_coeff_lists = empty(coeff_lists) for (key, coeff_list) in coeff_lists new_coeff_lists[key] = @@ -145,7 +145,7 @@ The function returns a tuple containing the following: if with_states && !isempty(ode.parameters) @debug "Generators of identifiable functions involve states, the parameter-only part is getting simplified" # NOTE: switching to a ring without states for a moment - param_ring, _ = PolynomialRing( + param_ring, _ = polynomial_ring( base_ring(bring), map(string, ode.parameters), ordering = Nemo.ordering(bring), @@ -195,7 +195,7 @@ Output: a list L of booleans with L[i] being the identifiability status of the i known::Array{P, 1} = Array{P, 1}(), prob_threshold::Float64 = 0.99, var_change_policy = :default, -) where {P <: MPolyElem{fmpq}} +) where {P <: MPolyRingElem{QQFieldElem}} states_needed = false for f in funcs_to_check num, den = unpack_fraction(f) @@ -236,7 +236,7 @@ function check_identifiability( known::Array{P, 1} = Array{P, 1}(), prob_threshold::Float64 = 0.99, var_change_policy = :default, -) where {P <: MPolyElem{fmpq}} +) where {P <: MPolyRingElem{QQFieldElem}} return check_identifiability( ode, ode.parameters, @@ -248,7 +248,7 @@ end #------------------------------------------------------------------------------ """ - assess_global_identifiability(ode::ODE{P}, prob_threshold::Float64=0.99; var_change=:default) where P <: MPolyElem{fmpq} + assess_global_identifiability(ode::ODE{P}, prob_threshold::Float64=0.99; var_change=:default) where P <: MPolyRingElem{QQFieldElem} Input: - `ode` - the ODE model @@ -266,7 +266,7 @@ function assess_global_identifiability( known::Array{P, 1} = Array{P, 1}(), prob_threshold::Float64 = 0.99; var_change = :default, -) where {P <: MPolyElem{fmpq}} +) where {P <: MPolyRingElem{QQFieldElem}} result_list = assess_global_identifiability( ode, ode.parameters, @@ -303,7 +303,7 @@ Checks global identifiability of functions of parameters specified in `funcs_to_ known::Array{P, 1} = Array{P, 1}(), prob_threshold::Float64 = 0.99; var_change = :default, -) where {P <: MPolyElem{fmpq}} +) where {P <: MPolyRingElem{QQFieldElem}} submodels = find_submodels(ode) if length(submodels) > 0 @info "Note: the input model has nontrivial submodels. If the computation for the full model will be too heavy, you may want to try to first analyze one of the submodels. They can be produced using function `find_submodels`" diff --git a/src/identifiable_functions.jl b/src/identifiable_functions.jl index d84e0f14e..ec116843e 100644 --- a/src/identifiable_functions.jl +++ b/src/identifiable_functions.jl @@ -37,7 +37,7 @@ ode = @ODEmodel( find_identifiable_functions(ode) # prints -3-element Vector{AbstractAlgebra.Generic.Frac{Nemo.fmpq_mpoly}}: +3-element Vector{AbstractAlgebra.Generic.Frac{Nemo.QQMPolyRingElem}}: a12 + a01 + a21 a12*a01 ``` @@ -51,7 +51,7 @@ function find_identifiable_functions( simplify = :standard, rational_interpolator = :VanDerHoevenLecerf, loglevel = Logging.Info, -) where {T <: MPolyElem{fmpq}} +) where {T <: MPolyRingElem{QQFieldElem}} restart_logging(loglevel = loglevel) reset_timings() with_logger(_si_logger[]) do @@ -73,7 +73,7 @@ function _find_identifiable_functions( with_states = false, simplify = :standard, rational_interpolator = :VanDerHoevenLecerf, -) where {T <: MPolyElem{fmpq}} +) where {T <: MPolyRingElem{QQFieldElem}} Random.seed!(seed) @assert simplify in (:standard, :weak, :strong, :absent) runtime_start = time_ns() diff --git a/src/io_equation.jl b/src/io_equation.jl index ed1b1b1c4..92d90ff4e 100644 --- a/src/io_equation.jl +++ b/src/io_equation.jl @@ -2,7 +2,12 @@ const PROJECTION_VARNAME = "rand_proj_var" # ------------------------------------------------------------------------------ -function generator_var_change(generator, var::P, numer::P, denom::P) where {P <: MPolyElem} +function generator_var_change( + generator, + var::P, + numer::P, + denom::P, +) where {P <: MPolyRingElem} return IterTools.imap( point -> begin result = copy(point) @@ -15,7 +20,7 @@ end # ------------------------------------------------------------------------------ -function diff_poly(poly::P, derivation::Dict{P, T}) where {P <: MPolyElem, T} +function diff_poly(poly::P, derivation::Dict{P, T}) where {P <: MPolyRingElem, T} return sum(derivative(poly, x) * xd for (x, xd) in derivation) end @@ -28,7 +33,7 @@ end # ------------------------------------------------------------------------------ -function generate_io_equation_problem(ode::ODE{P}) where {P <: MPolyElem{<:FieldElem}} +function generate_io_equation_problem(ode::ODE{P}) where {P <: MPolyRingElem{<:FieldElem}} dim_x = length(ode.x_vars) # Creating a ring @@ -40,7 +45,7 @@ function generate_io_equation_problem(ode::ODE{P}) where {P <: MPolyElem{<:Field [var_to_str(u) * "_$i" for i in 0:dim_x for u in ode.u_vars], [PROJECTION_VARNAME], ) - ring, ring_vars = Nemo.PolynomialRing(base_ring(ode.poly_ring), var_names) + ring, ring_vars = Nemo.polynomial_ring(base_ring(ode.poly_ring), var_names) # Definiting a (partial) derivation on it derivation = Dict{P, P}() @@ -105,7 +110,7 @@ Output: ode::ODE{P}, auto_var_change::Bool, extra_projection = nothing, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} # Initialization ring, derivation, x_equations, y_equations, point_generator = generate_io_equation_problem(ode) @@ -341,7 +346,7 @@ Output: ode::ODE{P}; var_change_policy = :default, loglevel = Logging.Info, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} # Setting the var_change policy if (var_change_policy == :yes) || (var_change_policy == :default && length(ode.y_vars) < 3) diff --git a/src/lincomp.jl b/src/lincomp.jl index 72dd6a327..0603e39a9 100644 --- a/src/lincomp.jl +++ b/src/lincomp.jl @@ -45,14 +45,15 @@ function linear_compartment_model( push!(edges_vars_names, "a_0_$(s)") end - R, vars = StructuralIdentifiability.Nemo.PolynomialRing( + R, vars = StructuralIdentifiability.Nemo.polynomial_ring( StructuralIdentifiability.Nemo.QQ, vcat(x_vars_names, y_vars_names, u_vars_names, edges_vars_names), ) x_vars = @view vars[1:n] - x_equations = Dict{fmpq_mpoly, Union{fmpq_mpoly, Generic.Frac{fmpq_mpoly}}}( - x => R(0) for x in x_vars - ) + x_equations = + Dict{QQMPolyRingElem, Union{QQMPolyRingElem, Generic.Frac{QQMPolyRingElem}}}( + x => R(0) for x in x_vars + ) for i in 1:n for j in graph[i] rate = str_to_var("a_$(j)_$(i)", R) @@ -68,14 +69,15 @@ function linear_compartment_model( end end - y_equations = Dict{fmpq_mpoly, Union{fmpq_mpoly, Generic.Frac{fmpq_mpoly}}}( - str_to_var("y$i", R) => str_to_var("x$i", R) for i in outputs - ) + y_equations = + Dict{QQMPolyRingElem, Union{QQMPolyRingElem, Generic.Frac{QQMPolyRingElem}}}( + str_to_var("y$i", R) => str_to_var("x$i", R) for i in outputs + ) - return ODE{fmpq_mpoly}( + return ODE{QQMPolyRingElem}( x_equations, y_equations, - Array{fmpq_mpoly}([str_to_var("u$i", R) for i in inputs]), + Array{QQMPolyRingElem}([str_to_var("u$i", R) for i in inputs]), ) end diff --git a/src/local_identifiability.jl b/src/local_identifiability.jl index da6909777..2580d2de2 100644 --- a/src/local_identifiability.jl +++ b/src/local_identifiability.jl @@ -30,7 +30,7 @@ function differentiate_solution( ic::Dict{P, T}, inputs::Dict{P, Array{T, 1}}, prec::Int, -) where {T <: Generic.FieldElem, P <: MPolyElem{T}} +) where {T <: Generic.FieldElem, P <: MPolyRingElem{T}} @debug "Computing the power series solution of the system" ps_sol = power_series_solution(ode, params, ic, inputs, prec) ps_ring = parent(first(values(ps_sol))) @@ -86,7 +86,7 @@ function differentiate_output( ic::Dict{P, T}, inputs::Dict{P, Array{T, 1}}, prec::Int, -) where {T <: Generic.FieldElem, P <: MPolyElem{T}} +) where {T <: Generic.FieldElem, P <: MPolyRingElem{T}} @debug "Computing partial derivatives of the solution" ps_sol, sol_diff = differentiate_solution(ode, params, ic, inputs, prec) ps_ring = parent(first(values(ps_sol))) @@ -124,7 +124,7 @@ end for `f` being a polynomial/rational function over rationals (`QQ`) returns a tuple `(degree, max_coef_size)` """ -function get_degree_and_coeffsize(f::MPolyElem{Nemo.fmpq}) +function get_degree_and_coeffsize(f::MPolyRingElem{Nemo.QQFieldElem}) if length(f) == 0 return (0, 1) end @@ -135,7 +135,7 @@ function get_degree_and_coeffsize(f::MPolyElem{Nemo.fmpq}) return (total_degree(f), max_coef) end -function get_degree_and_coeffsize(f::Generic.Frac{<:MPolyElem{Nemo.fmpq}}) +function get_degree_and_coeffsize(f::Generic.Frac{<:MPolyRingElem{Nemo.QQFieldElem}}) num_deg, num_coef = get_degree_and_coeffsize(numerator(f)) den_deg, den_coef = get_degree_and_coeffsize(denominator(f)) return (max(num_deg, den_deg), max(num_coef, den_coef)) @@ -144,7 +144,7 @@ end # ------------------------------------------------------------------------------ """ - assess_local_identifiability(ode::ODE{P}; funcs_to_check::Array{<: Any, 1}, prob_threshold::Float64=0.99, type=:SE, loglevel=Logging.Info) where P <: MPolyElem{Nemo.fmpq} + assess_local_identifiability(ode::ODE{P}; funcs_to_check::Array{<: Any, 1}, prob_threshold::Float64=0.99, type=:SE, loglevel=Logging.Info) where P <: MPolyRingElem{Nemo.QQFieldElem} Checks the local identifiability/observability of the functions in `funcs_to_check`. The result is correct with probability at least `prob_threshold`. @@ -160,7 +160,7 @@ function assess_local_identifiability( type = :SE, trbasis = nothing, loglevel = Logging.Info, -) where {P <: MPolyElem{Nemo.fmpq}} +) where {P <: MPolyRingElem{Nemo.QQFieldElem}} restart_logging(loglevel = loglevel) reset_timings() with_logger(_si_logger[]) do @@ -180,7 +180,7 @@ function _assess_local_identifiability( prob_threshold::Float64 = 0.99, type = :SE, trbasis = nothing, -) where {P <: MPolyElem{Nemo.fmpq}} +) where {P <: MPolyRingElem{Nemo.QQFieldElem}} if isempty(funcs_to_check) funcs_to_check = ode.parameters if type == :SE @@ -253,7 +253,7 @@ function _assess_local_identifiability( # in the SE case, it will exit right away while true ic = Dict(x => F(rand(1:prime)) for x in ode_red.x_vars) - inputs = Dict{Nemo.gfp_mpoly, Array{Nemo.gfp_elem, 1}}( + inputs = Dict{Nemo.gfp_mpoly, Array{Nemo.fpFieldElem, 1}}( u => [F(rand(1:prime)) for i in 1:prec] for u in ode_red.u_vars ) diff --git a/src/parametrizations.jl b/src/parametrizations.jl index a8b6e6ec4..c725c914c 100644 --- a/src/parametrizations.jl +++ b/src/parametrizations.jl @@ -174,7 +174,8 @@ $(join(map(x -> string(x[1]) * " -> " * string(x[2]), zip(fracs_gen, tag_string Saturation tag: $sat_string """ - poly_ring_tag, vars_tag = PolynomialRing(K, vcat(sat_string, orig_strings, tag_strings)) + poly_ring_tag, vars_tag = + polynomial_ring(K, vcat(sat_string, orig_strings, tag_strings)) sat_var = vars_tag[1] orig_vars = vars_tag[2:(nvars(poly_ring) + 1)] tag_vars = vars_tag[(nvars(poly_ring) + 2):end] @@ -227,7 +228,7 @@ $sat_string # # NOTE: reduction actually happens in K(T)[x]. So we map polynomials to the # parametric ring K(T)[x]. - ring_of_tags, tags = PolynomialRing(K, tag_strings) + ring_of_tags, tags = polynomial_ring(K, tag_strings) tag_to_gen = Dict(tags[i] => fracs_gen[i] for i in 1:length(fracs_gen)) if !isempty(intersect(tag_strings, orig_strings)) @warn """ @@ -236,7 +237,7 @@ $sat_string Original vars: $orig_strings""" end parametric_ring, _ = - PolynomialRing(FractionField(ring_of_tags), orig_strings, ordering = :degrevlex) + polynomial_ring(FractionField(ring_of_tags), orig_strings, ordering = :degrevlex) relations_between_tags = map(poly -> parent_ring_change(poly, ring_of_tags), relations_between_tags) param_var_mapping = merge( @@ -380,7 +381,7 @@ function reparametrize_with_respect_to(ode, new_states, new_params) input_variable_names, output_variable_names, ) - ring_output, _ = PolynomialRing( + ring_output, _ = polynomial_ring( base_ring(ring_of_tags), all_variable_names, ordering = Nemo.ordering(ring_of_tags), @@ -492,7 +493,7 @@ function _reparametrize_global(ode::ODE{P}; prob_threshold = 0.99, seed = 42) wh ode_ring = parent(ode) @assert base_ring(parent(first(id_funcs))) == ode_ring @info "Constructing a new parametrization" - contains_states(poly::MPolyElem) = any(x -> degree(poly, x) > 0, ode.x_vars) + contains_states(poly::MPolyRingElem) = any(x -> degree(poly, x) > 0, ode.x_vars) contains_states(func) = contains_states(numerator(func)) || contains_states(denominator(func)) id_funcs_contains_states = filter(contains_states, id_funcs) diff --git a/src/pb_representation.jl b/src/pb_representation.jl index 3594b143a..34a618bd4 100644 --- a/src/pb_representation.jl +++ b/src/pb_representation.jl @@ -13,7 +13,7 @@ struct PBRepresentation u_names::Array{String} # variables with infinite orders in the profile param_names::Array{String} # scalar parameters profile::Dict{String, Int} # the profile restricted on the y-variables - projections::Dict{String, <:MPolyElem} + projections::Dict{String, <:MPolyRingElem} function PBRepresentation(ode::ODE, io_equations) if length(keys(io_equations)) > length(ode.y_vars) @@ -33,10 +33,10 @@ struct PBRepresentation decompose_derivative(v, vcat(y_names, u_names)) != nothing, map(var_to_str, gens(old_ring)), ) - newring, _ = Nemo.PolynomialRing(base_ring(old_ring), new_varnames) + newring, _ = Nemo.polynomial_ring(base_ring(old_ring), new_varnames) profile = Dict{String, Int}() - projections = Dict{String, MPolyElem}() + projections = Dict{String, MPolyRingElem}() for (y, eq) in io_equations (name, ord) = decompose_derivative(var_to_str(y), y_names) profile[name] = ord @@ -60,7 +60,7 @@ Among the variables `vars`, determines the leading derivative if the y-variable (if exists) with respect to the ordering defined by the PB-representation (see Remark 2.20 in https://arxiv.org/abs/2111.00991) """ -function find_leader(vars::Array{<:MPolyElem}, pbr::PBRepresentation) +function find_leader(vars::Array{<:MPolyRingElem}, pbr::PBRepresentation) y_ders = filter(v -> decompose_derivative(var_to_str(v), pbr.y_names) != nothing, vars) if length(y_ders) == 0 return nothing @@ -83,7 +83,7 @@ For a polynomial `poly` in the same differential variables as `pbr`, finds a polynomial ring sufficient for carrying out the reduction and the corresponding differentiation mapping on the variables """ -function common_ring(poly::MPolyElem, pbr::PBRepresentation) +function common_ring(poly::MPolyRingElem, pbr::PBRepresentation) max_ords = Dict{String, Int}(v => 0 for v in vcat(pbr.y_names, pbr.u_names)) new_params = Array{String, 1}() for v in vars(poly) @@ -118,8 +118,8 @@ function common_ring(poly::MPolyElem, pbr::PBRepresentation) append!(varnames, new_params) newring, _ = - StructuralIdentifiability.Nemo.PolynomialRing(base_ring(parent(poly)), varnames) - derivation = Dict{MPolyElem, MPolyElem}() + StructuralIdentifiability.Nemo.polynomial_ring(base_ring(parent(poly)), varnames) + derivation = Dict{MPolyRingElem, MPolyRingElem}() for v in varnames d = decompose_derivative(v, vcat(pbr.y_names, pbr.u_names)) if d == nothing @@ -143,7 +143,7 @@ end Computes the leading coefficient of `f` viewed as a univariate polynomiall in variable `x` """ -function lc_univariate(f::MPolyElem, x::MPolyElem) +function lc_univariate(f::MPolyRingElem, x::MPolyRingElem) FieldType = typeof(one(base_ring(parent(f)))) dict_result = Dict{Array{Int, 1}, FieldType}() x_ind = findfirst(v -> v == x, gens(parent(f))) @@ -174,7 +174,7 @@ Input: Output: the pseudoremainder of `f` divided by `g` w.r.t. `x` """ -function pseudodivision(f::MPolyElem, g::MPolyElem, x::MPolyElem) +function pseudodivision(f::MPolyRingElem, g::MPolyRingElem, x::MPolyRingElem) result = f lcg = lc_univariate(g, x) while Nemo.degree(result, x) >= Nemo.degree(g, x) @@ -190,7 +190,7 @@ end # ----------------------------------------------------------------------------- -function diff(p::MPolyElem, derivation::Dict{<:MPolyElem, <:MPolyElem}, i::Int) +function diff(p::MPolyRingElem, derivation::Dict{<:MPolyRingElem, <:MPolyRingElem}, i::Int) if i == 0 return p end @@ -213,7 +213,7 @@ Input: Output: the result of differential reduction of `diffpoly` by `pbr` considered as a characteristic set (see Remark 2.20 in the paper) """ -function diffreduce(diffpoly::MPolyElem, pbr::PBRepresentation) +function diffreduce(diffpoly::MPolyRingElem, pbr::PBRepresentation) (ring, der) = common_ring(diffpoly, pbr) result = parent_ring_change(diffpoly, ring) diff --git a/src/power_series_utils.jl b/src/power_series_utils.jl index 3124d47c0..0e2e8e615 100644 --- a/src/power_series_utils.jl +++ b/src/power_series_utils.jl @@ -1,18 +1,18 @@ #------------------------------------------------------------------------------ -function truncate_matrix(M::MatElem{<:Generic.AbsSeriesElem}, prec::Int) +function truncate_matrix(M::MatElem{<:AbsPowerSeriesRingElem}, prec::Int) return map(e -> truncate(e, prec), M) end #------------------------------------------------------------------------------ -function matrix_set_precision!(M::MatElem{<:Generic.AbsSeriesElem}, prec::Int) +function matrix_set_precision!(M::MatElem{<:AbsPowerSeriesRingElem}, prec::Int) map(e -> set_precision!(e, prec), M) end #------------------------------------------------------------------------------ -function ps_matrix_const_term(M::MatElem{<:Generic.AbsSeriesElem}) +function ps_matrix_const_term(M::MatElem{<:AbsPowerSeriesRingElem}) return map(e -> coeff(e, 0), M) end @@ -26,7 +26,7 @@ Performs a single step of Newton iteration for inverting `M` with `Minv` being a function _matrix_inv_newton_iteration( M::MatElem{T}, Minv::MatElem{T}, -) where {T <: Generic.AbsSeriesElem{<:Generic.FieldElem}} +) where {T <: AbsPowerSeriesRingElem{<:Generic.FieldElem}} return 2 * Minv - Minv * M * Minv end @@ -44,7 +44,7 @@ Output: - the inverse of `M` computed up to `prec` """ function ps_matrix_inv( - M::MatElem{<:Generic.AbsSeriesElem{<:Generic.FieldElem}}, + M::MatElem{<:AbsPowerSeriesRingElem{<:Generic.FieldElem}}, prec::Int = -1, ) const_term = ps_matrix_const_term(M) @@ -70,7 +70,7 @@ Input: Output: - the derivative of `ps` """ -function ps_diff(ps::Generic.AbsSeriesElem{<:Generic.RingElem}) +function ps_diff(ps::AbsPowerSeriesRingElem{<:Generic.RingElem}) result = zero(parent(ps)) set_precision!(result, precision(ps)) for exp in 1:(precision(ps) - 1) @@ -89,7 +89,7 @@ Input: Output: - the integral of `ps` without constant term """ -function ps_integrate(ps::Generic.AbsSeriesElem{<:Generic.FieldElem}) +function ps_integrate(ps::AbsPowerSeriesRingElem{<:Generic.FieldElem}) result = zero(parent(ps)) set_precision!(result, precision(ps) + 1) for exp in 0:(precision(ps) - 1) @@ -109,7 +109,7 @@ Input: Output: - the natural log of `M` """ -function ps_matrix_log(M::MatElem{<:Generic.AbsSeriesElem{<:Generic.FieldElem}}) +function ps_matrix_log(M::MatElem{<:AbsPowerSeriesRingElem{<:Generic.FieldElem}}) const_term = ps_matrix_const_term(M) if const_term != one(parent(const_term)) throw(Base.DomainError("Constant term must be the identity matrix")) @@ -123,9 +123,9 @@ end #------------------------------------------------------------------------------ function _matrix_homlinear_de_newton_iteration( - A::MatElem{<:Generic.AbsSeriesElem{T}}, - Y::MatElem{<:Generic.AbsSeriesElem{T}}, - Z::MatElem{<:Generic.AbsSeriesElem{T}}, + A::MatElem{<:AbsPowerSeriesRingElem{T}}, + Y::MatElem{<:AbsPowerSeriesRingElem{T}}, + Z::MatElem{<:AbsPowerSeriesRingElem{T}}, cur_prec::Int, ) where {T <: Generic.FieldElem} Yprime = map(ps_diff, Y) @@ -150,7 +150,7 @@ Output: - matrix `Y` such that `Y' = AY` up to precision of `A - 1` and `Y(0) = Y0` """ function ps_matrix_homlinear_de( - A::MatElem{<:Generic.AbsSeriesElem{T}}, + A::MatElem{<:AbsPowerSeriesRingElem{T}}, Y0::MatElem{<:T}, prec::Int = -1, ) where {T <: Generic.FieldElem} @@ -173,10 +173,10 @@ end #------------------------------------------------------------------------------ function _variation_of_constants( - A::MatElem{<:Generic.AbsSeriesElem{T}}, - B::MatElem{<:Generic.AbsSeriesElem{T}}, - Yh::MatElem{<:Generic.AbsSeriesElem{T}}, - Zh::MatElem{<:Generic.AbsSeriesElem{T}}, + A::MatElem{<:AbsPowerSeriesRingElem{T}}, + B::MatElem{<:AbsPowerSeriesRingElem{T}}, + Yh::MatElem{<:AbsPowerSeriesRingElem{T}}, + Zh::MatElem{<:AbsPowerSeriesRingElem{T}}, Y0::MatElem{<:T}, prec::Int, ) where {T <: Generic.FieldElem} @@ -198,8 +198,8 @@ Output: - matrix `Y` such that `Y' = AY + B` up to precision of `A - 1` and `Y(0) = Y0` """ function ps_matrix_linear_de( - A::MatElem{<:Generic.AbsSeriesElem{T}}, - B::MatElem{<:Generic.AbsSeriesElem{T}}, + A::MatElem{<:AbsPowerSeriesRingElem{T}}, + B::MatElem{<:AbsPowerSeriesRingElem{T}}, Y0::MatElem{<:T}, prec::Int = -1, ) where {T <: Generic.FieldElem} @@ -231,7 +231,7 @@ function ps_ode_solution( ic::Dict{P, T}, inputs::Dict{P, Array{T, 1}}, prec::Int, -) where {T <: Generic.FieldElem, P <: MPolyElem{T}} +) where {T <: Generic.FieldElem, P <: MPolyRingElem{T}} n = length(equations) ring = parent(equations[1]) S = AbstractAlgebra.MatrixSpace(ring, n, n) @@ -292,7 +292,7 @@ function ps_ode_solution( ic::Dict{P, Int}, inputs::Dict{P, Array{Int, 1}}, prec::Int, -) where {P <: MPolyElem{<:Generic.FieldElem}} +) where {P <: MPolyRingElem{<:Generic.FieldElem}} bring = base_ring(parent(equations[1])) ps_ode_solution( equations, diff --git a/src/primality_check.jl b/src/primality_check.jl index ae98f006b..e236849d5 100644 --- a/src/primality_check.jl +++ b/src/primality_check.jl @@ -1,6 +1,6 @@ # ------------------------------------------------------------------------------ -function check_primality_zerodim(J::Array{fmpq_mpoly, 1}) +function check_primality_zerodim(J::Array{QQMPolyRingElem, 1}) J = Groebner.groebner(J, loglevel = _groebner_loglevel[]) basis = Groebner.kbase(J, loglevel = _groebner_loglevel[]) dim = length(basis) @@ -22,7 +22,7 @@ function check_primality_zerodim(J::Array{fmpq_mpoly, 1}) generic_multiplication = sum(Nemo.QQ(rand(1:100)) * M for M in matrices) @debug generic_multiplication - R, t = Nemo.PolynomialRing(Nemo.QQ, "t") + R, t = Nemo.polynomial_ring(Nemo.QQ, "t") @debug "$(Nemo.charpoly(R, generic_multiplication))" return Nemo.isirreducible(Nemo.charpoly(R, generic_multiplication)) @@ -30,7 +30,7 @@ end #------------------------------------------------------------------------------ """ - check_primality(polys::Dict{fmpq_mpoly, fmpq_mpoly}, extra_relations::Array{fmpq_mpoly, 1}) + check_primality(polys::Dict{QQMPolyRingElem, QQMPolyRingElem}, extra_relations::Array{QQMPolyRingElem, 1}) The function checks if the ideal generated by the polynomials and saturated at the leading coefficient with respect to the corresponding variables is prime @@ -39,13 +39,13 @@ over rationals. The `extra_relations` allows adding more polynomials to the generators (not affecting the saturation). """ function check_primality( - polys::Dict{fmpq_mpoly, fmpq_mpoly}, - extra_relations::Array{fmpq_mpoly, 1}, + polys::Dict{QQMPolyRingElem, QQMPolyRingElem}, + extra_relations::Array{QQMPolyRingElem, 1}, ) leaders = collect(keys(polys)) ring = parent(leaders[1]) - Rspec, vspec = Nemo.PolynomialRing(Nemo.QQ, [var_to_str(l) for l in leaders]) + Rspec, vspec = Nemo.polynomial_ring(Nemo.QQ, [var_to_str(l) for l in leaders]) eval_point = [v in keys(polys) ? v : ring(rand(1:100)) for v in gens(ring)] all_polys = vcat(collect(values(polys)), extra_relations) zerodim_ideal = @@ -56,14 +56,14 @@ end #------------------------------------------------------------------------------ """ - check_primality(polys::Dict{fmpq_mpoly, fmpq_mpoly}) + check_primality(polys::Dict{QQMPolyRingElem, QQMPolyRingElem}) The function checks if the ideal generated by the polynomials and saturated at the leading coefficient with respect to the corresponding variables is prime over rationals. """ -function check_primality(polys::Dict{fmpq_mpoly, fmpq_mpoly}) - return check_primality(polys, Array{fmpq_mpoly, 1}()) +function check_primality(polys::Dict{QQMPolyRingElem, QQMPolyRingElem}) + return check_primality(polys, Array{QQMPolyRingElem, 1}()) end # ------------------------------------------------------------------------------ diff --git a/src/states.jl b/src/states.jl index c706a9ab5..86e0269d8 100644 --- a/src/states.jl +++ b/src/states.jl @@ -15,7 +15,7 @@ Output: function extract_coefficients_ratfunc( f::AbstractAlgebra.Generic.Frac{<:P}, vars::Vector{<:P}, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} num, denom = unpack_fraction(f) total_coeffs = Vector{P}() for p in (num, denom) @@ -32,7 +32,7 @@ end function extract_coefficients_ratfunc( f::P, vars::Vector{<:P}, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} return extract_coefficients_ratfunc(f // 1, vars) end @@ -50,7 +50,7 @@ Output: function lie_derivative( f::Generic.Frac{<:P}, ode::ODE{<:P}, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} @assert all([(x in ode.parameters) || (x in ode.x_vars) for x in vars(f)]) res = zero(parent(ode)) // 1 for (x, eq) in ode.x_equations @@ -59,7 +59,7 @@ function lie_derivative( return res end -function lie_derivative(f::P, ode::ODE{<:P}) where {P <: MPolyElem{<:FieldElem}} +function lie_derivative(f::P, ode::ODE{<:P}) where {P <: MPolyRingElem{<:FieldElem}} return lie_derivative(f // 1, ode) end @@ -79,7 +79,7 @@ identifiable functions of parameters only @timeit _to function states_generators( ode::ODE{P}, io_equations::Dict{P, P}, -) where {P <: MPolyElem{<:FieldElem}} +) where {P <: MPolyRingElem{<:FieldElem}} y_to_ord = Dict{P, Int}() ynames = [var_to_str(y) for y in ode.y_vars] for (leader, ioeq) in io_equations diff --git a/src/submodels.jl b/src/submodels.jl index 107ceac4e..793e77ba4 100644 --- a/src/submodels.jl +++ b/src/submodels.jl @@ -12,15 +12,15 @@ Output: - Dictionary where each key is a variable and each value is a list of variables on which the key depends """ -function construct_graph(ode::ODE{P}) where {P <: MPolyElem} - graph = Dict{fmpq_mpoly, Set{fmpq_mpoly}}() +function construct_graph(ode::ODE{P}) where {P <: MPolyRingElem} + graph = Dict{QQMPolyRingElem, Set{QQMPolyRingElem}}() for (x, f) in ode.x_equations temp = unpack_fraction(f) - graph[x] = Set{fmpq_mpoly}(union(vars(temp[1]), vars(temp[2]))) + graph[x] = Set{QQMPolyRingElem}(union(vars(temp[1]), vars(temp[2]))) end for (y, f) in ode.y_equations temp = unpack_fraction(f) - graph[y] = Set{fmpq_mpoly}(union(vars(temp[1]), vars(temp[2]))) + graph[y] = Set{QQMPolyRingElem}(union(vars(temp[1]), vars(temp[2]))) end return graph @@ -29,9 +29,9 @@ end # ------------------------------------------------------------------------------ function dfs( - graph::Dict{fmpq_mpoly, Set{fmpq_mpoly}}, - start::fmpq_mpoly, - visited::Set{fmpq_mpoly}, + graph::Dict{QQMPolyRingElem, Set{QQMPolyRingElem}}, + start::QQMPolyRingElem, + visited::Set{QQMPolyRingElem}, ) push!(visited, start) if start in keys(graph) @@ -47,12 +47,12 @@ end # ------------------------------------------------------------------------------ function traverse_outputs( - graph::Dict{fmpq_mpoly, Set{fmpq_mpoly}}, - ys::Array{fmpq_mpoly, 1}, + graph::Dict{QQMPolyRingElem, Set{QQMPolyRingElem}}, + ys::Array{QQMPolyRingElem, 1}, ) - raw_models = Dict{fmpq_mpoly, Set{fmpq_mpoly}}() + raw_models = Dict{QQMPolyRingElem, Set{QQMPolyRingElem}}() for y in ys - model = dfs(graph, y, Set{fmpq_mpoly}()) + model = dfs(graph, y, Set{QQMPolyRingElem}()) raw_models[y] = model end return raw_models @@ -61,10 +61,10 @@ end # ------------------------------------------------------------------------------ function saturate_ys( - unions::Array{Set{fmpq_mpoly}, 1}, - Y::Array{fmpq_mpoly, 1}, - graph::Dict{fmpq_mpoly, Set{fmpq_mpoly}}, - X::Array{fmpq_mpoly, 1}, + unions::Array{Set{QQMPolyRingElem}, 1}, + Y::Array{QQMPolyRingElem, 1}, + graph::Dict{QQMPolyRingElem, Set{QQMPolyRingElem}}, + X::Array{QQMPolyRingElem, 1}, ) for element in unions for y in Y @@ -78,8 +78,8 @@ end # ------------------------------------------------------------------------------ -function search_add_unions(submodels::Array{Set{fmpq_mpoly}, 1}) - result = Array{Set{fmpq_mpoly}, 1}([Set{fmpq_mpoly}()]) +function search_add_unions(submodels::Array{Set{QQMPolyRingElem}, 1}) + result = Array{Set{QQMPolyRingElem}, 1}([Set{QQMPolyRingElem}()]) for model in submodels for index in 1:length(result) push!(result, union(result[index], model)) @@ -93,10 +93,10 @@ end # filters the models containin all states or no states function filter_max_empty( ode::ODE{P}, - submodels::Array{Set{fmpq_mpoly}, 1}, -) where {P <: MPolyElem} + submodels::Array{Set{QQMPolyRingElem}, 1}, +) where {P <: MPolyRingElem} n = length(ode.x_vars) - new_sub = Array{Set{fmpq_mpoly}, 1}([]) + new_sub = Array{Set{QQMPolyRingElem}, 1}([]) for submodel in submodels list_x = [x for x in submodel if x in ode.x_vars] if !(length(list_x) == n) && (length(list_x) > 0) @@ -108,10 +108,10 @@ end # ------------------------------------------------------------------------------ -function ode_aux(ode::ODE{P}, submodel::Set{fmpq_mpoly}) where {P <: MPolyElem} +function ode_aux(ode::ODE{P}, submodel::Set{QQMPolyRingElem}) where {P <: MPolyRingElem} new_y = copy(ode.y_equations) new_x = copy(ode.x_equations) - new_u = Array{fmpq_mpoly, 1}([u for u in ode.u_vars if u in submodel]) + new_u = Array{QQMPolyRingElem, 1}([u for u in ode.u_vars if u in submodel]) for (x, f) in ode.x_equations if !(issubset(vars(x), submodel) && issubset(vars(f), submodel)) delete!(new_x, x) @@ -125,8 +125,8 @@ function ode_aux(ode::ODE{P}, submodel::Set{fmpq_mpoly}) where {P <: MPolyElem} end sub_str = map(var_to_str, collect(submodel)) - S, _ = Nemo.PolynomialRing(Nemo.QQ, sub_str) - dict_type = Dict{fmpq_mpoly, Union{fmpq_mpoly, Generic.Frac{fmpq_mpoly}}} + S, _ = Nemo.polynomial_ring(Nemo.QQ, sub_str) + dict_type = Dict{QQMPolyRingElem, Union{QQMPolyRingElem, Generic.Frac{QQMPolyRingElem}}} fin_x = dict_type(parent_ring_change(x, S) => parent_ring_change(f, S) for (x, f) in new_x) fin_y = @@ -142,7 +142,7 @@ function ode_aux(ode::ODE{P}, submodel::Set{fmpq_mpoly}) where {P <: MPolyElem} y in ode.y_vars if var_to_str(y) in map(var_to_str, collect(keys(fin_y))) ] - return ODE{fmpq_mpoly}(new_x_vars, new_y_vars, fin_x, fin_y, fin_u) + return ODE{QQMPolyRingElem}(new_x_vars, new_y_vars, fin_x, fin_y, fin_u) end # ------------------------------------------------------------------------------ @@ -163,8 +163,8 @@ Output: function submodel2ode( ode::ODE{P}, - submodels::Array{Set{fmpq_mpoly}, 1}, -) where {P <: MPolyElem} + submodels::Array{Set{QQMPolyRingElem}, 1}, +) where {P <: MPolyRingElem} return [ode_aux(ode, submodel) for submodel in submodels] end @@ -187,14 +187,14 @@ Example: y1(t) = x1(t), y2(t) = x2(t)) >find_submodels(ode) - ODE{fmpq_mpoly}[ + ODE{QQMPolyRingElem}[ x1'(t) = a(t)*x2(t)^2 + x1(t) y1(t) = x1(t) ] ``` """ -function find_submodels(ode::ODE{P}) where {P <: MPolyElem} +function find_submodels(ode::ODE{P}) where {P <: MPolyRingElem} graph = construct_graph(ode) ys = ode.y_vars xs = ode.x_vars diff --git a/src/util.jl b/src/util.jl index b6cb29d83..5ed817315 100644 --- a/src/util.jl +++ b/src/util.jl @@ -1,10 +1,10 @@ # ------------------------------------------------------------------------------ -function Nemo.vars(f::Generic.Frac{<:MPolyElem}) +function Nemo.vars(f::Generic.Frac{<:MPolyRingElem}) return collect(union(Set(vars(numerator(f))), Set(vars(denominator(f))))) end -function Nemo.total_degree(f::Generic.Frac{<:MPolyElem}) +function Nemo.total_degree(f::Generic.Frac{<:MPolyRingElem}) return sum(map(total_degree, unpack_fraction(f))) end @@ -36,13 +36,13 @@ end Evaluates a polynomial/rational function on a dictionary of type `var => val` and missing values are replaced with zeroes """ -function eval_at_dict(poly::P, d::Dict{P, <:RingElem}) where {P <: MPolyElem} +function eval_at_dict(poly::P, d::Dict{P, <:RingElem}) where {P <: MPolyRingElem} R = parent(first(values(d))) point = [get(d, v, zero(R)) for v in gens(parent(poly))] return evaluate(poly, point) end -function eval_at_dict(poly::P, d::Dict{P, S}) where {P <: MPolyElem, S <: Real} +function eval_at_dict(poly::P, d::Dict{P, S}) where {P <: MPolyRingElem, S <: Real} R = parent(poly) @assert R == parent(first(keys(d))) xs = gens(parent(first(keys(d)))) @@ -59,7 +59,10 @@ function eval_at_dict(poly::P, d::Dict{P, S}) where {P <: MPolyElem, S <: Real} return accum end -function eval_at_dict(rational::Generic.Frac{T}, d::Dict{T, V}) where {T <: MPolyElem, V} +function eval_at_dict( + rational::Generic.Frac{T}, + d::Dict{T, V}, +) where {T <: MPolyRingElem, V} f, g = unpack_fraction(rational) return eval_at_dict(f, d) / eval_at_dict(g, d) end @@ -67,7 +70,7 @@ end function eval_at_dict( rational::Generic.Frac{<:T}, d::Dict{T, <:RingElem}, -) where {T <: MPolyElem} +) where {T <: MPolyRingElem} f, g = unpack_fraction(rational) return eval_at_dict(f, d) * inv(eval_at_dict(g, d)) end @@ -75,24 +78,24 @@ end function eval_at_dict( rational::Generic.Frac{<:P}, d::Dict{<:P, <:Union{<:Generic.Frac, <:P}}, -) where {P <: MPolyElem} +) where {P <: MPolyRingElem} f, g = unpack_fraction(rational) return eval_at_dict(f, d) // eval_at_dict(g, d) end # ------------------------------------------------------------------------------ -function unpack_fraction(f::MPolyElem) +function unpack_fraction(f::MPolyRingElem) return (f, one(parent(f))) end -function unpack_fraction(f::Generic.Frac{<:MPolyElem}) +function unpack_fraction(f::Generic.Frac{<:MPolyRingElem}) return (numerator(f), denominator(f)) end # ------------------------------------------------------------------------------ -function simplify_frac(numer::P, denom::P) where {P <: MPolyElem} +function simplify_frac(numer::P, denom::P) where {P <: MPolyRingElem} gcd_sub = gcd(numer, denom) sub_numer = divexact(numer, gcd_sub) sub_denom = divexact(denom, gcd_sub) @@ -163,7 +166,7 @@ function make_substitution( var_sub::P, val_numer::P, val_denom::P, -) where {P <: MPolyElem} +) where {P <: MPolyRingElem} d = Nemo.degree(f, var_sub) result = 0 @@ -180,7 +183,7 @@ end function homogenize(fs) ring = parent(fs[1]) - newring, hom_vars = PolynomialRing( + newring, hom_vars = polynomial_ring( base_ring(ring), vcat("X0", map(string, gens(ring))), ordering = ordering(ring), @@ -202,7 +205,7 @@ end function dehomogenize(Fs) ring = parent(Fs[1]) - newring, dehom_vars = PolynomialRing( + newring, dehom_vars = polynomial_ring( base_ring(ring), map(string, gens(ring)[2:end]), ordering = ordering(ring), @@ -229,7 +232,7 @@ Output: - a polynomial in `new_ring` “equal” to `poly` """ function parent_ring_change( - poly::MPolyElem, + poly::MPolyRingElem, new_ring::MPolyRing; matching = :byname, shift = 0, @@ -279,7 +282,7 @@ function parent_ring_change( end function parent_ring_change( - f::Generic.Frac{<:MPolyElem}, + f::Generic.Frac{<:MPolyRingElem}, new_ring::MPolyRing; matching = :byname, ) @@ -301,7 +304,7 @@ Output: - `div`'s are divisors of `f` such that `f` is their product with certain powers - if `certainty` is true, `div` is ``Q``-irreducible """ -function uncertain_factorization(f::MPolyElem{fmpq}) +function uncertain_factorization(f::MPolyRingElem{QQFieldElem}) vars_f = vars(f) if isempty(vars_f) return Array{Tuple{typeof(f), Bool}, 1}() @@ -319,7 +322,7 @@ function uncertain_factorization(f::MPolyElem{fmpq}) while true plugin = rand(-3:3, length(gens(parent(f)))) if evaluate(mainvar_coeffs[end], plugin) != 0 - uni_ring, T = Nemo.PolynomialRing(base_ring(f), "T") + uni_ring, T = Nemo.polynomial_ring(base_ring(f), "T") f_uni = sum([evaluate(mainvar_coeffs[i + 1], plugin) * T^i for i in 0:d]) if !isone(gcd(f_uni, derivative(f_uni))) factor_out = gcd(f, derivative(f, main_var)) @@ -342,7 +345,7 @@ end # ------------------------------------------------------------------------------ -function fast_factor(poly::MPolyElem{fmpq}) +function fast_factor(poly::MPolyRingElem{QQFieldElem}) prelim_factors = uncertain_factorization(poly) cert_factors = map(pair -> pair[1], filter(f -> f[2], prelim_factors)) uncert_factors = map(pair -> pair[1], filter(f -> !f[2], prelim_factors)) @@ -375,7 +378,7 @@ Input: Output: - dictionary with keys being tuples of length `lenght(variables)` and values being polynomials in the variables other than those which are the coefficients at the corresponding monomials (in a smaller polynomial ring) """ -function extract_coefficients(poly::P, variables::Array{P, 1}) where {P <: MPolyElem} +function extract_coefficients(poly::P, variables::Array{P, 1}) where {P <: MPolyRingElem} xs = gens(parent(poly)) @assert all(in(xs), variables) cut_indices = map(v -> findfirst(x -> x == v, xs), variables) @@ -383,7 +386,7 @@ function extract_coefficients(poly::P, variables::Array{P, 1}) where {P <: MPoly coeff_vars = xs[coeff_indices] K = base_ring(parent(poly)) - new_ring, _ = Nemo.PolynomialRing(K, map(vv -> var_to_str(vv, xs = xs), coeff_vars)) + new_ring, _ = Nemo.polynomial_ring(K, map(vv -> var_to_str(vv, xs = xs), coeff_vars)) FieldType = elem_type(K) result = Dict{Vector{Int}, Tuple{Vector{Vector{Int}}, Vector{FieldType}}}() @@ -422,7 +425,7 @@ end # ------------------------------------------------------------------------------ -function var_to_str(v::MPolyElem; xs = gens(parent(v))) +function var_to_str(v::MPolyRingElem; xs = gens(parent(v))) ind = findfirst(vv -> vv == v, xs) return string(symbols(parent(v))[ind]) end @@ -470,7 +473,7 @@ end For a variable `v`, returns a variable in `ring` with the same name """ -function switch_ring(v::MPolyElem, ring::MPolyRing) +function switch_ring(v::MPolyRingElem, ring::MPolyRing) ind = findfirst(vv -> vv == v, gens(parent(v))) return str_to_var(string(symbols(parent(v))[ind]), ring) @@ -504,7 +507,7 @@ Finds the order of a differential polynomial `diffpoly` in a variable `prefix`, returns -1 is the variable does not appear """ -function difforder(diffpoly::MPolyElem, prefix::String) +function difforder(diffpoly::MPolyRingElem, prefix::String) orders = [-1] for v in vars(diffpoly) d = decompose_derivative(var_to_str(v), [prefix]) diff --git a/src/wronskian.jl b/src/wronskian.jl index d796f4758..85bee6870 100644 --- a/src/wronskian.jl +++ b/src/wronskian.jl @@ -20,7 +20,7 @@ function monomial_compress(io_equation, ode::ODE) return monomial_compress(io_equation, ode.parameters) end -function monomial_compress(io_equation, params::Array{<:MPolyElem, 1}) +function monomial_compress(io_equation, params::Array{<:MPolyRingElem, 1}) params_xs = isempty(params) ? empty(params) : gens(parent(first(params))) other_vars = [ v for v in gens(parent(io_equation)) if @@ -197,7 +197,10 @@ Output: Computes the Wronskians of io_equations """ -@timeit _to function wronskian(io_equations::Dict{P, P}, ode::ODE{P}) where {P <: MPolyElem} +@timeit _to function wronskian( + io_equations::Dict{P, P}, + ode::ODE{P}, +) where {P <: MPolyRingElem} @debug "Compressing monomials" termlists = [monomial_compress(ioeq, ode)[2] for ioeq in values(io_equations)] @debug "Matrix sizes $(map(length, termlists))" @@ -209,7 +212,7 @@ Computes the Wronskians of io_equations PRIME = 2^31 - 1 F = Nemo.Native.GF(PRIME) polyring_red, gens_red = - Nemo.PolynomialRing(F, map(var_to_str, gens(parent(termlists[1][1])))) + Nemo.polynomial_ring(F, map(var_to_str, gens(parent(termlists[1][1])))) termlists = [map(p -> parent_ring_change(p, polyring_red), tlist) for tlist in termlists] ode_red = reduce_ode_mod_p(ode, PRIME) @@ -223,7 +226,7 @@ Computes the Wronskians of io_equations ord, ) @debug "Computing the derivatives of the solution" - ps_ext = Dict{MPolyElem, Nemo.gfp_abs_series}()# Generic.AbsSeries}() + ps_ext = Dict{MPolyRingElem, Nemo.gfp_abs_series}()# Generic.AbsSeries}() for v in vcat(ode_red.y_vars, ode_red.u_vars) cur_ps = ps[v] for i in 0:length(ode_red.x_vars) diff --git a/test/RationalFunctionFields/normalforms.jl b/test/RationalFunctionFields/normalforms.jl index b8c503de7..40381e74c 100644 --- a/test/RationalFunctionFields/normalforms.jl +++ b/test/RationalFunctionFields/normalforms.jl @@ -63,7 +63,7 @@ if GROUP == "All" || GROUP == "Core" ### # Some arbitrary generators for the SLIQR model R, (b, e, In, S, Ninv, s, Q, g, u, a, y, L) = - PolynomialRing(QQ, [:b, :e, :In, :S, :Ninv, :s, :Q, :g, :u, :a, :y, :L]) + polynomial_ring(QQ, [:b, :e, :In, :S, :Ninv, :s, :Q, :g, :u, :a, :y, :L]) f = [ In // one(R), s // one(R), diff --git a/test/check_field_membership.jl b/test/check_field_membership.jl index 3c42a3ed0..72f8eec82 100644 --- a/test/check_field_membership.jl +++ b/test/check_field_membership.jl @@ -1,6 +1,6 @@ if GROUP == "All" || GROUP == "Core" @testset "Check field membership" begin - R, (x, y, z) = Nemo.PolynomialRing(Nemo.QQ, ["x", "y", "z"]) + R, (x, y, z) = Nemo.polynomial_ring(Nemo.QQ, ["x", "y", "z"]) @test field_contains( RationalFunctionField([[R(1), x + y], [R(1), x * y], [z, (x + y)^2]]), diff --git a/test/check_primality_zerodim.jl b/test/check_primality_zerodim.jl index 2ac4005d5..b9e880f1f 100644 --- a/test/check_primality_zerodim.jl +++ b/test/check_primality_zerodim.jl @@ -1,6 +1,6 @@ if GROUP == "All" || GROUP == "Core" @testset "Primality check (zerodim subroutine)" begin - R, (x, y) = Nemo.PolynomialRing(Nemo.QQ, ["x", "y"]) + R, (x, y) = Nemo.polynomial_ring(Nemo.QQ, ["x", "y"]) @test check_primality_zerodim([x^2 - 1, y^2 - 4]) == false diff --git a/test/common_ring.jl b/test/common_ring.jl index 68c3e5bde..acec21ecf 100644 --- a/test/common_ring.jl +++ b/test/common_ring.jl @@ -3,7 +3,7 @@ if GROUP == "All" || GROUP == "Core" ode = @ODEmodel(x1'(t) = x2(t), x2'(t) = a * x1(t), y(t) = x1(t)) ioeqs = find_ioequations(ode) pbr = PBRepresentation(ode, ioeqs) - R, (y_2, y_5, c) = Nemo.PolynomialRing(Nemo.QQ, ["y(t)_2", "y(t)_5", "c"]) + R, (y_2, y_5, c) = Nemo.polynomial_ring(Nemo.QQ, ["y(t)_2", "y(t)_5", "c"]) p = y_2^2 + c * y_5 (r, der) = common_ring(p, pbr) @test Set(map(var_to_str, gens(r))) == @@ -19,7 +19,7 @@ if GROUP == "All" || GROUP == "Core" ioeqs = find_ioequations(ode) pbr = PBRepresentation(ode, ioeqs) R, (y1_0, y2_3, u_3) = - Nemo.PolynomialRing(Nemo.QQ, ["y1(t)_0", "y2(t)_3", "u(t)_3"]) + Nemo.polynomial_ring(Nemo.QQ, ["y1(t)_0", "y2(t)_3", "u(t)_3"]) p = y1_0 + y2_3 + u_3 (r, der) = common_ring(p, pbr) @test Set([var_to_str(v) for v in gens(r)]) == Set([ diff --git a/test/constructive_membership.jl b/test/constructive_membership.jl index d568a52b4..56bfe0636 100644 --- a/test/constructive_membership.jl +++ b/test/constructive_membership.jl @@ -1,6 +1,6 @@ if GROUP == "All" || GROUP == "Core" @testset "Constructive field membership" begin - R, (x,) = PolynomialRing(Nemo.QQ, ["x"]) + R, (x,) = polynomial_ring(Nemo.QQ, ["x"]) generators = [x^2, x^3] to_be_reduced = [x^2, x, 3one(R), zero(R)] @@ -22,13 +22,13 @@ if GROUP == "All" || GROUP == "Core" cases = [] - R, (T1,) = PolynomialRing(Nemo.QQ, ["T1"]) + R, (T1,) = polynomial_ring(Nemo.QQ, ["T1"]) append!( cases, [(generators = [T1^2], to_be_reduced = [T1, T1^2], memberships = Bool[0, 1])], ) - R, (T1, t, _t) = PolynomialRing(Nemo.QQ, ["T1", "t", "_t"]) + R, (T1, t, _t) = polynomial_ring(Nemo.QQ, ["T1", "t", "_t"]) append!( cases, [( @@ -38,7 +38,7 @@ if GROUP == "All" || GROUP == "Core" )], ) - R, (x,) = PolynomialRing(Nemo.QQ, ["x"]) + R, (x,) = polynomial_ring(Nemo.QQ, ["x"]) append!( cases, [ @@ -60,7 +60,7 @@ if GROUP == "All" || GROUP == "Core" ], ) - R, (x, y, z) = PolynomialRing(Nemo.QQ, ["x", "y", "z"]) + R, (x, y, z) = polynomial_ring(Nemo.QQ, ["x", "y", "z"]) append!( cases, [ @@ -84,7 +84,7 @@ if GROUP == "All" || GROUP == "Core" # NOTE: in this case it actually matter to cancel out the gcd after # computing the normal forms - R, (a, b, y, x2, c, x1) = PolynomialRing(Nemo.QQ, ["a", "b", "y", "x2", "c", "x1"]) + R, (a, b, y, x2, c, x1) = polynomial_ring(Nemo.QQ, ["a", "b", "y", "x2", "c", "x1"]) append!( cases, [ diff --git a/test/diff_sequence_solution.jl b/test/diff_sequence_solution.jl index c23475807..143654053 100644 --- a/test/diff_sequence_solution.jl +++ b/test/diff_sequence_solution.jl @@ -7,13 +7,13 @@ if GROUP == "All" || GROUP == "Core" ic::Dict{P, T}, inputs::Dict{P, Array{T, 1}}, num_terms::Int, - ) where {T <: Generic.FieldElem, P <: MPolyElem{T}} + ) where {T <: Generic.FieldElem, P <: MPolyRingElem{T}} newvars = [var_to_str(v) for v in gens(dds.poly_ring)] append!( newvars, [var_to_str(v) * "$i" for v in dds.u_vars for i in 1:num_terms], ) - R, _ = StructuralIdentifiability.Nemo.PolynomialRing( + R, _ = StructuralIdentifiability.Nemo.polynomial_ring( base_ring(dds.poly_ring), newvars, ) diff --git a/test/differentiate_output.jl b/test/differentiate_output.jl index f9a191bae..9d978b6e0 100644 --- a/test/differentiate_output.jl +++ b/test/differentiate_output.jl @@ -10,7 +10,7 @@ if GROUP == "All" || GROUP == "Core" [var_to_str(u) * "_$i" for u in ode.u_vars for i in 0:(prec - 1)], ) end - new_ring, vars = Nemo.PolynomialRing(base_ring(ode.poly_ring), new_varnames) + new_ring, vars = Nemo.polynomial_ring(base_ring(ode.poly_ring), new_varnames) # mapping everything to the new ring eval_point = Dict(v => switch_ring(v, new_ring) for v in gens(ode.poly_ring)) @@ -108,7 +108,7 @@ if GROUP == "All" || GROUP == "Core" @testset "Partial derivatives of an output w.r.t. to initial conditions and parameters" begin test_cases = [] - P = fmpq_mpoly + P = QQMPolyRingElem DType = Union{P, Generic.Frac{P}} ode = @ODEmodel(x'(t) = x(t) + a, y(t) = x(t)^2) @@ -118,7 +118,7 @@ if GROUP == "All" || GROUP == "Core" :ODE => ode, :ic => Dict(x => Nemo.QQ(rand(1:10))), :param_vals => Dict(a => Nemo.QQ(rand(1:10))), - :inputs => Dict{P, Array{fmpq, 1}}(), + :inputs => Dict{P, Array{QQFieldElem, 1}}(), :prec => 20, ), ) @@ -130,7 +130,7 @@ if GROUP == "All" || GROUP == "Core" :ODE => ode, :ic => Dict(x => Nemo.QQ(rand(1:10))), :param_vals => Dict(a => Nemo.QQ(rand(1:10))), - :inputs => Dict{P, Array{fmpq, 1}}(), + :inputs => Dict{P, Array{QQFieldElem, 1}}(), :prec => 20, ), ) @@ -147,7 +147,7 @@ if GROUP == "All" || GROUP == "Core" :ODE => ode, :ic => Dict(x => Nemo.QQ(rand(1:10)), y => Nemo.QQ(rand(1:10))), :param_vals => Dict(a => Nemo.QQ(rand(1:10)), b => Nemo.QQ(rand(1:10))), - :inputs => Dict{P, Array{fmpq, 1}}(), + :inputs => Dict{P, Array{QQFieldElem, 1}}(), :prec => 8, ), ) @@ -174,7 +174,7 @@ if GROUP == "All" || GROUP == "Core" ["u_$i" for i in 1:2], ["y_$i" for i in 1:3], ) - R, vars = Nemo.PolynomialRing(F, varnames) + R, vars = Nemo.polynomial_ring(F, varnames) push!( test_cases, Dict( @@ -196,7 +196,7 @@ if GROUP == "All" || GROUP == "Core" ["u_$i" for i in 1:2], ["y_$i" for i in 1:3], ) - R, vars = Nemo.PolynomialRing(F, varnames) + R, vars = Nemo.polynomial_ring(F, varnames) push!( test_cases, Dict( @@ -213,7 +213,7 @@ if GROUP == "All" || GROUP == "Core" ) varnames = vcat(["x_$i" for i in 1:2], ["p_$i" for i in 1:2], "u", ["y_1", "y_2"]) - R, vars = Nemo.PolynomialRing(F, varnames) + R, vars = Nemo.polynomial_ring(F, varnames) push!( test_cases, Dict( diff --git a/test/diffreduction.jl b/test/diffreduction.jl index 338a29be8..556a44d5c 100644 --- a/test/diffreduction.jl +++ b/test/diffreduction.jl @@ -2,7 +2,7 @@ if GROUP == "All" || GROUP == "Core" @testset "Differential reduction" begin ode = @ODEmodel(x'(t) = a * x(t), y(t) = x(t)) pbr = PBRepresentation(ode, find_ioequations(ode)) - R, (y_5, y_4) = Nemo.PolynomialRing(Nemo.QQ, ["y(t)_5", "y(t)_4"]) + R, (y_5, y_4) = Nemo.polynomial_ring(Nemo.QQ, ["y(t)_5", "y(t)_4"]) res = diffreduce(y_5, pbr) @test res == str_to_var("a", parent(res))^5 * str_to_var("y(t)_0", parent(res)) res = diffreduce(y_4, pbr) @@ -12,7 +12,7 @@ if GROUP == "All" || GROUP == "Core" ode = @ODEmodel(x1'(t) = x2(t), x2'(t) = -x1(t), y(t) = x1(t) + u(t)) pbr = PBRepresentation(ode, find_ioequations(ode)) - R, (y_5, y_4, u_10) = Nemo.PolynomialRing(Nemo.QQ, ["y(t)_5", "y(t)_4", "u(t)_10"]) + R, (y_5, y_4, u_10) = Nemo.polynomial_ring(Nemo.QQ, ["y(t)_5", "y(t)_4", "u(t)_10"]) res = diffreduce(y_4 + u_10, pbr) @test res == str_to_var("u(t)_10", parent(res)) + str_to_var("y(t)_0", parent(res)) - @@ -21,7 +21,7 @@ if GROUP == "All" || GROUP == "Core" # Next two verified with Maple # Mizuka's example R, (y_0, y_1, y_2, y_3, u_0, u_1, u_2) = - Nemo.PolynomialRing(Nemo.QQ, ["y_0", "y_1", "y_2", "y_3", "u_0", "u_1", "u_2"]) + Nemo.polynomial_ring(Nemo.QQ, ["y_0", "y_1", "y_2", "y_3", "u_0", "u_1", "u_2"]) pbr = PBRepresentation( ["y"], ["u"], @@ -130,7 +130,7 @@ if GROUP == "All" || GROUP == "Core" y(t) = x1(t) ) pbr = PBRepresentation(ode, find_ioequations(ode)) - R, (y_0, y_1, y_2, y_3, y_4, u_0, u_3) = Nemo.PolynomialRing( + R, (y_0, y_1, y_2, y_3, y_4, u_0, u_3) = Nemo.polynomial_ring( Nemo.QQ, ["y(t)_0", "y(t)_1", "y(t)_2", "y(t)_3", "y(t)_4", "u(t)_0", "u(t)_3"], ) diff --git a/test/extract_coefficients.jl b/test/extract_coefficients.jl index 7237ac142..a6092a23f 100644 --- a/test/extract_coefficients.jl +++ b/test/extract_coefficients.jl @@ -1,6 +1,6 @@ if GROUP == "All" || GROUP == "Core" @testset "Coefficient extraction for rational fucntions" begin - R, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"]) + R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]) C = extract_coefficients_ratfunc( (x^2 + y * z - y^2 * z^3 + 3 * x * z^3) // (x + y + z + z^2 * (x^2 + 1)), [z], @@ -15,12 +15,12 @@ if GROUP == "All" || GROUP == "Core" (x^2 + 1) // 1, ]) - R, (x, y) = PolynomialRing(QQ, ["x", "y"]) + R, (x, y) = polynomial_ring(QQ, ["x", "y"]) f = (x^2 + y^2) // (1 - x - 3 * y) - @test Set(extract_coefficients_ratfunc(f, Vector{Nemo.fmpq_mpoly}())) == + @test Set(extract_coefficients_ratfunc(f, Vector{Nemo.QQMPolyRingElem}())) == Set([f, one(R) // 1]) - R, (x, y, u, v) = PolynomialRing(QQ, ["x", "y", "u", "v"]) + R, (x, y, u, v) = polynomial_ring(QQ, ["x", "y", "u", "v"]) C = extract_coefficients_ratfunc( (x + (y + 3) * u * v + y^2 * v^3) // (u + 3 * v - (x^2 + y^2) * u^2), [u, v], @@ -36,21 +36,21 @@ if GROUP == "All" || GROUP == "Core" end @testset "Coefficient extraction for polynomials" begin - R, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"]) + R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]) C = extract_coefficients((y + z + 8), [x]) R_coef = parent(first(values(C))) y, z = gens(R_coef) @test symbols(R_coef) == [:y, :z] @test C == Dict([0] => y + z + 8) - R, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"]) + R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]) C = extract_coefficients((x^2 + y * z - y^2 * z^3 + 3 * x * z^3), [z]) R_coef = parent(first(values(C))) x, y = gens(R_coef) @test symbols(R_coef) == [:x, :y] @test C == Dict([3] => 3x - y^2, [1] => y, [0] => x^2) - R, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"]) + R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]) C = extract_coefficients((x^2 + y * z - y^2 * z^3 + 3 * x * z^3), [x, z]) R_coef = parent(first(values(C))) y = gens(R_coef)[1] diff --git a/test/find_leader.jl b/test/find_leader.jl index 36dd41c40..de9409632 100644 --- a/test/find_leader.jl +++ b/test/find_leader.jl @@ -11,7 +11,7 @@ if GROUP == "All" || GROUP == "Core" println("IOEQS: ", ioeqs) pbr = PBRepresentation(ode, ioeqs) - R, (y1_0, y1_1, y1_2, y2_0, y2_1, y2_2) = Nemo.PolynomialRing( + R, (y1_0, y1_1, y1_2, y2_0, y2_1, y2_2) = Nemo.polynomial_ring( Nemo.QQ, ["y1(t)_0", "y1(t)_1", "y1(t)_2", "y2(t)_0", "y2(t)_1", "y2(t)_2"], ) diff --git a/test/io_cases.jl b/test/io_cases.jl index 00dc85366..762f1c55f 100644 --- a/test/io_cases.jl +++ b/test/io_cases.jl @@ -3,7 +3,7 @@ if GROUP == "All" || GROUP == "Core" test_cases = [] # 2-compartiment model - R, (y_0, y_1, y_2, u_0, u_1, a01, a12, a21) = PolynomialRing( + R, (y_0, y_1, y_2, u_0, u_1, a01, a12, a21) = polynomial_ring( QQ, ["y(t)_0", "y(t)_1", "y(t)_2", "u(t)_0", "u(t)_1", "a01", "a12", "a21"], ) @@ -24,7 +24,7 @@ if GROUP == "All" || GROUP == "Core" #--------------------------------------- # Chen-Lee model R, (y1_0, y1_1, y1_2, y1_3, a, b, c) = - PolynomialRing(QQ, ["y1(t)_0", "y1(t)_1", "y1(t)_2", "y1(t)_3", "a", "b", "c"]) + polynomial_ring(QQ, ["y1(t)_0", "y1(t)_1", "y1(t)_2", "y1(t)_3", "a", "b", "c"]) correct = 9 * y1_3^2 * y1_0^2 - 18 * y1_3 * y1_2 * y1_1 * y1_0 - 18 * y1_3 * y1_2 * y1_0^2 * a - 36 * y1_3 * y1_2 * y1_0^2 * b - @@ -124,7 +124,7 @@ if GROUP == "All" || GROUP == "Core" # predator-prey model R, (y1_0, y1_1, y1_2, a, b, c, d) = - PolynomialRing(QQ, ["y1(t)_0", "y1(t)_1", "y1(t)_2", "a", "b", "c", "d"]) + polynomial_ring(QQ, ["y1(t)_0", "y1(t)_1", "y1(t)_2", "a", "b", "c", "d"]) correct = y1_2 * y1_0 - y1_1^2 - y1_1 * y1_0^2 * d + y1_1 * y1_0 * c + y1_0^3 * a * d - y1_0^2 * a * c diff --git a/test/lc_univariate.jl b/test/lc_univariate.jl index 0c442a97d..532b2a50c 100644 --- a/test/lc_univariate.jl +++ b/test/lc_univariate.jl @@ -1,6 +1,6 @@ if GROUP == "All" || GROUP == "Core" @testset "Univariate leading coefficient" begin - R, (x, y, z) = Nemo.PolynomialRing(Nemo.QQ, ["x", "y", "z"]) + R, (x, y, z) = Nemo.polynomial_ring(Nemo.QQ, ["x", "y", "z"]) p = x^2 * y + x^2 * (z + z^3) + y - 5 @test lc_univariate(p, x) == y + z + z^3 @test lc_univariate(p, z) == x^2 diff --git a/test/linear_compartment.jl b/test/linear_compartment.jl index 7d244f59e..1b2e48bda 100644 --- a/test/linear_compartment.jl +++ b/test/linear_compartment.jl @@ -158,7 +158,7 @@ if GROUP == "All" || GROUP == "Core" case[:leaks], ) bring = ode.poly_ring - correct = Dict{fmpq_mpoly, Symbol}() + correct = Dict{QQMPolyRingElem, Symbol}() for (e, id) in case[:result] correct[str_to_var("a_$(e[2])_$(e[1])", bring)] = id end diff --git a/test/local_identifiability_me.jl b/test/local_identifiability_me.jl index 769402e25..e14eb2f46 100644 --- a/test/local_identifiability_me.jl +++ b/test/local_identifiability_me.jl @@ -29,13 +29,16 @@ if GROUP == "All" || GROUP == "Core" push!(edges_vars_names, "a_$(s)_0") push!(edges_vars_names, "b_$(s)_0") end - R, vars = - Nemo.PolynomialRing(Nemo.QQ, vcat(x_vars_names, edges_vars_names, ["y1", "y2"])) + R, vars = Nemo.polynomial_ring( + Nemo.QQ, + vcat(x_vars_names, edges_vars_names, ["y1", "y2"]), + ) x_vars = vars[2:(n + 1)] x0 = vars[1] - equations = Dict{fmpq_mpoly, Union{fmpq_mpoly, Generic.Frac{fmpq_mpoly}}}( - x => R(0) for x in x_vars - ) + equations = + Dict{QQMPolyRingElem, Union{QQMPolyRingElem, Generic.Frac{QQMPolyRingElem}}}( + x => R(0) for x in x_vars + ) equations[x0] = R(0) for i in 1:n for j in graph[i] @@ -53,10 +56,10 @@ if GROUP == "All" || GROUP == "Core" equations[x_vars[i]] += -x_vars[i] * rate end end - return ODE{fmpq_mpoly}( + return ODE{QQMPolyRingElem}( equations, Dict(vars[end] => x_vars[1], vars[end - 1] => x0), - Array{fmpq_mpoly, 1}(), + Array{QQMPolyRingElem, 1}(), ) end diff --git a/test/monomial_compress.jl b/test/monomial_compress.jl index f7e378b9a..2eded4cc4 100644 --- a/test/monomial_compress.jl +++ b/test/monomial_compress.jl @@ -1,6 +1,6 @@ if GROUP == "All" || GROUP == "Core" @testset "Monomial compression test" begin - R, (v1, v2, v3, v4) = Nemo.PolynomialRing(Nemo.QQ, ["v1", "v2", "v3", "v4"]) + R, (v1, v2, v3, v4) = Nemo.polynomial_ring(Nemo.QQ, ["v1", "v2", "v3", "v4"]) tests = [ v1 + v2 - 2, v4 + v4 * v1 - 3 * v2 * v4, diff --git a/test/ode_ps_solution.jl b/test/ode_ps_solution.jl index 09145f6a6..dc2e17da2 100644 --- a/test/ode_ps_solution.jl +++ b/test/ode_ps_solution.jl @@ -21,17 +21,17 @@ if GROUP == "All" || GROUP == "Core" end @testset "Power series solution for an ODE system" begin - R, (x, x_dot) = Nemo.PolynomialRing(Nemo.QQ, ["x", "x_dot"]) + R, (x, x_dot) = Nemo.polynomial_ring(Nemo.QQ, ["x", "x_dot"]) exp_t = ps_ode_solution( [x_dot - x], - Dict{fmpq_mpoly, fmpq}(x => 1), - Dict{fmpq_mpoly, Array{fmpq, 1}}(), + Dict{QQMPolyRingElem, QQFieldElem}(x => 1), + Dict{QQMPolyRingElem, Array{QQFieldElem, 1}}(), 20, )[x] @test valuation(ps_diff(exp_t) - exp_t) == 19 R, (x, y, x_dot, y_dot, u) = - Nemo.PolynomialRing(Nemo.QQ, ["x", "y", "x_dot", "y_dot", "u"]) + Nemo.polynomial_ring(Nemo.QQ, ["x", "y", "x_dot", "y_dot", "u"]) prec = 100 eqs = [x_dot - x + 3 * x * y - u, y_dot + 2 * y - 4 * x * y] u_coeff = [rand(1:5) for i in 1:prec] @@ -51,7 +51,7 @@ if GROUP == "All" || GROUP == "Core" ["x_$i" for i in 1:NUMX], ["u_$i" for i in 1:NUMU], ) - R, vars = Nemo.PolynomialRing(F, varnames) + R, vars = Nemo.polynomial_ring(F, varnames) # Generating the initial conditions and inputs ic = Dict(vars[i + NUMX] => F(rand(-5:5)) for i in 1:NUMX) @@ -88,7 +88,7 @@ if GROUP == "All" || GROUP == "Core" ["p_$i" for i in 1:NUMP], ["u_$i" for i in 1:NUMU], ) - R, vars = Nemo.PolynomialRing(F, varnames) + R, vars = Nemo.polynomial_ring(F, varnames) PType = gfp_mpoly TDict = Dict{PType, Union{PType, Generic.Frac{PType}}} diff --git a/test/paradigm_shift.jl b/test/paradigm_shift.jl index ed1c009f9..6a76f2e06 100644 --- a/test/paradigm_shift.jl +++ b/test/paradigm_shift.jl @@ -23,7 +23,8 @@ if GROUP == "All" || GROUP == "Core" ic_point = map(Nemo.QQ, rand(1:bound, length(old_vars))) old_var_ic = Dict(old_vars .=> ic_point) input_ts = map(_ -> [Nemo.QQ(rand(1:bound))], 1:length(old_inputs)) - old_input_ts = Dict{eltype(old_vars), Vector{Nemo.fmpq}}(old_inputs .=> input_ts) + old_input_ts = + Dict{eltype(old_vars), Vector{Nemo.QQFieldElem}}(old_inputs .=> input_ts) old_solutions = StructuralIdentifiability.power_series_solution( old_ode, @@ -48,7 +49,7 @@ if GROUP == "All" || GROUP == "Core" merge(old_param_spec, old_var_ic), ) for new_var in new_vars ) - new_input_ts = Dict{eltype(new_vars), Vector{Nemo.fmpq}}( + new_input_ts = Dict{eltype(new_vars), Vector{Nemo.QQFieldElem}}( new_input => old_input_ts[numerator(var_mapping[new_input])] for new_input in new_inputs ) diff --git a/test/parent_ring_change.jl b/test/parent_ring_change.jl index 97fd4ac07..4fa0a58f9 100644 --- a/test/parent_ring_change.jl +++ b/test/parent_ring_change.jl @@ -1,10 +1,10 @@ if GROUP == "All" || GROUP == "Core" @testset "Parent ring change" begin for field in [Nemo.QQ, Nemo.Native.GF(2^31 - 1)] - R, (z, x, y) = PolynomialRing(QQ, ["z", "x", "y"], ordering = :degrevlex) - R_, (y_, x_) = PolynomialRing(QQ, ["y", "x"], ordering = :lex) + R, (z, x, y) = polynomial_ring(QQ, ["z", "x", "y"], ordering = :degrevlex) + R_, (y_, x_) = polynomial_ring(QQ, ["y", "x"], ordering = :lex) R__, (x__, t__, y__, z__) = - PolynomialRing(QQ, ["x", "t", "y", "z"], ordering = :deglex) + polynomial_ring(QQ, ["x", "t", "y", "z"], ordering = :deglex) f = 2x + 3y + x^7 * y @test f == @@ -42,9 +42,9 @@ if GROUP == "All" || GROUP == "Core" @test f__ == StructuralIdentifiability.parent_ring_change(f, R__, matching = :byindex) - R, (x,) = PolynomialRing(field, ["x"]) - R2, (x2,) = PolynomialRing(Nemo.FractionField(R), ["x"]) - R3, (x3,) = PolynomialRing(field, ["x"]) + R, (x,) = polynomial_ring(field, ["x"]) + R2, (x2,) = polynomial_ring(Nemo.FractionField(R), ["x"]) + R3, (x3,) = polynomial_ring(field, ["x"]) f = x3^2 f_ = StructuralIdentifiability.parent_ring_change(f, R2) @test parent(f) == R3 diff --git a/test/pseudodivision.jl b/test/pseudodivision.jl index 9fdf157a5..dec930243 100644 --- a/test/pseudodivision.jl +++ b/test/pseudodivision.jl @@ -1,6 +1,6 @@ if GROUP == "All" || GROUP == "Core" @testset "Pseudodivision" begin - R, (x, y, z) = Nemo.PolynomialRing(Nemo.QQ, ["x", "y", "z"]) + R, (x, y, z) = Nemo.polynomial_ring(Nemo.QQ, ["x", "y", "z"]) @test iszero(pseudodivision(x^2 - y^2, x - y, x)) @test pseudodivision(y * x^4 + x^3 + x, z * x^2, x) == x diff --git a/test/sequence_solution.jl b/test/sequence_solution.jl index 128a5c7df..70b37f719 100644 --- a/test/sequence_solution.jl +++ b/test/sequence_solution.jl @@ -5,9 +5,9 @@ if GROUP == "All" || GROUP == "Core" sol = sequence_solution( ode, - Dict{fmpq_mpoly, Int}(), + Dict{QQMPolyRingElem, Int}(), Dict(f0 => 1, f1 => 1), - Dict{fmpq_mpoly, Array{Int, 1}}(), + Dict{QQMPolyRingElem, Array{Int, 1}}(), 10, ) @test sol[f1] == [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]