Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] implementing an computer algebra systemwith proto
From: Kim Kuen Tang (kuentang_at_[hidden])
Date: 2009-01-27 16:01:00


Dave Jenkins schrieb:
>
> "Eric Niebler" <eric_at_[hidden]> wrote in message
> news:4978F428.8080107_at_boost-consulting.com...
>> A general equation solver will be challenging to write, but should be
>> possible. You'll need to familiarize yourself with Proto grammars and
>> transforms. Here is a toy example to get you started. Hope it helps.
>
> Suppose you want to move a series of additions to the right hand side.
> For example, transforming "var_ + 1 + 3 = 2" into "var_ = 2 - 3 - 1".
>
> Is there a general way to iterate the Solve() transform until all the
> plusses are consumed?
> Or do you need multiple calls to Solve(), e.g. "proto::display_expr(
> Solve()Solve()( var_ + 1 + 3 = 2 ) );"
Hi Dave,

this version of Solve

"struct Solve
  : proto::or_<
        // Solved:
        proto::assign<proto::terminal<placeholder>, _>

        // Rewrite "var_ + x = y" to "var_ = y - x"
       , proto::when<
           proto::assign< proto::plus<proto::terminal<placeholder>, _>, _ >
          ,Solve(proto::_make_assign( proto::_left(proto::_left) ,
proto::_make_minus( proto::_right, proto::_right(proto::_left) ) ) )
>
        , proto::when<
           proto::assign< proto::minus<proto::terminal<placeholder>, _>, _ >
          ,Solve(proto::_make_assign( proto::_left(proto::_left) ,
proto::_make_plus( proto::_right, proto::_right(proto::_left) ) ) )
>
>{}; "

has the feature of calling itsel recursively. So writing "Solve()( var_
+ 1 + 3 = 2 )" is enough to produce "var_ = 2-1-3".
It takes me about 1 to 2 hour to figure this out. So i would say that
proto is not difficult to learn and you really will gain more.

The next step will be to extend the grammar with the feature of
transforming such expression "1+2+var_+3=4" into
this "var_=4-1-2-3".

Cheers
Kim Tang

>
> Thanks,
> Dave Jenkins
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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