Assignments Assignments

algebra.h
Go to the documentation of this file.
1#ifndef ALGEBRA_INCLUDED
2#define ALGEBRA_INCLUDED
3
4#include <cmath>
5
6 namespace Util
7{
13 template< class Element >
14 class AdditiveGroup
15 {
16 public:
18 friend Element operator - ( const Element &e ){ return e.additiveInverse(); }
19
21 friend Element operator - ( const Element &e1 , const Element &e2 ){ return e1 + (-e2); }
22
24 friend Element& operator += ( Element &e1 , const Element &e2 ){ e1 = e1 + e2 ; return e1; }
25
27 friend Element& operator -= ( Element &e1 , const Element &e2 ){ e1 = e1 - e2 ; return e1; }
28 };
29
35 template< class Element >
36 class MultiplicativeGroup
37 {
38 public:
40 friend Element operator / ( const Element &e1 , const Element &e2 ){ return e1 * e2.multiplicativeInverse(); }
41
43 friend Element& operator *= ( Element &e1 , const Element &e2 ){ e1 = e1 * e2 ; return e1; }
44
46 friend Element& operator /= ( Element &e1 , const Element &e2 ){ e1 = e1 / e2 ; return e1; }
47 };
48
56 template< class Element >
57 class Field : public AdditiveGroup< Element > , public MultiplicativeGroup< Element >{};
58
64 template< class Element >
65 class VectorSpace
66 {
67 public:
69 friend Element operator - ( const Element &e1 , const Element &e2 ){ return e1 + (-e2); }
70
72 friend Element operator / ( const Element &e , double s ){ return e * (1./s); }
73
75 friend Element& operator += ( Element & e1 , const Element &e2 ){ e1 = e1 + e2 ; return e1; }
76
78 friend Element& operator -= ( Element &e1 , const Element &e2 ){ return e1 += (-e2); }
79
81 friend Element& operator *= ( Element &e , double s ){ e = e*s ; return e; }
82
84 friend Element& operator /= ( Element &e , double s ){ return e *= (1./s); }
85
87 friend Element operator - ( const Element &e ){ return e * (-1.); }
88
90 friend Element operator * ( double s , const Element &e ){ return e*s; }
91 };
92
97 template< class Element >
98 class _InnerProductSpace
99 {
100 public:
102 static double Dot( const Element &e1 , const Element &e2 ){ return e1.dot(e2); }
103
105 static double SquareNorm( const Element &e ){ return e.dot(e); }
106
108 static double Length( const Element &e ){ return sqrt( e.dot(e) ); }
109
111 static double SquareDistance( const Element &e1 , const Element &e2 ){ return SquareNorm(e1-e2); }
112
114 static double Distance( const Element &e1 , const Element &e2 ){ return sqrt( SquareDistance(e1,e2) ); }
115
117 double squareNorm( void ) const { return SquareNorm( *( Element * )this ); }
118
120 double length( void ) const { return sqrt( squareNorm() ); }
121
123 Element unit( void ) const { return *( Element * )this / _InnerProductSpace< Element >::length(); }
124 };
125
132 template< class Element >
133 class InnerProductSpace : public VectorSpace< Element > , public _InnerProductSpace< Element >{};
134
141 template< class Element >
142 class Algebra : public VectorSpace< Element >
143 {
144 public:
146 friend Element& operator *= ( Element &e1 , const Element &e2 ){ e1 = e1 * e2 ; return e1; }
147 };
148}
149#endif // ALGEBRA_INCLUDED
Util::_InnerProductSpace
Definition algebra.h:99
Util::_InnerProductSpace::Distance
static double Distance(const Element &e1, const Element &e2)
Definition algebra.h:114
Util::_InnerProductSpace::length
double length(void) const
Definition algebra.h:120
Util::_InnerProductSpace::SquareNorm
static double SquareNorm(const Element &e)
Definition algebra.h:105
Util::_InnerProductSpace::squareNorm
double squareNorm(void) const
Definition algebra.h:117
Util::_InnerProductSpace::Length
static double Length(const Element &e)
Definition algebra.h:108
Util::_InnerProductSpace::SquareDistance
static double SquareDistance(const Element &e1, const Element &e2)
Definition algebra.h:111
Util::_InnerProductSpace::unit
Element unit(void) const
Definition algebra.h:123
Util::_InnerProductSpace::Dot
static double Dot(const Element &e1, const Element &e2)
Definition algebra.h:102
Util::AdditiveGroup
Definition algebra.h:15
Util::AdditiveGroup::operator-
friend Element operator-(const Element &e)
Definition algebra.h:18
Util::AdditiveGroup::operator+=
friend Element & operator+=(Element &e1, const Element &e2)
Definition algebra.h:24
Util::AdditiveGroup::operator-=
friend Element & operator-=(Element &e1, const Element &e2)
Definition algebra.h:27
Util::Algebra
Definition algebra.h:143
Util::Algebra::operator*=
friend Element & operator*=(Element &e1, const Element &e2)
Definition algebra.h:146
Util::Field
Definition algebra.h:57
Util::InnerProductSpace
Definition algebra.h:133
Util::MultiplicativeGroup
Definition algebra.h:37
Util::MultiplicativeGroup::operator/
friend Element operator/(const Element &e1, const Element &e2)
Definition algebra.h:40
Util::MultiplicativeGroup::operator/=
friend Element & operator/=(Element &e1, const Element &e2)
Definition algebra.h:46
Util::MultiplicativeGroup::operator*=
friend Element & operator*=(Element &e1, const Element &e2)
Definition algebra.h:43
Util::VectorSpace
Definition algebra.h:66
Util::VectorSpace::operator*=
friend Element & operator*=(Element &e, double s)
Definition algebra.h:81
Util::VectorSpace::operator*
friend Element operator*(double s, const Element &e)
Definition algebra.h:90
Util::VectorSpace::operator/
friend Element operator/(const Element &e, double s)
Definition algebra.h:72
Util::VectorSpace::operator-
friend Element operator-(const Element &e1, const Element &e2)
Definition algebra.h:69
Util::VectorSpace::operator+=
friend Element & operator+=(Element &e1, const Element &e2)
Definition algebra.h:75
Util::VectorSpace::operator-=
friend Element & operator-=(Element &e1, const Element &e2)
Definition algebra.h:78
Util::VectorSpace::operator/=
friend Element & operator/=(Element &e, double s)
Definition algebra.h:84
Util
Definition algebra.h:7