Lean library · module TopologyByExample.Slices.Open

Slices with open rows

Source file

Some slices have consistent rows whose realisability is not known: no clause of the slice rules them out, and no space realising them is known. A row of this kind cannot be the meet of the rows of base spaces (otherwise the sum of those spaces would realise it), so the completeness argument of TopologyByExample.Slices.Horn does not apply to it. This file extends the decision algorithm to slices that set aside a list O of such rows, and proves it correct on every row and complete on every row outside O.

Main definitions

Main statements

Performance

For a slice with eleven properties (2048 rows), seventeen clauses and eighteen base rows, by decide proves CoversExcept in a few seconds, with no reformulation; see the timings in the project's notes.

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 : ℕ}

Rows

definition memB

TopologyByExample.Slices.Row.memB

Whether r is one of the rows O, as a boolean computed through Row.toList (fast under kernel evaluation).

def memB (O : List (Row n)) (r : Row n) : Bool
:= O.any fun s ↦ s.toList == r.toList

theorem memB_eq_true

TopologyByExample.Slices.Row.memB_eq_true

@[simp]
theorem memB_eq_true {O : List (Row n)} {r : Row n} : memB O r = true ↔ r ∈ O
Proof
:= by
  simp only [memB, List.any_eq_true, beq_iff_eq, Row.toList_inj]
  exact ⟨fun ⟨s, hs, h⟩ ↦ h ▸ hs, fun h ↦ ⟨r, h, rfl⟩⟩

theorem memB_eq_false

TopologyByExample.Slices.Row.memB_eq_false

theorem memB_eq_false {O : List (Row n)} {r : Row n} : memB O r = false ↔ r ∉ O
Proof
:= by
  simp [← memB_eq_true]

definition Extends

TopologyByExample.Slices.Row.Extends

The row r extends the partial assignment cells (pairs of a property and its value).

def Extends (r : Row n) (cells : List (Fin n × Bool)) : Prop
:= ∀ l ∈ cells, r l.1 = l.2

instance

instance (r : Row n) (cells : List (Fin n × Bool)) : Decidable (r.Extends cells)
Proof
:=
  inferInstanceAs (Decidable (∀ _ ∈ _, _))

theorem nodup_all

TopologyByExample.Slices.Row.nodup_all

theorem nodup_all : ∀ n, (all n).Nodup
Proof
  | 0 => List.nodup_singleton _
  | n + 1 => by
    rw [all, List.nodup_flatMap]
    refine ⟨fun r _ ↦ ?_, (nodup_all n).pairwise_of_forall_ne fun r _ s _ hne ↦ ?_⟩
    · simp only [List.nodup_cons, List.mem_singleton, List.not_mem_nil, not_false_eq_true,
        List.nodup_nil, and_true]
      exact fun h ↦ by simpa using congrFun h 0
    · have h (a b : Bool) : Fin.cons a r ≠ (Fin.cons b s : Row (n + 1)) := fun h ↦
        hne (Fin.cons_injective2 h).2
      simp only [Function.onFun, List.disjoint_cons_left, List.mem_cons, List.not_mem_nil,
        or_false, List.disjoint_nil_left, and_true]
      exact ⟨not_or.2 ⟨h _ _, h _ _⟩, not_or.2 ⟨h _ _, h _ _⟩⟩

theorem card_filter_eq_length

TopologyByExample.Slices.Row.card_filter_eq_length

The number of rows with a property, as the length of a filter of Row.all n. Kernel evaluation computes the right-hand side much faster than the cardinality of a Finset of functions.

theorem card_filter_eq_length (p : Row n → Prop) [DecidablePred p] :
    (Finset.univ.filter p).card = ((all n).filter fun r ↦ decide (p r)).length
Proof
:= by
  have : Finset.univ.filter p = ((all n).filter fun r ↦ decide (p r)).toFinset := by
    ext r
    simp [mem_all]
  rw [this, List.toFinset_card_of_nodup ((nodup_all n).filter _)]

Outcomes

inductive type OpenOutcome

TopologyByExample.Slices.OpenOutcome

The outcome of the decision algorithm on a row, when some rows are set aside as open: a violated clause, an expression for a space built from the base spaces, or open.

inductive OpenOutcome (n m : ℕ) : Type where
  /-- The row violates this clause. -/
  | refuted (c : Clause n) : OpenOutcome n m
  /-- The row is realised by the space this expression denotes. -/
  | witness (e : Expr (Fin m)) : OpenOutcome n m
  /-- The row is set aside: whether some space realises it is not settled. -/
  | «open» : OpenOutcome n m
  deriving DecidableEq, Repr

definition toOpen

TopologyByExample.Slices.Outcome.toOpen

An outcome of SliceData.solve, as an outcome with set-aside rows.

def Outcome.toOpen : Outcome n m → OpenOutcome n m
  | .refuted c => .refuted c
  | .witness e => .witness e

definition leaves

TopologyByExample.Slices.Expr.leaves

The leaves of an expression: its base spaces, from left to right.

def Expr.leaves {ι : Type} : Expr ι → List ι
  | .base i => [i]
  | .node e f => e.leaves ++ f.leaves

inductive type OutcomeCode

TopologyByExample.Slices.OutcomeCode

A compact summary of an outcome: the index of the refuting clause, the indices of the base spaces of the witness (from left to right), or open. Used to compare the algorithm with another implementation on many rows with a small table.

inductive OutcomeCode : Type where
  /-- Refuted by the clause with this index (in priority order). -/
  | refuted (i : ℕ) : OutcomeCode
  /-- Witnessed by the combination (sum or product) of the base spaces with these indices, from
  left to right. -/
  | witness (bs : List ℕ) : OutcomeCode
  /-- Set aside as open. -/
  | «open» : OutcomeCode
  deriving DecidableEq, Repr

definition code

TopologyByExample.Slices.OpenOutcome.code

The summary of an outcome, with refuting clauses numbered by their position in D.clauses.

def OpenOutcome.code (D : SliceData n m) : OpenOutcome n m → OutcomeCode
  | .refuted c => .refuted (D.clauses.idxOf c)
  | .witness e => .witness (e.leaves.map Fin.val)
  | .open => .open
variable (D : SliceData n m)

The algorithm

definition solveExcept

TopologyByExample.Slices.SliceData.solveExcept

The decision algorithm with set-aside rows. The first violated clause, if there is one; otherwise open if the row is one of O, and the witness expression if it is not.

def solveExcept (O : List (Row n)) (r : Row n) : OpenOutcome n m
Definition
:=
  match D.solve r with
  | .refuted c => .refuted c
  | .witness e => if Row.memB O r then .open else .witness e

definition CoversExcept

TopologyByExample.Slices.SliceData.CoversExcept

The combinatorial fact behind completeness outside O: every consistent row that is not set aside is the row of its witness expression.

def CoversExcept (O : List (Row n)) : Prop
:=
  ∀ r : Row n, D.Consistent r → r ∉ O → (D.witnessExpr r).row D.baseRow = r

definition coversExceptB

TopologyByExample.Slices.SliceData.coversExceptB

A boolean check of D.CoversExcept O, by enumerating every row.

def coversExceptB (O : List (Row n)) : Bool
:=
  (Row.all n).all fun r ↦ !decide (D.Consistent r) || Row.memB O r ||
    ((D.witnessExpr r).row D.baseRow).toList == r.toList

theorem coversExceptB_eq_true_iff

TopologyByExample.Slices.SliceData.coversExceptB_eq_true_iff

theorem coversExceptB_eq_true_iff {O : List (Row n)} :
    D.coversExceptB O = true ↔ D.CoversExcept O
Proof
:= by
  simp only [coversExceptB, List.all_eq_true, Bool.or_eq_true, Bool.not_eq_eq_eq_not,
    Bool.not_true, decide_eq_false_iff_not, Row.memB_eq_true, beq_iff_eq, Row.toList_inj,
    CoversExcept]
  refine ⟨fun h r hr hO ↦ ?_, fun h r _ ↦ ?_⟩
  · rcases h r (Row.mem_all r) with (h | h) | h
    exacts [absurd hr h, absurd h hO, h]
  · by_cases hr : D.Consistent r
    · by_cases hO : r ∈ O
      exacts [.inl (.inr hO), .inr (h r hr hO)]
    · exact .inl (.inl hr)

instance

instance (O : List (Row n)) : Decidable (D.CoversExcept O)
Proof
:=
  decidable_of_iff _ D.coversExceptB_eq_true_iff

theorem coversExcept_nil_iff

TopologyByExample.Slices.SliceData.coversExcept_nil_iff

With no rows set aside, CoversExcept is Covers.

theorem coversExcept_nil_iff : D.CoversExcept [] ↔ D.Covers
Proof
:= by
  simp [CoversExcept, Covers]

definition ConsistentExtensions

TopologyByExample.Slices.SliceData.ConsistentExtensions

O lists exactly the consistent rows that extend the partial assignment cells.

def ConsistentExtensions (cells : List (Fin n × Bool)) (O : List (Row n)) : Prop
:=
  ∀ r : Row n, r ∈ O ↔ D.Consistent r ∧ r.Extends cells

definition consistentExtensionsB

TopologyByExample.Slices.SliceData.consistentExtensionsB

A boolean check of D.ConsistentExtensions cells O, by enumerating every row.

def consistentExtensionsB (cells : List (Fin n × Bool)) (O : List (Row n)) : Bool
:=
  (Row.all n).all fun r ↦ Row.memB O r == (decide (D.Consistent r) && decide (r.Extends cells))

theorem consistentExtensionsB_eq_true_iff

TopologyByExample.Slices.SliceData.consistentExtensionsB_eq_true_iff

theorem consistentExtensionsB_eq_true_iff {cells : List (Fin n × Bool)} {O : List (Row n)} :
    D.consistentExtensionsB cells O = true ↔ D.ConsistentExtensions cells O
Proof
:= by
  simp only [consistentExtensionsB, List.all_eq_true, beq_iff_eq, ConsistentExtensions]
  refine ⟨fun h r ↦ ?_, fun h r _ ↦ ?_⟩
  · have := h r (Row.mem_all r)
    rw [← Row.memB_eq_true, this]
    simp
  · rw [Bool.eq_iff_iff, Row.memB_eq_true, h r]
    simp

instance

instance (cells : List (Fin n × Bool)) (O : List (Row n)) :
    Decidable (D.ConsistentExtensions cells O)
Proof
:=
  decidable_of_iff _ D.consistentExtensionsB_eq_true_iff

definition Correct

TopologyByExample.Slices.OpenOutcome.Correct

What it means for an outcome of the algorithm with set-aside rows O 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; and open is returned only for a consistent row that is set aside.

def _root_.TopologyByExample.Slices.OpenOutcome.Correct (D : SliceData n m) (O : List (Row n))
    (P : Fin n → SpaceProperty.{u}) (B : Fin m → TopCat.{u}) (r : Row n) :
    OpenOutcome n m → Prop
Definition
  | .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
  | .open => r ∈ O ∧ D.Consistent r
variable {D}

Characterising the outcomes

theorem solveExcept_eq_refuted_iff

TopologyByExample.Slices.SliceData.solveExcept_eq_refuted_iff

theorem solveExcept_eq_refuted_iff {O : List (Row n)} {r : Row n} {c : Clause n} :
    D.solveExcept O r = .refuted c ↔ D.solve r = .refuted c
Proof
:= by
  unfold solveExcept
  rcases D.solve r with c' | e
  · simp
  · cases Row.memB O r <;> simp

theorem solveExcept_eq_witness_iff

TopologyByExample.Slices.SliceData.solveExcept_eq_witness_iff

theorem solveExcept_eq_witness_iff {O : List (Row n)} {r : Row n} {e : Expr (Fin m)} :
    D.solveExcept O r = .witness e ↔ D.solve r = .witness e ∧ r ∉ O
Proof
:= by
  unfold solveExcept
  rcases D.solve r with c | e'
  · simp
  · rcases h : Row.memB O r
    · simp [Row.memB_eq_false.1 h]
    · simp [Row.memB_eq_true.1 h]

theorem solveExcept_eq_open_iff

TopologyByExample.Slices.SliceData.solveExcept_eq_open_iff

theorem solveExcept_eq_open_iff {O : List (Row n)} {r : Row n} :
    D.solveExcept O r = .open ↔ r ∈ O ∧ D.Consistent r
Proof
:= by
  unfold solveExcept
  rcases h : D.solve r with c | e
  · obtain ⟨c', hc'⟩ : ∃ c', D.solve r = .refuted c' := ⟨c, h⟩
    have := mem_clauses_of_solve_eq_refuted hc'
    simp only [reduceCtorEq, false_iff, not_and]
    exact fun _ hr ↦ by simp [hr c' this.1] at this
  · have hr := (solve_eq_witness_iff.1 h).1
    rcases hO : Row.memB O r
    · simp [Row.memB_eq_false.1 hO]
    · simp [Row.memB_eq_true.1 hO, hr]

theorem solveExcept_of_not_mem

TopologyByExample.Slices.SliceData.solveExcept_of_not_mem

On a row that is not set aside, the algorithm agrees with SliceData.solve.

theorem solveExcept_of_not_mem {O : List (Row n)} {r : Row n} (hr : r ∉ O) :
    D.solveExcept O r = (D.solve r).toOpen
Proof
:= by
  unfold solveExcept
  rcases D.solve r with c | e
  · rfl
  · simp [Row.memB_eq_false.2 hr, Outcome.toOpen]

theorem solveExcept_nil

TopologyByExample.Slices.SliceData.solveExcept_nil

With no rows set aside, the algorithm is SliceData.solve.

theorem solveExcept_nil (r : Row n) : D.solveExcept [] r = (D.solve r).toOpen
Proof
:=
  solveExcept_of_not_mem List.not_mem_nil

Correctness and completeness

theorem not_realises_of_solveExcept_eq_refuted

TopologyByExample.Slices.SliceData.not_realises_of_solveExcept_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_solveExcept_eq_refuted {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
    {O : List (Row n)} {r : Row n} {c : Clause n} (h : D.solveExcept O r = .refuted c)
    (X : Type u) [TopologicalSpace X] : ¬Realises P X r
Proof
:=
  not_realises_of_solve_eq_refuted hD (solveExcept_eq_refuted_iff.1 h) X

theorem mem_clauses_of_solveExcept_eq_refuted

TopologyByExample.Slices.SliceData.mem_clauses_of_solveExcept_eq_refuted

A refutation cites a clause of the slice that the row violates.

theorem mem_clauses_of_solveExcept_eq_refuted {O : List (Row n)} {r : Row n} {c : Clause n}
    (h : D.solveExcept O r = .refuted c) : c ∈ D.clauses ∧ c.eval r = false
Proof
:=
  mem_clauses_of_solve_eq_refuted (solveExcept_eq_refuted_iff.1 h)

theorem realises_of_solveExcept_eq_witness

TopologyByExample.Slices.SliceData.realises_of_solveExcept_eq_witness

Correctness of witnesses. If every property is sum-conjunctive, the base spaces realise the base rows and D.CoversExcept O holds, then the space a witness expression denotes realises the row.

theorem realises_of_solveExcept_eq_witness {P : Fin n → SpaceProperty.{u}}
    (hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) {O : List (Row n)}
    (hC : D.CoversExcept O) {r : Row n} {e : Expr (Fin m)}
    (h : D.solveExcept O r = .witness e) : Realises P (e.eval L.space) r
Proof
:= by
  obtain ⟨hs, hO⟩ := solveExcept_eq_witness_iff.1 h
  obtain ⟨hr, rfl⟩ := solve_eq_witness_iff.1 hs
  simpa only [hC r hr hO] using Expr.realises_eval hP L.realises (D.witnessExpr r)

theorem solveExcept_correct

TopologyByExample.Slices.SliceData.solveExcept_correct

Correctness of the decision algorithm with set-aside rows. If every clause of the slice is a theorem, every property is sum-conjunctive, the base spaces realise the base rows and D.CoversExcept O holds, then the algorithm's outcome on every row is correct.

theorem solveExcept_correct {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
    (hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) {O : List (Row n)}
    (hC : D.CoversExcept O) (r : Row n) : (D.solveExcept O r).Correct D O P L.space r
Proof
:= by
  rcases h : D.solveExcept O r with c | e | _
  · exact ⟨(mem_clauses_of_solveExcept_eq_refuted h).1,
      (mem_clauses_of_solveExcept_eq_refuted h).2, not_realises_of_solveExcept_eq_refuted hD h⟩
  · exact realises_of_solveExcept_eq_witness hP L hC h
  · exact solveExcept_eq_open_iff.1 h

theorem exists_realises_iff_consistent_of_not_mem

TopologyByExample.Slices.SliceData.exists_realises_iff_consistent_of_not_mem

Completeness outside the set-aside rows. Under the hypotheses of solveExcept_correct, a row that is not set aside is realised by some space in Type u if and only if it satisfies every clause of the slice.

theorem exists_realises_iff_consistent_of_not_mem {P : Fin n → SpaceProperty.{u}}
    (hD : D.Valid P) (hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) {O : List (Row n)}
    (hC : D.CoversExcept O) {r : Row n} (hr : r ∉ O) :
    (∃ X : TopCat.{u}, Realises P X r) ↔ D.Consistent r
Proof
:= by
  refine ⟨fun ⟨X, hX⟩ ↦ hD.consistent hX, fun hc ↦ ?_⟩
  exact ⟨_, realises_of_solveExcept_eq_witness hP L hC
    (solveExcept_eq_witness_iff.2 ⟨solve_eq_witness_iff.2 ⟨hc, rfl⟩, hr⟩)⟩

theorem exists_realises_iff_consistent_of_open

TopologyByExample.Slices.SliceData.exists_realises_iff_consistent_of_open

Completeness, given the set-aside rows. If, besides the hypotheses of solveExcept_correct, every set-aside row is realised by some space, then a row is realised by some space if and only if it satisfies every clause of the slice.

theorem exists_realises_iff_consistent_of_open {P : Fin n → SpaceProperty.{u}}
    (hD : D.Valid P) (hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) {O : List (Row n)}
    (hC : D.CoversExcept O) (hO : ∀ r ∈ O, ∃ X : TopCat.{u}, Realises P X r) (r : Row n) :
    (∃ X : TopCat.{u}, Realises P X r) ↔ D.Consistent r
Proof
:= by
  by_cases hr : r ∈ O
  · exact ⟨fun ⟨X, hX⟩ ↦ hD.consistent hX, fun _ ↦ hO r hr⟩
  · exact exists_realises_iff_consistent_of_not_mem hD hP L hC hr

theorem extends_iff

TopologyByExample.Slices.Realises.extends_iff

A space has the partial assignment cells exactly when its row extends cells.

theorem _root_.TopologyByExample.Slices.Realises.extends_iff {P : Fin n → SpaceProperty.{u}}
    {X : Type u} [TopologicalSpace X] {r : Row n} (h : Realises P X r)
    (cells : List (Fin n × Bool)) :
    r.Extends cells ↔ cells.Forall fun l ↦ (P l.1).Holds X ↔ l.2 = true
Proof
:= by
  rw [List.forall_iff_forall_mem]
  refine forall₂_congr fun l _ ↦ ?_
  rw [h l.1]
  cases r l.1 <;> cases l.2 <;> simp

theorem exists_mem_realises_iff

TopologyByExample.Slices.SliceData.exists_mem_realises_iff

The set-aside rows as a question about spaces. If the clauses are theorems and O lists exactly the consistent rows extending the partial assignment cells, then some set-aside row is realised by a space if and only if some space has the values cells.

theorem exists_mem_realises_iff {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
    {cells : List (Fin n × Bool)} {O : List (Row n)} (hO : D.ConsistentExtensions cells O) :
    (∃ r ∈ O, ∃ X : TopCat.{u}, Realises P X r) ↔
      ∃ X : TopCat.{u}, cells.Forall fun l ↦ (P l.1).Holds X ↔ l.2 = true
Proof
:= by
  constructor
  · rintro ⟨r, hr, X, hX⟩
    exact ⟨X, (hX.extends_iff cells).1 ((hO r).1 hr).2⟩
  · rintro ⟨X, hX⟩
    have hs := realises_rowOf P X
    exact ⟨_, (hO _).2 ⟨hD.consistent hs, (hs.extends_iff cells).2 hX⟩, X, hs⟩

Counting realisable rows

theorem ncard_mem_Icc

TopologyByExample.Slices.SliceData.ncard_mem_Icc

If a set S of rows contains every consistent row outside O and only consistent rows (as the set of rows realised by spaces does, by completeness outside O and validity), then its size lies between the number of consistent rows outside O and the number of consistent rows, both counted in Row.all n.

theorem ncard_mem_Icc {O : List (Row n)} {S : Set (Row n)}
    (h₁ : ∀ r, D.Consistent r → r ∉ O → r ∈ S) (h₂ : ∀ r ∈ S, D.Consistent r) :
    S.ncard ∈ Set.Icc ((Row.all n).filter fun r ↦ decide (D.Consistent r) && !Row.memB O r).length
      ((Row.all n).filter fun r ↦ decide (D.Consistent r)).length
Proof
:= by
  have e₁ : ((Row.all n).filter fun r ↦ decide (D.Consistent r) && !Row.memB O r).length =
      (Finset.univ.filter fun r ↦ D.Consistent r ∧ r ∉ O).card := by
    rw [Row.card_filter_eq_length]
    congr 1
    exact List.filter_congr fun r _ ↦ by
      by_cases h : r ∈ O <;> simp [h, Row.memB_eq_false.2, Row.memB_eq_true.2]
  have e₂ : ((Row.all n).filter fun r ↦ decide (D.Consistent r)).length =
      (Finset.univ.filter fun r ↦ D.Consistent r).card := (Row.card_filter_eq_length _).symm
  rw [e₁, e₂, ← Set.ncard_coe_finset, ← Set.ncard_coe_finset]
  simp only [Finset.coe_filter, Finset.mem_univ, true_and]
  exact ⟨Set.ncard_le_ncard (fun r ⟨hr, hO⟩ ↦ h₁ r hr hO) (Set.toFinite S),
    Set.ncard_le_ncard (fun r hr ↦ h₂ r hr) (Set.toFinite _)⟩

theorem ncard_setOf_realises_mem_Icc

TopologyByExample.Slices.SliceData.ncard_setOf_realises_mem_Icc

The number of rows realised by spaces in Type u lies between the number of consistent rows outside O and the number of consistent rows, under the hypotheses of solveExcept_correct.

theorem ncard_setOf_realises_mem_Icc {P : Fin n → SpaceProperty.{u}} (hD : D.Valid P)
    (hP : ∀ i, (P i).SumConjunctive) (L : D.Library P) {O : List (Row n)}
    (hC : D.CoversExcept O) :
    {r : Row n | ∃ X : TopCat.{u}, Realises P X r}.ncard ∈
      Set.Icc ((Row.all n).filter fun r ↦ decide (D.Consistent r) && !Row.memB O r).length
        ((Row.all n).filter fun r ↦ decide (D.Consistent r)).length
Proof
:=
  ncard_mem_Icc (fun _ hr hO ↦ (exists_realises_iff_consistent_of_not_mem hD hP L hC hO).2 hr)
    fun _ ⟨_, hX⟩ ↦ hD.consistent hX

theorem ncard_setOf_realises_by

TopologyByExample.Slices.SliceData.ncard_setOf_realises_by

The number of realised rows, through a combinator. Under the hypotheses of solve_correct_by, the number of rows realised by spaces in Type u is the number of consistent rows, counted in Row.all n (which kernel evaluation computes quickly).

theorem ncard_setOf_realises_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}.ncard =
      ((Row.all n).filter fun r ↦ decide (D.Consistent r)).length
Proof
:= by
  have : {r : Row n | ∃ X : TopCat.{u}, Realises P X r} =
      ↑(Finset.univ.filter fun r : Row n ↦ D.Consistent r) := by
    ext r
    simp [exists_realises_iff_consistent_by hD hP L hA hC]
  rw [this, Set.ncard_coe_finset, Row.card_filter_eq_length]

theorem ncard_setOf_realises_prod

TopologyByExample.Slices.SliceData.ncard_setOf_realises_prod

The number of realised rows, with product witnesses. Under the hypotheses of solve_correct_prod, the number of rows realised by spaces in Type u is the number of consistent rows.

theorem ncard_setOf_realises_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}.ncard =
      ((Row.all n).filter fun r ↦ decide (D.Consistent r)).length
Proof
:=
  ncard_setOf_realises_by (c := .prod) hD hP L hne hC