00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MATH_INVERSE_INCLUDE
00014 #define MATH_INVERSE_INCLUDE
00015
00016 #include <boost/numeric/linear_algebra/operators.hpp>
00017 #include <boost/numeric/linear_algebra/identity.hpp>
00018
00019 namespace math {
00020
00021 template <typename Operation, typename Element>
00022 struct inverse_t {} ;
00023
00024
00025 template <typename Element>
00026 struct inverse_t< add<Element>, Element >
00027 : public std::binary_function<add<Element>, Element, Element>
00028 {
00029 Element operator()(const add<Element>&, const Element& v) const
00030 {
00031 return -v;
00032 }
00033 };
00034
00035
00036 template <typename Element>
00037 struct inverse_t< mult<Element>, Element >
00038 : public std::binary_function<mult<Element>, Element, Element>
00039 {
00040 Element operator()(const mult<Element>&, const Element& v) const
00041 {
00042 return one(v) / v ;
00043 }
00044 };
00045
00046
00047
00048 template <typename Operation, typename Element>
00049 inline Element inverse(const Operation& op, const Element& v)
00050 {
00051 return inverse_t<Operation, Element>() (op, v);
00052 }
00053
00054
00055
00056 template <typename Element>
00057 inline Element reciprocal(const Element& v)
00058 {
00059 return inverse(math::mult<Element>(), v);
00060 }
00061
00062 }
00063
00064 #endif // MATH_INVERSE_INCLUDE