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

Commit

Permalink
Add functions split(), shift1OP() and unshift1() to FastAutomaton and…
Browse files Browse the repository at this point in the history
… correct some bugs.
  • Loading branch information
mercatp committed Nov 18, 2014
1 parent 4c59b96 commit 968d02a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/sage/combinat/words/automataC.c
Expand Up @@ -208,9 +208,10 @@ void ReallocAutomaton (Automaton *a, int n)
*/
}

Automaton CopyAutomaton (Automaton a)
Automaton CopyAutomaton (Automaton a, int nalloc, int naalloc)
{
Automaton r = NewAutomaton(a.n, a.na);
//a.n, a.na
Automaton r = NewAutomaton(nalloc, naalloc);
int i,j;
for (i=0;i<a.n;i++)
{
Expand Down Expand Up @@ -494,6 +495,8 @@ bool emptyLangage_rec (Automaton a, int e)
//détermine si le langage de l'automate est vide
bool emptyLangage (Automaton a)
{
if (a.i == -1)
return true;
bool res = emptyLangage_rec(a, a.i);
//remet les états finaux
int i;
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/words/automataC.h
Expand Up @@ -14,7 +14,7 @@ void printDict (Dict d);
void dictAdd (Dict *d, int e); //ajoute un élément au dictionnaire (même s'il était déjà présent)
Automaton NewAutomaton (int n, int na);
void FreeAutomaton (Automaton *a);
Automaton CopyAutomaton (Automaton a);
Automaton CopyAutomaton (Automaton a, int nalloc, int naalloc);
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
80 changes: 78 additions & 2 deletions src/sage/combinat/words/cautomata.pyx
Expand Up @@ -40,7 +40,7 @@ cdef extern from "automataC.h":

Automaton NewAutomaton (int n, int na)
void FreeAutomaton (Automaton *a)
Automaton CopyAutomaton (Automaton a)
Automaton CopyAutomaton (Automaton a, int nalloc, int naalloc)
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 @@ -559,6 +559,62 @@ cdef class FastAutomaton:
#r = r.minimise()
return r.emonde().minimise()

#split the automaton with respect to a
def split (self, FastAutomaton a, verb=False):
#complete the automaton a
sig_on()
CompleteAutomaton(a.a)
sig_off()

#make the product
d = {}
for l in self.A:
if l in a.A:
d[(l,l)] = l

cdef Automaton ap
cdef Dict dC
r = FastAutomaton(None)
r2 = FastAutomaton(None)
Av = []
sig_on()
dv = imagProductDict(d, self.A, a.A, Av=Av)
sig_off()
if verb:
print "Av=%s"%Av
print "dv=%s"%dv
sig_on()
dC = getProductDict(d, self.A, a.A, dv=dv, verb=verb)
sig_off()
if verb:
print "dC="
printDict(dC)
sig_on()
ap = Product(self.a[0], a.a[0], dC)
FreeDict(dC)
sig_off()

#set final states for the intersection
cdef int i,j
cdef n1 = self.a.n
for i in range(n1):
for j in range(a.a.n):
ap.e[i+n1*j].final = self.a.e[i].final and a.a.e[j].final

#complementary of a in self
cdef Automaton ap2
ap2 = CopyAutomaton(ap, ap.n, ap.na)
#set final states
for i in range(n1):
for j in range(a.a.n):
ap2.e[i+n1*j].final = self.a.e[i].final and not a.a.e[j].final

r.a[0] = ap
r.A = Av
r2.a[0] = ap2
r2.A = Av
return [r.emonde().minimise(), r2.emonde().minimise()]

#return the automaton recognizing the langage shifted
def shift (self, verb=False):
#détermine la liste des successeurs de l'état initial
Expand All @@ -582,6 +638,26 @@ cdef class FastAutomaton:
b = b.emonde().minimise()
a = a.union(b)
return a

#modify the automaton to recognize the langage shifted by a (letter given by its index)
def shift1OP (self, int a, verb=False):
if self.a.i != -1:
self.a.i = self.a.e[self.a.i].f[a]

def unshift1 (self, int a):
r = FastAutomaton(None)
sig_on()
cdef Automaton aut
aut = CopyAutomaton(self.a[0], self.a.n+1, self.a.na)
cdef int i
cdef int ne = self.a.n
for i in range(aut.na):
aut.e[ne].f[i] = -1
aut.e[ne].f[a] = self.a.i
aut.i = ne
r.a[0] = aut
r.A = self.A
return r

def determinise_proj (self, dict d, noempty=True, onlyfinals=False, nof=False, verb=False):
sig_on()
Expand Down Expand Up @@ -795,7 +871,7 @@ cdef class FastAutomaton:
def copy (self):
sig_on()
r = FastAutomaton(None)
r.a[0] = CopyAutomaton(self.a[0])
r.a[0] = CopyAutomaton(self.a[0], self.a.n, self.a.na)
r.A = self.A
sig_off()
return r
Expand Down
25 changes: 16 additions & 9 deletions src/sage/monoids/beta_adic_monoid.pyx
Expand Up @@ -106,7 +106,7 @@ cdef getElement (e, Element r, int n):

cdef InfoBetaAdic initInfoBetaAdic (self, Cd=None, verb=False) except *:
#compute all the data in sage
K = NumberField((1/self.b).minpoly(), 'b', embedding=QQbar(self.b))
K = NumberField((1/self.b).minpoly(), 'b', embedding=QQbar(1/self.b))
b = K.gen()
C = [c.lift()(1/b) for c in self.C]
if verb:
Expand Down Expand Up @@ -502,7 +502,7 @@ class BetaAdicMonoid(Monoid_class):
else:
return "Monoid of b-adic expansion with b root of %s and numerals set %s"%(K.modulus(),self.C) + str

def default_ss (self):
def default_ss (self, C=None):
r"""
Returns the full subshift (given by an Automaton) corresponding to the beta-adic monoid.
Expand All @@ -512,7 +512,8 @@ class BetaAdicMonoid(Monoid_class):
sage: m.default_ss()
Finite automaton with 1 states
"""
C = self.C
if C is None:
C = self.C
ss = Automaton()
ss.allow_multiple_edges(True)
ss.allow_loops(True)
Expand Down Expand Up @@ -2345,15 +2346,18 @@ class BetaAdicMonoid(Monoid_class):
if verb:
print "Cd=%s"%Cd
a = self.relations_automaton3(Cd=Cd, ext=ext)
if step == 1:
return a
if verb:
print " -> %s"%a
a = a.emonde_inf()
if step == 2:
if step == 1:
return a
if ext:
a = a.emonde_inf()
else:
a = a.emonde()
if verb:
print " Après émondation : %s"%a
if step == 2:
return a
d={}
for c1 in C2:
for c2 in C:
Expand All @@ -2368,7 +2372,7 @@ class BetaAdicMonoid(Monoid_class):
print a2
if step == 3:
return a2
ap = tss.product(FastAutomaton(self.default_ss()), verb=verb)
ap = tss.product(FastAutomaton(self.default_ss(C=C)), verb=verb)
if step == 4:
return ap
a2 = ap.intersection(a2)
Expand Down Expand Up @@ -2407,7 +2411,10 @@ class BetaAdicMonoid(Monoid_class):
def move (self, t, FastAutomaton tss=None, list C=None, step=None):
if tss is None:
if hasattr(self, 'tss'):
tss = FastAutomaton(self.tss)
if isinstance(self.tss, FastAutomaton):
tss = self.tss
else:
tss = FastAutomaton(self.tss)
else:
tss = FastAutomaton(self.default_ss())
if C is None:
Expand Down
3 changes: 3 additions & 0 deletions src/sage/monoids/relations.c
Expand Up @@ -107,6 +107,9 @@ void initHash ()
void freeInfoBetaAdic (InfoBetaAdic iba)
{
int i;
free(pile);
free(thash);
free(iba.cM);
for (i=0;i<iba.ncmax;i++)
{
FreeElement(iba.c[i]);
Expand Down

0 comments on commit 968d02a

Please sign in to comment.