------------------------------------------------------------------------
-- The Agda standard library
--
-- Some basic properties of bijections.
------------------------------------------------------------------------

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

module Function.Properties.Bijection where

open import Function.Bundles
  using (Bijection; Inverse; Equivalence; _⤖_; _↔_; _⇔_)
open import Level using (Level)
open import Relation.Binary.Bundles using (Setoid)
open import Relation.Binary.Structures using (IsEquivalence)
open import Relation.Binary.Definitions using (Reflexive; Trans)
open import Relation.Binary.PropositionalEquality.Properties using (setoid)
open import Data.Product.Base using (_,_; proj₁; proj₂)
open import Function.Base using (_∘_)
open import Function.Properties.Inverse using (Inverse⇒Equivalence)

import Function.Construct.Identity as Identity
import Function.Construct.Symmetry as Symmetry
import Function.Construct.Composition as Composition

private
  variable
    a b c  ℓ₁ ℓ₂ ℓ₃ : Level
    A B : Set a
    T S : Setoid a 


------------------------------------------------------------------------
-- Setoid properties

refl : Reflexive (Bijection {a} {})
refl = Identity.bijection _

sym : Bijection S T  Bijection T S
sym = Symmetry.bijection

trans : Trans (Bijection {a} {ℓ₁} {b} {ℓ₂}) (Bijection {b} {ℓ₂} {c} {ℓ₃}) Bijection
trans = Composition.bijection

------------------------------------------------------------------------
-- Propositional properties

⤖-isEquivalence : IsEquivalence { = } _⤖_
⤖-isEquivalence = record
  { refl  = refl
  ; sym   = sym
  ; trans = trans
  }

------------------------------------------------------------------------
-- Conversion functions

Bijection⇒Inverse : Bijection S T  Inverse S T
Bijection⇒Inverse bij = record
  { to        = B.to
  ; from      = B.from
  ; to-cong   = B.cong
  ; from-cong = B.from-cong
  ; inverse   = B.inverseˡ , B.inverseʳ
  }
  where module B = Bijection bij

Bijection⇒Equivalence : Bijection T S  Equivalence T S
Bijection⇒Equivalence = Inverse⇒Equivalence  Bijection⇒Inverse

⤖⇒↔ : A  B  A  B
⤖⇒↔ = Bijection⇒Inverse

⤖⇒⇔ : A  B  A  B
⤖⇒⇔ = Bijection⇒Equivalence


------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.

-- Version 3.0

sym-≡ = sym
{-# WARNING_ON_USAGE sym-≡
"Warning: sym-≡ was deprecated in v3.0.
Please use sym instead. "
#-}