1 | #ifndef IDEAL_CPP_HEADER |
---|
2 | #define IDEAL_CPP_HEADER |
---|
3 | #include <vector> |
---|
4 | #include <kernel/Poly.h> |
---|
5 | #include <kernel/ideals.h> |
---|
6 | //base for ideals as well for modules |
---|
7 | //doesn't need a destructor, as Polys will destroy itself |
---|
8 | template <class poly_type> class IdealBase { |
---|
9 | protected: |
---|
10 | std::vector<poly_type> storage; |
---|
11 | public: |
---|
12 | typedef poly_type value_type; |
---|
13 | typedef typename std::vector<poly_type>::size_type size_type; |
---|
14 | typedef typename std::vector<poly_type>::iterator iterator; |
---|
15 | typedef typename std::vector<poly_type>::difference_type difference_type; |
---|
16 | typedef typename std::vector<poly_type>::allocator_type allocator_type; |
---|
17 | IdealBase(){ |
---|
18 | } |
---|
19 | |
---|
20 | IdealBase(iterator first, |
---|
21 | iterator last, |
---|
22 | const typename |
---|
23 | std::vector<poly_type>::allocator_type& __a = allocator_type()): |
---|
24 | storage(first,last,__a) |
---|
25 | { |
---|
26 | |
---|
27 | } |
---|
28 | ring getRing() const{ |
---|
29 | //FIXME: is a hack |
---|
30 | if (size()>0){ |
---|
31 | return storage[0].getRing(); |
---|
32 | } |
---|
33 | else |
---|
34 | return (ring) NULL; |
---|
35 | } |
---|
36 | poly_type& operator[] (int n){ |
---|
37 | return storage[n]; |
---|
38 | } |
---|
39 | const poly_type& operator[](int n) const{ |
---|
40 | return storage[n]; |
---|
41 | } |
---|
42 | void push_back(const poly_type& p){ |
---|
43 | storage.push_back(p); |
---|
44 | } |
---|
45 | void push_front(const poly_type& p){ |
---|
46 | storage.push_front(p); |
---|
47 | } |
---|
48 | |
---|
49 | iterator begin(){ |
---|
50 | return storage.begin(); |
---|
51 | } |
---|
52 | iterator end(){ |
---|
53 | return storage.end(); |
---|
54 | } |
---|
55 | size_type size() const{ |
---|
56 | return storage.size(); |
---|
57 | } |
---|
58 | iterator |
---|
59 | insert(iterator __position, const value_type& __x){ |
---|
60 | return storage.insert(__position,__x); |
---|
61 | } |
---|
62 | iterator |
---|
63 | erase(iterator __position){ |
---|
64 | return storage.erase(__position); |
---|
65 | } |
---|
66 | iterator |
---|
67 | erase(iterator __first, iterator __last){ |
---|
68 | return storage.erase(__first,__last); |
---|
69 | } |
---|
70 | void insert(iterator __pos, iterator __first, iterator __last){ |
---|
71 | return insert(__pos,__first,__last); |
---|
72 | } |
---|
73 | |
---|
74 | }; |
---|
75 | |
---|
76 | class Ideal: |
---|
77 | public IdealBase<Poly>{ |
---|
78 | public: |
---|
79 | Ideal(){ |
---|
80 | } |
---|
81 | Ideal(ideal i, ring r){ |
---|
82 | for(int j=0;j<IDELEMS(i);j++){ |
---|
83 | storage.push_back(Poly(i->m[j],r)); |
---|
84 | } |
---|
85 | } |
---|
86 | Ideal(iterator first, |
---|
87 | iterator last, |
---|
88 | const allocator_type& __a = allocator_type()): |
---|
89 | IdealBase<Poly>(first,last,__a){ |
---|
90 | } |
---|
91 | ideal as_ideal() const{ |
---|
92 | //no checks for rings |
---|
93 | int s=size(); |
---|
94 | |
---|
95 | if (s==0) |
---|
96 | s=1; |
---|
97 | |
---|
98 | ideal result=idInit(s,1); |
---|
99 | result->m[0]=NULL; |
---|
100 | s=size(); |
---|
101 | for(int i=0;i<s;i++){ |
---|
102 | result->m[i]=storage[i].as_poly(); |
---|
103 | } |
---|
104 | return result; |
---|
105 | } |
---|
106 | }; |
---|
107 | class Module: |
---|
108 | public IdealBase<Vector>{ |
---|
109 | public: |
---|
110 | Module(ideal i, ring r){ |
---|
111 | for(int j=0;j<IDELEMS(i);j++){ |
---|
112 | storage.push_back(Vector(i->m[j],r)); |
---|
113 | } |
---|
114 | } |
---|
115 | ideal as_module() const{ |
---|
116 | |
---|
117 | //no checks for rings |
---|
118 | int s=size(); |
---|
119 | |
---|
120 | if (s==0) |
---|
121 | s=1; |
---|
122 | |
---|
123 | ideal result=idInit(s,1); |
---|
124 | result->m[0]=NULL; |
---|
125 | s=size(); |
---|
126 | for(int i=0;i<s;i++){ |
---|
127 | result->m[i]=storage[i].as_poly(); |
---|
128 | |
---|
129 | } |
---|
130 | if (size()==0) |
---|
131 | result->rank=0; |
---|
132 | else |
---|
133 | result->rank=idRankFreeModule(result,storage[0].getRing()); |
---|
134 | return result; |
---|
135 | |
---|
136 | } |
---|
137 | Module(iterator first, |
---|
138 | iterator last, |
---|
139 | const allocator_type& __a = allocator_type()): |
---|
140 | IdealBase<Vector>(first,last,__a){ |
---|
141 | } |
---|
142 | Module(){ |
---|
143 | } |
---|
144 | }; |
---|
145 | #endif |
---|