Skip to content

Commit

Permalink
Merge pull request #3 from isadofschi/develop
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
isadofschi authored Jun 24, 2020
2 parents 0e2c7cc + 5839447 commit 66dc313
Show file tree
Hide file tree
Showing 42 changed files with 876 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/*
Makefile
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ default: bin/$(GAPARCH)/smallcancellation
bin/$(GAPARCH)/smallcancellation: src/smallcancellation.cpp
mkdir -p bin/$(GAPARCH)
$(CC) -O2 -o bin/$(GAPARCH)/smallcancellation src/smallcancellation.cpp
$(CC) -Wall -o bin/$(GAPARCH)/tauexternal src/tauexternal.cpp -O3 -fopenmp

clean:
rm -rf bin
Expand Down
4 changes: 2 additions & 2 deletions PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ PackageName := "SmallCancellation",
Subtitle := "SmallCancellation/metric and nonmetric conditions",


Version := "1.0.3",
Version := "1.0.4",

Date := "04/03/2019",
Date := "24/06/2020",

PackageWWWHome :=
Concatenation( "https://github.com/isadofschi/", LowercaseString( ~.PackageName ) ),
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

* Website: https://github.com/isadofschi/smallcancellation
* Repository: https://github.com/isadofschi/smallcancellation
* Documentation: http://mate.dm.uba.ar/~isadofschi/smallcancellation

Metric and nonmetric small cancellation conditions.

Expand Down
7 changes: 7 additions & 0 deletions doc/SmallCancellation.bib
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ @article{Trie
YEAR = "2019",
URL = "https://en.wikipedia.org/wiki/Trie"
}

@article{BMSC20,
AUTHOR = {Blufstein, M. A. and Minian, E. G. and Sadofschi Costa, I.},
TITLE = {Generalized small cancellation conditions, non-positive curvature and diagrammatic reducibility},
JOURNAL = {Preprint},
YEAR = "2020",
}
19 changes: 13 additions & 6 deletions doc/chapters.autodoc
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
@Chapter Installing and Loading the SmallCancellation Package
@Section Compiling Binaries of the SmallCancellation Package
@Section Loading the SmallCancellation Package

@Chapter Small Cancellation Theory
@Chapter Small Cancellation Theory: the classical conditions
@Section Introduction
@Section Pieces
@Section Metric small cancellation conditions
@Section Non-metric small cancellation conditions
@Section Additional functions
@Section Implementation details

@Chapter More small cancellation conditions
@Section Condition Tau'

@Chapter Additional functions
@Section Additional functions



@Chapter Installing and Loading the SmallCancellation Package
@Section Compiling Binaries of the SmallCancellation Package
@Section Loading the SmallCancellation Package

1 change: 1 addition & 0 deletions init.g
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
ReadPackage( "smallcancellation", "lib/smallcancellation_internal.gd" );
ReadPackage( "smallcancellation", "lib/smallcancellation_external.gd" );
ReadPackage( "smallcancellation", "lib/smallcancellation.gd" );
ReadPackage( "smallcancellation", "lib/tau.gd" );
#E init.g . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here

8 changes: 5 additions & 3 deletions lib/smallcancellation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
## smallcancellation.gd SmallCancellation Package Iván Sadofschi Costa
##

#! @Chapter Small Cancellation Theory
#! @Chapter Small Cancellation Theory: the classical conditions

#! @Section Introduction

#! A standard reference for Small Cancellation Theory is Lyndon-Schupp <Cite Key="LyndonSchupp" Where="Chapter V"/>. We review here some definitions and results. <P/>
#! The standard reference for Small Cancellation Theory is Lyndon-Schupp <Cite Key="LyndonSchupp" Where="Chapter V"/>. We review here some definitions and results. <P/>

#! A subset <M>R</M> of a free group <M>F</M> is called <E>symmetrized</E> if all elements of <M>R</M> are cyclically reduced and for each <M>r</M> in <M>R</M> all cyclically reduced conjugates of <M>r</M> and <M>r^{-1}</M> are also in <M>R</M>. If the set <M>R</M> is not symmetrized we may work instead with the <E>symmetrization</E> <M>R^*</M> of <M>R</M> (the smallest symmetrized set containing <M>R</M>). <P/>

Expand All @@ -31,6 +31,8 @@
#! Relators and their prefixes are stored in a data structure called trie <Cite Key="Trie" />.
#! This provides an efficient way to write a word as a product of pieces using the minimum possible number of pieces.


#! @Chapter Small Cancellation Theory: the classical conditions
#! @Section Pieces

DeclareGlobalFunction("WordRotations");
Expand Down Expand Up @@ -118,7 +120,7 @@ DeclareGlobalFunction("GroupSatisfiesT");
DeclareGlobalFunction("PresentationSatisfiesT");



#! @Chapter Additional functions
#! @Section Additional functions

#! @Arguments A
Expand Down
1 change: 0 additions & 1 deletion lib/smallcancellation_external.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ DeclareGlobalFunction("GroupSatisfiesCPrimeExternal");

DeclareGlobalFunction("GetBoolFromOutput");


2 changes: 2 additions & 0 deletions lib/smallcancellation_external.gi
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ InstallGlobalFunction( CallExternalSmallCancellationProgram, function(G, order)
f:=IO_File(filename_out,"r");
output:=IO_ReadLines(f);
IO_Close(f);
Exec(Concatenation("rm ",filename_in));
Exec(Concatenation("rm ",filename_out));
return output;
end );

Expand Down
27 changes: 27 additions & 0 deletions lib/tau.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
########################################################################################
##
## ttilde.gd SmallCancellation Package Iván Sadofschi Costa
##

#! @Chapter More small cancellation conditions
#! @Section Condition Tau'

#! Condition $\mathcal{T}'$ was introduced in <Cite Key="BMSC20" />.
#! We give here the definition in terms of van Kampen diagrams.
#! If $v$ is an interior vertex in a reduced diagram $D$, let $$d'_F(v)=\sum_{c\in v} \frac{\ell_1(c)+\ell_2(c)}{\ell_r(c)}$$ where the sum is over all corners at $v$, $\ell_r(c)$ is the length of the relator corresponding to the corner $c$ and $\ell_i(c)$ are the lenghts of the words written in the edges of the corner.
#! A presentation $P$ satisfies $\mathcal{T}'$ if $2\leq d(v)-d'_F(v)$ for every interior vertex $v$ in every reduced diagram $D$ over $P$.
#! If this inequality is strict we say that the presentation satisfies condition $\mathcal{T}'_{&lt;}$.
#! $$ $$
#! If $P$ is a finite presentations satisfying $\mathcal{T}'_{&lt;}-C(3)$ then the group presented by $P$ is hyperbolic <Cite Key="BMSC20" Where="Theorem 3.3" />.
#! A presentation without proper powers which satisfies condition $\mathcal{T}'$ is diagrammatically reducible (DR) <Cite Key="BMSC20" Where="Theorem 3.2" />.
#! If $P$ satisfies $\mathcal{T'}-C'(\frac{1}{2})$ and the defining relators have the same length then $P$ satisfies a quadratic isoperimetric inequality and if in addition $P$ is finite, it has solvable conjugacy problem <Cite Key="BMSC20" Where="Theorem 4.2" />.

#! @Arguments G
#! @Description Given an FpGroup G gives the minimum of $d(v)-d'_F(v)$.
#! Thus if the function returns a number greater than or equal to $2$ the group presentation satisfies $\mathcal{T}'$ and if the number is greater than $2$ it satisfies $\mathcal{T}'_{&lt;}$.
#! This function implements the algorithm in <Cite Key="BMSC20" />.
#! For the moment the computation is done numerically using floating point numbers (this may be modified in a future version to do the computation exactly with rational numbers). External binaries need to be compiled.
#! @BeginExampleSession
#! @EndExampleSession
DeclareGlobalFunction("GroupSatisfiesTauPrime");

123 changes: 123 additions & 0 deletions lib/tau.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
########################################################################################
##
## ttilde.gi SmallCancellation Package Iván Sadofschi Costa
##

SaveGraphToFile:=function(n,edges,filename)
# n is the number of vertices
# vertices are numbered from 1 to n
# each edge in edges is represented as a list [source, target, cost]
local m,f,e;
m:=Length(edges);
f := IO_File(filename,"w");
IO_Write(f, n);
IO_Write(f, " ");
IO_Write(f, m);
IO_Write(f, "\n");
for e in edges do
IO_Write(f, e[1]); IO_Write(f, " "); IO_Write(f, e[2]); IO_Write(f, " "); IO_Write(f, e[3]); IO_Write(f, "\n");
od;
IO_Flush(f);
IO_Close(f);
end;;

ReadFloat:=function(filename)
local file,f;
file := IO_File(filename,"r");
f := Float(Chomp(IO_ReadLine(file)));
IO_Close(file);
return f;
end;;


InstallGlobalFunction(GroupSatisfiesTauPrime, function(G)
# Esta funcion da el minimo de d-dtilde para el grupo G
# el grupo cumple TTilde si devuelve >=2
local P,R_star,vertices,T,isPiece,
d_pieces,d_relations,d_vertices,
n_pieces,n_relations,n_vertices,
p,q,r,l,i,i0,i1,j,j0,j1,j2,j0rot,k,v,s,t,
ocurrences,
trick_k,M1,n_vertices_1,
e,edges,M,INF,girth,
next,
filename_in,filename_out,tmpdir,tTildeProgram,result;

R_star:=SymmetrizedRelationSet(G);
n_relations:= Length(R_star);
T:=TrieOfPieces(G);;
isPiece:=T[4];;
P:=PiecesOfGroup(G);
n_pieces := Length(P);
INF := 10000;
if n_pieces = 0 then # no pieces, we return INF
Print("# The presentation has no pieces.\n");
return INF;
fi;
d_pieces:=NewDictionary(P[1],true);
for i in [1..n_pieces] do
AddDictionary(d_pieces,P[i],i);
od;
d_relations:=NewDictionary(R_star[1],true);
for j in [1..n_relations] do
AddDictionary(d_relations,R_star[j],j);
od;
ocurrences:=List([1..n_pieces], j-> []);
for j in [1..n_relations] do
r:=R_star[j];
for t in [1..Length(r)] do
p:=Subword(r,1,t);
if isPiece(LetterRepAssocWord(p)) then
Add(ocurrences[LookupDictionary(d_pieces,p)],j);
fi;
od;
od;
edges:=[];
for r in R_star do
l:=Length(r);
j0:=LookupDictionary(d_relations,r);
for s in [1..l] do
p:=Subword(r,1,s);
if isPiece(LetterRepAssocWord(p)) then
i0:=LookupDictionary(d_pieces,p);
for t in [1..l-s] do
q:=Subword(r,s+1,s+t);
if isPiece(LetterRepAssocWord(q)) then
i1:=LookupDictionary(d_pieces,q^-1);
j0rot:=LookupDictionary(d_relations, (p*q)^-1*r^-1*(p*q));
for j1 in ocurrences[LookupDictionary(d_pieces,q^-1)] do
if j1<>j0rot then
Add(edges, [
[j0,i0],
[j1,i1],
1-((Length(p)+Length(q))/l) ]);
fi;
od;
fi;
od;
fi;
od;
od;
vertices := Set( Concatenation(List(edges, e->e[1]), List(edges,e->e[2])));
d_vertices:=NewDictionary(vertices[1],true);
n_vertices:=Length(vertices);
for i in [1..n_vertices] do
AddDictionary(d_vertices,vertices[i],i);
od;
# por ahora no nos preocupamos por el error numerico
edges:=List(edges, e-> [ LookupDictionary(d_vertices,e[1]), LookupDictionary(d_vertices,e[2]), Float(e[3]) ] );

tTildeProgram := Filename(DirectoriesPackagePrograms("smallcancellation"), "tauexternal");

tmpdir := DirectoryTemporary();;
filename_in:=Filename( tmpdir , "tmpIn" );
filename_out:=Filename( tmpdir , "tmpOut" );

SaveGraphToFile(n_vertices,edges,filename_in);
Exec(Concatenation(tTildeProgram," ", filename_in , " " , filename_out));
result:= ReadFloat(filename_out);
Exec(Concatenation("rm ",filename_in));
Exec(Concatenation("rm ",filename_out));

return result;
end );
1 change: 1 addition & 0 deletions read.g
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
ReadPackage( "smallcancellation", "lib/smallcancellation_internal.gi" );
ReadPackage( "smallcancellation", "lib/smallcancellation_external.gi" );
ReadPackage( "smallcancellation", "lib/smallcancellation.gi" );
ReadPackage( "smallcancellation", "lib/tau.gi" );
#E read.g . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here

115 changes: 115 additions & 0 deletions src/tauexternal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

#define forn(i,n) for(int i =0 ; i < (int)(n);i++)
#define forall(i,c) for(typeof((c).begin()) i = (c).begin();i != (c).end();i++)

typedef double cost;
typedef vector<int> vi;
typedef pair<cost,int> edge;
typedef vector< vector<edge > > Graph;

#define INF 10000.0

vector<cost> dijkstra(Graph & g, int source, int target = -1){
vector<cost> D(g.size(),INF);
D[source] = 0;
set<edge> pq;
pq.insert(make_pair(D[source],source));
while(!pq.empty()){
edge p = *pq.begin();
int u = p.second;
pq.erase(pq.begin());
if(u == target)
return D;
forall(it,g[u]){
cost c = it->first;
int v = it->second;
if(D[v] > D[u]+c){
if(D[v] != INF){
pq.erase(make_pair(D[v],v));
}
D[v] = D[u] + c;
pq.insert(make_pair(D[v],v));
}
}
}
return D;
}

Graph read_graph(char* filename){
int n,m;
FILE* F = freopen(filename,"r", stdin);
int ok = 1;
ok &= scanf("%d", &n);
Graph g(n);
ok &= scanf("%d", &m);
forn(i,m){
int v,w;
cost c;
ok &= scanf("%d",&v);
ok &= scanf("%d",&w);
ok &= scanf("%lf",&c);
edge e = make_pair(c,w-1);
g[v-1].push_back(e);
}
fclose(F);
if(not (ok==1)) cerr << "Error reading graph"<<endl;
return g;
}

// the graph obtained from G has vertex set V(G) x {0,..., k}
#define code(v,i,k1) ((k1)*(v)+(i)) // code(v,i,k1) is the number of the vertex (v,i) in the new graph

Graph trick(Graph &g, int k){
int n = g.size();
int k1 = k+1;
vector< vector<edge> > g1 ( k1*n );
forn(v,n){
forall(it,g[v]){
edge e = *it;
cost c = e.first;
int w = e.second;
forn(i,k){
g1[ code(v,i,k1) ].push_back( make_pair(c, code(w,i+1,k1)));
}
g1[ code(v,k,k1) ].push_back( make_pair(c, code(w,k,k1)));
}
}
return g1;
}

cost shortest_cycle(Graph &g, int k){
// returns the minimum cost of a cycle in g having length at least k
// (for k=1 this is the girth of g)
int n = g.size();
Graph g1 = trick(g, k);
int k1 = k+1;
vector<double> girths(n);
#pragma omp parallel for
forn(v,n){
int vs = code(v,0,k1);
int vt =code(v,k,k1);
girths[v] = dijkstra(g1,vs,vt)[vt];
}
double girth = INF;
forn(v,n)
girth = min(girth,girths[v]);
return girth;
}

int main(int argc, char *argv[]){
char* filename_in =argv[1];
char* filename_out =argv[2];
Graph g = read_graph( filename_in);
cost girth = shortest_cycle(g, 3);
FILE * F = freopen(filename_out, "w", stdout);
cout << girth << endl;
fclose(F);
return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 66dc313

Please sign in to comment.