-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
leading coefficient with respect to a given variable #171
Comments
Currently I have been using the following patch, but since I'm not very familiar with the package internals, I suspect my solution is way far from optimal 😄 function LC!(p, var)
d = maxdegree(p, var)
d == 0 && return zero(p)
idx = findfirst(x -> x == var, p.x.vars)
lc = zero(p)
@inbounds for term in p
if degree(term, var) == d
term.x.z[idx] = 0
lc += term
end
end
return lc
end
LC(p, var) = LC!(copy(p), var) |
bump 😄 |
Here is a one line: coefficient(leadingterm(isolate_variable(p, var))) but it's not the fastest as it computes the coefficient for each degree of function LC(p, var)
d = maxdegree(p, var)
d == 0 && return zero(p)
polynomial([subs(t, var => 1) for t in terms(p) if degree(t, var) == d)
end Your suggestion uses internals of DynamicPolynomials and will be slow because of the line: |
First of all, apologies for never answering you after even bumping the issue, it wasn't very polite from my side. 🤦♂️ Anyway, your suggested implementation seemed to give a good speedup to my naive approach! Thanks! |
No worry, I'll leave the issue open as it might be a nice additional feature of the package. |
Browsing the source code, I didn't find a function to compute the "leading coefficient" of a multivariate polynomial with respect to a given variable, for example if I have the polynomial
x^2*y + x*y
the expected behavior would be(sometimes that's also called initial of the polynomial)
this functionality is used e.g. when computing the pseudodivision with multivariate polynomials, which is used e.g. in the Ritt-Wu method of characteristic sets.
Would it be a nice addition to the package?
The text was updated successfully, but these errors were encountered: