5

我想创建一个具有这样的浮点系数的多项式环。我可以用整数创建,但是浮点数不起作用。

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
4

1 回答 1

4

虽然我以前没有使用过此特定(从外观上看,相当复杂)包Oscar.jl的经验,但解析此错误消息告诉我,您尝试调用的函数被BigFloat作为输入提供,但根本没有方法对于那种类型。

起初这有点令人惊讶,因为BigFloat您的输入中没有 s,但经过一番调查,似乎罪魁祸首如下

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包装器似乎不是必需的,因为它不会改变输入的类型,但我想它不会受到伤害。

于 2022-01-18T22:51:02.597 回答