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

Commit

Permalink
Correct some little problems with BetaAdicMonoid.relations_automaton3…
Browse files Browse the repository at this point in the history
…() and others.
  • Loading branch information
mercatp committed Nov 5, 2014
1 parent 2a6a48d commit f256a4b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/sage/combinat/words/cautomata.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ cdef class FastAutomaton:
DeleteVertexOP(self.a, i)
sig_off()

def spectral_radius (self, verb=False):
def spectral_radius (self, only_non_trivial=False, verb=False):
sig_on()
a = self.minimise()
if verb:
Expand All @@ -662,7 +662,7 @@ cdef class FastAutomaton:
print "%s composantes fortement connexes."%len(l)
r = 0 #valeur propre maximale trouvée
for c in l:
if len(c) > 1:
if not only_non_trivial or len(c) > 1:
if verb:
print "composante ayant %s états..."%len(c)
b = a.sub_automaton(c)
Expand Down Expand Up @@ -695,7 +695,7 @@ cdef class FastAutomaton:
sig_on()
res = emptyLangage(self.a[0])
sig_off()
return res
return Bool(res)

def equals_langages (self, FastAutomaton a2, minimized=False):
sig_on()
Expand All @@ -708,6 +708,7 @@ cdef class FastAutomaton:
break
res = equalsLangages(self.a, a2.a, d, minimized)
sig_off()
return res


return Bool(res)



65 changes: 57 additions & 8 deletions src/sage/monoids/beta_adic_monoid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ cdef extern from "relations.h":

InfoBetaAdic allocInfoBetaAdic (int n, int na, int ncmax, bool verb)
void freeInfoBetaAdic (InfoBetaAdic iba)
Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool verb)
Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool ext, bool verb)

cdef getElement (e, Element r, int n):
cdef j
Expand Down Expand Up @@ -152,7 +152,7 @@ cdef InfoBetaAdic initInfoBetaAdic (self, Cd=None, verb=False) except *:
if Cd is None:
Cd = Set([c-c2 for c in C for c2 in C])
else:
Cd = [c.lift()(1/b) for c in Cd]
Cd = [K(c).lift()(1/b) for c in Cd]
if verb: print "Cd = %s"%Cd
m = dict([])
for p in parch:
Expand Down Expand Up @@ -364,6 +364,8 @@ cdef BetaAdic getBetaAdic (self, prec=53, ss=None, tss=None, iss=None, transpose
if add_letters:
C = set(self.C)
C.update(a.Alphabet())
else:
C = a.Alphabet()
C = list(C)

b = NewBetaAdic(len(C))
Expand Down Expand Up @@ -754,7 +756,7 @@ class BetaAdicMonoid(Monoid_class):
Default values: between ``5`` and ``16`` depending on the number of generators.
- ``place`` - place of the number field of beta (default: ``None``)
The place we should use to evaluate elements of the number field.
The place used to evaluate elements of the number field.
- ``ss`` - Automaton (default: ``None``)
The subshift to associate to the beta-adic monoid for this drawing.
Expand Down Expand Up @@ -1468,18 +1470,29 @@ class BetaAdicMonoid(Monoid_class):
res.emonde()
return res

def relations_automaton3 (self, isvide=False, Cd=None, verb=False):
def relations_automaton3 (self, isvide=False, Cd=None, ext=False, verb=False):
r"""
Compute the relation automaton of the beta-adic monoid.
For beta algebraic integer only.
If isvide is True, it only checks if the automaton is trivial or not.
Cd is the set of differences A-B where A and B are the alphabets to compare.
ext : automate des relations à l'infini ou pas.
"""
if Cd is None:
Cd = Set([c-c2 for c in self.C for c2 in self.C])
Cd = list(Cd)
sig_on()
cdef InfoBetaAdic ib
ib = initInfoBetaAdic(self, Cd=Cd, verb=verb)
cdef Automate a
a = RelationsAutomaton(ib, isvide, verb)
a = RelationsAutomaton(ib, isvide, ext, verb)
r = FastAutomaton(None)
r.a[0] = a
r.A = Cd
freeInfoBetaAdic(ib)
sig_off()
if isvide:
return a.na != 0
return r

def critical_exponent_aprox (self, niter=10, verb=False):
Expand Down Expand Up @@ -1722,8 +1735,8 @@ class BetaAdicMonoid(Monoid_class):
sage: m = BetaAdicMonoid(1/(1+I), {0,1})
sage: import sage.combinat.words.cautomata
sage: from sage.combinat.words.cautomata import FastAutomaton
sage: ss0 = FastAutomaton([(0,1,0)]+[(1,1,l) for l in m.C], i=0, final_states=[1])
sage: from sage.combinat.words.cautomata import FastAutomaton
sage: ss0 = FastAutomaton([(0,1,0)]+[(1,1,l) for l in m.C], i=0, final_states=[1])
sage: ss1 = FastAutomaton([(0,1,1)]+[(1,1,l) for l in m.C], i=0, final_states=[1])
sage: ssi = m.intersection2(ss0, ss1)
sage: m.plot2(tss = ssi) # long time
Expand Down Expand Up @@ -2228,7 +2241,43 @@ class BetaAdicMonoid(Monoid_class):
print "Zero is an inner point iff the %s has non-empty interior."%self
self.ss = ss


#donne l'automate décrivant l'adhérence de l'ensemble limite avec un nouvel alphabet C
def adherence (self, C, tss=None, verb=False):
if verb:
print "Calcul de l'automate des relations..."
Cd = [c1-c2 for c1 in self.C for c2 in C]
if verb:
print "Cd=%s"%Cd
a = self.relations_automaton3(Cd=Cd, ext=True)
if verb:
print " -> %s"%a
a = a.emonde_inf()
if verb:
print " Après émondation : %s"%a
d={}
for c1 in self.C:
for c2 in C:
if not d.has_key(c1-c2):
d[c1-c2] = []
d[c1-c2].append((c1,c2))
if verb:
print d
a2 = a.duplicate(d, verb=verb)
if verb:
print a2.Alphabet()
print a2
print "déterminise..."
d={}
for c1,c2 in a2.Alphabet():
d[(c1,c2)] = c2
a2 = a2.determinise_proj(d, verb=verb)
if verb:
print " -> %s"%a2
#a2 = a2.emonde()
a2 = a2.emonde_inf()
if verb:
print "Après simplification : %s"%a2
return a2



Expand Down
29 changes: 26 additions & 3 deletions src/sage/monoids/relations.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool keep (Element e)
int i;
for (i=0;i<iba.na;i++)
{
if (cnorm(eval(e, i)) >= iba.cM[i])
if (cnorm(eval(e, i)) + .0000001 > iba.cM[i])
return false;
}
}
Expand Down Expand Up @@ -185,6 +185,17 @@ Element zeroElement ()
return e;
}

bool isNull (Element e)
{
int i;
for (i=0;i<iba.n;i++)
{
if (e.c[i] != 0)
return false;
}
return true;
}

bool equalsElements (Element e, Element f)
{
int i;
Expand Down Expand Up @@ -278,7 +289,7 @@ int indElement (Element e)
}

//calcule l'automate des relations
Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool verb)
Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool ext, bool verb)
{
int i,j;

Expand Down Expand Up @@ -313,7 +324,7 @@ Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool verb)
printf("parcours...\n");
int n = 1; //nombre d'éléments sur la pile
compteur = 0; //nombre d'états de l'automate
//état initial
//état initial
pile[0] = zeroElement();
inHash(pile[0]); //ajoute l'élément à la table de hachage
Element e = NewElement(iba.n);
Expand Down Expand Up @@ -345,10 +356,12 @@ Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool verb)
//teste si l'élément a déjà été vu et l'ajoute si non
if (!inHash(s))
{ //l'élement est nouveau et a été ajouté à la table de hachage
/*
if (isvide && !vide)
{ //l'automate n'est pas trivial
return NewAutomaton(1,0);
}
*/
//empile
pile[n] = NewElement(iba.n);
copy(s, pile[n]);
Expand All @@ -357,6 +370,16 @@ Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool verb)
{
printf("Erreur : dépassement de la pile !!!\n");
}
}else
{//on retombe sur un état déjà vu
if (isvide)
{
//if (!isNull(e) &&
if (ext || isNull(s))
{ //l'automate émondé inf ou émondé n'est pas vide
return NewAutomaton(1,0);
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sage/monoids/relations.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ InfoBetaAdic allocInfoBetaAdic (int n, int na, int ncmax, bool verb);
void freeInfoBetaAdic (InfoBetaAdic iba);

//calcule l'automate des relations
Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool verb);
Automate RelationsAutomaton (InfoBetaAdic iba2, bool isvide, bool ext, bool verb);

0 comments on commit f256a4b

Please sign in to comment.