math / data /lean /OAI /Computability /BinPacking /Hardness /PCPPackingGap.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
7.37 kB
import Mathlib.Data.Rat.Cast.Order
import Mathlib.Basic.Real.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.NormNum
import OAI.Computability.BinPacking.Configurations.K4Soundness
import OAI.Computability.BinPacking.Configurations.ReductionCompleteness
import OAI.Computability.BinPacking.Machines.GraphPackingOutput
import OAI.Computability.BinPacking.PCP.PCPSourceHardness
import OAI.Computability.BinPacking.Packing.LiteralSlotGap
namespace OAI
noncomputable section
namespace BinPackingGap.PCPFoundation
section
open BinPackingGames.Foundations
open Target
open BinPackingCompleteness
def gap : β„š := PCPSource.sourceGap
def rho : ℝ := (gap : ℝ) / 6
theorem gap_pos : 0 < gap := PCPSource.sourceGap_pos
theorem gap_cast_pos : (0 : ℝ) < gap := by exact_mod_cast gap_pos
theorem rho_pos : 0 < rho := div_pos gap_cast_pos (by norm_num)
theorem rho_lt_gap_third : rho < (gap : ℝ) / 3 := by
unfold rho
nlinarith [gap_cast_pos]
def formula (F : Formula) : Formula := PCPSource.normalizedFormula F
def graph (F : Formula) : GraphInput := LiteralSlotGraph.graph (formula F)
def target (F : Formula) : β„• := 2 * (formula F).clauses.length
theorem formula_nonempty (F : Formula) : (formula F).clauses β‰  [] :=
PCPSource.normalizedFormula_nonempty F
theorem clause_count_pos (F : Formula) : 0 < (formula F).clauses.length :=
List.length_pos_iff.mpr (formula_nonempty F)
theorem edges_nonempty (F : Formula) : (graph F).edges β‰  [] :=
LiteralSlotGraph.graph_edges_nonempty (formula F) (formula_nonempty F)
theorem target_le_vertices (F : Formula) : target F ≀ (graph F).n := by
change 2 * (formula F).clauses.length ≀ 3 * (formula F).clauses.length
omega
theorem cover_complete (F : Formula) (hF : F.Satisfiable) :
(graph F).CoverAtMost (target F) :=
LiteralSlotGraph.coverAtMost_of_satisfiable (formula F)
((PCPSource.normalizedFormula_satisfiable_iff F).mpr hF)
theorem failedCount_eq_card (F : Formula) (A : Fin F.variables β†’ Bool) :
PCP.NameCompaction.failedCount F A = (LiteralSlotGraph.failedClauses F A).card := by
rw [PCPSource.failedCount_eq_fin_sum]
simpa only [PCP.clauseAt, Fin.getElem_fin] using! (LiteralSlotGraph.failedClauses_card_sum F A).symm
private theorem realGapOfRatGap (q : β„š) (m n : β„•)
(h : q * (m : β„š) ≀ (n : β„š)) : (q : ℝ) * (m : ℝ) ≀ (n : ℝ) := by
exact_mod_cast h
private theorem realCountBound (a b c : β„•) (h : a + b ≀ c) :
(a : ℝ) + (b : ℝ) ≀ (c : ℝ) := by
exact_mod_cast h
theorem normalized_failed_gap (F : Formula) (hF : Β¬ F.Satisfiable)
(A : Fin (PCPSource.normalizedFormula F).variables β†’ Bool) :
PCPSource.sourceGap * ((PCPSource.normalizedFormula F).clauses.length : β„š) ≀
((LiteralSlotGraph.failedClauses (PCPSource.normalizedFormula F) A).card : β„š) := by
have bound := PCPSource.clauseGap F hF A
rw [PCPSource.violatedCount_eq_failedCount F A, failedCount_eq_card] at bound
exact bound
private theorem cover_bound_from_failed_gap (G : Formula) (q : β„š)
(bound : βˆ€ A : Fin G.variables β†’ Bool,
q * (G.clauses.length : β„š) ≀ ((LiteralSlotGraph.failedClauses G A).card : β„š))
(C : Finset (LiteralSlotGraph.graph G).Vertex)
(hC : (LiteralSlotGraph.graph G).IsCover C) :
((2 * G.clauses.length : β„•) : ℝ) + (q : ℝ) * (G.clauses.length : ℝ) ≀
(C.card : ℝ) := by
obtain ⟨A, hA⟩ := LiteralSlotGraph.assignment_count_of_cover G C hC
have hgap := realGapOfRatGap q G.clauses.length _ (bound A)
have hcount := realCountBound (2 * G.clauses.length)
(LiteralSlotGraph.failedClauses G A).card C.card hA
linarith only [hgap, hcount]
theorem cover_sound (F : Formula) (hF : Β¬ F.Satisfiable)
(C : Finset (graph F).Vertex) (hC : (graph F).IsCover C) :
(target F : ℝ) + (gap : ℝ) * ((formula F).clauses.length : ℝ) ≀ (C.card : ℝ) :=
cover_bound_from_failed_gap (formula F) gap (normalized_failed_gap F hF) C hC
theorem no_small_cover (F : Formula) (hF : Β¬ F.Satisfiable)
(C : Finset (graph F).Vertex) (hC : (graph F).IsCover C) :
Β¬ (C.card : ℝ) ≀ (target F : ℝ) + rho * ((graph F).n : ℝ) := by
intro hsmall
have hlarge := cover_sound F hF C hC
have hm : (0 : ℝ) < (formula F).clauses.length := by
exact_mod_cast clause_count_pos F
have hn : ((graph F).n : ℝ) = 3 * ((formula F).clauses.length : ℝ) := by
norm_num [graph, LiteralSlotGraph.graph_n]
rw [hn] at hsmall
unfold rho at hsmall
nlinarith [mul_pos gap_cast_pos hm]
theorem normalizedSource (language : List Bool β†’ Prop)
(membership : Complexity.CookLevin.InNP language) :
βˆƒ source : Complexity.CookLevin.PolynomialThreeSATReduction language,
βˆƒ runtime : Turing.TM2ComputableInPolyTime (id : List Bool β†’ List Bool)
Complexity.formulaBits (PCPSourceHardness.formula source),
Complexity.MachineFiniteAlphabet.FiniteAlphabet runtime.tm ∧
βˆ€ input : List Bool,
((PCPSourceHardness.formula source input).Satisfiable ↔ language input) ∧
(PCPSourceHardness.formula source input).clauses β‰  [] ∧
(βˆ€ (clause : Clause (PCPSourceHardness.formula source input).variables),
clause ∈ (PCPSourceHardness.formula source input).clauses β†’
βˆ€ i j : Fin 3, clause[i].variableIndex = clause[j].variableIndex β†’ i = j) ∧
(Β¬ language input β†’
SourceAmplification.ClauseGap (PCPSource.clauseFamily (source.reduce input))
PCPSource.sourceGap) :=
PCPSourceHardness.normalizedSource language membership
end
open BinPackingGames.Foundations.Target
def graphInput (F : Formula) : GraphReductionInput where
graph := graph F
k := target F
k_le := target_le_vertices F
nonempty := edges_nonempty F
def packingOutput (c : Nat) (F : Formula) : RawReductionOutput :=
graphPackingOutput c rho (graphInput F)
theorem packingOutput_valid (c : Nat) (F : Formula) :
(packingOutput c F).2.Valid :=
graphPackingOutput_valid c rho (graphInput F)
theorem packingOutput_count (c : Nat) (F : Formula) :
(packingOutput c F).2.length = 5 * (packingOutput c F).1 :=
graphPackingOutput_length c rho (graphInput F)
theorem packingOutput_size_lower (c : Nat) (F : Formula)
(i : ((packingOutput c F).2.toInstance (packingOutput_valid c F)).Item) :
(1 / 6 : β„š) < ((packingOutput c F).2.toInstance (packingOutput_valid c F)).size i :=
(graphPackingOutput_size_bounds c rho (graphInput F) i).1
theorem packingOutput_complete (c : Nat) (F : Formula) (hF : F.Satisfiable) :
HasPacking ((packingOutput c F).2.toInstance (packingOutput_valid c F))
(packingOutput c F).1 := by
apply (graphPackingOutput_hasPacking_iff c rho (graphInput F) _).mpr
exact cover_hasPacking_reduction c rho (graph F) (target F)
(target_le_vertices F) (cover_complete F hF)
theorem packingOutput_sound (c : Nat) (F : Formula) (hF : Β¬ F.Satisfiable) :
Β¬ HasPacking ((packingOutput c F).2.toInstance (packingOutput_valid c F))
((packingOutput c F).1 + c) := by
intro hp
obtain ⟨p⟩ := (graphPackingOutput_hasPacking_iff c rho (graphInput F) _).mp hp
obtain ⟨C, hcover, hsmall⟩ := packing_extracts_cover c rho rho_pos
(graph F) (target F) (target_le_vertices F) p (Nat.le_refl _)
exact no_small_cover F hF C hcover hsmall
end BinPackingGap.PCPFoundation
end
end OAI