Blogue

Animation des solutions d'un puzzle de Florent Hivert

22 juillet 2011 | Catégories: animation, sage | View Comments

On veut placer les pièces suivantes dans un carré 8 par 8.

/Files/2011/carre.jpg

En utilisant sage-4.7 muni des patchs du ticket #11379 et avec les commandes suivantes, on peut trouver une solution et même les calculer toutes:

sage: from sage.combinat.tiling import Polyomino, TilingSolver
sage: L = []
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,2),(1,3)], 'yellow'))
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,2)], "black"))
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,3)], "gray"))
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(0,3),(1,0),(1,3)],"cyan"))
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(0,3),(1,0),(1,1)],"red"))
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(0,3),(1,1),(1,2)],"blue"))
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(0,3),(1,1),(1,3)],"green"))
sage: L.append(Polyomino([(0,1),(0,2),(0,3),(1,0),(1,1),(1,3)],"magenta"))
sage: L.append(Polyomino([(0,1),(0,2),(0,3),(1,0),(1,1),(1,2)],"orange"))
sage: L.append(Polyomino([(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)],"pink"))
sage: T = TilingSolver(L, (8,8), reflection=True)
sage: T.number_of_solutions()
328

Ainsi (sans tenir compte de la non adjacence des carrés blancs et noirs), il y a 328 solutions. Les voici en animation:

sage: a = T.animate()
sage: a
Animation with 328 frames
sage: a.show(delay=50, iterations=1)
/Files/2011/florent_puzzle_328.gif

Chaque solution est répétée 8 fois (les 4 rotations et les 4 rotations de l'image miroir), ainsi il n'y a que 41 solutions vraiment distinctes:

sage:: factor(328)
8 * 41

J'ai aussi codé:

sage: a = T.animate('incremental', stop=300)

où une seule pièce est enlevée ou ajoutée à la fois ce qui permet vraiment de visualiser les liens dansants de Knuth (rafraîchir le navigateur pour faire recommencer l'animation):

/Files/2011/florent_increm_300.gif
Read and Post Comments

ReST to Sage Worksheet

17 juin 2011 | Mise à jour: 08 septembre 2011 | Catégories: rst, sage | View Comments

During Sage Days 31, I worked on the ticket #11459 to implement rst to sws conversion. This post intends to give some documentation about this new feature. Here is an example of a ReStructuredText file calculus.rst:

********
Calculus
********

Let's do some calculus using Sage.

Differentiation
===============

The derivative of $\\sin(x)$ is::

    sage: diff(sin(x), x)
    cos(x)

The derivative of $\\log(x) + x^2$ is::

    sage: diff(log(x) + x^2, x)
    2*x + 1/x

Integration
===========

Sage can integrate $\\int x^3 dx$::

    sage: f = x^3 
    sage: f.integral(x)
    1/4*x^4

Let's compute $\\int x \\sin(x^2) dx$::

    sage: f = x*sin(x^2)
    sage: integral(f,x)
    -1/2*cos(x^2)

Both the files calculus.rst and calculus.html, which was generated from the file calculus.rst using Docutils and the command rst2html.py calculus.rst calculus.html, can be uploaded into the Sage Notebook (copy their URL):

/Files/2011/upload.png

This will create a new worksheet:

/Files/2011/calculus.png

I also implemented two command line scripts to generate the worksheet text file:

sage -rst2txt file.rst file.txt

and to generate the Sage worksheet (.sws) directly:

sage -rst2sws file.rst file.sws

I also added the possibility to automatically escape every backslashes if they are not already so that they don't get lost in the translation process. For more info, consult the documentation:

sage -rst2txt -h
sage -rst2sws -h
Read and Post Comments

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

« Previous Page -- Next Page »