{"action":"created","issue":{"url":"https://api.github.com/repos/sympy/sympy/issues/6249","repository_url":"https://api.github.com/repos/sympy/sympy","labels_url":"https://api.github.com/repos/sympy/sympy/issues/6249/labels{/name}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/6249/comments","events_url":"https://api.github.com/repos/sympy/sympy/issues/6249/events","html_url":"https://github.com/sympy/sympy/issues/6249","id":28951975,"number":6249,"title":"Problems with MatrixSymbol and simplifying functions","user":{"login":"jrioux","id":1246890,"avatar_url":"https://avatars.githubusercontent.com/u/1246890?v=3","gravatar_id":"","url":"https://api.github.com/users/jrioux","html_url":"https://github.com/jrioux","followers_url":"https://api.github.com/users/jrioux/followers","following_url":"https://api.github.com/users/jrioux/following{/other_user}","gists_url":"https://api.github.com/users/jrioux/gists{/gist_id}","starred_url":"https://api.github.com/users/jrioux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrioux/subscriptions","organizations_url":"https://api.github.com/users/jrioux/orgs","repos_url":"https://api.github.com/users/jrioux/repos","events_url":"https://api.github.com/users/jrioux/events{/privacy}","received_events_url":"https://api.github.com/users/jrioux/received_events","type":"User","site_admin":false},"labels":[{"id":84627344,"url":"https://api.github.com/repos/sympy/sympy/labels/bug","name":"bug","color":"ededed","default":true},{"id":84627341,"url":"https://api.github.com/repos/sympy/sympy/labels/imported","name":"imported","color":"ededed","default":false},{"id":84627363,"url":"https://api.github.com/repos/sympy/sympy/labels/matrices","name":"matrices","color":"0000FF","default":false},{"id":84627358,"url":"https://api.github.com/repos/sympy/sympy/labels/simplify","name":"simplify","color":"0000FF","default":false},{"id":84627345,"url":"https://api.github.com/repos/sympy/sympy/labels/valid","name":"valid","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2012-03-16T04:23:04Z","updated_at":"2016-12-05T00:36:37Z","closed_at":null,"body":"```\nMatrixSymbol do not work with cancel, combsimp, factor, posify, separatevars, sqrtdenest.\n\n$ ipython\nPython 2.7.1+ ( r271 :86832, Apr 11 2011, 18:05:24) \nType \"copyright\", \"credits\" or \"license\" for more information.\n\nIPython 0.10.1 -- An enhanced Interactive Python.\n?         -> Introduction and overview of IPython's features.\n%quickref -> Quick reference.\nhelp      -> Python's own help system.\nobject?   -> Details about 'object'. ?object also works, ?? prints more.\n\nIn [1]: from sympy import *\n\nIn [2]: A=MatrixSymbol('A', 3, 3)\n\nIn [3]: B=MatrixSymbol('B', 3, 3)\n\nIn [4]: p=A*B-B*A\n\nIn [5]: cancel(p)\n---------------------------------------------------------------------------\nPolynomialError                           Traceback (most recent call last)\n\n/home/jrioux/git/sympy/<ipython console> in <module>()\n\n/home/jrioux/git/sympy/sympy/polys/polytools.pyc in cancel(f, *gens, **args)\n   5491 \n   5492     try:\n-> 5493         (F, G), opt = parallel_poly_from_expr((p, q), *gens, **args)\n   5494     except PolificationFailed:\n   5495         if not isinstance(f, (tuple, Tuple)):\n\n/home/jrioux/git/sympy/sympy/polys/polytools.pyc in parallel_poly_from_expr(exprs, *gens, **args)\n   3787     \"\"\"Construct polynomials from expressions. \"\"\"\n   3788     opt = options.build_options(gens, args)\n-> 3789     return _parallel_poly_from_expr(exprs, opt)\n   3790 \n   3791 def _parallel_poly_from_expr(exprs, opt):\n\n/home/jrioux/git/sympy/sympy/polys/polytools.pyc in _parallel_poly_from_expr(exprs, opt)\n   3838 \n   3839     try:\n-> 3840         reps, opt = _parallel_dict_from_expr(exprs, opt)\n   3841     except GeneratorsNeeded:\n   3842         raise PolificationFailed(opt, origs, exprs, True)\n\n/home/jrioux/git/sympy/sympy/polys/polyutils.pyc in _parallel_dict_from_expr(exprs, opt)\n    277 \n    278     if any(expr.is_commutative is False for expr in exprs):\n--> 279         raise PolynomialError('non-commutative expressions are not supported')\n    280 \n    281     if opt.gens:\n\nPolynomialError: non-commutative expressions are not supported\n\nIn [6]: combsimp(p)\n---------------------------------------------------------------------------\nAttributeError                            Traceback (most recent call last)\n\n/home/jrioux/git/sympy/<ipython console> in <module>()\n\n/home/jrioux/git/sympy/sympy/simplify/simplify.pyc in combsimp(expr)\n   2305 \n   2306     expr = expr.replace(binomial,\n-> 2307         lambda n, k: rf((n-k+1).expand(), k.expand())/rf(1, k.expand()))\n   2308     expr = expr.replace(factorial,                                                              \n   2309         lambda n: rf(1, n.expand()))\n\n/home/jrioux/git/sympy/sympy/core/basic.pyc in replace(self, query, value, map)\n   1118                     return None\n   1119 \n-> 1120         result = rec_replace(self)\n   1121 \n   1122         if result is None:\n\n/home/jrioux/git/sympy/sympy/core/basic.pyc in rec_replace(expr)\n   1094 \n   1095             for arg in expr.args:\n-> 1096                 result = rec_replace(arg)\n   1097 \n   1098                 if result is not None:\n\n/home/jrioux/git/sympy/sympy/core/basic.pyc in rec_replace(expr)\n   1094 \n   1095             for arg in expr.args:\n-> 1096                 result = rec_replace(arg)\n   1097 \n   1098                 if result is not None:\n\n/home/jrioux/git/sympy/sympy/core/basic.pyc in rec_replace(expr)\n   1094 \n   1095             for arg in expr.args:\n-> 1096                 result = rec_replace(arg)\n   1097 \n   1098                 if result is not None:\n\n/home/jrioux/git/sympy/sympy/core/basic.pyc in rec_replace(expr)\n   1093             args, construct = [], False\n   1094 \n-> 1095             for arg in expr.args:\n   1096                 result = rec_replace(arg)\n   1097 \n\nAttributeError: 'str' object has no attribute 'args'\n\nIn [7]: factor(p)\n---------------------------------------------------------------------------\nAttributeError                            Traceback (most recent call last)\n\n/home/jrioux/git/sympy/<ipython console> in <module>()\n\n/home/jrioux/git/sympy/sympy/polys/polytools.pyc in factor(f, *gens, **args)\n   5254         if not f.is_commutative:\n   5255             from sympy.core.exprtools import factor_nc\n-> 5256             return factor_nc(f)\n   5257         else:\n   5258             raise PolynomialError(msg)\n\n/home/jrioux/git/sympy/sympy/core/exprtools.pyc in factor_nc(expr)\n    603         return expr.func(*[factor_nc(a) for a in expr.args])\n    604 \n--> 605     expr, rep, nc_symbols = _mask_nc(expr)\n    606     if rep:\n    607         return factor(expr).subs(rep)\n\n/home/jrioux/git/sympy/sympy/core/exprtools.pyc in _mask_nc(eq)\n    569                 pass\n    570             elif (\n--> 571                 not a.is_commutative and\n    572                 not (a.is_Symbol or a.is_Add or a.is_Mul or a.is_Pow)\n    573                 ):\n\nAttributeError: 'str' object has no attribute 'is_commutative'\n\nIn [8]: posify(p)\nERROR: An unexpected error occurred while tokenizing input\nThe following traceback may be corrupted or invalid\nThe error message is: ('EOF in multi-line statement', (10, 0))\n\nERROR: An unexpected error occurred while tokenizing input\nThe following traceback may be corrupted or invalid\nThe error message is: ('EOF in multi-line statement', (10, 0))\n\n---------------------------------------------------------------------------\nAttributeError                            Traceback (most recent call last)\n\n/home/jrioux/git/sympy/<ipython console> in <module>()\n\n/home/jrioux/git/sympy/sympy/simplify/simplify.pyc in posify(eq)\n   1341         for i, e in enumerate(eq):\n   1342             eq[i] = e.subs(reps)\n-> 1343         return f(eq), dict([(r, s) for s, r in reps.iteritems()])\n   1344 \n   1345     reps = dict([(s, Dummy(s.name, positive=True))\n\n/home/jrioux/git/sympy/sympy/matrices/expressions/matadd.pyc in __new__(cls, *args)\n     21         args = [arg for arg in args if arg!=0]\n     22 \n---> 23         if not all(arg.is_Matrix for arg in args):\n     24             raise ValueError(\"Mix of Matrix and Scalar symbols\")\n     25 \n\n/home/jrioux/git/sympy/sympy/matrices/expressions/matadd.pyc in <genexpr>((arg,))\n     21         args = [arg for arg in args if arg!=0]\n     22 \n---> 23         if not all(arg.is_Matrix for arg in args):\n     24             raise ValueError(\"Mix of Matrix and Scalar symbols\")\n     25 \n\nAttributeError: 'list' object has no attribute 'is_Matrix'\n\nIn [9]: separatevars(p)\n---------------------------------------------------------------------------\nAttributeError                            Traceback (most recent call last)\n\n/home/jrioux/git/sympy/<ipython console> in <module>()\n\n/home/jrioux/git/sympy/sympy/simplify/simplify.pyc in separatevars(expr, symbols, dict, force)\n    648         return _separatevars_dict(_separatevars(expr, force), symbols)\n    649     else:\n--> 650         return _separatevars(expr, force)\n    651 \n    652 def _separatevars(expr, force):\n\n/home/jrioux/git/sympy/sympy/simplify/simplify.pyc in _separatevars(expr, force)\n    698         _expr = nonsepar\n    699         _expr, reps = posify(_expr) if force else (_expr, {})\n--> 700         _expr = (factor(_expr)).subs(reps)\n    701 \n    702         if not _expr.is_Add:\n\n/home/jrioux/git/sympy/sympy/polys/polytools.pyc in factor(f, *gens, **args)\n   5254         if not f.is_commutative:\n   5255             from sympy.core.exprtools import factor_nc\n-> 5256             return factor_nc(f)\n   5257         else:\n   5258             raise PolynomialError(msg)\n\n/home/jrioux/git/sympy/sympy/core/exprtools.pyc in factor_nc(expr)\n    603         return expr.func(*[factor_nc(a) for a in expr.args])\n    604 \n--> 605     expr, rep, nc_symbols = _mask_nc(expr)\n    606     if rep:\n    607         return factor(expr).subs(rep)\n\n/home/jrioux/git/sympy/sympy/core/exprtools.pyc in _mask_nc(eq)\n    569                 pass\n    570             elif (\n--> 571                 not a.is_commutative and\n    572                 not (a.is_Symbol or a.is_Add or a.is_Mul or a.is_Pow)\n    573                 ):\n\nAttributeError: 'str' object has no attribute 'is_commutative'\n\nIn [10]: sqrtdenest(p)\n---------------------------------------------------------------------------\nAttributeError                            Traceback (most recent call last)\n\n/home/jrioux/git/sympy/<ipython console> in <module>()\n\n/home/jrioux/git/sympy/sympy/simplify/sqrtdenest.pyc in sqrtdenest(expr, max_iter)\n    128     expr = expand_mul(sympify(expr))\n    129     for i in range(max_iter):\n--> 130         z = _sqrtdenest0(expr)\n    131         if expr == z:\n    132             return expr\n\n/home/jrioux/git/sympy/sympy/simplify/sqrtdenest.pyc in _sqrtdenest0(expr)\n    208         args = expr.args\n    209         if args:\n--> 210             return expr.func(*[_sqrtdenest0(a) for a in args])\n    211     return expr\n    212 \n\n/home/jrioux/git/sympy/sympy/simplify/sqrtdenest.pyc in _sqrtdenest0(expr)\n    208         args = expr.args\n    209         if args:\n--> 210             return expr.func(*[_sqrtdenest0(a) for a in args])\n    211     return expr\n    212 \n\n/home/jrioux/git/sympy/sympy/simplify/sqrtdenest.pyc in _sqrtdenest0(expr)\n    208         args = expr.args\n    209         if args:\n--> 210             return expr.func(*[_sqrtdenest0(a) for a in args])\n    211     return expr\n    212 \n\n/home/jrioux/git/sympy/sympy/simplify/sqrtdenest.pyc in _sqrtdenest0(expr)\n    190     \"\"\"Returns expr after denesting its arguments.\"\"\"\n    191 \n--> 192     if is_sqrt(expr):\n    193         n, d = expr.as_numer_denom()\n    194         if d is S.One: # n is a square root\n\n/home/jrioux/git/sympy/sympy/simplify/sqrtdenest.pyc in is_sqrt(expr)\n     13     \"\"\"Return True if expr is a sqrt, otherwise False.\"\"\"\n     14 \n---> 15     return expr.is_Pow and expr.exp.is_Rational and abs(expr.exp) is S.Half\n     16 \n     17 \n\nAttributeError: 'str' object has no attribute 'is_Pow'\n\nIn [11]: import sympy\n\nIn [12]: sympy.__version__\nOut[12]: '0.7.1-git'\n```\n\nOriginal issue for #6249: http://code.google.com/p/sympy/issues/detail?id=3150\nOriginal author: https://code.google.com/u/102137482174297837682/\n"},"comment":{"url":"https://api.github.com/repos/sympy/sympy/issues/comments/264744791","html_url":"https://github.com/sympy/sympy/issues/6249#issuecomment-264744791","issue_url":"https://api.github.com/repos/sympy/sympy/issues/6249","id":264744791,"user":{"login":"andreo","id":106359,"avatar_url":"https://avatars.githubusercontent.com/u/106359?v=3","gravatar_id":"","url":"https://api.github.com/users/andreo","html_url":"https://github.com/andreo","followers_url":"https://api.github.com/users/andreo/followers","following_url":"https://api.github.com/users/andreo/following{/other_user}","gists_url":"https://api.github.com/users/andreo/gists{/gist_id}","starred_url":"https://api.github.com/users/andreo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreo/subscriptions","organizations_url":"https://api.github.com/users/andreo/orgs","repos_url":"https://api.github.com/users/andreo/repos","events_url":"https://api.github.com/users/andreo/events{/privacy}","received_events_url":"https://api.github.com/users/andreo/received_events","type":"User","site_admin":false},"created_at":"2016-12-05T00:36:37Z","updated_at":"2016-12-05T00:36:37Z","body":"@asmeurer How should we handle the case `obj.__class__(*obj.args)` ?\r\n\r\n```\r\ndef test_invariants():\r\n    A = MatrixSymbol('A', n, m)\r\n    B = MatrixSymbol('B', m, l)\r\n    X = MatrixSymbol('X', n, n)\r\n    objs = [Identity(n), ZeroMatrix(m, n), A, MatMul(A, B), MatAdd(A, A),\r\n            Transpose(A), Adjoint(A), Inverse(X), MatPow(X, 2), MatPow(X, -1),\r\n            MatPow(X, 0)]\r\n    for obj in objs:\r\n        assert obj == obj.__class__(*obj.args)\r\n```"}}
{"actor":{"display_login":"andreo"}}