atlas  0.6
free_abelian.h
Go to the documentation of this file.
1 
5 /*
6  Copyright (C) 2008 Marc van Leeuwen
7  part of the Atlas of Lie Groups and Representations
8 
9  For license information see the LICENSE file
10 */
11 
12 #include <map>
13 
14 #ifndef FREE_ABELIAN_H /* guard against multiple inclusions */
15 #define FREE_ABELIAN_H
16 
17 #include "free_abelian_fwd.h"
18 
19 namespace atlas {
20 
21 namespace free_abelian {
22 
23 
24 /******** type declarations **************************************************/
25 
26 
27 /******** function declarations **********************************************/
28 
29 /******** type definitions ***************************************************/
30 
31 // A class that represents an element of the free abelian group on the set T
32 // or, with |C=polynomials::polynomial<int>| counting with $q$-multiplicities
33 // |T| value type, |C| coefficient type, |Compare| equivalence test for |T|
34 template<typename T, typename C, typename Compare>
35 struct Free_Abelian : public std::map<T,C,Compare>
36 {
37  typedef C coef_t;
38  typedef std::map<T,coef_t,Compare> base; // the (base) reresentation type
39  typedef typename base::iterator iterator;
40  typedef typename base::const_iterator const_iterator;
41 
42  Free_Abelian() : base(Compare()) {} // default |Compare| value for base
43 
44  Free_Abelian(Compare c) : base(c) {} // here a specific |Compare| is used
45 
46  explicit Free_Abelian(const base& m) : base(m) {} // promote base to derived
47 
48  explicit Free_Abelian(const T& p, Compare c=Compare()) // create a monomial
49  : base(c)
50  { base::insert(std::make_pair(p,coef_t(1L))); }
51 
52  Free_Abelian(const T& p,C m, Compare c=Compare()) // mononomial (single term)
53  : base(c)
54  { if (m!=C(0))
55  base::insert(std::make_pair(p,m));
56  }
57 
58  // convert other agregate of (monomial,coefficient) pairs to |Free_Abelian|
59  // warning: current implementation allows coefficients |C(0)| to slip through
60  template<typename InputIterator> // iterator over (T,coef_t) pairs
61  Free_Abelian(InputIterator first, InputIterator last, Compare c=Compare())
62  : base(first,last,c) {}
63 
64  Free_Abelian& add_term(const T& p, C m);
65  Free_Abelian& operator+=(const T& p) { return add_term(p,C(1)); }
66  Free_Abelian& operator-=(const T& p) { return add_term(p,C(-1)); }
67 
68  Free_Abelian& add_multiple(const Free_Abelian& p, C m);
69 
71  { if (base::empty())
72  return *this =(p); // assign, avoiding work on initial addition to empty
73  return add_multiple(p,C(1));
74  }
75 
77  { return add_multiple(p,C(-1)); }
78 
79  C operator[] (const T& t) const // find coefficient of |t| in |*this|
80  {
81  typename base::const_iterator p=base::find(t);
82  return p==base::end() ? C(0) : p->second;
83  }
84 
85 }; // |class Free_Abelian|
86 
87 /* When we also want a multiplication, |T| must have operator+=. Rather than
88  defining operator*= in Free_Abelian (possibly unused), we prefer to derive.
89 */
90 template<typename T, typename C=long int, typename Compare=std::less<T> >
91  struct Monoid_Ring : public Free_Abelian<T,C,Compare>
92 {
93  typedef C coef_t;
95  typedef typename base::iterator iterator;
96  typedef typename base::const_iterator const_iterator;
97 
98  Monoid_Ring() : base(Compare()) {}
99  Monoid_Ring(Compare c) : base(c) {}
100 
101  explicit Monoid_Ring(const typename base::base& m) : base(m) {}
102  explicit Monoid_Ring(T p, Compare c=Compare()) : base(p,c) {}
103  Monoid_Ring(T p,C m, Compare c=Compare()) : base(p,m,c) {}
104 
105  template<typename InputIterator>
106  Monoid_Ring(InputIterator first, InputIterator last, Compare c=Compare())
107  : base(first,last,c) {}
108 
110 
111  Monoid_Ring& add_multiple(const Monoid_Ring& p, C m,const T& expon);
112 
113 }; // |class Monoid_Ring|
114 
115 
116 } // |namespace free_abelian|
117 
118 } // |namespace atlas|
119 
120 #include "free_abelian_def.h"
121 
122 #endif
Monoid_Ring()
Definition: free_abelian.h:98
Free_Abelian & operator+=(const T &p)
Definition: free_abelian.h:65
Monoid_Ring(InputIterator first, InputIterator last, Compare c=Compare())
Definition: free_abelian.h:106
uA p
Definition: lists.cpp:26
base::iterator iterator
Definition: free_abelian.h:39
base::const_iterator const_iterator
Definition: free_abelian.h:40
Free_Abelian(const T &p, C m, Compare c=Compare())
Definition: free_abelian.h:52
Free_Abelian & operator+=(const Free_Abelian &p)
Definition: free_abelian.h:70
Monoid_Ring(T p, C m, Compare c=Compare())
Definition: free_abelian.h:103
base::const_iterator const_iterator
Definition: free_abelian.h:96
Definition: Atlas.h:116
base::iterator iterator
Definition: free_abelian.h:95
C operator[](const T &t) const
Definition: free_abelian.h:79
Monoid_Ring(const typename base::base &m)
Definition: free_abelian.h:101
RationalVector< C2 > operator*(const matrix::Matrix< C1 > &M, const RationalVector< C2 > &v)
Definition: ratvec.cpp:158
std::map< T, coef_t, Compare > base
Definition: free_abelian.h:38
Free_Abelian & operator-=(const T &p)
Definition: free_abelian.h:66
Free_Abelian & add_term(const T &p, C m)
Definition: free_abelian_def.h:22
Free_Abelian< T, C, Compare > base
Definition: free_abelian.h:94
C coef_t
Definition: free_abelian.h:93
Free_Abelian()
Definition: free_abelian.h:42
Monoid_Ring(Compare c)
Definition: free_abelian.h:99
simple_list< T, Alloc >::const_iterator end(const simple_list< T, Alloc > &l)
Definition: sl_list.h:650
Definition: Atlas.h:38
Monoid_Ring(T p, Compare c=Compare())
Definition: free_abelian.h:102
C coef_t
Definition: free_abelian.h:37
Free_Abelian & add_multiple(const Free_Abelian &p, C m)
Definition: free_abelian_def.h:39
Definition: cweave.c:343
Free_Abelian(const base &m)
Definition: free_abelian.h:46
Free_Abelian(Compare c)
Definition: free_abelian.h:44
Free_Abelian & operator-=(const Free_Abelian &p)
Definition: free_abelian.h:76
Free_Abelian(InputIterator first, InputIterator last, Compare c=Compare())
Definition: free_abelian.h:61
Definition: free_abelian.h:91
Free_Abelian(const T &p, Compare c=Compare())
Definition: free_abelian.h:48
const bool empty
Definition: axis.cpp:43