Martin Escardo, 30 May - 3rd June 2020. Further additions 6th July.

We look at

  * Quasidecidable propositions (generalizing semidecidable propositions).

  * The initial ฯƒ-frame.

  * The free ฯƒ-sup-lattice on one generator.

Their definitions are given below verbally and in Agda.

We work in a spartan univalent type theory with ฮ , ฮฃ, +, Id, ๐Ÿ˜, ๐Ÿ™, โ„•,
perhaps W-types, universes, propositional-truncation, propositional
extensionality and function extensionality - univalence is not
needed. Most of the time full univalence is not needed - propositional
and functional extenstionality suffice. Sometimes we also consider
propositional resizing, as an explicit assumption each time it is
used.

The above notions don't seem to be definable in our spartan univalent
type theory (but they are definable with higher-inductive
types). Their specifications are as follows:

  * Quasidecidable propositions.

    They are the smallest set of propositions closed under ๐Ÿ˜,๐Ÿ™, and
    countable existential quantification, or countable joins in the
    frame of propositions.

    They form a dominance.

  * The initial ฯƒ-frame.

    A ฯƒ-frame has finite meets โŠค and โˆง and countable joins โ‹, such
    that โˆง distributes over โ‹, with homomorphisms that preserve them.

  * The free ฯƒ-sup-lattice on one generator.

    A ฯƒ-sup-lattice has an empty join โŠฅ and countable joins โ‹ with
    homomorphisms that preserve them. It automatically has binary
    joins, which are automatically preserved by homomorphisms, and the
    generator is automatically the maximum element.

We have:

  * The type of quasidecidable propositions exists if and only if the
    free ฯƒ-sup-lattice on one generator exists.

    The quasidecidable propositions form a dominance.

  * The free ฯƒ-sup-lattice on one generator, if it exists, is also the
    initial ฯƒ-frame.

    We have that ฯƒ-sup-lattice homomorphisms from the free
    ฯƒ-sup-lattice on one generator into a ฯƒ-frame qua ฯƒ-sup-lattice
    automatically preserve finite meets and hence are ฯƒ-frame
    homomorphisms.

  * Assuming that the free ฯƒ-sup-lattice on one generator exists, we
    have that ฯƒ-sup-lattices (and hence ฯƒ-frames) have joins of
    families indexed by quasidecidable propositions.

\begin{code}

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

open import MLTT.Spartan
open import UF.FunExt
open import UF.PropTrunc
open import UF.Sets
open import UF.Subsingletons
open import UF.SubtypeClassifier renaming (โŠฅ to โŠฅฮฉ ; โŠค to โŠคฮฉ)
open import UF.SubtypeClassifier-Properties

\end{code}

We assume function extensionality, propositional extensionality and
the existence of propositional truncations, as explicit hypotheses for
this file.

\begin{code}

module NotionsOfDecidability.QuasiDecidable
        (fe  : Fun-Ext)
        (pe  : Prop-Ext)
        (pt  : propositional-truncations-exist)
       where

open import UF.Size

import OrderedTypes.Frame
import OrderedTypes.sigma-frame
import OrderedTypes.sigma-sup-lattice

open PropositionalTruncation pt

\end{code}

The following three definitions are parametrized by a universe ๐“ฃ,
which we may wish to be the first universe ๐“คโ‚€ in practice.

We adopt the following notational conventions:

  * ๐“ฃ is the universe where the quasidecidable truth values live.

    Typically ๐“ฃ will be ๐“คโ‚€ or ๐“คโ‚.

  * ๐“š is the universe where the knowledge they are quasidecidable lives.
    Typically ๐“š will be ๐“ฃ or ๐“ฃ โบ

Recall that ๐“ค, ๐“ฅ, ๐“ฆ, ๐“ฃ range over universes. We add ๐“š to this list.

\begin{code}

variable ๐“š : Universe

\end{code}

The notion of existence of quasidecidable propositions, formulated as
a record:

\begin{code}

record quasidecidable-propositions-exist (๐“ฃ ๐“š : Universe) : ๐“คฯ‰ where
 constructor
  quasidecidable-propositions

 field
  is-quasidecidable : ๐“ฃ ฬ‡ โ†’ ๐“š ฬ‡

  being-quasidecidable-is-prop : โˆ€ P โ†’ is-prop (is-quasidecidable P)

  ๐Ÿ˜-is-quasidecidable : is-quasidecidable ๐Ÿ˜

  ๐Ÿ™-is-quasidecidable : is-quasidecidable ๐Ÿ™

  quasidecidable-closed-under-ฯ‰-joins
   : (P : โ„• โ†’ ๐“ฃ ฬ‡ )
   โ†’ ((n : โ„•) โ†’ is-quasidecidable (P n))
   โ†’ is-quasidecidable (โˆƒ n ๊ž‰ โ„• , P n)

  quasidecidable-induction
   : โˆ€ {๐“ค}
     (F : ๐“ฃ ฬ‡ โ†’ ๐“ค ฬ‡ )
   โ†’ ((P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F P))
   โ†’ F ๐Ÿ˜
   โ†’ F ๐Ÿ™
   โ†’ ((P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n))
   โ†’ (P : ๐“ฃ ฬ‡ ) โ†’ is-quasidecidable P โ†’ F P

\end{code}

(It follows automatically that quasidecidable types are propositions -
see below.)

We also formulate the existence of the initial ฯƒ-frame as a record.

\begin{code}

record initial-ฯƒ-frame-exists (๐“ฃ : Universe) : ๐“คฯ‰ where
 constructor
  initial-ฯƒ-frame

 open OrderedTypes.sigma-frame fe

 field
  ๐“ : ฯƒ-Frame ๐“ฃ
  ๐“-is-initial : {๐“ค : Universe} (๐“‘ : ฯƒ-Frame ๐“ค)
               โ†’ โˆƒ! f ๊ž‰ (โŸจ ๐“ โŸฉ โ†’ โŸจ ๐“‘ โŸฉ), is-ฯƒ-frame-hom ๐“ ๐“‘ f

\end{code}

And finally the existence of the free ฯƒ-sup-lattice on one generator,
called โŠค (because it will be automatically the top element).

\begin{code}

record free-ฯƒ-SupLat-on-one-generator-exists (๐“ฃ ๐“š : Universe) : ๐“คฯ‰ where
 constructor
  free-ฯƒ-SupLat-on-one-generator

 open OrderedTypes.sigma-sup-lattice fe

 field
  ๐“ : ฯƒ-SupLat ๐“ฃ ๐“š
  โŠค : โŸจ ๐“ โŸฉ
  ๐“-free : {๐“ฅ ๐“ฆ : Universe} (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ)
         โ†’ โˆƒ! f ๊ž‰ (โŸจ ๐“ โŸฉ โ†’ โŸจ ๐“‘ โŸฉ) , is-ฯƒ-suplat-hom ๐“ ๐“‘ f
                                  ร— (f โŠค ๏ผ t)

\end{code}

The main theorems are as follows, where the proofs are given after we
have developed enough material:

\begin{code}

theoremโ‚ : quasidecidable-propositions-exist ๐“ฃ ๐“š
         โ†’ free-ฯƒ-SupLat-on-one-generator-exists (๐“ฃ โบ โŠ” ๐“š) ๐“ฃ

theoremโ‚‚ : free-ฯƒ-SupLat-on-one-generator-exists ๐“ฃ ๐“ค
         โ†’ quasidecidable-propositions-exist ๐“ฃ ๐“ฃ

theoremโ‚ƒ : free-ฯƒ-SupLat-on-one-generator-exists ๐“ฃ ๐“š
         โ†’ initial-ฯƒ-frame-exists ๐“ฃ

theoremโ‚„ : Propositional-Resizing
         โ†’ quasidecidable-propositions-exist ๐“ฃ ๐“š

\end{code}

  * We first work with a hypothetical collection of quasidecidable
    propositions and show that they form the initial ฯƒ-frame.

    This is in the submodule hypothetical-quasidecidability.

  * Then we construct it assuming propositional resizing.

    This is in the submodule quasidecidability-construction-from-resizing.

  * Assuming a hypothetical free ฯƒ-sup-lattice on one generator, it is
    automatically the initial ฯƒ-frame, and from it we can define the
    notion of quasidecidable proposition.

Can we construct them without resizing and without higher-inductive
types other than propositional truncation?

\begin{code}

open import UF.Base
open import UF.Embeddings
open import UF.Equiv
open import UF.Equiv-FunExt
open import UF.EquivalenceExamples
open import UF.Powerset
open import UF.Subsingletons-FunExt
open import UF.UA-FunExt
open import UF.Yoneda

open import Dominance.Definition

\end{code}

Digression. Before considering quasidecidable propositions, we review
semidecidable ones.

A proposition is semidecidable if it is a countable join of decidable
propositions. See the paper
https://www.cs.bham.ac.uk/~mhe/papers/partial-elements-and-recursion.pdf
by Martin Escardo and Cory Knapp.

NB. Semidecidable propositions are called Rosolini propositions in the
above reference.

\begin{code}

is-semidecidable : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
is-semidecidable X = โˆƒ ฮฑ ๊ž‰ (โ„• โ†’ ๐Ÿš), X โ‰ƒ (โˆƒ n ๊ž‰ โ„• , ฮฑ n ๏ผ โ‚)

\end{code}

Exercise. X is semidecidable iff it is a countable join of decidable
propositions:

\begin{code}

is-semidecidable' : ๐“ค ฬ‡ โ†’ ๐“ค โบ ฬ‡
is-semidecidable' {๐“ค} X = โˆƒ A ๊ž‰ (โ„• โ†’ ๐“ค ฬ‡ )
                              , ((n : โ„•) โ†’ is-decidable (A n))
                              ร— (X โ‰ƒ (โˆƒ n ๊ž‰ โ„• , A n))

\end{code}

The following shows that we need to truncate, because the Cantor type
(โ„• โ†’ ๐Ÿš) is certainly not the type of semidecidable propositions:

\begin{code}

semidecidability-data : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
semidecidability-data X = ฮฃ ฮฑ ๊ž‰ (โ„• โ†’ ๐Ÿš), X โ‰ƒ (โˆƒ n ๊ž‰ โ„• , ฮฑ n ๏ผ โ‚)

module only-use-of-univalence-in-this-file where

 open import UF.Univalence

 totality-of-semidecidability-data
  : is-univalent ๐“คโ‚€
  โ†’ (ฮฃ X ๊ž‰ ๐“คโ‚€ ฬ‡ , semidecidability-data X) โ‰ƒ (โ„• โ†’ ๐Ÿš)
 totality-of-semidecidability-data ua =

   (ฮฃ X ๊ž‰ ๐“คโ‚€ ฬ‡ , ฮฃ ฮฑ ๊ž‰ (โ„• โ†’ ๐Ÿš), X โ‰ƒ (โˆƒ n ๊ž‰ โ„• , ฮฑ n ๏ผ โ‚)) โ‰ƒโŸจ i โŸฉ
   (ฮฃ ฮฑ ๊ž‰ (โ„• โ†’ ๐Ÿš), ฮฃ X ๊ž‰ ๐“คโ‚€ ฬ‡ , X โ‰ƒ (โˆƒ n ๊ž‰ โ„• , ฮฑ n ๏ผ โ‚)) โ‰ƒโŸจ ii โŸฉ
   (ฮฃ ฮฑ ๊ž‰ (โ„• โ†’ ๐Ÿš), ฮฃ X ๊ž‰ ๐“คโ‚€ ฬ‡ , (โˆƒ n ๊ž‰ โ„• , ฮฑ n ๏ผ โ‚) โ‰ƒ X) โ‰ƒโŸจ iii โŸฉ
   (โ„• โ†’ ๐Ÿš) ร— ๐Ÿ™ {๐“คโ‚€}                                      โ‰ƒโŸจ iv โŸฉ
   (โ„• โ†’ ๐Ÿš)                                               โ– 
  where
   i   = ฮฃ-flip
   ii  = ฮฃ-cong (ฮป ฮฑ โ†’ ฮฃ-cong (ฮป X โ†’ โ‰ƒ-Sym'' (univalence-gives-funext ua)))
   iii = ฮฃ-cong (ฮป ฮฑ โ†’ singleton-โ‰ƒ-๐Ÿ™
                        (univalence-via-singletonsโ†’
                          ua
                          (โˆƒ n ๊ž‰ โ„• , ฮฑ n ๏ผ โ‚)))
   iv  = ๐Ÿ™-rneutral

\end{code}

End of module only-use-of-univalence-in-this-file.

\begin{code}

๐“ข : ๐“คโ‚ ฬ‡
๐“ข = ฮฃ X ๊ž‰ ๐“คโ‚€ ฬ‡ , is-semidecidable X

\end{code}

The type ๐“ข of semidecidable propositions is not a ฯƒ-frame unless we
have enough countable choice - see the Escardo-Knapp reference above.

End of digression.

The set of quasidecidable propositions, if it exists, is the smallest
collection of propositions containing ๐Ÿ˜ and ๐Ÿ™ and closed under
countable joins.

Exercise. It exists under propositional resizing assumptions (just
take the intersection of all subsets with ๐Ÿ˜ and ๐Ÿ™ as members and
closed under countable joins). This exercise is solved below in the
submodule quasidecidability-construction-from-resizing.

We now assume that there is a such a smallest collection of types,
called quasidecidable, satisfying the above closure property. The
types in this collection are automatically propositions. The
minimality condition of the collection amounts to an induction
principle.

We recall the above conventions:

  * ๐“ฃ is the universe where the quasidecidable truth values live.

    Typically ๐“ฃ will be ๐“คโ‚€ or ๐“คโ‚.

  * ๐“š is the universe where the knowledge they are quasidecidable lives.

    Typically ๐“š will be ๐“ฃ or ๐“ฃโบ.

\begin{code}

module hypothetical-quasidecidability
        {๐“ฃ ๐“š : Universe}
        (qde : quasidecidable-propositions-exist ๐“ฃ ๐“š)
       where

\end{code}

As promised, the quasidecidable types are automatically propositions,
with a proof by induction:

\begin{code}

 open quasidecidable-propositions-exist qde

 quasidecidable-types-are-props : โˆ€ P โ†’ is-quasidecidable P โ†’ is-prop P
 quasidecidable-types-are-props = quasidecidable-induction
                                   is-prop
                                   (ฮป _ โ†’ being-prop-is-prop fe)
                                   ๐Ÿ˜-is-prop
                                   ๐Ÿ™-is-prop
                                   (ฮป P ฯ† โ†’ โˆƒ-is-prop)

\end{code}

We collect the quasidecidable propositions in the type ๐“ :

\begin{code}

 ๐“  : ๐“ฃ โบ โŠ” ๐“š ฬ‡
 ๐“  = ฮฃ P ๊ž‰ ๐“ฃ ฬ‡ , is-quasidecidable P

 _is-true : ๐“  โ†’ ๐“ฃ ฬ‡
 _is-true (P , i) = P

 being-true-is-quasidecidable : (๐•ก : ๐“ ) โ†’ is-quasidecidable (๐•ก is-true)
 being-true-is-quasidecidable (P , i) = i

 being-true-is-prop : (๐•ก : ๐“ ) โ†’ is-prop (๐•ก is-true)
 being-true-is-prop (P , i) = quasidecidable-types-are-props P i

 ๐“ -to-ฮฉ : ๐“  โ†’ ฮฉ ๐“ฃ
 ๐“ -to-ฮฉ (P , i) = P , quasidecidable-types-are-props P i

 ๐“ -to-ฮฉ-is-embedding : is-embedding ๐“ -to-ฮฉ
 ๐“ -to-ฮฉ-is-embedding = Natฮฃ-is-embedding
                        is-quasidecidable
                        is-prop
                        ฮถ
                        ฮถ-is-embedding
  where
   ฮถ : (P : ๐“ฃ ฬ‡ ) โ†’ is-quasidecidable P โ†’ is-prop P
   ฮถ = quasidecidable-types-are-props

   ฮถ-is-embedding : (P : ๐“ฃ ฬ‡ ) โ†’ is-embedding (ฮถ P)
   ฮถ-is-embedding P = maps-of-props-are-embeddings (ฮถ P)
                       (being-quasidecidable-is-prop P)
                       (being-prop-is-prop fe)

 ๐“ -is-set : is-set ๐“ 
 ๐“ -is-set = subtypes-of-sets-are-sets ๐“ -to-ฮฉ
             ๐“ -to-ฮฉ-is-embedding
             (ฮฉ-is-set fe pe)

 โŠฅ : ๐“ 
 โŠฅ = ๐Ÿ˜ , ๐Ÿ˜-is-quasidecidable

 โŠค : ๐“ 
 โŠค = ๐Ÿ™ , ๐Ÿ™-is-quasidecidable

 โ‹ : (โ„• โ†’ ๐“ ) โ†’ ๐“ 
 โ‹ ๐•ก = (โˆƒ n ๊ž‰ โ„• , ๐•ก n is-true) ,
       quasidecidable-closed-under-ฯ‰-joins
        (ฮป n โ†’ ๐•ก n is-true)
        (ฮป n โ†’ being-true-is-quasidecidable (๐•ก n))

\end{code}

We formulate and prove induction on ๐“  in two different, equivalent
ways.

\begin{code}

 ๐“ -induction : (G : ๐“  โ†’ ๐“ค ฬ‡ )
             โ†’ ((๐•ก : ๐“ ) โ†’ is-prop (G ๐•ก))
             โ†’ G โŠฅ
             โ†’ G โŠค
             โ†’ ((๐•ก : โ„• โ†’ ๐“ ) โ†’ ((n : โ„•) โ†’ G (๐•ก n)) โ†’ G (โ‹ ๐•ก))
             โ†’ (๐•ก : ๐“ ) โ†’ G ๐•ก
 ๐“ -induction {๐“ค} G G-is-prop-valued gโ‚€ gโ‚ gฯ‰ (P , i) = ฮณ
  where
   F :  ๐“ฃ ฬ‡ โ†’ ๐“š โŠ” ๐“ค ฬ‡
   F P = ฮฃ j ๊ž‰ is-quasidecidable P , G (P , j)

   F-is-prop-valued : โˆ€ P โ†’ is-prop (F P)
   F-is-prop-valued P = ฮฃ-is-prop
                         (being-quasidecidable-is-prop P)
                         (ฮป j โ†’ G-is-prop-valued (P , j))

   Fโ‚€ : F ๐Ÿ˜
   Fโ‚€ = ๐Ÿ˜-is-quasidecidable , gโ‚€

   Fโ‚ : F ๐Ÿ™
   Fโ‚ = ๐Ÿ™-is-quasidecidable , gโ‚

   Fฯ‰ : (Q : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (Q n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , Q n)
   Fฯ‰ Q ฯ† = quasidecidable-closed-under-ฯ‰-joins Q (ฮป n โ†’ prโ‚ (ฯ† n)) ,
            gฯ‰ (ฮป n โ†’ (Q n , prโ‚ (ฯ† n))) (ฮป n โ†’ prโ‚‚ (ฯ† n))

   ฮด : ฮฃ j ๊ž‰ is-quasidecidable P , G (P , j)
   ฮด = quasidecidable-induction F F-is-prop-valued Fโ‚€ Fโ‚ Fฯ‰ P i

   j : is-quasidecidable P
   j = prโ‚ ฮด

   g : G (P , j)
   g = prโ‚‚ ฮด

   r : j ๏ผ i
   r = being-quasidecidable-is-prop P j i

   ฮณ : G (P , i)
   ฮณ = transport (ฮป - โ†’ G (P , -)) r g


 ๐“ -induction' : (๐“– : ๐“  โ†’ ฮฉ ๐“ค)
              โ†’ โŠฅ โˆˆ ๐“–
              โ†’ โŠค โˆˆ ๐“–
              โ†’ ((๐•ก : โ„• โ†’ ๐“ ) โ†’ ((n : โ„•) โ†’ ๐•ก n โˆˆ ๐“–) โ†’ โ‹ ๐•ก โˆˆ ๐“–)
              โ†’ (๐•ก : ๐“ ) โ†’ ๐•ก โˆˆ ๐“–
 ๐“ -induction' {๐“ค} ๐“– = ๐“ -induction (ฮป ๐•ก โ†’ prโ‚ (๐“– ๐•ก)) (ฮป ๐•ก โ†’ prโ‚‚ (๐“– ๐•ก))

\end{code}

The quasidecidable propositions form a dominance, with a proof by
quasidecidable-induction. The main dominance condition generalizes
closure under binary products (that is, conjunctions, or meets):

\begin{code}

 quasidecidable-types-form-a-dominance
  : (P : ๐“ฃ ฬ‡ )
  โ†’ is-quasidecidable P
  โ†’ (Q : ๐“ฃ ฬ‡ )
  โ†’ (P โ†’ is-quasidecidable Q)
  โ†’ is-quasidecidable (P ร— Q)
 quasidecidable-types-form-a-dominance
  = quasidecidable-induction F F-is-prop-valued Fโ‚€ Fโ‚ Fฯ‰
  where
   F : ๐“ฃ ฬ‡ โ†’ ๐“ฃ โบ โŠ” ๐“š ฬ‡
   F P = (Q : ๐“ฃ ฬ‡ ) โ†’ (P โ†’ is-quasidecidable Q) โ†’ is-quasidecidable (P ร— Q)

   F-is-prop-valued : (P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F P)
   F-is-prop-valued P = ฮ โ‚‚-is-prop fe
                         (ฮป Q _ โ†’ being-quasidecidable-is-prop (P ร— Q))

   Fโ‚€ : F ๐Ÿ˜
   Fโ‚€ Q ฯ† = transport is-quasidecidable r ๐Ÿ˜-is-quasidecidable
    where
     r : ๐Ÿ˜ ๏ผ ๐Ÿ˜ ร— Q
     r = pe ๐Ÿ˜-is-prop (ฮป (z , q) โ†’ ๐Ÿ˜-elim z) unique-from-๐Ÿ˜ prโ‚

   Fโ‚ : F ๐Ÿ™
   Fโ‚ Q ฯ† = transport is-quasidecidable r (ฯ† โ‹†)
    where
     i : is-prop Q
     i = quasidecidable-types-are-props Q (ฯ† โ‹†)

     r : Q ๏ผ ๐Ÿ™ ร— Q
     r = pe i (ร—-is-prop ๐Ÿ™-is-prop i) (ฮป q โ†’ (โ‹† , q)) prโ‚‚

   Fฯ‰ :  (P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n)
   Fฯ‰ P f Q ฯ† = ฮณ
    where
     ฯ†' : (n : โ„•) โ†’ P n โ†’ is-quasidecidable Q
     ฯ†' n p = ฯ† โˆฃ n , p โˆฃ

     a : (n : โ„•) โ†’ is-quasidecidable (P n ร— Q)
     a n = f n Q (ฯ†' n)

     b : is-quasidecidable (โˆƒ n ๊ž‰ โ„• , P n ร— Q)
     b = quasidecidable-closed-under-ฯ‰-joins (ฮป n โ†’ P n ร— Q) a

     c : (โˆƒ n ๊ž‰ โ„• , P n ร— Q) โ†’ ((โˆƒ n ๊ž‰ โ„• , P n) ร— Q)
     c s = (t , q)
      where
       t : โˆƒ n ๊ž‰ โ„• , P n
       t = โˆฅโˆฅ-rec โˆƒ-is-prop (ฮป (n , (p , q)) โ†’ โˆฃ n , p โˆฃ) s

       i : is-prop Q
       i = quasidecidable-types-are-props Q (ฯ† t)

       q : Q
       q = โˆฅโˆฅ-rec i (ฮป (n , (p , q)) โ†’ q) s

     d : ((โˆƒ n ๊ž‰ โ„• , P n) ร— Q) โ†’ (โˆƒ n ๊ž‰ โ„• , P n ร— Q)
     d (t , q) = โˆฅโˆฅ-functor (ฮป (n , p) โ†’ n , (p , q)) t

     r : (โˆƒ n ๊ž‰ โ„• , P n ร— Q) ๏ผ ((โˆƒ n ๊ž‰ โ„• , P n) ร— Q)
     r = pe โˆƒ-is-prop
            (ร—-prop-criterion
              ((ฮป _ โ†’ โˆƒ-is-prop) ,
              (ฮป e โ†’ quasidecidable-types-are-props Q (ฯ† e))))
            c
            d

     ฮณ : is-quasidecidable ((โˆƒ n ๊ž‰ โ„• , P n) ร— Q)
     ฮณ = transport is-quasidecidable r b

\end{code}

This condition automatically implies closure under ฮฃ, or joins indexed
by quasidecidable propositions:

\begin{code}

 quasidecidable-closed-under-ฮฃ
  : (P : ๐“ฃ ฬ‡ )
  โ†’ (Q : P โ†’ ๐“ฃ ฬ‡ )
  โ†’ is-quasidecidable P
  โ†’ ((p : P) โ†’ is-quasidecidable (Q p))
  โ†’ is-quasidecidable (ฮฃ Q)
 quasidecidable-closed-under-ฮฃ
  = D3-and-D5'-give-D5 pe is-quasidecidable
     (quasidecidable-types-are-props)
     (ฮป P Q' i โ†’ quasidecidable-types-form-a-dominance P i Q')

\end{code}

Notice that ฮฃ Q is equivalent to โˆƒ Q as quasidecidable types are
propositions, and propositions are closed under ฮฃ:

\begin{code}

 NB : (P : ๐“ฃ ฬ‡ )
    โ†’ (Q : P โ†’ ๐“ฃ ฬ‡ )
    โ†’ is-quasidecidable P
    โ†’ ((p : P) โ†’ is-quasidecidable (Q p))
    โ†’ ฮฃ Q โ‰ƒ โˆƒ Q
 NB P Q i j = logically-equivalent-props-are-equivalent
               k
               โˆƒ-is-prop
               (ฮป (p , q) โ†’ โˆฃ p , q โˆฃ)
               (โˆฅโˆฅ-rec k id)
  where
   k : is-prop (ฮฃ Q)
   k = quasidecidable-types-are-props
        (ฮฃ Q)
        (quasidecidable-closed-under-ฮฃ P Q i j)

\end{code}

The following summarizes the dominance conditions:

\begin{code}

 quasidecidability-is-dominance : is-dominance is-quasidecidable
 quasidecidability-is-dominance = being-quasidecidable-is-prop ,
                                  quasidecidable-types-are-props ,
                                  ๐Ÿ™-is-quasidecidable ,
                                  quasidecidable-closed-under-ฮฃ
\end{code}

We now give the quasidecidable propositions the structure of a
ฯƒ-sup-lattice. We have already defined โŠฅ, โŠค and โ‹.

\begin{code}

 _โ‰ค_ : ๐“  โ†’ ๐“  โ†’ ๐“ฃ ฬ‡
 ๐•ก โ‰ค ๐•ข = ๐•ก is-true โ†’ ๐•ข is-true

 โ‰ค-is-prop-valued : (๐•ก ๐•ข : ๐“ ) โ†’ is-prop (๐•ก โ‰ค ๐•ข)
 โ‰ค-is-prop-valued ๐•ก ๐•ข = ฮ -is-prop fe (ฮป _ โ†’ being-true-is-prop ๐•ข)

 โ‰ค-refl : (๐•ก : ๐“ ) โ†’ ๐•ก โ‰ค ๐•ก
 โ‰ค-refl ๐•ก = id

 โ‰ค-trans : (๐•ก ๐•ข ๐•ฃ : ๐“ ) โ†’ ๐•ก โ‰ค ๐•ข โ†’ ๐•ข โ‰ค ๐•ฃ โ†’ ๐•ก โ‰ค ๐•ฃ
 โ‰ค-trans ๐•ก ๐•ข ๐•ฃ l m = m โˆ˜ l

 โ‰ค-antisym : (๐•ก ๐•ข : ๐“ ) โ†’ ๐•ก โ‰ค ๐•ข โ†’ ๐•ข โ‰ค ๐•ก โ†’ ๐•ก ๏ผ ๐•ข
 โ‰ค-antisym ๐•ก ๐•ข l m = to-subtype-๏ผ
                      being-quasidecidable-is-prop
                      (pe (being-true-is-prop ๐•ก) (being-true-is-prop ๐•ข) l m)

 โŠฅ-is-minimum : (๐•ก : ๐“ ) โ†’ โŠฅ โ‰ค ๐•ก
 โŠฅ-is-minimum ๐•ก = unique-from-๐Ÿ˜

 โŠค-is-maximum : (๐•ก : ๐“ ) โ†’ ๐•ก โ‰ค โŠค
 โŠค-is-maximum ๐•ก = unique-to-๐Ÿ™

 โ‹-is-ub : (๐•ก : โ„• โ†’ ๐“ ) โ†’ (n : โ„•) โ†’ ๐•ก n โ‰ค โ‹ ๐•ก
 โ‹-is-ub ๐•ก n = (ฮป p โ†’ โˆฃ n , p โˆฃ)

 โ‹-is-lb-of-ubs : (๐•ก : โ„• โ†’ ๐“ ) โ†’ (๐•ฆ : ๐“ ) โ†’ ((n : โ„•) โ†’ ๐•ก n โ‰ค ๐•ฆ) โ†’ โ‹ ๐•ก โ‰ค ๐•ฆ
 โ‹-is-lb-of-ubs ๐•ก (U , i) ฯ† = ฮณ
  where
   ฮด : (ฮฃ n ๊ž‰ โ„• , ๐•ก n is-true) โ†’ U
   ฮด (n , p) = ฯ† n p

   ฮณ : (โˆƒ n ๊ž‰ โ„• , ๐•ก n is-true) โ†’ U
   ฮณ = โˆฅโˆฅ-rec (quasidecidable-types-are-props U i) ฮด

\end{code}

Putting these axioms together we get the ฯƒ-sup-lattice of
quasidecidable propositions:

\begin{code}

 open import OrderedTypes.sigma-sup-lattice fe

 QD : ฯƒ-SupLat (๐“ฃ โบ โŠ” ๐“š) ๐“ฃ
 QD = ๐“  ,
     (โŠฅ , โ‹) ,
     _โ‰ค_ ,
     โ‰ค-is-prop-valued ,
     โ‰ค-refl ,
     โ‰ค-trans ,
     โ‰ค-antisym ,
     โŠฅ-is-minimum ,
     โ‹-is-ub ,
     โ‹-is-lb-of-ubs

\end{code}

We now show that QD is the free ฯƒ-sup-lattice on one generator. For
this purpose, we assume that we are give a ฯƒ-sup-lattice ๐“ with a
distinguished element t.

\begin{code}

 module _ {๐“ค ๐“ฅ : Universe}
          (๐“ : ฯƒ-SupLat ๐“ค ๐“ฅ)
          (t : โŸจ ๐“ โŸฉ)
        where

\end{code}

We introduce some abbreviations, private to this anonymous module, for
notational convenience:

\begin{code}

  private

    A = โŸจ ๐“ โŸฉ
    โŠฅ' = โŠฅโŸจ ๐“ โŸฉ
    โ‹' = โ‹โŸจ ๐“ โŸฉ
    _โ‰ค'_ : A โ†’ A โ†’ ๐“ฅ ฬ‡
    a โ‰ค' b = a โ‰คโŸจ ๐“ โŸฉ b

\end{code}

And then, again by ๐“ -induction, there is at most one homomorphism from
๐“  to ๐“:

\begin{code}

  at-most-one-hom : (g h : ๐“  โ†’ A)
                  โ†’ is-ฯƒ-suplat-hom QD ๐“ g
                  โ†’ is-ฯƒ-suplat-hom QD ๐“ h
                  โ†’ g โŠค ๏ผ t
                  โ†’ h โŠค ๏ผ t
                  โ†’ g ๏ผ h
  at-most-one-hom g h (gโŠฅ , gโ‹) (hโŠฅ , hโ‹) gโŠค hโŠค = dfunext fe r
   where
    iโ‚€ = g โŠฅ ๏ผโŸจ gโŠฅ โŸฉ
         โŠฅ'  ๏ผโŸจ hโŠฅ โปยน โŸฉ
         h โŠฅ โˆŽ

    iโ‚ = g โŠค ๏ผโŸจ gโŠค โŸฉ
         t   ๏ผโŸจ hโŠค โปยน โŸฉ
         h โŠค โˆŽ

    iฯ‰ : (๐•ก : โ„• โ†’ ๐“ ) โ†’ ((n : โ„•) โ†’ g (๐•ก n) ๏ผ h (๐•ก n)) โ†’ g (โ‹ ๐•ก) ๏ผ h (โ‹ ๐•ก)
    iฯ‰ ๐•ก ฯ† = g (โ‹ ๐•ก)          ๏ผโŸจ gโ‹ ๐•ก โŸฉ
             โ‹' (n โ†ฆ g (๐•ก n)) ๏ผโŸจ ap โ‹' (dfunext fe ฯ†) โŸฉ
             โ‹' (n โ†ฆ h (๐•ก n)) ๏ผโŸจ (hโ‹ ๐•ก)โปยน โŸฉ
             h (โ‹ ๐•ก)          โˆŽ

    r : g โˆผ h
    r = ๐“ -induction (ฮป ๐•ก โ†’ g ๐•ก ๏ผ h ๐•ก) (ฮป ๐•ก โ†’ โŸจ ๐“ โŸฉ-is-set {g ๐•ก} {h ๐•ก}) iโ‚€ iโ‚ iฯ‰

\end{code}

The condition in the conclusion of the following lemma says that the
element a : A is the least upper bound of the (weakly) constant family
ฮป (p : P) โ†’ t.  Because least upper bounds are unique when they
exist, the type in the conclusion of the lemma is a proposition. This
is crucial because the induction principle can be applied to
proposition-valued predicates only.

\begin{code}

  freeness-lemma : (P : ๐“ฃ ฬ‡ )
                 โ†’ is-quasidecidable P
                 โ†’ ฮฃ a ๊ž‰ A , (P โ†’ t โ‰ค' a) ร— ((u : A) โ†’ (P โ†’ t โ‰ค' u) โ†’ a โ‰ค' u)
  freeness-lemma = quasidecidable-induction F F-is-prop-valued Fโ‚€ Fโ‚ Fฯ‰
   where
    F : ๐“ฃ ฬ‡ โ†’ ๐“ฃ โŠ” ๐“ค โŠ” ๐“ฅ ฬ‡
    F P = ฮฃ a ๊ž‰ A , (P โ†’ t โ‰ค' a) ร— ((u : A) โ†’ (P โ†’ t โ‰ค' u) โ†’ a โ‰ค' u)

    F-is-prop-valued : (P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F P)
    F-is-prop-valued P (a , ฮฑ , ฮฒ) (a' , ฮฑ' , ฮฒ') = ฮณ
     where
      j : (a : A) โ†’ is-prop ((P โ†’ t โ‰ค' a) ร— ((u : A) โ†’ (P โ†’ t โ‰ค' u) โ†’ a โ‰ค' u))
      j a = ร—-is-prop
             (ฮ -is-prop fe (ฮป _ โ†’ โŸจ ๐“ โŸฉ-order-is-prop-valued t a))
             (ฮ โ‚‚-is-prop fe (ฮป u _ โ†’ โŸจ ๐“ โŸฉ-order-is-prop-valued a u))

      r : a ๏ผ a'
      r = โŸจ ๐“ โŸฉ-antisym a a' (ฮฒ  a' ฮฑ') (ฮฒ' a ฮฑ)

      ฮณ : (a , ฮฑ , ฮฒ) ๏ผ (a' , ฮฑ' , ฮฒ')
      ฮณ = to-subtype-๏ผ j r

    Fโ‚€ : F ๐Ÿ˜
    Fโ‚€ = โŠฅ' , unique-from-๐Ÿ˜ , (ฮป u ฯˆ โ†’ โŸจ ๐“ โŸฉ-โŠฅ-is-minimum u)

    Fโ‚ : F ๐Ÿ™
    Fโ‚ = t , (ฮป _ โ†’ โŸจ ๐“ โŸฉ-refl t) , (ฮป u ฯˆ โ†’ ฯˆ โ‹†)

    Fฯ‰ :  (P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n)
    Fฯ‰ P ฯ† = aโˆž , ฮฑโˆž , ฮฒโˆž
     where
      a : โ„• โ†’ A
      a n = prโ‚ (ฯ† n)

      ฮฑ : (n : โ„•) โ†’ P n โ†’ t โ‰ค' a n
      ฮฑ n = prโ‚ (prโ‚‚ (ฯ† n))

      ฮฒ : (n : โ„•) (u : A) โ†’ (P n โ†’ t โ‰ค' u) โ†’ a n โ‰ค' u
      ฮฒ n = prโ‚‚ (prโ‚‚ (ฯ† n))

      aโˆž : A
      aโˆž = โ‹' a

      ฮฑโˆž : (โˆƒ n ๊ž‰ โ„• , P n) โ†’ t โ‰ค' aโˆž
      ฮฑโˆž = โˆฅโˆฅ-rec (โŸจ ๐“ โŸฉ-order-is-prop-valued t aโˆž)  ฮฑโˆž'
       where
        ฮฑโˆž' : (ฮฃ n ๊ž‰ โ„• , P n) โ†’ t โ‰ค' aโˆž
        ฮฑโˆž' (n , p) = โŸจ ๐“ โŸฉ-trans t (a n) aโˆž (ฮฑ n p) (โŸจ ๐“ โŸฉ-โ‹-is-ub a n)

      ฮฒโˆž : (u : A) โ†’ ((โˆƒ n ๊ž‰ โ„• , P n) โ†’ t โ‰ค' u) โ†’ aโˆž โ‰ค' u
      ฮฒโˆž u ฯˆ = โŸจ ๐“ โŸฉ-โ‹-is-lb-of-ubs a u l
       where
        l : (n : โ„•) โ†’ a n โ‰ค' u
        l n = ฮฒ n u (ฮป p โ†’ ฯˆ โˆฃ n , p โˆฃ)

\end{code}

We now have enough constructions and lemmas to show that the type of
quasidecidable propositions is the free ฯƒ-sup-lattice on one
generator. It remains to show that the function ๐“  โ†’ A induced by the
initiality lemma is a ฯƒ-sup-lattice homomorphism.

\begin{code}

  QD-is-free-ฯƒ-SupLat : โˆƒ! f ๊ž‰ (โŸจ QD โŸฉ โ†’ โŸจ ๐“ โŸฉ) , is-ฯƒ-suplat-hom QD ๐“ f
                                                ร— (f โŠค ๏ผ t)
  QD-is-free-ฯƒ-SupLat = ฮณ
   where
    f : ๐“  โ†’ A
    f (P , i) = prโ‚ (freeness-lemma P i)

    ฮฑ : (๐•ก : ๐“ ) โ†’ ๐•ก is-true โ†’ t โ‰ค' f ๐•ก
    ฮฑ (P , i) = prโ‚ (prโ‚‚ (freeness-lemma P i))

    ฮฒ : (๐•ก : ๐“ ) โ†’ ((u : A) โ†’ (๐•ก is-true โ†’ t โ‰ค' u) โ†’ f ๐•ก โ‰ค' u)
    ฮฒ (P , i) = prโ‚‚ (prโ‚‚ (freeness-lemma P i))

\end{code}

The conditions ฮฑ and ฮฒ on f are crucial to prove that f is indeed a
homomorphism, and are all we need for that purpose.

\begin{code}

    fโŠค : f โŠค ๏ผ t
    fโŠค = โŸจ ๐“ โŸฉ-antisym (f โŠค) t (ฮฒ โŠค t (ฮป _ โ†’ โŸจ ๐“ โŸฉ-refl t)) (ฮฑ โŠค โ‹†)

    fโŠฅ : f โŠฅ ๏ผ โŠฅ'
    fโŠฅ = โŸจ ๐“ โŸฉ-antisym (f โŠฅ) โŠฅ' (ฮฒ โŠฅ โŠฅ' unique-from-๐Ÿ˜) (โŸจ ๐“ โŸฉ-โŠฅ-is-minimum (f โŠฅ))

    f-is-monotone : (๐•ก ๐•ข : ๐“ ) โ†’ ๐•ก โ‰ค ๐•ข โ†’ f ๐•ก โ‰ค' f ๐•ข
    f-is-monotone ๐•ก ๐•ข l = ฮฒ ๐•ก (f ๐•ข) (ฮป p โ†’ ฮฑ ๐•ข (l p))

    fโ‹ : (๐•ก : โ„• โ†’ ๐“ ) โ†’ f (โ‹ ๐•ก) ๏ผ โ‹' (n โ†ฆ f (๐•ก n))
    fโ‹ ๐•ก = โŸจ ๐“ โŸฉ-antisym (f (โ‹ ๐•ก)) (โ‹' (n โ†ฆ f (๐•ก n))) v w
      where
       ฯ†' : (ฮฃ n ๊ž‰ โ„• , ๐•ก n is-true) โ†’ t โ‰ค' โ‹' (n โ†ฆ f (๐•ก n))
       ฯ†' (n , p) = โŸจ ๐“ โŸฉ-trans t (f (๐•ก n)) (โ‹' (n โ†ฆ f (๐•ก n))) r s
        where
         r : t โ‰ค' f (๐•ก n)
         r = ฮฑ (๐•ก n) p

         s : f (๐•ก n) โ‰ค' โ‹' (n โ†ฆ f (๐•ก n))
         s = โŸจ ๐“ โŸฉ-โ‹-is-ub (n โ†ฆ f (๐•ก n)) n

       ฯ† : (โˆƒ n ๊ž‰ โ„• , ๐•ก n is-true) โ†’ t โ‰ค' โ‹' (n โ†ฆ f (๐•ก n))
       ฯ† = โˆฅโˆฅ-rec (โŸจ ๐“ โŸฉ-order-is-prop-valued _ _) ฯ†'

       v : f (โ‹ ๐•ก) โ‰ค' โ‹' (n โ†ฆ f (๐•ก n))
       v = ฮฒ (โ‹ ๐•ก) (โ‹' (n โ†ฆ f (๐•ก n))) ฯ†

       l : (n : โ„•) โ†’ ๐•ก n โ‰ค โ‹ ๐•ก
       l = โ‹-is-ub ๐•ก

       m : (n : โ„•) โ†’ f (๐•ก n) โ‰ค' f (โ‹ ๐•ก)
       m n = f-is-monotone (๐•ก n) (โ‹ ๐•ก) (l n)

       w : โ‹' (n โ†ฆ f (๐•ก n)) โ‰ค' f (โ‹ ๐•ก)
       w = โŸจ ๐“ โŸฉ-โ‹-is-lb-of-ubs (n โ†ฆ f (๐•ก n)) (f (โ‹ ๐•ก)) m

\end{code}

And then we are done:

\begin{code}

    f-is-hom : is-ฯƒ-suplat-hom QD ๐“ f
    f-is-hom = fโŠฅ , fโ‹

    ฮณ : โˆƒ! f ๊ž‰ (โŸจ QD โŸฉ โ†’ A) , is-ฯƒ-suplat-hom QD ๐“ f
                            ร— (f โŠค ๏ผ t)
    ฮณ = (f , f-is-hom , fโŠค) ,
        (ฮป (g , g-is-hom , gโŠค) โ†’ to-subtype-๏ผ
                                  (ฮป f โ†’ ร—-is-prop
                                          (being-ฯƒ-suplat-hom-is-prop QD ๐“ f)
                                          โŸจ ๐“ โŸฉ-is-set)
                                  (at-most-one-hom f g f-is-hom g-is-hom fโŠค gโŠค))
\end{code}

This concludes the module hypothetical-quasidecidability.

We discussed above the specification of the notion of quasidecidable
proposition. But can we define or construct it? Yes if, for example,
propositional resizing is available:

\begin{code}

module quasidecidability-construction-from-resizing
        (๐“ฃ ๐“š : Universe)
        (ฯ : Propositional-Resizing)
       where

 open import UF.Powerset-Resizing fe ฯ

\end{code}

This assumption says that any proposition in the universe ๐“ค is
equivalent to some proposition in the universe ๐“ฅ, for any two
universes ๐“ค and ๐“ฅ.

The crucial fact exploited here is that intersections of collections
of subcollections ๐“ : ๐“Ÿ (๐“Ÿ X) exist under propositional resizing.

To define the type of quasi-decidable propositions, we take the
intersection of the collections of types satisfying the following
closure condition:

\begin{code}

 QD-closed-types : (๐“ค ฬ‡ โ†’ ฮฉ ๐“ฅ) โ†’ ฮฉ (๐“ค โบ โŠ” ๐“ฅ)
 QD-closed-types {๐“ค} {๐“ฅ} A = closure-condition , i
  where
   closure-condition : ๐“ค โบ โŠ” ๐“ฅ ฬ‡
   closure-condition =
      (๐Ÿ˜ โˆˆ A)
    ร— (๐Ÿ™ โˆˆ A)
    ร— ((P : โ„• โ†’ ๐“ค ฬ‡ ) โ†’ ((n : โ„•) โ†’ P n โˆˆ A) โ†’ (โˆƒ n ๊ž‰ โ„• , P n) โˆˆ A)

   i : is-prop closure-condition
   i = ร—โ‚ƒ-is-prop
        (โˆˆ-is-prop A ๐Ÿ˜)
        (โˆˆ-is-prop A ๐Ÿ™)
        (ฮ โ‚‚-is-prop fe (ฮป P _ โ†’ โˆˆ-is-prop A (โˆƒ n ๊ž‰ โ„• , P n)))

 is-quasidecidable : ๐“ฃ ฬ‡ โ†’ ๐“š ฬ‡
 is-quasidecidable P = P โˆˆ โ‹‚ QD-closed-types

 being-quasidecidable-is-prop : โˆ€ P โ†’ is-prop (is-quasidecidable P)
 being-quasidecidable-is-prop = โˆˆ-is-prop (โ‹‚ QD-closed-types)

 ๐Ÿ˜-is-quasidecidable : is-quasidecidable ๐Ÿ˜
 ๐Ÿ˜-is-quasidecidable = to-โ‹‚ QD-closed-types ๐Ÿ˜ (ฮป A (cโ‚€ , cโ‚ , cฯ‰) โ†’ cโ‚€)

 ๐Ÿ™-is-quasidecidable : is-quasidecidable ๐Ÿ™
 ๐Ÿ™-is-quasidecidable = to-โ‹‚ QD-closed-types ๐Ÿ™ (ฮป A (cโ‚€ , cโ‚ , cฯ‰) โ†’ cโ‚)

 quasidecidable-closed-under-ฯ‰-joins : (P : โ„• โ†’ ๐“ฃ ฬ‡ )
                                     โ†’ ((n : โ„•) โ†’ is-quasidecidable (P n))
                                     โ†’ is-quasidecidable (โˆƒ n ๊ž‰ โ„• , P n)
 quasidecidable-closed-under-ฯ‰-joins P ฯ† = to-โ‹‚ QD-closed-types (โˆƒ P) vi
  where
   i : (n : โ„•) โ†’ P n โˆˆ โ‹‚ QD-closed-types
   i = ฯ†

   ii : (n : โ„•) (A : ๐“ฃ ฬ‡ โ†’ ฮฉ ๐“š) โ†’ A โˆˆ QD-closed-types โ†’ P n โˆˆ A
   ii n = from-โ‹‚ QD-closed-types (P n) (i n)

   iii : (A : ๐“ฃ ฬ‡ โ†’ ฮฉ ๐“š) โ†’ A โˆˆ QD-closed-types โ†’ โˆƒ P โˆˆ A
   iii A (cโ‚ , cโ‚‚ , cฯ‰) = cฯ‰ P (ฮป n โ†’ ii n A (cโ‚ , cโ‚‚ , cฯ‰))

   iv : โˆƒ P โˆˆ โ‹‚ QD-closed-types
   iv = to-โ‹‚ QD-closed-types (โˆƒ P) iii

   vi : (A : ๐“ฃ ฬ‡ โ†’ ฮฉ ๐“š) โ†’ A โˆˆ QD-closed-types โ†’ โˆƒ P โˆˆ A
   vi = from-โ‹‚ QD-closed-types (โˆƒ P) iv

\end{code}

The full induction principle requires a further application of
resizing. We first prove a particular case and then reduce the general
case to this particular case.

\begin{code}

 quasidecidable-inductionโ‚€
  : (F : ๐“ฃ ฬ‡ โ†’ ๐“š ฬ‡ )
  โ†’ ((P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F P))
  โ†’ F ๐Ÿ˜
  โ†’ F ๐Ÿ™
  โ†’ ((P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n))
  โ†’ (P : ๐“ฃ ฬ‡ ) โ†’  is-quasidecidable P โ†’ F P
 quasidecidable-inductionโ‚€ F F-is-prop-valued Fโ‚€ Fโ‚ Fฯ‰ P P-is-quasidecidable
  = ฮณ
  where
   A : (P : ๐“ฃ ฬ‡ ) โ†’ ฮฉ ๐“š
   A P = F P , F-is-prop-valued P

   A-is-QD-closed : A โˆˆ QD-closed-types
   A-is-QD-closed = Fโ‚€ , Fโ‚ , Fฯ‰

   pqd : P โˆˆ โ‹‚ QD-closed-types
   pqd = P-is-quasidecidable

   ฮด : P โˆˆ A
   ฮด = from-โ‹‚ QD-closed-types P pqd A A-is-QD-closed

   ฮณ : F P
   ฮณ = ฮด

\end{code}

To get the full induction principle we apply the above particular case
with back and forth resizing coercions. The point is that now F has
values in any universe ๐“ค rather than the universe ๐“š as above.

\begin{code}

 quasidecidable-induction
  : {๐“ค : Universe}
    (F : ๐“ฃ ฬ‡ โ†’ ๐“ค ฬ‡ )
  โ†’ ((P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F P))
  โ†’ F ๐Ÿ˜
  โ†’ F ๐Ÿ™
  โ†’ ((P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n))
  โ†’ (P : ๐“ฃ ฬ‡ ) โ†’ is-quasidecidable P โ†’ F P
 quasidecidable-induction {๐“ค} F F-is-prop Fโ‚€ Fโ‚ Fฯ‰ P P-is-quasidecidable = ฮณ
  where
   i = F-is-prop

   F' : ๐“ฃ ฬ‡ โ†’ ๐“š ฬ‡
   F' P = resize ฯ (F P) (i P)

   i' : (P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F' P)
   i' P = resize-is-prop ฯ (F P) (i P)

   ฮด : F' P
   ฮด = quasidecidable-inductionโ‚€
        F'
        i'
        (to-resize ฯ (F ๐Ÿ˜) (i ๐Ÿ˜) Fโ‚€)
        (to-resize ฯ (F ๐Ÿ™) (i ๐Ÿ™) Fโ‚)
        (ฮป P Q โ†’ to-resize ฯ
                  (F (โˆƒ P))
                  (i (โˆƒ P))
                  (Fฯ‰ P (ฮป n โ†’ from-resize ฯ
                                (F (P n))
                                (i (P n))
                                (Q n))))
        P
        P-is-quasidecidable

   ฮณ : F P
   ฮณ = from-resize ฯ (F P) (i P) ฮด

\end{code}

Hence the free ฯƒ-sup-lattice on one generator exists under
propositional resizing: we simply plug the construction of the
quasidecidable propositions to the above hypothetical development.

\begin{code}

 open OrderedTypes.sigma-sup-lattice fe

 free-ฯƒ-suplat-on-one-generator-exists
  : ฮฃ ๐“ ๊ž‰ ฯƒ-SupLat (๐“ฃ โบ โŠ” ๐“š) ๐“ฃ
  , ฮฃ t ๊ž‰ โŸจ ๐“ โŸฉ
  , ((๐“‘ : ฯƒ-SupLat ๐“ค ๐“ฅ) (u : โŸจ ๐“‘ โŸฉ)
        โ†’ โˆƒ! f ๊ž‰ (โŸจ ๐“ โŸฉ โ†’ โŸจ ๐“‘ โŸฉ) , is-ฯƒ-suplat-hom ๐“ ๐“‘ f
                                  ร— (f t ๏ผ u))
 free-ฯƒ-suplat-on-one-generator-exists {๐“ค} {๐“ฅ}
  = QD , โŠค , QD-is-free-ฯƒ-SupLat
  where
   open hypothetical-quasidecidability
         (quasidecidable-propositions
           is-quasidecidable
           being-quasidecidable-is-prop
           ๐Ÿ˜-is-quasidecidable
           ๐Ÿ™-is-quasidecidable
           quasidecidable-closed-under-ฯ‰-joins
           quasidecidable-induction)

\end{code}

This concludes the module quasidecidability-construction-from-resizing.

The initial ฯƒ-frame can also be constructed as a higher-inductive
type, as is well known.

The ฯƒ-sup-lattice on one generator is automatically the initial
ฯƒ-frame. This is shown below.

TODO. Write in Agda some of the proofs of the above reference with
Cory Knapp, particularly regarding choice. E.g. the semidecidable
properties form a dominance if and only if a certain particular case
of countable choice holds.

TODO. This certain particular case of countable choice holds if and
only if the quasidecidable propositions are semidecidable. This is not
in the paper, but the methods of proof of the paper should apply more
or less directly.

Question. Can we construct the collection of quasidecidable
propositions without resizing and without higher-inductive types other
than propositional truncation?

We now explore the consequences of the hypothetical existence of a
free ฯƒ-sup-lattice on one generator โŠค.

\begin{code}

module hypothetical-free-ฯƒ-SupLat-on-one-generator where

 open import OrderedTypes.sigma-sup-lattice fe

 module assumptions
         {๐“ฃ ๐“š : Universe}
         (๐“ : ฯƒ-SupLat ๐“ฃ ๐“š)
         (โŠค : โŸจ ๐“ โŸฉ)
         (๐“-free : {๐“ฅ ๐“ฆ : Universe} (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ)
                 โ†’ โˆƒ! f ๊ž‰ (โŸจ ๐“ โŸฉ โ†’ โŸจ ๐“‘ โŸฉ) , is-ฯƒ-suplat-hom ๐“ ๐“‘ f
                                          ร— (f โŠค ๏ผ t))
        where

\end{code}

We first introduce some abbreviations:

\begin{code}

  private
   A   = โŸจ ๐“ โŸฉ
   โŠฅ   = โŠฅโŸจ ๐“ โŸฉ
   โ‹  = โ‹โŸจ ๐“ โŸฉ

  _โ‰ค_ : A โ†’ A โ†’ ๐“š ฬ‡
  a โ‰ค b = a โ‰คโŸจ ๐“ โŸฉ b

  ฯƒ-rec : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) โ†’ โŸจ ๐“‘ โŸฉ โ†’ โŸจ ๐“ โŸฉ โ†’ โŸจ ๐“‘ โŸฉ
  ฯƒ-rec ๐“‘ t = prโ‚ (center (๐“-free ๐“‘ t))

  ฯƒ-rec-is-hom : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ)
               โ†’ is-ฯƒ-suplat-hom ๐“ ๐“‘ (ฯƒ-rec ๐“‘ t)
  ฯƒ-rec-is-hom ๐“‘ t = prโ‚ (prโ‚‚ (center (๐“-free ๐“‘ t)))

  ฯƒ-rec-โŠฅ : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ)
          โ†’ ฯƒ-rec ๐“‘ t โŠฅ ๏ผ โŠฅโŸจ ๐“‘ โŸฉ
  ฯƒ-rec-โŠฅ ๐“‘ t = ฯƒ-suplat-hom-โŠฅ ๐“ ๐“‘ (ฯƒ-rec ๐“‘ t) (ฯƒ-rec-is-hom ๐“‘ t)

  ฯƒ-rec-โ‹ : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ) (a : โ„• โ†’ A)
          โ†’ ฯƒ-rec ๐“‘ t (โ‹ a) ๏ผ โ‹โŸจ ๐“‘ โŸฉ (n โ†ฆ ฯƒ-rec ๐“‘ t (a n))
  ฯƒ-rec-โ‹ ๐“‘ t = ฯƒ-suplat-hom-โ‹ ๐“ ๐“‘ (ฯƒ-rec ๐“‘ t) (ฯƒ-rec-is-hom ๐“‘ t)

  ฯƒ-rec-โŠค : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ)
          โ†’ ฯƒ-rec ๐“‘ t โŠค ๏ผ t
  ฯƒ-rec-โŠค ๐“‘ t = prโ‚‚ (prโ‚‚ (center (๐“-free ๐“‘ t)))

  ฯƒ-rec-is-unique : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ)
                    (f : A โ†’ โŸจ ๐“‘ โŸฉ)
                  โ†’ is-ฯƒ-suplat-hom ๐“ ๐“‘ f
                  โ†’ f โŠค ๏ผ t
                  โ†’ ฯƒ-rec ๐“‘ t ๏ผ f
  ฯƒ-rec-is-unique ๐“‘ t f i p = ap prโ‚ (centrality (๐“-free ๐“‘ t) (f , i , p))

  at-most-one-hom : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ)
                    (f g : A โ†’ โŸจ ๐“‘ โŸฉ)
                  โ†’ is-ฯƒ-suplat-hom ๐“ ๐“‘ f
                  โ†’ is-ฯƒ-suplat-hom ๐“ ๐“‘ g
                  โ†’ f โŠค ๏ผ t
                  โ†’ g โŠค ๏ผ t
                  โ†’ f ๏ผ g
  at-most-one-hom ๐“‘ t f g i j p q = ap prโ‚
                                       (singletons-are-props
                                         (๐“-free ๐“‘ t)
                                         (f , i , p)
                                         (g , j , q))
\end{code}

We now establish the induction principle for the free ฯƒ-sup-lattice on
one generator by constructing a ฯƒ-sup-lattice from the property we
want to prove.

\begin{code}

  ฯƒ-induction : (P : A โ†’ ๐“ฅ ฬ‡ )
              โ†’ ((a : A) โ†’ is-prop (P a))
              โ†’ P โŠค
              โ†’ P โŠฅ
              โ†’ ((a : โ„• โ†’ A) โ†’ ((n : โ„•) โ†’ P (a n)) โ†’ P (โ‹ a))
              โ†’ (a : A) โ†’ P a
  ฯƒ-induction {๐“ฅ} P P-is-prop-valued โŠค-closure โŠฅ-closure โ‹-closure = ฮณ
   where
    X = ฮฃ a ๊ž‰ A , P a

    โŠค' โŠฅ' : X
    โŠค' = (โŠค , โŠค-closure)
    โŠฅ' = (โŠฅ , โŠฅ-closure)

    โ‹' : (โ„• โ†’ X) โ†’ X
    โ‹' x = (โ‹ (prโ‚ โˆ˜ x) , โ‹-closure (prโ‚ โˆ˜ x) (prโ‚‚ โˆ˜ x))

    _โ‰ค'_ : X โ†’ X โ†’ ๐“š ฬ‡
    (a , _) โ‰ค' (b , _) = a โ‰ค b

    ๐“‘ : ฯƒ-SupLat (๐“ฃ โŠ” ๐“ฅ) ๐“š
    ๐“‘ = X ,
        (โŠฅ' , โ‹') ,
        _โ‰ค'_ ,
        (ฮป (a , _) (b , _) โ†’ โŸจ ๐“ โŸฉ-order-is-prop-valued a b) ,
        (ฮป (a , _) โ†’ โŸจ ๐“ โŸฉ-refl a) ,
        (ฮป (a , _) (b , _) (c , _) โ†’ โŸจ ๐“ โŸฉ-trans a b c) ,
        (ฮป (a , _) (b , _) l m โ†’ to-subtype-๏ผ
                                  P-is-prop-valued
                                  (โŸจ ๐“ โŸฉ-antisym a b l m)) ,
        (ฮป (a , _) โ†’ โŸจ ๐“ โŸฉ-โŠฅ-is-minimum a) ,
        (ฮป x n โ†’ โŸจ ๐“ โŸฉ-โ‹-is-ub (prโ‚ โˆ˜ x) n) ,
        (ฮป x (u , _) ฯ† โ†’ โŸจ ๐“ โŸฉ-โ‹-is-lb-of-ubs (prโ‚ โˆ˜ x) u ฯ†)

    g : X โ†’ A
    g = prโ‚

    g-is-hom : is-ฯƒ-suplat-hom ๐“‘ ๐“ g
    g-is-hom = refl , (ฮป ๐•’ โ†’ refl)

    h : A โ†’ A
    h = g โˆ˜ ฯƒ-rec ๐“‘ โŠค'

    hโŠค : h โŠค ๏ผ โŠค
    hโŠค = ap g (ฯƒ-rec-โŠค ๐“‘ โŠค')

    h-is-hom : is-ฯƒ-suplat-hom ๐“ ๐“ h
    h-is-hom = โˆ˜-ฯƒ-suplat-hom ๐“ ๐“‘ ๐“ (ฯƒ-rec ๐“‘ โŠค') g (ฯƒ-rec-is-hom ๐“‘ โŠค') g-is-hom

    H : h ๏ผ id
    H = at-most-one-hom ๐“ โŠค h id h-is-hom (id-is-ฯƒ-suplat-hom ๐“) hโŠค refl

    ฮด : (a : A) โ†’ P (h a)
    ฮด a = prโ‚‚ (ฯƒ-rec ๐“‘ โŠค' a)

    ฮณ : (a : A) โ†’ P a
    ฮณ a = transport P (happly H a) (ฮด a)

\end{code}

For example, we see that the generator โŠค is the maximum element by
ฯƒ-induction:

\begin{code}

  โŠค-is-maximum : (a : A) โ†’ a โ‰ค โŠค
  โŠค-is-maximum = ฯƒ-induction
                  (_โ‰ค โŠค)
                  (ฮป a โ†’ โŸจ ๐“ โŸฉ-order-is-prop-valued a โŠค)
                  (โŸจ ๐“ โŸฉ-refl โŠค)
                  (โŸจ ๐“ โŸฉ-โŠฅ-is-minimum โŠค)
                  (ฮป a โ†’ โŸจ ๐“ โŸฉ-โ‹-is-lb-of-ubs a โŠค)
\end{code}

We use the following little lemma a couple of times:

\begin{code}

  โ‹-โŠค : (a : โ„• โ†’ A) (n : โ„•) โ†’ a n ๏ผ โŠค โ†’ โ‹ a ๏ผ โŠค
  โ‹-โŠค a n p = โŸจ ๐“ โŸฉ-antisym (โ‹ a) โŠค
                   (โŠค-is-maximum (โ‹ a))
                   (โŸจ ๐“ โŸฉ-trans โŠค (a n) (โ‹ a)
                          (โŸจ ๐“ โŸฉ-๏ผ-gives-โ‰ค (p โปยน))
                          (โŸจ ๐“ โŸฉ-โ‹-is-ub a n))
\end{code}

We now characterize ฯƒ-rec as a least upper bound, or join. We first
define joins and their basic properties:

\begin{code}

  join-of : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) {I : ๐“ฆ' ฬ‡ } โ†’ (I โ†’ โŸจ ๐“‘ โŸฉ) โ†’ โŸจ ๐“‘ โŸฉ โ†’ ๐“ฅ โŠ” ๐“ฆ โŠ” ๐“ฆ' ฬ‡
  join-of ๐“‘ f x = (โˆ€ i โ†’ f i โ‰คโŸจ ๐“‘ โŸฉ x)
                ร— ((u : โŸจ ๐“‘ โŸฉ) โ†’ (โˆ€ i โ†’ f i โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ x โ‰คโŸจ ๐“‘ โŸฉ u)

  syntax join-of ๐“‘ f x = x is-the-join-of f on ๐“‘

  being-join-is-prop : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ)
                       {I : ๐“ฆ' ฬ‡ }
                       (x : โŸจ ๐“‘ โŸฉ)
                       (f : I โ†’ โŸจ ๐“‘ โŸฉ)
                     โ†’ is-prop (x is-the-join-of f on ๐“‘)
  being-join-is-prop ๐“‘ x f = ร—-is-prop
                              (ฮ -is-prop fe
                                (ฮป i โ†’ โŸจ ๐“‘ โŸฉ-order-is-prop-valued (f i) x))
                              (ฮ โ‚‚-is-prop fe
                                (ฮป u _ โ†’ โŸจ ๐“‘ โŸฉ-order-is-prop-valued x u))

  at-most-one-join : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ)
                     {I : ๐“ฆ' ฬ‡ }
                     (x x' : โŸจ ๐“‘ โŸฉ)
                     (f : I โ†’ โŸจ ๐“‘ โŸฉ)
                   โ†’ x  is-the-join-of f on ๐“‘
                   โ†’ x' is-the-join-of f on ๐“‘
                   โ†’ x ๏ผ x'
  at-most-one-join ๐“‘ x x' f (ฮฑ , ฮฒ) (ฮฑ' , ฮฒ') =
   โŸจ ๐“‘ โŸฉ-antisym x x' (ฮฒ x' ฮฑ') (ฮฒ' x ฮฑ)

\end{code}

We have that the following characterization of (ฯƒ-rec ๐“‘ t a) as the
least upper bound of the weakly constant family ฮป (_ : a ๏ผ โŠค) โ†’ t:

\begin{code}

  ฯƒ-rec-is-join : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ) (a : A)
                โ†’ (ฯƒ-rec ๐“‘ t a) is-the-join-of (ฮป (_ : a ๏ผ โŠค) โ†’ t) on ๐“‘
  ฯƒ-rec-is-join ๐“‘ t a = ฮฑ , ฮฒ
   where
    h : A โ†’ โŸจ ๐“‘ โŸฉ
    h = ฯƒ-rec ๐“‘ t

    ฮฑ : a ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ h a
    ฮฑ p = โŸจ ๐“‘ โŸฉ-๏ผ-gives-โ‰ค (t    ๏ผโŸจ (ฯƒ-rec-โŠค ๐“‘ t)โปยน โŸฉ
                            h โŠค ๏ผโŸจ ap (h) (p โปยน) โŸฉ
                            h a โˆŽ)

    ฮฒ : (u : โŸจ ๐“‘ โŸฉ) โ†’ (a ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ h a โ‰คโŸจ ๐“‘ โŸฉ u
    ฮฒ = ฯƒ-induction
         (ฮป a โ†’ (u : โŸจ ๐“‘ โŸฉ) โ†’ (a ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ h a โ‰คโŸจ ๐“‘ โŸฉ u)
         (ฮป a โ†’ ฮ โ‚‚-is-prop fe (ฮป u p โ†’ โŸจ ๐“‘ โŸฉ-order-is-prop-valued (h a) u))
         ฮฒโŠค
         ฮฒโŠฅ
         ฮฒโ‹
         a
     where
      ฮฒโŠค : (u : โŸจ ๐“‘ โŸฉ) โ†’ (โŠค ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ h โŠค โ‰คโŸจ ๐“‘ โŸฉ u
      ฮฒโŠค u ฯ† = transport
                (ฮป - โ†’ - โ‰คโŸจ ๐“‘ โŸฉ u)
                ((ฯƒ-rec-โŠค ๐“‘ t )โปยน)
                (ฯ† refl)

      ฮฒโŠฅ : (u : โŸจ ๐“‘ โŸฉ) โ†’ (โŠฅ ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ h โŠฅ โ‰คโŸจ ๐“‘ โŸฉ u
      ฮฒโŠฅ u ฯ† = transport
                (ฮป - โ†’ - โ‰คโŸจ ๐“‘ โŸฉ u)
                ((ฯƒ-rec-โŠฅ ๐“‘ t)โปยน)
                (โŸจ ๐“‘ โŸฉ-โŠฅ-is-minimum u)

      ฮฒโ‹ : (c : โ„• โ†’ A)
         โ†’ ((n : โ„•) (u : โŸจ ๐“‘ โŸฉ) โ†’ (c n ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ h (c n) โ‰คโŸจ ๐“‘ โŸฉ u)
         โ†’ (u : โŸจ ๐“‘ โŸฉ) โ†’ (โ‹ c ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ h (โ‹ c) โ‰คโŸจ ๐“‘ โŸฉ u
      ฮฒโ‹ c ฯˆ u ฯ† = transport (ฮป - โ†’ - โ‰คโŸจ ๐“‘ โŸฉ u) ((ฯƒ-rec-โ‹ ๐“‘ t c)โปยน) ฮณ
       where
        ฮณ : โ‹โŸจ ๐“‘ โŸฉ (h โˆ˜ c) โ‰คโŸจ ๐“‘ โŸฉ u
        ฮณ = โŸจ ๐“‘ โŸฉ-โ‹-is-lb-of-ubs
                 (h โˆ˜ c)
                 u
                 (ฮป n โ†’ ฯˆ n u (ฮป (p : c n ๏ผ โŠค) โ†’ ฯ† (โ‹-โŠค c n p)))

  ฯƒ-rec-is-ub : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ) (a : A)
              โ†’ a ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ ฯƒ-rec ๐“‘ t a
  ฯƒ-rec-is-ub ๐“‘ t a = prโ‚ (ฯƒ-rec-is-join ๐“‘ t a)

  ฯƒ-rec-is-lb-of-ubs : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ) (a : A)
                     โ†’ (u : โŸจ ๐“‘ โŸฉ) โ†’ (a ๏ผ โŠค โ†’ t โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ ฯƒ-rec ๐“‘ t a โ‰คโŸจ ๐“‘ โŸฉ u
  ฯƒ-rec-is-lb-of-ubs ๐“‘ t a = prโ‚‚ (ฯƒ-rec-is-join ๐“‘ t a)

\end{code}

Such joins are absolute, in the sense that they are preserved by all
homomorphisms:

\begin{code}

  ฯƒ-suplat-homs-preserve-ฯƒ-rec : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ)
                                 (๐“’ : ฯƒ-SupLat ๐“ฃ' ๐“ฅ')
                                 (f : โŸจ ๐“‘ โŸฉ โ†’ โŸจ ๐“’ โŸฉ)
                               โ†’ is-ฯƒ-suplat-hom ๐“‘ ๐“’ f
                               โ†’ (t : โŸจ ๐“‘ โŸฉ)
                                 (a : A)
                               โ†’ f (ฯƒ-rec ๐“‘ t a) ๏ผ ฯƒ-rec ๐“’ (f t) a
  ฯƒ-suplat-homs-preserve-ฯƒ-rec ๐“‘ ๐“’ f i t = happly ฮณ
   where
    composite-is-hom : is-ฯƒ-suplat-hom ๐“ ๐“’ (f โˆ˜ ฯƒ-rec ๐“‘ t)
    composite-is-hom = โˆ˜-ฯƒ-suplat-hom ๐“ ๐“‘ ๐“’ (ฯƒ-rec ๐“‘ t) f (ฯƒ-rec-is-hom ๐“‘ t) i

    ฮณ : f โˆ˜ ฯƒ-rec ๐“‘ t ๏ผ ฯƒ-rec ๐“’ (f t)
    ฮณ = at-most-one-hom ๐“’ (f t)
         (f โˆ˜ ฯƒ-rec ๐“‘ t)
         (ฯƒ-rec ๐“’ (f t))
         composite-is-hom
         (ฯƒ-rec-is-hom ๐“’ (f t))
         (ap f (ฯƒ-rec-โŠค ๐“‘ t))
         (ฯƒ-rec-โŠค ๐“’ (f t))

\end{code}

In particular, ฯƒ-rec preserves ฯƒ-rec:

\begin{code}

  ฯƒ-rec-preserves-ฯƒ-rec : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (t : โŸจ ๐“‘ โŸฉ) (a b : A)
                        โ†’ ฯƒ-rec ๐“‘ t (ฯƒ-rec ๐“ a b) ๏ผ ฯƒ-rec ๐“‘ (ฯƒ-rec ๐“‘ t a) b
  ฯƒ-rec-preserves-ฯƒ-rec ๐“‘ t = ฯƒ-suplat-homs-preserve-ฯƒ-rec ๐“ ๐“‘
                               (ฯƒ-rec ๐“‘ t)
                               (ฯƒ-rec-is-hom ๐“‘ t)

\end{code}

We now derive the existence of binary meets in ฯƒ-sup-lattice ๐“ on one
generator โŠค from the above kind of joins.

\begin{code}

  _โˆง_ : A โ†’ A โ†’ A
  a โˆง b = ฯƒ-rec ๐“ a b

  meetโŠค : (a : A) โ†’ a โˆง โŠค ๏ผ a
  meetโŠค = ฯƒ-rec-โŠค ๐“

  meetโŠฅ : (a : A) โ†’ a โˆง โŠฅ ๏ผ โŠฅ
  meetโŠฅ = ฯƒ-rec-โŠฅ ๐“

  meetโ‹ : (a : A) (b : โ„• โ†’ A) โ†’ a โˆง โ‹ b ๏ผ โ‹ (n โ†ฆ a โˆง b n)
  meetโ‹ = ฯƒ-rec-โ‹ ๐“

  infix 100 _โˆง_

  โˆง-associative : (a b c : A) โ†’ a โˆง (b โˆง c) ๏ผ (a โˆง b) โˆง c
  โˆง-associative = ฯƒ-rec-preserves-ฯƒ-rec ๐“

  โˆง-is-lb-left : (a b : A) โ†’ a โˆง b โ‰ค a
  โˆง-is-lb-left a b = ฯƒ-rec-is-lb-of-ubs ๐“ a b a
                      (ฮป (_ : b ๏ผ โŠค) โ†’ โŸจ ๐“ โŸฉ-refl a)

  โˆง-is-lb-right : (a b : A) โ†’ a โˆง b โ‰ค b
  โˆง-is-lb-right a b = ฯƒ-rec-is-lb-of-ubs ๐“ a b b
                       (ฮป (r : b ๏ผ โŠค) โ†’ transport (a โ‰ค_) (r โปยน) (โŠค-is-maximum a))

\end{code}

Using this, we show that a โˆง b is the greatest lower bound of a and b.
One step needs ฯƒ-induction:

\begin{code}

  โˆง-is-ub-of-lbs : (a b c : A) โ†’ c โ‰ค a โ†’ c โ‰ค b โ†’ c โ‰ค a โˆง b
  โˆง-is-ub-of-lbs a b = ฯƒ-induction
                        (ฮป c โ†’ c โ‰ค a โ†’ c โ‰ค b โ†’ c โ‰ค a โˆง b)
                        (ฮป c โ†’ ฮ โ‚‚-is-prop fe
                                (ฮป _ _ โ†’ โŸจ ๐“ โŸฉ-order-is-prop-valued c (a โˆง b)))
                        pโŠค
                        pโŠฅ
                        pโ‹
   where
    pโŠค : โŠค โ‰ค a โ†’ โŠค โ‰ค b โ†’ โŠค โ‰ค a โˆง b
    pโŠค l m = โŸจ ๐“ โŸฉ-trans _ _ _ l ii
     where
      i : b ๏ผ โŠค
      i = โŸจ ๐“ โŸฉ-antisym _ _ (โŠค-is-maximum b) m

      ii : a โ‰ค a โˆง b
      ii = ฯƒ-rec-is-ub ๐“ a b i

    pโŠฅ : โŠฅ โ‰ค a โ†’ โŠฅ โ‰ค b โ†’ โŠฅ โ‰ค a โˆง b
    pโŠฅ _ _ = โŸจ ๐“ โŸฉ-โŠฅ-is-minimum (a โˆง b)

    pโ‹ : (d : โ„• โ†’ A)
       โ†’ ((n : โ„•) โ†’ d n โ‰ค a โ†’ d n โ‰ค b โ†’ d n โ‰ค a โˆง b)
       โ†’ โ‹ d โ‰ค a
       โ†’ โ‹ d โ‰ค b
       โ†’ โ‹ d โ‰ค (a โˆง b)
    pโ‹ d ฯ† l m = โŸจ ๐“ โŸฉ-โ‹-is-lb-of-ubs d (a โˆง b)
                      (ฮป n โ†’ ฯ† n (โŸจ ๐“ โŸฉ-trans (d n) _ a (โŸจ ๐“ โŸฉ-โ‹-is-ub d n) l)
                                 (โŸจ ๐“ โŸฉ-trans (d n) _ b (โŸจ ๐“ โŸฉ-โ‹-is-ub d n) m))

  โˆง-idempotent : (a : A) โ†’ a โˆง a ๏ผ a
  โˆง-idempotent a = โŸจ ๐“ โŸฉ-antisym _ _ l m
   where
    l : a โˆง a โ‰ค a
    l = โˆง-is-lb-left a a

    m : a โ‰ค a โˆง a
    m = โˆง-is-ub-of-lbs a a a (โŸจ ๐“ โŸฉ-refl a) (โŸจ ๐“ โŸฉ-refl a)

  โˆง-commutative : (a b : A) โ†’ a โˆง b ๏ผ b โˆง a
  โˆง-commutative a b = โŸจ ๐“ โŸฉ-antisym _ _ (l a b) (l b a)
   where
    l : (a b : A) โ†’ a โˆง b โ‰ค b โˆง a
    l a b = โˆง-is-ub-of-lbs b a (a โˆง b) (โˆง-is-lb-right a b) (โˆง-is-lb-left a b)

\end{code}

The intrinsic order coincides with the โˆง-semilattice order:

\begin{code}

  from-โ‰ค : (a b : A) โ†’ a โ‰ค b โ†’ a โˆง b ๏ผ a
  from-โ‰ค a b l = โŸจ ๐“ โŸฉ-antisym _ _ (โˆง-is-lb-left a b) m
   where
    m : a โ‰ค a โˆง b
    m = โˆง-is-ub-of-lbs _ _ _ (โŸจ ๐“ โŸฉ-refl a) l

  to-โ‰ค : (a b : A) โ†’ a โˆง b ๏ผ a โ†’ a โ‰ค b
  to-โ‰ค a b p = โŸจ ๐“ โŸฉ-trans _ _ _ l (โˆง-is-lb-right a b)
   where
    l : a โ‰ค a โˆง b
    l = โŸจ ๐“ โŸฉ-๏ผ-gives-โ‰ค (p โปยน)

\end{code}

We now show that the the ฯƒ-suplat on one generator is also the initial
ฯƒ-frame. The following renaming is annoying.

\begin{code}
  open OrderedTypes.sigma-frame fe
        hiding (order)
        renaming
         (โŸจ_โŸฉ to โŸจ_โŸฉ' ;
          โŠฅโŸจ_โŸฉ to โŠฅโŸจ_โŸฉ' ;
          โŠคโŸจ_โŸฉ to โŠคโŸจ_โŸฉ' ;
          meet to meet' ;
          โ‹โŸจ_โŸฉ to โ‹โŸจ_โŸฉ' ;
          โŸจ_โŸฉ-is-set to โŸจ_โŸฉ'-is-set ;
          โŸจ_โŸฉ-refl to โŸจ_โŸฉ'-refl ;
          โŸจ_โŸฉ-trans to โŸจ_โŸฉ'-trans ;
          โŸจ_โŸฉ-antisym to โŸจ_โŸฉ'-antisym ;
          โŸจ_โŸฉ-โŠค-maximum to โŸจ_โŸฉ'-โŠค-maximum ;
          โŸจ_โŸฉ-โŠฅ-minimum to โŸจ_โŸฉ'-โŠฅ-minimum ;
          โŸจ_โŸฉ-โ‹-is-ub to โŸจ_โŸฉ'-โ‹-is-ub ;
          โŸจ_โŸฉ-โ‹-is-lb-of-ubs to โŸจ_โŸฉ'-โ‹-is-lb-of-ubs)

  A-qua-ฯƒ-frame : ฯƒ-Frame ๐“ฃ
  A-qua-ฯƒ-frame = A ,
                  (โŠค , _โˆง_ , โŠฅ , โ‹) ,
                  โŸจ ๐“ โŸฉ-is-set ,
                  โˆง-idempotent ,
                  โˆง-commutative ,
                  โˆง-associative ,
                  (ฮป a โ†’ โˆง-commutative โŠฅ a โˆ™ meetโŠฅ a) ,
                  meetโŠค ,
                  meetโ‹ ,
                  (ฮป a n โ†’ from-โ‰ค (a n) (โ‹ a)
                            (โŸจ ๐“ โŸฉ-โ‹-is-ub a n)) ,
                  (ฮป a u ฯ† โ†’ from-โ‰ค (โ‹ a) u
                              (โŸจ ๐“ โŸฉ-โ‹-is-lb-of-ubs a u
                                    (ฮป n โ†’ to-โ‰ค (a n) u (ฯ† n))))

  A-qua-ฯƒ-frame-is-initial : (๐“‘ : ฯƒ-Frame ๐“ฅ)
                           โ†’ โˆƒ! f ๊ž‰ (A โ†’ โŸจ ๐“‘ โŸฉ), is-ฯƒ-frame-hom A-qua-ฯƒ-frame ๐“‘ f
  A-qua-ฯƒ-frame-is-initial {๐“ฅ} ๐“‘ = ฮณ
   where
    B = โŸจ ๐“‘ โŸฉ

    _โˆง'_ : B โ†’ B โ†’ B
    _โˆง'_ = meet' ๐“‘

    ๐“‘-qua-ฯƒ-suplat : ฯƒ-SupLat ๐“ฅ ๐“ฅ
    ๐“‘-qua-ฯƒ-suplat = ฯƒ-frames-are-ฯƒ-suplats ๐“‘

    โŠค' : B
    โŠค' = โŠคโŸจ ๐“‘ โŸฉ'

    f : A โ†’ B
    f = ฯƒ-rec ๐“‘-qua-ฯƒ-suplat โŠค'

    f-is-hom : is-ฯƒ-suplat-hom ๐“ ๐“‘-qua-ฯƒ-suplat f
    f-is-hom = ฯƒ-rec-is-hom ๐“‘-qua-ฯƒ-suplat โŠค'

    f-preserves-โˆง : (a b : A) โ†’ f (a โˆง b) ๏ผ f a โˆง' f b
    f-preserves-โˆง a = ฯƒ-induction
                       (ฮป b โ†’ f (a โˆง b) ๏ผ f a โˆง' f b)
                       (ฮป b โ†’ โŸจ ๐“‘ โŸฉ'-is-set)
                       fโŠค
                       fโŠฅ
                       fโ‹
     where
      fโŠค = f (a โˆง โŠค)  ๏ผโŸจ I โŸฉ
           f a        ๏ผโŸจ II โŸฉ
           f a โˆง' โŠค'  ๏ผโŸจ III โŸฉ
           f a โˆง' f โŠค โˆŽ
            where
             I   = ap f (meetโŠค a)
             II  = (โŸจ ๐“‘ โŸฉ'-โŠค-maximum (f a))โปยน
             III = ap (f a โˆง'_) ((ฯƒ-rec-โŠค ๐“‘-qua-ฯƒ-suplat โŠค')โปยน)

      fโŠฅ = f (a โˆง โŠฅ)      ๏ผโŸจ I โŸฉ
           f โŠฅ            ๏ผโŸจ II โŸฉ
           โŠฅโŸจ ๐“‘ โŸฉ'        ๏ผโŸจ III โŸฉ
           โŠฅโŸจ ๐“‘ โŸฉ' โˆง' f a ๏ผโŸจ IV โŸฉ
           f โŠฅ โˆง' f a     ๏ผโŸจ V โŸฉ
           f a โˆง' f โŠฅ     โˆŽ
            where
             I   = ap f (meetโŠฅ a)
             II  = ฯƒ-suplat-hom-โŠฅ ๐“ ๐“‘-qua-ฯƒ-suplat f f-is-hom
             III = (โŸจ ๐“‘ โŸฉ'-โŠฅ-minimum (f a))โปยน
             IV  = ap (ฮป - โ†’ - โˆง' f a)
                      ((ฯƒ-suplat-hom-โŠฅ ๐“ ๐“‘-qua-ฯƒ-suplat f f-is-hom)โปยน)
             V   = โŸจ ๐“‘ โŸฉ-commutativity (f โŠฅ) (f a)

      fโ‹ = ฮป c p โ†’
           f (a โˆง โ‹ c)                    ๏ผโŸจ I c โŸฉ
           f (โ‹ (n โ†ฆ a โˆง c n))            ๏ผโŸจ II c โŸฉ
           โ‹โŸจ ๐“‘ โŸฉ' (n โ†ฆ f (a โˆง c n))      ๏ผโŸจ III c p โŸฉ
           โ‹โŸจ ๐“‘ โŸฉ' (n โ†ฆ f a โˆง' f (c n))   ๏ผโŸจ IV c โŸฉ
           f a โˆง' โ‹โŸจ ๐“‘ โŸฉ' (ฮป n โ†’ f (c n)) ๏ผโŸจ V c โŸฉ
           f a โˆง' f (โ‹ c)                 โˆŽ
            where
             I   = ฮป (c : โ„• โ†’ โŸจ ๐“ โŸฉ) โ†’ ap f (meetโ‹ a c)
             II  = ฮป (c : โ„• โ†’ โŸจ ๐“ โŸฉ) โ†’ ฯƒ-suplat-hom-โ‹
                                        ๐“
                                        ๐“‘-qua-ฯƒ-suplat
                                        f
                                        f-is-hom
                                        (ฮป n โ†’ a โˆง c n)
             III = ฮป (c : โ„• โ†’ โŸจ ๐“ โŸฉ)
                     (p : (n : โ„•) โ†’ _ ๏ผ meet' ๐“‘ (f a) (f (c n)))
                        โ†’ ap โ‹โŸจ ๐“‘ โŸฉ' (dfunext fe p)
             IV  = ฮป (c : โ„• โ†’ โŸจ ๐“ โŸฉ) โ†’ (โŸจ ๐“‘ โŸฉ-distributivity (f a) (ฮป n โ†’ f (c n)))โปยน
             V   = ฮป (c : โ„• โ†’ โŸจ ๐“ โŸฉ) โ†’ ap (f a โˆง'_)
                                         ((ฯƒ-suplat-hom-โ‹ ๐“ ๐“‘-qua-ฯƒ-suplat f f-is-hom c)โปยน)

    f-is-hom' : is-ฯƒ-frame-hom A-qua-ฯƒ-frame ๐“‘ f
    f-is-hom' = ฯƒ-rec-โŠค ๐“‘-qua-ฯƒ-suplat โŠค' ,
                f-preserves-โˆง ,
                ฯƒ-suplat-hom-โŠฅ ๐“ ๐“‘-qua-ฯƒ-suplat f f-is-hom ,
                ฯƒ-suplat-hom-โ‹ ๐“ ๐“‘-qua-ฯƒ-suplat f f-is-hom

    forget : (g : A โ†’ B)
           โ†’ is-ฯƒ-frame-hom  A-qua-ฯƒ-frame ๐“‘              g
           โ†’ is-ฯƒ-suplat-hom ๐“             ๐“‘-qua-ฯƒ-suplat g
    forget g (i , ii , iii , iv) = (iii , iv)

    f-uniqueness : (g : A โ†’ B) โ†’ is-ฯƒ-frame-hom A-qua-ฯƒ-frame ๐“‘ g โ†’ f ๏ผ g
    f-uniqueness g g-is-hom' = at-most-one-hom ๐“‘-qua-ฯƒ-suplat โŠค' f g
                                f-is-hom
                                (forget g g-is-hom')
                                (ฯƒ-rec-โŠค ๐“‘-qua-ฯƒ-suplat โŠค')
                                (ฯƒ-frame-hom-โŠค A-qua-ฯƒ-frame ๐“‘ g g-is-hom')

    ฮณ : โˆƒ! f ๊ž‰ (A โ†’ B), is-ฯƒ-frame-hom A-qua-ฯƒ-frame ๐“‘ f
    ฮณ = (f , f-is-hom') ,
        (ฮป (g , g-is-hom') โ†’ to-subtype-๏ผ
                              (being-ฯƒ-frame-hom-is-prop A-qua-ฯƒ-frame ๐“‘)
                              (f-uniqueness g g-is-hom'))
\end{code}

We now regard the type of propositions as a ฯƒ-sup-lattice:

\begin{code}

  ฮฉ-qua-ฯƒ-Frame : ฯƒ-Frame (๐“ฃ โบ)
  ฮฉ-qua-ฯƒ-Frame = OrderedTypes.sigma-frame.ฮฉ-qua-ฯƒ-frame fe pe pt

  ฮฉ-qua-ฯƒ-SupLat : ฯƒ-SupLat (๐“ฃ โบ) (๐“ฃ โบ)
  ฮฉ-qua-ฯƒ-SupLat = OrderedTypes.sigma-frame.ฮฉ-qua-ฯƒ-suplat fe pe pt

  private
   โŠฅ'   = โŠฅโŸจ ฮฉ-qua-ฯƒ-SupLat โŸฉ
   โŠค'   = โŠคโŸจ ฮฉ-qua-ฯƒ-Frame โŸฉ'
   โ‹'  = โ‹โŸจ ฮฉ-qua-ฯƒ-SupLat โŸฉ
   _โ‰ค'_ : ฮฉ ๐“ฃ โ†’ ฮฉ ๐“ฃ โ†’ ๐“ฃ โบ ฬ‡
   x โ‰ค' y = x โ‰คโŸจ ฮฉ-qua-ฯƒ-SupLat โŸฉ y

   ๏ผ-gives-โ‰ค' : (p q : ฮฉ ๐“ฃ) โ†’ p ๏ผ q โ†’ p โ‰ค' q
   ๏ผ-gives-โ‰ค' p q r = โŸจ ฮฉ-qua-ฯƒ-SupLat โŸฉ-๏ผ-gives-โ‰ค r

\end{code}

In a frame the bottom element is not taken explicitly as part of the
structure and is defined to be the join of the family indexed by the
empty set. In the particular case of the frame of propositions, this
is equal to the empty type ๐Ÿ˜, but not definitionally:

\begin{code}

  โŠฅ-holds-is-๐Ÿ˜ : โŠฅ' holds ๏ผ ๐Ÿ˜
  โŠฅ-holds-is-๐Ÿ˜ = p
   where
    p : (โˆƒ x ๊ž‰ ๐Ÿ˜ , unique-from-๐Ÿ˜ x holds) ๏ผ ๐Ÿ˜
    p = pe โˆƒ-is-prop
           ๐Ÿ˜-is-prop
           (โˆฅโˆฅ-rec ๐Ÿ˜-is-prop (unique-from-๐Ÿ˜ โˆ˜ prโ‚))
           unique-from-๐Ÿ˜

  ฮฉ-non-trivial : โŠฅ' โ‰  โŠค'
  ฮฉ-non-trivial q = ๐Ÿ˜-is-not-๐Ÿ™ r
   where
    r : ๐Ÿ˜ ๏ผ ๐Ÿ™
    r = (โŠฅ-holds-is-๐Ÿ˜)โปยน โˆ™ ap _holds q

\end{code}

The following map ฯ„ will play an important role:

\begin{code}

  ฯ„ : A โ†’ ฮฉ ๐“ฃ
  ฯ„ = ฯƒ-rec ฮฉ-qua-ฯƒ-SupLat โŠค'

  ฯ„-is-hom : is-ฯƒ-suplat-hom ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„
  ฯ„-is-hom = ฯƒ-rec-is-hom ฮฉ-qua-ฯƒ-SupLat โŠค'

\end{code}

Using ฯ„ we derive the non-triviality of ๐“ from that of ฮฉ:

\begin{code}

  ๐“-non-trivial : โŠฅ โ‰  โŠค
  ๐“-non-trivial p = ฮฉ-non-trivial q
   where
    q = โŠฅ'  ๏ผโŸจ (ฯƒ-suplat-hom-โŠฅ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom)โปยน โŸฉ
        ฯ„ โŠฅ ๏ผโŸจ ap ฯ„ p โŸฉ
        ฯ„ โŠค ๏ผโŸจ ฯƒ-rec-โŠค ฮฉ-qua-ฯƒ-SupLat โŠค' โŸฉ
        โŠค'  โˆŽ

\end{code}

A crucial property of the map ฯ„ is that it reflects top elements (in
point-free topological terms, this says that ฯ„ is dense):

\begin{code}

  ฯ„-reflects-โŠค : (a : A) โ†’ ฯ„ a ๏ผ โŠค' โ†’ a ๏ผ โŠค
  ฯ„-reflects-โŠค = ฯƒ-induction
                  (ฮป a โ†’ ฯ„ a ๏ผ โŠค' โ†’ a ๏ผ โŠค)
                  (ฮป a โ†’ ฮ -is-prop fe (ฮป _ โ†’ โŸจ ๐“ โŸฉ-is-set))
                  iโŠค
                  iโŠฅ
                  iโ‹
   where
    iโŠค : ฯ„ โŠค ๏ผ โŠค' โ†’ โŠค ๏ผ โŠค
    iโŠค _ = refl

    iโŠฅ : ฯ„ โŠฅ ๏ผ โŠค' โ†’ โŠฅ ๏ผ โŠค
    iโŠฅ p = ๐Ÿ˜-elim (ฮฉ-non-trivial q)
     where
      q : โŠฅ' ๏ผ โŠค'
      q = (ฯƒ-suplat-hom-โŠฅ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom)โปยน โˆ™ p

    iโ‹ : (a : โ„• โ†’ A)
       โ†’ ((n : โ„•) โ†’ ฯ„ (a n) ๏ผ โŠค' โ†’ a n ๏ผ โŠค)
       โ†’ ฯ„ (โ‹ a) ๏ผ โŠค'
       โ†’ โ‹ a ๏ผ โŠค
    iโ‹ a ฯ† p = โˆฅโˆฅ-rec โŸจ ๐“ โŸฉ-is-set iii ii
     where
      i : โ‹' (ฯ„ โˆ˜ a) ๏ผ โŠค'
      i = (ฯƒ-suplat-hom-โ‹ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom a)โปยน โˆ™ p

      ii : โˆƒ n ๊ž‰ โ„• , ฯ„ (a n) holds
      ii = equal-โŠค-gives-holds (โ‹' (ฯ„ โˆ˜ a)) i

      iii : (ฮฃ n ๊ž‰ โ„• , ฯ„ (a n) holds) โ†’ โ‹ a ๏ผ โŠค
      iii (n , h) = vi
       where
        iv : ฯ„ (a n) ๏ผ โŠค'
        iv = holds-gives-equal-โŠค pe fe (ฯ„ (a n)) h

        v : a n ๏ผ โŠค
        v = ฯ† n iv

        vi : โ‹ a ๏ผ โŠค
        vi = โ‹-โŠค a n v

\end{code}

A frame is called compact if every cover of its top element has a
finite subcover. It is supercompact (I think the terminology is due to
John Isbell) if every cover of the top element has a singleton
subcover. This motivates the name of the following theorem, whose
crucial ingredient is the homomorphism ฯ„ and the fact that it reflects
top elements.

\begin{code}

  ๐“-is-ฯƒ-supercompact : (a : โ„• โ†’ A) โ†’ โ‹ a ๏ผ โŠค โ†’ โˆƒ n ๊ž‰ โ„• , a n ๏ผ โŠค
  ๐“-is-ฯƒ-supercompact a p = vi
   where
    i = โ‹' (ฯ„ โˆ˜ a) ๏ผโŸจ (ฯƒ-suplat-hom-โ‹ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom a)โปยน โŸฉ
        ฯ„ (โ‹ a)    ๏ผโŸจ ap ฯ„ p โŸฉ
        ฯ„ โŠค        ๏ผโŸจ ฯƒ-rec-โŠค ฮฉ-qua-ฯƒ-SupLat โŠค' โŸฉ
        โŠค'         โˆŽ

    ii : (โˆƒ n ๊ž‰ โ„• , ฯ„ (a n) holds) ๏ผ ๐Ÿ™
    ii = ap _holds i

    iii : (ฮฃ n ๊ž‰ โ„• , ฯ„ (a n) holds) โ†’ (ฮฃ n ๊ž‰ โ„• , a n ๏ผ โŠค)
    iii (n , h) = n , v
     where
      iv : ฯ„ (a n) ๏ผ โŠค'
      iv = holds-gives-equal-โŠค pe fe (ฯ„ (a n)) h

      v : a n ๏ผ โŠค
      v = ฯ„-reflects-โŠค (a n) iv

    vi : โˆƒ n ๊ž‰ โ„• , a n ๏ผ โŠค
    vi = โˆฅโˆฅ-functor iii (equal-๐Ÿ™-gives-holds (โˆƒ n ๊ž‰ โ„• , ฯ„ (a n) holds) ii)

\end{code}

We have that ฯ„ a holds precisely when a ๏ผ โŠค (hence the name ฯ„ for the
function):

\begin{code}

  ฯ„-characโ†’ : (a : A) โ†’ ฯ„ a holds โ†’ a ๏ผ โŠค
  ฯ„-characโ†’ a h = ฯ„-reflects-โŠค a (holds-gives-equal-โŠค pe fe (ฯ„ a) h)

  ฯ„-characโ† : (a : A) โ†’ a ๏ผ โŠค โ†’ ฯ„ a holds
  ฯ„-characโ† a p = equal-โŠค-gives-holds (ฯ„ a)
                   (ฯ„ a ๏ผโŸจ ap ฯ„ p โŸฉ
                    ฯ„ โŠค ๏ผโŸจ ฯƒ-rec-โŠค ฮฉ-qua-ฯƒ-SupLat โŠค' โŸฉ
                    โŠค'  โˆŽ)

  ฯ„-charac' : (a : A) โ†’ ฯ„ a holds ๏ผ (a ๏ผ โŠค)
  ฯ„-charac' a = pe (holds-is-prop (ฯ„ a)) โŸจ ๐“ โŸฉ-is-set (ฯ„-characโ†’ a) (ฯ„-characโ† a)

  ฯ„-charac : (a : A) โ†’ ฯ„ a ๏ผ ((a ๏ผ โŠค) , โŸจ ๐“ โŸฉ-is-set)
  ฯ„-charac a = to-subtype-๏ผ (ฮป a โ†’ being-prop-is-prop fe) (ฯ„-charac' a)

\end{code}

The following criterion for a โ‰ค b will be useful:

\begin{code}

  โ‰ค-criterion : (a b : A) โ†’ (a ๏ผ โŠค โ†’ b ๏ผ โŠค) โ†’ a โ‰ค b
  โ‰ค-criterion = ฯƒ-induction
                  (ฮป a โ†’ (b : A) โ†’ (a ๏ผ โŠค โ†’ b ๏ผ โŠค) โ†’ a โ‰ค b)
                  (ฮป a โ†’ ฮ โ‚‚-is-prop fe (ฮป b _ โ†’ โŸจ ๐“ โŸฉ-order-is-prop-valued a b))
                  iโŠค
                  iโŠฅ
                  iโ‹
   where
    iโŠค : (b : A) โ†’ (โŠค ๏ผ โŠค โ†’ b ๏ผ โŠค) โ†’ โŠค โ‰ค b
    iโŠค b f = โŸจ ๐“ โŸฉ-๏ผ-gives-โ‰ค ((f refl)โปยน)

    iโŠฅ : (b : A) โ†’ (โŠฅ ๏ผ โŠค โ†’ b ๏ผ โŠค) โ†’ โŠฅ โ‰ค b
    iโŠฅ b _ = โŸจ ๐“ โŸฉ-โŠฅ-is-minimum b

    iโ‹ : (a : โ„• โ†’ A)
       โ†’ ((n : โ„•) (b : A) โ†’ (a n ๏ผ โŠค โ†’ b ๏ผ โŠค) โ†’ a n โ‰ค b)
       โ†’ (b : A)
       โ†’ (โ‹ a ๏ผ โŠค โ†’ b ๏ผ โŠค)
       โ†’ โ‹ a โ‰ค b
    iโ‹ a ฯ† b ฯˆ = โŸจ ๐“ โŸฉ-โ‹-is-lb-of-ubs a b
                      (ฮป n โ†’ ฯ† n b (ฮป (p : a n ๏ผ โŠค) โ†’ ฯˆ (โ‹-โŠค a n p)))

  โ‰ค-criterion-converse : (a b : A) โ†’ a โ‰ค b โ†’ (a ๏ผ โŠค โ†’ b ๏ผ โŠค)
  โ‰ค-criterion-converse a b l p =
   โŸจ ๐“ โŸฉ-antisym _ _
        (โŠค-is-maximum b)
        (โŸจ ๐“ โŸฉ-trans _ _ _ (โŸจ ๐“ โŸฉ-๏ผ-gives-โ‰ค (p โปยน)) l)

\end{code}

The map ฯ„ reflects order and hence is left-cancellable, and therefore
is an embedding (its fibers are propositions) because it is a map into
a set:

\begin{code}

  ฯ„-order-lc : (a b : A) โ†’ ฯ„ a โ‰ค' ฯ„ b โ†’ a โ‰ค b
  ฯ„-order-lc a b l = iv
   where
    i : ฯ„ a holds โ†’ ฯ„ b holds
    i = OrderedTypes.Frame.from-โ‰คฮฉ fe pe pt {๐“ฃ} {ฯ„ a} {ฯ„ b} l

    ii : ฯ„ a ๏ผ โŠค' โ†’ ฯ„ b ๏ผ โŠค'
    ii p = holds-gives-equal-โŠค pe fe (ฯ„ b) (i (equal-โŠค-gives-holds (ฯ„ a) p))

    iii : a ๏ผ โŠค โ†’ b ๏ผ โŠค
    iii q = ฯ„-reflects-โŠค b (ii r)
     where
      r = ฯ„ a ๏ผโŸจ ap ฯ„ q โŸฉ
          ฯ„ โŠค ๏ผโŸจ ฯƒ-rec-โŠค ฮฉ-qua-ฯƒ-SupLat โŠค' โŸฉ
          โŠค'  โˆŽ

    iv : a โ‰ค b
    iv = โ‰ค-criterion a b iii

  ฯ„-lc : left-cancellable ฯ„
  ฯ„-lc {a} {b} p = โŸจ ๐“ โŸฉ-antisym a b l r
   where
    l : a โ‰ค b
    l = ฯ„-order-lc a b (๏ผ-gives-โ‰ค' (ฯ„ a) (ฯ„ b) p)

    r : b โ‰ค a
    r = ฯ„-order-lc b a (๏ผ-gives-โ‰ค' (ฯ„ b) (ฯ„ a) (p โปยน))

  ฯ„-is-embedding : is-embedding ฯ„
  ฯ„-is-embedding = lc-maps-into-sets-are-embeddings ฯ„ ฯ„-lc (ฮฉ-is-set fe pe)

  holds-is-embedding : is-embedding (_holds {๐“ฃ})
  holds-is-embedding = prโ‚-is-embedding (ฮป _ โ†’ being-prop-is-prop fe)

\end{code}

Hence the composite ฯ„-holds is an embedding of A into the universe ๐“ฃ:

\begin{code}

  ฯ„-holds : A โ†’ ๐“ฃ ฬ‡
  ฯ„-holds a = ฯ„ a holds

  ฯ„-holds-is-embedding : is-embedding ฯ„-holds
  ฯ„-holds-is-embedding = โˆ˜-is-embedding ฯ„-is-embedding holds-is-embedding

\end{code}

Using this we define the notion of quasidecidability and its required
properties. We define the quasidecidability of the type P to be the
type

  fiber ฯ„-holds P,

which amounts to the type

  ฮฃ a ๊ž‰ A , (ฯ„ a holds ๏ผ P)

by construction:

\begin{code}

  is-quasidecidable : ๐“ฃ ฬ‡ โ†’ ๐“ฃ โบ ฬ‡
  is-quasidecidable P = ฮฃ a ๊ž‰ A , (ฯ„ a holds ๏ผ P)

  being-quasidecidable-is-prop : โˆ€ P โ†’ is-prop (is-quasidecidable P)
  being-quasidecidable-is-prop = ฯ„-holds-is-embedding

  quasidecidable-types-are-props : โˆ€ P โ†’ is-quasidecidable P โ†’ is-prop P
  quasidecidable-types-are-props P (a , p) =
   transport is-prop p (holds-is-prop (ฯ„ a))

  ๐Ÿ˜-is-quasidecidable : is-quasidecidable ๐Ÿ˜
  ๐Ÿ˜-is-quasidecidable = โŠฅ ,
                        (ฯ„ โŠฅ holds ๏ผโŸจ I โŸฉ
                         โŠฅ' holds  ๏ผโŸจ II โŸฉ
                         ๐Ÿ˜         โˆŽ)
                          where
                           I  = ap _holds
                                   (ฯƒ-suplat-hom-โŠฅ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom)
                           II = โŠฅ-holds-is-๐Ÿ˜

  ๐Ÿ™-is-quasidecidable : is-quasidecidable ๐Ÿ™
  ๐Ÿ™-is-quasidecidable = โŠค , ap _holds (ฯƒ-rec-โŠค ฮฉ-qua-ฯƒ-SupLat โŠค')

  quasidecidable-closed-under-ฯ‰-joins
   : (P : โ„• โ†’ ๐“ฃ ฬ‡ )
   โ†’ ((n : โ„•) โ†’ is-quasidecidable (P n))
   โ†’ is-quasidecidable (โˆƒ n ๊ž‰ โ„• , P n)
  quasidecidable-closed-under-ฯ‰-joins P ฯ† = vii
   where
    i : (n : โ„•) โ†’ ฯ„-holds (fiber-point (ฯ† n)) ๏ผ P n
    i n = fiber-identification (ฯ† n)

    ii : (n : โ„•)
       โ†’ ฯ„ (fiber-point (ฯ† n))
       ๏ผ (P n , quasidecidable-types-are-props (P n) (ฯ† n))
    ii n = to-subtype-๏ผ (ฮป _ โ†’ being-prop-is-prop fe) (i n)

    iii : ฯ„ (โ‹ (n โ†ฆ fiber-point (ฯ† n)))
        ๏ผ โ‹' (ฮป n โ†’ P n , quasidecidable-types-are-props (P n) (ฯ† n))
    iii = ฯ„ (โ‹ (n โ†ฆ fiber-point (ฯ† n)))                               ๏ผโŸจ iv โŸฉ
          โ‹' (n โ†ฆ ฯ„ (fiber-point (ฯ† n)))                              ๏ผโŸจ v โŸฉ
          โ‹' (n โ†ฆ (P n , quasidecidable-types-are-props (P n) (ฯ† n))) โˆŽ
     where
      iv = ฯƒ-suplat-hom-โ‹ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom (ฮป n โ†’ fiber-point (ฯ† n))
      v  = ap โ‹' (dfunext fe ii)

    vi : ฯ„-holds (โ‹ (n โ†ฆ fiber-point (ฯ† n))) ๏ผ (โˆƒ n ๊ž‰ โ„• , P n)
    vi = ap _holds iii

    vii : is-quasidecidable (โˆƒ n ๊ž‰ โ„• , P n)
    vii = โ‹ (n โ†ฆ fiber-point (ฯ† n)) , vi

\end{code}

Then we get quasidecidable induction by ฯƒ-induction:

\begin{code}

  quasidecidable-induction :
     (F : ๐“ฃ ฬ‡ โ†’ ๐“ฅ ฬ‡ )
   โ†’ ((P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F P))
   โ†’ F ๐Ÿ˜
   โ†’ F ๐Ÿ™
   โ†’ ((P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n))
   โ†’ (P : ๐“ฃ ฬ‡ ) โ†’ is-quasidecidable P โ†’ F P
  quasidecidable-induction {๐“ฅ} F i Fโ‚€ Fโ‚ Fฯ‰ P (a , r) = ฮณ a P r
   where
    ฮณโŠค : (P : ๐“ฃ ฬ‡ ) โ†’ ฯ„ โŠค holds ๏ผ P โ†’ F P
    ฮณโŠค P s = transport F (t โปยน โˆ™ s) Fโ‚
     where
      t : ฯ„ โŠค holds ๏ผ ๐Ÿ™
      t = ap _holds (ฯƒ-rec-โŠค ฮฉ-qua-ฯƒ-SupLat โŠค')

    ฮณโŠฅ : (P : ๐“ฃ ฬ‡ ) โ†’ ฯ„ โŠฅ holds ๏ผ P โ†’ F P
    ฮณโŠฅ P s = transport F (t โปยน โˆ™ s) Fโ‚€
     where
      t : ฯ„ โŠฅ holds ๏ผ ๐Ÿ˜
      t = ap _holds (ฯƒ-suplat-hom-โŠฅ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom) โˆ™ โŠฅ-holds-is-๐Ÿ˜

    ฮณโ‹ : (a : โ„• โ†’ A)
       โ†’ ((n : โ„•) (P : ๐“ฃ ฬ‡ ) โ†’ (ฯ„ (a n) holds) ๏ผ P โ†’ F P)
       โ†’ (P : ๐“ฃ ฬ‡ ) โ†’ (ฯ„ (โ‹ a) holds) ๏ผ P โ†’ F P
    ฮณโ‹ a ฯ† P s = transport F (t โปยน โˆ™ s) (Fฯ‰ (ฮป n โ†’ ฯ„ (a n) holds) ฯˆ)
     where
      t : ฯ„ (โ‹ a) holds ๏ผ (โˆƒ n ๊ž‰ โ„• , ฯ„ (a n) holds)
      t = ap _holds (ฯƒ-suplat-hom-โ‹ ๐“ ฮฉ-qua-ฯƒ-SupLat ฯ„ ฯ„-is-hom a)
      ฯˆ : (n : โ„•) โ†’ F (ฯ„ (a n) holds)
      ฯˆ n = ฯ† n (ฯ„ (a n) holds) refl

    ฮณ : (a : A) (P : ๐“ฃ ฬ‡ ) โ†’ ฯ„ a holds ๏ผ P โ†’ F P
    ฮณ = ฯƒ-induction
         (ฮป a โ†’ (P : ๐“ฃ ฬ‡ ) โ†’ ฯ„ a holds ๏ผ P โ†’ F P)
         (ฮป a โ†’ ฮ โ‚‚-is-prop fe (ฮป P _ โ†’ i P))
         ฮณโŠค
         ฮณโŠฅ
         ฮณโ‹

\end{code}

We then get the dominance axiom for quasidecidable propositions by an
application of the submodule hypothetical-quasidecidability.

\begin{code}

  quasidecidable-closed-under-ฮฃ
   : (P : ๐“ฃ ฬ‡ )
   โ†’ (Q : P โ†’ ๐“ฃ ฬ‡ )
   โ†’ is-quasidecidable P
   โ†’ ((p : P) โ†’ is-quasidecidable (Q p))
   โ†’ is-quasidecidable (ฮฃ Q)
  quasidecidable-closed-under-ฮฃ
   = hypothetical-quasidecidability.quasidecidable-closed-under-ฮฃ
      (quasidecidable-propositions
         is-quasidecidable
         being-quasidecidable-is-prop
         ๐Ÿ˜-is-quasidecidable
         ๐Ÿ™-is-quasidecidable
         quasidecidable-closed-under-ฯ‰-joins
         quasidecidable-induction)

\end{code}

Here are some consequences for the sake of illustration of the meaning
of this.

\begin{code}

  dependent-binary-meet
   : (a : A) (b : ฯ„ a holds โ†’ A)
   โ†’ ฮฃ c ๊ž‰ A , (ฯ„ c holds ๏ผ (ฮฃ h ๊ž‰ ฯ„ a holds , ฯ„ (b h) holds))
  dependent-binary-meet a b = quasidecidable-closed-under-ฮฃ
                               (ฯ„ a holds)
                               (ฮป h โ†’ ฯ„ (b h) holds)
                               (a , refl)
                               (ฮป h โ†’ b h , refl)
\end{code}

The following just applies back-and-forth the characterization of
ฯ„ a holds as a ๏ผ โŠค.

\begin{code}

  dependent-binary-meet' : (a : A) (b : a ๏ผ โŠค โ†’ A)
                         โ†’ ฮฃ c ๊ž‰ A , (c ๏ผ โŠค โ†” (ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค))
  dependent-binary-meet' a b = f ฯƒ
   where
    b' : ฯ„ a holds โ†’ A
    b' h = b (ฯ„-characโ†’ a h)

    ฯƒ : ฮฃ c ๊ž‰ A , (ฯ„ c holds) ๏ผ (ฮฃ h ๊ž‰ ฯ„ a holds , ฯ„ (b' h) holds)
    ฯƒ = dependent-binary-meet a b'

    f : (ฮฃ c ๊ž‰ A , (ฯ„ c holds) ๏ผ (ฮฃ h ๊ž‰ ฯ„ a holds , ฯ„ (b' h) holds))
      โ†’ ฮฃ c ๊ž‰ A , ((c ๏ผ โŠค) โ†” (ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค))
    f ( c , q) = c , g , h
     where
      g : c ๏ผ โŠค โ†’ ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค
      g r = ฯ„-characโ†’ a (prโ‚ (Idtofun q (ฯ„-characโ† c r))) ,
            transport (ฮป - โ†’ b - ๏ผ โŠค)
              (โŸจ ๐“ โŸฉ-is-set _ _)
              (ฯ„-characโ†’ (b _) (prโ‚‚ (Idtofun q (ฯ„-characโ† c r))))

      h : (ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค) โ†’ c ๏ผ โŠค
      h (p , s) = ฯ„-characโ†’ c
                   (Idtofun
                     (q โปยน)
                     (ฯ„-characโ† a p , ฯ„-characโ† (b' (ฯ„-characโ† a p))
                     (transport (ฮป - โ†’ b - ๏ผ โŠค) (โŸจ ๐“ โŸฉ-is-set _ _) s)))
\end{code}

We can replace the bi-implication by an equality:

\begin{code}

  dependent-binary-meet'' : (a : A) (b : a ๏ผ โŠค โ†’ A)
                          โ†’ ฮฃ c ๊ž‰ A , ((c ๏ผ โŠค) ๏ผ (ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค))
  dependent-binary-meet'' a b = f (dependent-binary-meet' a b)
   where
    f : (ฮฃ c ๊ž‰ A , (c ๏ผ โŠค โ†” (ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค)))
      โ†’ ฮฃ c ๊ž‰ A , ((c ๏ผ โŠค) ๏ผ (ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค))
    f (c , g , h) = c , โŒœ prop-univalent-โ‰ƒ pe fe (c ๏ผ โŠค) (ฮฃ p ๊ž‰ a ๏ผ โŠค , b p ๏ผ โŠค)
                           (ฮฃ-is-prop โŸจ ๐“ โŸฉ-is-set (ฮป p โ†’ โŸจ ๐“ โŸฉ-is-set)) โŒโปยน
                          (logically-equivalent-props-are-equivalent
                             โŸจ ๐“ โŸฉ-is-set
                             (ฮฃ-is-prop
                               โŸจ ๐“ โŸฉ-is-set
                               (ฮป p โ†’ โŸจ ๐“ โŸฉ-is-set)) g h)
\end{code}

The non-dependent special case:

\begin{code}

  binary-meet : (a b : A) โ†’ ฮฃ c ๊ž‰ A , (c ๏ผ โŠค โ†” ((a ๏ผ โŠค) ร— (b ๏ผ โŠค)))
  binary-meet a b = dependent-binary-meet' a (ฮป _ โ†’ b)

\end{code}

Using the criterion for โ‰ค we get that this does indeed give binary
meets:

\begin{code}

  binary-meet'-is-โˆง : (a b c : A)
                    โ†’ (c ๏ผ โŠค โ†” ((a ๏ผ โŠค) ร— (b ๏ผ โŠค)))
                    โ†’ c ๏ผ a โˆง b
  binary-meet'-is-โˆง a b c (f , g) = viii
   where
    i : c โ‰ค a
    i = โ‰ค-criterion c a (ฮป (p : c ๏ผ โŠค) โ†’ prโ‚ (f p))

    ii : c โ‰ค b
    ii = โ‰ค-criterion c b (ฮป (p : c ๏ผ โŠค) โ†’ prโ‚‚ (f p))

    iii : c โ‰ค a โˆง b
    iii = โˆง-is-ub-of-lbs a b c i ii

    iv : a โˆง b ๏ผ โŠค โ†’ a ๏ผ โŠค
    iv p = โŸจ ๐“ โŸฉ-antisym a โŠค
                (โŠค-is-maximum a)
                (โŸจ ๐“ โŸฉ-trans โŠค (a โˆง b) a
                      (โŸจ ๐“ โŸฉ-๏ผ-gives-โ‰ค (p โปยน))
                      (โˆง-is-lb-left a b))

    v : a โˆง b ๏ผ โŠค โ†’ b ๏ผ โŠค
    v p = โŸจ ๐“ โŸฉ-antisym b โŠค
               (โŠค-is-maximum b)
               (โŸจ ๐“ โŸฉ-trans โŠค (a โˆง b) b
                     (โŸจ ๐“ โŸฉ-๏ผ-gives-โ‰ค (p โปยน))
                     (โˆง-is-lb-right a b))

    vi : a โˆง b ๏ผ โŠค โ†’ c ๏ผ โŠค
    vi p = g (iv p , v p)

    vii : a โˆง b โ‰ค c
    vii = โ‰ค-criterion (a โˆง b) c vi

    viii : c ๏ผ a โˆง b
    viii = โŸจ ๐“ โŸฉ-antisym c (a โˆง b) iii vii

\end{code}

ฯƒ-sup-lattices have joins of quasidecidable-indexed families:

\begin{code}

  ฯƒ-suplats-have-quasidecidable-joins : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) (P : ๐“ฃ ฬ‡ )
                                      โ†’ is-quasidecidable P
                                      โ†’ (f : P โ†’ โŸจ ๐“‘ โŸฉ)
                                      โ†’ ฮฃ b ๊ž‰ โŸจ ๐“‘ โŸฉ , (b is-the-join-of f on ๐“‘)
  ฯƒ-suplats-have-quasidecidable-joins {๐“ฅ} {๐“ฆ} ๐“‘ =
    quasidecidable-induction F F-is-prop-valued Fโ‚€ Fโ‚ Fฯ‰
   where
    F : ๐“ฃ ฬ‡ โ†’ ๐“ฃ โŠ” ๐“ฅ โŠ” ๐“ฆ ฬ‡
    F P = (f : P โ†’ โŸจ ๐“‘ โŸฉ) โ†’ ฮฃ b ๊ž‰ โŸจ ๐“‘ โŸฉ , (b is-the-join-of f on ๐“‘)

    F-is-prop-valued : โˆ€ P โ†’ is-prop (F P)
    F-is-prop-valued P = ฮ -is-prop fe
                          (ฮป f (b , i) (b' , i')
                             โ†’ to-subtype-๏ผ
                                (ฮป b โ†’ being-join-is-prop ๐“‘ b f)
                                (at-most-one-join ๐“‘ b b' f i i'))

    Fโ‚€ : F ๐Ÿ˜
    Fโ‚€ f = โŠฅโŸจ ๐“‘ โŸฉ , (ฮป (i : ๐Ÿ˜) โ†’ ๐Ÿ˜-elim i) , ฮป u ฯˆ โ†’ โŸจ ๐“‘ โŸฉ-โŠฅ-is-minimum u

    Fโ‚ : F ๐Ÿ™
    Fโ‚ f = f โ‹† , (ฮป โ‹† โ†’ โŸจ ๐“‘ โŸฉ-refl (f โ‹†)) , ฮป u ฯˆ โ†’ ฯˆ โ‹†

    Fฯ‰ : ((P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n))
    Fฯ‰ P ฯ† f = bโˆž , ฮฑโˆž , ฮฒโˆž
     where
      g : (n : โ„•) โ†’ P n โ†’ โŸจ ๐“‘ โŸฉ
      g n p = f โˆฃ n , p โˆฃ

      h : (n : โ„•) โ†’ ฮฃ b ๊ž‰ โŸจ ๐“‘ โŸฉ , (b is-the-join-of g n on ๐“‘)
      h n = ฯ† n (g n)

      b : โ„• โ†’ โŸจ ๐“‘ โŸฉ
      b n = prโ‚ (h n)

      ฮฑ : (n : โ„•) (p : P n) โ†’ g n p โ‰คโŸจ ๐“‘ โŸฉ b n
      ฮฑ n = prโ‚ (prโ‚‚ (h n))

      ฮฒ : (n : โ„•) (u : โŸจ ๐“‘ โŸฉ) โ†’ ((p : P n) โ†’ (g n p) โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ b n โ‰คโŸจ ๐“‘ โŸฉ u
      ฮฒ n = prโ‚‚ (prโ‚‚ (h n))

      bโˆž : โŸจ ๐“‘ โŸฉ
      bโˆž = โ‹โŸจ ๐“‘ โŸฉ b

      ฮฑโˆž : (q : โˆƒ n ๊ž‰ โ„• , P n) โ†’ f q โ‰คโŸจ ๐“‘ โŸฉ bโˆž
      ฮฑโˆž = โˆฅโˆฅ-induction (ฮป s โ†’ โŸจ ๐“‘ โŸฉ-order-is-prop-valued (f s) bโˆž) ฮฑโˆž'
       where
        ฮฑโˆž' : (ฯƒ : ฮฃ n ๊ž‰ โ„• , P n) โ†’ f โˆฃ ฯƒ โˆฃ โ‰คโŸจ ๐“‘ โŸฉ bโˆž
        ฮฑโˆž' (n , p) = โŸจ ๐“‘ โŸฉ-trans (g n p) (b n) bโˆž (ฮฑ n p) (โŸจ ๐“‘ โŸฉ-โ‹-is-ub b n)

      ฮฒโˆž : (u : โŸจ ๐“‘ โŸฉ) โ†’ ((q : โˆƒ n ๊ž‰ โ„• , P n) โ†’ f q โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ bโˆž โ‰คโŸจ ๐“‘ โŸฉ u
      ฮฒโˆž u ฯˆ = โŸจ ๐“‘ โŸฉ-โ‹-is-lb-of-ubs b u l
       where
        l : (n : โ„•) โ†’ b n โ‰คโŸจ ๐“‘ โŸฉ u
        l n = ฮฒ n u (ฮป p โ†’ ฯˆ โˆฃ n , p โˆฃ)

\end{code}

We repackage the above.

\begin{code}

  module _ {๐“ฅ ๐“ฆ : Universe}
           (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ)
           (P : ๐“ฃ ฬ‡ )
           (i : is-quasidecidable P)
           (f : P โ†’ โŸจ ๐“‘ โŸฉ)
         where

    sup : โŸจ ๐“‘ โŸฉ
    sup = prโ‚ (ฯƒ-suplats-have-quasidecidable-joins ๐“‘ P i f)

    sup-is-ub : (p : P) โ†’ f p โ‰คโŸจ ๐“‘ โŸฉ sup
    sup-is-ub = prโ‚ (prโ‚‚ (ฯƒ-suplats-have-quasidecidable-joins ๐“‘ P i f))

    sup-is-lb-of-ubs : (u : โŸจ ๐“‘ โŸฉ) โ†’ ((p : P) โ†’ f p โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ sup โ‰คโŸจ ๐“‘ โŸฉ u
    sup-is-lb-of-ubs = prโ‚‚ (prโ‚‚ (ฯƒ-suplats-have-quasidecidable-joins ๐“‘ P i f))

\end{code}

We say that a map is a q-embedding if its fibers are all
quasidecidable. We define three versions of the same definition to
help Agda to solve constraints.

\begin{code}

  is-q-embedding : {X : ๐“ฃ ฬ‡ } {Y : ๐“ฃ ฬ‡ } โ†’ (X โ†’ Y) โ†’ ๐“ฃ โบ ฬ‡
  is-q-embedding f = โˆ€ y โ†’ is-quasidecidable (fiber f y)

  is-q-embeddingl : {X : ๐“ฃ ฬ‡ } {Y : ๐“คโ‚€ ฬ‡ } โ†’ (X โ†’ Y) โ†’ ๐“ฃ โบ ฬ‡
  is-q-embeddingl f = โˆ€ y โ†’ is-quasidecidable (fiber f y)

  is-q-embeddingr : {X : ๐“คโ‚€ ฬ‡ } {Y : ๐“ฃ ฬ‡ } โ†’ (X โ†’ Y) โ†’ ๐“ฃ โบ ฬ‡
  is-q-embeddingr f = โˆ€ y โ†’ is-quasidecidable (fiber f y)

\end{code}

The following generalizes the existence of quasidecidable-indexed
joins.

\begin{code}

  ฯƒ-suplats-have-quasidecidable-joins'
   : (๐“‘ : ฯƒ-SupLat ๐“ฅ ๐“ฆ) {I : ๐“ฃ ฬ‡ }
   โ†’ (f : I โ†’ โ„•)
   โ†’ is-q-embeddingl f
   โ†’ (b : โ„• โ†’ โŸจ ๐“‘ โŸฉ)
   โ†’ ฮฃ c ๊ž‰ โŸจ ๐“‘ โŸฉ , (c is-the-join-of (b โˆ˜ f) on ๐“‘)
  ฯƒ-suplats-have-quasidecidable-joins' {๐“ฅ} {๐“ฆ} ๐“‘ {I} f q b
   = c , ฮฑ , ฮฒ
   where
    g : I โ†’ โŸจ ๐“‘ โŸฉ
    g = b โˆ˜ f

    a : โ„• โ†’ A
    a n = prโ‚ (q n)

    e : (n : โ„•) โ†’ ฯ„ (a n) holds ๏ผ (ฮฃ i ๊ž‰ I , f i ๏ผ n)
    e n = prโ‚‚ (q n)

    ฮณ : (n : โ„•) โ†’ ฯ„ (a n) holds โ†’ (ฮฃ i ๊ž‰ I , f i ๏ผ n)
    ฮณ n = Idtofun (e n)

    ฮด : (n : โ„•)  โ†’ (ฮฃ i ๊ž‰ I , f i ๏ผ n) โ†’ ฯ„ (a n) holds
    ฮด n = Idtofun ((e n)โปยน)

    g' : (n : โ„•) โ†’ ฯ„ (a n) holds โ†’ โŸจ ๐“‘ โŸฉ
    g' n h = g (prโ‚ (ฮณ n h))

    b' : โ„• โ†’ โŸจ ๐“‘ โŸฉ
    b' n = sup ๐“‘ (ฯ„ (a n) holds) (a n , refl) (g' n)

    c : โŸจ ๐“‘ โŸฉ
    c = โ‹โŸจ ๐“‘ โŸฉ b'

    ฮฑ : โˆ€ i โ†’ b (f i) โ‰คโŸจ ๐“‘ โŸฉ c
    ฮฑ i = โŸจ ๐“‘ โŸฉ-trans (b (f i)) (b' (f i)) c lโ‚‚ lโ‚€
     where
      lโ‚€ : b' (f i) โ‰คโŸจ ๐“‘ โŸฉ c
      lโ‚€ = โŸจ ๐“‘ โŸฉ-โ‹-is-ub b' (f i)

      lโ‚ : g' (f i) (ฮด (f i) (i , refl)) โ‰คโŸจ ๐“‘ โŸฉ b' (f i)
      lโ‚ = sup-is-ub ๐“‘
            (ฯ„ (a (f i)) holds)
            (a (f i) , refl)
            (g' (f i))
            (ฮด (f i)
            (i , refl))

      r : g' (f i) (ฮด (f i) (i , refl))
        ๏ผ b (f (prโ‚ (ฮณ (f i) (ฮด (f i) (i , refl)))))
      r = refl

      s : b (f (prโ‚ (ฮณ (f i) (ฮด (f i) (i , refl))))) ๏ผ b (f i)
      s = ap (ฮป - โ†’ b (f (prโ‚ -))) (Idtofun-retraction (e (f i)) (i , refl))

      t : g' (f i) (ฮด (f i) (i , refl)) ๏ผ b (f i)
      t = s

      lโ‚‚ : b (f i) โ‰คโŸจ ๐“‘ โŸฉ b' (f i)
      lโ‚‚ = transport (ฮป - โ†’ - โ‰คโŸจ ๐“‘ โŸฉ b' (f i)) s lโ‚

    ฮฒ : (u : โŸจ ๐“‘ โŸฉ) โ†’ (โˆ€ i โ†’ b (f i) โ‰คโŸจ ๐“‘ โŸฉ u) โ†’ c โ‰คโŸจ ๐“‘ โŸฉ u
    ฮฒ u ฯ† = โŸจ ๐“‘ โŸฉ-โ‹-is-lb-of-ubs b' u l
     where
      ฯ†' : (n : โ„•) (h : ฯ„ (a n) holds) โ†’ g' n h โ‰คโŸจ ๐“‘ โŸฉ u
      ฯ†' n h = ฯ† (prโ‚ (ฮณ n h))

      l : (n : โ„•) โ†’ b' n โ‰คโŸจ ๐“‘ โŸฉ u
      l n = sup-is-lb-of-ubs ๐“‘ (ฯ„ (a n) holds) (a n , refl) (g' n) u (ฯ†' n)

\end{code}

We now generalize and resize part of the above (without resizing
axioms) by replacing equality by equivalence in the definition of
quasidecidability:

\begin{code}

  is-quasidecidable' : ๐“ฅ ฬ‡ โ†’ ๐“ฃ โŠ” ๐“ฅ ฬ‡
  is-quasidecidable' P = ฮฃ a ๊ž‰ A , (ฯ„ a holds โ‰ƒ P)

  is-quasidecidableโ‚€ : ๐“ฃ ฬ‡ โ†’ ๐“ฃ ฬ‡
  is-quasidecidableโ‚€ = is-quasidecidable' {๐“ฃ}

  quasidecidability-resizing : (P : ๐“ฃ ฬ‡ )
                             โ†’ is-quasidecidable P โ‰ƒ is-quasidecidableโ‚€ P
  quasidecidability-resizing P = ฮฃ-cong e
   where
    e : (a : A) โ†’ (ฯ„ a holds ๏ผ P) โ‰ƒ (ฯ„ a holds โ‰ƒ P)
    e a = prop-univalent-โ‰ƒ' pe fe P (ฯ„ a holds) (holds-is-prop (ฯ„ a))

  being-quasidecidableโ‚€-is-prop : (P : ๐“ฃ ฬ‡ ) โ†’ is-prop (is-quasidecidableโ‚€ P)
  being-quasidecidableโ‚€-is-prop P = equiv-to-prop
                                     (โ‰ƒ-sym (quasidecidability-resizing P))
                                     (being-quasidecidable-is-prop P)

  ๐Ÿ˜-is-quasidecidableโ‚€ : is-quasidecidableโ‚€ ๐Ÿ˜
  ๐Ÿ˜-is-quasidecidableโ‚€ = โŒœ quasidecidability-resizing ๐Ÿ˜ โŒ ๐Ÿ˜-is-quasidecidable

  ๐Ÿ™-is-quasidecidableโ‚€ : is-quasidecidableโ‚€ ๐Ÿ™
  ๐Ÿ™-is-quasidecidableโ‚€ = โŒœ quasidecidability-resizing ๐Ÿ™ โŒ ๐Ÿ™-is-quasidecidable

  quasidecidableโ‚€-closed-under-ฯ‰-joins
   : (P : โ„• โ†’ ๐“ฃ ฬ‡ )
   โ†’ ((n : โ„•) โ†’ is-quasidecidableโ‚€ (P n))
   โ†’ is-quasidecidableโ‚€ (โˆƒ n ๊ž‰ โ„• , P n)
  quasidecidableโ‚€-closed-under-ฯ‰-joins P ฯ† =
   โŒœ quasidecidability-resizing (โˆƒ n ๊ž‰ โ„• , P n) โŒ
    (quasidecidable-closed-under-ฯ‰-joins P ฯ†')
   where
    ฯ†' : (n : โ„•) โ†’ is-quasidecidable (P n)
    ฯ†' n = โŒœ quasidecidability-resizing (P n) โŒโปยน (ฯ† n)

  quasidecidableโ‚€-induction
   : (F : ๐“ฃ ฬ‡ โ†’ ๐“ฅ ฬ‡ )
   โ†’ ((P : ๐“ฃ ฬ‡ ) โ†’ is-prop (F P))
   โ†’ F ๐Ÿ˜
   โ†’ F ๐Ÿ™
   โ†’ ((P : โ„• โ†’ ๐“ฃ ฬ‡ ) โ†’ ((n : โ„•) โ†’ F (P n)) โ†’ F (โˆƒ n ๊ž‰ โ„• , P n))
   โ†’ (P : ๐“ฃ ฬ‡ ) โ†’ is-quasidecidableโ‚€ P โ†’ F P
  quasidecidableโ‚€-induction F i Fโ‚€ Fโ‚ Fฯ‰ P q
   = quasidecidable-induction F i Fโ‚€ Fโ‚ Fฯ‰ P (โŒœ quasidecidability-resizing P โŒโปยน q)

\end{code}

This concludes the module hypothetical-free-ฯƒ-SupLat-on-one-generator.

We now give the proofs of the main theorems by calling the above modules.

\begin{code}

theoremโ‚ {๐“ฃ} {๐“ค} q = free-ฯƒ-SupLat-on-one-generator QD โŠค QD-is-free-ฯƒ-SupLat
 where
  open quasidecidable-propositions-exist q
  open hypothetical-quasidecidability {๐“ฃ} {๐“ค}
        (quasidecidable-propositions
          is-quasidecidable
          being-quasidecidable-is-prop
          ๐Ÿ˜-is-quasidecidable
          ๐Ÿ™-is-quasidecidable
          quasidecidable-closed-under-ฯ‰-joins
          quasidecidable-induction)

theoremโ‚‚ {๐“ฃ} {๐“ค} f = quasidecidable-propositions
                       is-quasidecidableโ‚€
                       being-quasidecidableโ‚€-is-prop
                       ๐Ÿ˜-is-quasidecidableโ‚€
                       ๐Ÿ™-is-quasidecidableโ‚€
                       quasidecidableโ‚€-closed-under-ฯ‰-joins
                       quasidecidableโ‚€-induction
 where
  open free-ฯƒ-SupLat-on-one-generator-exists f
  open hypothetical-free-ฯƒ-SupLat-on-one-generator
  open assumptions {๐“ฃ} {๐“ค} ๐“ โŠค ๐“-free

theoremโ‚ƒ {๐“ฃ} {๐“š} f = initial-ฯƒ-frame A-qua-ฯƒ-frame A-qua-ฯƒ-frame-is-initial
 where
  open free-ฯƒ-SupLat-on-one-generator-exists f
  open hypothetical-free-ฯƒ-SupLat-on-one-generator
  open assumptions {๐“ฃ} {๐“š} ๐“ โŠค ๐“-free

theoremโ‚„ {๐“ฃ} {๐“š} ฯ = quasidecidable-propositions
                       is-quasidecidable
                       being-quasidecidable-is-prop
                       ๐Ÿ˜-is-quasidecidable
                       ๐Ÿ™-is-quasidecidable
                       quasidecidable-closed-under-ฯ‰-joins
                       quasidecidable-induction
 where
  open quasidecidability-construction-from-resizing ๐“ฃ ๐“š ฯ

\end{code}

TODO.

  * Very little here has to do with the nature of the type โ„•. We never used
    zero, successor, or induction! (But they are used in
    OrderedTypes.sigma-sup-lattice to construct binary joins, which are not
    used here.) Any indexing type replacing โ„• works in the above development,
    with the definition of ฯƒ-sup-lattice generalized to have an arbitrary (but
    fixed) indexing type in place of โ„•. (We could have multiple indexing types,
    but this would require a modification of the above development.)

  * Define, by induction (or as a W-type) a type similar to the
    Brouwer ordinals, with two constructors 0 and 1 and a formal
    โ„•-indexed sup operation. We have a unique map to the initial
    ฯƒ-sup-lattice that transforms formal sups into sups and maps 0 to
    โŠฅ and 1 to โŠค. Is this function a surjection (it is definitely not
    an injection), or what (known) axioms are needed for it to be a
    surjection? Countable choice suffices. But is it necessary? It
    seems likely that the choice principle studied in the above paper
    with Cory Knapp is necessary and sufficient. This principle
    implies that the quasidecidable propositions agree with the
    semidecidable ones.