03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

228 CHAPTER 8. FINITE WORLD OF COMPUTERS<br />

namespace compiletime<br />

{<br />

template<br />

typename result of::set coeff::type<br />

set coeff(Polynomial const &p,<br />

Coeff const &c);<br />

}<br />

namespace runtime<br />

{<br />

template<br />

typename result of::set coeff::type<br />

set coeff(index type n,<br />

Polynomial const &p,<br />

Coeff const &c);<br />

}<br />

Write access is then available by:<br />

polynomial p;<br />

compiletime::set coeff(p, 1);<br />

runtime::set coeff(n, p, 1);<br />

The degree of the polynomial is defined as the maximum degree of all of its terms, where the<br />

degree of a term is given as the sum of the degree of all variables in this term. The polynomial<br />

library defines the degree as the index of the highest non-zero coefficient. To obtain the correct<br />

degree requires to use a polynomial <strong>for</strong> each variable and finally combine them:<br />

struct X;<br />

typedef polynomial<<br />

X,<br />

fusion::map< pair< mpl::int , double> ><br />

> inner poly;<br />

degree � 3 x 4 y 2� = 4 + 2 = 6<br />

typedef polynomial<<br />

Y,<br />

fusion::map< pair< mpl::int , inner poly> ><br />

> the polynomial;<br />

By instantiating the polynomial the calculation of its degree is possible:<br />

the polynomial p;<br />

assert( degree(p) == 6 );

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!