Lean library · module TopologyByExample.Slices.Horn
Horn slices and the decision algorithm
A slice whose properties are all sum-conjunctive has a set of realised rows that is closed under
meets (a sum realises the meet of the rows of its summands). Its theory is therefore given by
Horn clauses p₁ ∧ ⋯ ∧ pₖ → q and p₁ ∧ ⋯ ∧ pₖ → False, and every realised row is the meet of
the rows of a few base spaces: those realising the meet-irreducible rows.
This file makes that precise and proves the decision algorithm correct.
Main definitions
TopologyByExample.Slices.Clause n: a Horn clause overnproperties, with its boolean evaluation on rowsClause.evaland its meaning for spacesClause.Valid.TopologyByExample.Slices.SliceData n m: the combinatorial data of a slice withnproperties andmbase spaces: a list of clauses, in priority order, the base rows and the index of the top base space, whose row is all true.TopologyByExample.Slices.SliceData.Consistent: a row satisfies every clause (decidable).TopologyByExample.Slices.SliceData.solve: the algorithm. It returns the first clause the row violates (Outcome.refuted), or else a witness expression (Outcome.witness): the top base space for the all-true row, and otherwise the left-nested tree (Expr.nodeList) of the base spaces other than the top space whose rows lie above the row, in index order, read as their disjoint sum or, for a slice witnessed by products, as their product.TopologyByExample.Slices.SliceData.Covers: the finite combinatorial fact that makes the algorithm complete: for every consistent row, the witness expression has exactly that row. It is decidable, so for a concrete sliceby decideproves it by kernel evaluation.TopologyByExample.Slices.SliceData.Library: base spaces realising the base rows.TopologyByExample.Slices.Outcome.CorrectBy: correctness of an outcome of the algorithm, with witnesses read through a combinator. For the sum it isOutcome.Correct(Outcome.correctBy_sum_iff).
Main statements
TopologyByExample.Slices.SliceData.not_realises_of_solve_eq_refuted: a refutation is sound: no space realises the row.TopologyByExample.Slices.SliceData.realises_of_solve_eq_witness: a witness is correct: the space the expression denotes realises the row.TopologyByExample.Slices.SliceData.solve_correct: both at once, for every row.TopologyByExample.Slices.SliceData.exists_realises_iff_consistent: completeness: a row is realised by some space if and only if it is consistent.TopologyByExample.Slices.SliceData.realises_of_solve_eq_witness_by,TopologyByExample.Slices.SliceData.solve_correct_by,TopologyByExample.Slices.SliceData.exists_realises_iff_consistent_by: the same three for witnesses read through any combinator, given that the base spaces are admissible for it; for the sum they are the three statements above.TopologyByExample.Slices.SliceData.realises_of_solve_eq_witness_prod,TopologyByExample.Slices.SliceData.solve_correct_prod,TopologyByExample.Slices.SliceData.exists_realises_iff_consistent_prod: their instances for products, for a slice of product-conjunctive properties with nonempty base spaces. Refutations do not depend on the combinator:SliceData.not_realises_of_solve_eq_refutedapplies as it stands.TopologyByExample.Slices.SliceData.Consistent.inf: consistent rows (models of a Horn theory) are closed under meets.TopologyByExample.Slices.SliceData.realises_of_determines: a space realises a row as soon as it has a few of the row's values that, together with the clauses, determine the rest. This is how a base space's full row is obtained from the facts proved about it.
The top row
The empty selection of base spaces (the all-true row) is handled by a designated top base
space, rather than by the empty space, to match the content's slice algorithm
(top_space in content/slices/). The empty space would also work for the slice S1, since it
has all six S1 properties and is a unit for the disjoint sum, but a designated top space works
for any slice, including those with properties the empty space lacks.
A slice witnessed by products uses the same designated top space. Like every base space of such
a slice it must be nonempty; a one-point space is the natural choice, since it has every
product-conjunctive property that holds of some nonempty space and is a unit for the product up
to homeomorphism. (The empty space, a unit for sums, is absorbing for products and is never a
factor.) Nonemptiness is a hypothesis on the base library (∀ b, Nonempty (L.space b)) and
passes to every product expression (Expr.nonempty_evalBy_prod); refutations still hold for
every space, empty or not, since SliceData.Valid quantifies over all spaces.
This file was written by Claude (Anthropic's AI model) working under the direction of David R. MacIver, who reviews it and is responsible for it.
Imports
variable {n m : ℕ}
structure Clause
TopologyByExample.Slices.Clause
A Horn clause over n properties: the hypotheses hyps (all positive) imply the
conclusion concl, a property, or False when concl = none.
structure Clause (n : ℕ) : Type where
/-- The properties assumed. -/
hyps : List (Fin n)
/-- The property concluded, or `none` for `False`. -/
concl : Option (Fin n)
deriving DecidableEq, Repr
definition eval
TopologyByExample.Slices.Clause.eval
Whether a row satisfies the clause.
def eval (c : Clause n) (r : Row n) : Bool
:= !c.hyps.all r || c.concl.elim false r
theorem eval_eq_true_iff
TopologyByExample.Slices.Clause.eval_eq_true_iff
theorem eval_eq_true_iff {c : Clause n} {r : Row n} :
c.eval r = true ↔ ((∀ i ∈ c.hyps, r i = true) → c.concl.elim False fun j ↦ r j = true)
Proof
:= by
rcases c with ⟨hyps, _ | j⟩ <;> simp [eval, imp_iff_not_or]
definition Models
TopologyByExample.Slices.Clause.Models
The clause holds of the space X.
def Models (c : Clause n) (P : Fin n → SpaceProperty.{u}) (X : Type u) [TopologicalSpace X] :
Prop
:=
(∀ i ∈ c.hyps, (P i).Holds X) → c.concl.elim False fun j ↦ (P j).Holds X
definition Valid
TopologyByExample.Slices.Clause.Valid
The clause is a theorem: it holds of every space in Type u.
def Valid (c : Clause n) (P : Fin n → SpaceProperty.{u}) : Prop
:=
∀ (X : Type u) [TopologicalSpace X], c.Models P X
theorem models_iff
TopologyByExample.Slices.Realises.models_iff
theorem _root_.TopologyByExample.Slices.Realises.models_iff {P : Fin n → SpaceProperty.{u}}
{X : Type u} [TopologicalSpace X] {r : Row n} (h : Realises P X r) (c : Clause n) :
c.Models P X ↔ c.eval r = true
Proof
:= by
rw [eval_eq_true_iff]
rcases c with ⟨hyps, _ | j⟩ <;> simp [Models, h _]
theorem eval_inf
TopologyByExample.Slices.Clause.eval_inf
Horn clauses are preserved by meets of rows.
theorem eval_inf {c : Clause n} {r s : Row n} (hr : c.eval r = true) (hs : c.eval s = true) :
c.eval (r ⊓ s) = true
Proof
:= by
rw [eval_eq_true_iff] at *
intro h
have h₁ := hr fun i hi ↦ (Row.inf_apply_eq_true.1 (h i hi)).1
have h₂ := hs fun i hi ↦ (Row.inf_apply_eq_true.1 (h i hi)).2
rcases c with ⟨hyps, _ | j⟩
· exact h₁
· exact Row.inf_apply_eq_true.2 ⟨h₁, h₂⟩
structure SliceData
TopologyByExample.Slices.SliceData
The combinatorial data of a slice with n properties and m base spaces.
structure SliceData (n m : ℕ) : Type where
/-- The theory of the slice, in priority order: a refutation cites the first clause the row
violates. -/
clauses : List (Clause n)
/-- The row of each base space. -/
baseRow : Fin m → Row n
/-- The base space used for the all-true row. -/
top : Fin m
inductive type Outcome
TopologyByExample.Slices.Outcome
The outcome of the decision algorithm on a row: a violated clause, or an expression for a space built from the base spaces.
inductive Outcome (n m : ℕ) : Type where
/-- The row violates this clause. -/
| refuted (c : Clause n) : Outcome n m
/-- The row is realised by the space this expression denotes. -/
| witness (e : Expr (Fin m)) : Outcome n m
deriving DecidableEq, Repr
variable (D : SliceData n m)
definition Consistent
TopologyByExample.Slices.SliceData.Consistent
The row satisfies every clause of the slice.
def Consistent (r : Row n) : Prop
:= ∀ c ∈ D.clauses, c.eval r = true
instance
instance (r : Row n) : Decidable (D.Consistent r)
Proof
:= inferInstanceAs (Decidable (∀ _ ∈ _, _))
definition Valid
TopologyByExample.Slices.SliceData.Valid
Every clause of the slice is a theorem about spaces in Type u.
def Valid (P : Fin n → SpaceProperty.{u}) : Prop
:= ∀ c ∈ D.clauses, c.Valid P
definition firstViolated
TopologyByExample.Slices.SliceData.firstViolated
The first clause, in priority order, that the row violates.
def firstViolated (r : Row n) : Option (Clause n)
:= D.clauses.find? fun c ↦ !c.eval r
definition above
TopologyByExample.Slices.SliceData.above
The base spaces, other than the top one, whose rows lie above r, in index order.
def above (r : Row n) : List (Fin m)
:=
(List.finRange m).filter fun b ↦ b != D.top && r.leB (D.baseRow b)
definition witnessExpr
TopologyByExample.Slices.SliceData.witnessExpr
The witness expression for a row: the top base space for the all-true row; otherwise the
left-nested tree (a disjoint sum, or a product, according to the evaluation) of D.above r
(or the top space, if that list is empty, which for a consistent row cannot happen when
D.Covers).
def witnessExpr (r : Row n) : Expr (Fin m)
Definition
:=
if (List.finRange n).all r then .base D.top
else match D.above r with
| [] => .base D.top
| b :: bs => .nodeList b bs
definition solve
TopologyByExample.Slices.SliceData.solve
The decision algorithm. The first violated clause, if there is one, and otherwise the witness expression.
def solve (r : Row n) : Outcome n m
Definition
:=
match D.firstViolated r with
| some c => .refuted c
| none => .witness (D.witnessExpr r)
definition Covers
TopologyByExample.Slices.SliceData.Covers
The combinatorial fact behind completeness: every consistent row is the row of its witness expression, which is the meet of the base rows above it (or the top row).
def Covers : Prop
:= ∀ r : Row n, D.Consistent r → (D.witnessExpr r).row D.baseRow = r
definition coversB
TopologyByExample.Slices.SliceData.coversB
A boolean check of D.Covers, by enumerating every row.
def coversB : Bool
:=
(Row.all n).all fun r ↦ !decide (D.Consistent r) ||
((D.witnessExpr r).row D.baseRow).toList == r.toList
theorem coversB_eq_true_iff
TopologyByExample.Slices.SliceData.coversB_eq_true_iff
theorem coversB_eq_true_iff : D.coversB = true ↔ D.Covers
Proof
:= by
simp only [coversB, List.all_eq_true, Bool.or_eq_true, Bool.not_eq_eq_eq_not, Bool.not_true,
decide_eq_false_iff_not, beq_iff_eq, Row.toList_inj, Covers]
exact ⟨fun h r hr ↦ (h r (Row.mem_all r)).resolve_left (not_not.2 hr),
fun h r _ ↦ or_iff_not_imp_left.2 fun hr ↦ h r (not_not.1 hr)⟩
instance
instance : Decidable D.Covers
Proof
:= decidable_of_iff _ D.coversB_eq_true_iff
structure Library
TopologyByExample.Slices.SliceData.Library
Base spaces in Type u realising the base rows.
structure Library (P : Fin n → SpaceProperty.{u}) : Type (u + 1) where
/-- The base space with each index. -/
space : Fin m → TopCat.{u}
/-- Each base space realises its base row. -/
realises : ∀ b, Realises P (space b) (D.baseRow b)
variable {D}
theorem inf
TopologyByExample.Slices.SliceData.Consistent.inf
Consistent rows are closed under meets: the models of a Horn theory form a meet semilattice.
theorem Consistent.inf {r s : Row n} (hr : D.Consistent r) (hs : D.Consistent s) :
D.Consistent (r ⊓ s)
Proof
:= fun c hc ↦ Clause.eval_inf (hr c hc) (hs c hc)
theorem consistent
TopologyByExample.Slices.SliceData.Valid.consistent
theorem Valid.consistent {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P) {X : Type u}
[TopologicalSpace X] {r : Row n} (h : Realises P X r) : D.Consistent r
Proof
:= fun c hc ↦
(h.models_iff c).1 (hD c hc X)
theorem solve_eq_refuted_iff
TopologyByExample.Slices.SliceData.solve_eq_refuted_iff
theorem solve_eq_refuted_iff {r : Row n} {c : Clause n} :
D.solve r = .refuted c ↔ D.firstViolated r = some c
Proof
:= by
unfold solve
cases D.firstViolated r <;> simp
theorem solve_eq_witness_iff
TopologyByExample.Slices.SliceData.solve_eq_witness_iff
theorem solve_eq_witness_iff {r : Row n} {e : Expr (Fin m)} :
D.solve r = .witness e ↔ D.Consistent r ∧ D.witnessExpr r = e
Proof
:= by
unfold solve
rcases h : D.firstViolated r with _ | c
· simp only [firstViolated, List.find?_eq_none, Bool.not_eq_true', Bool.not_eq_false] at h
simp only [Outcome.witness.injEq, iff_and_self]
exact fun _ c hc ↦ by simpa using h c hc
· simp only [reduceCtorEq, false_iff, not_and]
intro hr
have := List.find?_some h
simp [hr c (List.mem_of_find?_eq_some h)] at this
theorem solve_eq_refuted_iff_append
TopologyByExample.Slices.SliceData.solve_eq_refuted_iff_append
The refutation cites the first clause, in priority order, that the row violates.
theorem solve_eq_refuted_iff_append {r : Row n} {c : Clause n} :
D.solve r = .refuted c ↔ c.eval r = false ∧
∃ l₁ l₂, D.clauses = l₁ ++ c :: l₂ ∧ ∀ c' ∈ l₁, c'.eval r = true
Proof
:= by
simp [solve_eq_refuted_iff, firstViolated, List.find?_eq_some_iff_append]
theorem solve_eq_refuted_of_not_consistent
TopologyByExample.Slices.SliceData.solve_eq_refuted_of_not_consistent
theorem solve_eq_refuted_of_not_consistent {r : Row n} (h : ¬D.Consistent r) :
∃ c, D.solve r = .refuted c
Proof
:= by
rcases hs : D.solve r with c | e
· exact ⟨c, rfl⟩
· exact absurd (solve_eq_witness_iff.1 hs).1 h
theorem mem_clauses_of_solve_eq_refuted
TopologyByExample.Slices.SliceData.mem_clauses_of_solve_eq_refuted
The clause a refutation cites is a clause of the slice that the row violates.
theorem mem_clauses_of_solve_eq_refuted {r : Row n} {c : Clause n}
(h : D.solve r = .refuted c) : c ∈ D.clauses ∧ c.eval r = false
Proof
:=
(solve_eq_refuted_iff.1 h) |> fun h ↦ ⟨List.mem_of_find?_eq_some h, by
simpa using List.find?_some h⟩
theorem not_realises_of_solve_eq_refuted
TopologyByExample.Slices.SliceData.not_realises_of_solve_eq_refuted
Soundness of refutations. If every clause of the slice is a theorem, then no space realises a row the algorithm refutes.
theorem not_realises_of_solve_eq_refuted {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
{r : Row n} {c : Clause n} (h : D.solve r = .refuted c) (X : Type u) [TopologicalSpace X] :
¬Realises P X r
Proof
:= fun hX ↦ by
have := mem_clauses_of_solve_eq_refuted h
simp [hD.consistent hX c this.1] at this
theorem realises_of_solve_eq_witness
TopologyByExample.Slices.SliceData.realises_of_solve_eq_witness
Correctness of witnesses. If every property is sum-conjunctive, the base spaces realise
the base rows and D.Covers holds, then the space a witness expression denotes realises the
row.
theorem realises_of_solve_eq_witness {P : Fin n → SpaceProperty.{u}}
(hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) (hC : D.Covers) {r : Row n}
{e : Expr (Fin m)} (h : D.solve r = .witness e) : Realises P (e.eval L.space) r
Proof
:= by
obtain ⟨hr, rfl⟩ := solve_eq_witness_iff.1 h
simpa only [hC r hr] using Expr.realises_eval hP L.realises (D.witnessExpr r)
definition Correct
TopologyByExample.Slices.Outcome.Correct
What it means for an outcome of the algorithm on the row r to be correct: a refutation
cites a clause of the slice that r violates, and no space realises r; a witness expression
denotes a space realising r.
def _root_.TopologyByExample.Slices.Outcome.Correct (D : SliceData n m)
(P : Fin n → SpaceProperty.{u}) (B : Fin m → TopCat.{u}) (r : Row n) : Outcome n m → Prop
| .refuted c => c ∈ D.clauses ∧ c.eval r = false ∧
∀ (X : Type u) [TopologicalSpace X], ¬Realises P X r
| .witness e => Realises P (e.eval B) r
theorem solve_correct
TopologyByExample.Slices.SliceData.solve_correct
Correctness of the decision algorithm. If every clause of the slice is a theorem, every
property is sum-conjunctive, the base spaces realise the base rows and D.Covers holds, then
the algorithm's outcome on every row is correct.
theorem solve_correct {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
(hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) (hC : D.Covers) (r : Row n) :
(D.solve r).Correct D P L.space r
Proof
:= by
rcases h : D.solve r with c | e
· exact ⟨(mem_clauses_of_solve_eq_refuted h).1, (mem_clauses_of_solve_eq_refuted h).2,
not_realises_of_solve_eq_refuted hD h⟩
· exact realises_of_solve_eq_witness hP L hC h
theorem exists_realises_iff_consistent
TopologyByExample.Slices.SliceData.exists_realises_iff_consistent
Completeness. Under the hypotheses of solve_correct, a row is realised by some space
in Type u if and only if it satisfies every clause of the slice.
theorem exists_realises_iff_consistent {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
(hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) (hC : D.Covers) (r : Row n) :
(∃ X : TopCat.{u}, Realises P X r) ↔ D.Consistent r
Proof
:= by
refine ⟨fun ⟨X, hX⟩ ↦ hD.consistent hX, fun hr ↦ ?_⟩
exact ⟨_, realises_of_solve_eq_witness hP L hC (solve_eq_witness_iff.2 ⟨hr, rfl⟩)⟩
Witnesses read through a combinator
definition CorrectBy
TopologyByExample.Slices.Outcome.CorrectBy
What it means for an outcome of the algorithm on the row r to be correct when witnesses
are read through the combinator c: a refutation cites a clause of the slice that r violates,
and no space realises r; a witness expression denotes, through c, a space realising r.
def _root_.TopologyByExample.Slices.Outcome.CorrectBy (c : Combinator) (D : SliceData n m)
(P : Fin n → SpaceProperty.{u}) (B : Fin m → TopCat.{u}) (r : Row n) : Outcome n m → Prop
| .refuted c' => c' ∈ D.clauses ∧ c'.eval r = false ∧
∀ (X : Type u) [TopologicalSpace X], ¬Realises P X r
| .witness e => Realises P (e.evalBy c B) r
theorem correctBy_sum_iff
TopologyByExample.Slices.Outcome.correctBy_sum_iff
Read through the disjoint sum, correctness is Outcome.Correct.
theorem _root_.TopologyByExample.Slices.Outcome.correctBy_sum_iff {D : SliceData n m}
{P : Fin n → SpaceProperty.{u}} {B : Fin m → TopCat.{u}} {r : Row n} {o : Outcome n m} :
o.CorrectBy .sum D P B r ↔ o.Correct D P B r
Proof
:= by
cases o
· rfl
· simp only [Outcome.CorrectBy, Outcome.Correct]
rw [Expr.evalBy_sum]
theorem realises_of_solve_eq_witness_by
TopologyByExample.Slices.SliceData.realises_of_solve_eq_witness_by
Correctness of witnesses, through a combinator. If every property is conjunctive for the
combinator, the base spaces are admissible and realise the base rows and D.Covers holds, then
the space a witness expression denotes realises the row.
theorem realises_of_solve_eq_witness_by {P : Fin n → SpaceProperty.{u}} {c : Combinator}
(hP : ∀ i, (P i).Conjunctive c) (L : D.Library P) (hA : ∀ b, c.Admissible (L.space b))
(hC : D.Covers) {r : Row n} {e : Expr (Fin m)} (h : D.solve r = .witness e) :
Realises P (e.evalBy c L.space) r
Proof
:= by
obtain ⟨hr, rfl⟩ := solve_eq_witness_iff.1 h
simpa only [hC r hr] using Expr.realises_evalBy hP hA L.realises (D.witnessExpr r)
theorem solve_correct_by
TopologyByExample.Slices.SliceData.solve_correct_by
Correctness of the decision algorithm, through a combinator. If every clause of the
slice is a theorem, every property is conjunctive for the combinator, the base spaces are
admissible and realise the base rows and D.Covers holds, then the algorithm's outcome on every
row is correct.
theorem solve_correct_by {P : Fin n → SpaceProperty.{u}} {c : Combinator} (hD : D.Valid P)
(hP : ∀ i, (P i).Conjunctive c) (L : D.Library P) (hA : ∀ b, c.Admissible (L.space b))
(hC : D.Covers) (r : Row n) : (D.solve r).CorrectBy c D P L.space r
Proof
:= by
rcases h : D.solve r with c' | e
· exact ⟨(mem_clauses_of_solve_eq_refuted h).1, (mem_clauses_of_solve_eq_refuted h).2,
not_realises_of_solve_eq_refuted hD h⟩
· exact realises_of_solve_eq_witness_by hP L hA hC h
theorem exists_realises_iff_consistent_by
TopologyByExample.Slices.SliceData.exists_realises_iff_consistent_by
Completeness, through a combinator. Under the hypotheses of solve_correct_by, a row is
realised by some space in Type u if and only if it satisfies every clause of the slice.
theorem exists_realises_iff_consistent_by {P : Fin n → SpaceProperty.{u}} {c : Combinator}
(hD : D.Valid P) (hP : ∀ i, (P i).Conjunctive c) (L : D.Library P)
(hA : ∀ b, c.Admissible (L.space b)) (hC : D.Covers) (r : Row n) :
(∃ X : TopCat.{u}, Realises P X r) ↔ D.Consistent r
Proof
:= by
refine ⟨fun ⟨X, hX⟩ ↦ hD.consistent hX, fun hr ↦ ?_⟩
exact ⟨_, realises_of_solve_eq_witness_by hP L hA hC (solve_eq_witness_iff.2 ⟨hr, rfl⟩)⟩
Products
theorem realises_of_solve_eq_witness_prod
TopologyByExample.Slices.SliceData.realises_of_solve_eq_witness_prod
Correctness of product witnesses. If every property is product-conjunctive, the base
spaces are nonempty and realise the base rows and D.Covers holds, then the product a witness
expression denotes realises the row.
theorem realises_of_solve_eq_witness_prod {P : Fin n → SpaceProperty.{u}}
(hP : ∀ i, (P i).ProdConjunctive) (L : D.Library P) (hne : ∀ b, Nonempty (L.space b))
(hC : D.Covers) {r : Row n} {e : Expr (Fin m)} (h : D.solve r = .witness e) :
Realises P (e.evalBy .prod L.space) r
Proof
:=
realises_of_solve_eq_witness_by (c := .prod) hP L hne hC h
theorem solve_correct_prod
TopologyByExample.Slices.SliceData.solve_correct_prod
Correctness of the decision algorithm with product witnesses. If every clause of the
slice is a theorem, every property is product-conjunctive, the base spaces are nonempty and
realise the base rows and D.Covers holds, then the algorithm's outcome on every row is correct,
with witness expressions read as products.
theorem solve_correct_prod {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
(hP : ∀ i, (P i).ProdConjunctive) (L : D.Library P) (hne : ∀ b, Nonempty (L.space b))
(hC : D.Covers) (r : Row n) : (D.solve r).CorrectBy .prod D P L.space r
Proof
:=
solve_correct_by (c := .prod) hD hP L hne hC r
theorem exists_realises_iff_consistent_prod
TopologyByExample.Slices.SliceData.exists_realises_iff_consistent_prod
Completeness with product witnesses. Under the hypotheses of solve_correct_prod, a row
is realised by some space in Type u if and only if it satisfies every clause of the slice.
theorem exists_realises_iff_consistent_prod {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
(hP : ∀ i, (P i).ProdConjunctive) (L : D.Library P) (hne : ∀ b, Nonempty (L.space b))
(hC : D.Covers) (r : Row n) : (∃ X : TopCat.{u}, Realises P X r) ↔ D.Consistent r
Proof
:=
exists_realises_iff_consistent_by (c := .prod) hD hP L hne hC r
Completing a row from a few of its values
variable (D) in
definition Determines
TopologyByExample.Slices.SliceData.Determines
The values cells (pairs of a property and its value) determine the row r: r is the
only consistent row with these values.
def Determines (cells : List (Fin n × Bool)) (r : Row n) : Prop
:=
∀ s : Row n, D.Consistent s → (∀ l ∈ cells, s l.1 = l.2) → s = r
variable (D) in
definition determinesB
TopologyByExample.Slices.SliceData.determinesB
A boolean check of D.Determines cells r, by enumerating every row.
def determinesB (cells : List (Fin n × Bool)) (r : Row n) : Bool
:=
(Row.all n).all fun s ↦
!(decide (D.Consistent s) && cells.all fun l ↦ s l.1 == l.2) || s.toList == r.toList
theorem determinesB_eq_true_iff
TopologyByExample.Slices.SliceData.determinesB_eq_true_iff
theorem determinesB_eq_true_iff {cells : List (Fin n × Bool)} {r : Row n} :
D.determinesB cells r = true ↔ D.Determines cells r
Proof
:= by
simp only [determinesB, List.all_eq_true, Bool.or_eq_true, Bool.not_eq_eq_eq_not,
Bool.not_true, Bool.and_eq_false_iff, decide_eq_false_iff_not, beq_iff_eq, Row.toList_inj,
Determines]
refine ⟨fun h s hs hc ↦ ?_, fun h s _ ↦ ?_⟩
· rcases h s (Row.mem_all s) with (h | h) | h
· exact absurd hs h
· simp only [List.all_eq_false] at h
obtain ⟨l, hl, hne⟩ := h
exact absurd (hc l hl) (by simpa using hne)
· exact h
· by_cases hs : D.Consistent s
· by_cases hc : ∀ l ∈ cells, s l.1 = l.2
· exact .inr (h s hs hc)
· simp only [not_forall, exists_prop] at hc
obtain ⟨l, hl, hne⟩ := hc
exact .inl (.inr (List.all_eq_false.2 ⟨l, hl, by simpa using hne⟩))
· exact .inl (.inl hs)
instance
instance (cells : List (Fin n × Bool)) (r : Row n) : Decidable (D.Determines cells r)
Proof
:=
decidable_of_iff _ determinesB_eq_true_iff
theorem realises_of_determines
TopologyByExample.Slices.SliceData.realises_of_determines
A space realises the row r if it has the values cells, these determine r and the
clauses of the slice are theorems.
theorem realises_of_determines {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
{X : Type u} [TopologicalSpace X] {cells : List (Fin n × Bool)} {r : Row n}
(hX : cells.Forall fun l ↦ (P l.1).Holds X ↔ l.2 = true) (hr : D.Determines cells r) :
Realises P X r
Proof
:= by
have hs := realises_rowOf P X
refine hr _ (hD.consistent hs) (fun l hl ↦ ?_) ▸ hs
rw [Bool.eq_iff_iff, ← hs, List.forall_iff_forall_mem.1 hX l hl]