
Boost : 
Subject: Re: [boost] Math tools polynomial enhancements
From: Robert Ramey (ramey_at_[hidden])
Date: 20151029 16:26:51
On 10/29/15 11:35 AM, John Maddock wrote:
>
>
> On 29/10/2015 15:04, Robert Ramey wrote:
>> On 10/29/15 3:22 AM, John Maddock wrote:
>>>
>>> I think there is a place for polynomial manipulation within Boost, but
>>> I'm not sure that this class is the best basis. As we say in the docs,
>>> it's a braindead implementation that's good enough for what I needed at
>>> the time to implement Boost.Math, but not really suitable for heavy duty
>>> polynomial manipulation.
>>
>> While you're at it, How about a constexpr/tmp version which would do
>> polynomial manipulation at compile time?
>>
>
> Interesting idea, what kind of manipulation did you have in mind 
> arithmetic? Might be possible in C++14 but certainly not in C++11.
> Probably a whole different library actually,
Right
since the order would have
> to be a compile time parameter?
I'm thinking it would be a variadic tuple.
here's what I had in mind:
// define a polynomial with coefficients of type T (int, float, etc)
template<typename T>
using polynomial = std::tuple<T ...>
// now define some operators on these polynomials
template<typename T>j
// polynomial addition  easy to implement
operator+(polynomial<T>lhs, polynomial<T>rhs);
// other ops ... easy to implement
// polynomial division  aaaa  more compilicated to implement
operator/(polynomial<T>lhs, polynomial<T>rhs);
// very cool functions
template<typename T>
constexpr polynomial<T> derivative(polynomial<T> p);
template<typename T>
constexpr polynomial<T> integrate(polynomial<T> p);
// and of course we could evaluate any polynomial at
// specific point at either compile and/or run time
constexpr T evaluate(const polynomial<T> & p);
// a taylor series has the last two terms reserved for a rational
// representation of an error term
template<typename T>
using taylor_series = polynomial<T>;
// evaluate
T value(taylor_series<T>, T x);
// get error value
T error(taylor_series<T>, T x);
// given a sequence of derivatives of F at point x
// calculate a taylor series
template<T, F>
constexpr taylor_series::taylor_series(x = 0);
// now I can replace my clunky quadrature of function
// F with
// return value and error
template<class T, class F>
const expr std::pair<T, T> fast_integral(
const T & start,
const T & finish
){
using f = integrate(taylor_series<F>(3.233));
T value = evaluate(f, finish)  evaluate(f, start);
T error_value = abs(error(f, finish)) + abs(error(f, start));
return std::pair<value, error_value>
};
This would be pretty useful as it stands. Of course it
brings to mind a few more ideas
a) T above is presumed to be a scalar variable  but it
doesn't have to be. What I really need is to permit T
to be a tuble itself so I could handle complex and
and n dimensional space situations.
b) The creating of F is problematic and tedious. For this we need
TMP expression template driven automatic differentiation.
I'm thinking you could put this together in a couple of days
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk