|
Boost Users : |
Subject: Re: [Boost-users] proto: analytical-only math functions
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-02-04 17:09:13
Hi Eric,
Thank you for the LHS grammar. I have made the changes you suggested in the
attached files.
The main header <math.h> (I'll change this name later) includes constants
(c0 ... c100), variables(x0... x100 and x y z S r q v t), basic functions
from <cmath> and general functions defined by the user, with dimensions 0 to
100.
Question1: With PP, I define constants c0 to c100, as non-const because I
let the user initialize them to a integer variables or literals or floating
point variables or literals.
Does the non-constness matter? They are defined in a header file included by
users of the library.
Question2: With PP, I also define variables. I had variable_tag as a
template taking <unsigned int subscript>.
Not subscript has nothing to do with the dimensionality here. These are just
different 1d variables.
But then to match the proto:_ in the grammar, I high jacked your idea of a
numerical MPL metafunction mpl::size_t<> for variables
as well.
Also, note the non-constness??
What do you think of the stand alone x y z S .... non subscripted variables?
Queestion3: I made dimension_of a numerical metafunction with an embedded
value member. What is the convenience
of making metafunctions numerical? Should dimension_of be specialized for
function_tag<> templates rather than on any type,
as:
template <size_t dim>
struct dimension_of< function_tag< mpl::size_t<dim> > >
{ ... };
Any advantage to this?
Question4: What is a quick way to test fundef_lhs_grammar does what I
intend?
Thank you for your help,
Regards,
-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Eric Niebler
Sent: 03 February 2009 17:46
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] proto: analytical-only math functions
Hi Hicham,
Hicham Mouline wrote:
> Hello,
>
> There are a few posts these days about generic libraries for math
> derivation of math functions, analytically or numerically.
>
<snip>
> template <size_t dim =1> struct function_tag {};
Use MPL Integral Constants here instead:
template<typename dim = mpl::size_t<1> >
struct function_tag {
typedef dim dimension;
};
And define a dimension_of metafunction like this:
template<typename FunTag>
struct dimension_of {
typedef typename FunTag::dimension type;
};
> I want to have 0 variables (nothing) for the 0-dim function in the
> proto::function case, and I want to have exactly dim variables in the
dim>0 proto::function case.
>
> Is it possible to "math-define" the function at the same time of the
> function<> object definition (in c++ terms) and have the dimension
> deducted, like:
>
> function f(x,y,z) = x+y+z ;
>
Yes. Your LHS grammar should look something like this (untested):
struct lhs_grammar
: proto::or_<
// lone functions are ok
proto::terminal< function_tag< mpl::size_t<0> > >
, proto::and_<
// f(x,y,z,...) is ok ...
proto::function<
proto::terminal< function_tag< proto::_ > >
, proto::vararg< proto::terminal< variable_tag > >
>
// ... as long as the dimension of the function
// matches the number of arguments.
, proto::if_<
mpl::equal_to<
dimension_of< proto::_value(proto::_child0) >
, mpl::prior<proto::arity_of<proto::_> >
>()
>
>
>
{};
HTH,
-- Eric Niebler BoostPro Computing
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