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 / qqbar_example.c
Created May 14, 2026 00:42
Example program (generated by Claude)
/*
* Demonstration of qqbar_sgn_re from FLINT.
*
* We construct three sums of nontrivial complex algebraic numbers whose
* real parts are negative, zero, and positive respectively, using roots
* of unity via qqbar_root_of_unity(res, p, q) = exp(2*pi*i * p/q).
*
* Example 1 (negative):
* zeta_3 + zeta_3^2 = e^(2pi*i/3) + e^(2pi*i*2/3)
* Each summand is a primitive cube root of unity with Re = -1/2.
@fredrik-johansson
fredrik-johansson / polymul.c
Created April 28, 2026 12:11
SIMD + Karatsuba polynomial multiplication experiments
#define _POSIX_C_SOURCE 199309L
#include <immintrin.h>
#include "profiler.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "nmod.h"
void n_poly_mul_n_classical(ulong * c, const ulong * a, const ulong * b, slong n)
{
#include <pthread.h>
#include <stdio.h>
#include <stdint.h>
#include "flint.h"
#include "ulong_extras.h"
#include "profiler.h"
#include "thread_support.h"
#define NUM_PSEUDOPRIMES 31894014
@fredrik-johansson
fredrik-johansson / padic.c
Created October 29, 2025 14:17
p-adic draft
#include "padic.h"
#include "nmod.h"
#include "gr.h"
typedef struct
{
ulong p;
slong n;
nmod_t p_mod;
#include "ulong_extras.h"
#include "nmod.h"
#include "fmpz.h"
#include "thread_support.h"
#define N_FAST1 UWORD(1000000)
#define N_FAST2 UWORD(100000000)
#define N_SLOW UWORD(10000000000000000000)
ulong * tab1;
@fredrik-johansson
fredrik-johansson / ball.tex
Created January 21, 2025 12:13
ball bearing
\documentclass[tikz,border=0.3mm]{standalone}
\usepackage{tikz,ifthen}
\usepackage{contour}
\usepackage{arrayjob}
\begin{document}
\begin{tikzpicture}[scale=2.5, every node/.style={transform shape}, every draw/.style={transform shape}]
\definecolor{gray55} {HTML}{555555}
\definecolor{gray44} {HTML}{444444}
#include "gr.h"
#include "arf.h"
#include "mpn_extras.h"
#include "crt_helpers.h"
typedef struct
{
slong sign;
slong exp;
mp_limb_t d[4];
@fredrik-johansson
fredrik-johansson / taylortest.c
Created March 7, 2024 19:54
Taylor experiment
#include <math.h>
#include "longlong.h"
#include "ulong_extras.h"
#include "mpn_extras.h"
#include "arf.h"
#include "arb.h"
#include "profiler.h"
/* util: print fixed-point number given by n limbs where fracn limbs are fractional. */
void
#include <stdint.h>
#include "profiler.h"
#include "mpn_extras.h"
#include "crt_helpers.h"
#include "ulong_extras.h"
FLINT_FORCE_INLINE mp_limb_t
flint_mpn_inline_addmul_1(mp_ptr res, mp_srcptr a, mp_size_t n, mp_limb_t c)
{
mp_limb_t hi, lo, cy_limb;
@fredrik-johansson
fredrik-johansson / addmul1.c
Last active December 8, 2023 22:24
mpn instrinsics
#include <x86intrin.h>
#include "flint.h"
#include "longlong.h"
#include "ulong_extras.h"
#include "mpn_extras.h"
#include "profiler.h"
#define umul_ppmm_mulx(w1, w0, u, v) \
__asm__ ("mulx\t%3, %q0, %q1" \
: "=r" (w0), "=r" (w1) \