source: git/factory/DegreePattern.cc @ 6db552

fieker-DuValspielwiese
Last change on this file since 6db552 was 6db552, checked in by Hans Schoenemann <hannes@…>, 13 years ago
removed include-wrapppers git-svn-id: file:///usr/local/Singular/svn/trunk@13772 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.6 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 * @internal @version \$Id$
11 *
12 **/
13/*****************************************************************************/
14
15#include <config.h>
16
[806c18]17#include "DegreePattern.h"
[7bf145]18#include "cf_iter.h"
[6db552]19#include "templates/ftmpl_functions.h"
[7bf145]20#include "gfops.h"
21
[d52c12]22
[806c18]23DegreePattern::DegreePattern (const CFList& l)
24{
[7bf145]25  m_data = NULL;
26
27  if (l.length() == 0)
28    m_data = new Pattern();
29  else
30  {
[806c18]31
[7bf145]32  Variable x= Variable (1);
33  int p= getCharacteristic();
34  int d= getGFDegree();
35  char cGFName= gf_name;
36  setCharacteristic(0);
37  CanonicalForm buf= 1;
38  CFListIterator k= l;
39  for (int i= 0; i < l.length(); i++, k++)
40    buf *= (power (x, degree (k.getItem(), x)) + 1);
41
42  int j= 0;
43  for (CFIterator i= buf; i.hasTerms(); i++, j++)
[806c18]44    ;
[7bf145]45
46  ASSERT ( j > 1, "j > 1 expected" );
[806c18]47
[7bf145]48  m_data = new Pattern( j - 1 );
49
50  int i= 0;
51  for (CFIterator m = buf; i < getLength(); i++, m++)
52    (*this) [i]= m.exp();
53
54  if (d > 1)
55    setCharacteristic (p, d, cGFName);
56  else
57    setCharacteristic (p);
58  }
59}
60
61
[d52c12]62void DegreePattern::intersect (const DegreePattern& degPat)
[7bf145]63{
[806c18]64  if (degPat.getLength() < getLength())
[7bf145]65  {
66    DegreePattern bufDeg= *this;
67    *this= degPat;
68    return (*this).intersect (bufDeg);
69  }
70
71  int count= 0;
72  int length= tmin (getLength(), degPat.getLength());
73  int* buf= new int [length];
[806c18]74  for (int i= 0; i < length; i++)
[7bf145]75  {
[806c18]76    if (degPat.find ((*this)[i]))
77    {
[7bf145]78      buf[i]= (*this)[i];
79      count++;
80    }
81    else
82      buf[i]= -1;
83  }
84  ASSERT ( count > 0, "count > 0 expected" );
85
86  init (count);
87  count= 0;
[806c18]88  for (int i= 0; i < length; i++)
[7bf145]89  {
[806c18]90    if (buf[i] != -1)
[7bf145]91    {
92      (*this) [count]= buf[i];
93      count++;
94    }
95  }
96  delete[] buf;
97}
[806c18]98
[d52c12]99void DegreePattern::refine ()
[7bf145]100{
101  if (getLength() <= 1)
102    return;
103  int count= 0;
104  int* buf= new int [getLength()];
105  int d= (*this) [0];
106  int pos;
107  for (int i= 0; i < getLength(); i++)
108    buf[i]= -1;
[806c18]109  for (int i= 1; i < getLength(); i++)
[7bf145]110  {
111    pos= (*this).find (d - (*this)[i]);
[806c18]112    if (pos)
113    {
[7bf145]114      buf[i]= (*this)[i];
115      count++;
116    }
117  }
118  buf[0]= d;
119  count++;
120  if (count == getLength())
121  {
122    return;
123  }
124  int length= getLength();
125
126  ASSERT ( count > 0, "count > 0 expected" );
127  init (count);
128  count= 0;
[806c18]129  for (int i= 0; i < length; i++)
[7bf145]130  {
[806c18]131    if (buf[i] != -1)
[7bf145]132    {
133      (*this)[count]= buf[i];
134      count++;
135    }
136  }
137
138  delete[] buf;
139  return;
140}
141
Note: See TracBrowser for help on using the repository browser.