Skip to content

Commit

Permalink
Initial Coq commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1ff committed Sep 3, 2024
1 parent 2f0e084 commit 10583b2
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ configure
*.gz
*.xz
*.zst
coq
5 changes: 5 additions & 0 deletions coq/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Makefile.coq.d
Makefile.cq
Makefile.coq.conf
doc
Makefile.coq
24 changes: 24 additions & 0 deletions coq/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Taken from <https://github.com/coq-community/manifesto/wiki/Recommended-Project-Structure>
all: Makefile.coq
@+$(MAKE) -f Makefile.coq all

clean: Makefile.coq
@+$(MAKE) -f Makefile.coq cleanall
@rm -f Makefile.coq Makefile.coq.conf
@rm -rf doc

Makefile.coq: _CoqProject
$(COQBIN)coq_makefile -f _CoqProject -o Makefile.coq

force _CoqProject Makefile: ;

DOCDIR := doc

doc:
@test -d doc || mkdir doc
coqdoc --html --utf8 -d doc/ theories/wf.v

%: Makefile.coq force
@+$(MAKE) -f Makefile.coq $@

.PHONY: all clean force doc
12 changes: 12 additions & 0 deletions coq/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#+TITLE: README
#+DESCRIPTION: A Coq development of Damerau-Levenshtein edit distance
#+DATE: <2024-09-03 Tue 13:52>
#+AUTODATE: t
#+AUTHOR: Michael Herstine
#+EMAIL: [email protected]
#+OPTIONS: toc:nil org-md-headline-style:setext *:t ^:nil ^:{}

* Introduction

This directory contains a [[https://coq.inria.fr/][Coq]] development of Damerau-Levenshtein edit distance. It's my first Coq development, so please don't judge it too harshly.

3 changes: 3 additions & 0 deletions coq/_CoqProject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-Q theories DamerauLevenshtein

theories/wf.v
8 changes: 8 additions & 0 deletions coq/theories/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.lia.cache
*.aux
*.glob
*.vo
*.vok
*.vos
.old-files

53 changes: 53 additions & 0 deletions coq/theories/wf.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(* Copyright (C) 2024 Michael Herstine *)

Require Import Coq.Arith.PeanoNat.
Require Import Lia.

(** * Introduction *)

(** This is my attempted formalization of "The String-to-String
Correction Problem" by Wagner & Fischer:
Wagner, Robert A., and Michael J. Fischer. 1974. "The
String-to-String Correction Problem." Journal of the Acm 21 (1):
168-73. https://doi.org/10.1145/321796.321811.
I started with Wagner & Lowrance, but found it to be difficult to
formalize. Perhaps related is the fact that Ukkonen, the next step
in the evolution of these algorithms, bases his work on Wagner &
Fischer.
This is my first non-trivial Coq development, so it's going to be
quite chatty as I figure things out. *)

(** * Preliminaries *)

(** Throughout, let [a] & [b] be strings. While Wagner & Fischer use
capital letters for their strings, that conflicts with Coq naming
conventions, so I'm going to switch to lower-case. I first thought
to use the stdlib [string] to represent them, but found that List
is much more featureful, so instead I'll just use a List of Ascii.
*)

Require Import Ascii.

Open Scope char_scope.
Definition c := "c".
Definition a := "097".
Print a. (** :=> "a" : ascii-- 'a' is ASCII code 97 *)

Close Scope char_scope.
Reset c.

(** I've played a bit with [Vector.t], but like others found it a bit
tedious to work with. John Wiegley has some interesting
alternatives here
<https://stackoverflow.com/questions/42302300/which-vector-library-to-use-in-coq>,
but for now let's just use lists: *)

Require Import List.
Import ListNotations.

Definition string := list ascii.

Compute ["H";"e";"l";"l";"o"].

0 comments on commit 10583b2

Please sign in to comment.