Repository: sympy/sympy

Issue:
sympify could delete newlines, perhaps
```
>>> S('''a+
... b''')
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "sympy\core\sympify.py", line 163, in sympify
    raise SympifyError('could not parse %r' % a)
sympy.core.sympify.SympifyError: SympifyError: "could not parse u'a+\\nb'"

I would have liked this to come back as `a + b`
```

Original issue for #5939: http://code.google.com/p/sympy/issues/detail?id=2840
Original author: https://code.google.com/u/117933771799683895267/


Discussion:

Patch:
diff --git a/.mailmap b/.mailmap
index 9338d58a44..37f68ffdd1 100644
--- a/.mailmap
+++ b/.mailmap
@@ -394,10 +394,6 @@ Gagandeep Singh <singh.23@iitj.ac.in> czgdp1807 <gdp.1807@gmail.com>
 Gagandeep Singh <singh.23@iitj.ac.in> czgdp1807 <36567889+czgdp1807@users.noreply.github.com>
 Gagandeep Singh <singh.23@iitj.ac.in> czgdp1807 <czgdp1807@gmail.com>
 Gagandeep Singh <singh.23@iitj.ac.in> MathLover <36567889+czgdp1807@users.noreply.github.com>
-Gagandeep Singh <singh.23@iitj.ac.in> czgdp1807 <singh.23@iitj.ac.in>
-Gagandeep Singh <singh.23@iitj.ac.in> Gagandeep Singh <36567889+czgdp1807@users.noreply.github.com>
-Gagandeep Singh <singh.23@iitj.ac.in> Gagandeep Singh <czgdp1807@gmail.com>
-Gagandeep Singh <singh.23@iitj.ac.in> Gagandeep Singh <singh.23@iitj.ac.in>
 S.Y. Lee <sylee957@gmail.com> sylee957 <sylee957@gmail.com>
 Yatna Verma <yatnavermaa@gmail.com> yatna <yatnavermaa@gmail.com>
 Jared Lumpe <mjlumpe@gmail.com> Michael Jared Lumpe <mjlumpe@gmail.com>
@@ -407,9 +403,3 @@ amsuhane <ayushsuhane99@iitkgp.ac.in> amsuhane <“ayushsuhane99@iitkgp.ac.in”
 Ritu Raj Singh <RituRajSingh878@gmail.com> Ritu Raj Singh <37741324+RituRajSingh878@users.noreply.github.com>
 Ritu Raj Singh <RituRajSingh878@gmail.com> RituRajSingh878 <RituRajSingh878@gmail.com>
 rationa-kunal <kunalgk1999@gmail.com> kunal <kunalgk1999@protonmail.com>
-shiksha11 <shiksharawat01@gmail.com> shiksha11 <33157995+shiksha11@users.noreply.github.com>
-Jogi Miglani <jmig5776@gmail.com> jmig5776 <jmig5776@gmail.com>
-Supreet Agrawal <supreet11agrawal@gmail.com> stm <supreet11agrawal@gmail.com>
-Bavish Kulur <bavishkulur@gmail.com> bavish2201 <bavishkulur@gmail.com>
-Divyanshu Thakur <divyanshu@iiitmanipur.ac.in> Divyanshu <divyanshu@iiitmanipur.ac.in>
-Shubham Kumar Jha <skjha832@gmail.com> ShubhamKJha <skjha832@gmail.com>
diff --git a/AUTHORS b/AUTHORS
index 525bc9cb75..3f288c13e1 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -4,7 +4,7 @@ those who explicitly didn't want to be mentioned. People with a * next
 to their names are not found in the metadata of the git history. This
 file is generated automatically by running `./bin/authors_update.py`.
 
-There are a total of 798 authors.
+There are a total of 782 authors.
 
 Ondřej Čertík <ondrej@certik.cz>
 Fabian Pedregosa <fabian@fseoane.net>
@@ -788,19 +788,3 @@ Ritu Raj Singh <RituRajSingh878@gmail.com>
 Rajiv Ranjan Singh <42106787+iamrajiv@users.noreply.github.com>
 Vera Lozhkina <veralozhkina@gmail.com>
 adhoc-king <46354827+adhoc-king@users.noreply.github.com>
-Mikel Rouco <mikel.mrm@gmail.com>
-Oscar Gustafsson <oscar.gustafsson@gmail.com>
-damianos <damianos@semmle.com>
-Supreet Agrawal <supreet11agrawal@gmail.com>
-shiksha11 <shiksharawat01@gmail.com>
-Martin Ueding <dev@martin-ueding.de>
-sharma-kunal <kunalsharma6914@gmail.com>
-Divyanshu Thakur <divyanshu@iiitmanipur.ac.in>
-Susumu Ishizuka <susumu.ishizuka@kii.com>
-Samnan Rahee <namanush.rsr.16@gmail.com>
-Fredrik Andersson <fredrik.andersson@fcc.chalmers.se>
-Bhavya Srivastava <bhavya17037@iiitd.ac.in>
-Alpesh Jamgade <alpeshjamgade21@gmail.com>
-Shubham Abhang <shubhamabhang77@gmail.com>
-Vishesh Mangla <manglavishesh64@gmail.com>
-Nicko van Someren <nicko@nicko.org>
diff --git a/bin/authors_update.py b/bin/authors_update.py
index 0362356f15..d23b4ce96d 100755
--- a/bin/authors_update.py
+++ b/bin/authors_update.py
@@ -94,8 +94,6 @@ def move(l, i1, i2, who):
         ), 'Sergey B Kirpichev was not found at line 226.'
     assert 'azure-pipelines[bot]' == \
         author_name(git_people.pop(751)), 'azure-pipelines[bot] was not found at line 751'
-    assert 'whitesource-bolt-for-github[bot]' == \
-        author_name(git_people.pop(792)), 'whitesource-bolt-for-github[bot] not found at line 792'
 except AssertionError as msg:
     print(red(msg))
     sys.exit(1)
@@ -154,5 +152,3 @@ def move(l, i1, i2, who):
     print()
     for i in sorted(new_authors, key=lambda x: x.lower()):
         print('\t%s' % i)
-else:
-    print(yellow("The AUTHORS file was updated."))
diff --git a/sympy/matrices/expressions/matadd.py b/sympy/matrices/expressions/matadd.py
index 1c28021249..22315096ce 100644
--- a/sympy/matrices/expressions/matadd.py
+++ b/sympy/matrices/expressions/matadd.py
@@ -8,9 +8,8 @@
 from sympy.matrices.matrices import MatrixBase
 from sympy.matrices.expressions.transpose import transpose
 from sympy.strategies import (rm_id, unpack, flatten, sort, condition,
-    exhaust, do_one, glom)
-from sympy.matrices.expressions.matexpr import (MatrixExpr, ShapeError,
-    ZeroMatrix, GenericZeroMatrix)
+        exhaust, do_one, glom)
+from sympy.matrices.expressions.matexpr import MatrixExpr, ShapeError, ZeroMatrix
 from sympy.utilities import default_sort_key, sift
 from sympy.core.operations import AssocOp
 
@@ -33,12 +32,6 @@ class MatAdd(MatrixExpr, Add):
     is_MatAdd = True
 
     def __new__(cls, *args, **kwargs):
-        if not args:
-            return GenericZeroMatrix()
-
-        # This must be removed aggressively in the constructor to avoid
-        # TypeErrors from GenericZeroMatrix().shape
-        args = filter(lambda i: GenericZeroMatrix() != i, args)
         args = list(map(sympify, args))
         check = kwargs.get('check', False)
 
diff --git a/sympy/matrices/expressions/matexpr.py b/sympy/matrices/expressions/matexpr.py
index 69124d89fe..124e9994e2 100644
--- a/sympy/matrices/expressions/matexpr.py
+++ b/sympy/matrices/expressions/matexpr.py
@@ -738,10 +738,6 @@ def cols(self):
     def shape(self):
         return (self.args[0], self.args[0])
 
-    @property
-    def is_square(self):
-        return True
-
     def _eval_transpose(self):
         return self
 
@@ -765,39 +761,6 @@ def _entry(self, i, j, **kwargs):
     def _eval_determinant(self):
         return S.One
 
-class GenericIdentity(Identity):
-    """
-    An identity matrix without a specified shape
-
-    This exists primarily so MatMul() with no arguments can return something
-    meaningful.
-    """
-    def __new__(cls):
-        # super(Identity, cls) instead of super(GenericIdentity, cls) because
-        # Identity.__new__ doesn't have the same signature
-        return super(Identity, cls).__new__(cls)
-
-    @property
-    def rows(self):
-        raise TypeError("GenericIdentity does not have a specified shape")
-
-    @property
-    def cols(self):
-        raise TypeError("GenericIdentity does not have a specified shape")
-
-    @property
-    def shape(self):
-        raise TypeError("GenericIdentity does not have a specified shape")
-
-    # Avoid Matrix.__eq__ which might call .shape
-    def __eq__(self, other):
-        return isinstance(other, GenericIdentity)
-
-    def __ne__(self, other):
-        return not (self == other)
-
-    def __hash__(self):
-        return super(GenericIdentity, self).__hash__()
 
 class ZeroMatrix(MatrixExpr):
     """The Matrix Zero 0 - additive identity
@@ -853,40 +816,6 @@ def __nonzero__(self):
 
     __bool__ = __nonzero__
 
-class GenericZeroMatrix(ZeroMatrix):
-    """
-    A zero matrix without a specified shape
-
-    This exists primarily so MatAdd() with no arguments can return something
-    meaningful.
-    """
-    def __new__(cls):
-        # super(ZeroMatrix, cls) instead of super(GenericZeroMatrix, cls)
-        # because ZeroMatrix.__new__ doesn't have the same signature
-        return super(ZeroMatrix, cls).__new__(cls)
-
-    @property
-    def rows(self):
-        raise TypeError("GenericZeroMatrix does not have a specified shape")
-
-    @property
-    def cols(self):
-        raise TypeError("GenericZeroMatrix does not have a specified shape")
-
-    @property
-    def shape(self):
-        raise TypeError("GenericZeroMatrix does not have a specified shape")
-
-    # Avoid Matrix.__eq__ which might call .shape
-    def __eq__(self, other):
-        return isinstance(other, GenericZeroMatrix)
-
-    def __ne__(self, other):
-        return not (self == other)
-
-
-    def __hash__(self):
-        return super(GenericZeroMatrix, self).__hash__()
 
 def matrix_symbols(expr):
     return [sym for sym in expr.free_symbols if sym.is_Matrix]
diff --git a/sympy/matrices/expressions/matmul.py b/sympy/matrices/expressions/matmul.py
index cff91f73f7..fb861a70ba 100644
--- a/sympy/matrices/expressions/matmul.py
+++ b/sympy/matrices/expressions/matmul.py
@@ -8,7 +8,7 @@
 from sympy.strategies import (rm_id, unpack, typed, flatten, exhaust,
         do_one, new)
 from sympy.matrices.expressions.matexpr import (MatrixExpr, ShapeError,
-        Identity, ZeroMatrix, GenericIdentity)
+        Identity, ZeroMatrix)
 from sympy.matrices.expressions.matpow import MatPow
 from sympy.matrices.matrices import MatrixBase
 
@@ -31,22 +31,12 @@ class MatMul(MatrixExpr, Mul):
 
     def __new__(cls, *args, **kwargs):
         check = kwargs.get('check', True)
-
-        if not args:
-            return GenericIdentity()
-
-        # This must be removed aggressively in the constructor to avoid
-        # TypeErrors from GenericIdentity().shape
-        args = filter(lambda i: GenericIdentity() != i, args)
         args = list(map(sympify, args))
         obj = Basic.__new__(cls, *args)
         factor, matrices = obj.as_coeff_matrices()
         if check:
             validate(*matrices)
         if not matrices:
-            # Should it be
-            #
-            # return Basic.__neq__(cls, factor, GenericIdentity()) ?
             return factor
         return obj
 
diff --git a/sympy/printing/mathml.py b/sympy/printing/mathml.py
index 6ddab5edf1..9d2455dcd7 100644
--- a/sympy/printing/mathml.py
+++ b/sympy/printing/mathml.py
@@ -929,7 +929,7 @@ def _print_Basic(self, e):
     def _print_AssocOp(self, e):
         mrow = self.dom.createElement('mrow')
         mi = self.dom.createElement('mi')
-        mi.appendChild(self.dom.createTextNode(self.mathml_tag(e)))
+        mi.append(self.dom.createTextNode(self.mathml_tag(e)))
         mrow.appendChild(mi)
         for arg in e.args:
             mrow.appendChild(self._print(arg))
@@ -950,50 +950,6 @@ def _print_int(self, p):
         return dom_element
 
 
-    def _print_Integers(self, e):
-        x = self.dom.createElement('mi')
-        x.setAttribute('mathvariant', 'normal')
-        x.appendChild(self.dom.createTextNode('&#x2124;'))
-        return x
-
-
-    def _print_Complexes(self, e):
-        x = self.dom.createElement('mi')
-        x.setAttribute('mathvariant', 'normal')
-        x.appendChild(self.dom.createTextNode('&#x2102;'))
-        return x
-
-
-    def _print_Reals(self, e):
-        x = self.dom.createElement('mi')
-        x.setAttribute('mathvariant', 'normal')
-        x.appendChild(self.dom.createTextNode('&#x211D;'))
-        return x
-
-
-    def _print_Naturals(self, e):
-        x = self.dom.createElement('mi')
-        x.setAttribute('mathvariant', 'normal')
-        x.appendChild(self.dom.createTextNode('&#x2115;'))
-        return x
-
-
-    def _print_Naturals0(self, e):
-        sub = self.dom.createElement('msub')
-        x = self.dom.createElement('mi')
-        x.setAttribute('mathvariant', 'normal')
-        x.appendChild(self.dom.createTextNode('&#x2115;'))
-        sub.appendChild(x)
-        sub.appendChild(self._print(S.Zero))
-        return sub
-
-
-    def _print_EmptySet(self, e):
-        x = self.dom.createElement('mo')
-        x.appendChild(self.dom.createTextNode('&#x2205;'))
-        return x
-
-
 def mathml(expr, printer='content', **settings):
     """Returns the MathML representation of expr. If printer is presentation then
      prints Presentation MathML else prints content MathML.


Test patch:
diff --git a/sympy/core/tests/test_args.py b/sympy/core/tests/test_args.py
index 5895f1ca84..dc98b2191c 100644
--- a/sympy/core/tests/test_args.py
+++ b/sympy/core/tests/test_args.py
@@ -2666,9 +2666,6 @@ def test_sympy__matrices__expressions__matexpr__Identity():
     from sympy.matrices.expressions.matexpr import Identity
     assert _test_args(Identity(3))
 
-def test_sympy__matrices__expressions__matexpr__GenericIdentity():
-    from sympy.matrices.expressions.matexpr import GenericIdentity
-    assert _test_args(GenericIdentity())
 
 @SKIP("abstract class")
 def test_sympy__matrices__expressions__matexpr__MatrixExpr():
@@ -2689,9 +2686,6 @@ def test_sympy__matrices__expressions__matexpr__ZeroMatrix():
     from sympy.matrices.expressions.matexpr import ZeroMatrix
     assert _test_args(ZeroMatrix(3, 5))
 
-def test_sympy__matrices__expressions__matexpr__GenericZeroMatrix():
-    from sympy.matrices.expressions.matexpr import GenericZeroMatrix
-    assert _test_args(GenericZeroMatrix())
 
 def test_sympy__matrices__expressions__matmul__MatMul():
     from sympy.matrices.expressions.matmul import MatMul
diff --git a/sympy/core/tests/test_sympify.py b/sympy/core/tests/test_sympify.py
index c82e272b3b..1cb13e2f25 100644
--- a/sympy/core/tests/test_sympify.py
+++ b/sympy/core/tests/test_sympify.py
@@ -660,3 +660,9 @@ class CustomSymbol(Symbol):
     a = sympify(numpy.str_('x + x'), evaluate=False)
     assert isinstance(a, Add)
     assert a == Add(x, x, evaluate=False)
+
+
+def test_issue_5939():
+     a = Symbol('a')
+     b = Symbol('b')
+     assert sympify('''a+\nb''') == a + b
diff --git a/sympy/matrices/expressions/tests/test_matexpr.py b/sympy/matrices/expressions/tests/test_matexpr.py
index 21c92ea8e8..ace95c2802 100644
--- a/sympy/matrices/expressions/tests/test_matexpr.py
+++ b/sympy/matrices/expressions/tests/test_matexpr.py
@@ -8,8 +8,7 @@
 from sympy.matrices import (Identity, ImmutableMatrix, Inverse, MatAdd, MatMul,
         MatPow, Matrix, MatrixExpr, MatrixSymbol, ShapeError, ZeroMatrix,
         SparseMatrix, Transpose, Adjoint)
-from sympy.matrices.expressions.matexpr import (MatrixElement,
-    GenericZeroMatrix, GenericIdentity)
+from sympy.matrices.expressions.matexpr import MatrixElement
 from sympy.utilities.pytest import raises
 
 
@@ -361,42 +360,3 @@ def test_issue_2749():
 def test_issue_2750():
     x = MatrixSymbol('x', 1, 1)
     assert (x.T*x).as_explicit()**-1 == Matrix([[x[0, 0]**(-2)]])
-
-def test_generic_zero_matrix():
-    z = GenericZeroMatrix()
-    A = MatrixSymbol("A", n, n)
-
-    assert z == z
-    assert z != A
-    assert A != z
-
-    assert z.is_ZeroMatrix
-
-    raises(TypeError, lambda: z.shape)
-    raises(TypeError, lambda: z.rows)
-    raises(TypeError, lambda: z.cols)
-
-    assert MatAdd() == z
-    assert MatAdd(z, A) == MatAdd(A)
-    # Make sure it is hashable
-    hash(z)
-
-def test_generic_identity():
-    I = GenericIdentity()
-    A = MatrixSymbol("A", n, n)
-
-    assert I == I
-    assert I != A
-    assert A != I
-
-    assert I.is_Identity
-    assert I**-1 == I
-
-    raises(TypeError, lambda: I.shape)
-    raises(TypeError, lambda: I.rows)
-    raises(TypeError, lambda: I.cols)
-
-    assert MatMul() == I
-    assert MatMul(I, A) == MatMul(A)
-    # Make sure it is hashable
-    hash(I)
diff --git a/sympy/printing/tests/test_mathml.py b/sympy/printing/tests/test_mathml.py
index 5c876d140b..21df48d6eb 100644
--- a/sympy/printing/tests/test_mathml.py
+++ b/sympy/printing/tests/test_mathml.py
@@ -925,25 +925,6 @@ def test_toprettyxml_hooking():
     assert prettyxml_old2 == doc2.toprettyxml()
 
 
-def test_print_domains():
-    from sympy import Complexes, Integers, Naturals, Naturals0, Reals
-
-    assert mpp.doprint(Complexes) == '<mi mathvariant="normal">&#x2102;</mi>'
-    assert mpp.doprint(Integers) == '<mi mathvariant="normal">&#x2124;</mi>'
-    assert mpp.doprint(Naturals) == '<mi mathvariant="normal">&#x2115;</mi>'
-    assert mpp.doprint(Naturals0) == '<msub><mi mathvariant="normal">&#x2115;</mi><mn>0</mn></msub>'
-    assert mpp.doprint(Reals) == '<mi mathvariant="normal">&#x211D;</mi>'
-
-
-def test_print_AssocOp():
-    from sympy.core.operations import AssocOp
-    class TestAssocOp(AssocOp):
-        identity = 0
-
-    expr = TestAssocOp(1, 2)
-    mpp.doprint(expr) == '<mrow><mi>testassocop</mi><mn>2</mn><mn>1</mn></mrow>'
-
-
 def test_print_basic():
     expr = Basic(1, 2)
     assert mpp.doprint(expr) == '<mrow><mi>basic</mi><mfenced><mn>1</mn><mn>2</mn></mfenced></mrow>'