File: test-RKBP.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 (96 lines) | stat: -rw-r--r-- 2,799 bytes parent folder | download | duplicates (3)
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
// Copyright (C) 1994 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: Test of RKBPackage.
//           Should produce output identical to test-RKBPackage.mastertestout,
//           given test-RKBPackage.data as input.
//
// Principal Author: Sarah Rees
//
// Status: in progress
//
// Revision History:
//
// XI/94: RN: Brought into line with project guidelines.

#include "RKBPackage.h"
#include "FPGroup.h"
#include "Set.h"
#include "Word.h"

// This runs the RKBPackage, estimates the growth rate of the group, and then
// reduces 10 words using the rewrite function of the RKBPackage (printing the
// reduced words).
// The input is a group presentation followed by 10 words, each terminated
// by a comma.


main()
{
  do {
    FPGroup G;
    cin >> G;
    if (G.numberOfGenerators()==0) break;
    char ch;
  
    VectorOf<int> order;
    cin >> ch;
    if (ch != '[') { cerr << "Unexpected input, aborted"<<endl; exit(1);}
    do {
      int i;
      cin >> i;
      order.append(i);
      cin>> ch;
      if (ch==']') break;
      else if (ch!=','){ cerr << "Unexpected input, aborted"<<endl; exit(1);}
    } while (ch==',');
  
    VectorOf<int> weight;
    cin >> ch;
    if (ch != '[') { cerr << "Unexpected input, aborted"<<endl; exit(1);}
    do {
      int i;
      cin >> i;
      weight.append(i);
      cin>> ch;
      if (ch==']') break;
      else if (ch!=','){ cerr << "Unexpected input, aborted"<<endl; exit(1);}
    } while (ch==',');
  
    WordOrder word_order("WtShortLex",order,weight);
    RKBPackage rkbp(G.namesOfGenerators(),G.getRelators(),word_order);
  
    if ( !rkbp.sanityCheck() ) {
      error("RKBPackage failed sanity check.\n");
    }
  
    int maxRelLen = 2; // the relators xx^-1 and x^-1x are always added
    SetOf<Word> relators = G.getRelators();
    SetIterator<Word> I(relators);
    while (!I.done()){
      Word w = I.value();
      int l = w.length();
      if ( l > maxRelLen ) maxRelLen = l;
      I.next();
    }
    cout << "Running RKBPackage with parameter " << 2*maxRelLen << endl;
    rkbp.runKB(2*maxRelLen, -1, 2*maxRelLen, 2*maxRelLen);
    float* A = rkbp.growthRate(2*maxRelLen, 50, 25);     //@rn A pointer?!
    for ( int i = 1; i <= 2*maxRelLen; i++ )
      cout << "Estimated no. of words of length " << i << ": " << A[i] << endl;
    delete A;
    rkbp.enterRewriteMode();
    while (0!=1){
      Chars errmesg;
      cout << "Enter word to be reduced (terminated with a comma)." << endl;
      Word w = G.readWord(cin, errmesg);
      G.printWord(cout, w);
      if (w.length()==0) { cout << endl; break;}
      cout << " rewrites using rkbp as ";
      rkbp.rewrite(w);
      G.printWord(cout, w);
      cout << endl;
    }
    rkbp.quitRewriteMode();
  } while (0!=1);
}