File size: 6,107 Bytes
ae00908
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Algebra.Universal.GraphCriterion
import Mathlib.Data.Fintype.Powerset

namespace OAI

/-!
# Decidability of fixed-size graph witnesses

Connectivity is characterized by containment in every Boolean equivalence relation containing
the marked edges. On a finite carrier this gives an executable decision procedure, and hence
a decision procedure for the existence of a graph witness at each fixed size. The size of a
witness in `HasGraphWitness` is not bounded by these results.
-/

namespace FiniteCongruence

/-- A Boolean relation is closed if it is an equivalence containing every marked edge. -/
def ClosedMarking {Lat Carrier : Type} [LE Lat] (color : Carrier → Carrier → Lat)
    (seeds : Finset (Carrier × Carrier)) (rel : Carrier → Carrier → Bool) : Prop :=
  (∀ point, rel point point = true) ∧
  (∀ left right, rel left right = true → rel right left = true) ∧
  (∀ left middle right, rel left middle = true → rel middle right = true → rel left right = true) ∧
  (∀ left right, Marked color seeds left right → rel left right = true)

/-- Connectivity is the intersection of the Boolean equivalence relations containing all
marked edges. This characterization uses classical logic but allows finite enumeration. -/
theorem connected_iff_closedMarkings {Lat Carrier : Type} [LE Lat]
    (color : Carrier → Carrier → Lat) (seeds : Finset (Carrier × Carrier)) (left right : Carrier) :
    Connected color seeds left right ↔
      ∀ rel : Carrier → Carrier → Bool, ClosedMarking color seeds rel → rel left right = true := by
  constructor
  · intro connected rel closed
    induction connected with
    | rel first second marked => exact closed.2.2.2 first second marked
    | refl point => exact closed.1 point
    | symm first second _ inductionHyp => exact closed.2.1 first second inductionHyp
    | trans first middle last _ _ firstHyp secondHyp =>
      exact closed.2.2.1 first middle last firstHyp secondHyp
  · classical
    intro contained
    let rel : Carrier → Carrier → Bool := fun first second =>
      decide (Connected color seeds first second)
    have closed : ClosedMarking color seeds rel := by
      refine ⟨?_, ?_, ?_, ?_⟩
      · intro point
        exact decide_eq_true (Relation.EqvGen.refl point)
      · intro first second related
        exact decide_eq_true (Relation.EqvGen.symm first second (of_decide_eq_true related))
      · intro first middle last firstRelated secondRelated
        exact decide_eq_true (Relation.EqvGen.trans first middle last
          (of_decide_eq_true firstRelated) (of_decide_eq_true secondRelated))
      · intro first second marked
        exact decide_eq_true (Relation.EqvGen.rel first second marked)
    exact of_decide_eq_true (contained rel closed)

instance decidableAdmissible {Lat Carrier : Type} [LE Lat] [DecidableLE Lat] [Fintype Carrier]
    (color : Carrier → Carrier → Lat) (placement : Carrier → Carrier) :
    Decidable (Admissible color placement) :=
  inferInstanceAs (Decidable
    (∀ left right, color (placement left) (placement right) ≤ color left right))

instance decidableMarked {Lat Carrier : Type} [LE Lat] [DecidableLE Lat]
    [Fintype Carrier] [DecidableEq Carrier] (color : Carrier → Carrier → Lat)
    (seeds : Finset (Carrier × Carrier)) (left right : Carrier) :
    Decidable (Marked color seeds left right) :=
  inferInstanceAs (Decidable
    (∃ placement : Carrier → Carrier, Admissible color placement ∧
      ∃ edge ∈ seeds, placement edge.1 = left ∧ placement edge.2 = right))

instance decidableClosedMarking {Lat Carrier : Type} [LE Lat] [DecidableLE Lat]
    [Fintype Carrier] [DecidableEq Carrier] (color : Carrier → Carrier → Lat)
    (seeds : Finset (Carrier × Carrier)) (rel : Carrier → Carrier → Bool) :
    Decidable (ClosedMarking color seeds rel) :=
  inferInstanceAs (Decidable
    ((∀ point, rel point point = true) ∧
    (∀ left right, rel left right = true → rel right left = true) ∧
    (∀ left middle right, rel left middle = true → rel middle right = true → rel left right = true) ∧
    (∀ left right, Marked color seeds left right → rel left right = true)))

instance decidableConnected {Lat Carrier : Type} [LE Lat] [DecidableLE Lat]
    [Fintype Carrier] [DecidableEq Carrier] (color : Carrier → Carrier → Lat)
    (seeds : Finset (Carrier × Carrier)) (left right : Carrier) :
    Decidable (Connected color seeds left right) :=
  decidable_of_iff
    (∀ rel : Carrier → Carrier → Bool, ClosedMarking color seeds rel → rel left right = true)
    (connected_iff_closedMarkings color seeds left right).symm

/-- An executable fixed-size test, with no classical choice in its computational content. -/
def graphWitnessDecidable (Lat Carrier : Type) [Fintype Lat] [Lattice Lat] [OrderBot Lat]
    [DecidableEq Lat] [DecidableLE Lat] [Fintype Carrier] [DecidableEq Carrier]
    (color : Carrier → Carrier → Lat) : Decidable (IsGraphWitness color) :=
  inferInstanceAs (Decidable
    ((∀ left right, color left right = color right left) ∧
    (∀ left right, color left right = ⊥ ↔ left = right) ∧
    (∀ left right middle, color left right ≤ color left middle ⊔ color middle right) ∧
    (∀ lower upper : Lat, ¬ lower ≤ upper →
      ∃ left right, color left right ≤ lower ∧ ¬ color left right ≤ upper) ∧
    (∀ seeds : Finset (Carrier × Carrier), seeds.Nonempty → ∀ left right,
      color left right ≤ seeds.sup (fun edge => color edge.1 edge.2) →
        Connected color seeds left right)))

/-- Existence of a colored-graph witness at a fixed candidate size is decidable. -/
def graphSizeDecidable (Lat : Type) [Fintype Lat] [Lattice Lat] [OrderBot Lat]
    [DecidableEq Lat] [DecidableLE Lat] (size : ℕ) :
    Decidable (0 < size ∧ ∃ color : Fin size → Fin size → Lat, IsGraphWitness color) := by
  letI : DecidablePred (fun color : Fin size → Fin size → Lat => IsGraphWitness color) :=
    graphWitnessDecidable Lat (Fin size)
  infer_instance

end FiniteCongruence

end OAI