Skip to content

Instantly share code, notes, and snippets.

@baruchel
baruchel / gist:9416637
Last active August 29, 2015 13:57
Pivot de Gauss
pivot = (
lambda m:
(lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args))))
(lambda g:
(lambda h,n:
g(
(lambda i:
[
[ z - y[n]*i[n][k]/i[n][n] for k,z in enumerate(y) ]
if x!=n else
@baruchel
baruchel / TD_simulnum.md
Last active August 29, 2015 13:57
T.D. Informatique / simulation numérique

Code en Python3 pour les T.D. d'informatique de mars 2014

On trouvera :

  • TD_simulnum_gauss.py : méthode du pivot de Gauss
  • TD_simulnum_riemann.py : méthodes d'intégration
  • TD_simulnum_solve.py : recherche du zéro d'une fonction
@baruchel
baruchel / gist:9546517
Last active August 29, 2015 13:57
Settings for various languages for my Vim REPL plugin

Put the four relevant lines in your ~/.vimrc file. The plugin has to be installed separately from here.

GNU APL

let g:repl_cmd = '/home/pi/APL/svn/trunk/src/apl --noSV --rawCIN --noColor'
let g:repl_stop = ')OFF'
let g:repl_send = "'REPL-VIM'"
let g:repl_detect = 'REPL-VIM'

Maxima

-- Reproduire la table `CountryLanguage` à la différence près que la colonne Percentage doit maintenant contenir le pourcentage de locuteurs d'une langue dans un pays par rapport au nombre total de locuteurs de cette langue dans le monde.
SELECT CountryCode, Language, IsOfficial,
(A.Percentage * A.Population / B.nbr) AS Percentage
FROM (
SELECT CountryLanguage.*, Country.Population
FROM CountryLanguage
LEFT JOIN Country
ON CountryLanguage.CountryCode = Country.Code
) AS A
@baruchel
baruchel / notebook.md
Last active August 29, 2015 14:09
Thomas Baruchel's mathematical notebook

Thomas Baruchel's mathematical notebook

(https://gist.github.com/2b870728323456f71402)

This is my mathematical notebook; I put here the identities I find from time to time; this notebook is written in the markdown format with the vim editor. I use my own vim-notebook plugin for embedding Maxima code in it; thus I can evaluate each cell of code.

" quickmove.vim : move the cursor according to the more/less game
" Author: Thomas Baruchel
" Version: 1.0
" Date: Mar 14, 2015
"
let g:quickmove_version = "1.0"
if &compatible
finish
endif
@baruchel
baruchel / gist:75c4134a362cd0ebd1f5
Created June 10, 2015 07:25
Quick version of k-means with numpy written in a functional style
# -*- coding: utf-8 -*-
import numpy as np
import scipy.ndimage.measurements
import random
def kMeans( data, k, centers=None, iter=64 ):
if len(data.shape) == 1:
data = np.vstack(data)

Hacking Dyalog APL # 1

Dyalog APL is a great tool but the interface for working in an interactive session is rather poor. Editing previous lines by moving the cursor to some other location is rather painful. Of course Dyalog APL isn't allowed to use the great readline library. But it is not too difficult to replace the officiel ncurses interface by some more modern readline-based one as long as you do it with an external tool.

What you will get is:

  • a modern readline-based input;
  • a great history system (persistent accross sessions if you wish);
  • the ability to launch your favorite editor on the fly for editing a more complex line of input (or defining a traditional function) whenever you want;
  • leaving Dyalog APL with the Ctrl-D signal;
@baruchel
baruchel / library_sort.py
Last active November 21, 2015 04:04
Library sort in Python
# -*- coding: utf8 -*-
def library_sort(l):
# Initialization
d = len(l)
k = [None]*(d<<1)
m = d.bit_length() # floor(log2(n) + 1)
for i in range(d): k[2*i+1] = l[i]
# main loop
@baruchel
baruchel / dd.py
Last active December 11, 2015 13:03
Fast vectorized arithmetic with ~32 significant digits under Numpy
# Adapted from:
# "A Floating-Point Technique for Extending the vailable Precision"
# by T.J. Dekker in Numer. Math. 18, 224-242, 1971.
# (adapted to Numpy from the Algol 60 code in the paper)
import numpy as np
import decimal
_npDecimal = np.vectorize(decimal.Decimal, otypes=[object])