Skip to content

Instantly share code, notes, and snippets.

View andrejbauer's full-sized avatar

Andrej Bauer andrejbauer

View GitHub Profile
@andrejbauer
andrejbauer / kernel.ml
Created March 5, 2026 16:30
How to implement in OCaml a trusted kernel that can also expose its internal structure safely
(* We want to implement a trusted kernel which is the only module that can
produce values of some abstract type jdg, but at the same time we want to be
able to expose the values of type jdg so they can be inspected, tested, etc.
In some cases OCaml private types will do the job, but not always. Here is a
solution that uses OCaml modules. The idea is as follows:
1. Implement an untrusted transparent kernel which makes everything visible.
2. Using signatures, create a trusted opaque version of the transparent kernel
with an additional expose function that maps opaque values to non-opaque values.
@andrejbauer
andrejbauer / Ackermann.agda
Last active February 1, 2026 16:45
The definition of Ackermann function by double primitive recursion
module Ackermann where
open import Data.Nat
open import Relation.Binary.PropositionalEquality
-- Primitive recursion a la System T, for defining maps ℕ → τ for any type τ.
primrec : : Set} τ (ℕ τ τ) τ
primrec x f zero = x
primrec x f (suc m) = f m (primrec x f m)
-- In type theory we can show that ℕ and Bool are not equal as follows
module N≠Bool where
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Bool
open import Data.Sum
open import Data.Empty
@andrejbauer
andrejbauer / sheafify.v
Last active March 4, 2026 10:24
Sheafification with respect to a Lawvere-Tierney closure in logical form.
(* The basic theory of Lawvere-Tierney operators and sheafification in logical form.
This formalization is based on:
Barbara Veit: A proof of the associated sheaf theorem by means of categorical logic,
The Journal of Symbolic Logic , Volume 46 , Issue 1 , March 1981 , pp. 45–55
DOI: https://doi.org/10.2307/2273255
*)
Require Import Utf8.
@andrejbauer
andrejbauer / Myhill.hs
Last active April 29, 2025 13:13
A Haskell implementation of Myhill's isomorphism theorem
module Myhill where
import Data.List (find)
type N = Integer
-- given injective maps `f, g : N → N` that witness 1-1 reductions `A ≤₁ B` and `B ≤₁ A`, respectively,
-- `myhill f g` computes the graph of a bijection `h : N → N` that witnesses `A ≡ B`, see
-- https://en.wikipedia.org/wiki/Myhill_isomorphism_theorem
myhill :: (N -> N) -> (N -> N) -> [(N,N)]
@andrejbauer
andrejbauer / forcing.v
Last active December 22, 2024 14:35
The construction of the least closure operator that forces a given predicate to be true.
(* A proof that there is a least closure operator which forces a given
predicate to be true. The construction can be found in, e.g.,
Martin Hyland's “Effective topos” paper, Proposition 16.3. *)
(* A closure operator on [Prop] is an idempotent, monotone, inflationary enodmap.
One often requires additionally that the operator preserves conjunctions,
in which case these are also called j-operators and Lawvere-Tierney topologies.
We eschew the condition to obtain a slighly more general result, but we
also show that the closure operator of interst happens to preserve conjunctions.
@andrejbauer
andrejbauer / PropositionalCalculus.v
Created December 1, 2024 14:47
A formalization of a classical propositional calculus used in some questions and answers at ProofAssistants StackExchange
(* A formalization of a classical propositional calculus a la user4035,
see https://proofassistants.stackexchange.com/q/4443/169 and
https://proofassistants.stackexchange.com/q/4468/169 ,
with the following modifications:
1) We use a set of assumptions rather than a list of assumptions.
2) We use derivation trees to represent proofs instead of lists of formulas.
Proofs-as-lists are used in Hilbert-style systems, whereas
derivation trees are more common in natural-deduction style rules.
@andrejbauer
andrejbauer / Tarski.agda
Last active October 10, 2024 22:12
A predicative version of Tarski's fixed-point theorem.
-- A predicative version of Tarski's fixed-point theorem
open import Level
open import Data.Product
module Tarski where
-- a complete preorder with carrier at level a, the preorder is at level b,
-- and suprema indexed by sets from level c
record CompletePreorder a b c : Setω where
@andrejbauer
andrejbauer / README.md
Last active August 23, 2024 08:47
Playing around with Miquel's theorem
@andrejbauer
andrejbauer / LaTeX.inputplugin
Last active February 19, 2026 04:13
LaTeX symbols input method for MacOS
#
METHOD: TABLE
ENCODE: Unicode
PROMPT: LaTeX
VERSION: 1.0
DELIMITER: ,
VALIDINPUTKEY: ^,.?!:;"'/\()[]{}<>$%&@*01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
TERMINPUTKEY:
BEGINCHARACTER
alpha α