Skip to content

Commit 327ec79

Browse files
authored
Lemmata for if_then_else_ (#2747)
* [add]: lemmata for if_then_else_ * [changelog]: lemmata for if_then_else_ * [refactor]: rename if-swap to if-swap-else * [changelog]: rename if-swap to if-swap-else * [add]: Data.Bool.Properties.if-swap-then * [add]: Data.Bool.Properties.if-swap-then * [add]: if-idem-then + if-idem-else * [changelog]: if-idem-then + if-idem-else * rename and extend if-cong lemmata * [refactor]: fix indentation of if-cong * [docs]: Reasoning behind if-cong lemmas * [refactor]: add line breaks to some if-lemmas This (1) follows the style guide of having a line length limit of 72 characters and (2) increases readability because it enables immediately seeing which sub-terms of an if_then_else_ expression are substituted.
1 parent 5bd195e commit 327ec79

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,23 @@ Additions to existing modules
253253
∙-cong-∣ : x ∣ y → a ∣ b → x ∙ a ∣ y ∙ b
254254
```
255255

256+
* In `Data.Bool.Properties`:
257+
```agda
258+
if-eta : ∀ b → (if b then x else x) ≡ x
259+
if-idem-then : ∀ b → (if b then (if b then x else y) else y) ≡ (if b then x else y)
260+
if-idem-else : ∀ b → (if b then x else (if b then x else y)) ≡ (if b then x else y)
261+
if-swap-then : ∀ b c → (if b then (if c then x else y) else y) ≡ (if c then (if b then x else y) else y)
262+
if-swap-else : ∀ b c → (if b then x else (if c then x else y)) ≡ (if c then x else (if b then x else y))
263+
if-not : ∀ b → (if not b then x else y) ≡ (if b then y else x)
264+
if-∧ : ∀ b → (if b ∧ c then x else y) ≡ (if b then (if c then x else y) else y)
265+
if-∨ : ∀ b → (if b ∨ c then x else y) ≡ (if b then x else (if c then x else y))
266+
if-xor : ∀ b → (if b xor c then x else y) ≡ (if b then (if c then y else x) else (if c then x else y))
267+
if-cong : b ≡ c → (if b then x else y) ≡ (if c then x else y)
268+
if-cong-then : ∀ b → x ≡ z → (if b then x else y) ≡ (if b then z else y)
269+
if-cong-else : ∀ b → y ≡ z → (if b then x else y) ≡ (if b then x else z)
270+
if-cong₂ : ∀ b → x ≡ z → y ≡ w → (if b then x else y) ≡ (if b then z else w)
271+
```
272+
256273
* In `Data.Fin.Base`:
257274
```agda
258275
_≰_ : Rel (Fin n) 0ℓ

src/Data/Bool/Properties.agda

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,91 @@ if-float : ∀ (f : A → B) b {x y} →
745745
if-float _ true = refl
746746
if-float _ false = refl
747747

748+
if-eta : b {x : A}
749+
(if b then x else x) ≡ x
750+
if-eta false = refl
751+
if-eta true = refl
752+
753+
if-idem-then : b {x y : A}
754+
(if b then (if b then x else y) else y)
755+
≡ (if b then x else y)
756+
if-idem-then false = refl
757+
if-idem-then true = refl
758+
759+
if-idem-else : b {x y : A}
760+
(if b then x else (if b then x else y))
761+
≡ (if b then x else y)
762+
if-idem-else false = refl
763+
if-idem-else true = refl
764+
765+
if-swap-then : b c {x y : A}
766+
(if b then (if c then x else y) else y)
767+
≡ (if c then (if b then x else y) else y)
768+
if-swap-then false false = refl
769+
if-swap-then false true = refl
770+
if-swap-then true _ = refl
771+
772+
if-swap-else : b c {x y : A}
773+
(if b then x else (if c then x else y))
774+
≡ (if c then x else (if b then x else y))
775+
if-swap-else false _ = refl
776+
if-swap-else true false = refl
777+
if-swap-else true true = refl
778+
779+
if-not : b {x y : A}
780+
(if not b then x else y) ≡ (if b then y else x)
781+
if-not false = refl
782+
if-not true = refl
783+
784+
if-∧ : b {c} {x y : A}
785+
(if b ∧ c then x else y) ≡ (if b then (if c then x else y) else y)
786+
if-∧ false = refl
787+
if-∧ true = refl
788+
789+
if-∨ : b {c} {x y : A}
790+
(if b ∨ c then x else y) ≡ (if b then x else (if c then x else y))
791+
if-∨ false = refl
792+
if-∨ true = refl
793+
794+
if-xor : b {c} {x y : A}
795+
(if b xor c then x else y)
796+
≡ (if b then (if c then y else x) else (if c then x else y))
797+
if-xor false = refl
798+
if-xor true {false} = refl
799+
if-xor true {true } = refl
800+
801+
-- The following congruence lemmas are short hands for
802+
-- cong (if_then x else y)
803+
-- cong (if b then_else y)
804+
-- cong (if b then x else_)
805+
-- cong (if b then_else_)
806+
-- on the different sub-terms in an if_then_else_ expression.
807+
-- With these short hands, the branches x and y can be inferred
808+
-- automatically (i.e., they are implicit arguments) whereas
809+
-- the branches have to be spelled out explicitly when using cong.
810+
-- (Using underscores as in "cong (if b then _ else_)"
811+
-- unfortunately fails to resolve the omitted argument.)
812+
813+
if-cong : {b c} {x y : A} b ≡ c
814+
(if b then x else y)
815+
≡ (if c then x else y)
816+
if-cong refl = refl
817+
818+
if-cong-then : b {x y z : A} x ≡ z
819+
(if b then x else y)
820+
≡ (if b then z else y)
821+
if-cong-then _ refl = refl
822+
823+
if-cong-else : b {x y z : A} y ≡ z
824+
(if b then x else y)
825+
≡ (if b then x else z)
826+
if-cong-else _ refl = refl
827+
828+
if-cong₂ : b {x y z w : A} x ≡ z y ≡ w
829+
(if b then x else y)
830+
≡ (if b then z else w)
831+
if-cong₂ _ refl refl = refl
832+
748833
------------------------------------------------------------------------
749834
-- Properties of T
750835

0 commit comments

Comments
 (0)