diff --git a/src/sage/combinat/words/automataC.c b/src/sage/combinat/words/automataC.c index 21cb7935e7d..27aed5388e4 100644 --- a/src/sage/combinat/words/automataC.c +++ b/src/sage/combinat/words/automataC.c @@ -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 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 0) + r.i = 0; + else + r.i = a.i; + return r; +} + void init (Automaton *a) { int i,j; diff --git a/src/sage/combinat/words/automataC.h b/src/sage/combinat/words/automataC.h index b6f3825de0a..d7f59c283d8 100644 --- a/src/sage/combinat/words/automataC.h +++ b/src/sage/combinat/words/automataC.h @@ -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); diff --git a/src/sage/combinat/words/cautomata.pyx b/src/sage/combinat/words/cautomata.pyx index faa9b8d943f..68faa45df12 100644 --- a/src/sage/combinat/words/cautomata.pyx +++ b/src/sage/combinat/words/cautomata.pyx @@ -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) @@ -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 = 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) diff --git a/src/sage/monoids/beta_adic_monoid.pyx b/src/sage/monoids/beta_adic_monoid.pyx index ab160629954..b1245b0035e 100644 --- a/src/sage/monoids/beta_adic_monoid.pyx +++ b/src/sage/monoids/beta_adic_monoid.pyx @@ -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() @@ -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""" @@ -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 !")