TransformAction.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "TransformAction.h"
#include "BigIdeal.h"
#include "IOFacade.h"
#include "IdealFacade.h"
#include "Scanner.h"
#include "ElementDeleter.h"
#include "VarSorter.h"
#include "DataType.h"
#include <algorithm>
TransformAction::TransformAction():
Action
(staticGetName(),
"Change the representation of the input ideal.",
"By default, transform simply writes the input ideals to output. A "
"number of parameters allow one to transform the input ideal in various ways.",
false),
_io(DataType::getMonomialIdealType(), DataType::getMonomialIdealType()),
_canonicalize
("canon",
"Sort variables, generators and ideals to get canonical representation.",
false),
_sort
("sort",
"Sort generators according to the reverse lexicographic order.",
false),
_unique
("unique",
"Remove duplicate generators.",
false),
_minimize
("minimize",
"Remove non-minimial generators.",
false),
_deform
("deform",
"Apply a generic deformation to the input ideal.",
false),
_radical
("radical",
"Take the radical of the generators. Combine this with -minimize to "
"get rid of any non-minimal ones.",
false),
_product
("product",
"Replace each ideal with the product of its generators.",
false),
_addPurePowers
("addPurePowers",
"Adds a pure power for each variable that does not already have a pure "
"power in the ideal. Each exponent is chosen to be one larger than the "
"maximal exponent of that variable that appears in the ideal.",
false),
_trimVariables
("trimVariables",
"Remove variables that divide none of the generators.",
false),
_transpose
("transpose",
"Exchange variables and minimal generators. Let M be a matrix whose "
"rows are labeled by minimal generators and whose columns are labeled "
"by variables. The entry at row g and column x is the number of times "
"that x divides g. This options transposes that matrix.",
false),
_swap01
("swap01",
"Change all 0 exponents to 1 and vice versa.",
false),
_projectVar
("projectVar",
"Project away the i'th variable counting from 1. No action is taken "
"for a value of 0 or more than the number of variables in the ring.",
0) {
}
void TransformAction::obtainParameters(vector<Parameter*>& parameters) {
_io.obtainParameters(parameters);
parameters.push_back(&_canonicalize);
parameters.push_back(&_minimize);
parameters.push_back(&_sort);
parameters.push_back(&_unique);
parameters.push_back(&_deform);
parameters.push_back(&_radical);
parameters.push_back(&_product);
parameters.push_back(&_addPurePowers);
parameters.push_back(&_trimVariables);
parameters.push_back(&_swap01);
parameters.push_back(&_projectVar);
parameters.push_back(&_transpose);
Action::obtainParameters(parameters);
}
void TransformAction::perform() {
Scanner in(_io.getInputFormat(), stdin);
_io.autoDetectInputFormat(in);
_io.validateFormats();
IOFacade facade(_printActions);
vector<BigIdeal*> ideals;
ElementDeleter<vector<BigIdeal*> > idealsDeleter(ideals);
VarNames names;
facade.readIdeals(in, ideals, names);
in.expectEOF();
IdealFacade idealFacade(_printActions);
if (_transpose) {
names.clear();
for (size_t i = 0; i < ideals.size(); ++i) {
const BigIdeal& ideal = *(ideals[i]);
BigIdeal trans(VarNames(ideal.getGeneratorCount()));
trans.reserve(ideal.getVarCount());
for (size_t var = 0; var < ideal.getVarCount(); ++var) {
trans.newLastTerm();
for (size_t gen = 0; gen < ideal.getGeneratorCount(); ++gen)
trans.getLastTermRef()[gen] = ideal[gen][var];
}
(*ideals[i]) = trans;
if (i == ideals.size() - 1)
names = ideal.getNames();
}
}
if (0 < _projectVar && _projectVar <= names.getVarCount()) {
size_t var = _projectVar - 1;
names.projectVar(var);
for (size_t i = 0; i < ideals.size(); ++i) {
BigIdeal& ideal = *(ideals[i]);
idealFacade.projectVar(ideal, var);
}
}
if (_product) {
unique_ptr<BigIdeal> ideal;
ideal.reset(new BigIdeal(names));
idealFacade.takeProducts(ideals, *ideal);
idealsDeleter.deleteElements();
exceptionSafePushBack(ideals, std::move(ideal));
}
for (size_t i = 0; i < ideals.size(); ++i) {
BigIdeal& ideal = *(ideals[i]);
if (_radical)
idealFacade.takeRadical(ideal);
if (_swap01)
idealFacade.swap01(ideal);
if (_minimize)
idealFacade.sortAllAndMinimize(ideal);
if (_deform)
idealFacade.deform(ideal);
}
if (_trimVariables)
idealFacade.trimVariables(ideals, names);
for (size_t i = 0; i < ideals.size(); ++i) {
BigIdeal& ideal = *(ideals[i]);
if (_addPurePowers)
idealFacade.addPurePowers(ideal);
if (_canonicalize)
idealFacade.sortVariables(ideal);
if (_unique)
idealFacade.sortGeneratorsUnique(ideal);
else if (_sort || _canonicalize)
idealFacade.sortGenerators(ideal);
}
if (_canonicalize) {
VarSorter sorter(names);
sorter.getOrderedNames(names);
sort(ideals.begin(), ideals.end(), compareIdeals);
}
unique_ptr<IOHandler> output(_io.createOutputHandler());
facade.writeIdeals(ideals, names, output.get(), stdout);
}
const char* TransformAction::staticGetName() {
return "transform";
}
bool TransformAction::compareIdeals(const BigIdeal* a, const BigIdeal* b) {
return *a < *b;
}
BigIdeal.h
DataType.h
ElementDeleter.h
exceptionSafePushBack
void exceptionSafePushBack(Container &container, unique_ptr< Element > pointer)
Definition ElementDeleter.h:129
IOFacade.h
IdealFacade.h
Scanner.h
TransformAction.h
VarSorter.h
Action::_printActions
BoolParameter _printActions
Definition Action.h:68
Action::Action
Action(const char *name, const char *shortDescription, const char *description, bool acceptsNonParameter)
Definition Action.cpp:46
Action::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition Action.cpp:133
BigIdeal
Definition BigIdeal.h:27
BigIdeal::reserve
void reserve(size_t capacity)
Definition BigIdeal.cpp:112
BigIdeal::newLastTerm
void newLastTerm()
Definition BigIdeal.cpp:104
BigIdeal::getVarCount
size_t getVarCount() const
Definition BigIdeal.h:148
BigIdeal::getNames
const VarNames & getNames() const
Definition BigIdeal.cpp:253
BigIdeal::getGeneratorCount
size_t getGeneratorCount() const
Definition BigIdeal.h:144
BigIdeal::getLastTermRef
vector< mpz_class > & getLastTermRef()
Definition BigIdeal.h:133
DataType
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition DataType.h:29
ElementDeleter
Definition ElementDeleter.h:50
ElementDeleter::deleteElements
void deleteElements()
Definition ElementDeleter.h:72
IOFacade
A facade for input and output of mathematical objects.
Definition IOFacade.h:39
IOFacade::readIdeals
void readIdeals(Scanner &in, vector< BigIdeal * > &ideals, VarNames &names)
Insert the ideals that are read into the parameter ideals.
Definition IOFacade.cpp:132
IOFacade::writeIdeals
void writeIdeals(const vector< BigIdeal * > &ideals, const VarNames &names, IOHandler *handler, FILE *out)
Definition IOFacade.cpp:168
IdealFacade
A facade for performing operations on BigIdeal.
Definition IdealFacade.h:34
IdealFacade::sortAllAndMinimize
void sortAllAndMinimize(BigIdeal &bigIdeal)
Remove redundant generators from ideal.
Definition IdealFacade.cpp:156
IdealFacade::trimVariables
void trimVariables(const vector< BigIdeal * > &ideals, VarNames &names)
Remove those variables that do not appear in any generator.
Definition IdealFacade.cpp:181
IdealFacade::addPurePowers
void addPurePowers(BigIdeal &bigIdeal)
Adds x_i^(l_i+1) to the ideal for each i where that will be a minimal generator, where x^l is the lcm...
Definition IdealFacade.cpp:209
IdealFacade::swap01
void swap01(BigIdeal &ideal)
Change all 0 exponents to 1 and vice versa.
Definition IdealFacade.cpp:65
IdealFacade::sortGenerators
void sortGenerators(BigIdeal &ideal)
Sorts the generators of ideal.
Definition IdealFacade.cpp:237
IdealFacade::deform
void deform(BigIdeal &ideal)
Applies some generic deformation to the ideal.
Definition IdealFacade.cpp:37
IdealFacade::takeRadical
void takeRadical(BigIdeal &ideal)
Takes the radical of the generators of ideal.
Definition IdealFacade.cpp:51
IdealFacade::sortVariables
void sortVariables(BigIdeal &ideal)
Sorts the variables of ideal.
Definition IdealFacade.cpp:245
IdealFacade::projectVar
void projectVar(BigIdeal &bigIdeal, size_t var)
Remove the variable var from the ideal and ring by substituting it by 1.
Definition IdealFacade.cpp:171
IdealFacade::sortGeneratorsUnique
void sortGeneratorsUnique(BigIdeal &ideal)
Sorts the generators of ideal and removes duplicates.
Definition IdealFacade.cpp:229
IdealFacade::takeProducts
void takeProducts(const vector< BigIdeal * > &ideals, BigIdeal &ideal)
Take the product of the minimal generators of each ideal, and add the resulting monomials as generato...
Definition IdealFacade.cpp:120
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
Scanner::expectEOF
void expectEOF()
Require that there is no more input.
Definition Scanner.cpp:77
TransformAction::compareIdeals
static bool compareIdeals(const BigIdeal *a, const BigIdeal *b)
Definition TransformAction.cpp:227
TransformAction::_deform
BoolParameter _deform
Definition TransformAction.h:45
TransformAction::TransformAction
TransformAction()
Definition TransformAction.cpp:30
TransformAction::_canonicalize
BoolParameter _canonicalize
Definition TransformAction.h:41
TransformAction::_addPurePowers
BoolParameter _addPurePowers
Definition TransformAction.h:48
TransformAction::_transpose
BoolParameter _transpose
Definition TransformAction.h:50
TransformAction::_io
IOParameters _io
Definition TransformAction.h:40
TransformAction::_swap01
BoolParameter _swap01
Definition TransformAction.h:51
TransformAction::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition TransformAction.cpp:108
TransformAction::_minimize
BoolParameter _minimize
Definition TransformAction.h:44
TransformAction::staticGetName
static const char * staticGetName()
Definition TransformAction.cpp:223
TransformAction::_product
BoolParameter _product
Definition TransformAction.h:47
TransformAction::_unique
BoolParameter _unique
Definition TransformAction.h:43
TransformAction::_sort
BoolParameter _sort
Definition TransformAction.h:42
TransformAction::_radical
BoolParameter _radical
Definition TransformAction.h:46
TransformAction::perform
virtual void perform()
Definition TransformAction.cpp:125
TransformAction::_trimVariables
BoolParameter _trimVariables
Definition TransformAction.h:49
TransformAction::_projectVar
IntegerParameter _projectVar
Definition TransformAction.h:52
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
VarNames::getVarCount
size_t getVarCount() const
Returns the current number of variables.
Definition VarNames.h:113
VarNames::projectVar
void projectVar(size_t index)
Definition VarNames.cpp:161
VarNames::clear
void clear()
Resets the number of variables to zero.
Definition VarNames.cpp:106
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
VarSorter
Definition VarSorter.h:27
VarSorter::getOrderedNames
void getOrderedNames(VarNames &names)
Definition VarSorter.cpp:50