Frobby  0.9.5
Deformer.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2010 University of Aarhus
3  Contact Bjarke Hammersholt Roune for license information (www.broune.com)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see http://www.gnu.org/licenses/.
17 */
18 #include "stdinc.h"
19 #include "Deformer.h"
20 
21 #include "Term.h"
22 #include "TermPredicate.h"
23 #include "Ideal.h"
24 #include "TermPredicate.h"
25 #include "error.h"
26 #include "IdealOrderer.h"
27 #include <map>
28 
29 namespace {
30  void deform(Ideal& ideal,
31  vector<Exponent>& undeform,
32  size_t var,
33  bool stronglyGeneric) {
34  ASSERT(undeform.empty());
35 
36  map<Exponent, vector<Exponent*> > exps;
37 
38  Ideal::const_iterator end = ideal.end();
39  for (Ideal::const_iterator it = ideal.begin(); it != end; ++it) {
40  Exponent& e = (*it)[var];
41  if (e == 0)
42  continue;
43  exps[e].push_back(*it);
44  }
45 
46  Term tmp(ideal.getVarCount());
47  undeform.push_back(0); // zero always maps to zero
48  for (map<Exponent, vector<Exponent*> >::iterator it = exps.begin();
49  it != exps.end(); ++it) {
50  vector<Exponent*>& block = it->second;
51 
52  typedef vector<Exponent*>::iterator BlockIt;
53  if (stronglyGeneric) {
54  for (BlockIt blockIt = block.begin(); blockIt != block.end();
55  ++blockIt) {
56  undeform.push_back((*blockIt)[var]);
57  (*blockIt)[var] = undeform.size() - 1;
58  }
59  } else {
60  undeform.push_back(block.front()[var]);
61  Exponent sharedDeformedExponent = undeform.size() - 1;
62 
63  for (BlockIt blockIt = block.begin(); blockIt != block.end();
64  ++blockIt) {
65  bool canUseShared = true;
66  for (BlockIt other = blockIt + 1; other != block.end(); ++other) {
67  tmp.lcm(*blockIt, *other);
68  if (!ideal.strictlyContains(tmp)) {
69  canUseShared = false;
70  break;
71  }
72  }
73  if (canUseShared)
74  (*blockIt)[var] = sharedDeformedExponent;
75  else {
76  undeform.push_back((*blockIt)[var]);
77  (*blockIt)[var] = undeform.size() - 1;
78  }
79  }
80  }
81  }
82  }
83 }
84 
86  const IdealOrderer& orderer,
87  bool stronglyGeneric):
88  _undeform(ideal.getVarCount()) {
89 
90  orderer.order(ideal);
91 
92  for (size_t var = 0; var < ideal.getVarCount(); ++var)
93  deform(ideal, _undeform[var], var, stronglyGeneric);
94 
95  ASSERT(!stronglyGeneric || ideal.isStronglyGeneric());
96  ASSERT(ideal.isWeaklyGeneric());
97 }
98 
99 void Deformer::undeform(Term& term) const {
100  ASSERT(term.getVarCount() == _undeform.size());
101 
102  for (size_t var = 0; var < term.getVarCount(); ++var) {
103  ASSERT(term[var] < _undeform[var].size());
104  term[var] = _undeform[var][term[var]];
105  }
106 }
Deformer(Ideal &ideal, const IdealOrderer &deformationOrder, bool makeStronglyGeneric=true)
Apply a generic deformation to ideal such that it becomes generic.
Definition: Deformer.cpp:85
vector< vector< Exponent > > _undeform
var^e undeforms to var^(_undeform[var][e]).
Definition: Deformer.h:53
void undeform(Term &term) const
Apply the reverse transformation on term than that applied to the Ideal passed to the constructor.
Definition: Deformer.cpp:99
void order(Ideal &ideal) const
Definition: IdealOrderer.h:27
Represents a monomial ideal with int exponents.
Definition: Ideal.h:27
Cont::const_iterator const_iterator
Definition: Ideal.h:43
bool strictlyContains(const Exponent *term) const
Definition: Ideal.cpp:73
const_iterator end() const
Definition: Ideal.h:49
const_iterator begin() const
Definition: Ideal.h:48
bool isWeaklyGeneric() const
Definition: Ideal.cpp:121
bool isStronglyGeneric()
Definition: Ideal.cpp:106
size_t getVarCount() const
Definition: Ideal.h:56
Term represents a product of variables which does not include a coefficient.
Definition: Term.h:49
size_t getVarCount() const
Definition: Term.h:85
unsigned int Exponent
Definition: stdinc.h:89
#define ASSERT(X)
Definition: stdinc.h:86