-
Notifications
You must be signed in to change notification settings - Fork 257
Filters - alternative to the base of Domain theory #2829
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
gabriellisboaconegero
wants to merge
3
commits into
agda:master
Choose a base branch
from
gabriellisboaconegero:filters
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+131
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Structures for order-theoretic filters | ||
------------------------------------------------------------------------ | ||
-- As per our discussion, we should add the definition of a filter to | ||
-- agda-stdlib. | ||
|
||
-- ## Background | ||
|
||
-- First, some background. Let (P, ≤) be a preorder (or more generally, I | ||
-- guess just a relation `R : P → P → Set`). A *filter* of size κ in P consists of | ||
-- a predicate `F : P → Set κ` that satisfies the following conditions: | ||
|
||
-- - `F` is upwards closed: if x ≤ y and F(x), then F(y) | ||
-- - `F` is downwards directed: there exists some x with F(x), and for | ||
-- - every x, y : P with F(x) and F(y), there exists some z : P with | ||
-- F(z) × z ≤ x × z ≤ y | ||
|
||
-- Some useful facts: | ||
|
||
-- - If P is a meet semilattice, then conditions 1 and 2 jointly imply that | ||
-- F(⊤), and conditions 1 and 3 mean that F(x) × F(y) → F(x ∧ y), where ∧ | ||
-- is the meet. | ||
-- - Alternatively, if P is a meet semilattice, then a κ-small filter is | ||
-- equivalent to a meet semilattice homomorphism P → Type κ, where the | ||
-- unit type is the top element, and meets are given by products of | ||
-- types. | ||
|
||
-- ## Programming | ||
|
||
-- There does need to be some thought as to organization. We should go with | ||
-- the definition I listed first as our primary definition, as it is the | ||
-- most general. The useful facts would be nice to prove as theorems. | ||
|
||
-- Moreover, I think we should place the definition either in it's own file | ||
-- `Relation.Binary.Filter`, or inside of a folder like | ||
-- `Relation.Binary.Diagram.Filter`; not sure here. Theorems would be | ||
-- somewhere in Relation.Binary.Lattice.Filter or something. | ||
|
||
-- We might want to factor out the "downward directed" and "upwards closed" bits into their own | ||
-- definitions? Could also place all of this in `Relation.Binary.Subset` or | ||
-- something, as they are all definitions regarding subsets of binary | ||
-- relations? Note that there are also "downwards closed" and "upwards | ||
-- directed" sets, so be careful with names! | ||
|
||
-- PS: for bonus points, you could also add *ideals* in a preorder: these | ||
-- are the duals of filters; IE: downwards-closed, upwards directed. | ||
|
||
-- Hope that makes sense, | ||
-- Reed :) | ||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module Relation.Binary.Filter where | ||
|
||
open import Relation.Binary.Core using (Rel) | ||
open import Data.Product.Base using (∃-syntax; _×_; _,_) | ||
open import Level | ||
open import Relation.Binary.Structures using (IsPreorder) | ||
open import Relation.Binary.Definitions using (_Respects_) | ||
open import Function.Base using (flip) | ||
|
||
private | ||
variable | ||
a κ ℓ₁ ℓ₂ : Level | ||
A : Set a | ||
|
||
UpwardClosure : (A → Set ℓ₁) → Rel A ℓ₂ → Set _ | ||
UpwardClosure F _≤_ = F Respects _≤_ | ||
|
||
DownwardDirectdness : (A → Set ℓ₁) → Rel A ℓ₂ → Set _ | ||
DownwardDirectdness {A = A} F _≤_ = (∃[ x ] F x) × (∀ x y → (F x) × (F y) → ∃[ z ] (F z × z ≤ x × z ≤ y)) | ||
|
||
DownwardClosure : (A → Set ℓ₁) → Rel A ℓ₂ → Set _ | ||
DownwardClosure {A = A} F _≤_ = UpwardClosure F (flip _≤_) | ||
|
||
UpwardDirectdness : (A → Set ℓ₁) → Rel A ℓ₂ → Set _ | ||
UpwardDirectdness {A = A} F _≤_ = DownwardDirectdness F (flip _≤_) | ||
|
||
record IsFilter {a κ ℓ} {A : Set κ} (F : A → Set κ) (_≤_ : Rel A ℓ) : Set (a ⊔ κ ⊔ ℓ) where | ||
field | ||
upClosed : UpwardClosure F _≤_ | ||
downDirected : DownwardDirectdness F _≤_ | ||
|
||
record IsIdeal {a κ ℓ} {A : Set κ} (F : A → Set κ) (_≤_ : Rel A ℓ) : Set (a ⊔ κ ⊔ ℓ) where | ||
field | ||
downClosed : DownwardClosure F _≤_ | ||
upDirected : UpwardDirectdness F _≤_ | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Properties satisfied by meet semilattices | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
open import Relation.Binary.Lattice | ||
|
||
module Relation.Binary.Lattice.Filter | ||
{κ ℓ₁ ℓ₂} (P : BoundedMeetSemilattice κ ℓ₁ ℓ₂) where | ||
|
||
open import Function.Base using (flip; _∘_) | ||
open import Relation.Binary.Structures using (IsDecPartialOrder) | ||
open import Relation.Binary.Definitions using (Decidable) | ||
open import Relation.Binary.Filter using (IsFilter) | ||
open import Data.Product.Base using (∃-syntax; _×_; _,_; proj₁; proj₂) | ||
|
||
open BoundedMeetSemilattice P | ||
|
||
open import Relation.Binary.Lattice.Properties.MeetSemilattice meetSemilattice | ||
|
||
open import Relation.Binary.Properties.Poset poset using (≥-isPartialOrder) | ||
import Relation.Binary.Lattice.Properties.JoinSemilattice as J | ||
|
||
-- The dual construction is a join semilattice. | ||
|
||
fact0 : (F : Carrier → Set κ) → IsFilter F _≤_ → F ⊤ | ||
fact0 F filter = | ||
let (x , Fx) = downDirected .proj₁ | ||
in upClosed {x = x} {y = ⊤} (maximum x) Fx | ||
where | ||
open IsFilter filter | ||
|
||
fact1 : (F : Carrier → Set κ) → IsFilter F _≤_ → (∀ x y → F x × F y → F (x ∧ y)) | ||
fact1 F filter x y (Fx , Fy) = | ||
let (z , Fz , z≤x , z≤y) = downDirected .proj₂ x y (Fx , Fy) | ||
in upClosed {x = z} {y = x ∧ y} (∧-greatest z≤x z≤y) Fz | ||
where | ||
open IsFilter filter |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that the thing which makes me uneasy about such a definition is that it fuses two aspects of the definition, in the interest of avoiding some of the difficulties that Reed alludes to in #2814 , namely:
F
_≤_
restricted to the subset defined byF
', as being directedI think as far as
stdlib
is concerned, it would be (more) helpful to isolate the second one, as for example in #2813 (where it would make sense simply to cherry-pick the definition, and perhaps some of its properties, and leave thePointed
extension construction to a separate PR), and as to the first, perhaps introduce a/the construction, analogous toFunction.Base._on_
, corresponding to the first one?Not sure whether we should continue the discussion here, or else on #2814 though.