{"action":"created","comment":{"url":"https://api.github.com/repos/math-comp/math-comp/pulls/comments/62665526","id":62665526,"diff_hunk":"@@ -2477,6 +2567,173 @@ rewrite /N /= count_cat -/(N x _) Nx0 ?mem_rem_uniq ?undup_uniq ?inE ?eqxx //.\n by rewrite addn0 -{2}(size_nseq (_ s) x) -all_count all_pred1_nseq.\n Qed.\n \n+Section FlattenReshape.\n+\n+Variables S T : eqType.\n+Implicit Types (s : seq T) (ss : seq (seq T)).\n+\n+Lemma flatten_rcons s t : flatten (rcons t s) = flatten t ++ s.\n+Proof.\n+elim: t => [| t0 t IHt /=]; first by rewrite /= cats0.\n+by rewrite IHt catA.\n+Qed.\n+\n+Lemma flatten_seq1 s : flatten [seq [:: x] | x <- s] = s.\n+Proof. by elim: s => //= s0 s ->. Qed.\n+\n+Lemma count_flatten ss P :\n+  count P (flatten ss) = sumn [seq count P x | x <- ss].\n+Proof. by elim: ss => //= s ss IHss; rewrite count_cat IHss. Qed.\n+\n+Lemma map_flatten (f : T -> S) ss :\n+  map f (flatten ss) = flatten (map (map f) ss).\n+Proof. elim: ss => // s ss /= <-; exact: map_cat. Qed.\n+\n+Lemma filter_flatten ss (P : pred T) :\n+  filter P (flatten ss) = flatten [seq filter P i | i <- ss].\n+Proof. elim: ss => // s ss /= <-; exact: filter_cat. Qed.\n+\n+Lemma sumn_flatten (ss : seq (seq nat)) :\n+  sumn (flatten ss) = sumn (map sumn ss).\n+Proof. elim: ss => // s ss /= <-; exact: sumn_cat. Qed.\n+\n+Lemma rev_flatten ss :\n+  rev (flatten ss) = flatten (rev (map rev ss)).\n+Proof.\n+elim: ss => //= s ss IHss.\n+by rewrite rev_cons flatten_rcons -IHss rev_cat.\n+Qed.\n+\n+Lemma nth_shape ss i : nth 0 (shape ss) i = size (nth [::] ss i).\n+Proof.\n+rewrite /shape; case: (ltnP i (size ss)) => Hi; first exact: nth_map.\n+by rewrite !nth_default // size_map.\n+Qed.\n+\n+Lemma shape_rev ss : shape (rev ss) = rev (shape ss).\n+Proof. by rewrite /shape; elim: ss => //= s ss IHss; rewrite map_rev. Qed.\n+\n+Lemma eq_from_flatten_shape (u v : seq (seq T)) :\n+  (u = v) <-> ((flatten u = flatten v) /\\ (shape u = shape v)).\n+Proof.\n+split=> [-> // | [Hflat Hshape]].\n+by rewrite -(flattenK u) -(flattenK v) Hflat Hshape.\n+Qed.\n+\n+Lemma rev_reshape (s : seq nat) (l : seq T) :\n+  size l = sumn s -> rev (map rev (reshape (rev s) (rev l))) = reshape s l.\n+Proof.\n+move=> H; apply eq_from_flatten_shape; split.\n+- rewrite reshapeKr; last by rewrite H.\n+  rewrite -rev_flatten reshapeKr; first by rewrite revK.\n+  by rewrite size_rev H sumn_rev.\n+- rewrite shape_rev /shape -map_comp.\n+  rewrite (eq_map (f2 := size)); last by move=> v; rewrite /= size_rev.\n+  rewrite -/(shape _) reshapeKl; last by rewrite size_rev sumn_rev H.\n+  rewrite -/(shape _) reshapeKl; last by rewrite H.\n+  by rewrite revK.\n+Qed.\n+\n+Lemma nth_reshape (s : seq nat) (l : seq T) n :\n+  nth [::] (reshape s l) n = take (nth 0 s n) (drop (sumn (take n s)) l).\n+Proof.\n+elim: n s l => [| n IHn] [| s0 s] l; rewrite ?take0 ?drop0 //=.\n+rewrite addnC -drop_drop; exact: IHn.\n+Qed.\n+\n+Lemma map_reshape (T1 T2 : Type) (f : T1 -> T2) sh (s : seq T1) :\n+  map (map f) (reshape sh s) = reshape sh (map f s).\n+Proof. elim: sh s => //= sh0 sh IHsh s; by rewrite map_take IHsh map_drop. Qed.\n+\n+Lemma size_reshape sh s : size (reshape sh s) = size sh.","path":"mathcomp/ssreflect/seq.v","position":221,"original_position":221,"commit_id":"38e95390c526a4b96cd5ba42bfdee50fdfc69d17","original_commit_id":"38e95390c526a4b96cd5ba42bfdee50fdfc69d17","user":{"login":"ggonthier","id":15231773,"avatar_url":"https://avatars.githubusercontent.com/u/15231773?v=3","gravatar_id":"","url":"https://api.github.com/users/ggonthier","html_url":"https://github.com/ggonthier","followers_url":"https://api.github.com/users/ggonthier/followers","following_url":"https://api.github.com/users/ggonthier/following{/other_user}","gists_url":"https://api.github.com/users/ggonthier/gists{/gist_id}","starred_url":"https://api.github.com/users/ggonthier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ggonthier/subscriptions","organizations_url":"https://api.github.com/users/ggonthier/orgs","repos_url":"https://api.github.com/users/ggonthier/repos","events_url":"https://api.github.com/users/ggonthier/events{/privacy}","received_events_url":"https://api.github.com/users/ggonthier/received_events","type":"User","site_admin":false},"body":"Should go before nth_reshape.","created_at":"2016-05-10T12:56:13Z","updated_at":"2016-05-10T12:56:13Z","html_url":"https://github.com/math-comp/math-comp/pull/41#discussion_r62665526","pull_request_url":"https://api.github.com/repos/math-comp/math-comp/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/math-comp/math-comp/pulls/comments/62665526"},"html":{"href":"https://github.com/math-comp/math-comp/pull/41#discussion_r62665526"},"pull_request":{"href":"https://api.github.com/repos/math-comp/math-comp/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/math-comp/math-comp/pulls/41","id":69081787,"html_url":"https://github.com/math-comp/math-comp/pull/41","diff_url":"https://github.com/math-comp/math-comp/pull/41.diff","patch_url":"https://github.com/math-comp/math-comp/pull/41.patch","issue_url":"https://api.github.com/repos/math-comp/math-comp/issues/41","number":41,"state":"open","locked":false,"title":"Missing lemmas in seq","user":{"login":"hivert","id":7465401,"avatar_url":"https://avatars.githubusercontent.com/u/7465401?v=3","gravatar_id":"","url":"https://api.github.com/users/hivert","html_url":"https://github.com/hivert","followers_url":"https://api.github.com/users/hivert/followers","following_url":"https://api.github.com/users/hivert/following{/other_user}","gists_url":"https://api.github.com/users/hivert/gists{/gist_id}","starred_url":"https://api.github.com/users/hivert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hivert/subscriptions","organizations_url":"https://api.github.com/users/hivert/orgs","repos_url":"https://api.github.com/users/hivert/repos","events_url":"https://api.github.com/users/hivert/events{/privacy}","received_events_url":"https://api.github.com/users/hivert/received_events","type":"User","site_admin":false},"body":"Dear Math-Comp developpers,\r\n\r\nDuring my development in combinatorics, I've been needing a bunch of lemmas about seq. I've selected those which seems to me of general interest. Here are they. \r\n\r\nBest,\r\n\r\nFlorent","created_at":"2016-05-05T22:37:18Z","updated_at":"2016-05-10T12:56:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1fb62a49bf4838f0e1e70cb15a0f93a801162ac7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/math-comp/math-comp/pulls/41/commits","review_comments_url":"https://api.github.com/repos/math-comp/math-comp/pulls/41/comments","review_comment_url":"https://api.github.com/repos/math-comp/math-comp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/math-comp/math-comp/issues/41/comments","statuses_url":"https://api.github.com/repos/math-comp/math-comp/statuses/38e95390c526a4b96cd5ba42bfdee50fdfc69d17","head":{"label":"hivert:master","ref":"master","sha":"38e95390c526a4b96cd5ba42bfdee50fdfc69d17","user":{"login":"hivert","id":7465401,"avatar_url":"https://avatars.githubusercontent.com/u/7465401?v=3","gravatar_id":"","url":"https://api.github.com/users/hivert","html_url":"https://github.com/hivert","followers_url":"https://api.github.com/users/hivert/followers","following_url":"https://api.github.com/users/hivert/following{/other_user}","gists_url":"https://api.github.com/users/hivert/gists{/gist_id}","starred_url":"https://api.github.com/users/hivert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hivert/subscriptions","organizations_url":"https://api.github.com/users/hivert/orgs","repos_url":"https://api.github.com/users/hivert/repos","events_url":"https://api.github.com/users/hivert/events{/privacy}","received_events_url":"https://api.github.com/users/hivert/received_events","type":"User","site_admin":false},"repo":{"id":52955415,"name":"math-comp","full_name":"hivert/math-comp","owner":{"login":"hivert","id":7465401,"avatar_url":"https://avatars.githubusercontent.com/u/7465401?v=3","gravatar_id":"","url":"https://api.github.com/users/hivert","html_url":"https://github.com/hivert","followers_url":"https://api.github.com/users/hivert/followers","following_url":"https://api.github.com/users/hivert/following{/other_user}","gists_url":"https://api.github.com/users/hivert/gists{/gist_id}","starred_url":"https://api.github.com/users/hivert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hivert/subscriptions","organizations_url":"https://api.github.com/users/hivert/orgs","repos_url":"https://api.github.com/users/hivert/repos","events_url":"https://api.github.com/users/hivert/events{/privacy}","received_events_url":"https://api.github.com/users/hivert/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hivert/math-comp","description":"Mathematical Components","fork":true,"url":"https://api.github.com/repos/hivert/math-comp","forks_url":"https://api.github.com/repos/hivert/math-comp/forks","keys_url":"https://api.github.com/repos/hivert/math-comp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hivert/math-comp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hivert/math-comp/teams","hooks_url":"https://api.github.com/repos/hivert/math-comp/hooks","issue_events_url":"https://api.github.com/repos/hivert/math-comp/issues/events{/number}","events_url":"https://api.github.com/repos/hivert/math-comp/events","assignees_url":"https://api.github.com/repos/hivert/math-comp/assignees{/user}","branches_url":"https://api.github.com/repos/hivert/math-comp/branches{/branch}","tags_url":"https://api.github.com/repos/hivert/math-comp/tags","blobs_url":"https://api.github.com/repos/hivert/math-comp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hivert/math-comp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hivert/math-comp/git/refs{/sha}","trees_url":"https://api.github.com/repos/hivert/math-comp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hivert/math-comp/statuses/{sha}","languages_url":"https://api.github.com/repos/hivert/math-comp/languages","stargazers_url":"https://api.github.com/repos/hivert/math-comp/stargazers","contributors_url":"https://api.github.com/repos/hivert/math-comp/contributors","subscribers_url":"https://api.github.com/repos/hivert/math-comp/subscribers","subscription_url":"https://api.github.com/repos/hivert/math-comp/subscription","commits_url":"https://api.github.com/repos/hivert/math-comp/commits{/sha}","git_commits_url":"https://api.github.com/repos/hivert/math-comp/git/commits{/sha}","comments_url":"https://api.github.com/repos/hivert/math-comp/comments{/number}","issue_comment_url":"https://api.github.com/repos/hivert/math-comp/issues/comments{/number}","contents_url":"https://api.github.com/repos/hivert/math-comp/contents/{+path}","compare_url":"https://api.github.com/repos/hivert/math-comp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hivert/math-comp/merges","archive_url":"https://api.github.com/repos/hivert/math-comp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hivert/math-comp/downloads","issues_url":"https://api.github.com/repos/hivert/math-comp/issues{/number}","pulls_url":"https://api.github.com/repos/hivert/math-comp/pulls{/number}","milestones_url":"https://api.github.com/repos/hivert/math-comp/milestones{/number}","notifications_url":"https://api.github.com/repos/hivert/math-comp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hivert/math-comp/labels{/name}","releases_url":"https://api.github.com/repos/hivert/math-comp/releases{/id}","deployments_url":"https://api.github.com/repos/hivert/math-comp/deployments","created_at":"2016-03-02T10:46:31Z","updated_at":"2016-03-02T10:46:38Z","pushed_at":"2016-05-06T11:56:34Z","git_url":"git://github.com/hivert/math-comp.git","ssh_url":"git@github.com:hivert/math-comp.git","clone_url":"https://github.com/hivert/math-comp.git","svn_url":"https://github.com/hivert/math-comp","homepage":"","size":5907,"stargazers_count":0,"watchers_count":0,"language":"Coq","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"math-comp:master","ref":"master","sha":"0fedd37679abe2a9909ec03aebf01aab359a06fd","user":{"login":"math-comp","id":11424151,"avatar_url":"https://avatars.githubusercontent.com/u/11424151?v=3","gravatar_id":"","url":"https://api.github.com/users/math-comp","html_url":"https://github.com/math-comp","followers_url":"https://api.github.com/users/math-comp/followers","following_url":"https://api.github.com/users/math-comp/following{/other_user}","gists_url":"https://api.github.com/users/math-comp/gists{/gist_id}","starred_url":"https://api.github.com/users/math-comp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/math-comp/subscriptions","organizations_url":"https://api.github.com/users/math-comp/orgs","repos_url":"https://api.github.com/users/math-comp/repos","events_url":"https://api.github.com/users/math-comp/events{/privacy}","received_events_url":"https://api.github.com/users/math-comp/received_events","type":"Organization","site_admin":false},"repo":{"id":32018344,"name":"math-comp","full_name":"math-comp/math-comp","owner":{"login":"math-comp","id":11424151,"avatar_url":"https://avatars.githubusercontent.com/u/11424151?v=3","gravatar_id":"","url":"https://api.github.com/users/math-comp","html_url":"https://github.com/math-comp","followers_url":"https://api.github.com/users/math-comp/followers","following_url":"https://api.github.com/users/math-comp/following{/other_user}","gists_url":"https://api.github.com/users/math-comp/gists{/gist_id}","starred_url":"https://api.github.com/users/math-comp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/math-comp/subscriptions","organizations_url":"https://api.github.com/users/math-comp/orgs","repos_url":"https://api.github.com/users/math-comp/repos","events_url":"https://api.github.com/users/math-comp/events{/privacy}","received_events_url":"https://api.github.com/users/math-comp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/math-comp/math-comp","description":"Mathematical Components","fork":false,"url":"https://api.github.com/repos/math-comp/math-comp","forks_url":"https://api.github.com/repos/math-comp/math-comp/forks","keys_url":"https://api.github.com/repos/math-comp/math-comp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/math-comp/math-comp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/math-comp/math-comp/teams","hooks_url":"https://api.github.com/repos/math-comp/math-comp/hooks","issue_events_url":"https://api.github.com/repos/math-comp/math-comp/issues/events{/number}","events_url":"https://api.github.com/repos/math-comp/math-comp/events","assignees_url":"https://api.github.com/repos/math-comp/math-comp/assignees{/user}","branches_url":"https://api.github.com/repos/math-comp/math-comp/branches{/branch}","tags_url":"https://api.github.com/repos/math-comp/math-comp/tags","blobs_url":"https://api.github.com/repos/math-comp/math-comp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/math-comp/math-comp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/math-comp/math-comp/git/refs{/sha}","trees_url":"https://api.github.com/repos/math-comp/math-comp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/math-comp/math-comp/statuses/{sha}","languages_url":"https://api.github.com/repos/math-comp/math-comp/languages","stargazers_url":"https://api.github.com/repos/math-comp/math-comp/stargazers","contributors_url":"https://api.github.com/repos/math-comp/math-comp/contributors","subscribers_url":"https://api.github.com/repos/math-comp/math-comp/subscribers","subscription_url":"https://api.github.com/repos/math-comp/math-comp/subscription","commits_url":"https://api.github.com/repos/math-comp/math-comp/commits{/sha}","git_commits_url":"https://api.github.com/repos/math-comp/math-comp/git/commits{/sha}","comments_url":"https://api.github.com/repos/math-comp/math-comp/comments{/number}","issue_comment_url":"https://api.github.com/repos/math-comp/math-comp/issues/comments{/number}","contents_url":"https://api.github.com/repos/math-comp/math-comp/contents/{+path}","compare_url":"https://api.github.com/repos/math-comp/math-comp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/math-comp/math-comp/merges","archive_url":"https://api.github.com/repos/math-comp/math-comp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/math-comp/math-comp/downloads","issues_url":"https://api.github.com/repos/math-comp/math-comp/issues{/number}","pulls_url":"https://api.github.com/repos/math-comp/math-comp/pulls{/number}","milestones_url":"https://api.github.com/repos/math-comp/math-comp/milestones{/number}","notifications_url":"https://api.github.com/repos/math-comp/math-comp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/math-comp/math-comp/labels{/name}","releases_url":"https://api.github.com/repos/math-comp/math-comp/releases{/id}","deployments_url":"https://api.github.com/repos/math-comp/math-comp/deployments","created_at":"2015-03-11T13:13:27Z","updated_at":"2016-05-04T22:39:51Z","pushed_at":"2016-05-09T15:52:42Z","git_url":"git://github.com/math-comp/math-comp.git","ssh_url":"git@github.com:math-comp/math-comp.git","clone_url":"https://github.com/math-comp/math-comp.git","svn_url":"https://github.com/math-comp/math-comp","homepage":"","size":5955,"stargazers_count":26,"watchers_count":26,"language":"Coq","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":9,"mirror_url":null,"open_issues_count":16,"forks":9,"open_issues":16,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/math-comp/math-comp/pulls/41"},"html":{"href":"https://github.com/math-comp/math-comp/pull/41"},"issue":{"href":"https://api.github.com/repos/math-comp/math-comp/issues/41"},"comments":{"href":"https://api.github.com/repos/math-comp/math-comp/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/math-comp/math-comp/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/math-comp/math-comp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/math-comp/math-comp/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/math-comp/math-comp/statuses/38e95390c526a4b96cd5ba42bfdee50fdfc69d17"}}}}