Blogue

ReST syntax highlighting for Sage docstrings in VIM

15 juin 2011 | Catégories: sage | View Comments

Author: Franco Saliola
Contact: saliola at gmail dot com
Date: 3 December 2010

Sage uses ReST syntax in its (Python) docstrings, but the default Python syntax highlighting in vim treats all docstrings as Python strings. Here is a method (by Franco Saliola) to enable ReST highlighting in the docstrings and highlighting of doctests.

/Files/2011/sage_docstring_highlighting.png

Prerequisites

The usual syntax files python.vim and rst.vim must be in the ~/.vim/syntax folder. You can find those on the web. Here is the rst.vim file made by Nikolai Weibull (latest revision: 2010-01-23).

Configuration

Create the directory:

mkdir -p ~/.vim/after/syntax

Any file in this directory will be loaded after the default syntax files, allowing us modify the default highlighting and add our own customizations.

Copy the file python.vim (which can be found in the same directory as this file) into the directory ~/.vim/after/syntax.

The first few lines of the file python.vim define the default colours for the docstring text, the sage keywords and the sage prompt. You might want to modify these to suit your colour scheme.

References

Read and Post Comments

Suivre l'évolution d'un match d'ultimate point par point

19 avril 2011 | Catégories: ultimate | View Comments

Dans un tournoi et surtout dans une saison, on joue plusieurs parties, alors il est facile d'oublier le déroulement des parties jouées et du même coup les leçons qu'on y a faites. Cette saison, l'équipe Odyssée utilisera une méthode facile et innovatrice afin d'archiver les parties jouées et ainsi avoir un support visuel pour se rappeler de celles-ci, de leur déroulement et surtout des erreurs à ne pas refaire et des bons coups à répéter. La méthode est de remplir une grille d'évolution des matchs jouées où on encercle simplement le pointage en cours. Par exemple, voici la grille d'évolution de la finale du CQU4 Ninjax vs Bergers tenue en avril dernier :

/Files/2011/grille_bergers_ninjax.png

Comme vous voyez, en un coup d'oeil, la grille réussit bien à se rappeler le cours du match ou même à quelqu'un qui n'a pas vu le match d'avoir une bonne idée de l'allure du match. La grille permet de dire plus. Par exemple, elle permet de déterminer le nombre de fois qu'une équipe se fait briser : il suffit de calculer la longueurs des plateaux horizontaux et verticaux. Les Bergers se sont faits briser 8 fois de suite 3-3 à 11-3 ce qui a été fatal. Par la suite, la pente illustre qu'il y a eu un certain retour dans le match de la part des Bergers mais jamais assez pour retoucher à la diagonale ou autrement dit à revenir à égalité avec Ninjax.

Voici la grille montrant l'évolution de la finale division masculine des Championnats canadiens d'ultimate (CUC) 2010:

Les grilles vierges que nous utiliserons au cours de la saison sont les suivantes (en format pdf):

Read and Post Comments

Evolution of the overall doctest coverage of Sage

06 mars 2011 | Catégories: sage | View Comments

I just did a graph of the Evolution of the Overall Doctest Coverage of Sage since 3 years. The png is below.

/Files/2011/coverage_evolution.png

The coverage evolved quiet regularly during the last 20 releases (=20 months) with an average of a bit less than 5 percent a year. For sage-4.6.2, it is actually 84.8%. If we keep this rhythm, we should reach 90% coverage by March 2012 and 100% by April 2014.

The code I used is here : coverage_evolution.py.

Read and Post Comments

Occurences of a certain factor in the Kolakoski word

16 février 2011 | Catégories: Kolakoski, sage | View Comments

The factor 212212112112212112122112112212212112112212112122112112 occurs in the Kolakoski word at the positions 3190, 6366, 7614, 12950, 13765, 14277, 20385, 21344, 39674 and so on. The successive gaps of these first eight occurences are 3176, 1248, 5336, 815, 512, 6108, 959, 18330. Are the gap between all of these occurences bounded or not? The following table lists only the gap that are going increasingly for the Kolakoski word up to 100 billion (=10^9).

i ith occurence (i+1)th occurence gap
0 3190 6366 3176
2 7614 12950 5336
5 14277 20385 6108
7 21344 39674 18330
8 39674 58946 19272
17 85963 107018 21055
225 945732 966924 21192
685 2832810 2858670 25860
822 3549762 3583161 33399
965 4188934 4223349 34415
1526 6773992 6809208 35216
7117 31279355 31320896 41541
18054 79167173 79213333 46160
20838 90761663 90809563 47900
176198 768146935 768195609 48674
292643 1278852293 1278906094 53801
554207 2424441033 2424495471 54438
590128 2581311276 2581367730 56454
948506 4150204101 4150264753 60652
1156072 5055131250 5055199553 68303
1514374 6620302433 6620372047 69614
11154155 48788048239 48788121823 73584

The following image draws all the gaps in function of i for the first 10 million digit.

/Files/2011/kolakoski_from0_to10000000.png
Read and Post Comments

Writing object oriented code in Python

20 janvier 2011 | Catégories: sage | View Comments

I am currently at Sage Days 28. Right now, there is a discussion about Analytic combinatorics in Sage and the new code written by Alex Raichev at tikcet #10519 was mentionned in the discussion. His code is a bunch of def python functions in a sage file. In Sage, code is written in object oriented way.

I am not an expert of the domain of analytic combinatorics, but I am coding oriented object Python since some time now. So I wrote a comment on the ticket gathering my thoughts to, I hope, help Alex to rewrite his set of functions into an oriented object structure. I copied the content of my comment below as it will be easier to share it.

Writing object oriented code : Finding the objects

How to structure a bunch of functions into classes? How to find which objects (python classes) you need? Here is the trick I personaly use. Consider each of your functions as a question you ask. Then, ask yourself to who are you asking each of your questions? Answers often gives you a good hint about the objects you need to implement. EXAMPLE. Suppose I code the function determinant. Question : To who do I ask the determinant?. Answer: To a matrix. Hence, matrix might be a good object (a python class) to implement.

You are the best person to answer to these questions. You might have 30 functions in your file, but only two or three different answers to the above question. Regroup the similar functions together: they will become the methods of a same class.

The sage file you uploaded starts with:

r"""
[...]

This code relates to analytic combinatorics.
More specifically, it is a collection of functions designed
to compute asymptotics of Maclaurin coefficients of certain classes of
multivariate generating functions.

The main function asymptotics() returns the first `N` terms of
the asymptotic expansion of the Maclaurin coefficients `F_{n\alpha}`
of the multivariate meromorphic function `F=G/H` as `n\to\infty`.
It assumes that `F` is holomorphic in a neighborhood of the origin,
that `H` is a polynomial, and that asymptotics in the direction of
`\alpha` (a tuple of positive integers) are controlled by smooth
or multiple points.

[...]
"""

Reading only these lines, I imagine the following structure:

class HolomorphicMultivariateMeromorphicFunction(object):

    # Constructor of the object
    def __init__(self, F, G):
        #stores important information on the object as attributes of self
        self._F = F
        self._G = G

    def maclaurin_coefficients(self, n, alpha):
        r"""
        Return the maclaurin coefficients of self.

        INPUT:

        - ``alpha`` - tuple of positive integers

        OUTPUT:

        a python list of the first terms

        OR

        maybe an object of a class you implement if there exists pertinent
        questions to ask to it.
        """
        #Do some computations based (I guess) on self._F and self._G
        intermediate_result1 = self.some_intermediate_computations_1()
        #Do more computations
        return something

    def asymptotics(self, N, alpha):
        r"""
        Returns the asymptotics of Maclaurin coefficients.
        """
        #Do some computations based (I guess) on self._F and self._G
        intermediate_result2 = self.some_intermediate_computations_2()
        intermediate_result3 = self.some_intermediate_computations_3()
        return something

    #put here all the others functions needed to compute the asymptotics
    def some_intermediate_computations_1(self):
        pass
    def some_intermediate_computations_2(self):
        pass
    def some_intermediate_computations_3(self):
        pass

    ...

It also looks like you need some robustness somehow. But I need to know more information about what means

"that asymptotics in the direction of \(\alpha\) (a tuple of positive integers) are controlled by smooth or multiple points."

to decide whether this is checked at the creation of the object or before returning the asymptotics. But these hypothesis should be checked somewhere.

Hope this helps.

Cheers,

Sébastien Labbé, Montréal, (but currently at Sage Days 28, Orsay, France)

Read and Post Comments

« Previous Page -- Next Page »