Skip to content

Commit 200ef72

Browse files
MatthewDaggittjamesmckinna
authored andcommitted
Move T? to Relation.Nullary.Decidable.Core (agda#2189)
* Move `T?` to `Relation.Nullary.Decidable.Core` * Var name fix * Some refactoring * Fix failing tests and address remaining comments * Fix style-guide
1 parent 188f74c commit 200ef72

File tree

12 files changed

+67
-57
lines changed

12 files changed

+67
-57
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,9 @@ Non-backwards compatible changes
838838

839839
4. The modules `Relation.Nullary.(Product/Sum/Implication)` have been deprecated
840840
and their contents moved to `Relation.Nullary.(Negation/Reflects/Decidable)`.
841+
842+
5. The proof `T?` has been moved from `Data.Bool.Properties` to `Relation.Nullary.Decidable.Core`
843+
(but is still re-exported by the former).
841844

842845
as well as the following breaking changes:
843846

@@ -3574,6 +3577,12 @@ Additions to existing modules
35743577
poset : Set a → Poset _ _ _
35753578
```
35763579

3580+
* Added new proof in `Relation.Nullary.Reflects`:
3581+
```agda
3582+
T-reflects : Reflects (T b) b
3583+
T-reflects-elim : Reflects (T a) b → b ≡ a
3584+
```
3585+
35773586
* Added new operations in `System.Exit`:
35783587
```
35793588
isSuccess : ExitCode → Bool

README/Design/Hierarchies.agda

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ record Semigroup : Set (suc (a ⊔ ℓ)) where
265265
-- IsA A
266266
-- / || \ / || \
267267
-- IsB IsC IsD B C D
268-
268+
269269
-- The procedure for re-exports in the bundles is as follows:
270270

271271
-- 1. `open IsA isA public using (IsC, M)` where `M` is everything
@@ -280,7 +280,7 @@ record Semigroup : Set (suc (a ⊔ ℓ)) where
280280

281281
-- 5. `open B b public using (O)` where `O` is everything exported
282282
-- by `B` but not exported by `IsA`.
283-
283+
284284
-- 6. Construct `d : D` via the `isC` obtained in step 1.
285285

286286
-- 7. `open D d public using (P)` where `P` is everything exported

notes/style-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ word within a compound word is capitalized except for the first word.
402402

403403
* Rational variables are named `p`, `q`, `r`, ... (default `p`)
404404

405-
* All other variables tend to be named `x`, `y`, `z`.
405+
* All other variables should be named `x`, `y`, `z`.
406406

407407
* Collections of elements are usually indicated by appending an `s`
408408
(e.g. if you are naming your variables `x` and `y` then lists

src/Data/Bool.agda

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
module Data.Bool where
1010

11-
open import Relation.Nullary
12-
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
13-
1411
------------------------------------------------------------------------
1512
-- The boolean type and some operations
1613

src/Data/Bool/Base.agda

+10-8
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,19 @@ true xor b = not b
5757
false xor b = b
5858

5959
------------------------------------------------------------------------
60-
-- Other operations
61-
62-
infix 0 if_then_else_
63-
64-
if_then_else_ : Bool A A A
65-
if true then t else f = t
66-
if false then t else f = f
60+
-- Conversion to Set
6761

6862
-- A function mapping true to an inhabited type and false to an empty
6963
-- type.
70-
7164
T : Bool Set
7265
T true =
7366
T false =
67+
68+
------------------------------------------------------------------------
69+
-- Other operations
70+
71+
infix 0 if_then_else_
72+
73+
if_then_else_ : Bool A A A
74+
if true then t else f = t
75+
if false then t else f = f

src/Data/Bool/Properties.agda

+23-20
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ open import Relation.Binary.Definitions
2828
using (Decidable; Reflexive; Transitive; Antisymmetric; Minimum; Maximum; Total; Irrelevant; Irreflexive; Asymmetric; Trans; Trichotomous; tri≈; tri<; tri>; _Respects₂_)
2929
open import Relation.Binary.PropositionalEquality.Core
3030
open import Relation.Binary.PropositionalEquality.Properties
31-
open import Relation.Nullary.Reflects using (ofʸ; ofⁿ)
32-
open import Relation.Nullary.Decidable.Core using (True; does; proof; yes; no)
31+
open import Relation.Nullary.Decidable.Core using (True; yes; no; fromWitness)
3332
import Relation.Unary as U
3433

3534
open import Algebra.Definitions {A = Bool} _≡_
@@ -726,15 +725,17 @@ xor-∧-commutativeRing = ⊕-∧-commutativeRing
726725
open XorRing _xor_ xor-is-ok
727726

728727
------------------------------------------------------------------------
729-
-- Miscellaneous other properties
728+
-- Properties of if_then_else_
730729

731-
⇔→≡ : {x y z : Bool} x ≡ z ⇔ y ≡ z x ≡ y
732-
⇔→≡ {true } {true } hyp = refl
733-
⇔→≡ {true } {false} {true } hyp = sym (Equivalence.to hyp refl)
734-
⇔→≡ {true } {false} {false} hyp = Equivalence.from hyp refl
735-
⇔→≡ {false} {true } {true } hyp = Equivalence.from hyp refl
736-
⇔→≡ {false} {true } {false} hyp = sym (Equivalence.to hyp refl)
737-
⇔→≡ {false} {false} hyp = refl
730+
if-float : (f : A B) b {x y}
731+
f (if b then x else y) ≡ (if b then f x else f y)
732+
if-float _ true = refl
733+
if-float _ false = refl
734+
735+
------------------------------------------------------------------------
736+
-- Properties of T
737+
738+
open Relation.Nullary.Decidable.Core public using (T?)
738739

739740
T-≡ : {x} T x ⇔ x ≡ true
740741
T-≡ {false} = mk⇔ (λ ()) (λ ())
@@ -757,18 +758,20 @@ T-∨ {false} {false} = mk⇔ inj₁ [ id , id ]
757758
T-irrelevant : U.Irrelevant T
758759
T-irrelevant {true} _ _ = refl
759760

760-
T? : U.Decidable T
761-
does (T? b) = b
762-
proof (T? true ) = ofʸ _
763-
proof (T? false) = ofⁿ λ()
764-
765761
T?-diag : b T b True (T? b)
766-
T?-diag true _ = _
762+
T?-diag b = fromWitness
763+
764+
------------------------------------------------------------------------
765+
-- Miscellaneous other properties
766+
767+
⇔→≡ : {x y z : Bool} x ≡ z ⇔ y ≡ z x ≡ y
768+
⇔→≡ {true } {true } hyp = refl
769+
⇔→≡ {true } {false} {true } hyp = sym (Equivalence.to hyp refl)
770+
⇔→≡ {true } {false} {false} hyp = Equivalence.from hyp refl
771+
⇔→≡ {false} {true } {true } hyp = Equivalence.from hyp refl
772+
⇔→≡ {false} {true } {false} hyp = sym (Equivalence.to hyp refl)
773+
⇔→≡ {false} {false} hyp = refl
767774

768-
if-float : (f : A B) b {x y}
769-
f (if b then x else y) ≡ (if b then f x else f y)
770-
if-float _ true = refl
771-
if-float _ false = refl
772775

773776
------------------------------------------------------------------------
774777
-- DEPRECATED NAMES

src/Data/List/Relation/Binary/BagAndSetEquality.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Relation.Binary.Reasoning.Preorder as PreorderReasoning
4444
open import Relation.Binary.PropositionalEquality as P
4545
using (_≡_; _≢_; _≗_; refl)
4646
open import Relation.Binary.Reasoning.Syntax
47-
open import Relation.Nullary
47+
open import Relation.Nullary.Negation using (¬_)
4848
open import Data.List.Membership.Propositional.Properties
4949

5050
private

src/Effect/Applicative.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ record RawApplicative (F : Set f → Set g) : Set (suc f ⊔ g) where
5656
-- Haskell-style alternative name for pure
5757
return : A F A
5858
return = pure
59-
59+
6060
-- backwards compatibility: unicode variants
6161
_⊛_ : F (A B) F A F B
6262
_⊛_ = _<*>_

src/Function/Bundles.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ module _ (From : Setoid a ℓ₁) (To : Setoid b ℓ₂) where
380380
-- For further background on (split) surjections, one may consult any
381381
-- general mathematical references which work without the principle
382382
-- of choice. For example:
383-
--
383+
--
384384
-- https://ncatlab.org/nlab/show/split+epimorphism.
385385
--
386386
-- The connection to set-theoretic notions with the same names is

src/Relation/Nullary.agda

+3-14
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,9 @@ open import Agda.Builtin.Equality
1515
------------------------------------------------------------------------
1616
-- Re-exports
1717

18-
open import Relation.Nullary.Negation.Core public using
19-
( ¬_; _¬-⊎_
20-
; contradiction; contradiction₂; contraposition
21-
)
22-
23-
open import Relation.Nullary.Reflects public using
24-
( Reflects; ofʸ; ofⁿ
25-
; _×-reflects_; _⊎-reflects_; _→-reflects_
26-
)
27-
28-
open import Relation.Nullary.Decidable.Core public using
29-
( Dec; does; proof; yes; no; _because_; recompute
30-
; ¬?; _×-dec_; _⊎-dec_; _→-dec_
31-
)
18+
open import Relation.Nullary.Negation.Core public
19+
open import Relation.Nullary.Reflects public
20+
open import Relation.Nullary.Decidable.Core public
3221

3322
------------------------------------------------------------------------
3423
-- Irrelevant types

src/Relation/Nullary/Decidable/Core.agda

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
module Relation.Nullary.Decidable.Core where
1313

1414
open import Level using (Level; Lift)
15-
open import Data.Bool.Base using (Bool; false; true; not; T; _∧_; _∨_)
15+
open import Data.Bool.Base using (Bool; T; false; true; not; _∧_; _∨_)
1616
open import Data.Unit.Base using (⊤)
1717
open import Data.Empty using (⊥)
1818
open import Data.Empty.Irrelevant using (⊥-elim)
@@ -79,6 +79,9 @@ recompute (no ¬a) a = ⊥-elim (¬a a)
7979
infixr 1 _⊎-dec_
8080
infixr 2 _×-dec_ _→-dec_
8181

82+
T? : x Dec (T x)
83+
T? x = x because T-reflects x
84+
8285
¬? : Dec A Dec (¬ A)
8386
does (¬? a?) = not (does a?)
8487
proof (¬? a?) = ¬-reflects (proof a?)

src/Relation/Nullary/Reflects.agda

+12-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ module Relation.Nullary.Reflects where
1111
open import Agda.Builtin.Equality
1212

1313
open import Data.Bool.Base
14+
open import Data.Unit.Base using (⊤)
1415
open import Data.Empty
1516
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
1617
open import Data.Product.Base using (_×_; _,_; proj₁; proj₂)
1718
open import Level using (Level)
18-
open import Function.Base using (_$_; _∘_; const)
19+
open import Function.Base using (_$_; _∘_; const; id)
1920

2021
open import Relation.Nullary.Negation.Core
2122

@@ -54,28 +55,31 @@ invert (ofⁿ ¬a) = ¬a
5455
------------------------------------------------------------------------
5556
-- Interaction with negation, product, sums etc.
5657

58+
infixr 1 _⊎-reflects_
59+
infixr 2 _×-reflects_ _→-reflects_
60+
61+
T-reflects : b Reflects (T b) b
62+
T-reflects true = of _
63+
T-reflects false = of id
64+
5765
-- If we can decide A, then we can decide its negation.
5866
¬-reflects : {b} Reflects A b Reflects (¬ A) (not b)
5967
¬-reflects (ofʸ a) = ofⁿ (_$ a)
6068
¬-reflects (ofⁿ ¬a) = ofʸ ¬a
6169

6270
-- If we can decide A and Q then we can decide their product
63-
infixr 2 _×-reflects_
6471
_×-reflects_ : {a b} Reflects A a Reflects B b
6572
Reflects (A × B) (a ∧ b)
6673
ofʸ a ×-reflects ofʸ b = ofʸ (a , b)
6774
ofʸ a ×-reflects ofⁿ ¬b = ofⁿ (¬b ∘ proj₂)
6875
ofⁿ ¬a ×-reflects _ = ofⁿ (¬a ∘ proj₁)
6976

70-
71-
infixr 1 _⊎-reflects_
7277
_⊎-reflects_ : {a b} Reflects A a Reflects B b
7378
Reflects (A ⊎ B) (a ∨ b)
7479
ofʸ a ⊎-reflects _ = ofʸ (inj₁ a)
7580
ofⁿ ¬a ⊎-reflects ofʸ b = ofʸ (inj₂ b)
7681
ofⁿ ¬a ⊎-reflects ofⁿ ¬b = ofⁿ (¬a ¬-⊎ ¬b)
7782

78-
infixr 2 _→-reflects_
7983
_→-reflects_ : {a b} Reflects A a Reflects B b
8084
Reflects (A B) (not a ∨ b)
8185
ofʸ a →-reflects ofʸ b = ofʸ (const b)
@@ -95,3 +99,6 @@ det (ofʸ a) (ofʸ _) = refl
9599
det (ofʸ a) (ofⁿ ¬a) = contradiction a ¬a
96100
det (ofⁿ ¬a) (ofʸ a) = contradiction a ¬a
97101
det (ofⁿ ¬a) (ofⁿ _) = refl
102+
103+
T-reflects-elim : {a b} Reflects (T a) b b ≡ a
104+
T-reflects-elim {a} r = det r (T-reflects a)

0 commit comments

Comments
 (0)