Word Encoding of an Instance
Lax117284.InstanceEncoding · concepts/Lax117284/InstanceEncoding.lean · lax-117284
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
An instance is handed to a word random access machine as a word of numbers: the number of clients, the number of days, then the processing times day by day, then the due dates day by day. A decision instance of appends the fairness parameter as a final entry, and a decision instance of the per-client problem appends one parameter per client.
A word determines the instance it encodes, so notions defined for instances — the number of days, the treewidth of the overall conflict graph — are notions of the word as well.
Concept map
Evidence
Lean source view on GitHub
| 1 | import Lax117284.ConflictGraph |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: Word Encoding of an Instance |
| 6 | type: definition |
| 7 | --- |
| 8 | An instance is handed to a word random access machine as a word of numbers: the number |
| 9 | of clients, the number of days, then the processing times day by day, then the |
| 10 | due dates day by day. A decision instance of |
| 11 | appends the fairness parameter as a final |
| 12 | entry, and a decision instance of the per-client problem appends one parameter per client. |
| 13 | |
| 14 | A word determines the instance it encodes, so notions defined for instances — the number of |
| 15 | days, the treewidth of the overall conflict graph — are notions of the word as well. |
| 16 | |
| 17 | # Formalization Notes |
| 18 | |
| 19 | This is the point at which magnitudes stop being free. The processing times and due dates |
| 20 | are entries of the word, so a claim about a program reading it has to say that they are |
| 21 | words, which the fitting condition of the parameterized notions does. A size measure |
| 22 | counting only the number of clients and days would make the due dates of an instance |
| 23 | invisible and a running time stated against it would not be a claim about anything a |
| 24 | machine does. |
| 25 | |
| 26 | Cells are read with `List.getD`, which returns `0` outside the word; the length condition |
| 27 | pins the word down completely, so the default is never reached at a position the other |
| 28 | conditions constrain. |
| 29 | |
| 30 | The parameter is appended last, so that the instance block sits at the same positions |
| 31 | whether or not a parameter follows it, and the split of the word into its two parts is |
| 32 | determined by the word rather than chosen. |
| 33 | |
| 34 | Decoding is stated as a function into instances, undefined — an instance with no client and |
| 35 | no day — on the words that encode none. That a word encodes at most one instance is a |
| 36 | statement rather than a convention, and it is what makes the decoded instance a function of |
| 37 | the word. |
| 38 | -/ |
| 39 | |
| 40 | namespace Lax117284.InstanceEncoding |
| 41 | |
| 42 | open Lax117284.Scheduling |
| 43 | |
| 44 | /-- The number of clients declared by a word: its first entry. -/ |
| 45 | def clientCount (x : List ℕ) : ℕ := x.getD 0 0 |
| 46 | |
| 47 | /-- The number of days declared by a word: its second entry. -/ |
| 48 | def dayCount (x : List ℕ) : ℕ := x.getD 1 0 |
| 49 | |
| 50 | /-- The processing time of client `j`'s job on day `i`: the processing times follow the two |
| 51 | header entries, day by day. -/ |
| 52 | def proc (x : List ℕ) (i j : ℕ) : ℕ := x.getD (2 + i * clientCount x + j) 0 |
| 53 | |
| 54 | /-- The due date of client `j`'s job on day `i`: the due dates follow the processing |
| 55 | times. -/ |
| 56 | def due (x : List ℕ) (i j : ℕ) : ℕ := |
| 57 | x.getD (2 + dayCount x * clientCount x + i * clientCount x + j) 0 |
| 58 | |
| 59 | /-- The word `x` encodes the instance `I`. -/ |
| 60 | structure EncodesInstance (x : List ℕ) (I : Instance) : Prop where |
| 61 | /-- The word declares `I`'s clients. -/ |
| 62 | clientCount_eq : clientCount x = I.clients |
| 63 | /-- The word declares `I`'s days. -/ |
| 64 | dayCount_eq : dayCount x = I.days |
| 65 | /-- The word consists of the two header entries and the two arrays of one number per |
| 66 | job. -/ |
| 67 | length_eq : x.length = 2 + 2 * I.days * I.clients |
| 68 | /-- The processing times are `I`'s. -/ |
| 69 | proc_eq : ∀ (i : Fin I.days) (j : Fin I.clients), proc x i j = I.p i j |
| 70 | /-- The due dates are `I`'s. -/ |
| 71 | due_eq : ∀ (i : Fin I.days) (j : Fin I.clients), due x i j = I.d i j |
| 72 | |
| 73 | /-- The word `x` presents the instance `I` together with the fairness parameter `k`: an |
| 74 | instance block followed by the single entry `k`. -/ |
| 75 | def EncodesUniform (x : List ℕ) (I : Instance) (k : ℕ) : Prop := |
| 76 | ∃ y, x = y ++ [k] ∧ EncodesInstance y I |
| 77 | |
| 78 | /-- The word `x` presents the instance `I` together with one fairness parameter per |
| 79 | client. -/ |
| 80 | def EncodesPerClient (x : List ℕ) (I : Instance) (k : Fin I.clients → ℕ) : Prop := |
| 81 | ∃ y, x = y ++ (List.ofFn k) ∧ EncodesInstance y I |
| 82 | |
| 83 | /-- The words that encode an instance and a fairness parameter. -/ |
| 84 | def UniformInstances : Set (List ℕ) := {x | ∃ I k, EncodesUniform x I k} |
| 85 | |
| 86 | /-- The instance with no client and no day, the value of the decoding on a word that |
| 87 | encodes no instance. -/ |
| 88 | def empty : Instance where |
| 89 | clients := 0 |
| 90 | days := 0 |
| 91 | p := fun i => i.elim0 |
| 92 | d := fun i => i.elim0 |
| 93 | p_pos := fun i => i.elim0 |
| 94 | p_le_d := fun i => i.elim0 |
| 95 | |
| 96 | open Classical in |
| 97 | /-- The instance a word encodes, and `empty` on a word that encodes none. -/ |
| 98 | noncomputable def decode (x : List ℕ) : Instance := |
| 99 | if h : ∃ I, EncodesInstance x I then h.choose else empty |
| 100 | |
| 101 | /-- The fairness parameter a word declares: its last entry. -/ |
| 102 | def parameter (x : List ℕ) : ℕ := (x.getLast? ).getD 0 |
| 103 | |
| 104 | /-- **A word encodes at most one instance.** -/ |
| 105 | axiom encodesInstance_unique {x : List ℕ} {I J : Instance} (hI : EncodesInstance x I) |
| 106 | (hJ : EncodesInstance x J) : I = J |
| 107 | |
| 108 | /-- **The decoding of a word that encodes an instance is that instance.** -/ |
| 109 | axiom decode_eq {x : List ℕ} {I : Instance} (h : EncodesInstance x I) : decode x = I |
| 110 | |
| 111 | end Lax117284.InstanceEncoding |
| 112 |
Formalization Notes
This is the point at which magnitudes stop being free. The processing times and due dates are entries of the word, so a claim about a program reading it has to say that they are words, which the fitting condition of the parameterized notions does. A size measure counting only the number of clients and days would make the due dates of an instance invisible and a running time stated against it would not be a claim about anything a machine does.
Cells are read with , which returns outside the word; the length condition pins the word down completely, so the default is never reached at a position the other conditions constrain.
The parameter is appended last, so that the instance block sits at the same positions whether or not a parameter follows it, and the split of the word into its two parts is determined by the word rather than chosen.
Decoding is stated as a function into instances, undefined — an instance with no client and no day — on the words that encode none. That a word encodes at most one instance is a statement rather than a convention, and it is what makes the decoded instance a function of the word.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments