source: git/factory/DegreePattern.cc @ 362fc67

spielwiese
Last change on this file since 362fc67 was 72bfc8, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: deleted @internal
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR
3\*****************************************************************************/
4/** @file DegreePattern.cc
5 *
6 * This file provides functions for manipulating DegreePatterns
7 *
8 * @author Martin Lee
9 *
10 **/
11/*****************************************************************************/
12
13#include "config.h"
14
15#include "DegreePattern.h"
16#include "cf_iter.h"
17#include "templates/ftmpl_functions.h"
18#include "gfops.h"
19#include "cf_factory.h"
20
21
22DegreePattern::DegreePattern (const CFList& l)
23{
24  m_data = NULL;
25
26  if (l.length() == 0)
27    m_data = new Pattern();
28  else
29  {
30
31  Variable x= Variable (1);
32  int p= getCharacteristic();
33  int d= 0;
34  char cGFName= 'Z';
35  if (CFFactory::gettype() == GaloisFieldDomain)
36  {
37    d= getGFDegree();
38    cGFName= gf_name;
39  }
40  setCharacteristic(0);
41  CanonicalForm buf= 1;
42  CFListIterator k= l;
43  for (int i= 0; i < l.length(); i++, k++)
44    buf *= (power (x, degree (k.getItem(), x)) + 1);
45
46  int j= 0;
47  for (CFIterator i= buf; i.hasTerms(); i++, j++)
48    ;
49
50  ASSERT ( j > 1, "j > 1 expected" );
51
52  m_data = new Pattern( j - 1 );
53
54  int i= 0;
55  for (CFIterator m = buf; i < getLength(); i++, m++)
56    (*this) [i]= m.exp();
57
58  if (d > 1)
59    setCharacteristic (p, d, cGFName);
60  else
61    setCharacteristic (p);
62  }
63}
64
65
66void DegreePattern::intersect (const DegreePattern& degPat)
67{
68  if (degPat.getLength() < getLength())
69  {
70    DegreePattern bufDeg= *this;
71    *this= degPat;
72    return (*this).intersect (bufDeg);
73  }
74
75  int count= 0;
76  int length= tmin (getLength(), degPat.getLength());
77  int* buf= new int [length];
78  for (int i= 0; i < length; i++)
79  {
80    if (degPat.find ((*this)[i]))
81    {
82      buf[i]= (*this)[i];
83      count++;
84    }
85    else
86      buf[i]= -1;
87  }
88  ASSERT ( count > 0, "count > 0 expected" );
89
90  init (count);
91  count= 0;
92  for (int i= 0; i < length; i++)
93  {
94    if (buf[i] != -1)
95    {
96      (*this) [count]= buf[i];
97      count++;
98    }
99  }
100  delete[] buf;
101}
102
103void DegreePattern::refine ()
104{
105  if (getLength() <= 1)
106    return;
107  int count= 0;
108  int* buf= new int [getLength()];
109  int d= (*this) [0];
110  int pos;
111  for (int i= 0; i < getLength(); i++)
112    buf[i]= -1;
113  for (int i= 1; i < getLength(); i++)
114  {
115    pos= (*this).find (d - (*this)[i]);
116    if (pos)
117    {
118      buf[i]= (*this)[i];
119      count++;
120    }
121  }
122  buf[0]= d;
123  count++;
124  if (count == getLength())
125  {
126    return;
127  }
128  int length= getLength();
129
130  ASSERT ( count > 0, "count > 0 expected" );
131  init (count);
132  count= 0;
133  for (int i= 0; i < length; i++)
134  {
135    if (buf[i] != -1)
136    {
137      (*this)[count]= buf[i];
138      count++;
139    }
140  }
141
142  delete[] buf;
143  return;
144}
145
Note: See TracBrowser for help on using the repository browser.