Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add a function piece to FastAutomaton, add intersection2 and intersec…
Browse files Browse the repository at this point in the history
…t to BetaAdicMonoid
  • Loading branch information
mercatp committed Jul 8, 2015
1 parent 8efcdea commit fda86b7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 8 deletions.
45 changes: 45 additions & 0 deletions src/sage/combinat/words/automataC.c
Expand Up @@ -313,6 +313,51 @@ Automaton CopyAutomaton (Automaton a, int nalloc, int naalloc)
return r;
}

//donne un automate reconnaissant w(w^(-1)L) où L est le langage de a partant de e
Automaton PieceAutomaton (Automaton a, int *w, int n, int e)
{
//printf("n = %d, e=%d\n", n, e);
int i, j, f;
Automaton r = NewAutomaton(a.n+n, a.na);
//met les sommets pour le mot w
for (i=0;i<n;i++)
{
for (j=0;j<a.na;j++)
{
r.e[i].f[j] = -1;
}
r.e[i].f[w[i]] = i+1;
r.e[i].final = false;
f = a.e[e].f[w[i]];
e = f;
}
if (n > 0)
r.e[n-1].f[w[n-1]] = e+n;
//teste si vide
if (f == -1)
{
FreeAutomaton(&r);
return NewAutomaton(0, a.na);
}
//met les sommets de l'automate a
for (i=0;i<a.n;i++)
{
for (j=0;j<a.na;j++)
{
if (a.e[i].f[j] == -1)
r.e[i+n].f[j] = -1;
else
r.e[i+n].f[j] = a.e[i].f[j]+n;
}
r.e[i+n].final = a.e[i].final;
}
if (n > 0)
r.i = 0;
else
r.i = a.i;
return r;
}

void init (Automaton *a)
{
int i,j;
Expand Down
1 change: 1 addition & 0 deletions src/sage/combinat/words/automataC.h
Expand Up @@ -22,6 +22,7 @@ void ReallocNAutomaton (NAutomaton *a, int n);
void FreeAutomaton (Automaton *a);
void FreeNAutomaton (NAutomaton *a);
Automaton CopyAutomaton (Automaton a, int nalloc, int naalloc);
Automaton PieceAutomaton (Automaton a, int *w, int n, int e); //donne un automate reconnaissant w(w^(-1)L) où L est le langage de a partant de e
void init (Automaton *a);
void printAutomaton (Automaton a);
void plotTikZ (Automaton a, const char **labels, const char *graph_name, double sx, double sy);
Expand Down
32 changes: 27 additions & 5 deletions src/sage/combinat/words/cautomata.pyx
Expand Up @@ -43,6 +43,7 @@ cdef extern from "automataC.h":
void FreeAutomaton (Automaton *a)
void FreeNAutomaton (NAutomaton *a)
Automaton CopyAutomaton (Automaton a, int nalloc, int naalloc)
Automaton PieceAutomaton (Automaton a, int *w, int n, int e)
void init (Automaton *a)
void printAutomaton (Automaton a)
void plotTikZ (Automaton a, const char **labels, const char *graph_name, double sx, double sy)
Expand Down Expand Up @@ -1049,10 +1050,31 @@ cdef class FastAutomaton:
return p;

return p.has_empty_langage()

#donne un automate reconnaissant w(w^(-1)L) où L est le langage de a partant de e
def piece (self, w, e=None):
cdef int* l = <int*>malloc(sizeof(int)*self.a.n)
cdef int i
for i in range(len(w)):
l[i] = w[i]
if e is None:
e = self.a.i
r = FastAutomaton(None)
sig_on()
r.a[0] = PieceAutomaton(self.a[0], l, len(w), e)
sig_off()
r.A = self.A
return r






#tell if the language of the automaton is empty
#(this function is not very efficient)
def is_empty (self, ext=True):
if ext:
return self.emonde().emonde_inf().n_states() == 0
else:
return self.emonde().n_states() == 0

#determine if the languages intersect
def intersect (self, FastAutomaton b, ext=True):
return not self.intersection(b).is_empty(ext)

27 changes: 24 additions & 3 deletions src/sage/monoids/beta_adic_monoid.pyx
Expand Up @@ -2296,7 +2296,7 @@ class BetaAdicMonoid(Monoid_class):

#test if 0 is an inner point of the limit set
def ZeroInner (self, verb=False):

if not hasattr(self, 'ss'):
self.ss = self.default_ss()

Expand Down Expand Up @@ -2339,7 +2339,7 @@ class BetaAdicMonoid(Monoid_class):
self.ss = None
print "Zero is an inner point iff the %s has non-empty interior."%self
self.ss = ss

#complete the langage of a
def complete (self, FastAutomaton a, C=None, ext=False, verb=False):
r"""
Expand Down Expand Up @@ -2506,6 +2506,27 @@ class BetaAdicMonoid(Monoid_class):

#compute the adherence of the new automaton
return self.adherence(tss=a, C=C, C2=nA)


#calcule l'intersection des ensembles limites
def intersection2 (self, FastAutomaton a, FastAutomaton b, ext=True):
a2 = self.complete(a, ext=ext)
b2 = self.complete(b, ext=ext)
return a2.intersection(b2).emonde()

#determine if the limit sets intersect
def intersect (self, FastAutomaton a, FastAutomaton b, ext=True):
a2 = self.complete(a, ext=ext)
b2 = self.complete(b, ext=ext)
return not a2.intersection(b2).is_empty(ext)

#Dit si l'ensemble limite est connexe ou pas
def connexe (self, FastAutomaton a=None):
if a is None:
if hasattr(self, 'tss'):
a = FastAutomaton(self.tss)
else:
a = FastAutomaton(None).full(self.C)

raise ValueError("Not implemented !")


0 comments on commit fda86b7

Please sign in to comment.