40 const auto& p1 =
dynamic_cast<const Polynomial&
>(f1);
41 const auto& p2 =
dynamic_cast<const Polynomial&
>(f2);
45 for (
size_t i = 0; i < c1.
size(); ++i)
46 for (
size_t j = 0; j < c2.
size(); ++j)
47 resultCoef[i + j] += c1[i] * c2[j];
48 return make_unique<Polynomial>(
std::move(resultCoef));
54 const auto& piecewise =
dynamic_cast<const Piecewise&
>(f1);
55 const auto& interval_functions = piecewise.
getFunctions();
58 std::transform(interval_functions.begin(), interval_functions.end(), functions.begin(),
60 return make_unique<Piecewise>(piecewise.getKnots(), functions);
63 template <
typename Iter>
65 for (
auto i1 = start1, i2 = start2; i1 != end1 && i2 != end2;) {
68 if (i1 != end1 && *i1 > *i2) {
73 if (i2 != end2 && *i1 < *i2) {
88 while (p1Iter != knots1.
end() && p2Iter != knots2.
end()) {
89 if (*p1Iter < *p2Iter) {
90 knotSet.insert(*p1Iter);
102 const auto& p1 =
dynamic_cast<const Piecewise&
>(f1);
103 const auto& p2 =
dynamic_cast<const Piecewise&
>(f2);
112 auto& p1func = p1.getFunctions();
113 auto& p2func = p2.getFunctions();
116 for (
double knot : knots) {
117 if (knot == knots.back()) {
120 while (p1.getKnots()[i1 + 1] <= knot) {
123 while (p2.getKnots()[i2 + 1] <= knot) {
129 return make_unique<Piecewise>(knots,
std::move(functions));
ELEMENTS_API std::unique_ptr< Function > multiply(const Function &f1, const Function &f2)
std::unique_ptr< Function > multiplyPolynomials(const Function &f1, const Function &f2)
Function for multiplying two Polynomials. It multiplies their coefficients.
std::unique_ptr< Function >(* MultiplyFunction)(const Function &, const Function &)
Alias of a function which multiplies Function objects.
const std::vector< std::unique_ptr< Function > > & getFunctions() const
Returns the functions in the ranges between the knots.
ELEMENTS_API std::map< std::type_index, MultiplyFunction > multiplySpecificGenericMap
std::unique_ptr< Function > multiplyPiecewiseWithGeneric(const Function &f1, const Function &f2)
Represents a polynomial function.
Interface class representing a function with an arbitrary number of parameters.
static std::pair< Iter, Iter > overlappingStart(Iter start1, Iter end1, Iter start2, Iter end2)
ELEMENTS_API std::map< std::pair< std::type_index, std::type_index >, MultiplyFunction > multiplySpecificSpecificMap
std::unique_ptr< Function > multiplyPiecewises(const Function &f1, const Function &f2)
Represents a piecewise function.
std::vector< double > overlappingKnots(const std::vector< double > &knots1, const std::vector< double > &knots2)
Returns a vector of the overlapping knots from the given vectors.