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: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."
#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;
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")
@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)
#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: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 ;}
@fredrik-johansson
fredrik-johansson / gist:8198480
Created December 31, 2013 15:36
mpir/gmp exp(1) benchmark
#include <stdio.h>
#include <math.h>
#include "gmp.h"
#include "time.h"
#define ulong unsigned long
void
mpz_bsplit(mpz_t p, mpz_t q, ulong a, ulong b)
{
if (b - a == 1)
@fredrik-johansson
fredrik-johansson / gist:8198432
Created December 31, 2013 15:33
bsdnt exp(1) benchmark program
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "nn.h"
#include "test.h"
#include "zz.h"
void
zz_bsplit(zz_t p, zz_t q, ulong a, ulong b)
@fredrik-johansson
fredrik-johansson / numerical integration
Created October 3, 2013 13:27
example code for numerical integration
#include "fmpcb_calc.h"
#include "profiler.h"
int
sinx(fmpcb_ptr out, const fmpcb_t inp, void * params, long order, long prec)
{
int xlen = FLINT_MIN(2, order);
fmpcb_set(out, inp);
if (xlen > 1)
fmpcb_one(out + 1);
@fredrik-johansson
fredrik-johansson / gist:6102998
Created July 29, 2013 08:40
100000 digits of rho_1, decimal approximation
14.1347251417346937904572519835624702707842571156992431756855674601499634298092567649490103931715610127792029715487974367661426914698822545825053632394471377804133812372059705496219558658602005555667258360107737002054109826615075427805174425913062544819786510723049387256297383215774203952157256748093321400349904680343462673144209203773854871413783173563969953654281130796805314916885290678208229804926433866673462332007875876179200560486805435680144442465106559756866590322868651054485944432062407272703209427452221304874872092412385141835146054279015244783383542545334400448793680676169730081900073139385498373621501304516726968389200391762851232128542205239691334258322753351640601697635275637589695376749203361272092599917304270756830879511844534891800863008264831251691127106829105237596179774318151707135453167754951538289378490364747097270199484855322092535743579092261252477365955180169752334612139773160053541259267474557258778014726098308089786007125320875093959979666606753783812148919088649772775544206565320524