Skip to content

[Add] Initial files for Domain theory #2721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ New modules

* `Data.Sign.Show` to show a sign

* Added a new domain theory section to the library under `Relation.Binary.Domain.*`:
- Introduced new modules and bundles for domain theory, including `DCPO`, `Lub`, and `ScottContinuous`.
- All files for domain theory are now available in `src/Relation/Binary/Domain/`.

Additions to existing modules
-----------------------------

Expand Down
16 changes: 16 additions & 0 deletions src/Relation/Binary/Domain.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Order-theoretic Domains
------------------------------------------------------------------------

{-# OPTIONS --cubical-compatible --safe #-}

module Relation.Binary.Domain where

------------------------------------------------------------------------
-- Re-export various components of the Domain hierarchy

open import Relation.Binary.Domain.Definitions public
open import Relation.Binary.Domain.Structures public
open import Relation.Binary.Domain.Bundles public
53 changes: 53 additions & 0 deletions src/Relation/Binary/Domain/Bundles.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bundles for domain theory
------------------------------------------------------------------------

{-# OPTIONS --cubical-compatible --safe #-}

module Relation.Binary.Domain.Bundles where

open import Level using (Level; _⊔_; suc)
open import Relation.Binary.Bundles using (Poset)
open import Relation.Binary.Domain.Structures
open import Relation.Binary.Domain.Definitions

private
variable
o ℓ e o' ℓ' e' ℓ₂ : Level
Ix A B : Set o

------------------------------------------------------------------------
-- DCPOs
------------------------------------------------------------------------

record DCPO (c ℓ₁ ℓ₂ : Level) : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
field
poset : Poset c ℓ₁ ℓ₂
DcpoStr : IsDCPO poset

open Poset poset public
open IsDCPO DcpoStr public

------------------------------------------------------------------------
-- Scott-continuous functions
------------------------------------------------------------------------

record ScottContinuous {c ℓ₁ ℓ₂ : Level} {P : Poset c ℓ₁ ℓ₂} {Q : Poset c ℓ₁ ℓ₂} :
Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
field
f : Poset.Carrier P → Poset.Carrier Q
Scottfunction : IsScottContinuous {P = P} {Q = Q} f

------------------------------------------------------------------------
-- Lubs
------------------------------------------------------------------------

record Lub {c ℓ₁ ℓ₂ : Level} {P : Poset c ℓ₁ ℓ₂} {Ix : Set c} (s : Ix → Poset.Carrier P) : Set (c ⊔ ℓ₁ ⊔ ℓ₂) where
private
module P = Poset P
field
lub : P.Carrier
is-upperbound : ∀ i → P._≤_ (s i) lub
is-least : ∀ y → (∀ i → P._≤_ (s i) y) → P._≤_ lub y
28 changes: 28 additions & 0 deletions src/Relation/Binary/Domain/Definitions.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Definitions for domain theory
------------------------------------------------------------------------

{-# OPTIONS --cubical-compatible --safe #-}

module Relation.Binary.Domain.Definitions where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that neither of the definitions here depend on Poset (now), maybe they should go where all the other binary relations are defined?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that all 3 definitions below should be moved to Relation.Binary.Definitions, with the naming made consistent with the names already in that file.


open import Data.Product using (∃-syntax; _×_; _,_)
open import Level using (Level; _⊔_)
open import Relation.Binary.Bundles using (Poset)
open import Relation.Binary.Morphism.Structures using (IsOrderHomomorphism)

private
variable
c o ℓ e o' ℓ' e' ℓ₁ ℓ₂ : Level
Ix A B : Set o
P : Poset c ℓ e

------------------------------------------------------------------------
-- Directed families
------------------------------------------------------------------------

IsSemidirectedFamily : (P : Poset c ℓ₁ ℓ₂) → ∀ {Ix : Set c} → (s : Ix → Poset.Carrier P) → Set _
IsSemidirectedFamily P {Ix} s = ∀ i j → ∃[ k ] (Poset._≤_ P (s i) (s k) × Poset._≤_ P (s j) (s k))

66 changes: 66 additions & 0 deletions src/Relation/Binary/Domain/Structures.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Structures for domain theory
------------------------------------------------------------------------

{-# OPTIONS --cubical-compatible --safe #-}

module Relation.Binary.Domain.Structures where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To 'fit' the rest of stdlib, even though this is all "most useful" for a full Poset, these structures should be in terms of a RawRelation, as that is all that is used in the definitions.


open import Data.Product using (_×_; _,_)
open import Data.Nat.Properties using (≤-trans)
open import Function using (_∘_)
open import Level using (Level; _⊔_; suc)
open import Relation.Binary.Bundles using (Poset)
open import Relation.Binary.Domain.Definitions
open import Relation.Binary.Morphism.Structures using (IsOrderHomomorphism)

private variable
o ℓ e o' ℓ' e' ℓ₂ : Level
Ix A B : Set o

module _ {c ℓ₁ ℓ₂ : Level} (P : Poset c ℓ₁ ℓ₂) where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these definitions really need a Poset or just a relation? I don't immediately see the use of any of the other fields of Poset below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition doesn't need a Poset, but this is essentially always going to be used with a Poset/Preorder. Using a bare relation could cause rather poor inference later down the line, so I'd hesitate a bit on this generalization.

We could also use a Preorder here, but that doesn't really buy us much. Doing posetal completions is really, really cheap with setoids, and the preorder versions of lemmas would be essentially the same thing as the plugging in a posetal completion to a poset-based version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of which: is posetal completion anywhere in the stdlib?

open Poset P

record IsDirectedFamily {Ix : Set c} (s : Ix → Carrier) : Set (c ⊔ ℓ₁ ⊔ ℓ₂) where
no-eta-equality
field
elt : Ix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does elt stand for?

Copy link
Contributor Author

@jmougeot jmougeot Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elt stands for element, should I change it ?

SemiDirected : IsSemidirectedFamily P s

record IsLub {Ix : Set c} (s : Ix → Carrier) (lub : Carrier) : Set (c ⊔ ℓ₁ ⊔ ℓ₂) where
field
is-upperbound : ∀ i → s i ≤ lub
is-least : ∀ y → (∀ i → s i ≤ y) → lub ≤ y

record IsDCPO : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
field
⋁ : ∀ {Ix : Set c}
→ (s : Ix → Carrier)
→ IsDirectedFamily s
→ Carrier
⋁-isLub : ∀ {Ix : Set c}
→ (s : Ix → Carrier)
→ (dir : IsDirectedFamily s)
→ IsLub s (⋁ s dir)

module _ {Ix : Set c} {s : Ix → Carrier} {dir : IsDirectedFamily s} where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this module's renaming? Could we document it?

Copy link
Contributor Author

@jmougeot jmougeot Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the renaming to simplify domain properties proofs for instance in the following proof :

  •  With the renaming you can prove immediately:
myUpperBound
  : ∀ {B : Set c} (f : B → Carrier) (dir : IsDirectedFamily f) (i : B)
  → f i ≤ ⋁ f dir
myUpperBound f dir i = ⋁-≤ f dir i
  •  Without the renaming you’d have to write something like:
myUpperBound
  : ∀ {B : Set c} (f : B → Carrier) (dir : IsDirectedFamily f) (i : B)
  → f i ≤ ⋁ f dir
myUpperBound′ f dir i = IsLub.isUpperBound (IsDirectedCompletePartialOrder.⋁-isLub f dir) i

But let me know if changes are needed

open IsLub (⋁-isLub s dir)
renaming (is-upperbound to ⋁-≤; is-least to ⋁-least)
public

module _ {c ℓ₁ ℓ₂ : Level} {P : Poset c ℓ₁ ℓ₂} {Q : Poset c ℓ₁ ℓ₂} where

private
module P = Poset P
module Q = Poset Q

record IsScottContinuous (f : P.Carrier → Q.Carrier) : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
field
PreserveLub : ∀ {Ix : Set c} {s : Ix → P.Carrier}
→ (dir : IsDirectedFamily P s)
→ (lub : P.Carrier)
→ IsLub P s lub
→ IsLub Q (f ∘ s) (f lub)
PreserveEquality : ∀ {x y} → x P.≈ y → f x Q.≈ f y