J. A. Carr 8 July 2025.

The untruncated form of the at-most-two elements is equivalent
to the statement that Aut ฮฉ has exactly 1 or 2 elements
(and hence every element is either identity or negation)

\begin{code}

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

open import MLTT.Spartan
open import MLTT.Plus-Properties
open import UF.DiscreteAndSeparated
open import TypeTopology.SigmaDiscreteAndTotallySeparated
open import UF.Equiv hiding (_โ‰…_)
open import UF.FunExt
open import UF.Logic
open import UF.PropTrunc
open import UF.Subsingletons
open import UF.SubtypeClassifier hiding (ฮฉ)
open import Fin.Type
open import Fin.Topology
open import Fin.Pigeonhole

module Higgs.UntruncatedAtMostTwo
        {๐“ค : Universe}
        (fe : Fun-Ext)
        (pe : propext ๐“ค)
        (pt : propositional-truncations-exist)
       where

open import Higgs.Rigidity fe pe
open import Higgs.InvolutionTheorem fe pe
open import Higgs.AutomorphismsOfOmega fe pe
open import Higgs.AutomorphismsOfOmegaWEM fe pe pt

open Conjunction
open Implication fe
open Universal fe

\end{code}

Assuming function extensionality, having an untruncated pigeonhole principle
reflects discreteness to the codomain.

The core method is to note that the pidgeonhole function must respect equality
of functions, so we produce a pair of functions, where equality of their results
holds if and only if the two elements of the codomain are equal.

\begin{code}

constantly : {๐“ค ๐“ฅ : Universe}
           โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ }
           โ†’ Y โ†’ X โ†’ Y
constantly y _ = y

almost-constantly-inner : {๐“ค ๐“ฅ : Universe}
                  โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ }
                  โ†’ (x' : X) โ†’ Y โ†’ Y โ†’ (x : X)
                  โ†’ ((x' ๏ผ x) + (x' โ‰  x))
                  โ†’ Y
almost-constantly-inner _ y' y _ (inl _) = y'
almost-constantly-inner _ y' y _ (inr _) = y

almost-constantly : {๐“ค ๐“ฅ : Universe}
                  โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ }
                  โ†’ is-discrete X
                  โ†’ X โ†’ Y โ†’ Y โ†’ X
                  โ†’ Y
almost-constantly X-discrete x' y' y x =
 almost-constantly-inner x' y' y x (X-discrete x' x)

almost-constantly-eq : {๐“ค ๐“ฅ : Universe}
                     โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ }
                     โ†’ (X-discrete : is-discrete X)
                     โ†’ (x : X)
                     โ†’ (y' y : Y)
                     โ†’ almost-constantly X-discrete x y' y x ๏ผ y'
almost-constantly-eq X-discrete x y' y =
 almost-constantly X-discrete x y' y x               ๏ผโŸจ refl โŸฉ
 almost-constantly-inner x y' y x (X-discrete x x)   ๏ผโŸจ I โŸฉ
 almost-constantly-inner x y' y x (inl refl)         ๏ผโŸจ refl โŸฉ
 y'                                                  โˆŽ
 where
  I : almost-constantly-inner x y' y x (X-discrete x x)
      ๏ผ almost-constantly-inner x y' y x (inl refl)
  I = ap (almost-constantly-inner x y' y x)
         (discrete-inl-refl X-discrete x)

almost-constantly-neq : {๐“ค ๐“ฅ : Universe}
                      โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ }
                      โ†’ (X-discrete : is-discrete X)
                      โ†’ (x' x : X)
                      โ†’ (y' y : Y)
                      โ†’ (x' โ‰  x)
                      โ†’ almost-constantly X-discrete x' y' y x ๏ผ y
almost-constantly-neq X-discrete x' x y' y ฮฝ =
 almost-constantly X-discrete x' y' y x               ๏ผโŸจ refl โŸฉ
 almost-constantly-inner x' y' y x (X-discrete x' x)  ๏ผโŸจ I โŸฉ
 almost-constantly-inner x' y' y x (inr ฮฝ)            ๏ผโŸจ refl โŸฉ
 y                                                    โˆŽ
 where
  I :  almost-constantly-inner x' y' y x (X-discrete x' x)
       ๏ผ almost-constantly-inner x' y' y x (inr ฮฝ)
  I = ap (almost-constantly-inner x' y' y x)
         (discrete-inr fe X-discrete x' x ฮฝ)


almost-constantly-is-constant
 : {๐“ค ๐“ฅ : Universe}
 โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ }
 โ†’ (X-discrete : is-discrete X)
 โ†’ (x' : X)
 โ†’ (y y' : Y)
 โ†’ y ๏ผ y'
 โ†’ constantly y ๏ผ almost-constantly X-discrete x' y' y
almost-constantly-is-constant {_} {_} {X} {Y} X-discrete x' y _ refl = dfunext fe III
 where
  I : constantly y x' ๏ผ y
  I = refl

  II : (x : X)
     โ†’ ((x' ๏ผ x) + (x' โ‰  x))
     โ†’ almost-constantly X-discrete x' y y x ๏ผ y
  II _ (inl refl) = almost-constantly-eq X-discrete x' y y
  II x (inr ฮฝ) = almost-constantly-neq X-discrete x' x y y ฮฝ

  III : (x : X) โ†’ constantly y x' ๏ผ almost-constantly X-discrete x' y y x
  III x = I โˆ™ II x (X-discrete x' x) โปยน


at-most-discrete-gives-discrete
 : {๐“ค ๐“ฅ : Universe}
 โ†’ (X : ๐“ค ฬ‡) (Y : ๐“ฅ ฬ‡)
 โ†’ is-discrete X
 โ†’ ((f : X โ†’ Y) โ†’ f has-a-repetition)
 โ†’ is-discrete Y
at-most-discrete-gives-discrete X Y X-discrete f-ph y y' = V VI
 where

  repeat-indices : (X โ†’ Y)
                 โ†’ X ร— X
  repeat-indices f =
    (ฮป (x , x' , _) โ†’ (x , x'))
    (f-ph f)

  repeat-is-repeat : (f : X โ†’ Y)
                   โ†’ let (x , x') = repeat-indices f
                     in f x ๏ผ f x'
  repeat-is-repeat f =
    let (x , x' , _ , pf) = f-ph f
    in pf

  repeat-distinct : (f : X โ†’ Y)
                  โ†’ let (x , x') = repeat-indices f
                    in x โ‰  x'
  repeat-distinct f =
    let (x , x' , pf , _) = f-ph f
    in pf

  fโ‚ = constantly y
  ixโ‚ = repeat-indices fโ‚
  fโ‚‚ = almost-constantly X-discrete (prโ‚ ixโ‚) y' y
  ixโ‚‚ = repeat-indices fโ‚‚

  I : y ๏ผ y' โ†’ ixโ‚ ๏ผ ixโ‚‚
  I e = ap repeat-indices
           (almost-constantly-is-constant X-discrete (prโ‚ ixโ‚) y y' e)

  II : (x : X)
     โ†’ (prโ‚ ixโ‚ โ‰  x)
     โ†’ y ๏ผ fโ‚‚ x
  II x ne = almost-constantly-neq X-discrete (prโ‚ ixโ‚) x y' y ne โปยน

  III : fโ‚‚ (prโ‚ ixโ‚) ๏ผ y'
  III = almost-constantly-eq X-discrete (prโ‚ ixโ‚) y' y

  IV : ixโ‚ ๏ผ ixโ‚‚ โ†’ y ๏ผ y'
  IV e =
   y                            ๏ผโŸจ II (prโ‚‚ ixโ‚) (repeat-distinct fโ‚) โŸฉ
   fโ‚‚ (prโ‚‚ ixโ‚)                 ๏ผโŸจ ap (fโ‚‚ โˆ˜ prโ‚‚) e โŸฉ
   fโ‚‚ (prโ‚‚ ixโ‚‚)                 ๏ผโŸจ refl โŸฉ
   fโ‚‚ (prโ‚‚ (repeat-indices fโ‚‚)) ๏ผโŸจ repeat-is-repeat fโ‚‚ โปยน โŸฉ
   fโ‚‚ (prโ‚ (repeat-indices fโ‚‚)) ๏ผโŸจ refl โŸฉ
   fโ‚‚ (prโ‚ ixโ‚‚)                 ๏ผโŸจ ap (fโ‚‚ โˆ˜ prโ‚) (e โปยน) โŸฉ
   fโ‚‚ (prโ‚ ixโ‚)                 ๏ผโŸจ III โŸฉ
   y'                           โˆŽ

  V : is-decidable (ixโ‚ ๏ผ ixโ‚‚) โ†’ is-decidable (y ๏ผ y')
  V (inl e) = inl (IV e)
  V (inr ne) = inr (ne โˆ˜ I)

  VI : is-decidable (ixโ‚ ๏ผ ixโ‚‚)
  VI = ร—-is-discrete X-discrete X-discrete ixโ‚ ixโ‚‚

\end{code}

We may write the untruncated form of the at-most-2 lemma in this form

\begin{code}ย 

at-most-two-is-pigeonhole
 : {๐“ค : Universe}
 โ†’ {X : ๐“ค ฬ‡}
 โ†’ ((x y z : X) โ†’ (z ๏ผ x) + (x ๏ผ y) + (y ๏ผ z))
 โ†’ (f : Fin 3 โ†’ X)
 โ†’ f has-a-repetition
at-most-two-is-pigeonhole at-most-2 f = II I
 where
  v1 v2 v3 : Fin 3
  v1 = inr โ‹†
  v2 = inl (inr โ‹†)
  v3 = inl (inl (inr โ‹†))

  true-when-eq : Fin 3
               โ†’ Fin 3
               โ†’ ๐“ค โบ ฬ‡
  true-when-eq (inl (inl _)) (inl (inl _)) = ๐Ÿ™
  true-when-eq (inl (inl _)) (inl (inr _)) = ๐Ÿ˜
  true-when-eq (inl (inl _)) (inr _) = ๐Ÿ˜

  true-when-eq (inl (inr _)) (inl (inl _)) = ๐Ÿ˜
  true-when-eq (inl (inr _)) (inl (inr _)) = ๐Ÿ™
  true-when-eq (inl (inr _)) (inr _) = ๐Ÿ˜

  true-when-eq (inr _) (inl (inl _)) = ๐Ÿ˜
  true-when-eq (inr _) (inl (inr _)) = ๐Ÿ˜
  true-when-eq (inr _) (inr _) = ๐Ÿ™

  v3-not-1 : v3 โ‰  v1
  v3-not-1 e = ๐Ÿ˜-elim (transport (true-when-eq v3) e โ‹†)
  v1-not-2 : v1 โ‰  v2
  v1-not-2 e = ๐Ÿ˜-elim (transport (true-when-eq v1) e โ‹†)
  v2-not-3 : v2 โ‰  v3
  v2-not-3 e = ๐Ÿ˜-elim (transport (true-when-eq v2) e โ‹†)

  I : (f v3 ๏ผ f v1) + (f v1 ๏ผ f v2) + (f v2 ๏ผ f v3)
  I = at-most-2 (f v1) (f v2) (f v3)

  II : (f v3 ๏ผ f v1) + (f v1 ๏ผ f v2) + (f v2 ๏ผ f v3)
     โ†’ f has-a-repetition
  II (inl e31)       = ( v3 , v1 , v3-not-1 , e31 )
  II (inr (inl e12)) = ( v1 , v2 , v1-not-2 , e12 )
  II (inr (inr e23)) = ( v2 , v3 , v2-not-3 , e23 )

aut-ฮฉ-discrete-has-em
 : is-discrete (Aut ฮฉ)
 โ†’ (๐•— : Aut ฮฉ)
 โ†’ (๐•— ๏ผ ๐•š๐••) + (๐•— โ‰  ๐•š๐••)
aut-ฮฉ-discrete-has-em aut-disc ๐•— = aut-disc ๐•— ๐•š๐••

untruncated-at-most-two-iff-em
 : ((f g h : Aut ฮฉ) โ†’ (h ๏ผ f) + (f ๏ผ g) + (g ๏ผ h))
 โ†” ((๐•— : Aut ฮฉ) โ†’ (๐•— ๏ผ ๐•š๐••) + (๐•— โ‰  ๐•š๐••))
untruncated-at-most-two-iff-em = (FW , BW)
 where
  FW : ((f g h : Aut ฮฉ) โ†’ (h ๏ผ f) + (f ๏ผ g) + (g ๏ผ h))
     โ†’ ((๐•— : Aut ฮฉ) โ†’ (๐•— ๏ผ ๐•š๐••) + (๐•— โ‰  ๐•š๐••))
  FW at-most-two = aut-ฮฉ-discrete-has-em
   (at-most-discrete-gives-discrete
    (Fin 3) (Aut ฮฉ)
    Fin-is-discrete
    (at-most-two-is-pigeonhole at-most-two))

  I : {f g : Aut ฮฉ}
    โ†’ (f โ‰  ๐•š๐••)
    โ†’ (g โ‰  ๐•š๐••)
    โ†’ (f ๏ผ g)
  I {f} f-not g-not = ((not-id-is-not f-not em) โˆ™ (not-id-is-not g-not em) โปยน)
   where
    em = ฮฉ-automorphism-distinct-from-๐•š๐••-gives-EM (f , f-not)

  II : {f g h : Aut ฮฉ}
     โ†’ ((f ๏ผ ๐•š๐••) + (f โ‰  ๐•š๐••))
     โ†’ ((g ๏ผ ๐•š๐••) + (g โ‰  ๐•š๐••))
     โ†’ ((h ๏ผ ๐•š๐••) + (h โ‰  ๐•š๐••))
     โ†’ (h ๏ผ f) + (f ๏ผ g) + (g ๏ผ h)
  II (inl  ef) (inl  eg) (_      ) = inr (inl (ef โˆ™ eg โปยน))
  II (inl  _ ) (inr neg) (inr neh) = inr (inr (I neg neh))
  II (inl  ef) (inr neg) (inl  eh) = inl (eh โˆ™ ef โปยน)
  II (inr  _ ) (inl  eg) (inl  eh) = inr (inr (eg โˆ™ eh โปยน))
  II (inr nef) (inr neg) (_      ) = inr (inl (I nef neg))
  II (inr nef) (inl  _ ) (inr neh) = inl (I neh nef)

  BW : ((๐•— : Aut ฮฉ) โ†’ (๐•— ๏ผ ๐•š๐••) + (๐•— โ‰  ๐•š๐••))
     โ†’ ((f g h : Aut ฮฉ) โ†’ (h ๏ผ f) + (f ๏ผ g) + (g ๏ผ h))
  BW em f g h = II (em f) (em g) (em h)


\end{code}ย