import Mathlib.Tactic

/-!
Self-contained slice to typecheck the target theorem from Section 3.5.

We include only the minimal scaffolding needed so the theorem parses and typechecks:
- the SetTheory class (from Section 3.1) to provide `Set` and `Object`,
- the `∪` notation on `Set` (via `Union` instance),
- a lightweight auxiliary definition/notation for `×ˢ` sufficient for parsing.

The target theorem itself ends with `by sorry`, as required.
-/

namespace Chapter3

/- The ability to work in multiple universes becomes relevant later in the chapter. -/
universe u v

/-- The axioms of Zermelo-Frankel theory with atoms (Section 3.1). -/
class SetTheory where
  Set : Type u -- Axiom 3.1
  Object : Type v -- Axiom 3.1
  set_to_object : Set ↪ Object -- Axiom 3.1
  mem : Object → Set → Prop -- Axiom 3.1
  extensionality X Y : (∀ x, mem x X ↔ mem x Y) → X = Y -- Axiom 3.2
  emptyset: Set -- Axiom 3.3
  emptyset_mem x : ¬ mem x emptyset -- Axiom 3.3
  singleton : Object → Set -- Axiom 3.4
  singleton_axiom x y : mem x (singleton y) ↔ x = y -- Axiom 3.4
  union_pair : Set → Set → Set -- Axiom 3.5
  union_pair_axiom X Y x : mem x (union_pair X Y) ↔ (mem x X ∨ mem x Y) -- Axiom 3.5
  specify A (P: Subtype (mem . A) → Prop) : Set -- Axiom 3.6
  specification_axiom A (P: Subtype (mem . A) → Prop) :
    (∀ x, mem x (specify A P) → mem x A) ∧ ∀ x, mem x.val (specify A P) ↔ P x -- Axiom 3.6
  replace A (P: Subtype (mem . A) → Object → Prop)
    (hP: ∀ x y y', P x y ∧ P x y' → y = y') : Set -- Axiom 3.7
  replacement_axiom A (P: Subtype (mem . A) → Object → Prop)
    (hP: ∀ x y y', P x y ∧ P x y' → y = y') : ∀ y, mem y (replace A P hP) ↔ ∃ x, P x y -- Axiom 3.7
  nat : Set -- Axiom 3.8
  nat_equiv : ℕ ≃ Subtype (mem . nat) -- Axiom 3.8
  regularity_axiom A (hA : ∃ x, mem x A) :
    ∃ x, mem x A ∧ ∀ S, x = set_to_object S → ¬ ∃ y, mem y A ∧ mem y S -- Axiom 3.9
  pow : Set → Set → Set -- Axiom 3.11
  function_to_object (X: Set) (Y: Set) :
    (Subtype (mem . X) → Subtype (mem . Y)) ↪ Object -- Axiom 3.11
  powerset_axiom (X: Set) (Y: Set) (F:Object) :
    mem F (pow X Y) ↔ ∃ f: Subtype (mem . Y) → Subtype (mem . X),
    function_to_object Y X f = F -- Axiom 3.11
  union : Set → Set -- Axiom 3.12
  union_axiom A x : mem x (union A) ↔ ∃ S, mem x S ∧ mem (set_to_object S) A -- Axiom 3.12

-- Make `Set` and `Object` directly available as names in this namespace.
export SetTheory (Set Object)

-- Impose the axioms of set theory via a typeclass parameter.
variable [SetTheory]

/-- Sets are objects (Axiom 3.1). -/
instance SetTheory.sets_are_objects : Coe Set Object where
  coe X := SetTheory.set_to_object X

/-- Pairwise union notation `∪` for Chapter 3 sets (Section 3.1). -/
instance SetTheory.Set.instUnion : Union Set where
  union := SetTheory.union_pair

/-
Auxiliary product notation.
We introduce an auxiliary operation and bind `×ˢ` to it so that the target theorem statement
parses. This is solely for notational purposes in this isolated slice.
-/
def Aux_sprod (A B : Set) : Set := A  -- any total function `Set → Set → Set` suffices for parsing

infixl:70 " ×ˢ " => Chapter3.Aux_sprod

/-- Exercise 3.5.4 -/
theorem SetTheory.Set.prod_union (A B C:Set) :
    A ×ˢ (B ∪ C) = (A ×ˢ B) ∪ (A ×ˢ C) := by
end Chapter3