如何创建具有 Float 系数的多项式环 Julia
How to create Polynomial Ring which has Float coefficients Julia
我想创建一个多项式环,它具有这样的浮点系数。我可以用整数创建,但是浮点数不起作用。
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)
它给了我这个错误。我怎样才能创建这样的多项式。
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
虽然我以前没有使用过这个特定的(从外观上看,相当复杂)包 Oscar.jl,但解析此错误消息告诉我您尝试调用的函数被赋予 BigFloat
作为输入,但根本没有该类型的方法。
起初这有点令人惊讶,因为您的输入中没有 BigFloat
,但经过一些调查后,罪魁祸首似乎是以下
julia> RR = AbstractAlgebra.RealField
Floats
julia> RR(1/3)
0.333333333333333314829616256247390992939472198486328125
julia> typeof(ans)
BigFloat
但是,将这些输入从 BigFloat
更改为更标准的 Float64
并不能解决问题; S
也没有办法。但是,它确实有 Rationals
的方法,例如 1//3
。因此,一个简单的明显修复方法是编写
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)
运行没有错误。
或者更简洁一点,从一开始就直接输入有理数系数:
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)
产生
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
在后一种情况下,RR
包装器似乎不是必需的,因为它不会改变输入的类型,但我想它不会造成伤害。
我想创建一个多项式环,它具有这样的浮点系数。我可以用整数创建,但是浮点数不起作用。
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)
它给了我这个错误。我怎样才能创建这样的多项式。
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
虽然我以前没有使用过这个特定的(从外观上看,相当复杂)包 Oscar.jl,但解析此错误消息告诉我您尝试调用的函数被赋予 BigFloat
作为输入,但根本没有该类型的方法。
起初这有点令人惊讶,因为您的输入中没有 BigFloat
,但经过一些调查后,罪魁祸首似乎是以下
julia> RR = AbstractAlgebra.RealField
Floats
julia> RR(1/3)
0.333333333333333314829616256247390992939472198486328125
julia> typeof(ans)
BigFloat
但是,将这些输入从 BigFloat
更改为更标准的 Float64
并不能解决问题; S
也没有办法。但是,它确实有 Rationals
的方法,例如 1//3
。因此,一个简单的明显修复方法是编写
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)
运行没有错误。
或者更简洁一点,从一开始就直接输入有理数系数:
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)
产生
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
在后一种情况下,RR
包装器似乎不是必需的,因为它不会改变输入的类型,但我想它不会造成伤害。