File size: 4,165 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 | import Std
namespace OAI
namespace BinPackingGames.Foundations.Target
structure Literal (variables : Nat) where
variableIndex : Fin variables
positive : Bool
deriving DecidableEq
def Literal.eval {n : Nat} (literal : Literal n) (assignment : Fin n β Bool) : Bool :=
if literal.positive then assignment literal.variableIndex else !(assignment literal.variableIndex)
abbrev Clause (variables : Nat) := Vector (Literal variables) 3
def Clause.eval {n : Nat} (clause : Clause n) (assignment : Fin n β Bool) : Bool :=
(clause[0].eval assignment || clause[1].eval assignment) || clause[2].eval assignment
structure Formula where
variables : Nat
clauses : List (Clause variables)
def Formula.Satisfiable (formula : Formula) : Prop :=
β assignment : Fin formula.variables β Bool,
β clause β formula.clauses, clause.eval assignment = true
structure PermutationTable (alphabet : Nat) where
images : Vector (Fin alphabet) alphabet
inverseImages : Vector (Fin alphabet) alphabet
leftInverse : β label : Fin alphabet, inverseImages[images[label]] = label
rightInverse : β label : Fin alphabet, images[inverseImages[label]] = label
theorem PermutationTable.images_injective {q : Nat} (table : PermutationTable q)
{x y : Fin q} (h : table.images[x] = table.images[y]) : x = y := by
have inverseEquality := congrArg (fun label : Fin q => table.inverseImages[label]) h
simpa only [table.leftInverse] using inverseEquality
theorem PermutationTable.images_surjective {q : Nat} (table : PermutationTable q)
(label : Fin q) : β preimage : Fin q, table.images[preimage] = label :=
β¨table.inverseImages[label], table.rightInverse labelβ©
structure Constraint (vertices alphabet : Nat) where
source : Fin vertices
target : Fin vertices
permutation : PermutationTable alphabet
def Constraint.satisfied {n q : Nat} (constraint : Constraint n q)
(labeling : Fin n β Fin q) : Bool :=
decide (constraint.permutation.images[labeling constraint.source] = labeling constraint.target)
structure Instance (alphabet : Nat) where
vertices : Nat
constraints : List (Constraint vertices alphabet)
nonempty : constraints β []
def countSatisfied {n q : Nat} (labeling : Fin n β Fin q) :
List (Constraint n q) β Nat
| [] => 0
| constraint :: rest =>
(if constraint.satisfied labeling then 1 else 0) + countSatisfied labeling rest
theorem countSatisfied_le_length {n q : Nat} (labeling : Fin n β Fin q)
(constraints : List (Constraint n q)) :
countSatisfied labeling constraints β€ constraints.length := by
induction constraints with
| nil => simp [countSatisfied]
| cons constraint rest ih =>
simp only [countSatisfied, List.length_cons]
split <;> omega
theorem Instance.constraintCount_positive {q : Nat} (game : Instance q) :
0 < game.constraints.length := by
cases h : game.constraints with
| nil => exact False.elim (game.nonempty h)
| cons constraint rest => simp
structure RationalError where
numerator : Nat
denominator : Nat
numeratorPositive : 0 < numerator
denominatorPositive : 0 < denominator
belowHalf : 2 * numerator < denominator
def CompleteAt {q : Nat} (error : RationalError) (game : Instance q) : Prop :=
β labeling : Fin game.vertices β Fin q,
error.denominator * game.constraints.length β€
error.denominator * countSatisfied labeling game.constraints +
error.numerator * game.constraints.length
def SoundAt {q : Nat} (error : RationalError) (game : Instance q) : Prop :=
β labeling : Fin game.vertices β Fin q,
error.denominator * countSatisfied labeling game.constraints β€
error.numerator * game.constraints.length
structure SemanticGapReduction (completenessError soundnessError : RationalError) where
alphabet : Nat
alphabetAtLeastTwo : 2 β€ alphabet
reduce : Formula β Instance alphabet
completeness : β formula : Formula,
formula.Satisfiable β CompleteAt completenessError (reduce formula)
soundness : β formula : Formula,
Β¬ formula.Satisfiable β SoundAt soundnessError (reduce formula)
end BinPackingGames.Foundations.Target
end OAI
|