-
Notifications
You must be signed in to change notification settings - Fork 248
Port two Endomorphism submodules over to new Function hierarchy #2342
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6619f11
port over two modules
JacquesCarette 1af553e
and add to CHANGELOG
JacquesCarette 81230ec
fix whitespace
JacquesCarette 3305480
fix warning: it was pointing to a record that did not exist.
JacquesCarette e1e7c57
Merge branch 'FixWarning' into Endomorphism
JacquesCarette d1cae72
fix things as per Matthew's review - though this remains a breaking c…
JacquesCarette 93e9e0f
take care of comments from James.
JacquesCarette 35d3bb9
Merge branch 'master' into Endomorphism
JacquesCarette d258064
Merge branch 'master' into Endomorphism
JacquesCarette a2e3c26
adjust CHANGELOG for what will be implemented shortly
JacquesCarette e9fc145
Revert "take care of comments from James."
JacquesCarette 9665443
Revert "fix things as per Matthew's review - though this remains a br…
JacquesCarette 8cb04db
Revert "fix whitespace"
JacquesCarette 154fb0e
Revert "port over two modules"
JacquesCarette d5d8113
rename these
JacquesCarette b04ab5d
fix tiny merge issue
JacquesCarette 60ecbeb
get deprecations right (remove where not needed, make more global whe…
JacquesCarette 08c8866
style guide - missing blank lines
JacquesCarette e7d4961
fix a bad merge
JacquesCarette b28f62d
fixed deprecations
jamesmckinna 278547a
fix #2394
jamesmckinna c71cb83
minor tweaks
JacquesCarette 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
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,108 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Endomorphisms on a Set | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module Function.Endo.Propositional {a} (A : Set a) where | ||
|
||
open import Algebra using (Semigroup; Magma; RawMagma; Monoid; RawMonoid) | ||
open import Algebra.Core | ||
open import Algebra.Structures using (IsMagma; IsSemigroup; IsMonoid) | ||
open import Algebra.Morphism | ||
using (module Definitions; IsMagmaHomomorphism; IsMonoidHomomorphism) | ||
open Definitions using (Homomorphic₂) | ||
|
||
open import Data.Nat.Base using (ℕ; zero; suc; _+_; +-rawMagma; +-0-rawMonoid) | ||
open import Data.Nat.Properties using (+-0-monoid; +-semigroup) | ||
open import Data.Product.Base using (_,_) | ||
|
||
open import Function.Base using (id; _∘′_; _∋_) | ||
open import Function.Bundles using (Func; _⟶ₛ_; _⟨$⟩_) | ||
open import Relation.Binary.Core using (_Preserves_⟶_) | ||
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong; cong₂) | ||
import Relation.Binary.PropositionalEquality.Properties as ≡ | ||
|
||
import Function.Endo.Setoid (≡.setoid A) as Setoid | ||
|
||
Endo : Set a | ||
Endo = A → A | ||
|
||
------------------------------------------------------------------------ | ||
-- Conversion back and forth with the Setoid-based notion of Endomorphism | ||
|
||
fromSetoidEndo : Setoid.Endo → Endo | ||
fromSetoidEndo = _⟨$⟩_ | ||
|
||
toSetoidEndo : Endo → Setoid.Endo | ||
toSetoidEndo f = record | ||
{ to = f | ||
; cong = cong f | ||
} | ||
|
||
------------------------------------------------------------------------ | ||
-- N-th composition | ||
|
||
infixr 8 _^_ | ||
|
||
_^_ : Endo → ℕ → Endo | ||
f ^ zero = id | ||
f ^ suc n = f ∘′ (f ^ n) | ||
|
||
^-homo : ∀ f → Homomorphic₂ ℕ Endo _≡_ (f ^_) _+_ _∘′_ | ||
^-homo f zero n = refl | ||
^-homo f (suc m) n = cong (f ∘′_) (^-homo f m n) | ||
|
||
------------------------------------------------------------------------ | ||
-- Structures | ||
|
||
∘-isMagma : IsMagma _≡_ (Op₂ Endo ∋ _∘′_) | ||
jamesmckinna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
∘-isMagma = record | ||
{ isEquivalence = ≡.isEquivalence | ||
; ∙-cong = cong₂ _∘′_ | ||
} | ||
|
||
∘-magma : Magma _ _ | ||
∘-magma = record { isMagma = ∘-isMagma } | ||
|
||
∘-isSemigroup : IsSemigroup _≡_ (Op₂ Endo ∋ _∘′_) | ||
∘-isSemigroup = record | ||
{ isMagma = ∘-isMagma | ||
; assoc = λ _ _ _ → refl | ||
} | ||
|
||
∘-semigroup : Semigroup _ _ | ||
∘-semigroup = record { isSemigroup = ∘-isSemigroup } | ||
|
||
∘-id-isMonoid : IsMonoid _≡_ _∘′_ id | ||
∘-id-isMonoid = record | ||
{ isSemigroup = ∘-isSemigroup | ||
; identity = (λ _ → refl) , (λ _ → refl) | ||
} | ||
|
||
∘-id-monoid : Monoid _ _ | ||
∘-id-monoid = record { isMonoid = ∘-id-isMonoid } | ||
|
||
private | ||
∘-rawMagma : RawMagma a a | ||
∘-rawMagma = Semigroup.rawMagma ∘-semigroup | ||
|
||
∘-id-rawMonoid : RawMonoid a a | ||
∘-id-rawMonoid = Monoid.rawMonoid ∘-id-monoid | ||
jamesmckinna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
------------------------------------------------------------------------ | ||
-- Homomorphism | ||
|
||
^-isMagmaHomomorphism : ∀ f → IsMagmaHomomorphism +-rawMagma ∘-rawMagma (f ^_) | ||
^-isMagmaHomomorphism f = record | ||
{ isRelHomomorphism = record { cong = cong (f ^_) } | ||
; homo = ^-homo f | ||
} | ||
jamesmckinna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
^-isMonoidHomomorphism : ∀ f → IsMonoidHomomorphism +-0-rawMonoid ∘-id-rawMonoid (f ^_) | ||
^-isMonoidHomomorphism f = record | ||
{ isMagmaHomomorphism = ^-isMagmaHomomorphism f | ||
; ε-homo = refl | ||
} |
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,110 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Endomorphisms on a Setoid | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
open import Relation.Binary.Bundles using (Setoid) | ||
|
||
module Function.Endo.Setoid {c e} (S : Setoid c e) where | ||
|
||
open import Agda.Builtin.Equality | ||
|
||
open import Algebra using (Semigroup; Magma; RawMagma; Monoid; RawMonoid) | ||
open import Algebra.Structures using (IsMagma; IsSemigroup; IsMonoid) | ||
open import Algebra.Morphism | ||
using (module Definitions; IsMagmaHomomorphism; IsMonoidHomomorphism) | ||
open Definitions using (Homomorphic₂) | ||
open import Data.Nat.Base using (ℕ; zero; suc; _+_; +-rawMagma; +-0-rawMonoid) | ||
open import Data.Nat.Properties using (+-semigroup; +-identityʳ) | ||
open import Data.Product.Base using (_,_) | ||
open import Function.Bundles using (Func; _⟶ₛ_; _⟨$⟩_) | ||
open import Function.Construct.Identity using () renaming (function to identity) | ||
open import Function.Construct.Composition using () renaming (function to _∘_) | ||
open import Function.Relation.Binary.Setoid.Equality as Eq using (_⇨_) | ||
open import Level using (Level; _⊔_) | ||
open import Relation.Binary.Core using (_Preserves_⟶_) | ||
|
||
private | ||
open module E = Setoid (S ⇨ S) hiding (refl) | ||
module S = Setoid S | ||
open Func using (cong) | ||
|
||
|
||
------------------------------------------------------------------------ | ||
JacquesCarette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-- Basic type and functions | ||
|
||
Endo : Set _ | ||
Endo = S ⟶ₛ S | ||
|
||
infixr 8 _^_ | ||
|
||
private | ||
id : Endo | ||
id = identity S | ||
|
||
_^_ : Endo → ℕ → Endo | ||
f ^ zero = id | ||
f ^ suc n = f ∘ (f ^ n) | ||
|
||
^-cong₂ : ∀ f → (f ^_) Preserves _≡_ ⟶ _≈_ | ||
^-cong₂ f {n} refl = cong (f ^ n) S.refl | ||
|
||
^-homo : ∀ f → Homomorphic₂ ℕ Endo _≈_ (f ^_) _+_ _∘_ | ||
^-homo f zero n = S.refl | ||
^-homo f (suc m) zero = ^-cong₂ f (+-identityʳ m) | ||
^-homo f (suc m) (suc n) = ^-homo f m (suc n) | ||
|
||
------------------------------------------------------------------------ | ||
-- Structures | ||
|
||
∘-isMagma : IsMagma _≈_ _∘_ | ||
∘-isMagma = record | ||
{ isEquivalence = isEquivalence | ||
; ∙-cong = λ {_} {_} {_} {v} x≈y u≈v → S.trans u≈v (cong v x≈y) | ||
} | ||
|
||
∘-magma : Magma (c ⊔ e) (c ⊔ e) | ||
∘-magma = record { isMagma = ∘-isMagma } | ||
|
||
∘-isSemigroup : IsSemigroup _≈_ _∘_ | ||
∘-isSemigroup = record | ||
{ isMagma = ∘-isMagma | ||
; assoc = λ _ _ _ → S.refl | ||
} | ||
|
||
∘-semigroup : Semigroup (c ⊔ e) (c ⊔ e) | ||
∘-semigroup = record { isSemigroup = ∘-isSemigroup } | ||
|
||
∘-id-isMonoid : IsMonoid _≈_ _∘_ id | ||
∘-id-isMonoid = record | ||
{ isSemigroup = ∘-isSemigroup | ||
; identity = (λ _ → S.refl) , (λ _ → S.refl) | ||
} | ||
|
||
∘-id-monoid : Monoid (c ⊔ e) (c ⊔ e) | ||
∘-id-monoid = record { isMonoid = ∘-id-isMonoid } | ||
|
||
private | ||
∘-rawMagma : RawMagma (c ⊔ e) (c ⊔ e) | ||
∘-rawMagma = Semigroup.rawMagma ∘-semigroup | ||
|
||
∘-id-rawMonoid : RawMonoid (c ⊔ e) (c ⊔ e) | ||
∘-id-rawMonoid = Monoid.rawMonoid ∘-id-monoid | ||
|
||
------------------------------------------------------------------------ | ||
-- Homomorphism | ||
|
||
^-isMagmaHomomorphism : ∀ f → IsMagmaHomomorphism +-rawMagma ∘-rawMagma (f ^_) | ||
^-isMagmaHomomorphism f = record | ||
{ isRelHomomorphism = record { cong = ^-cong₂ f } | ||
; homo = ^-homo f | ||
} | ||
|
||
^-isMonoidHomomorphism : ∀ f → IsMonoidHomomorphism +-0-rawMonoid ∘-id-rawMonoid (f ^_) | ||
^-isMonoidHomomorphism f = record | ||
{ isMagmaHomomorphism = ^-isMagmaHomomorphism f | ||
; ε-homo = S.refl | ||
} |
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
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
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
Oops, something went wrong.
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.