Skip to content

Instantly share code, notes, and snippets.

View andrejbauer's full-sized avatar

Andrej Bauer andrejbauer

View GitHub Profile
@andrejbauer
andrejbauer / mandelbrot.c
Created December 11, 2013 22:23
A simple program for computing the Mandelbrot set.
/*
This program is an adaptation of the Mandelbrot program
from the Programming Rosetta Stone, see
http://rosettacode.org/wiki/Mandelbrot_set
Compile the program with:
gcc -o mandelbrot -O4 mandelbrot.c
Usage:
@andrejbauer
andrejbauer / wlem.agda
Last active June 19, 2023 04:40
A formal proof that weak excluded middle holds from the familiar facts about real numbers.
{-
Weak excluded middle states that for every propostiion P, either ¬¬P or ¬P holds.
We give a proof of weak excluded middle, relying just on basic facts about real numbers,
which we carefully state, in order to make the dependence on them transparent.
Some people might doubt the formalization. To convince yourself that there is no cheating, you should:
* Carefully read the facts listed in the RealFacts below to see that these are all
just familiar facts about the real numbers.
@andrejbauer
andrejbauer / example.agda
Last active April 20, 2023 08:30
Inductive trees in various proof assistants
open import Data.Nat
open import Data.Product
module example where
data SimpleTree (A : Set) : Set where
empty : SimpleTree A
leaf : A -> SimpleTree A
node : A -> SimpleTree A -> SimpleTree A -> SimpleTree A
@andrejbauer
andrejbauer / Epimorphism.agda
Last active January 26, 2023 20:44
A setoid satisfies choice if, and only if its equivalence relation is equality.
open import Level
open import Relation.Binary
open import Data.Product
open import Data.Unit
open import Agda.Builtin.Sigma
open import Relation.Binary.PropositionalEquality renaming (refl to ≡-refl; trans to ≡-trans; sym to ≡-sym; cong to ≡-cong)
open import Relation.Binary.PropositionalEquality.Properties
open import Function.Equality hiding (setoid)
module Epimorphism where
@andrejbauer
andrejbauer / Set2Bool.v
Created May 25, 2022 22:08
A proof in Coq that `Set -> bool` is not equal to `Set`.
Require Import Setoid.
Definition coerce {A B : Type} : A = B -> A -> B.
Proof.
intros [] a.
exact a.
Defined.
Lemma coerce_coerce {A B : Type} (e : A = B) (b : B) :
coerce e (coerce (eq_sym e) b) = b.
@andrejbauer
andrejbauer / README.md
Last active February 24, 2022 14:40
How to formulate and prove the statement "all functions are continuous" in an effectful functional language?

Are all functions continuous?

Mathematical background

Brouwer's statement "all functions are continuous" can be formulated without reference to topology as follows.

Definition: A functional f : (N → N) → N is continuous at a : N → N when there exists m : N such that, for all b : N → N, if ∀ k < m, a k = b k then f a = f b.

@andrejbauer
andrejbauer / Queue.agda
Last active September 1, 2021 23:23
An implementation of infinite queues fashioned after the von Neuman ordinals
open import Data.Nat
open import Data.Maybe
open import Data.Product
-- An implementation of infinite queues fashioned after the von Neuman ordinals
module Queue where
infixl 5 _⊕_
@andrejbauer
andrejbauer / Corey.agda
Created June 1, 2021 22:46
The type of bit streams is uncountable.
open import Data.Bool
open import Data.Empty
open import Agda.Builtin.Nat
open import Agda.Builtin.Sigma
open import Relation.Binary.PropositionalEquality
module Corey where
-- streams of bits
record Stream : Set where
@andrejbauer
andrejbauer / Graph.v
Last active April 7, 2021 19:35
Graph theory in Coq
(** An attempt to formalize graphs. *)
Require Import Arith.
(** In order to avoid the intricacies of constructive mathematics,
we consider finite simple graphs whose sets of vertices are
natural numbers 0, 1, , ..., n-1 and the edges form a decidable
relation. *)
(** We shall work a lot with statements of the form
@andrejbauer
andrejbauer / algebra.v
Last active March 12, 2021 06:34
Uinversal algebra in Coq
(* An initial attempt at universal algebra in Coq.
Author: Andrej Bauer <Andrej.Bauer@andrej.com>
If someone knows of a less painful way of doing this, please let me know.
We would like to define the notion of an algebra with given operations satisfying given
equations. For example, a group has of three operations (unit, multiplication, inverse)
and five equations (associativity, unit left, unit right, inverse left, inverse right).
*)