#19520: implement random triangulations in a bijective way
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:
  chapoton               |       Status:  needs_review
           Type:         |    Milestone:  sage-6.10
  enhancement            |   Resolution:
       Priority:  major  |    Merged in:
      Component:  graph  |    Reviewers:  Nathann Cohen
  theory                 |  Work issues:
       Keywords:         |       Commit:
  random graph           |  3a7356b7b4b667ebdaa8f955452e7c8aaefa283c
        Authors:         |     Stopgaps:
  Frédéric Chapoton      |
Report Upstream:  N/A    |
         Branch:         |
  public/19520           |
   Dependencies:         |
-------------------------+-------------------------------------------------

Comment (by ncohen):

 Hellooo Frédéric,

 I am reading the 'main' part of the algorithm, and trying to understand
 how you find the subsequences of the form 'in,in,in,lf,in'. It seems (I am
 not sure) that you do this manually. Here is something that you may like:

 {{{
 sage: 'abcdefghihijk'.index('def')
 3
 }}}

 This 'index' function of str also takes an optional argument that means
 that the search should not start from the first character of the string,
 but from some later index. Eg
 {{{
 sage: 'abcdefghihijk'.index('def',5)
 ...
 ValueError: substring not found
 }}}

 If you do what I think you are doing, then you are rewriting this .index
 function.

 Now, you cannot directly use this function, because it is a member of
 'str' and not a member of 'list'. And your list is a sequence of pairs.
 Thus, it could be 'made to work' by creating a 'copy' of your list that
 only contains the indication of in/lf. Something like that
 {{{
 sage: w=[('in',3)]*5+[('lf',4)]+[('in',3)]
 sage: s="".join(x[0] for x in w)
 sage: s.index('inininlfin')
 4
 }}}

 With this index you can now do whatever operation on w you need.

 This requires a copy of the list into a string, though on the other hand
 it would make your code much easier to read -- if you actually do what I
 think you do.

 What do you think?

 Alternatively, you could 'rewrite' an index function that applies to
 lists. Something like:
 {{{
 sage: def find_pattern(l):
 ....:     for i in range(len(l)-4):
 ....:         if 'in' == l[i] == l[i+1] == l[i+2] == l[i+4] and l[i+3] ==
 'lf':
 ....:             return i
 }}}

 It is not the 'best algorithmic way to compute it', but it would work. Do
 you think something like that may improve the code?

 Nathann

--
Ticket URL: <http://trac.sagemath.org/ticket/19520#comment:33>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to