Frobby  0.9.5
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 }
void validateSplit(const SliceParams &params, bool allowLabel, bool allowDegree)
Definition: SliceParams.cpp:61
Definition: Action.h:25
BoolParameter _printActions
Definition: Action.h:68
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
static const DataType & getNullType()
Returns the one and only instance for null.
Definition: DataType.cpp:40
static const char * staticGetName()
BoolParameter _useSlice
IOParameters _io
BoolParameter _codimension
virtual void obtainParameters(vector< Parameter * > &parameters)
BoolParameter _squareFreeAndMinimal
virtual void perform()
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
void readIdeal(Scanner &in, BigTermConsumer &consumer)
Read an ideal from in and feed it to consumer.
Definition: IOFacade.cpp:81
void autoDetectInputFormat(Scanner &in)
If using the input format, this must be called before validating the ideals, since the auto detect fo...
const string & getInputFormat() const
void validateFormats() const
A facade for performing operations on BigIdeal.
Definition: IdealFacade.h:34
mpz_class computeDimension(const BigIdeal &ideal, bool codimension=false, bool squareFreeAndMinimal=false)
Compute the Krull dimension of ideal.
Definition: IdealFacade.cpp:82
void obtainParameters(vector< Parameter * > &parameters)
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
void expectEOF()
Require that there is no more input.
Definition: Scanner.cpp:77
A facade for operations on monomial ideals using the Slice Algorithm.
Definition: SliceFacade.h:44
mpz_class computeDimension(bool codimension=false)
Compute the Krull dimension of ideal.
void useIndependenceSplits(bool value)
Definition: SliceParams.h:34