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
|
// Copyright (C) 1994 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.
// Contents: test-Diff.
//
// Principal Author: Sarah Rees
//
// Status: in progress
//
// Revision History:
//
#include "RKBPackage.h"
#include "DiffMachine.h"
#include "FPGroup.h"
#include "Set.h"
#include "Word.h"
//This runs the rkbp for a bit on a given group and builds the associated
//difference machine,and prints it out.
// The input is simply a presentation.
main()
{
do {
FPGroup G;
cin >> G;
if (G.numberOfGenerators()==0) break;
VectorOf<int> order;
VectorOf<int> weight;
char ch;
while (((ch = cin.peek()) != EOF) && isspace(ch)) ch = cin.get();
if (ch == '[') {
ch = cin.get();
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==',');
while (((ch = cin.peek()) != EOF) && isspace(ch)) ch = cin.get();
if (ch == '[') {
ch = cin.get();
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("ShortLex",2*G.numberOfGenerators());
if (order.length() && weight.length()==0){
WordOrder wo("ShortLex",order);
word_order = wo;
}
else if (order.length() && weight.length()){
WordOrder wo("WtShortLex",order,weight);
word_order = wo;
}
RKBPackage rkbp(G.namesOfGenerators(),G.getRelators(),word_order);
if ( !rkbp.sanityCheck() ) {
error("RKBPackage failed sanity check.\n");
}
int maxRelLen=0;
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 rkbp with parameter "<< 2*maxRelLen << endl;
rkbp.runKB(2*maxRelLen,-1,2*maxRelLen,2*maxRelLen);
SetOf<Word> differences = rkbp.wordDifferences();
DiffMachine D=rkbp.differenceMachine(differences);
D.setName("DiffMachine");
D.printOn(cout);
DiffMachine D2=rkbp.differenceMachine();
if (D!=D2) cout << "The two difference machines aren't equal."<< endl;
while (0!=1){
Chars errmesg;
cout << "Enter word to be reduced (terminated with a comma)." << endl;
Word u = G.readWord(cin, errmesg);
Word v = u;
G.printWord(cout, u);
if (u.length()==0) { cout << endl; break;}
cout << " rewrites using computed difference machine and "<<
word_order.getOrderType() << "word order as ";
D.rewrite(u,word_order);
G.printWord(cout, u);
cout << endl;
if (word_order.getOrderType()=="WtShortLex"){
u=v;
WordOrder word_order2("WtLex",order,weight);
D.rewrite(u,word_order2);
}
cout << " and using weightedLex as ";
G.printWord(cout, u);
cout << endl;
cout << " and using rkbp as ";
rkbp.oneOffRewrite(v);
G.printWord(cout, v);
cout << endl;
}
} while (0!=1);
}
|