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

Commit

Permalink
Add a non-recursive version of combinat/words/Automaton/determinize
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul MERCAT authored and Paul MERCAT committed Apr 25, 2014
1 parent cf8e9c8 commit 43b1ee6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
45 changes: 45 additions & 0 deletions src/sage/combinat/words/automata.pyx
Expand Up @@ -368,6 +368,51 @@ class Automaton (DiGraph):
# res.F.add(v)
return res

def determinize2 (self, I=None, A=None, nof=set(), noempty=True, verb=False):
if I is None:
if hasattr(self, 'I'):
I = self.I
if I is None:
raise ValueError("The set I of initial states must be defined !")
if A is None:
if hasattr(self, 'A'):
A = self.A
if A is None:
A = set(self.edge_labels())
#raise ValueError("The alphabet A must be defined !")
#from sage.sets.set import set

nof = set(nof)

c = 0
a = Automaton(loops=True, multiedges=True)
SS = set([Set(I)])
a.I = set([Set(I)])
a.A = A
a.add_vertex(Set(I))
while len(SS) != 0:
S = SS.pop()
o = dict([])
for l in A:
o[l] = set([])
for s in S:
for f, d, l in self.outgoing_edges(s):
o[l].add(d)
for l in A:
if o[l] != set([]) or not noempty:
if nof.isdisjoint(o[l]):
o[l] = Set(o[l])
if not a.has_vertex(o[l]):
a.add_vertex(o[l])
SS.add(o[l])
c+=1
if c%1000 == 0 and verb:
print c
a.add_edge(S, o[l], l)
if hasattr(self, 'F'):
a.F = set([v for v in a.vertices() for f in self.F if f in v])
return a

def complete (self, name=None, verb=False):
r"""
Complete the given automaton.
Expand Down
26 changes: 17 additions & 9 deletions src/sage/monoids/beta_adic_monoid.pyx
Expand Up @@ -296,14 +296,21 @@ class BetaAdicMonoid(Monoid_class):
from sage.functions.log import log
n = int(5.2/-log(abs(self.b.N(prec=prec))))

if place is None:
#choisis une place
places = K.places()
place = places[0]
for p in places:
if abs(p(b)) < 1:
place = p
#break
from sage.rings.complex_field import ComplexField
CC = ComplexField(prec)
if place is None:
if abs(b) < 1:
#garde la place courante
#place = lambda x: CC(x.n())
return [CC(c).conjugate().N(prec) for c in self.points_exact(n=n, ss=ss, iss=iss)]
else:
#choisis une place
places = K.places()
place = places[0]
for p in places:
if abs(p(b)) < 1:
place = p
#break

#from sage.rings.qqbar import QQbar
#from sage.rings.qqbar import QQbar, AA
Expand Down Expand Up @@ -1266,7 +1273,8 @@ class BetaAdicMonoid(Monoid_class):

if verb: print "Determinization..."
#determinize
ad = a.determinize(nof=a.F, verb=False)
ad = a.determinize2(nof=a.F)
#ad = a.determinize(nof=a.F, verb=False)
#ad = a.determinize(I, self.C, nof, verb=verb)

if verb: print " -> %s"%ad
Expand Down

0 comments on commit 43b1ee6

Please sign in to comment.