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