Frobby  0.9.1
DimensionAction.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2009 Bjarke Hammersholt Roune (www.broune.com)
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see http://www.gnu.org/licenses/.
16 */
17 #include "stdinc.h"
18 #include "DimensionAction.h"
19 
20 #include "DataType.h"
21 #include "IOFacade.h"
22 #include "IdealFacade.h"
23 #include "Scanner.h"
24 #include "BigIdeal.h"
25 #include "BigTermConsumer.h"
26 #include "SliceFacade.h"
27 #include "SliceParams.h"
28 #include "NullTermConsumer.h"
29 #include "SliceParameters.h"
30 #include "error.h"
31 
32 #include <algorithm>
33 
36  Action
37 (staticGetName(),
38  "Compute the (co)dimension of the input ideal.",
39  "Compute the dimension or codimension of the input ideal. This is the\n"
40  "dimension of the zero set of the ideal. The ideal containing the identity\n"
41  "has an empty zero set, and we define the dimension of this to be -1.\n"
42  "All other ideals have non-negative dimension.",
43  false),
44 
45  _codimension
46  ("codim",
47  "Compute the codimension instead of the dimension. The codimension is the\n"
48  "number of variables in the polynomial ring minus the dimension.",
49  false),
50 
51  _squareFreeAndMinimal
52  ("squareFreeAndMinimal",
53  "State that the input ideal is square free and minimally generated. This\n"
54  "can speed up the the computation, but will result in unpredictable\n"
55  "behavior if it is not true.",
56  false),
57 
58  _useSlice
59  ("useSlice",
60  "Use the Slice Algorithm to compute the dimension instead of the usual\n"
61  "algorithm.",
62  false),
63 
64  _io(DataType::getMonomialIdealType(), DataType::getNullType()) {
65 }
66 
67 void DimensionAction::obtainParameters(vector<Parameter*>& parameters) {
68  parameters.push_back(&_codimension);
69  parameters.push_back(&_squareFreeAndMinimal);
70  parameters.push_back(&_useSlice);
71  _io.obtainParameters(parameters);
72  Action::obtainParameters(parameters);
73 }
74 
76  mpz_class result;
77  if (_useSlice) {
78  SliceParams params;
79  params.useIndependenceSplits(false); // not supported
80  validateSplit(params, true, false);
81  SliceFacade facade(params, DataType::getNullType());
82  result = facade.computeDimension(_codimension);
83  } else {
84  BigIdeal ideal;
85  Scanner in(_io.getInputFormat(), stdin);
88 
89  IOFacade ioFacade(_printActions);
90  ioFacade.readIdeal(in, ideal);
91  in.expectEOF();
92 
93  IdealFacade facade(_printActions);
94  result = facade.computeDimension(ideal,
97  }
98  gmp_fprintf(stdout, "%Zd\n", result.get_mpz_t());
99 }
100 
102  return "dimension";
103 }
BigIdeal
Definition: BigIdeal.h:27
DataType.h
IdealFacade::computeDimension
mpz_class computeDimension(const BigIdeal &ideal, bool codimension=false, bool squareFreeAndMinimal=false)
Compute the Krull dimension of ideal.
Definition: IdealFacade.cpp:82
stdinc.h
DataType::getNullType
static const DataType & getNullType()
Returns the one and only instance for null.
Definition: DataType.cpp:40
Scanner::expectEOF
void expectEOF()
Require that there is no more input.
Definition: Scanner.cpp:77
BigTermConsumer.h
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
SliceParameters.h
DimensionAction::_useSlice
BoolParameter _useSlice
Definition: DimensionAction.h:38
IOParameters::validateFormats
void validateFormats() const
Definition: IOParameters.cpp:154
DimensionAction::staticGetName
static const char * staticGetName()
Definition: DimensionAction.cpp:101
DimensionAction::_io
IOParameters _io
Definition: DimensionAction.h:39
Action::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
Action
Definition: Action.h:25
IOParameters::autoDetectInputFormat
void autoDetectInputFormat(Scanner &in)
If using the input format, this must be called before validating the ideals, since the auto detect fo...
Definition: IOParameters.cpp:141
Scanner.h
DimensionAction::_codimension
BoolParameter _codimension
Definition: DimensionAction.h:36
SliceParams
Definition: SliceParams.h:25
DimensionAction::_squareFreeAndMinimal
BoolParameter _squareFreeAndMinimal
Definition: DimensionAction.h:37
DimensionAction::DimensionAction
DimensionAction()
Definition: DimensionAction.cpp:35
error.h
IdealFacade.h
SliceFacade.h
DimensionAction::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: DimensionAction.cpp:67
SliceParams::useIndependenceSplits
void useIndependenceSplits(bool value)
Definition: SliceParams.h:34
NullTermConsumer.h
SliceParams.h
IOFacade.h
DimensionAction.h
SliceFacade::computeDimension
mpz_class computeDimension(bool codimension=false)
Compute the Krull dimension of ideal.
Definition: SliceFacade.cpp:114
IOFacade::readIdeal
void readIdeal(Scanner &in, BigTermConsumer &consumer)
Read an ideal from in and feed it to consumer.
Definition: IOFacade.cpp:81
IdealFacade
A facade for performing operations on BigIdeal.
Definition: IdealFacade.h:34
Action::_printActions
BoolParameter _printActions
Definition: Action.h:68
IOParameters::getInputFormat
const string & getInputFormat() const
Definition: IOParameters.cpp:108
validateSplit
void validateSplit(const SliceParams &params, bool allowLabel, bool allowDegree)
Definition: SliceParams.cpp:61
DataType
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
SliceFacade
A facade for operations on monomial ideals using the Slice Algorithm.
Definition: SliceFacade.h:44
DimensionAction::perform
virtual void perform()
Definition: DimensionAction.cpp:75
BigIdeal.h
ParameterGroup::obtainParameters
void obtainParameters(vector< Parameter * > &parameters)
Definition: ParameterGroup.cpp:37
IOFacade
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39