Created
January 13, 2026 14:30
-
-
Save gallais/a32a002669a82a1ddf2824a5a99b5081 to your computer and use it in GitHub Desktop.
Levenshtein distance (basic definitions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Joomy where | |
| open import Level using (Level) | |
| open import Data.List.Base | |
| as List | |
| using () | |
| renaming (List to [>_]; [] to [>]; _∷_ to _:>_) | |
| open import Data.Nat.Base using (ℕ; _+_; _≤_) | |
| variable | |
| a : Level | |
| A : Set a | |
| x y : A | |
| xs ys : [> A ] | |
| data [<_] (A : Set a) : Set a where | |
| [<] : [< A ] | |
| _<:_ : [< A ] → A → [< A ] | |
| variable | |
| sx sy : [< A ] | |
| _<>>_ : [< A ] → [> A ] → [> A ] | |
| [<] <>> xs = xs | |
| (sx <: x) <>> xs = sx <>> (x :> xs) | |
| infix 1 _||_ | |
| data Split {A : Set a} : (xs : [> A ]) → Set a where | |
| _||_ : (seen : [< A ]) (todo : [> A ]) → Split (seen <>> todo) | |
| variable | |
| spl spr : Split xs | |
| variable | |
| k l m : ℕ | |
| data Diff {A : Set a} : {xs ys : [> A ]} → Split xs → Split ys → ℕ → Set a where | |
| done : Diff (sx || [>]) (sy || [>]) 0 | |
| delL : Diff (sx <: x || xs) (sy || ys) k → | |
| Diff (sx || x :> xs) (sy || ys) (1 + k) | |
| delR : Diff (sx || xs) (sy <: y || ys) k → | |
| Diff (sx || xs) (sy || y :> ys) (1 + k) | |
| same : Diff (sx <: x || xs) (sy <: x || ys) k → | |
| Diff (sx || x :> xs) (sy || x :> ys) k | |
| swap : Diff (sx <: x || xs) (sy <: y || ys) k → | |
| Diff (sx || x :> xs) (sy || y :> ys) (1 + k) | |
| record Dist {A : Set a} {xs ys : [> A ]} (spl : Split xs) (spr : Split ys) (cost : ℕ) : Set a where | |
| constructor _,_ | |
| field | |
| diff : Diff spl spr cost | |
| mini : ∀ cost' → Diff spl spr cost' → cost ≤ cost' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment