source: git/factory/DegreePattern.cc @ 183688

fieker-DuValspielwiese
Last change on this file since 183688 was 72bfc8, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: deleted @internal
  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[7bf145]1/*****************************************************************************\
[806c18]2 * Computer Algebra System SINGULAR
[7bf145]3\*****************************************************************************/
4/** @file DegreePattern.cc
[806c18]5 *
6 * This file provides functions for manipulating DegreePatterns
[7bf145]7 *
8 * @author Martin Lee
9 *
10 **/
11/*****************************************************************************/
12
[e4fe2b]13#include "config.h"
[7bf145]14
[806c18]15#include "DegreePattern.h"
[7bf145]16#include "cf_iter.h"
[6db552]17#include "templates/ftmpl_functions.h"
[7bf145]18#include "gfops.h"
[17f4dc]19#include "cf_factory.h"
[7bf145]20
[d52c12]21
[806c18]22DegreePattern::DegreePattern (const CFList& l)
23{
[7bf145]24  m_data = NULL;
25
26  if (l.length() == 0)
27    m_data = new Pattern();
28  else
29  {
[806c18]30
[7bf145]31  Variable x= Variable (1);
32  int p= getCharacteristic();
[17f4dc]33  int d= 0;
[7a1151]34  char cGFName= 'Z';
[17f4dc]35  if (CFFactory::gettype() == GaloisFieldDomain)
36  {
37    d= getGFDegree();
38    cGFName= gf_name;
39  }
[7bf145]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++)
[806c18]48    ;
[7bf145]49
50  ASSERT ( j > 1, "j > 1 expected" );
[806c18]51
[7bf145]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
[d52c12]66void DegreePattern::intersect (const DegreePattern& degPat)
[7bf145]67{
[806c18]68  if (degPat.getLength() < getLength())
[7bf145]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];
[806c18]78  for (int i= 0; i < length; i++)
[7bf145]79  {
[806c18]80    if (degPat.find ((*this)[i]))
81    {
[7bf145]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;
[806c18]92  for (int i= 0; i < length; i++)
[7bf145]93  {
[806c18]94    if (buf[i] != -1)
[7bf145]95    {
96      (*this) [count]= buf[i];
97      count++;
98    }
99  }
100  delete[] buf;
101}
[806c18]102
[d52c12]103void DegreePattern::refine ()
[7bf145]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;
[806c18]113  for (int i= 1; i < getLength(); i++)
[7bf145]114  {
115    pos= (*this).find (d - (*this)[i]);
[806c18]116    if (pos)
117    {
[7bf145]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;
[806c18]133  for (int i= 0; i < length; i++)
[7bf145]134  {
[806c18]135    if (buf[i] != -1)
[7bf145]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.