While this submission is a draft, it cannot be used by other submissions.

Construction 2

Lax470956.Construction2 · concepts/Lax470956/Construction2.lean · lax-470956

proven

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    The scheduling instance built from a (3,4)(3,4) formula. Each variable gets two machines, one for each truth value, and one job spanning a fixed window of length 2525. Each clause gets three machines, and each of its three literal occurrences gets three jobs: a unit job whose deadline 2(k+1)+8h2(k+1) + 8h records which occurrence kk of its variable it is and which literal hh of its clause, flanked by two jobs filling the rest of the window.

    The window is what makes the construction work. A variable job overlaps every job of every occurrence of its variable, so a schedule that places all of them must put the variable job on one of the two machines of its variable, and that choice is the truth value. The bounded number of occurrences of a variable is what keeps the window, and with it every processing time, bounded by an absolute constant.

    Concept map
    9 concepts
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A
    Evidence

    This concept declares 8 statements. Each proof establishes one of them relative to its assumptions.

    2 emit_computesInTime proven

    3 emit_encodes proven

    5 reduce_correct proven

    6 reduce_ramPolytime proven

    7 reduce_slice proven

    Lean source view on GitHub

    1import Lax470956.Exact34Encoding
    2import Lax470956.InstanceEncoding
    3import Lax759944.RamPolytime
    4import Mathlib.Data.Finset.Lattice.Fold
    5
    6/-!
    7---
    8title: Construction 2
    9type: definition
    10---
    11The scheduling instance built from a (3,4)(3,4) formula. Each variable gets two
    12machines, one for each truth value, and one job spanning a fixed window of length 2525.
    13Each clause gets three machines, and each of its three literal occurrences gets three
    14jobs: a unit job whose deadline 2(k+1)+8h2(k+1) + 8h records which occurrence kk of its
    15variable it is and which literal hh of its clause, flanked by two jobs filling the rest
    16of the window.
    17
    18The window is what makes the construction work. A variable job overlaps every job of
    19every occurrence of its variable, so a schedule that places all of them must put the
    20variable job on one of the two machines of its variable, and that choice is the truth
    21value. The bounded number of occurrences of a variable is what keeps the window, and
    22with it every processing time, bounded by an absolute constant.
    23
    24# Formalization notes
    25
    26The construction is a total function on words, so that the map it induces is defined
    27everywhere and the statements about it need no side condition. A word that is not a
    28well-formed formula still produces an instance, because the deadline is clamped to
    29[2,24][2, 24] — exactly the range it already occupies when the appearance index is below
    30four and the literal index below three. The clamp is therefore invisible on well-formed
    31input, and it is what discharges the two standing conventions 0<p0 < p and pdp \le d
    32without a hypothesis.
    33
    34Jobs and machines are numbered rather than tagged. Job vv for v<Vv < V belongs to
    35variable vv; job V+9c+3h+sV + 9c + 3h + s belongs to occurrence hh of clause cc, in slot
    36ss — the literal job for s=0s = 0 and its two wrappers for s=1,2s = 1, 2. Machine 2v2v is
    37the true machine of variable vv and 2v+12v + 1 its false machine; machine
    382V+3c+t2V + 3c + t is the tt-th machine of clause cc. The numbering is part of the
    39construction because an instance is something a machine is handed, and a word presents
    40its jobs in an order.
    41-/
    42
    43namespace Lax470956.Construction2
    44
    45open Lax470956.Scheduling Lax470956.Exact34Encoding
    46
    47variable (x : List ℕ)
    48
    49/-- The number of variables the word declares. -/
    50abbrev nVar : ℕ := varCount x
    51
    52/-- The number of clauses the word declares. -/
    53abbrev nCla : ℕ := clauseCount x
    54
    55/-- One job per variable and nine per clause. -/
    56def nJobs : ℕ := nVar x + 9 * nCla x
    57
    58/-- Two machines per variable and three per clause. -/
    59def nMach : ℕ := 2 * nVar x + 3 * nCla x
    60
    61/-- The deadline of the literal job of occurrence `h` of clause `c`, clamped to the
    62range `[2, 24]` it already lies in on a well-formed word. -/
    63def dl (c h : ℕ) : ℕ := min 24 (max 2 (2 * (litApp x c h + 1) + 8 * h))
    64
    65lemma dl_ge (c h : ℕ) : 2dl x c h := by
    66 simp only [dl]; omega
    67
    68lemma dl_le (c h : ℕ) : dl x c h ≤ 24 := by
    69 simp only [dl]; omega
    70
    71/-- On a well-formed word the clamp is inactive: the deadline is the formula's own
    72`2(k+1) + 8h`. -/
    73lemma dl_eq_of_lt {c h : ℕ} (happ : litApp x c h < 4) (hh : h < 3) :
    74 dl x c h = 2 * (litApp x c h + 1) + 8 * h := by
    75 simp only [dl]; omega
    76
    77variable {x}
    78
    79/-- The clause of job index `i` counted from the first clause job. -/
    80def cOf (i : ℕ) : ℕ := i / 9
    81
    82/-- The literal of job index `i` counted from the first clause job. -/
    83def hOf (i : ℕ) : ℕ := i % 9 / 3
    84
    85/-- The slot of job index `i` counted from the first clause job. -/
    86def sOf (i : ℕ) : ℕ := i % 3
    87
    88variable (x)
    89
    90/-- The processing time of job `j`. -/
    91def procOf (j : ℕ) : ℕ :=
    92 if j < nVar x then 25
    93 else
    94 match sOf (j - nVar x) with
    95 | 0 => 1
    96 | 1 => dl x (cOf (j - nVar x)) (hOf (j - nVar x)) - 1
    97 | _ => 25 - dl x (cOf (j - nVar x)) (hOf (j - nVar x))
    98
    99/-- The deadline of job `j`. -/
    100def dueOf (j : ℕ) : ℕ :=
    101 if j < nVar x then 25
    102 else
    103 match sOf (j - nVar x) with
    104 | 0 => dl x (cOf (j - nVar x)) (hOf (j - nVar x))
    105 | 1 => dl x (cOf (j - nVar x)) (hOf (j - nVar x)) - 1
    106 | _ => 25
    107
    108/-- The machines eligible to run job `j`, as a list of machine numbers. -/
    109def eligOf (j : ℕ) : List ℕ :=
    110 if j < nVar x then [2 * j, 2 * j + 1]
    111 else
    112 let i := j - nVar x
    113 let base := 2 * nVar x + 3 * cOf i
    114 match sOf i with
    115 | 0 => [base + 1, base + 2,
    116 2 * litVar x (cOf i) (hOf i) + (if litSign x (cOf i) (hOf i) = 1 then 0 else 1)]
    117 | _ => [base, base + 1, base + 2]
    118
    119lemma procOf_pos (j : ℕ) : 0 < procOf x j := by
    120 unfold procOf
    121 split
    122 · omega
    123 · have h1 := dl_ge x (cOf (j - nVar x)) (hOf (j - nVar x))
    124 have h2 := dl_le x (cOf (j - nVar x)) (hOf (j - nVar x))
    125 match hs : sOf (j - nVar x) with
    126 | 0 => simp
    127 | 1 => simp <;> omega
    128 | (k + 2) => simp <;> omega
    129
    130lemma procOf_le_dueOf (j : ℕ) : procOf x j ≤ dueOf x j := by
    131 unfold procOf dueOf
    132 split
    133 · omega
    134 · have h1 := dl_ge x (cOf (j - nVar x)) (hOf (j - nVar x))
    135 have h2 := dl_le x (cOf (j - nVar x)) (hOf (j - nVar x))
    136 match hs : sOf (j - nVar x) with
    137 | 0 => simp <;> omega
    138 | 1 => simp
    139 | (k + 2) => simp <;> omega
    140
    141lemma procOf_le_25 (j : ℕ) : procOf x j ≤ 25 := by
    142 unfold procOf
    143 split
    144 · omega
    145 · have h1 := dl_ge x (cOf (j - nVar x)) (hOf (j - nVar x))
    146 have h2 := dl_le x (cOf (j - nVar x)) (hOf (j - nVar x))
    147 match hs : sOf (j - nVar x) with
    148 | 0 => simp
    149 | 1 => simp <;> omega
    150 | (k + 2) => simp <;> omega
    151
    152/-- **Construction 2.** The scheduling instance built from the word `x`. -/
    153def inst : Instance where
    154 jobs := nJobs x
    155 machines := nMach x
    156 p j := procOf x j
    157 d j := dueOf x j
    158 w _ := 1
    159 eligible j := Finset.univ.filter fun i : Fin (nMach x) => (i : ℕ) ∈ eligOf x j
    160 p_pos j := procOf_pos x j
    161 p_le_d j := procOf_le_dueOf x j
    162
    163@[simp] lemma inst_jobs : (inst x).jobs = nJobs x := rfl
    164@[simp] lemma inst_machines : (inst x).machines = nMach x := rfl
    165@[simp] lemma inst_p (j : Fin (nJobs x)) : (inst x).p j = procOf x j := rfl
    166@[simp] lemma inst_d (j : Fin (nJobs x)) : (inst x).d j = dueOf x j := rfl
    167
    168
    169/-- Where job `j`'s block of eligible machines begins. -/
    170def offOf (j : ℕ) : ℕ :=
    171 if j ≤ nVar x then 2 * j else 2 * nVar x + 3 * (j - nVar x)
    172
    173/-- The processing-time block. -/
    174def procBlock : List ℕ := (List.range (nJobs x)).map (procOf x)
    175
    176/-- The deadline block. -/
    177def dueBlock : List ℕ := (List.range (nJobs x)).map (dueOf x)
    178
    179/-- The weight block: every job has weight one. -/
    180def wtBlock : List ℕ := List.replicate (nJobs x) 1
    181
    182/-- The offset block, one entry per job and one more. -/
    183def offBlock : List ℕ := (List.range (nJobs x + 1)).map (offOf x)
    184
    185/-- The target block: the eligible machines of each job in turn. -/
    186def tgtBlock : List ℕ := (List.range (nJobs x)).flatMap (eligOf x)
    187
    188/-- **The word Construction 2 emits.** -/
    189def emit : List ℕ :=
    190 [nJobs x, nMach x] ++ procBlock x ++ dueBlock x ++ wtBlock x ++ offBlock x ++ tgtBlock x
    191
    192/-- The word a malformed input is sent to: one job, no machine, so its only job cannot
    193be scheduled. -/
    194def noWord : List ℕ := [1, 0, 1, 1, 1, 0, 0]
    195
    196/-- **Construction 2 as a total map on words.** A word that is not a well-formed formula
    197is sent to a fixed instance that cannot schedule every job. A reduction is a function on
    198all words, and the machine that computes it has to decide which case it is in; making the
    199diversion part of the map rather than a side condition is what keeps the statement below
    200free of hypotheses.
    201
    202The case split is on a proposition rather than on a decision procedure, so the map is
    203`noncomputable` in Lean. Nothing is lost: what has to be computable is the machine
    204program, and the statement that one computes this map is `reduce_computesInTime`. -/
    205noncomputable def reduce (x : List ℕ) : List ℕ :=
    206 open Classical in
    207 if Lax470956.Exact34Encoding.WellFormed x then emit x else noWord
    208
    209/-- Every weight of the constructed instance is `1`. -/
    210axiom weights_one (x : List ℕ) (j : Fin (inst x).jobs) : (inst x).w j = 1
    211
    212/-- Every processing time of the constructed instance is at most `25`. -/
    213axiom pmax_le (x : List ℕ) : (inst x).pmax25
    214
    215/-- **Construction 2 is correct.** A well-formed `(3,4)` formula is satisfiable
    216exactly when every job of the instance it builds can be scheduled. -/
    217axiom correct (x : List ℕ) (hwf : Lax470956.Exact34Encoding.WellFormed x) :
    218 (∃ τ, Lax470956.Exact34Encoding.Satisfies x τ) ↔ (inst x).AllSchedulable
    219
    220/-- **The emitted word encodes the constructed instance.** -/
    221axiom emit_encodes (x : List ℕ) (hwf : Lax470956.Exact34Encoding.WellFormed x) :
    222 Lax470956.InstanceEncoding.EncodesInstance (emit x) (inst x)
    223
    224/-- **The reduction is correct.** A word is a satisfiable `(3,4)` formula exactly
    225when the instance it is sent to can schedule every job. -/
    226axiom reduce_correct (x : List ℕ) :
    227 x ∈ Lax470956.Exact34Encoding.Satisfiable
    228 ∃ I, Lax470956.InstanceEncoding.EncodesInstance (reduce x) I ∧ I.AllSchedulable
    229
    230/-- **The reduction lands in the bounded slice.** Every instance it emits has processing
    231times at most `25` and unit weights. -/
    232axiom reduce_slice (x : List ℕ) :
    233 ∃ I, Lax470956.InstanceEncoding.EncodesInstance (reduce x) I ∧
    234 I.pmax25 ∧ ∀ j, I.w j = 1
    235
    236open Lax759944.RamPolytime in
    237/-- **The reduction runs in polynomial time.** One word RAM program computes the map on
    238every word — well-formed or not — within a polynomial number of instructions in the bit
    239size of its input.
    240
    241This is the running-time half of the reduction, and it is the half the hardness
    242statements need, so it is stated in their currency: `Lax759944.RamPolytime` measures the
    243input by its bit size rather than by the number of entries, hands the machine the input
    244preceded by its length, and is proved in that submission to be interchangeable with
    245polynomial time on a Turing machine. The statement about the emitter alone,
    246`emit_computesInTime`, is the same claim in the archive's word-RAM currency and on
    247well-formed input only; it is the part of this one that does the work, and deciding
    248well-formedness is what the rest of it adds.
    249
    250Deciding well-formedness is not a formality. The condition that distinct occurrences of
    251one variable carry distinct appearance indices is a disjointness condition on `3C`
    252pairs, and it is decidable in one pass only because the pairs live in a universe of size
    253`4V`: an occurrence is bucketed at `4v + k`, and a bucket claimed twice refutes it. -/
    254axiom reduce_ramPolytime : RamPolytime reduce
    255
    256open Lax808846.Ram Lax808846.RamComputes Lax470956.ParameterizedComplexity in
    257/-- **Construction 2 runs in linear time.** One word RAM program and one constant `c`
    258such that, at every word length, on every well-formed formula whose entries fit, the
    259program halts within `c · (|x| + 1)` instructions having written `emit x`. -/
    260axiom emit_computesInTime :
    261 ∃ (prog : Program) (c : ℕ), ∀ w : ℕ,
    262 ComputesInTime w prog
    263 {y | Lax470956.Exact34Encoding.WellFormed y ∧ Fits c w y}
    264 emit (fun y => c * (y.length + 1))
    265
    266end Lax470956.Construction2
    267
    Show ProofShow ProofShow ProofShow ProofShow ProofShow ProofShow ProofShow Proof
    Formalization notes

    The construction is a total function on words, so that the map it induces is defined everywhere and the statements about it need no side condition. A word that is not a well-formed formula still produces an instance, because the deadline is clamped to [2,24][2, 24] — exactly the range it already occupies when the appearance index is below four and the literal index below three. The clamp is therefore invisible on well-formed input, and it is what discharges the two standing conventions 0<p0 < p and pdp \le d without a hypothesis.

    Jobs and machines are numbered rather than tagged. Job vv for v<Vv < V belongs to variable vv; job V+9c+3h+sV + 9c + 3h + s belongs to occurrence hh of clause cc, in slot ss — the literal job for s=0s = 0 and its two wrappers for s=1,2s = 1, 2. Machine 2v2v is the true machine of variable vv and 2v+12v + 1 its false machine; machine 2V+3c+t2V + 3c + t is the tt-th machine of clause cc. The numbering is part of the construction because an instance is something a machine is handed, and a word presents its jobs in an order.

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…