Skip to content

Instantly share code, notes, and snippets.

View bollu's full-sized avatar

Siddharth bollu

View GitHub Profile
@bollu
bollu / graded1.hs
Created December 22, 2020 16:46 — forked from emilypi/graded1.hs
Graded semigroups/monoids/groups - two versions
{-# language FlexibleInstances #-}
{-# language DefaultSignatures #-}
{-# language RankNTypes #-}
{-# language MultiParamTypeClasses #-}
{-# language QuantifiedConstraints #-}
module Data.Group.Graded where
import Data.Functor.WithIndex
import Data.Group
import Data.Map (Map)
@bollu
bollu / flows-problems.txt
Created October 27, 2020 15:31 — forked from anurudhp/flows-problems.md
Collection of problems on flows
http://codeforces.com/problemset/problem/628/F
http://codeforces.com/gym/100729 : Problem F
http://codeforces.com/gym/100517 : Problem H
http://codeforces.com/gym/101128 : Problem F
http://codeforces.com/gym/100491 : Problem A
http://codeforces.com/gym/101175 : Problem D (WF)
http://codeforces.com/gym/101221 : Problem I (WF)
http://codeforces.com/gym/100800 : Problem A
http://codeforces.com/gym/101239 : Problem C (WF)
http://codeforces.com/gym/101208 : Problem C (WF)
[11:48 PM] Goose: OK I finished the epilogue
[11:54 PM] cantordust: Mm, right, so now it's time to read the webpage
[11:54 PM] cantordust: https://www.gregegan.net/DICHRONAUTS/DICHRONAUTS.html
Dichronauts — Greg Egan
Illustrations for Dichronauts by Greg Egan
[11:54 PM] Goose: I am reading the webpage already. :stuck_out_tongue:
[11:54 PM] cantordust: There's basically an entire treatise :stuck_out_tongue:
[11:54 PM] Goose: I am going through it right now.
[11:54 PM] cantordust: man nice, he has the same thing for incandescence which is about SR/GR
[11:54 PM] cantordust: https://www.gregegan.net/INCANDESCENCE/Incandescence.html#CONTENTS
@bollu
bollu / nanpun.cpp
Created August 22, 2020 13:11
Use NaN punning to box an int32_t and a double together
#include <assert.h>
#include <iostream>
#include <limits>
using namespace std;
#define INT32_TAG 0xfffffffe
// https://github.com/WebKit/webkit/blob/950143da027e80924b4bb86defa8a3f21fd3fb1e/Source/JavaScriptCore/runtime/JSCJSValueInlines.h
// https://github.com/WebKit/webkit/blob/950143da027e80924b4bb86defa8a3f21fd3fb1e/Source/JavaScriptCore/runtime/JSCJSValue.h
// https://en.wikipedia.org/wiki/NaN
union PunDouble {
double d;
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-- | to define <*> in terms of monad.
import Control.Monad (ap)
import Control.Category
import GHC.Types (Int, Float)
import GHC.Float
import GHC.Real hiding (fromIntegral, floor, Real)
import qualified GHC.Real
import GHC.Num
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-- | to define <*> in terms of monad.
import Control.Monad (ap)
import Control.Category
import GHC.Types (Int, Float)
import GHC.Float
import GHC.Real hiding (fromIntegral, floor, Real)
import qualified GHC.Real
import GHC.Num
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-- | to define <*> in terms of monad.
import Control.Monad (ap)
import Control.Category
import GHC.Types (Int, Float)
import GHC.Float
import GHC.Real hiding (fromIntegral, floor, Real)
import qualified GHC.Real
import GHC.Num
@bollu
bollu / localization-intuition-sage.py
Created August 1, 2020 07:39
Code to compute localization in SAGE of Z/nZ at a particular choice of multiplicative subset S = { s0^i }
import itertools
# check all pairs (a, c in R | b, d in S):
# (a/b) ~ (c/d)
# check exists e in S: (ad - bc)e = 0
R = IntegerModRing(10)
S = []
s0 = R(6)
for i in range(0, 10000):
@bollu
bollu / tardis-reverse-mode.hs
Created April 13, 2020 16:06
Using tardis for elegant reverse mode AD
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE DeriveFunctor #-}
import Control.Monad
import Control.Monad.Fix
data T fix f bix b a = T { runt :: (fix -> f, bix -> b) -> (a, fix -> f, bix -> b) } deriving(Functor)
instance Applicative (T fix f bix b) where pure = return; (<*>) = ap
instance Monad (T fix f bix b) where
return x = T $ \ ~(f, b) -> (x, f, b)
tx >>= x2ty = T $ \ ~(f, b) ->
#!/usr/bin/env python3
# The Category of M-sets
# M. Mehdi Ebrahimi and M. Mahmoudi
# Department of Mathematics
# Shahid Beheshti University
# Tehran 19839, Iran
class FinSet(set):
def __init__(self, s = ()):
set.__init__(self, s)