-
Notifications
You must be signed in to change notification settings - Fork 258
[ refactor ] Data.Fin.Properties.decFinSubset
#2793
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
jamesmckinna
wants to merge
7
commits into
agda:master
Choose a base branch
from
jamesmckinna:decFinSubset
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.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fdc2c02
[ refactoring ] decidable `Data.Fin.Properties`
jamesmckinna 2af5d21
refactor: make `variable`s `P`, `Q` local again
jamesmckinna ef5b6cf
Merge branch 'agda:master' into decFinSubset
jamesmckinna ee4d349
refactor: use flipped contradiction
jamesmckinna 5d0f79f
fix: comment
jamesmckinna 8d4b5a7
Merge branch 'agda:master' into decFinSubset
jamesmckinna b24b455
Restored deleted `import` of `Function.Base.flip`
jamesmckinna 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 |
---|---|---|
|
@@ -28,7 +28,7 @@ open import Data.Product.Properties using (,-injective) | |
open import Data.Product.Algebra using (×-cong) | ||
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_]; [_,_]′) | ||
open import Data.Sum.Properties using ([,]-map; [,]-∘) | ||
open import Function.Base using (_∘_; id; _$_; flip) | ||
open import Function.Base using (_∘_; id; _$_; flip; const; λ-; _$-) | ||
open import Function.Bundles using (Injection; _↣_; _⇔_; _↔_; mk⇔; mk↔ₛ′) | ||
open import Function.Definitions using (Injective; Surjective) | ||
open import Function.Consequences.Propositional using (contraInjective) | ||
|
@@ -54,10 +54,13 @@ open import Relation.Unary.Properties using (U?) | |
|
||
private | ||
variable | ||
a : Level | ||
a p q : Level | ||
A : Set a | ||
m n o : ℕ | ||
i j : Fin n | ||
P : Pred (Fin n) p | ||
Q : Pred (Fin n) q | ||
|
||
|
||
------------------------------------------------------------------------ | ||
-- Fin | ||
|
@@ -954,7 +957,7 @@ pinch-injective {i = suc i} {suc j} {suc k} 1+i≢j 1+i≢k eq = | |
-- Quantification | ||
------------------------------------------------------------------------ | ||
|
||
module _ {p} {P : Pred (Fin (suc n)) p} where | ||
module _ {P : Pred (Fin (suc n)) p} where | ||
|
||
∀-cons : P zero → Π[ P ∘ suc ] → Π[ P ] | ||
∀-cons z s zero = z | ||
|
@@ -976,33 +979,19 @@ module _ {p} {P : Pred (Fin (suc n)) p} where | |
⊎⇔∃ : (P zero ⊎ ∃⟨ P ∘ suc ⟩) ⇔ ∃⟨ P ⟩ | ||
⊎⇔∃ = mk⇔ [ ∃-here , ∃-there ] ∃-toSum | ||
|
||
decFinSubset : ∀ {p q} {P : Pred (Fin n) p} {Q : Pred (Fin n) q} → | ||
Decidable Q → (∀ {i} → Q i → Dec (P i)) → Dec (Q ⊆ P) | ||
decFinSubset {zero} {_} {_} Q? P? = yes λ {} | ||
decFinSubset {suc n} {P = P} {Q} Q? P? | ||
with Q? zero | ∀-cons {P = λ x → Q x → P x} | ||
... | false because [¬Q0] | cons = | ||
map′ (λ f {x} → cons (⊥-elim ∘ invert [¬Q0]) (λ x → f {x}) x) | ||
(λ f {x} → f {suc x}) | ||
(decFinSubset (Q? ∘ suc) P?) | ||
... | true because [Q0] | cons = | ||
map′ (uncurry λ P0 rec {x} → cons (λ _ → P0) (λ x → rec {x}) x) | ||
< _$ invert [Q0] , (λ f {x} → f {suc x}) > | ||
(P? (invert [Q0]) ×-dec decFinSubset (Q? ∘ suc) P?) | ||
|
||
any? : ∀ {p} {P : Pred (Fin n) p} → Decidable P → Dec (∃ P) | ||
any? {zero} {P = _} P? = no λ { (() , _) } | ||
any? {suc n} {P = P} P? = Dec.map ⊎⇔∃ (P? zero ⊎-dec any? (P? ∘ suc)) | ||
|
||
all? : ∀ {p} {P : Pred (Fin n) p} → Decidable P → Dec (∀ f → P f) | ||
all? P? = map′ (λ ∀p f → ∀p tt) (λ ∀p {x} _ → ∀p x) | ||
(decFinSubset U? (λ {f} _ → P? f)) | ||
any? : Decidable P → Dec (∃ P) | ||
any? {zero} P? = no λ{ (() , _) } | ||
any? {suc _} P? = Dec.map ⊎⇔∃ (P? zero ⊎-dec any? (P? ∘ suc)) | ||
|
||
all? : Decidable P → Dec (∀ i → P i) | ||
all? {zero} P? = yes λ() | ||
all? {suc _} P? = Dec.map ∀-cons-⇔ (P? zero ×-dec all? (P? ∘ suc)) | ||
|
||
private | ||
-- A nice computational property of `all?`: | ||
-- The boolean component of the result is exactly the | ||
-- obvious fold of boolean tests (`foldr _∧_ true`). | ||
note : ∀ {p} {P : Pred (Fin 3) p} (P? : Decidable P) → | ||
note : ∀ {P : Pred (Fin 3) p} (P? : Decidable P) → | ||
∃ λ z → Dec.does (all? P?) ≡ z | ||
note P? = Dec.does (P? 0F) ∧ Dec.does (P? 1F) ∧ Dec.does (P? 2F) ∧ true | ||
, refl | ||
|
@@ -1025,6 +1014,29 @@ private | |
¬ (∀ i → P i) → (∃ λ i → ¬ P i) | ||
¬∀⟶∃¬ n P P? ¬P = map id proj₁ (¬∀⟶∃¬-smallest n P P? ¬P) | ||
|
||
-- Kleisli lifting of Dec over Unary subset relation | ||
|
||
|
||
decFinSubset : Decidable Q → Q ⊆ Dec ∘ P → Dec (Q ⊆ P) | ||
decFinSubset {zero} {_} {_} Q? P? = yes λ{} | ||
decFinSubset {suc _} {Q = Q} {P = P} Q? P? = dec[Q⊆P] | ||
module DecFinSubset where | ||
Q⊆₀P = Q 0F → P 0F | ||
Q⊆ₛP = Q ∘ suc ⊆ P ∘ suc | ||
|
||
cons : Q⊆₀P → Q⊆ₛP → Q ⊆ P | ||
cons q₀⊆p₀ qₛ⊆pₛ = ∀-cons {P = Q U.⇒ P} q₀⊆p₀ (λ- qₛ⊆pₛ) $- | ||
|
||
ih : Dec Q⊆ₛP | ||
ih = decFinSubset (Q? ∘ suc) P? | ||
|
||
Q⊆P⇒Q⊆ₛP : Q ⊆ P → Q⊆ₛP | ||
Q⊆P⇒Q⊆ₛP q⊆p {x} = q⊆p {suc x} | ||
|
||
dec[Q⊆P] : Dec (Q ⊆ P) | ||
dec[Q⊆P] with Q? zero | ||
... | no ¬q₀ = map′ (cons (flip contradiction ¬q₀)) Q⊆P⇒Q⊆ₛP ih | ||
... | yes q₀ = map′ (uncurry (cons ∘ const)) < _$ q₀ , Q⊆P⇒Q⊆ₛP > (P? q₀ ×-dec ih) | ||
|
||
------------------------------------------------------------------------ | ||
-- Properties of functions to and from Fin | ||
------------------------------------------------------------------------ | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.