|
Boost Users : |
Subject: Re: [Boost-users] proto: analytical-only math functions
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-03-07 14:46:16
-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Eric Niebler
Sent: 07 March 2009 02:32
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] proto: analytical-only math functions
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) );
Hmm. That is a bit unfortunate. I don't like
very much how this syntax looks like.
I thought I could store the expression tree
inside the f objects themselves.
that is I thought the operator= or the ctor
of the function_tag could be run entirely at compile-time?
But I realize it might not be possible:
The ideal syntax would be:
function<2> f(x,y) = x*y + x - y;
// f object defined in c++ terms and at the
same assigned to the expression tree
// all at compile time
// The above can't be correct c++ right?
Both construction and call to operator=
// how about the following?
const function<2> f(x, y, x*y + x - y); //
this might be ok, only constructor called
//can this be ran entirely at compile time?
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) ];
Yes, I didn't think the derivative
function/metafunction through. These are the valid expressions:
derivative<1>(f, x) // first order
derivative of f wrt to x
derivative<1>(f, y) // first order
derivative of f wrt to y
derivative<2>(f, x) // second order
derivative of f wrt to x
derivative<2>(f, y) // second order
derivative of f wrt to y
derivative<2>(f, x, y) // second order
cross derivative of f wrt to x and y
in general, a n-dim function of n variables
x1.xn, you can define all these valid expression
derivative<1>(f, x1).. derivative<1>(f, xn)
derivative<2>(f, x1).. derivative<2>(f, xn)
derivative<2>(f, x1, x2). all combinations of 2 vars
derivative<3>(f, x1).. ).. derivative<3>(f,
xn) derivative<3>(f, x1, x2) derivative<3>(f, x1, x3). derivative<3>(f, x1,
x2, x3). all comb. of 3 vars
.
derivative<n>(f, x1).. You get the idea
For now, I am still focusing on constants.
Thanks very much,
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