Debian Codegraph @

src/Algebra/Construct/LexProduct/Base.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Definitions of the lexicographic product of two operators.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Algebra.Core using (Op₂)
10 open import Data.Bool.Base using (true; false)
11 open import Data.Product.Base using (_×_; _,_)
12 open import Relation.Binary.Core using (Rel)
13 open import Relation.Binary.Definitions using (Decidable)
14 open import Relation.Nullary.Decidable.Core using (does; yes; no)
15
16 module Algebra.Construct.LexProduct.Base
17 {a b ℓ} {A : Set a} {B : Set b}
18 (_∙_ : Op₂ A) (_◦_ : Op₂ B)
19 {_≈₁_ : Rel A ℓ} (_≟₁_ : Decidable _≈₁_)
20 where
21
22 ------------------------------------------------------------------------
23 -- Definition
24
25 -- In order to get the first component to be definitionally equal to
26 -- `a ∙ b` and to simplify some of the proofs we first define an inner
27 -- operator that only calculates the second component of product.
28
29 innerLex : A → A → B → B → B
30 innerLex a b x y with does ((a ∙ b) ≟₁ a) | does ((a ∙ b) ≟₁ b)
31 ... | true | false = x
32 ... | false | true = y
33 ... | _ | _ = x ◦ y
34
35 -- The full lexicographic choice operator can then be simply defined
36 -- in terms of the inner one.
37
38 lex : Op₂ (A × B)
39 lex (a , x) (b , y) = (a ∙ b , innerLex a b x y)