-
Notifications
You must be signed in to change notification settings - Fork 246
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
New functions take-drop-1
and take-one-more
added to Data.List.Properties
#1984
New functions take-drop-1
and take-one-more
added to Data.List.Properties
#1984
Conversation
…rties Names of those functions are up to debate
Add functions : take-drop-1 take-one-more to stdl Data.List.Propreties
take-drop-1
and take-one-more
added to Data.List.Properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments in #1983 for similar things that need addressing.
src/Data/List/Properties.agda
Outdated
@@ -758,6 +758,10 @@ length-take zero xs = refl | |||
length-take (suc n) [] = refl | |||
length-take (suc n) (x ∷ xs) = cong suc (length-take n xs) | |||
|
|||
take-one-more : {ℓ : Level} {X : Set ℓ} {m : ℕ} (x : Fin m) (f : Fin m → X) → | |||
take (toℕ x) (tabulate f) ∷ʳ f x ≡ take (suc (toℕ x)) (tabulate f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this equality should the other way around. We usually have the function application on the left and the reduction behaviour on the right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meta-heuristic being
complex => simple(r)
Not sure that the
Suggest splitting out the first one. That may also uncouple the dependency on |
So I had tried the lemmas without For example, with So yes, both of these should have |
`take-one-more` to `take-suc-tabulate` `take-drop-1` to `take-tabulate-1` `take-tabulate-1` is now with other `take` functions
Added `take-tabulate-1` and `take-suc-tabulate` to Data.List.Properties
Hmm. @JacquesCarette i would look at these proofs... but have no spare time to allocate right now. My first thought (don't be the first to groan) is: clearly try to avoid This is what So I'm sorry not to have the time, if I could then try to make this a good didactic example on non-trivial with programming... Separately: I further can't help thinking that proofs of lemmas about |
OK... I may have to revise my comments above (but I still need to think some more). But in the meantime:
take-suc : (xs : List A) (i : Fin (length xs)) → let m = toℕ i in
take (suc m) xs ≡ take m xs ∷ʳ lookup xs i
take-suc (x ∷ xs) zero = refl
take-suc (x ∷ xs) (suc i) = cong (x ∷_) (take-suc xs i)
take-suc-tabulate : ∀ {n} (f : Fin n → A) (i : Fin n) → let m = toℕ i in
take (suc m) (tabulate f) ≡ take m (tabulate f) ∷ʳ f i
take-suc-tabulate f i rewrite sym (toℕ-cast (sym (length-tabulate f)) i) | sym (lookup-tabulate f i)
= take-suc (tabulate f) (cast _ i) Conclusion (partisan/partial, at least on my side): the refactoring is worth doing, and not as bad as @JacquesCarette claims. |
Likewise: drop-take-suc : (xs : List A) (i : Fin (length xs)) → let m = toℕ i in
drop m (take (suc m) xs) ≡ [ lookup xs i ]
drop-take-suc (x ∷ xs) zero = refl
drop-take-suc (x ∷ xs) (suc i) = drop-take-suc xs i
drop-take-suc-tabulate : ∀ {n} (f : Fin n → A) (i : Fin n) → let m = toℕ i in
drop m (take (suc m) (tabulate f)) ≡ [ f i ]
drop-take-suc-tabulate f i rewrite sym (toℕ-cast (sym (length-tabulate f)) i) | sym (lookup-tabulate f i)
= drop-take-suc (tabulate f) (cast _ i) |
…ast` instead of `subst` separation f each function into two function `take-one-more` replaced by `take-suc`+ `take-suc-tabulate` `take-drop-1` replaced by `drop-take-suc`+`drop-take-suc-tabulate`
update corresponding to rewritte of `take-one-more` and `take-drop-1`
…sa/agda-stdlib into new-functions-take-drop
Apart from that, and the merge conflicts, this now looks good to go. Thanks for the help @jamesmckinna! |
Of course, the multiple appeals to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry forgot to post his review. Once this is addressed, and the merge conflicts are resolved, I'll merge this in 👍
functions
take-drop-1
take-one-more
added to Data.List.Properties and declared in CHANGELOG.md
Creation of a section take-drop in Data.List.Properties.
Moved
take++drop
from drop section to take-drop section.The name of the two new functions are up to debate