Skip to content

Instantly share code, notes, and snippets.

View jakobrs's full-sized avatar

Jakob Rødal Skaar jakobrs

View GitHub Profile
@jakobrs
jakobrs / gentzen.lean
Last active May 14, 2025 14:46
Partial implementation of stupid Gentzen proof search
import Mathlib.Data.Multiset.Basic
import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Data.Multiset.MapFold
inductive Wff
| var (name : String)
| imp (a b : Wff)
| not (a : Wff)
| or (a b : Wff)
def List.instMonad : Monad List where
pure x := [x]
bind := List.flatMap
def List.guard : Bool -> List Unit
| false => []
| true => [()]
declare_syntax_cat comprRule
@jakobrs
jakobrs / gist:40deb8a32494c47442c35ed83bc7f88a
Created October 21, 2024 10:52
All Lean names containing `i`
This file has been truncated, but you can view the full file.
IO
Id
id
Div
EIO
Fin
Fix
Iff
Inf
Int
#include <functional>
#include <iostream>
#include <memory>
#include <optional>
#include <variant>
template <typename T> struct Thunk {
std::variant<T, std::function<T()>> contents;
Thunk(const T &val) : contents{val} {}
@jakobrs
jakobrs / bindings.cpp
Last active July 11, 2024 13:31
not as broken tun bindings for lean
#include <lean/lean.h>
#include <cstring>
#include <fcntl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <string>
#include <sys/ioctl.h>
#include <unistd.h>
{-# LANGUAGE GHC2021 #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NoFieldSelectors #-}
import Data.Function ((&))
import Data.Functor.Identity (Identity (..))
import Data.Monoid (Endo (..), Sum (..))
{-# LANGUAGE ViewPatterns #-}
import Control.Monad (forM_)
import Control.Monad.ST (ST)
import Data.Functor ((<&>))
import Data.Monoid (Endo (..))
import Data.STRef (STRef, newSTRef)
import Data.Vector qualified as V
import Data.Vector.Generic.Mutable qualified as GV
import Data.Vector.Mutable qualified as MV
import Data.Ratio
-- Q5 = Q(sqrt(5))
data Q5 = Q5 Rational Rational deriving (Show, Eq)
instance Num Q5 where
fromInteger n = Q5 (fromInteger n) 0
Q5 a b + Q5 c d = Q5 (a + c) (b + d)
Q5 a b * Q5 c d = Q5 (a * c + 5 * b * d) (a * d + b * c)
negate (Q5 a b) = Q5 (-a) (-b)
// #define USE_BITS_STDCPP
// #define USE_RARE_HEADERS
#ifdef USE_BITS_STDCPP
#include <bits/stdc++.h>
#endif
#include <algorithm>
#include <array>
#include <iostream>
@jakobrs
jakobrs / main.cpp
Last active May 22, 2024 14:24
vEB tree based on CLRS 3rd edition
#include "veb.hpp"
#include <iostream>
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
assert((1 << 18 > 200'001));
int q;
std::cin >> q;