Skip to content

Instantly share code, notes, and snippets.

View dwarn's full-sized avatar

David Wärn dwarn

View GitHub Profile
@dwarn
dwarn / coind.agda
Created December 7, 2023 10:50
a trick for indexed corecursor in Cubical Agda
{-# OPTIONS --cubical --guardedness #-}
open import Cubical.Foundations.Everything
open import Cubical.Data.Sigma.Properties
-- We are given an indexed container.
module _
(Ix : Type)
(A : Ix → Type)
(B : (i : Ix) → A i → Type)
@dwarn
dwarn / Magic.agda
Created May 28, 2023 12:07
Truncation magic trick
{- A simple, general version of Kraus' magic trick, to recover truncated data. -}
{-# OPTIONS --cubical #-}
module Magic where
open import Cubical.Foundations.Everything
open import Cubical.HITs.PropositionalTruncation
-- Let A be an arbitrary type (not necessarily homogeneous).
module _ {ℓ : Level} {A : Type ℓ} where
-- Define a family of contractible types over A using contractibility of singletons.
@dwarn
dwarn / lawvere.lean
Created October 16, 2022 09:00
lawvere fixed point
import category_theory.closed.cartesian
noncomputable theory
open category_theory category_theory.limits tactic interactive interactive.types
def tidy_prod_helper {C} [category C] [has_binary_products C] {Γ X Y : C}
(h : Π Δ, (Δ ⟶ Γ) → (Δ ⟶ X) → (Δ ⟶ Y)) : X ⨯ Γ ⟶ Y :=
h (X ⨯ Γ) limits.prod.snd limits.prod.fst
import category_theory.closed.cartesian
noncomputable theory
open category_theory category_theory.limits tactic interactive interactive.types
lemma tidy_prod_helper {C} [category C] [has_binary_products C] {X Y Z : C}
(h : Π Γ, (Γ ⟶ X) → (Γ ⟶ Y) → (Γ ⟶ Z)) : X ⨯ Y ⟶ Z :=
h (X ⨯ Y) limits.prod.fst limits.prod.snd
import tactic.basic
/-- The states and moves of an infinite two-player game. -/
structure game :=
(angel_state devil_state : Type)
(angel_move : angel_state → set devil_state)
(devil_move : devil_state → set angel_state)
-- one could also define `angel_move : angel_state → Type`
-- and `next_state : Π {s}, angel_move s → devil_state`,
-- to allow the game to distinguish moves leading to the same state.
import order.ideal
/- Say a partial order `P` is directed complete, or a dcpo, if every directed subset in `P` has a
supremum (we actually work with ideals instead of general directed subsets, but every directed
subset is cofinal with an ideal so it doesn't matter). A morphism `P → Q` of dcpo's is a monotone
function which preserves suprema of directed subsets.
The main result of this file is that for any preorder `P`, `ideal P` is the free dcpo on `P`, in
the sense that any monotone funtcion `P → Q` where `Q` is a dcpo extends uniquely to a morphism
`ideal P → Q` of dcpo's. -/
@dwarn
dwarn / coproduct.lean
Created April 27, 2021 23:11
coproduct of groups as reduced words
import data.list.chain
section monoids
-- given a family of monoids, where both the monoids and the indexing set have decidable equality.
variables {ι : Type*} (G : Π i : ι, Type*) [Π i, monoid (G i)]
[decidable_eq ι] [∀ i, decidable_eq (G i)]
-- The coproduct of our monoids.
@[derive decidable_eq]
@dwarn
dwarn / ultra.lean
Created April 30, 2020 11:14
applicative ultrapower
import order.filter.filter_product
import category_theory.category.default -- for the `tidy` tactic
open filter filter.filter_product
noncomputable theory
/-- The ultrapower of a `Type`. -/
def upower (α : Type*) := filterprod α (@hyperfilter ℕ)
/-- We think of inhabitants of upower (α → β) as nonstandard functions internal