This project provides an opportunity to build a grammar group representation in two ways, which is displayed in the following picture:
Implementation of Isoperimetric and Isodiametric Functions of Groups in Haskell.
Implementation algorithm building the presentation of the group for a formal language with the preservation of the language. The implementation of this algorithm is necessary for research in the field of formal languages with the involvement of the group-theoretical methods. At present, there are only theoretical works showing the possibility of such construction, however, the algorithm and its implementation are absent up to this point. As far as we know, this implementation is the first in its area.
Implementation of building Turing machine by boolean grammar algorithm, described in Boolean grammars and algorithm, descrbied in An Introduction to the Theory of Groups, which by given Turing machine builds group presentation via building semigroup presentation.
There are two modifications of second approach, which produce a more compact group presentation, but this modifications haven't strict theoretical proof of saving properties of original approach. So, use them if size of group presentation is more important than theoretical properties.
This modifications of second approach use modified conversions from Turing machine to semigroup representation (here G
is set of generators and R
is set of relations of produced semigroup presentation):
This conversion is represented in An Introduction to the Theory of Groups
This conversion uses the same set of generators as the original, but smaller size of set of relations
This conversion uses different set of generators as opposed to the first conversion
stack build
stack test
stack run -- LangToGroup-cli <options>
-i file_path
--input=file_path
Full path to file with grammar definition-o file_path
--output=file_path
Full path to file for printing results-e file_path
--error=file_path
Full path to file, where errors should be recorded during parsing-a approach
--approach=approach
Used approach (see section Approaches)-I objects
--info=objects
Print useful information about objects (see section Objects)-h
--help
Print help and exit
first
Implementation of algorithm from Isoperimetric and Isodiametric Functions of Groupssecond
Implementation of algorithms from Boolean grammars and An Introduction to the Theory of Groupssecond_a
Modifications ofsecond
approach with modified algorithm from An Introduction to the Theory of Groupssecond_b
Modifications ofsecond
approach with modified algorithm from An Introduction to the Theory of Groups
grammar
Input grammar (context-free, conjunctive or boolean)turing_machine
,tm
Produced Turing machine (its type depends on used approach)group_presentation
,gp
Produced group presentation
NOTE: When enumerating objects, they must be separated by commas WITHOUT SPACES!
-
stack run -- LangToGroup-cli -i grammar.txt -a second_b -I tm,gp
If you want build presentation of grammar via second modification of the second approach and get metrics of produced group presentation and Turing machine
-
stack run -- LangToGroup-cli -i grammar.txt -o group_presentation.txt -a first
If you want to build presentation of grammar via first approach and save produced group presentation to file
Here are some format restrictions which grammars should satisfy to be handled by group presentation builder properly:
- Empty word specified via
Eps
; - Conjunction and negation logical signs for defining boolean and conjunctive grammars should be written as
&
and!
respectively; - All nonterminals must have one capital letter and zero or more small letters in their names;
- All terminals must have one or more small letters in their names;
- First string must contain start nonterminal, set of nonterminals, set of terminals, separated by
;
sign; - In subsequent lines grammar rules should be specified;
- All signs, used for defining grammar as
;
,->
,&
,!
, should be written exactly after previous signs and grammar symbols without commas, and there is a space after last sign; - Here are examples of input grammars, satisfying restrictions above:
Boolean grammar
S; S Sa; c v b
S-> c&! v&! Sa&! Eps
Sa->! b
S-> a& b&! v&! Sa&! Eps
Conjunctive grammar
S; S Abc D Cr; c b d e
S-> D c& d Abc
Abc-> b
D-> Cr
Cr-> e
Context-free grammar
S; S A D1; c2 b e
S-> c2 D1 A
A-> b
D1-> e
- Also there are files with experiment grammars in folder
\examples\grammar\experiments
with correct input.
NOTE: second approach for building group presentation accepts only grammar in normal form due to the specifics of the algorithm described in the article on the construction of a Turing machine by a boolean grammar!
Here are the tables with some examples of building group presentations by different grammars, where:
- States -- number of states in built Turing machine,
- Gen -- number of generators,
- Rel -- number of relations,
- N -- number of rules in normal grammar.
Language | Grammar | N | States | Generators | Relations |
---|---|---|---|---|---|
1 rule | CFG | 1 | 6 | 89508 | 56187 |
Dyck language without empty word | CFG | 10 | 77 | 2798322 | 1773449 |
CFG | 2 | 10 | 228160 | 129611 | |
CFG | 5 | 63 | 2241518 | 1355357 |
NOTE: Old CLI was saved because some of posibilities aren't available in new CLI.
For run experiments and print its numerical results you can use is_det <bool>
flag.
So, for print experiments' results using deterministic symmetrization:
stack exec -- LangToGroup-printer --is_det true
using nondeterministic symmetrization:
stack exec -- LangToGroup-printer --is_det false
Grammar's transformations also can be printed in LaTeX. For this should be used --print_example <grammar>
flag.
The following grammars can be used as print examples: "one" --- one rule grammar, "a*" --- grammar for regular language
, "dyck" --- Dyck language grammar.
For example,
stack exec -- LangToGroup-printer --is_det true --print_example one
Output filename can be specified by -o <filename>
flag.
For this you can use -G
flag without a parameter, but with --is_det <bool>
and --print_example <grammar>
flags.
Also, output filename can be specified by -o <filename>
flag, if it does not speccified it been printing with default filename "out.txt".
For example, following prints in "out.txt" a group presentation, which obtained from Dyck language grammar using nondeterministic symmetrization:
stack exec -- LangToGroup-printer -G --is_det false --print_example dyck