Skip to content

Instantly share code, notes, and snippets.

View cppio's full-sized avatar

Parth Shastri cppio

View GitHub Profile
@cppio
cppio / Hurkens.agda
Created May 30, 2025 17:09
Girard-Hurkens paradox in Agda
{-# OPTIONS --rewriting --confluence-check #-}
module Hurkens where
open import Agda.Builtin.Equality
import Agda.Builtin.Equality.Rewrite
postulate
Π₁ : (Set₁ → Set₁) → Set₁
λ₁ : ∀ {F} → (∀ A → F A) → Π₁ F
@cppio
cppio / NoEmbedding.lean
Created May 27, 2025 12:03
Lean proof that higher universes don't embed into lower ones.
inductive Tree : Sort (max (u + 1) v)
| node {A : Sort u} (c : A → Tree)
theorem no_embedding
(Lower : Sort (max (u + 1) v) → Sort u)
(down : ∀ {α}, α → Lower α)
(up : ∀ {α}, Lower α → α)
(up_down : ∀ {α} (x : α), x = up (down x))
: False := by
induction h : Tree.node up
opaque f : Nat → Nat
opaque g : Nat → Nat → Nat
inductive T : Nat → Type
| mk₁ x : T (f x)
| mk₂ x y : T (g x y)
theorem hcongrArg₂ {α : Sort u} {β : α → Sort v} {γ : ∀ a, β a → Sort w} (f : ∀ a b, γ a b) {a₁ a₂ : α} (ha : a₁ = a₂) {b₁ : β a₁} {b₂ : β a₂} (hb : HEq b₁ b₂) : HEq (f a₁ b₁) (f a₂ b₂) :=
by cases ha; cases hb; rfl
inductive Le (x : Nat) : (y : Nat) → Prop
| refl : Le x x
| step : Le x y → Le x y.succ
inductive Ge (x : Nat) : (y : Nat) → Prop
| refl : Ge x x
| step : Ge x y.succ → Ge x y
inductive Le' : (x y : Nat) → Prop
| zero : Le' .zero y
import Lean.Elab.Command
elab tk:"#show " "macro " i:ident : command => do
let key ← Lean.Elab.Command.liftCoreM do Lean.Elab.realizeGlobalConstNoOverloadWithInfo i
let env ← Lean.getEnv
let names := Lean.Elab.macroAttribute.getEntries env key |>.map (·.declName)
Lean.logInfoAt tk (.joinSep names Lean.Format.line)
elab tk:"#show " "term_elab " i:ident : command => do
let key ← Lean.Elab.Command.liftCoreM do Lean.Elab.realizeGlobalConstNoOverloadWithInfo i
@cppio
cppio / ansi.py
Created January 5, 2025 22:34
ANSI escape codes in Python
from collections import namedtuple
colors = namedtuple("colors", "black red green yellow blue magenta cyan white default")(0, 1, 2, 3, 4, 5, 6, 7, 9)
brightcolors = namedtuple("brightcolors", "black red green yellow blue magenta cyan white")(60, 61, 62, 63, 64, 65, 66, 67)
color = namedtuple("color", "r g b")
del namedtuple
def ansi(*, bold=None, underlined=None, inverse=None, foreground=None, background=None):
params = []
if bold is not None:
␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟
␠!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~␡
def foo : x = y → Bool := Eq.rec true
theorem bar : False = PEmpty := propext ⟨False.elim, PEmpty.elim⟩
theorem baz : Quot.mk (fun _ _ => True) false = Quot.mk _ true := Quot.sound trivial
theorem qux : foo h = true := h.rec (motive := fun _ h => h.rec true = true) rfl
example : foo bar = true := rfl
example : foo baz = true := rfl
example : foo bar = true := qux
example : foo baz = true := qux
def cantor_sur (f : α → (α → Prop)) : { g // ∀ x, g ≠ f x } :=
⟨fun x => ¬f x x, fun x h => not_iff_self <| iff_of_eq <| congrFun h x⟩
def cantor_inj (f : (α → Prop) → α) : { g // ¬(∀ {h}, f g = f h → g = h) } :=
let g x := ∀ h, x = f h → ¬h x
⟨g, fun inj => @not_iff_self (g (f g)) ⟨fun p _ q => inj q ▸ p, fun p => p g rfl⟩⟩
namespace NonStrictlyPositiveInductive
unsafe inductive T
variable {α : Sort u} (r : α → α → Prop)
inductive EqvClos a : α → Prop
| refl : EqvClos a a
| step : r b c → EqvClos a b → EqvClos a c
| unstep : r b c → EqvClos a c → EqvClos a b
variable {r}
def Quot.exact (h : mk r a = mk r b) : EqvClos r a b :=