Skip to content

Instantly share code, notes, and snippets.

View jozefg's full-sized avatar

daniel gratzer jozefg

View GitHub Profile
@jozefg
jozefg / halt.jonprl
Last active August 31, 2015 21:03
A proof that the halting problem is undecidable in JonPRL
||| The proof of the halting problem here is pretty much
||| what you would expect, we apply the standard diagonalization
||| trick to prove that if we have a halting oracle there is a
||| program which both does and doesn't terminate.
Operator dec : (0).
[dec(M)] =def= [plus(M; not(M))].
Theorem has-value-wf : [{A : base} member(has-value(A); U{i})] {
unfold <has-value>; auto
Operator P : (0).
[P(N)] =def= [natrec(N; unit; _._.void)].
Theorem one-not-zero : [not(=(zero; succ(zero); nat))] {
auto;
assert [P(succ(zero))];
aux {
unfold <P>; hyp-subst ← #1 [h.natrec(h; _; _._._)];
reduce; auto
};
@jozefg
jozefg / russell.jonprl
Last active August 29, 2015 14:27
A proof that Type cannot be of type Type in JonPRL.
Operator Russell : ().
[Russell] =def= [{x : U{i} | not(member(x; x))}].
Tactic break-plus {
@{ [x : _ + _ |- _] => elim <x> }
}.
Theorem u-in-u-wf : [member(member(U{i}; U{i}); U{i'})] {
unfold <member>; eq-eq-base; unfold <bunion>; auto;
csubst [ceq(U{i}; lam(x.snd(x)) pair(inr(<>); U{i}))]
@jozefg
jozefg / conat.jonprl
Last active August 29, 2015 14:24
conats in JonPRL built from nats and \bigcap
Operator iterate : (0; 1; 0).
[iterate(N; F; B)] =def= [natrec(N; B; _.x.so_apply(F; x))].
Operator top : ().
[top] =def= [⋂(void; _.void)].
Theorem top-is-top :
[⋂(base; x.
⋂(base; y.
=(x; y; top)))] {
@jozefg
jozefg / j-to-j.agda
Created June 23, 2015 21:01
Deriving a nicer induction principle for equality
{-# OPTIONS --without-K #-}
module j-to-j where
open import Level
-- Gives rise to the annoying induction principle.
data _≡_ {A : Set} : A → A → Set where
refl : ∀ {a : A} → a ≡ a
-- Ignore the "Level" junk in here. It's needed because
-- we're trying to eliminate into a Set1 (U1 in Peter's
@jozefg
jozefg / binary.agda
Created June 12, 2015 14:06
Binary trees ala How To Keep Your Neighbors in Order
open import Level
open import Relation.Nullary
open import Relation.Binary
module binary (ord : DecTotalOrder zero zero zero) where
A = DecTotalOrder.Carrier ord
open DecTotalOrder {{...}}
module bound where
@jozefg
jozefg / general.agda
Created June 8, 2015 21:38
Fun with McBride's General monad
module general where
open import Function
import Data.Nat as N
import Data.Fin as F
import Data.Maybe as M
import Relation.Nullary as R
data General (S : Set)(T : S -> Set)(X : Set) : Set where
!! : X -> General S T X
_??_ : (s : S) -> (T s -> General S T X) -> General S T X
@jozefg
jozefg / who-imports.py
Last active August 29, 2015 14:21
A quick script to plot which Haskell libs I import
#! /usr/bin/env python3
import os
import os.path as path
import re
import collections
from ascii_graph import Pyasciigraph
import sys
imports_re = re.compile('^import (qualified )?([a-z\.A-Z0-9]+)')
@jozefg
jozefg / regex.agda
Created May 7, 2015 03:38
Regex matcher
module regex where
open import Data.Char using (Char; _≟_)
open import Data.List using (List ; _∷_ ; [])
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Data.Empty using (⊥)
-- Reason for this is because it simplifies pattern matching.
String : Set
String = List Char
@jozefg
jozefg / Bracket.hs
Created May 3, 2015 00:19
A conversion from Lambda Calculus to SK calculus
module Bracket where
data Lam = Var Int | Ap Lam Lam | Lam Lam deriving Show
data SK = S | K | SKAp SK SK deriving Show
data SKH = Var' Int | S' | K' | SKAp' SKH SKH
-- Remove one variable
bracket :: SKH -> SKH
bracket (Var' 0) = SKAp' (SKAp' S' K') K'