File size: 4,697 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | import Mathlib
namespace OAI
namespace MinUncutGames.BinaryFormula
structure Literal where
name : Nat
positive : Bool
deriving DecidableEq
def Literal.eval (literal : Literal) (assignment : Nat β Bool) : Bool :=
if literal.positive then assignment literal.name else !(assignment literal.name)
abbrev Clause := Vector Literal 3
def Clause.eval (clause : Clause) (assignment : Nat β Bool) : Bool :=
(clause[0].eval assignment || clause[1].eval assignment) || clause[2].eval assignment
structure Formula where
clauses : List Clause
def Formula.Satisfiable (F : Formula) : Prop :=
β assignment : Nat β Bool, β clause β F.clauses, clause.eval assignment = true
end MinUncutGames.BinaryFormula
namespace MinUncutGames.BinaryEncoding
open BinaryFormula
def frame : List Bool β List Bool
| [] => [false]
| b :: bits => true :: b :: frame bits
def nameBits (name : Nat) : List Bool := frame name.bits
def literalBits (literal : Literal) : List Bool :=
literal.positive :: nameBits literal.name
def clauseBits (clause : Clause) : List Bool :=
literalBits clause[0] ++ literalBits clause[1] ++ literalBits clause[2]
def clausesBits : List Clause β List Bool
| [] => [false]
| clause :: clauses => true :: (clauseBits clause ++ clausesBits clauses)
def formulaBits (formula : Formula) : List Bool := clausesBits formula.clauses
end MinUncutGames.BinaryEncoding
namespace MinUncut
open MinUncutGames.BinaryFormula MinUncutGames.BinaryEncoding
structure Output where
vertices : β
adjacent : Fin vertices β Fin vertices β Bool
symmetric : β u v, adjacent u v = adjacent v u
loopless : β u, adjacent u u = false
threshold : β
threshold_pos : 1 β€ threshold
def Output.uncut (G : Output) (cut : Fin G.vertices β Bool) : β :=
(Finset.univ.filter fun uv : Fin G.vertices Γ Fin G.vertices =>
uv.1 < uv.2 β§ G.adjacent uv.1 uv.2 = true β§ cut uv.1 = cut uv.2).card
noncomputable def Output.opt (G : Output) : β :=
(Finset.univ.image G.uncut).min' (by
exact Finset.image_nonempty.mpr Finset.univ_nonempty)
def Output.bits (G : Output) : List Bool :=
nameBits G.vertices ++
((List.finRange G.vertices).flatMap fun u =>
(List.finRange G.vertices).map fun v => G.adjacent u v) ++
nameBits G.threshold
def inputBits (input : β Γ Formula) : List Bool :=
nameBits input.1 ++ formulaBits input.2
structure Reduction where
reduce : β β Formula β Output
machine : Turing.TM2Computable inputBits Output.bits (fun p => reduce p.1 p.2)
finiteAlphabet : β k : machine.tm.K, Finite (machine.tm.Ξ k)
time : β β Polynomial β
runtime : β K Ο,
Turing.TM2OutputsInTime machine.tm
((inputBits (K, Ο)).map machine.inputAlphabet.symm)
(some (((reduce K Ο).bits).map machine.outputAlphabet.symm))
((time K).eval (formulaBits Ο).length)
size : β β Polynomial β
output_size : β K Ο,
(reduce K Ο).vertices + (reduce K Ο).bits.length β€
(size K).eval (formulaBits Ο).length
yes : β K, 2 β€ K β β Ο, Ο.Satisfiable β
(reduce K Ο).opt β€ (reduce K Ο).threshold
no : β K, 2 β€ K β β Ο, Β¬ Ο.Satisfiable β
K * (reduce K Ο).threshold < (reduce K Ο).opt
end MinUncut
end OAI
|