Skip to content

Instantly share code, notes, and snippets.

@axionbuster
axionbuster / smawk.zig
Last active September 26, 2025 17:41
The SMAWK algorithm
// The SMAWK algorithm for finding row minima of a totally monotone matrix,
// based on the notes:
// - "Advanced Dynamic Programming," https://courses.grainger.illinois.edu/cs473/sp2016/notes/06-sparsedynprog.pdf
// - Larmore, L.L.; and UNLV, "The SMAWK Algorithm."
//
// COPYRIGHT (c) 2025 by YuJin Kim <axionbuster@gmail.com>.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
@axionbuster
axionbuster / Zipper.hs
Created August 16, 2025 06:56
Easy nonrecursive list zipper
{-# LANGUAGE ParallelListComp #-}
module Data.Zipper (zipper) where
import Data.List
import qualified Data.List.NonEmpty as NE
-- helper
dropLast :: [a] -> [a]
dropLast = maybe [] fst . unsnoc
@axionbuster
axionbuster / geometric.hs
Last active July 30, 2025 03:53
Fast modular geometric sum
-- https://stackoverflow.com/a/9486650 (no relation with author)
import Control.Monad
import Data.Foldable
import GHC.Natural
import Prelude hiding (exp)
import Text.Printf
type N = Natural
@axionbuster
axionbuster / egglog-ai-coprocessor-vision.md
Created July 26, 2025 08:03
Egglog as an AI coprocessor notes

Egglog as an AI Co-Processor: A Comprehensive Vision

Foreword

This document represents the culmination of extensive research and discussion about egglog's potential role in AI systems. Through multiple conversations spanning several models and research phases, we've evolved from viewing egglog as a database-like tool to understanding it as a specialized symbolic reasoning co-processor for AI agents.

The central insight that emerged is treating egglog not as a competitor to LLMs on general intelligence, but as what the x87 math co-processor was to x86 CPUs - a specialized accelerator for symbolic reasoning tasks that neural approaches handle poorly. This vision positions egglog at the intersection of algebraic effects, equality saturation, and AI agent verification.

Executive Summary

@axionbuster
axionbuster / Main.hs
Last active July 7, 2025 01:26
Existential Type Classes 2
{-# LANGUAGE GADTs, UndecidableInstances #-}
-- | Demonstration of existential multiple dictionary passing
--
-- - Synopsis: You can check if an unknown type 't' implements
-- a type class 'c'.
-- - Restriction: This is implemented using a simple linear
-- search.
-- - Restriction 2: Haskell's type classes are inherently open.
-- To get around logical unsoundness, one must fully specify
@axionbuster
axionbuster / Main.hs
Created July 6, 2025 23:26
POC: Existentially-quantified type classes
-- | Demonstration of an existentially-qualified type class
module Main (main) where
import Data.Constraint (Dict (Dict)) -- constraints
import Data.Kind (Type, Constraint) -- base
-- A variant that contains a constraint and a term of unknown type.
data Z (c :: Type -> Constraint)
= forall t. ZY (Dict (c t)) t
| forall t. ZN t
@axionbuster
axionbuster / Hilbert3D.hs
Last active March 17, 2025 17:04
Efficient 3D Hilbert Curve Generation and Inverse (GHC Haskell, GHC 9.8.1+)
{-# LANGUAGE BlockArguments, MagicHash, UnboxedTuples #-}
{-# LANGUAGE ExtendedLiterals, NoImplicitPrelude, ViewPatterns #-}
-- | Convert between 3D Hilbert curve coordinates and distance.
--
-- The chosen curve goes from (0,0,0) to (1,0,0) to (1,0,1)
-- for the first three points (listed in x,y,z order).
module Data.Hilbert3D (hils, hils#, shil, shil#) where
import GHC.Base (($))
@axionbuster
axionbuster / hilbert.c
Last active March 17, 2025 14:56
Efficient 3D Hilbert Curve Generation and Inverse (C99)
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h>
#pragma intrinsic(_BitScanReverse)
#endif // intrin.h for _BitScanReverse
// Algorithm is from "Algorithms for Encoding and Decoding 3D Hilbert Orderings"
// by David Walker, U. Tennessee at Chattanooga. Aug 2023.
typedef uint8_t C;
@axionbuster
axionbuster / Lib.hs
Last active December 21, 2024 03:39
Grid ray marching with floating-point error compensation
-- | march along a line segment, finding all intersections with grid points
module Lib (march) where
import Control.Monad.Fix
import Control.Monad.ST.Lazy
import Data.Functor
import Data.Functor.Rep
import Data.STRef.Lazy
import Prelude hiding (read)
@axionbuster
axionbuster / TYPEDHOL.TXT
Created December 5, 2024 00:31
TYPEDHOL.TXT
craftus-executables> /home/asdf/p/craftus/craftus-executables/app/Demo2/Play.hs:70:10: error: [GHC-88464]
craftus-executables> • Found hole: _what :: m a0
craftus-executables> Where: ‘a0’ is an ambiguous type variable
craftus-executables> ‘m’ is a rigid type variable bound by
craftus-executables> the type signature for:
craftus-executables> play0 :: forall (m :: * -> *).
craftus-executables> MonadPatternGeneral m =>
craftus-executables> JPlayer -> JWorld -> m ()
craftus-executables> at app/Demo2/Play.hs:43:1-61
craftus-executables> Or perhaps ‘_what’ is mis-spelled, or not in scope