Skip to content

Instantly share code, notes, and snippets.

View Kha's full-sized avatar

Sebastian Ullrich Kha

View GitHub Profile
@Kha
Kha / AesopSort.lean
Last active June 27, 2022 11:08
Lean 4 port of [Proving insertion sort correct easily in Coq](https://gist.github.com/siraben/3fedfc2c5a242136a9bc6725064e9b7d) using https://github.com/JLimperg/aesop
import Aesop
variable [LE α] [DecidableRel ((· ≤ ·) : α → α → Prop)]
@[aesop safe constructors]
inductive Sorted : List α → Prop where
| nil : Sorted []
| single : Sorted [x]
| cons_cons : x ≤ x' → Sorted (x' :: xs) → Sorted (x :: x' :: xs)
@Kha
Kha / Calc.lean
Last active March 3, 2021 09:07
Extensible, typeclass-driven `calc` in Lean 4
class Trans (r : α → β → Prop) (s : β → γ → Prop) (t : outParam (α → γ → Prop)) where
trans : r a b → s b c → t a c
export Trans (trans)
instance (r : α → γ → Prop) : Trans Eq r r where
trans heq h' := heq ▸ h'
instance (r : α → β → Prop) : Trans r Eq r where
trans h' heq := heq ▸ h'
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import data.set.finite
-- we don't need no infinite sets here
open finset
open function
-- `fin n` is the type of the first `n` natural numbers
theorem pigeonhole (n m : ℕ) (f : fin n → fin m) : n > m → ¬(injective f) :=
assume : n > m,
-- proof of negation: show contradiction
section
universe u
parameters (α β : Type u) (op : α → β → Prop)
structure chained_op_val :=
(left : α)
(right : β)
(val : Prop)
instance coe_chained_op_val : has_coe chained_op_val Prop :=
namespace nqueens
open nat
class lt (n : out_param ℕ) (m : ℕ)
instance succ_lt_succ_of_lt (n m) [lt n m] : lt (succ n) (succ m) := by constructor
instance zero_lt_succ (m) : lt 0 (succ m) := by constructor
class ne (n m : ℕ)
instance ne_of_lt (n m) [lt n m] : ne n m := by constructor
instance ne_of_gt (n m) [lt m n] : ne n m := by constructor
import data.int.basic
import data.int.order
open bool
open int
open eq.ops
-- 1
abbreviation Var := string
public class MatchVariants : TowerFall.MatchVariants
{
public Variant NoHeadBounce;
}
public class Player : TowerFall.Player
{
public override void BouncedOn(TowerFall.Player bouncer)
{
if (!((MatchVariants)Level.Session.MatchSettings.Variants).NoHeadBounce)
@Kha
Kha / client.py
Created June 2, 2013 11:22
khaderp, the Rocket Scissors Spacegoo bruteforce bot
import socket, json
import random, pprint
import sys
import math
import re
class arith_list(list):
def __add__(self, other):
return arith_list([x + y for x, y in zip(self, other)])
@Kha
Kha / heap_rec.py
Created January 20, 2013 01:26
Minimally invasive function for heap recursion
def heap_rec(f):
stack = [f]
result = None
while stack:
try:
stack.append(stack[-1].send(result))
result = None
except StopIteration as ex:
result = ex.value
stack.pop()