I’m using LinearAlgebra and Symbolics package. I have a polynomial created by
for ivar in 1:num_vars
push!(variables, "x[" * string(ivar) * "]")
end
global ZZ = RealField
global R, = PolynomialRing(ZZ, variables)
global C = MPolyBuildCtx(R)
push_term!(C, ZZ(coefficient), exponent);
global objFunct = finish(C)
Now I would like to use Symbolics to compute derivative of sin(objFunct). I implemented:
Symbolics.@variables x[1:num_vars]
f = objFunct
f = sin(f)
but I get the following error:
ERROR: LoadError: MethodError: no method matching sin(::AbstractAlgebra.Generic.MPoly{BigFloat})
What I have to do? I tried to convert objFunct to String and this String to expression, but it does not work. All your suggestions are really appreciated. Thanks very much!
It is a shame that f(symbolics_vars...) resp. evaluate(f, symbolics_vars) is not supported (the blame is on us). Anyway, the following is a version of your code which uses the official interface of accessing exponents and coefficients, which should be more reliable:
using AbstractAlgebra, Symbolics
R, (x, y) = PolynomialRing(ZZ, ["x", "y"])
C = MPolyBuildCtx(R)
push_term!(C, ZZ(3), [1, 2]);
push_term!(C, ZZ(2), [1, 4]);
f = finish(C) # 2xy^4 + 3xy^2
symbolics_vars = Symbolics.variable.(symbols(parent(f))) |> reverse
symb_f = sum(c * reduce(*, symbolics_vars.^e) for (c, e) in zip(coefficients(f), exponent_vectors(f)))