Skip to content

Instantly share code, notes, and snippets.

View fredrik-johansson's full-sized avatar
🕵️‍♂️
Deep into the code

Fredrik Johansson fredrik-johansson

🕵️‍♂️
Deep into the code
View GitHub Profile
@fredrik-johansson
fredrik-johansson / gist:10761192
Last active August 29, 2015 13:59
Most beautiful C indent style
void _nmod_poly_powmod_mpz_binexp(mp_ptr res, mp_srcptr poly,
mpz_srcptr e, mp_srcptr f,
slong lenf, nmod_t mod) {
mp_ptr T, Q ;
slong lenT, lenQ ;
slong i ;
if (lenf == 2) {
res[0] = n_powmod2_mpz(poly[0], e, mod.n, mod.ninv) ;
return ;}
#include "ulong_extras.h"
#include "profiler.h"
mp_limb_t n_sqrtmod_brute(mp_limb_t a, mp_limb_t p)
{
mp_limb_t t, t2;
if (a <= 1)
{
return a;
@fredrik-johansson
fredrik-johansson / gist:80aa4df800f7ee6b87f3
Last active August 29, 2015 14:05
chebyshev polynomial in nemo
function chebyshev_t_pair{S <: Ring}(n::Int, x::S)
if n == 0
return one(S), x
elseif n == 1
return x, one(S)
elseif n < 0
a, b = chebyshev_t_pair(1-n, x)
return b, a
elseif iseven(n)
a, b = chebyshev_t_pair(n>>1, x)
function exp{T <: Ring}(a::T)
a != 0 && error("Exponential of nonzero element")
return one(T)
end
function exp{T<: Ring, S}(a::PowerSeries{T, S})
if a == 0
return PowerSeries(PowerSeries{T, S}, [one(T)], a.prec)
elseif a.prec == nothing
error("Unable to compute exponential of infinite precision power series")
#include "acb_modular.h"
#include "profiler.h"
/* HLS algorithm from python's colorsys module */
static double vv(double m1, double m2, double hue)
{
hue = hue - floor(hue);
if (hue < 1/6.)
return m1 + (m2-m1)*hue*6.0;
@fredrik-johansson
fredrik-johansson / gist:327573e1aa39c6358fcb
Created June 14, 2015 09:04
ASOIAF according to char-rnn
Tyrion thought. Her mother slapped his gloved hands. "The direwolf to her father."
"The city," Jon said. "The led had his mother climbed up and always wanted so much even his place and pucked in the shadow of her grave. The dragons lined in the east, and she must in a woman and the cage.
"Maybe I should make the promises I shall look until the three-eyed man will be done. She ought to ride in the Summer Isles, and to him, but if the other burned that he had been
free of the keep."
"He was served to my husband when I was clever on the coat, but no more than her son?"
"You will believe a son of
Dorne."
"This is a time saying that you are four much than the wildling with down a good stones look for her own man."
"The dragons?"
"No, Your Grace," said Jaime. "A certain day that I would show her the man of us."
@fredrik-johansson
fredrik-johansson / stats.py
Created August 27, 2015 13:52
Python script to generate scrobbling stats page
# -*- coding: utf-8 -*-
import datetime
import matplotlib
import codecs
# history downloaded with lastexport.py https://gist.github.com/bitmorse/5201491
fp = codecs.open("tracks.txt", "r", "utf8")
albums = {}
sf2011 2.2148 ( 60136 / 27151.49)
sf2012 1.5506 ( 58373 / 37644.64)
sod 1.2943 ( 14345 / 11083.45)
ksutra 0.8053 ( 10215 / 12685.39)
hr2 0.7973 ( 10109 / 12679.42)
scythe 0.7924 ( 3379 / 4264.11)
av 0.7730 ( 10317 / 13346.92)
scythe2 0.7381 ( 6094 / 8256.14)
doom2 0.6963 ( 3540 / 5083.80)
doom 0.5851 ( 2907 / 4968.16)
/* This file is public domain. Author: Fredrik Johansson. */
/* complex_plot.c, hacked to render animation frames */
/* convert to video with: */
/* avconv -r 32 -i anim%04d.png -r 32 -c:v h264 -crf 1 test.flv */
#include <stdlib.h>
#include <string.h>
#include "acb.h"
#include "acb_hypgeom.h"
@fredrik-johansson
fredrik-johansson / zetanim.py
Created December 14, 2015 17:10
Root-finding animation script
"""
Animates output of
build/examples/real_roots 0 0 50 -verbose > outlog.txt
build/examples/real_roots 0 47 50 -verbose > outlog2.txt
assuming that the following hack of a patch has been applied to arb:
diff --git a/arb_calc/isolate_roots.c b/arb_calc/isolate_roots.c
index ac425fb..4981601 100644