Crossings along a finite membership sequence
Lax235315.SequenceCrossings · concepts/Lax235315/SequenceCrossings.lean · lax-235315
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
For a set and a listed order of vertices, write down whether each vertex belongs to the set. Its crossing count is the number of changes between consecutive entries. For two sequences of the same length, their Hamming distance is the number of positions with different entries.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.Data.List.Basic |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: Crossings along a finite membership sequence |
| 6 | type: definition |
| 7 | --- |
| 8 | For a set and a listed order of vertices, write down whether each vertex |
| 9 | belongs to the set. Its crossing count is the number of changes between |
| 10 | consecutive entries. For two sequences of the same length, their Hamming |
| 11 | distance is the number of positions with different entries. |
| 12 | |
| 13 | # Formalization notes |
| 14 | |
| 15 | Boolean entries are the actual membership data manipulated by an algorithm. |
| 16 | These definitions do not assert that the vertex list is a permutation; that |
| 17 | is a separate invariant when this representation is used for an order. |
| 18 | The Hamming-distance recursion is used only on equal-length lists. |
| 19 | -/ |
| 20 | |
| 21 | namespace Lax235315.SequenceCrossings |
| 22 | |
| 23 | /-- The number of changes between consecutive membership bits. -/ |
| 24 | def crossings : List Bool → ℕ |
| 25 | | [] => 0 |
| 26 | | [_] => 0 |
| 27 | | a :: b :: rest => (if a = b then 0 else 1) + crossings (b :: rest) |
| 28 | |
| 29 | /-- The number of disagreeing positions of two equal-length membership lists. -/ |
| 30 | def hamming : List Bool → List Bool → ℕ |
| 31 | | a :: rest, b :: rest' => (if a = b then 0 else 1) + hamming rest rest' |
| 32 | | _, _ => 0 |
| 33 | |
| 34 | end Lax235315.SequenceCrossings |
| 35 |
Formalization notes
Boolean entries are the actual membership data manipulated by an algorithm. These definitions do not assert that the vertex list is a permutation; that is a separate invariant when this representation is used for an order. The Hamming-distance recursion is used only on equal-length lists.
Builds on
none
From Mathlib
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments