Boost logo

Boost Users :

Subject: Re: [Boost-users] proto: analytical-only math functions
From: Eric Niebler (eric_at_[hidden])
Date: 2009-03-06 21:32:00


Hicham Mouline wrote:
>
> Step1 is to have a derivative metafunction which computers the nth
> derivative of a function at compile time.
>
> In order to do that, I need a mathematical language to write my
> functions.
>
> so I have constants, variables, basic_functions and user-defined
> functions that are terminals of my language
>
> f(x) = log(x);
>
> g(x) = derivative(1, f, x);
>
> g(x) will be 1/x;
>
> I should manage to run derivative purely in compile time.

You won't be able to do it this way with exactly this syntax. The object
"f" will not carry the compile-time information that derivative() would
need to do its job. You might need something like this:

   BOOST_PROTO_AUTO( _f, f(x) = log(x) );
   BOOST_PROTO_AUTO( _g, g(x) = derivative(1, _f, x) );

Or, you could do it all in one big expression, like:

   let( f(x) = log(x) )[ g(x) = derivative(1, f, x) ];

or something. And if I'm right in assuming that the first parameter of
derivative is which derivative to take, you'll need to make that
information available at compile-time as well, so:

   let( f(x) = log(x) )[ g(x) = derivative<1>(f, x) ];

> Later, I will look at stochastic and partial differential equations
> and write functions to solve them analytically whenever possible...
>
> proto will help me define terminals, the grammars for what are
> acceptable expressions.

Right.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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