mathjuliapolynomialscoefficientsabstract-algebra

How to create Polynomial Ring which has Float coefficients Julia


I want to create a polynomial ring which has float Coefficients like this. I can create with integers but, Floats does not work.

using Oscar

S, (a,b,c,d) = PolynomialRing(QQ,["a","b","c","d"])
RR = AbstractAlgebra.RealField
s1 = S( 8*a - RR(0.51234)*a*(1+RR(1/2)*a+RR(1/3)*b+RR(1/4)*c) - 8)
s2 = S( 8*b - RR(0.51234)*b*(1+RR(2/3)*a+RR(2/4)*b+RR(2/5)*c) - 8)
s3 = S( 8*c - RR(0.51234)*c*(1+RR(3/4)*a+RR(3/5)*b+RR(3/6)*c) - 8)
s4 = S( 8*d - RR(0.51234)*d*(1+RR(4/5)*a+RR(4/6)*b+RR(4/7)*c) - 8)

It gives me this error. How can I create polynomials like this.

ERROR: LoadError: MethodError: no method matching (::FmpqMPolyRing)(::BigFloat)
Closest candidates are:
  (::FmpqMPolyRing)() at ~/.julia/packages/Nemo/5CDLD/src/flint/fmpq_mpoly.jl:1063
  (::AbstractAlgebra.Ring)(::Singular.n_RingElem{Singular.RingElemWrapper{S, T}}) where {S, T} at ~/.julia/packages/Singular/uG7uo/src/number/n_unknown.jl:358
  (::AbstractAlgebra.Ring)(::Union{Singular.n_FieldElem{T}, Singular.n_RingElem{T}} where T) at ~/.julia/packages/Oscar/iRpOQ/src/Rings/mpoly.jl:736
  ...
Stacktrace:
 [1] *(x::BigFloat, y::fmpq_mpoly)
   @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/mQIYL/src/Rings.jl:84
 [2] top-level scope
   @ /mnt/c/Users/yusuf/Desktop/7.Semester/bitirme/Repo_Resultant_System/resultant-system/chandra4.jl:7
in expression starting at /mnt/c/Users/yusuf/Desktop/7.Semester/bitirme/Repo_Resultant_System/resultant-system/chandra4.jl:7

Solution

  • While I do not have previous experience with this particular (from appearances, rather sophisticated) package Oscar.jl, parsing this error message tells me that the function you are trying to call is being given a BigFloat as input, but simply does not have a method for that type.

    At first this was a bit surprising given that there are no BigFloats in your input, but after a bit of investigation, it appears that the culprit is the following

    julia> RR = AbstractAlgebra.RealField
    Floats
    
    julia> RR(1/3)
    0.333333333333333314829616256247390992939472198486328125
    
    julia> typeof(ans)
    BigFloat
    

    However, changing these inputs from BigFloat to a more standard Float64 does not fix the problem; S has no method for those either. It does, however, have methods for Rationals such as 1//3. Consequently, a simple apparent fix would be to write

    using Oscar
    
    S, (a,b,c,d) = PolynomialRing(QQ,["a","b","c","d"])
    RR = AbstractAlgebra.Rational # Note the change here!
    s1 = S( 8*a - RR(0.51234)*a*(1+RR(1/2)*a+RR(1/3)*b+RR(1/4)*c) - 8)
    s2 = S( 8*b - RR(0.51234)*b*(1+RR(2/3)*a+RR(2/4)*b+RR(2/5)*c) - 8)
    s3 = S( 8*c - RR(0.51234)*c*(1+RR(3/4)*a+RR(3/5)*b+RR(3/6)*c) - 8)
    s4 = S( 8*d - RR(0.51234)*d*(1+RR(4/5)*a+RR(4/6)*b+RR(4/7)*c) - 8)
    

    which runs without error.

    Or perhaps a bit more cleanly, by directly inputting your coefficients as rationals from the start:

    S, (a,b,c,d) = PolynomialRing(QQ,["a","b","c","d"])
    RR = AbstractAlgebra.Rational
    s1 = S( 8*a - RR(51234//100000)*a*(1+RR(1//2)*a+RR(1//3)*b+RR(1//4)*c) - 8)
    s2 = S( 8*b - RR(51234//100000)*b*(1+RR(2//3)*a+RR(2//4)*b+RR(2//5)*c) - 8)
    s3 = S( 8*c - RR(51234//100000)*c*(1+RR(3//4)*a+RR(3//5)*b+RR(3//6)*c) - 8)
    s4 = S( 8*d - RR(51234//100000)*d*(1+RR(4//5)*a+RR(4//6)*b+RR(4//7)*c) - 8)
    

    which yields

    julia> s1 = S( 8*a - RR(51234//100000)*a*(1+RR(1//2)*a+RR(1//3)*b+RR(1//4)*c) - 8)
    -25617//100000*a^2 - 8539//50000*a*b - 25617//200000*a*c + 374383//50000*a - 8
    
    julia> s2 = S( 8*b - RR(51234//100000)*b*(1+RR(2//3)*a+RR(2//4)*b+RR(2//5)*c) - 8)
    -8539//25000*a*b - 25617//100000*b^2 - 25617//125000*b*c + 374383//50000*b - 8
    
    julia> s3 = S( 8*c - RR(51234//100000)*c*(1+RR(3//4)*a+RR(3//5)*b+RR(3//6)*c) - 8)
    -76851//200000*a*c - 76851//250000*b*c - 25617//100000*c^2 + 374383//50000*c - 8
    
    julia> s4 = S( 8*d - RR(51234//100000)*d*(1+RR(4//5)*a+RR(4//6)*b+RR(4//7)*c) - 8)
    -25617//62500*a*d - 8539//25000*b*d - 25617//87500*c*d + 374383//50000*d - 8
    

    In this latter case, the RR wrapper does not appear to be necessary, as it does not change the type of the inputs, but I suppose it doesn't hurt.