Skip to content

Instantly share code, notes, and snippets.

View andrejbauer's full-sized avatar

Andrej Bauer andrejbauer

View GitHub Profile
@andrejbauer
andrejbauer / algebraic.py
Created August 14, 2019 12:47
Pictures of algebraic numbers
#!/usr/local/bin/python3
# Compute algebraic numbers in the complex plane and draw a nice picture
import numpy
import sys
import argparse
import math
import cairo
import pickle
@andrejbauer
andrejbauer / LaTeX.inputplugin
Last active March 24, 2024 09:29
LaTeX symbols input method for MacOS
#
METHOD: TABLE
ENCODE: Unicode
PROMPT: LaTeX
VERSION: 1.0
DELIMITER: ,
VALIDINPUTKEY: ^,.?!:;"'/\()[]{}<>$%&@*01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
TERMINPUTKEY:
BEGINCHARACTER
alpha α
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andrejbauer
andrejbauer / example.m31
Last active February 19, 2024 09:02
Example of Andromeda ML-programming
(* In Andromeda everything the user writes is "meta-level programming. *)
(* ML-level natural numbers *)
mltype rec mlnat =
| zero
| succ of mlnat
end
(* We can use the meta-level numbers to define a program which computes n-fold iterations
of f. Here we give an explicit type of iterate because the ML-type inference cannot tell
@andrejbauer
andrejbauer / AgdaSolver.agda
Last active February 4, 2024 11:34
How to use Agda ring solvers to prove equations?
{- Here is a short demonstration on how to use Agda's solvers that automatically
prove equations. It seems quite impossible to find complete worked examples
of how Agda solvers are used.
Thanks go to @anormalform who helped out with these on Twitter, see
https://twitter.com/andrejbauer/status/1549693506922364929?s=20&t=7cb1TbB2cspIgktKXU8rng
I welcome improvements and additions to this file.
This file works with Agda 2.6.2.2 and standard-library-1.7.1
@andrejbauer
andrejbauer / Primrec.agda
Created July 6, 2021 10:21
Primitive recursive functions in Agda
open import Data.Nat
open import Data.Fin as Fin
module Primrec where
-- The datatype of primitive recursive function
data PR : ∀ (k : ℕ) → Set where
pr-zero : PR 0 -- zero
pr-succ : PR 1 -- successor
pr-proj : ∀ {k} (i : Fin k) → PR k -- projection
@andrejbauer
andrejbauer / MPimpliesPost.v
Created December 3, 2023 09:26
Markov's principle implies Post's theorem, constructively.
(* Post's theorem in computability theory states that a subset S ⊆ ℕ is
decidable if both S and its complement ℕ \ S are semidecidable.
Just how much classical logic is needed to prove the theorem, though?
In this note we show that Markov's principle suffices.
Rather than working with subsets of ℕ we work synthetically, with
semidecidable and decidable truth values. (This is more general than
the traditional Post's theorem.)
*)
@andrejbauer
andrejbauer / Bijection.md
Last active November 29, 2023 22:05
A bijection between numbers and pairs of numbers.

A bijection between numbers and pairs of numbers

Every once in a while I am faced with someone who denies that the rational numbers (or fractions, or pairs of integers) can be put into a bijective correspondence with natural numbers. To deal with the situation, I coded up the bijection. So now I can just say: "Really? Interesting. Please provide a pair of numbers (i,j) which is not enumerated by f, as defined in my gist." I am still waiting for a valid counter-example.

Anyhow, here is a demo of f and g at work. I am using the Python version, but a Haskell variant is included as well.

The 100-th pair is:

>>> f(100)

(10, 4)

@andrejbauer
andrejbauer / topology.v
Last active November 28, 2023 19:40
How to get started with point-set topology in Coq. This is not actually how one would do it, but it is an intuitive setup for a classical mathematician.
(* How do to topology in Coq if you are secretly an HOL fan.
We will not use type classes or canonical structures because they
count as "advanced" technology. But we will use notations.
*)
(* We think of subsets as propositional functions.
Thus, if [A] is a type [x : A] and [U] is a subset of [A],
[U x] means "[x] is an element of [U]".
*)
Definition P (A : Type) := A -> Prop.
@andrejbauer
andrejbauer / ZF.v
Created November 8, 2023 00:56
Minimalist formalization of first-order signatures, logic, theories and models. As an example, we formalize a small fragment of ZF set theory.
(*
A formalization of first-order logic, theories and their models.
As an example we formalize the language of ZF set theory and a a small fragment of ZF.
*)
(* A signature is given by function symbols, relation symbols, and their arities. *)
Structure Signature :=
{ funSym : Type (* names of function symbols *)
; funArity : funSym -> Type (* arities of function symbols *)
; relSym : Type (* names of relation symbols *)