Skip to content

Instantly share code, notes, and snippets.

View siraben's full-sized avatar

Ben Siraphob siraben

View GitHub Profile
@siraben
siraben / Verif_xor_swap.v
Last active July 16, 2021 05:16
Formal verification of XOR swap in C
Require Import VST.floyd.proofauto.
Require Import VST.floyd.library.
Require Import xor_swap.
Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
(* Specification of xor swap. In words:
Let a and b be unsigned int pointers to values n and m
respectively, with respective writable shares sh1 and sh2, and
(* Coq code for https://siraben.github.io/2021/06/27/classical-math-coq.html *)
Definition left_inverse {A B} (f : A -> B) g := forall a, g (f a) = a.
Definition right_inverse {A B} (f : A -> B) g := forall b, f (g b) = b.
Module NaiveInjective.
Definition injective {A B} (f : A -> B) :=
forall a' a'', a' <> a'' -> f a' <> f a''.
@siraben
siraben / asm.v
Last active July 7, 2021 08:23
Verifying factorial for a simple assembly language
Require Import Arith.PeanoNat.
Require Import List.
Import Nat.
Import ListNotations.
(** * Reflexive transitive closure of a relation *)
Definition relation (X : Type) := X -> X -> Prop.
Inductive multi {X : Type} (R : relation X) : relation X :=
| multi_refl : forall (x : X), multi R x x
| multi_step : forall (x y z : X),
@siraben
siraben / Verif_factorial.v
Last active June 14, 2021 07:17
Verifying factorial in C with Coq
Require Import VST.floyd.proofauto.
Require Import VST.floyd.library.
Require Import factorial.
Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
(* First we right down a specification of factorial in Coq that
operates on integers. We need to prove that it terminates as well. *)
Function factorial (n: Z) { measure Z.to_nat n } :=
if Z_gt_dec n 0 then n * factorial (n-1) else 1.
@siraben
siraben / projects-leaving-freenode.md
Last active March 31, 2023 18:13
List of projects and channels that have left or stayed on Freenode

Note: due to volume, this has been moved to https://github.com/siraben/freenode-exodus

Projects and channels that have left Freenode

This is a (necessarily incomplete) list of projects and channels that have decided to permanently move out of Freenode to https://libera.chat (unless stated otherwise). Please reach out below or on IRC if there's additions or corrections.

Sources are mostly comments I've seen on HN, various IRC channels and web searches.

@siraben
siraben / church-rosser.v
Last active May 19, 2021 06:55
Mechanized proof of the Church-Rosser theorem
Set Warnings "-notation-overridden,-parsing,-deprecated-hint-without-locality".
Require Import Arith.
Import Nat.
Require Import Lia.
(** * Reflexive transitive closure of a relation *)
Definition relation (X : Type) := X -> X -> Prop.
Inductive multi {X : Type} (R : relation X) : relation X :=
| multi_refl : forall (x : X), multi R x x
| multi_step : forall (x y z : X),
@siraben
siraben / tactics_from_scratch.v
Last active May 16, 2021 12:38
Creating common tactics in Coq from scratch
(* Showing how to create new tactics only using refine *)
Inductive equal {A : Type} (x : A) : A -> Prop := equal_refl : equal x x.
Check equal_refl.
(* equal_refl *)
(* : forall x : ?A, equal x x *)
(* where *)
(* ?A : [ |- Type] *)
@siraben
siraben / forth.v
Last active April 16, 2023 04:50
Small-step operational semantics of Forth in Coq
Set Warnings "-notation-overridden,-parsing".
From Coq Require Import Arith.Arith.
From Coq Require Import Arith.EqNat.
From Coq Require Import Init.Nat.
From Coq Require Import Lia.
From Coq Require Import Lists.List.
Import ListNotations.
From PLF Require Import Maps.
From PLF Require Import Smallstep.
Import Nat.
@siraben
siraben / set-theory.v
Last active April 18, 2021 12:36
Basic set theory formalized in Coq (last modified 2019-08-12 06:15)
(** Originally written when I was in high school so many things are not ideal here **)
Section Sets.
Variable set : Type.
Variable element : set -> set -> Prop.
Definition subset (x:set) (y:set) :=
forall z:set, element z x -> element z y.
Axiom equality : forall x y:set, x = y <-> forall z:set, element z x <-> element z y.
@siraben
siraben / fib.v
Last active April 17, 2021 10:12
Proof that Fibonacci of n > 0 is less than 2^n
(* For the proof idea see https://math.stackexchange.com/a/894767 *)
Require Import Psatz.
From Coq.Arith Require Import PeanoNat.
Import Nat.
Fixpoint fib n :=
match n with
| 0 => 1
| S n =>
match n with