File: debug-MSCGConjugacyProblem.C

package info (click to toggle)
magnus 20060324-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,404 kB
  • ctags: 20,466
  • sloc: cpp: 130,118; ansic: 37,076; tcl: 10,970; perl: 1,109; makefile: 963; sh: 403; yacc: 372; csh: 57; awk: 33; asm: 10
file content (190 lines) | stat: -rw-r--r-- 4,372 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright (C) 1995 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: informal test of MSCGConjugacyProblem class
//
// Principal Author: Dmitry Bormotov
//
// Status: in progress
//
// Revision History:
//

#include "iostream.h"
#include "MSCGConjugacyProblem.h"
#include "NormalRandomWord.h"

ostream& operator << (ostream& o, Trichotomy t)
{
  if ( t == YES ) o << " YES ";
  else if ( t == NO ) o << " NO ";
  else o << " DONTKNOW ";

  return o;
}

Word initWord(const Generator* p, int len) {
  VectorOf<Generator> v(len);
  for( int i = 0; i < len; i ++ ) v[i] = *p++;
  return Word(v);
}

void singleTest() {
  FPGroup F;
  cout << "Enter a MSC represenatation, i.e. <a,b,c| a^7, b = c> : " << endl;
  Chars errMsg = cin >> F;
  if( errMsg.length() > 0 ) {
    cout << errMsg << endl;
      exit(-1);
  }

  cout << endl;
  MSCGroup G(F);
  cout << "You typed the MSC group: " << F << endl << endl;

  bool quit = false;
  while( !quit ) {
    cout << "Type a word: ";
    Word w = F.readWord(cin, errMsg);
    if( errMsg.length() > 0 ) {
      cout << errMsg << endl;
      exit(0);
    }
    cout << endl << "You typed: ";
    F.printWord(cout, w);
    
    cout << endl << "type a second word: ";
    Word u = F.readWord(cin, errMsg);
    if( errMsg.length() > 0 ) {
      cout << errMsg << endl;
      exit(0);
    }

    cout << endl << "you typed: ";
    F.printWord(cout, u);

    MSCGConjugacyProblem CP(G,w,u);

    cout << endl << "conjugacyProblem says ... ";
    CP.startComputation();
    while( !CP.continueComputation() ) ;
    Trichotomy answer = CP.answer(); 
    cout<< answer << endl;
    if ( answer == YES ) {
      cout << "The conjugator: ";
      Word conjugator = CP.conjugator();
      F.printWord(cout, conjugator);
      cout << endl;
      cout << "Checking: ";
      bool bChecking = G.areEqual(w.conjugateBy(conjugator),u);
      if ( bChecking )
	cout << "success";
      else
	cout << "error";
      cout << endl << endl;
    }
    char reply;
    cout << "Repeat (y/n)? ";
    do {
      cin >> reply;
      reply = tolower(reply);
    } while( reply != 'y' && reply != 'n' );
    if( reply == 'n' ) quit = true;
    cout << endl;
  }
}

void error( const Chars& msg, const FPGroup& G, const Word& w, const Word& c,
	    const Word& u, const Word& conjugator )
{
  cout << msg << ": w = ";
  G.printWord( cout, w );
  cout << ", c = ";
  G.printWord( cout, c );
  cout << ", u = ";
  G.printWord( cout, u );
  cout << ", found conjugator = ";
  G.printWord( cout, conjugator );
  cout << endl;
}

void randomTests( )
{
  FPGroup F;
  cout << "Enter a MSC represenatation, i.e. <a,b,c| a^7, b = c> : " << endl;
  Chars errMsg = cin >> F;
  if( errMsg.length() > 0 ) {
    cout << errMsg << endl;
      exit(-1);
  }

  cout << endl;
  MSCGroup G(F);
  cout << "You typed the MSC group: " << F << endl << endl;

  int meanLen;
  cout << "Type average length of test words:";
  cin >> meanLen;
  cout << meanLen << endl;

  int numberOfTests;
  cout << "Type number of tests: ";
  cin >> numberOfTests;
  cout << numberOfTests << endl;

  NormalRandomWord rw( F.numberOfGenerators(), 
		       meanLen, 
		       meanLen/2,	// lengthStdDev
		       2345,		// lengthSeed
		       1234		// generatorSeed
		       );
    
  int failed = 0;
  int passed = 0;
  Word w,c,u;
  for( int test = 0; test < numberOfTests; ++test ) {
    w = rw.word();
    int probe = 0; 
    do {
      c = rw.word();
      u = w.conjugateBy(c);
      u = u.cyclicallyReduce();
      ++probe;
    } while( w == u && probe < 1000 );
    if( probe < 1000 ) {
      MSCGConjugacyProblem CP(G,w,u);
      CP.startComputation();
      while( !CP.continueComputation() ) ;
      Trichotomy answer = CP.answer(); 
      if ( answer == yes ) {
	Word conjugator = CP.conjugator();
	bool bChecking = G.areEqual(w.conjugateBy(conjugator),u);
	if ( bChecking )
	  ++passed;
	else {
	  error("bad conj", F, w,c,u,conjugator);
	  ++failed;
	}
      }
      else if( answer == no ) {
	error("negative answer", F, w,c,u, Word() );
	++failed;
      }
      else {
	error("no answer", F, w,c,u, Word() );
	++failed;
      }
    }
  }
  cout << endl << endl 
       << "+ " << passed << " tests passed." << endl
       << "- " << failed << " tests failed." << endl;
}

void main( )
{
  randomTests();
  //  singleTest();
}