source: git/kernel/old.Ideal.h @ fbc7cb

spielwiese
Last change on this file since fbc7cb was a9c298, checked in by Hans Schoenemann <hannes@…>, 10 years ago
format stuff
  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[d964f9]1#ifndef IDEAL_CPP_HEADER
2#define IDEAL_CPP_HEADER
[b88c36e]3#include <vector>
[599326]4#include <kernel/Poly.h>
5#include <kernel/ideals.h>
[d964f9]6//base for ideals as well for modules
[ef413f]7//doesn't need a destructor, as Polys will destroy itself
[d964f9]8template <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 }
[a9c298]19
20 IdealBase(iterator first,
21             iterator last,
22             const typename
23             std::vector<poly_type>::allocator_type& __a = allocator_type()):
[d964f9]24   storage(first,last,__a)
25   {
[a9c298]26
[d964f9]27 }
[92a473]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 }
[d964f9]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 }
[a9d624]55 size_type size() const{
[d964f9]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 }
[a9d624]73
[d964f9]74};
75
76class Ideal:
77public IdealBase<Poly>{
78 public:
79  Ideal(){
80  }
[a9d624]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  }
[a9c298]86  Ideal(iterator first,
87        iterator last,
88        const allocator_type& __a = allocator_type()):
[d964f9]89    IdealBase<Poly>(first,last,__a){
90  }
[a9d624]91 ideal as_ideal() const{
92   //no checks for rings
93   int s=size();
[a9c298]94
[dcf733]95   if (s==0)
96    s=1;
[a9c298]97
[dcf733]98   ideal result=idInit(s,1);
99   result->m[0]=NULL;
100   s=size();
[a9d624]101   for(int i=0;i<s;i++){
102     result->m[i]=storage[i].as_poly();
103   }
104   return result;
105 }
[d964f9]106};
[451a9a]107class Module:
[d964f9]108public IdealBase<Vector>{
[451a9a]109public:
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{
[a9c298]116
[451a9a]117   //no checks for rings
118        int s=size();
[a9c298]119
[451a9a]120        if (s==0)
121        s=1;
[a9c298]122
[451a9a]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;
[a9c298]135
[451a9a]136  }
[a9c298]137  Module(iterator first,
138        iterator last,
139        const allocator_type& __a = allocator_type()):
[451a9a]140    IdealBase<Vector>(first,last,__a){
141  }
142  Module(){
143  }
[d964f9]144};
145#endif
Note: See TracBrowser for help on using the repository browser.