~ubuntu-branches/ubuntu/saucy/gfan/saucy-proposed

« back to all changes in this revision

Viewing changes to app_symmetries.cpp

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2013-07-09 10:44:01 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130709104401-5q66ozz5j5af0dak
Tags: 0.5+dfsg-3
* Upload to unstable.
* modify remove_failing_tests_on_32bits.patch to replace command of
  0009RenderStairCase test with an empty one instead of deleting it.
* remove lintian override about spelling error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "vektor.h"
 
2
#include "printer.h"
 
3
#include "parser.h"
 
4
#include "gfanapplication.h"
 
5
#include "minkowskisum.h"
 
6
#include "newtonpolytope.h"
 
7
#include "buchberger.h"
 
8
#include "wallideal.h"
 
9
#include "lp.h"
 
10
#include "tropical.h"
 
11
#include "division.h"
 
12
#include "bergman.h"
 
13
#include "tropical2.h"
 
14
#include "dimension.h"
 
15
#include "timer.h"
 
16
#include "log.h"
 
17
#include "linalg.h"
 
18
#include "tropicaltraverse.h"
 
19
#include "traverser_tropical.h"
 
20
#include "symmetrictraversal.h"
 
21
#include "traverser_stableintersection.h"
 
22
 
 
23
class SymmetriesApplication : public GFanApplication
 
24
{
 
25
  SimpleOption optionSymmetry;
 
26
  SimpleOption optionTorusSymmetry;
 
27
public:
 
28
  bool includeInDefaultInstallation()
 
29
  {
 
30
    return true;
 
31
  }
 
32
  const char *helpText()
 
33
  {
 
34
    return "This program computes the symmetries of a polynomial ideal. The program is slow, so think before using it. Use --symmetry to give hints about which subgroup of the symmetry group could be useful. The program checks each element of the specified subgroup to see if it preserves the ideal.\n";
 
35
  }
 
36
  SymmetriesApplication():
 
37
    optionSymmetry("--symmetry","Specify subgroup to be searched for permutations keeping the ideal fixed."),
 
38
    optionTorusSymmetry("--symsigns","Specify for each generator of the group specified wiht --symmetry an element of ${-1,+1}^n$ which by its multiplication on the variables together with the permutation is expected to keep the ideal fixed.")
 
39
  {
 
40
    registerOptions();
 
41
  }
 
42
  const char *name()
 
43
  {
 
44
    return "_symmetries";
 
45
  }
 
46
  int main()
 
47
  {
 
48
    FileParser P(Stdin);
 
49
 
 
50
    AsciiPrinter p(Stdout);
 
51
    PolynomialSet gb=P.parsePolynomialSetWithRing();
 
52
    int n=gb.numberOfVariablesInRing();
 
53
 
 
54
    WeightReverseLexicographicTermOrder T(IntegerVector::allOnes(n));
 
55
    buchberger(&gb,T);
 
56
 
 
57
    assert(n>=2);
 
58
 
 
59
    SymmetryGroup signSymmetries(2*n);
 
60
    if(optionSymmetry.getValue())
 
61
      {
 
62
        IntegerVectorList generators=P.parseIntegerVectorList();
 
63
 
 
64
        IntegerMatrix torusAction(generators.size(),n);
 
65
        if(optionTorusSymmetry.getValue())
 
66
        {
 
67
                torusAction=rowsToIntegerMatrix(P.parseIntegerVectorList());
 
68
        }
 
69
        else
 
70
        {
 
71
                for(int i=0;i<torusAction.getHeight();i++)
 
72
                for(int j=0;j<torusAction.getWidth();j++)
 
73
                        torusAction[i][j]=1;
 
74
        }
 
75
        IntegerVectorList doubleGenerators;
 
76
        int I=0;
 
77
        for(IntegerVectorList::const_iterator i=generators.begin();i!=generators.end();i++,I++)
 
78
                doubleGenerators.push_back(SymmetryGroup::combinePermutationAndSignChanges(*i,torusAction[I]));
 
79
        signSymmetries.computeClosure(doubleGenerators);
 
80
      }
 
81
    else
 
82
    {
 
83
        if(optionTorusSymmetry.getValue())
 
84
        {
 
85
                debug<<"Option --symsigns can only be used together with --symmetry\n";
 
86
                assert(0);
 
87
        }
 
88
        IntegerVectorList doubleGenerators;
 
89
        IntegerVector cycle(n);
 
90
        for(int i=0;i<n;i++)cycle[i]=((i+1)%n);
 
91
        IntegerVector transposition=SymmetryGroup::identity(n);
 
92
        transposition[0]=1;
 
93
        transposition[1]=0;
 
94
        doubleGenerators.push_back(SymmetryGroup::combinePermutationAndSignChanges(cycle,IntegerVector::allOnes(n)));
 
95
        doubleGenerators.push_back(SymmetryGroup::combinePermutationAndSignChanges(transposition,IntegerVector::allOnes(n)));
 
96
        signSymmetries.computeClosure(doubleGenerators);
 
97
    }
 
98
 
 
99
    IntegerVectorList doubleGenerators2;
 
100
 
 
101
    for(SymmetryGroup::ElementContainer::const_iterator i=signSymmetries.elements.begin();i!=signSymmetries.elements.end();i++)
 
102
    {
 
103
        IntegerVector permutation,signChanges;
 
104
        SymmetryGroup::extractPermuationAndSignChanges(*i,permutation,signChanges);
 
105
 
 
106
        log1 debug<<"Checking "<<permutation<<" "<<signChanges<<"\n";
 
107
        PolynomialSet b2=SymmetryGroup::permutePolynomialSet(gb,permutation);
 
108
        //log0 AsciiPrinter(Stderr).printPolynomialSet(b2);
 
109
 
 
110
        b2=b2.torusAct(integerVectorToFieldVector(signChanges,Q));
 
111
        if(areIdealsEqual(gb,b2))
 
112
        {
 
113
                doubleGenerators2.push_back(*i);
 
114
                log1 debug<<"OK";
 
115
        }
 
116
    }
 
117
 
 
118
    IntegerVectorList permutations;
 
119
    IntegerVectorList signChangess;
 
120
    for(IntegerVectorList::const_iterator i=doubleGenerators2.begin();i!=doubleGenerators2.end();i++)
 
121
    {
 
122
        IntegerVector permutation,signChanges;
 
123
        SymmetryGroup::extractPermuationAndSignChanges(*i,permutation,signChanges);
 
124
        permutations.push_back(permutation);
 
125
        signChangess.push_back(signChanges);
 
126
    }
 
127
 
 
128
    pout<<permutations<<signChangess;
 
129
 
 
130
    return 0;
 
131
  }
 
132
};
 
133
 
 
134
static SymmetriesApplication theApplication;