Boost logo

Boost Users :

Subject: Re: [Boost-users] [math][tools][units] genericlibrariesnotgenericenough
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-08-29 07:00:30


>> to give a concrete example, the root finding algorithm that started
>> this
>> thread uses a polynomial approximation to the function to greatly
>> speed up
>> finding the root (we can find the polynomial approximation and it's
>> root
>> algebraically once we have evaluated enough points in the function).
>> It's
>> this insight that makes the algorithm converge so rapidly compared to
>> the
>> alternatives, but requiring that T*T != T breaks the underlying
>> assumptions
>> not only in how it's implemented, but in how it actually works
>> algorithmically.
>>
>> The easy answer is that A, B, C and D are different types then.
>> the types of A, B, C and D can be deduced from the type of T and the type
>> of the result R, which are know at that
>> point.
>
> I think (and John can correct me if I'm mistaken) that the problem is
> that it's an iterative algorithm (and even if it isn't, you can imagine
> it is; many such functions are iterative). You have to go through that
> calculation a number of times that can only be known at runtime, each
> time feeding the last result back into the input, until it converges.
> So how do you know what the result type should be? At compile-time, you
> don't! And even if you could declare it, would it be meaningful?

I suspect that technically Alfredo is correct that it's doable that way
(ultimately if you don't care how many templates get instantiated, then
almost anything can be done at compile time, right?), but:

* It would preclude defining tables of constants for polynomials (and then
using (optimized) boilerplate code to evaluate them).
* In general it would involve a huge amount of template metaprogamming to
figure out all the types (so even longer compile times).

A consequence of the above is that it would involve an awful lot of coding
time not to mention head-scratching and testing to make it all work.

John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net