math / data /lean /OAI /Computability /MinUncut /Model.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.7 kB
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