Martin Escardo, December 2012, going back to work done circa 2010.

The theorem here is that the "squashed sum" of any countable family of
searchable sets is itself searchable (see the module Searchable,
imported below, for the definition and fundamental facts about the
notion).

(The terminology "squashed sum" comes from the paper "Infinite sets
that satisfy the principle of omniscience in all varieties of
constructive mathematics", where this concept is investigated within
the Cantor type ℕ → ₂, which makes the squashing self-evident.)

Given a countable family of sets.

X : ℕ → Set,

extend it to a ℕ∞-indexed family of sets as follows

_[_] : (ℕ → Set) → (ℕ∞ → Set)
X [ u ] = (k : ℕ) → u ≣ k → X k

where u ranges over ℕ∞, the one-point compactification of the natural
numbers ℕ, defined in the module GenericConvergentSequence.

The squashed sum of X : ℕ → Set is defined to be

Σ¹ X = Σ \(u : ℕ∞) → X [ u ]

Intuitively, the squashed sum is the disjoint sum with an added limit
point at infinity.

Assuming excluded middle, Σ¹ X is isomorphic to (Σ \(n : ℕ) → X n) + 1
where 1 is the one-point type.

Assuming Brouwerian continuity axioms, Σ¹ X is the one-point
compatification of the disjoint sum (Σ \(n : ℕ) → X n).

But we don't assume excluded middle or continuiy axioms here. We work
within intensional MLTT with function extensionality as a postulate
(rather than as a meta-theoretical rule).

\begin{code}

{-# OPTIONS --without-K #-}

module SquashedSumOld where

open import GenericConvergentSequence
open import Naturals hiding (_≣_)
open import SetsAndFunctions
open import Searchable
open import ConvergentSequenceSearchable
open import Two
open import CurryHoward
open import Equality
open import Extensionality

_[_] : (ℕ → Set) → (ℕ∞ → Set)
X [ u ] = (k : ℕ) → u ≣ k → X k

Σ¹ : (ℕ → Set) → Set
Σ¹ X = Σ \(u : ℕ∞) → X [ u ]

∞¹ : {X : ℕ → Set} → Σ¹ X
∞¹ = (∞ , (λ k r → ⊥-elim (∞-is-not-ℕ k r)))

\end{code}

This point at infinity is unique assuming extensionality, because:

\begin{code}

H : {X : ℕ → Set} → ∀ u → u ≡ ∞ → ∀(y y' : X [ u ]) → y ≡ y'
H {X} u r y y' = funext(λ k → funext(λ s → lemma k s))
where
lemma : ∀ k s → y k s ≡ y' k s
lemma k s = ⊥-elim(∞-is-not-ℕ k (trans (sym r) s))

\end{code}

Next we have an isomorphism X [ u ] ≅ X n if u ≣ n:

\begin{code}

F : {X : ℕ → Set} → ∀ n u → u ≣ n → X n → X [ u ]
F {X} n u r x k s = subst {ℕ} {X} (under-mono(trans (sym r) s)) x

G : {X : ℕ → Set} → ∀ n u → u ≣ n → X [ u ] → X n
G n u r y = y n r

FG : {X : ℕ → Set} → ∀ n u → ∀(r : u ≣ n) → ∀ y → F n u r (G n u r y) ≡ y
FG {X} n u r y = funext(λ k → funext(λ s → lemma k s))
where
t : ∀ k → u ≣ k → n ≡ k
t k s = under-mono(trans (sym r) s)

A :  ∀ n k → n ≡ k → Set
A n k t = ∀ u → ∀(r : u ≣ n)(s : u ≣ k) → ∀(y : X [ u ])
→ subst {ℕ} {X} t (y n r) ≡ y k s

φ : ∀ n → A n n refl
φ n = λ u r s y → cong (y n) (ℕ∞-hset r s)

lemma : ∀ k s → subst {ℕ} {X} (under-mono (trans (sym r) s)) (y n r) ≡ y k s
lemma k s = J A φ {n} {k} (t k s) u r s y

GF : {X : ℕ → Set} → ∀ n u → ∀(r : u ≣ n) → ∀(x : X n) → G {X} n u r (F n u r x) ≡ x
GF {X} n u r x = s
where
claim₀ : subst  {ℕ} {X} (under-mono (trans (sym r) r)) x ≡ subst  {ℕ} {X} (under-mono refl) x
claim₀ = cong (λ t → subst  {ℕ} {X} (under-mono t) x) (trans-sym r)
claim₁ : subst {ℕ} {X} (under-mono refl) x ≡ x
claim₁ = cong (λ t → subst {ℕ} {X} t x) (under-mono-refl n)
s : subst {ℕ} {X} (under-mono (trans (sym r) r)) x ≡ x
s = trans claim₀ claim₁

\end{code}

We now can show that the type X [ u ] is searchable for every u : ℕ∞
provided the type X n is searchable for every n : ℕ. This is tricky,
because a priory it is not enough to consider the cases u ≣ n and u ≡ ∞.

The above isomorphism is used to prove the correctness of the witness
y₀ below, which is easily defined (using one direction of the
isomorphism):

\begin{code}

extension-searchable : {X : ℕ → Set} → (∀ n → searchable(X n)) → ∀ u → searchable(X [ u ])
extension-searchable {X} ε u p = ∃-intro y₀ lemma
where
Y : Set
Y = X [ u ]
-- ε : ∀ n → searchable(X n)
-- u : ℕ∞
-- p  : Y → ₂

y₀ : Y
y₀ n r = ∃-witness(ε n (p ∘ (F n u r)))

lemma₁ : ∀ n → u ≣ n → p y₀ ≡ ₁ → ∀ y → p y ≡ ₁
lemma₁ n r e = claim₃
where
claim₀ : ∀ y → p(F n u r (G n u r y)) ≡ p y
claim₀ y = cong p (FG n u r y)
claim₁ : p(F n u r (G n u r y₀)) ≡ ₁ → ∀(x : X n) → p(F n u r x) ≡ ₁
claim₁ =  ∃-elim(ε n (p ∘ (F n u r)))
claim₂ : ∀(x : X n) → p(F n u r x) ≡ ₁
claim₂ = claim₁ (trans (claim₀ y₀) e)
claim₃ : ∀ y → p y ≡ ₁
claim₃ y = trans (sym(claim₀ y)) (claim₂ (G n u r y))

lemma₂ : u ≡ ∞ → p y₀ ≡ ₁ → ∀ y → p y ≡ ₁
lemma₂ r e y = trans (cong p (H u r y y₀)) e

lemma₁' : p y₀ ≡ ₁ → ∀ y → p y ≡ ₀ → ∀ n → u ≢ under n
lemma₁' e y s n r = zero-is-not-one (trans (sym s) (lemma₁ n r e y))

lemma₂' : p y₀ ≡ ₁ → ∀ y → p y ≡ ₀ → u ≢ ∞
lemma₂' e y s r = zero-is-not-one (trans (sym s) (lemma₂ r e y))

lemma : p y₀ ≡ ₁ → ∀ y → p y ≡ ₁
lemma r y = Lemma[b≢₀→b≡₁](λ s → lemma₂' r y s (not-ℕ-is-∞(lemma₁' r y s)))

\end{code}

Finally, we can show that the squashed sum of any sequence of
searchable sets is itself searchable, as claimed above:

\begin{code}

squashed-sum-searchable : {X : ℕ → Set} → (∀ n → searchable(X n)) → searchable(Σ¹ X)
squashed-sum-searchable {X} f = sums-preserve-searchability {ℕ∞} ℕ∞-is-searchable (extension-searchable {X} f)

\end{code}