3 #include "../MultivariatePolynomial.h"
4 #include "../UnivariatePolynomial.h"
10 namespace detail_derivative {
12 constexpr
inline std::size_t
multiply(std::size_t n, std::size_t k) {
14 for (; k > 0; --k) res *= n - k + 1;
22 template<
typename T, EnableIf<is_number_type<T>> = dummy>
36 if (n == 0)
return std::make_pair(1, m);
37 auto it = std::find_if(m->begin(), m->end(),
38 [v](
const auto& e){ return e.first == v; }
40 if ((it == m->end()) || (it->second < n)) {
41 CARL_LOG_DEBUG(
"carl.core",
"derivative(" << m <<
", " << v <<
", " << n <<
") = 0");
42 return std::make_pair(0,
nullptr);
43 }
else if (it->second == n) {
45 if (m->exponents().size() == 1) {
46 CARL_LOG_DEBUG(
"carl.core",
"derivative(" << m <<
", " << v <<
", " << n <<
") = " << factor);
47 return std::make_pair(factor,
nullptr);
50 for (
const auto& e: *m) {
51 if (e.first == v)
continue;
52 newExps.emplace_back(e);
55 CARL_LOG_DEBUG(
"carl.core",
"derivative(" << m <<
", " << v <<
", " << n <<
") = " << factor <<
"*" << res);
56 return std::make_pair(factor, res);
61 newExps[
static_cast<std::size_t
>(std::distance(m->begin(), it))].second -= n;
63 CARL_LOG_DEBUG(
"carl.core",
"derivative(" << m <<
", " << v <<
", " << n <<
") = " << factor <<
"*" << res);
64 return std::make_pair(factor, res);
85 template<
typename C,
typename O,
typename P>
93 for (
const auto& t: p) {
95 if (
is_zero(newTerms.back())) newTerms.pop_back();
105 if (n == 0)
return p;
108 CARL_LOG_DEBUG(
"carl.core",
"derivative(" << p <<
", " << n <<
") = 0");
112 std::vector<C> newCoeffs;
113 for (std::size_t i = 0; i < p.
degree() + 1 - n; ++i) {
115 newCoeffs.emplace_back(
static_cast<C
>(factor) * p.
coefficients()[i + n]);
126 if (n == 0)
return p;
130 std::vector<C> newCoeffs;
132 [v,n](
const auto& c) { return derivative(c, v, n); }
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
Monomial::Arg createMonomial(T &&... t)
const T & derivative(const T &t, Variable, std::size_t n=1)
Computes the n'th derivative of a number, which is either the number itself (for n = 0) or zero.
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
constexpr std::size_t multiply(std::size_t n, std::size_t k)
Returns n * (n-1) * ... * (n-k+1)
A Variable represents an algebraic variable that can be used throughout carl.
This class represents a univariate polynomial with coefficients of an arbitrary type.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.
Variable main_var() const
Retrieves the main variable of this polynomial.
uint degree() const
Get the maximal exponent of the main variable.
The general-purpose multivariate polynomial class.
bool is_constant() const
Check if the polynomial is constant.
std::vector< Term< Coeff > > TermsType
Type our terms vector.f.
std::shared_ptr< const Monomial > Arg
std::vector< std::pair< Variable, std::size_t > > Content
Represents a single term, that is a numeric coefficient and a monomial.
Coefficient & coeff()
Get the coefficient.
Monomial::Arg & monomial()
Get the monomial.