class StraightLineProgramWord. More...
#include <StraightLineProgramWord.h>
Classes | |
struct | Assertion |
Structure used in function equal() only. More... | |
struct | Production |
A production for a rule of a composition system. More... | |
Public Member Functions | |
StraightLineProgramWord () | |
Default constructor. | |
StraightLineProgramWord (int init, int gens) | |
Create a composition system producing a 1-generator word 'init'. | |
template<class ConstMapIterator > | |
StraightLineProgramWord (int init, ConstMapIterator B, ConstMapIterator E) | |
Construct a composition system for a generator init acted on by a sequence of mappings. | |
StraightLineProgramWord & | operator= (const StraightLineProgramWord &SLP) |
Assignement operator. | |
int | operator[] (LongInteger i) const |
Index operator. Obtain a generator at the ith position in the word. | |
StraightLineProgramWord | operator- () const |
Compute a composition system which produces the inverse of the current word. | |
StraightLineProgramWord | operator* (const StraightLineProgramWord &SLP) const |
Compute an SLP which produces a product of words produced by *this and SLP (as semigroup elements). | |
bool | equal (int n1, const StraightLineProgramWord &SLP, int n2) const |
Check if words produced by in *this and in SLP are the same (as elements of semigroup). | |
int | terminalSegment (int n, LongInteger length) |
Add a vertex into SLP (if required) which represents the word which the terminal segment of the word represented by of required length. | |
int | initialSegment (int n, LongInteger length) |
Add a vertex into SLP (if required) which represents the word which the initial segment of the word represented by of required length. | |
int | truncateVertexLeft (int n, LongInteger length) |
Add a vertex into SLP (if required) which represents the word truncated on the left. | |
int | truncateVertexRight (int n, LongInteger length) |
Add a vertex into SLP (if required) which represents the word truncated on the left. | |
LongInteger | leftGCDLength (const StraightLineProgramWord &CS) const |
Compute the length of the longest common initial segment of 2 words given by SLPs (as elements of semigroup). | |
Word | getWord () const |
Get a word represented (produced) by the SLP. | |
Word | getWord (int N) const |
Get a word represented (produced) by (non-)terminal symbol. | |
LongInteger | length () const |
Compute the length of the word produced by the SLP. | |
void | reduce () |
Reduce the SLP. | |
void | simplify () |
Simplify the structure of SLP. | |
Private Member Functions | |
void | order_vertices (int n, list< int > &order, set< int > &closure) const |
Order the descendants of . | |
void | order_vertices (int n, list< int > &order) const |
LongInteger | length_rule (int n) const |
Compute the length of the word corresponding to a rule. | |
int | height_rule (int n) const |
Compute the height of the rule. | |
bool | assertionType (const Assertion &A, const StraightLineProgramWord &SLP) const |
Determine the type of the assertion. | |
void | extendTerminals (int nt) |
Extend the set of non-terminals. The word produced by the result is the same as the original. | |
void | reduce_rule (int n) |
Reduce a subgraph of the SLP reachable from the vertex n. | |
LongInteger | leftGCDLength (int n1, const StraightLineProgramWord &CS, int n2) const |
Compute the length of the longest common initial segment of 2 words given by composition systems. | |
set< Assertion > | splitAssertion (const Assertion &A, bool firstTerm, const StraightLineProgramWord &SLP) const |
void | update_lengths () |
Update the lengths of all rules in the system. | |
void | update_length (int n) |
Recursively update the length of the rule. | |
void | update_heights () |
Update the heights of all rules in the system. | |
void | update_height (int n) |
Recursively update the height of the rule. | |
int | getGenerator (int n, LongInteger pos) const |
Get a generator at ith position of the word . | |
LongInteger | cancellationLength (int n1, int n2) const |
Find the amount of cancellation in a product . | |
StraightLineProgramWord | applyMapping (const Map &M) const |
For a composition system and a mapping compute a composition system representing . | |
int | max_rule_number () const |
Get the maximal number of the rule in SLP. | |
Static Private Member Functions | |
static void | invertProductionPair (int &A, int &B) |
Function inverts a production pair (A,B). | |
static pair< map< int, Production >, vector< int > > | map_rules (const Map &M) |
Construct the composition system rules for the map M. | |
Private Attributes | |
int | theRoot |
The number of the root non-terminal. Theroot==0 if the system is empty (default constructor). | |
int | theTerminals |
The number of terminals in the system. | |
map< int, Production > | theRules |
The production rules of the system. | |
Friends | |
ostream & | operator<< (ostream &os, const StraightLineProgramWord &CS) |
class StraightLineProgramWord.
A straight line program is basically a program computing a single word. We used "Polynomial-time Word problems" by Saul Schleimer when implementing this class.
In this implementation the class StraightLineProgramWord serves 1 purpose - it is a special container class for words. In other words it is just another representation for words, used mainly to efficiently solve the Word problem for the automorphism group of a free group.
Notice that we do not reduce SLP when constructing, i.e., initially a word represented by SLP is not reduced and length() is not the same as the length of getWord(). You need to use reduce() for that.
Another thing to remember... I do not assume that for all rules . Though it is assumed that . In a situation when must be removed from the system.
After all is done need to check that all those assumptions are really satisfied.
Definition at line 52 of file StraightLineProgramWord.h.
StraightLineProgramWord::StraightLineProgramWord | ( | ) | [inline] |
Default constructor.
Definition at line 140 of file StraightLineProgramWord.h.
StraightLineProgramWord::StraightLineProgramWord | ( | int | init, | |
int | gens | |||
) |
Create a composition system producing a 1-generator word 'init'.
StraightLineProgramWord::StraightLineProgramWord | ( | int | init, | |
ConstMapIterator | B, | |||
ConstMapIterator | E | |||
) | [inline] |
Construct a composition system for a generator init acted on by a sequence of mappings.
Here if is a sequence of mappings then the action of a sequence is a sequence of actions where is the first mapping to apply, and so on up to .
Definition at line 154 of file StraightLineProgramWord.h.
References applyMapping(), theRoot, theRules, and theTerminals.
StraightLineProgramWord StraightLineProgramWord::applyMapping | ( | const Map & | M | ) | const [private] |
For a composition system and a mapping compute a composition system representing .
The result is computed in a very straightforward way. There is no check that is applicable. In case when the domain alphabet of is strictly smaller than the number of terminals the output is an empty composition sequence. In case when the domain alphabet of is strictly greater than the number of terminals the result is a correct composition sequence.
Referenced by StraightLineProgramWord().
bool StraightLineProgramWord::assertionType | ( | const Assertion & | A, | |
const StraightLineProgramWord & | SLP | |||
) | const [private] |
Determine the type of the assertion.
The function determines the type of the assertion. The output==true if A is an overlap assertion. The output==false if A is an subword assertion.
LongInteger StraightLineProgramWord::cancellationLength | ( | int | n1, | |
int | n2 | |||
) | const [private] |
Find the amount of cancellation in a product .
bool StraightLineProgramWord::equal | ( | int | n1, | |
const StraightLineProgramWord & | SLP, | |||
int | n2 | |||
) | const |
Check if words produced by in *this and in SLP are the same (as elements of semigroup).
void StraightLineProgramWord::extendTerminals | ( | int | nt | ) | [private] |
Extend the set of non-terminals. The word produced by the result is the same as the original.
int StraightLineProgramWord::getGenerator | ( | int | n, | |
LongInteger | pos | |||
) | const [private] |
Get a generator at ith position of the word .
Referenced by operator[]().
Word StraightLineProgramWord::getWord | ( | int | N | ) | const |
Get a word represented (produced) by (non-)terminal symbol.
The current implementation is the most straightforward approach (not efficient). Notice that can be negative.
Word StraightLineProgramWord::getWord | ( | ) | const [inline] |
Get a word represented (produced) by the SLP.
Be careful!!! Relatively small SLPs can represent huge words.
Definition at line 244 of file StraightLineProgramWord.h.
References getWord(), and theRoot.
Referenced by getWord().
int StraightLineProgramWord::height_rule | ( | int | n | ) | const [inline, private] |
Compute the height of the rule.
Definition at line 303 of file StraightLineProgramWord.h.
References theRules, and theTerminals.
int StraightLineProgramWord::initialSegment | ( | int | n, | |
LongInteger | length | |||
) | [inline] |
Add a vertex into SLP (if required) which represents the word which the initial segment of the word represented by of required length.
Definition at line 213 of file StraightLineProgramWord.h.
References length_rule(), and truncateVertexRight().
static void StraightLineProgramWord::invertProductionPair | ( | int & | A, | |
int & | B | |||
) | [static, private] |
Function inverts a production pair (A,B).
LongInteger StraightLineProgramWord::leftGCDLength | ( | int | n1, | |
const StraightLineProgramWord & | CS, | |||
int | n2 | |||
) | const [private] |
Compute the length of the longest common initial segment of 2 words given by composition systems.
LongInteger StraightLineProgramWord::leftGCDLength | ( | const StraightLineProgramWord & | CS | ) | const [inline] |
Compute the length of the longest common initial segment of 2 words given by SLPs (as elements of semigroup).
Definition at line 235 of file StraightLineProgramWord.h.
References theRoot.
LongInteger StraightLineProgramWord::length | ( | ) | const [inline] |
Compute the length of the word produced by the SLP.
Definition at line 256 of file StraightLineProgramWord.h.
References length_rule(), and theRoot.
LongInteger StraightLineProgramWord::length_rule | ( | int | n | ) | const [inline, private] |
Compute the length of the word corresponding to a rule.
Definition at line 293 of file StraightLineProgramWord.h.
References theRules, and theTerminals.
Referenced by initialSegment(), length(), and terminalSegment().
static pair< map< int , Production > , vector< int > > StraightLineProgramWord::map_rules | ( | const Map & | M | ) | [static, private] |
Construct the composition system rules for the map M.
Function prepares a block of rules for the given map. The range terminals have the lowest numbers . The domain non-terminals are given in the vector.
int StraightLineProgramWord::max_rule_number | ( | ) | const [private] |
Get the maximal number of the rule in SLP.
StraightLineProgramWord StraightLineProgramWord::operator* | ( | const StraightLineProgramWord & | SLP | ) | const |
Compute an SLP which produces a product of words produced by *this and SLP (as semigroup elements).
StraightLineProgramWord StraightLineProgramWord::operator- | ( | ) | const |
Compute a composition system which produces the inverse of the current word.
StraightLineProgramWord& StraightLineProgramWord::operator= | ( | const StraightLineProgramWord & | SLP | ) | [inline] |
Assignement operator.
Definition at line 173 of file StraightLineProgramWord.h.
References theRoot, theRules, and theTerminals.
int StraightLineProgramWord::operator[] | ( | LongInteger | i | ) | const [inline] |
Index operator. Obtain a generator at the ith position in the word.
Definition at line 181 of file StraightLineProgramWord.h.
References getGenerator(), and theRoot.
void StraightLineProgramWord::order_vertices | ( | int | n, | |
list< int > & | order | |||
) | const [inline, private] |
Definition at line 286 of file StraightLineProgramWord.h.
References order_vertices().
void StraightLineProgramWord::order_vertices | ( | int | n, | |
list< int > & | order, | |||
set< int > & | closure | |||
) | const [private] |
Order the descendants of .
Operation returns 2 structures: order - contains the ordered set of descendants and closure which contains the same vertices ordered as integers. It is assumed that order and closure are initially empty.
Referenced by order_vertices().
void StraightLineProgramWord::reduce | ( | ) | [inline] |
Reduce the SLP.
Definition at line 260 of file StraightLineProgramWord.h.
References reduce_rule(), and theRoot.
void StraightLineProgramWord::reduce_rule | ( | int | n | ) | [private] |
Reduce a subgraph of the SLP reachable from the vertex n.
Referenced by reduce().
void StraightLineProgramWord::simplify | ( | ) |
Simplify the structure of SLP.
Update vertices of out_degree 1 and remove all vertices that can not be reached from the root.
set< Assertion > StraightLineProgramWord::splitAssertion | ( | const Assertion & | A, | |
bool | firstTerm, | |||
const StraightLineProgramWord & | SLP | |||
) | const [private] |
int StraightLineProgramWord::terminalSegment | ( | int | n, | |
LongInteger | length | |||
) | [inline] |
Add a vertex into SLP (if required) which represents the word which the terminal segment of the word represented by of required length.
Definition at line 207 of file StraightLineProgramWord.h.
References length_rule(), and truncateVertexLeft().
int StraightLineProgramWord::truncateVertexLeft | ( | int | n, | |
LongInteger | length | |||
) |
Add a vertex into SLP (if required) which represents the word truncated on the left.
If , , and is the output of this function then . The vertex can be negative. Foolproof.
Referenced by terminalSegment().
int StraightLineProgramWord::truncateVertexRight | ( | int | n, | |
LongInteger | length | |||
) |
Add a vertex into SLP (if required) which represents the word truncated on the left.
If , , and is the output of this function then . The vertex can be negative. Foolproof.
Referenced by initialSegment().
void StraightLineProgramWord::update_height | ( | int | n | ) | [private] |
Recursively update the height of the rule.
void StraightLineProgramWord::update_heights | ( | ) | [private] |
Update the heights of all rules in the system.
void StraightLineProgramWord::update_length | ( | int | n | ) | [private] |
Recursively update the length of the rule.
void StraightLineProgramWord::update_lengths | ( | ) | [private] |
Update the lengths of all rules in the system.
ostream& operator<< | ( | ostream & | os, | |
const StraightLineProgramWord & | CS | |||
) | [friend] |
int StraightLineProgramWord::theRoot [private] |
The number of the root non-terminal. Theroot==0 if the system is empty (default constructor).
The root is always non-negative!!!
Definition at line 407 of file StraightLineProgramWord.h.
Referenced by getWord(), leftGCDLength(), length(), operator=(), operator[](), reduce(), and StraightLineProgramWord().
map< int , Production > StraightLineProgramWord::theRules [private] |
The production rules of the system.
Definition at line 415 of file StraightLineProgramWord.h.
Referenced by height_rule(), length_rule(), operator=(), and StraightLineProgramWord().
int StraightLineProgramWord::theTerminals [private] |
The number of terminals in the system.
Definition at line 411 of file StraightLineProgramWord.h.
Referenced by height_rule(), length_rule(), operator=(), and StraightLineProgramWord().