{"action":"created","comment":{"url":"https://api.github.com/repos/sympy/sympy/pulls/comments/29548901","id":29548901,"diff_hunk":"@@ -6288,7 +6288,7 @@ def cancel(f, *gens, **args):\n             raise PolynomialError(msg)\n         # Handling of noncommutative and/or piecewise expressions\n         if f.is_Add or f.is_Mul:\n-            sifted = sift(f.args, lambda x: x.is_commutative and not x.has(Piecewise))\n+            sifted = sift(f.args, lambda x: bool(x.is_commutative) and not x.has(Piecewise))","path":"sympy/polys/polytools.py","position":5,"original_position":5,"commit_id":"a9facf10fe282a63540ce7ee150c61bcff594bd2","original_commit_id":"a9facf10fe282a63540ce7ee150c61bcff594bd2","user":{"login":"truongduy134","id":1406224,"avatar_url":"https://avatars.githubusercontent.com/u/1406224?v=3","gravatar_id":"","url":"https://api.github.com/users/truongduy134","html_url":"https://github.com/truongduy134","followers_url":"https://api.github.com/users/truongduy134/followers","following_url":"https://api.github.com/users/truongduy134/following{/other_user}","gists_url":"https://api.github.com/users/truongduy134/gists{/gist_id}","starred_url":"https://api.github.com/users/truongduy134/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/truongduy134/subscriptions","organizations_url":"https://api.github.com/users/truongduy134/orgs","repos_url":"https://api.github.com/users/truongduy134/repos","events_url":"https://api.github.com/users/truongduy134/events{/privacy}","received_events_url":"https://api.github.com/users/truongduy134/received_events","type":"User","site_admin":false},"body":"If one of the operands is None, the expression returns None (instead of a Boolean). Quite strange indeed.\r\n\r\n```\r\n>>> a = None and True\r\n>>> type(a)\r\n<type 'NoneType'>\r\n```","created_at":"2015-05-02T17:05:39Z","updated_at":"2015-05-02T17:05:39Z","html_url":"https://github.com/sympy/sympy/pull/9364#discussion_r29548901","pull_request_url":"https://api.github.com/repos/sympy/sympy/pulls/9364","_links":{"self":{"href":"https://api.github.com/repos/sympy/sympy/pulls/comments/29548901"},"html":{"href":"https://github.com/sympy/sympy/pull/9364#discussion_r29548901"},"pull_request":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9364"}}},"pull_request":{"url":"https://api.github.com/repos/sympy/sympy/pulls/9364","id":34587578,"html_url":"https://github.com/sympy/sympy/pull/9364","diff_url":"https://github.com/sympy/sympy/pull/9364.diff","patch_url":"https://github.com/sympy/sympy/pull/9364.patch","issue_url":"https://api.github.com/repos/sympy/sympy/issues/9364","number":9364,"state":"open","locked":false,"title":"[Ready to review] Fix 9363: Bug in cancel MatrixElement expressions","user":{"login":"truongduy134","id":1406224,"avatar_url":"https://avatars.githubusercontent.com/u/1406224?v=3","gravatar_id":"","url":"https://api.github.com/users/truongduy134","html_url":"https://github.com/truongduy134","followers_url":"https://api.github.com/users/truongduy134/followers","following_url":"https://api.github.com/users/truongduy134/following{/other_user}","gists_url":"https://api.github.com/users/truongduy134/gists{/gist_id}","starred_url":"https://api.github.com/users/truongduy134/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/truongduy134/subscriptions","organizations_url":"https://api.github.com/users/truongduy134/orgs","repos_url":"https://api.github.com/users/truongduy134/repos","events_url":"https://api.github.com/users/truongduy134/events{/privacy}","received_events_url":"https://api.github.com/users/truongduy134/received_events","type":"User","site_admin":false},"body":"Refer to issue: https://github.com/sympy/sympy/issues/9363\r\n\r\nProblem: When applying cancel function with expression involving MatrixElement (e.g. M[0,0] + 10), the result is not correct (MatrixElement disappears). See the following program:\r\n```\r\n >>> from sympy import *\r\n >>> X = Symbol('X', commutative=False)\r\n >>> M = MatrixSymbol('M', 3, 3)\r\n >>> cancel(X + 1)\r\nX + 1\r\n>>> cancel(M[0,0] + 1)\r\n1\r\n```\r\n\r\nFix Attempt: In the condition at line https://github.com/sympy/sympy/blob/master/sympy/polys/polytools.py#L6291-L6292, use \r\n```\r\nbool(x.is_commutative) \r\n```\r\ninstead of\r\n```\r\nx.is_commutative\r\n```\r\nSo if x.is_commutative is None, we treat x as non-commutative. Note that in Python, strangely (None and True) is None, similar to (None and False)) (which is the cause of the bug)","created_at":"2015-05-02T15:57:33Z","updated_at":"2015-05-02T17:05:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b82fd2dcbefab30c760df5ff4c99da130f0befaf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sympy/sympy/pulls/9364/commits","review_comments_url":"https://api.github.com/repos/sympy/sympy/pulls/9364/comments","review_comment_url":"https://api.github.com/repos/sympy/sympy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/9364/comments","statuses_url":"https://api.github.com/repos/sympy/sympy/statuses/a9facf10fe282a63540ce7ee150c61bcff594bd2","head":{"label":"truongduy134:master","ref":"master","sha":"a9facf10fe282a63540ce7ee150c61bcff594bd2","user":{"login":"truongduy134","id":1406224,"avatar_url":"https://avatars.githubusercontent.com/u/1406224?v=3","gravatar_id":"","url":"https://api.github.com/users/truongduy134","html_url":"https://github.com/truongduy134","followers_url":"https://api.github.com/users/truongduy134/followers","following_url":"https://api.github.com/users/truongduy134/following{/other_user}","gists_url":"https://api.github.com/users/truongduy134/gists{/gist_id}","starred_url":"https://api.github.com/users/truongduy134/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/truongduy134/subscriptions","organizations_url":"https://api.github.com/users/truongduy134/orgs","repos_url":"https://api.github.com/users/truongduy134/repos","events_url":"https://api.github.com/users/truongduy134/events{/privacy}","received_events_url":"https://api.github.com/users/truongduy134/received_events","type":"User","site_admin":false},"repo":{"id":34949422,"name":"sympy","full_name":"truongduy134/sympy","owner":{"login":"truongduy134","id":1406224,"avatar_url":"https://avatars.githubusercontent.com/u/1406224?v=3","gravatar_id":"","url":"https://api.github.com/users/truongduy134","html_url":"https://github.com/truongduy134","followers_url":"https://api.github.com/users/truongduy134/followers","following_url":"https://api.github.com/users/truongduy134/following{/other_user}","gists_url":"https://api.github.com/users/truongduy134/gists{/gist_id}","starred_url":"https://api.github.com/users/truongduy134/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/truongduy134/subscriptions","organizations_url":"https://api.github.com/users/truongduy134/orgs","repos_url":"https://api.github.com/users/truongduy134/repos","events_url":"https://api.github.com/users/truongduy134/events{/privacy}","received_events_url":"https://api.github.com/users/truongduy134/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/truongduy134/sympy","description":"A computer algebra system written in pure Python","fork":true,"url":"https://api.github.com/repos/truongduy134/sympy","forks_url":"https://api.github.com/repos/truongduy134/sympy/forks","keys_url":"https://api.github.com/repos/truongduy134/sympy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/truongduy134/sympy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/truongduy134/sympy/teams","hooks_url":"https://api.github.com/repos/truongduy134/sympy/hooks","issue_events_url":"https://api.github.com/repos/truongduy134/sympy/issues/events{/number}","events_url":"https://api.github.com/repos/truongduy134/sympy/events","assignees_url":"https://api.github.com/repos/truongduy134/sympy/assignees{/user}","branches_url":"https://api.github.com/repos/truongduy134/sympy/branches{/branch}","tags_url":"https://api.github.com/repos/truongduy134/sympy/tags","blobs_url":"https://api.github.com/repos/truongduy134/sympy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/truongduy134/sympy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/truongduy134/sympy/git/refs{/sha}","trees_url":"https://api.github.com/repos/truongduy134/sympy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/truongduy134/sympy/statuses/{sha}","languages_url":"https://api.github.com/repos/truongduy134/sympy/languages","stargazers_url":"https://api.github.com/repos/truongduy134/sympy/stargazers","contributors_url":"https://api.github.com/repos/truongduy134/sympy/contributors","subscribers_url":"https://api.github.com/repos/truongduy134/sympy/subscribers","subscription_url":"https://api.github.com/repos/truongduy134/sympy/subscription","commits_url":"https://api.github.com/repos/truongduy134/sympy/commits{/sha}","git_commits_url":"https://api.github.com/repos/truongduy134/sympy/git/commits{/sha}","comments_url":"https://api.github.com/repos/truongduy134/sympy/comments{/number}","issue_comment_url":"https://api.github.com/repos/truongduy134/sympy/issues/comments{/number}","contents_url":"https://api.github.com/repos/truongduy134/sympy/contents/{+path}","compare_url":"https://api.github.com/repos/truongduy134/sympy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/truongduy134/sympy/merges","archive_url":"https://api.github.com/repos/truongduy134/sympy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/truongduy134/sympy/downloads","issues_url":"https://api.github.com/repos/truongduy134/sympy/issues{/number}","pulls_url":"https://api.github.com/repos/truongduy134/sympy/pulls{/number}","milestones_url":"https://api.github.com/repos/truongduy134/sympy/milestones{/number}","notifications_url":"https://api.github.com/repos/truongduy134/sympy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/truongduy134/sympy/labels{/name}","releases_url":"https://api.github.com/repos/truongduy134/sympy/releases{/id}","created_at":"2015-05-02T13:49:42Z","updated_at":"2015-05-02T16:19:29Z","pushed_at":"2015-05-02T16:19:29Z","git_url":"git://github.com/truongduy134/sympy.git","ssh_url":"git@github.com:truongduy134/sympy.git","clone_url":"https://github.com/truongduy134/sympy.git","svn_url":"https://github.com/truongduy134/sympy","homepage":"http://sympy.org/","size":68930,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"sympy:master","ref":"master","sha":"701e46f95c054a233efdf8d7bb882ba0c1c80643","user":{"login":"sympy","id":260832,"avatar_url":"https://avatars.githubusercontent.com/u/260832?v=3","gravatar_id":"","url":"https://api.github.com/users/sympy","html_url":"https://github.com/sympy","followers_url":"https://api.github.com/users/sympy/followers","following_url":"https://api.github.com/users/sympy/following{/other_user}","gists_url":"https://api.github.com/users/sympy/gists{/gist_id}","starred_url":"https://api.github.com/users/sympy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sympy/subscriptions","organizations_url":"https://api.github.com/users/sympy/orgs","repos_url":"https://api.github.com/users/sympy/repos","events_url":"https://api.github.com/users/sympy/events{/privacy}","received_events_url":"https://api.github.com/users/sympy/received_events","type":"Organization","site_admin":false},"repo":{"id":640534,"name":"sympy","full_name":"sympy/sympy","owner":{"login":"sympy","id":260832,"avatar_url":"https://avatars.githubusercontent.com/u/260832?v=3","gravatar_id":"","url":"https://api.github.com/users/sympy","html_url":"https://github.com/sympy","followers_url":"https://api.github.com/users/sympy/followers","following_url":"https://api.github.com/users/sympy/following{/other_user}","gists_url":"https://api.github.com/users/sympy/gists{/gist_id}","starred_url":"https://api.github.com/users/sympy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sympy/subscriptions","organizations_url":"https://api.github.com/users/sympy/orgs","repos_url":"https://api.github.com/users/sympy/repos","events_url":"https://api.github.com/users/sympy/events{/privacy}","received_events_url":"https://api.github.com/users/sympy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sympy/sympy","description":"A computer algebra system written in pure Python","fork":false,"url":"https://api.github.com/repos/sympy/sympy","forks_url":"https://api.github.com/repos/sympy/sympy/forks","keys_url":"https://api.github.com/repos/sympy/sympy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sympy/sympy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sympy/sympy/teams","hooks_url":"https://api.github.com/repos/sympy/sympy/hooks","issue_events_url":"https://api.github.com/repos/sympy/sympy/issues/events{/number}","events_url":"https://api.github.com/repos/sympy/sympy/events","assignees_url":"https://api.github.com/repos/sympy/sympy/assignees{/user}","branches_url":"https://api.github.com/repos/sympy/sympy/branches{/branch}","tags_url":"https://api.github.com/repos/sympy/sympy/tags","blobs_url":"https://api.github.com/repos/sympy/sympy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sympy/sympy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sympy/sympy/git/refs{/sha}","trees_url":"https://api.github.com/repos/sympy/sympy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sympy/sympy/statuses/{sha}","languages_url":"https://api.github.com/repos/sympy/sympy/languages","stargazers_url":"https://api.github.com/repos/sympy/sympy/stargazers","contributors_url":"https://api.github.com/repos/sympy/sympy/contributors","subscribers_url":"https://api.github.com/repos/sympy/sympy/subscribers","subscription_url":"https://api.github.com/repos/sympy/sympy/subscription","commits_url":"https://api.github.com/repos/sympy/sympy/commits{/sha}","git_commits_url":"https://api.github.com/repos/sympy/sympy/git/commits{/sha}","comments_url":"https://api.github.com/repos/sympy/sympy/comments{/number}","issue_comment_url":"https://api.github.com/repos/sympy/sympy/issues/comments{/number}","contents_url":"https://api.github.com/repos/sympy/sympy/contents/{+path}","compare_url":"https://api.github.com/repos/sympy/sympy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sympy/sympy/merges","archive_url":"https://api.github.com/repos/sympy/sympy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sympy/sympy/downloads","issues_url":"https://api.github.com/repos/sympy/sympy/issues{/number}","pulls_url":"https://api.github.com/repos/sympy/sympy/pulls{/number}","milestones_url":"https://api.github.com/repos/sympy/sympy/milestones{/number}","notifications_url":"https://api.github.com/repos/sympy/sympy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sympy/sympy/labels{/name}","releases_url":"https://api.github.com/repos/sympy/sympy/releases{/id}","created_at":"2010-04-30T20:37:14Z","updated_at":"2015-05-02T08:57:09Z","pushed_at":"2015-05-02T16:19:29Z","git_url":"git://github.com/sympy/sympy.git","ssh_url":"git@github.com:sympy/sympy.git","clone_url":"https://github.com/sympy/sympy.git","svn_url":"https://github.com/sympy/sympy","homepage":"http://sympy.org/","size":151416,"stargazers_count":2089,"watchers_count":2089,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1036,"mirror_url":null,"open_issues_count":1881,"forks":1036,"open_issues":1881,"watchers":2089,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9364"},"html":{"href":"https://github.com/sympy/sympy/pull/9364"},"issue":{"href":"https://api.github.com/repos/sympy/sympy/issues/9364"},"comments":{"href":"https://api.github.com/repos/sympy/sympy/issues/9364/comments"},"review_comments":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9364/comments"},"review_comment":{"href":"https://api.github.com/repos/sympy/sympy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9364/commits"},"statuses":{"href":"https://api.github.com/repos/sympy/sympy/statuses/a9facf10fe282a63540ce7ee150c61bcff594bd2"}}}}