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 relations_automata2() to BetaAdicMonoid much more effi…
Browse files Browse the repository at this point in the history
…cient than relations_automaton(), and using FastAutomaton.
  • Loading branch information
mercatp committed Nov 5, 2014
1 parent f256a4b commit 79686e5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/sage/combinat/words/cautomata.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ cdef extern from "automataC.h":
Automaton DeleteVertex (Automaton a, int e)
bool equalsLangages (Automaton *a1, Automaton *a2, Dict a1toa2, bool minimized)
bool emptyLangage (Automaton a)
void AddEtat (Automaton *a, bool final)
void Test ()

#dictionnaire numérotant l'alphabet projeté
Expand Down Expand Up @@ -400,11 +401,19 @@ cdef class FastAutomaton:
raise ValueError("%d is not a state !"%f)
self.a.e[f].final = 1

def set_final_state (self, int e, final=True):
self.a.e[e].final = final

def succ (self, int i, int j):
if i<0 or i>=self.a.n or j<0 or j>=self.a.na:
return -1
return self.a.e[i].f[j]

def set_succ (self, int i, int j, int k):
if i<0 or i>=self.a.n or j<0 or j>=self.a.na:
raise ValueError("set_succ(%s, %s) : index out of bounds !"%(i,j))
self.a.e[i].f[j] = k

def emonde_inf (self, verb=False):
sig_on()
cdef Automaton a
Expand Down Expand Up @@ -710,5 +719,11 @@ cdef class FastAutomaton:
sig_off()
return Bool(res)

def add_state (self, bool final):
sig_on()
AddEtat(self.a, final)
sig_off()

def n_states (self):
return self.a.n

87 changes: 87 additions & 0 deletions src/sage/monoids/beta_adic_monoid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,93 @@ class BetaAdicMonoid(Monoid_class):
ssd = ssd.emonde0_simplify()
return ssd


def reduced_words_automaton2 (self, step=100, verb=False):
r"""
Compute the reduced words automaton of the beta-adic monoid (without considering the automaton of authorized words).
See http://www.latp.univ-mrs.fr/~paul.mercat/Publis/Semi-groupes%20fortement%20automatiques.pdf for a definition of such automaton.
Use fast C-functions but works only for algebraic integer.
(Consider using reduced_words_automaton() if you're not in this case.)
INPUT:
- ``verb`` - bool (default: ``False``)
If True, print informations for debugging.
OUTPUT:
FastAutomaton.
"""

#compute the relations automaton
Cd = list(set([c-c2 for c in self.C for c2 in self.C]))
Cdp = [k for k in range(len(Cd)) if Cd[k] in [self.C[j]-self.C[i] for i in range(len(self.C)) for j in range(i)]] #indices des chiffres strictements négatifs dans Cd
arel = self.relations_automaton3(Cd=Cd, ext=False)
arel = arel.emonde()
if verb:
print "arel = %s"%arel
if step == 1:
return arel

#add a new state
cdef int ne, ei
ei = arel.initial_state()
ne = arel.n_states() #new added state
arel.add_state(True)
arel.set_final_state(ei, final=False) #it is the new final state
if step == 2:
return arel

#add edges from the new state (copy edges from the initial state)
for j in range(len(Cd)):
arel.set_succ(ne, j, arel.succ(ei, j))
if step == 3:
return arel

#suppress some edges from the initial state
for j in Cdp:
arel.set_succ(ei, j, -1)
if step == 4:
return arel

#change edges that point to the initial state : make them point to the new state
for e in arel.states():
if e != ei:
for j in range(len(Cd)):
if arel.succ(e, j) == ei:
arel.set_succ(e, j, ne)
if step == 5:
return arel

#project, determinise and take the complementary
d = {}
for a in self.C:
for b in self.C:
if not d.has_key(a-b):
d[a-b] = []
d[a-b].append((a,b))
if verb:
print d
arel = arel.duplicate(d) #replace differences with couples
d = {}
for j in self.C:
for i in self.C:
d[(i,j)] = i
if verb:
print d
print arel
arel = arel.determinise_proj(d, noempty=False, nof=True) #, verb=True) #project on the first value of the couple, determinise and take the complementary
if verb:
print arel
arel = arel.emonde()
arel = arel.emonde_inf()
if step == 10:
return arel
return arel.minimise()




def reduced_words_automaton (self, ss=None, Iss=None, ext=False, verb=False, step=None, arel=None):
r"""
Compute the reduced words automaton of the beta-adic monoid (with or without subshift).
Expand Down

0 comments on commit 79686e5

Please sign in to comment.