-
Notifications
You must be signed in to change notification settings - Fork 259
Proofs of the Binomial Theorem for (Commutative)Semiring [supersedes #1287]
#1928
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 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3c0de49
proofs of the Binomial Theorem
jamesmckinna 5e93491
followed Nathan's suggestions; fixed up dependencies; rebase and recheck
jamesmckinna 434546f
`--cubica-compatible` plus fix-whitespace
jamesmckinna d6cc72b
clean copy of `Top` view
jamesmckinna 54fdf95
updated `CHANGELOG` with `Top` view
jamesmckinna a16a15f
review changes
jamesmckinna 809c115
minor simplification
jamesmckinna 9b11064
cosmetic tweaks
jamesmckinna 73db427
removed dependency on `Top.Instances`
jamesmckinna f3bebb5
tightened imports
jamesmckinna 2942b08
moved `Top` to `TopBinomial` for subsequent deletion after merging #1923
jamesmckinna 81679a5
more tweaks to private lemma
jamesmckinna 249a772
pushed before saving
jamesmckinna e20d47e
cosmetic tweaks to final proof
jamesmckinna 699b00c
added more syntax for sums
jamesmckinna 2c31571
Merge branch 'master' into binomial-theorem
jamesmckinna 854eb38
Update Binomial.agda to bring up to date with #1923
jamesmckinna e3e4cdf
Delete temporary copy src/Data/Fin/Relation/Unary/TopBinomial.agda
jamesmckinna 3b67531
Flattened module structure
MatthewDaggitt 11e2fb3
Fix comment
MatthewDaggitt 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,141 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- The 'top' view of Fin | ||
| -- | ||
| -- This is an example of a view of (elements of) a datatype, | ||
| -- here i : Fin (suc n), which exhibits every such i as | ||
| -- * either, i = fromℕ n | ||
| -- * or, i = inject₁ j for a unique j : Fin n | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --cubical-compatible --safe #-} | ||
|
|
||
| module Data.Fin.Relation.Unary.Top where | ||
|
|
||
| open import Data.Empty using (⊥; ⊥-elim) | ||
| open import Data.Nat.Base using (ℕ; zero; suc; _<_; _∸_) | ||
| open import Data.Nat.Properties using (n∸n≡0; +-∸-assoc) | ||
| open import Data.Product using (uncurry) | ||
| open import Data.Sum using (inj₁; inj₂) | ||
| open import Data.Fin.Base hiding (_<_) | ||
| open import Data.Fin.Properties as Fin | ||
| using (suc-injective; toℕ-fromℕ; toℕ<n; toℕ-inject₁; inject₁ℕ<) | ||
| open import Relation.Binary.PropositionalEquality | ||
|
|
||
| private | ||
| variable | ||
| n : ℕ | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- The View, considered as a unary relation on Fin (suc n) | ||
|
|
||
| -- First, a lemma not in `Data.Fin.Properties`, | ||
| -- but which establishes disjointness of the | ||
| -- (interpretations of the) constructors of the View | ||
|
|
||
| top≢inject₁ : ∀ (j : Fin n) → fromℕ n ≢ inject₁ j | ||
| top≢inject₁ (suc j) eq = top≢inject₁ j (suc-injective eq) | ||
|
|
||
| -- The View, itself | ||
|
|
||
| data View : (i : Fin (suc n)) → Set where | ||
|
|
||
| top : View (fromℕ n) | ||
| inj : (j : Fin n) → View (inject₁ j) | ||
|
|
||
| -- The view covering function, witnessing soundness of the view | ||
|
|
||
| view : ∀ {n} i → View {n} i | ||
| view {n = zero} zero = top | ||
| view {n = suc _} zero = inj _ | ||
| view {n = suc n} (suc i) with view {n} i | ||
| ... | top = top | ||
| ... | inj j = inj (suc j) | ||
|
|
||
| -- Interpretation of the view constructors | ||
|
|
||
| ⟦_⟧ : ∀ {i} → View {n} i → Fin (suc n) | ||
| ⟦ top ⟧ = fromℕ _ | ||
| ⟦ inj j ⟧ = inject₁ j | ||
|
|
||
| -- Completeness of the view | ||
|
|
||
| view-complete : ∀ {i} (v : View {n} i) → ⟦ v ⟧ ≡ i | ||
| view-complete top = refl | ||
| view-complete (inj j) = refl | ||
|
|
||
| -- 'Computational' behaviour of the covering function | ||
|
|
||
| view-top : ∀ n → view {n} (fromℕ n) ≡ top | ||
| view-top zero = refl | ||
| view-top (suc n) rewrite view-top n = refl | ||
|
|
||
| view-inj : ∀ j → view {n} (inject₁ j) ≡ inj j | ||
| view-inj zero = refl | ||
| view-inj (suc j) rewrite view-inj j = refl | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Experimental | ||
| -- | ||
| -- Because we work --without-K, Agda's unifier will complain about | ||
| -- attempts to match `refl` against hypotheses of the form | ||
| -- `view {n] i ≡ v` | ||
| -- or gets stuck trying to solve unification problems of the form | ||
| -- (inferred index ≟ expected index) | ||
| -- even when these problems are *provably* solvable. | ||
| -- | ||
| -- So the two predicates on values of the view defined below | ||
| -- are extensionally equivalent to the assertions | ||
| -- `view {n] i ≡ top` and `view {n] i ≡ inj j` | ||
| -- | ||
| -- But such assertions can only ever have a unique (irrelevant) proof | ||
| -- so we introduce instances to witness them, themselves given by | ||
| -- the functions `view-top` and `view-inj` defined above | ||
|
|
||
| module Instances {n} where | ||
|
|
||
| data IsTop : ∀ {i} → View {n} i → Set where | ||
|
|
||
| top : IsTop top | ||
|
|
||
| instance | ||
|
|
||
| top⁺ : IsTop {i = fromℕ n} (view (fromℕ n)) | ||
| top⁺ rewrite view-top n = top | ||
|
|
||
| data IsInj : ∀ {i} → View {n} i → Set where | ||
|
|
||
| inj : ∀ j → IsInj (inj j) | ||
|
|
||
| instance | ||
|
|
||
| inj⁺ : ∀ {j} → IsInj (view (inject₁ j)) | ||
| inj⁺ {j} rewrite view-inj j = inj j | ||
|
|
||
| inject₁≡⁺ : ∀ {i} {j} {eq : inject₁ i ≡ j} → IsInj (view j) | ||
| inject₁≡⁺ {eq = refl} = inj⁺ | ||
|
|
||
| n≢inject₁⁺ : ∀ {i} {n≢i : n ≢ toℕ (inject₁ i)} → IsInj (view i) | ||
| n≢inject₁⁺ {i} {n≢i} with view i | ||
| ... | top = ⊥-elim (n≢i (begin | ||
| n ≡˘⟨ toℕ-fromℕ n ⟩ | ||
| toℕ (fromℕ n) ≡˘⟨ toℕ-inject₁ (fromℕ n) ⟩ | ||
| toℕ (inject₁ (fromℕ n)) ∎)) where open ≡-Reasoning | ||
| ... | inj j = inj j | ||
|
|
||
| open Instances | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- As a corollary, we obtain two useful properties, which are | ||
| -- witnessed by, but can also serve as proxy replacements for, | ||
| -- the corresponding properties in `Data.Fin.Properties` | ||
|
|
||
| module _ {n} where | ||
|
|
||
| view-top-toℕ : ∀ i → .{{IsTop (view i)}} → toℕ i ≡ n | ||
| view-top-toℕ i with top ← view i = toℕ-fromℕ n | ||
|
|
||
| view-inj-toℕ< : ∀ i → .{{IsInj (view i)}} → toℕ i < n | ||
| view-inj-toℕ< i with inj j ← view i = inject₁ℕ< j | ||
|
|
||
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.