Repository: sympy/sympy

Issue:
Core: Enhancing the unchanged function
This issue follows from https://github.com/sympy/sympy/issues/16177.
For solving this issue, an `unchanged` function was added in `expr.py` through PR https://github.com/sympy/sympy/pull/16189
Currently, this `unchanged` function works perfectly for checking if an expression remains unchanged if the expression is something like `cos(x)` or `exp(x)`. However, for expressions like https://github.com/sympy/sympy/blob/00252f18af78cdc3013042e7ef264af8161c9366/sympy/core/tests/test_arit.py#L348 this function is insufficient. The idea here is to improve the `unchanged` function or maybe introduce a new one which checks if expressions of this form remain unchanged or not

Discussion:

Patch:
diff --git a/doc/src/install.rst b/doc/src/install.rst
index 2bf734e36a..34fce81a73 100644
--- a/doc/src/install.rst
+++ b/doc/src/install.rst
@@ -34,7 +34,7 @@ If you wish to contribute to SymPy or like to get the latest updates as they
 come, install SymPy from git. To download the repository, execute the
 following from the command line::
 
-    git clone https://github.com/sympy/sympy.git
+    git clone git://github.com/sympy/sympy.git
 
 To update to the latest version, go into your repository and execute::
 
diff --git a/sympy/core/basic.py b/sympy/core/basic.py
index 67a6447d66..2636ec4979 100644
--- a/sympy/core/basic.py
+++ b/sympy/core/basic.py
@@ -945,8 +945,7 @@ def subs(self, *args, **kwargs):
                 # when old is a string we prefer Symbol
                 s = Symbol(s[0]), s[1]
             try:
-                s = [sympify(_, strict=not isinstance(_, string_types))
-                     for _ in s]
+                s = [sympify(_, strict=type(_) is not str) for _ in s]
             except SympifyError:
                 # if it can't be sympified, skip it
                 sequence[i] = None
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index 58e6621764..0736fc906d 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -1075,7 +1075,7 @@ def _print_subfactorial(self, expr, exp=None):
         tex = r"!%s" % self.parenthesize(expr.args[0], PRECEDENCE["Func"])
 
         if exp is not None:
-            return r"\left(%s\right)^{%s}" % (tex, exp)
+            return r"%s^{%s}" % (tex, exp)
         else:
             return tex
 
@@ -1740,7 +1740,7 @@ def _print_KroneckerDelta(self, expr, exp=None):
             tex = r'\delta_{%s %s}' % (i, j)
         else:
             tex = r'\delta_{%s, %s}' % (i, j)
-        if exp is not None:
+        if exp:
             tex = r'\left(%s\right)^{%s}' % (tex, exp)
         return tex
 
diff --git a/sympy/printing/mathml.py b/sympy/printing/mathml.py
index ad0c01fef3..1aa0ee01a2 100644
--- a/sympy/printing/mathml.py
+++ b/sympy/printing/mathml.py
@@ -5,9 +5,8 @@
 from __future__ import print_function, division
 
 from sympy import sympify, S, Mul
-from sympy.core.compatibility import range, string_types, default_sort_key
 from sympy.core.function import _coeff_isneg
-from sympy.core.numbers import E
+from sympy.core.compatibility import range, string_types, default_sort_key
 from sympy.printing.conventions import split_super_sub, requires_partial
 from sympy.printing.precedence import precedence_traditional, PRECEDENCE
 from sympy.printing.pretty.pretty_symbology import greek_unicode
@@ -293,7 +292,7 @@ def _print_Pi(self, e):
     def _print_Infinity(self, e):
         return self.dom.createElement('infinity')
 
-    def _print_NegativeInfinity(self, e):
+    def _print_Negative_Infinity(self, e):
         x = self.dom.createElement('apply')
         x.appendChild(self.dom.createElement('minus'))
         x.appendChild(self.dom.createElement('infinity'))
@@ -515,9 +514,6 @@ def mathml_tag(self, e):
             'StrictGreaterThan': '>',
             'StrictLessThan': '<',
             'lerchphi': '&#x3A6;',
-            'BooleanTrue' : 'True',
-            'BooleanFalse' : 'False',
-            'NoneType' : 'None',
         }
 
         def mul_symbol_selection():
@@ -715,7 +711,7 @@ def _print_Infinity(self, e):
         x.appendChild(self.dom.createTextNode('&#x221E;'))
         return x
 
-    def _print_NegativeInfinity(self, e):
+    def _print_Negative_Infinity(self, e):
         mrow = self.dom.createElement('mrow')
         y = self.dom.createElement('mo')
         y.appendChild(self.dom.createTextNode('-'))
@@ -1179,63 +1175,6 @@ def _print_Not(self, e):
         mrow.appendChild(x)
         return mrow
 
-    def _print_bool(self, e):
-        mi = self.dom.createElement('mi')
-        mi.appendChild(self.dom.createTextNode(self.mathml_tag(e)))
-        return mi
-
-    _print_BooleanTrue = _print_bool
-    _print_BooleanFalse = _print_bool
-
-    def _print_NoneType(self, e):
-        mi = self.dom.createElement('mi')
-        mi.appendChild(self.dom.createTextNode(self.mathml_tag(e)))
-        return mi
-
-    def _print_Range(self, s):
-        dots = u"\u2026"
-        brac = self.dom.createElement('mfenced')
-        brac.setAttribute('open', '{')
-        brac.setAttribute('close', '}')
-
-        if s.start.is_infinite:
-            printset = s.start, dots, s[-1] - s.step, s[-1]
-        elif s.stop.is_infinite or len(s) > 4:
-            it = iter(s)
-            printset = next(it), next(it), dots, s[-1]
-        else:
-            printset = tuple(s)
-
-        for el in printset:
-            if el == dots:
-                mi = self.dom.createElement('mi')
-                mi.appendChild(self.dom.createTextNode(dots))
-                brac.appendChild(mi)
-            else:
-                brac.appendChild(self._print(el))
-
-        return brac
-
-    def _hprint_variadic_function(self, expr):
-        args = sorted(expr.args, key=default_sort_key)
-        mrow = self.dom.createElement('mrow')
-        mo = self.dom.createElement('mo')
-        mo.appendChild(self.dom.createTextNode((str(expr.func)).lower()))
-        mrow.appendChild(mo)
-        brac = self.dom.createElement('mfenced')
-        for symbol in args:
-            brac.appendChild(self._print(symbol))
-        mrow.appendChild(brac)
-        return mrow
-
-    _print_Min = _print_Max = _hprint_variadic_function
-
-    def _print_exp(self, expr):
-        msup = self.dom.createElement('msup')
-        msup.appendChild(self._print_Exp1(None))
-        msup.appendChild(self._print(expr.args[0]))
-        return msup
-
     def _print_Relational(self, e):
         mrow = self.dom.createElement('mrow')
         mrow.appendChild(self._print(e.lhs))
@@ -1332,26 +1271,6 @@ def _print_Lambda(self, e):
         return x
 
 
-    def _print_tuple(self, e):
-        x = self.dom.createElement('mfenced')
-        for i in e:
-            x.appendChild(self._print(i))
-        return x
-
-
-    def _print_IndexedBase(self, e):
-        return self._print(e.label)
-
-    def _print_Indexed(self, e):
-        x = self.dom.createElement('msub')
-        x.appendChild(self._print(e.base))
-        if len(e.indices) == 1:
-            x.appendChild(self._print(e.indices[0]))
-            return x
-        x.appendChild(self._print(e.indices))
-        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.
diff --git a/sympy/series/fourier.py b/sympy/series/fourier.py
index fb62b23bfa..04dacd3b87 100644
--- a/sympy/series/fourier.py
+++ b/sympy/series/fourier.py
@@ -96,28 +96,30 @@ def finite_check(f, x, L):
     def check_fx(exprs, x):
         return x not in exprs.free_symbols
 
-    def check_sincos(_expr, x, L):
-        if isinstance(_expr, (sin, cos)):
-            sincos_args = _expr.args[0]
+    def check_sincos(expr, x, L):
+        if type(expr) == sin or type(expr) == cos:
+            sincos_args = expr.args[0]
 
             if sincos_args.match(a*(pi/L)*x + b) is not None:
                 return True
             else:
                 return False
 
-    _expr = sincos_to_sum(TR2(TR1(f)))
-    add_coeff = _expr.as_coeff_add()
+    expr = sincos_to_sum(TR2(TR1(f)))
+    res_expr = S.Zero
+    add_coeff = expr.as_coeff_add()
+    res_expr += add_coeff[0]
 
     a = Wild('a', properties=[lambda k: k.is_Integer, lambda k: k != S.Zero, ])
-    b = Wild('b', properties=[lambda k: x not in k.free_symbols, ])
+    b = Wild('b', properties=[lambda k: x not in k.free_symbols or k == S.Zero, ])
 
     for s in add_coeff[1]:
         mul_coeffs = s.as_coeff_mul()[1]
         for t in mul_coeffs:
             if not (check_fx(t, x) or check_sincos(t, x, L)):
                 return False, f
-
-    return True, _expr
+        res_expr += TR10(s)
+    return True, res_expr.collect([sin(a*(pi/L)*x), cos(a*(pi/L)*x)])
 
 
 class FourierSeries(SeriesBase):
@@ -178,10 +180,6 @@ def stop(self):
     def length(self):
         return oo
 
-    @property
-    def L(self):
-        return abs(self.period[1] - self.period[0]) / 2
-
     def _eval_subs(self, old, new):
         x = self.x
         if old.has(x):
@@ -442,145 +440,16 @@ def __sub__(self, other):
         return self.__add__(-other)
 
 
-class FiniteFourierSeries(FourierSeries):
-    r"""Represents Finite Fourier sine/cosine series.
-
-    For how to compute Fourier series, see the :func:`fourier_series`
-    docstring.
-
-    Parameters
-    ==========
-    f : Expr
-        Expression for finding fourier_series
-
-    limits : ( x, start, stop)
-        x is the independent variable for the expression f
-        (start, stop) is the period of the fourier series
-
-    exprs: (a0, an, bn) or Expr
-        a0 is the constant term a0 of the fourier series
-        an is a dictionary of coefficients of cos terms
-         an[k] = coefficient of cos(pi*(k/L)*x)
-        bn is a dictionary of coefficients of sin terms
-         bn[k] = coefficient of sin(pi*(k/L)*x)
-
-        or exprs can be an expression to be converted to fourier form
-
-    Methods
-    =======
-    This class is an extension of FourierSeries class.
-    Please refer to sympy.series.fourier.FourierSeries for
-    further information.
-
-    See Also
-    ========
-
-    sympy.series.fourier.FourierSeries
-    sympy.series.fourier.fourier_series
-    """
-
-    def __new__(cls, f, limits, exprs):
-        if not (type(exprs) == tuple and len(exprs) == 3):  # exprs is not of form (a0, an, bn)
-            # Converts the expression to fourier form
-            c, e = exprs.as_coeff_add()
-            rexpr = c + Add(*[TR10(i) for i in e])
-            a0, exp_ls = rexpr.expand(trig=False, power_base=False, power_exp=False, log=False).as_coeff_add()
-
-            x = limits[0]
-            L = abs(limits[2] - limits[1]) / 2
-
-            a = Wild('a', properties=[lambda k: k.is_Integer, lambda k: k is not S.Zero, ])
-            b = Wild('b', properties=[lambda k: x not in k.free_symbols, ])
-
-            an = dict()
-            bn = dict()
-
-            # separates the coefficients of sin and cos terms in dictionaries an, and bn
-            for p in exp_ls:
-                t = p.match(b * cos(a * (pi / L) * x))
-                q = p.match(b * sin(a * (pi / L) * x))
-                if t:
-                    an[t[a]] = t[b] + an.get(t[a], S.Zero)
-                elif q:
-                    bn[q[a]] = q[b] + bn.get(q[a], S.Zero)
-                else:
-                    a0 += p
-
-            exprs = (a0, an, bn)
-
-        args = map(sympify, (f, limits, exprs))
-
-        return Expr.__new__(cls, *args)
-
-    @property
-    def interval(self):
-        _length = 1 if self.a0 else 0
-        _length += max(set(self.an.keys()).union(set(self.bn.keys()))) + 1
-        return Interval(0, _length)
-
-    @property
-    def length(self):
-        return self.stop - self.start
-
-    def shiftx(self, s):
-        s, x = sympify(s), self.x
-
-        if x in s.free_symbols:
-            raise ValueError("'%s' should be independent of %s" % (s, x))
-
-        _expr = self.truncate().subs(x, x + s)
-        sfunc = self.function.subs(x, x + s)
-
-        return self.func(sfunc, self.args[1], _expr)
-
-    def scale(self, s):
-        s, x = sympify(s), self.x
-
-        if x in s.free_symbols:
-            raise ValueError("'%s' should be independent of %s" % (s, x))
-
-        _expr = self.truncate() * s
-        sfunc = self.function * s
-
-        return self.func(sfunc, self.args[1], _expr)
-
-    def scalex(self, s):
-        s, x = sympify(s), self.x
-
-        if x in s.free_symbols:
-            raise ValueError("'%s' should be independent of %s" % (s, x))
-
-        _expr = self.truncate().subs(x, x * s)
-        sfunc = self.function.subs(x, x * s)
-
-        return self.func(sfunc, self.args[1], _expr)
-
-    def _eval_term(self, pt):
-        if pt == 0:
-            return self.a0
-
-        _term = self.an.get(pt, S.Zero) * cos(pt * (pi / self.L) * self.x) \
-                + self.bn.get(pt, S.Zero) * sin(pt * (pi / self.L) * self.x)
-        return _term
-
-    def __add__(self, other):
-        if isinstance(other, FourierSeries):
-            return other.__add__(fourier_series(self.function, self.args[1],\
-                                                finite=False))
-        elif isinstance(other, FiniteFourierSeries):
-            if self.period != other.period:
-                raise ValueError("Both the series should have same periods")
-
-            x, y = self.x, other.x
-            function = self.function + other.function.subs(y, x)
-
-            if self.x not in function.free_symbols:
-                return function
+class FiniteFourierSeries(Basic):
+    def __new__(cls, *args):
+        obj = Basic.__new__(cls, *args)
+        return obj
 
-            return fourier_series(function, limits=self.args[1])
+    def truncate(self, n=3):
+        return Add(*self._args)
 
 
-def fourier_series(f, limits=None, finite=True):
+def fourier_series(f, limits=None):
     """Computes Fourier sine/cosine series expansion.
 
     Returns a :class:`FourierSeries` object.
@@ -642,11 +511,11 @@ def fourier_series(f, limits=None, finite=True):
     if x not in f.free_symbols:
         return f
 
-    if finite:
-        L = abs(limits[2] - limits[1]) / 2
-        is_finite, res_f = finite_check(f, x, L)
-        if is_finite:
-            return FiniteFourierSeries(f, limits, res_f)
+    L = abs(limits[2] - limits[1])/2
+    is_finite, res_f = finite_check(f, x, L)
+
+    if is_finite:
+        return FiniteFourierSeries(res_f)
 
     n = Dummy('n')
     neg_f = f.subs(x, -x)


Test patch:
diff --git a/sympy/core/tests/test_arit.py b/sympy/core/tests/test_arit.py
index 28af93d239..79f96bf871 100644
--- a/sympy/core/tests/test_arit.py
+++ b/sympy/core/tests/test_arit.py
@@ -3,6 +3,7 @@
         sign, im, nan, Dummy, factorial, comp, refine
 )
 from sympy.core.compatibility import long, range
+from sympy.core.expr import unchanged
 from sympy.utilities.iterables import cartes
 from sympy.utilities.pytest import XFAIL, raises
 from sympy.utilities.randtest import verify_numerically
@@ -345,8 +346,8 @@ def test_powerbug():
 def test_Mul_doesnt_expand_exp():
     x = Symbol('x')
     y = Symbol('y')
-    assert exp(x)*exp(y) == exp(x)*exp(y)
-    assert 2**x*2**y == 2**x*2**y
+    assert unchanged(Mul, exp(x), exp(y))
+    assert unchanged(Mul, 2**x, 2**y)
     assert x**2*x**3 == x**5
     assert 2**x*3**x == 6**x
     assert x**(y)*x**(2*y) == x**(3*y)
diff --git a/sympy/core/tests/test_basic.py b/sympy/core/tests/test_basic.py
index c62351cc7d..57adece5a3 100644
--- a/sympy/core/tests/test_basic.py
+++ b/sympy/core/tests/test_basic.py
@@ -120,15 +120,6 @@ def test_subs():
     assert Symbol(u"text").subs({u"text": b1}) == b1
 
 
-def test_subs_with_unicode_symbols():
-    expr = Symbol('var1')
-    replaced = expr.subs('var1', u'x')
-    assert replaced.name == 'x'
-
-    replaced = expr.subs('var1', 'x')
-    assert replaced.name == 'x'
-
-
 def test_atoms():
     assert b21.atoms() == set()
 
diff --git a/sympy/core/tests/test_function.py b/sympy/core/tests/test_function.py
index 6ee8de75a5..4632ad048a 100644
--- a/sympy/core/tests/test_function.py
+++ b/sympy/core/tests/test_function.py
@@ -1127,7 +1127,7 @@ def test_issue_15241():
     assert (y*G + y*Gy*G).diff(y, G) == y*Gy.diff(y) + Gy + 1
 
 
-def test_issue_15226():
+def test_issue_15266():
     assert Subs(Derivative(f(y), x, y), y, g(x)).doit() != 0
 
 
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index c071953dcc..d9cd85f3f4 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -17,7 +17,7 @@
     Contains, divisor_sigma, SymmetricDifference, SeqPer, SeqFormula,
     SeqAdd, SeqMul, fourier_series, pi, ConditionSet, ComplexRegion, fps,
     AccumBounds, reduced_totient, primenu, primeomega, SingularityFunction,
-     UnevaluatedExpr, Quaternion, I, KroneckerProduct, Intersection)
+     UnevaluatedExpr, Quaternion, I)
 
 from sympy.ntheory.factor_ import udivisor_sigma
 
@@ -272,7 +272,6 @@ def test_latex_functions():
     # not to be confused with the beta function
     assert latex(mybeta(x, y, z)) == r"\beta{\left(x,y,z \right)}"
     assert latex(beta(x, y)) == r'\operatorname{B}\left(x, y\right)'
-    assert latex(beta(x, y)**2) == r'\operatorname{B}^{2}\left(x, y\right)'
     assert latex(mybeta(x)) == r"\beta{\left(x \right)}"
     assert latex(mybeta) == r"\beta"
 
@@ -312,38 +311,29 @@ def test_latex_functions():
 
     assert latex(factorial(k)) == r"k!"
     assert latex(factorial(-k)) == r"\left(- k\right)!"
-    assert latex(factorial(k)**2) == r"k!^{2}"
 
     assert latex(subfactorial(k)) == r"!k"
     assert latex(subfactorial(-k)) == r"!\left(- k\right)"
-    assert latex(subfactorial(k)**2) == r"\left(!k\right)^{2}"
 
     assert latex(factorial2(k)) == r"k!!"
     assert latex(factorial2(-k)) == r"\left(- k\right)!!"
-    assert latex(factorial2(k)**2) == r"k!!^{2}"
 
     assert latex(binomial(2, k)) == r"{\binom{2}{k}}"
-    assert latex(binomial(2, k)**2) == r"{\binom{2}{k}}^{2}"
 
     assert latex(FallingFactorial(3, k)) == r"{\left(3\right)}_{k}"
     assert latex(RisingFactorial(3, k)) == r"{3}^{\left(k\right)}"
 
     assert latex(floor(x)) == r"\left\lfloor{x}\right\rfloor"
     assert latex(ceiling(x)) == r"\left\lceil{x}\right\rceil"
-    assert latex(floor(x)**2) == r"\left\lfloor{x}\right\rfloor^{2}"
-    assert latex(ceiling(x)**2) == r"\left\lceil{x}\right\rceil^{2}"
     assert latex(Min(x, 2, x**3)) == r"\min\left(2, x, x^{3}\right)"
     assert latex(Min(x, y)**2) == r"\min\left(x, y\right)^{2}"
     assert latex(Max(x, 2, x**3)) == r"\max\left(2, x, x^{3}\right)"
     assert latex(Max(x, y)**2) == r"\max\left(x, y\right)^{2}"
     assert latex(Abs(x)) == r"\left|{x}\right|"
-    assert latex(Abs(x)**2) == r"\left|{x}\right|^{2}"
     assert latex(re(x)) == r"\Re{\left(x\right)}"
     assert latex(re(x + y)) == r"\Re{\left(x\right)} + \Re{\left(y\right)}"
     assert latex(im(x)) == r"\Im{x}"
     assert latex(conjugate(x)) == r"\overline{x}"
-    assert latex(conjugate(x)**2) == r"\overline{x}^{2}"
-    assert latex(conjugate(x**2)) == r"\overline{x}^{2}"
     assert latex(gamma(x)) == r"\Gamma\left(x\right)"
     w = Wild('w')
     assert latex(gamma(w)) == r"\Gamma\left(w\right)"
@@ -356,9 +346,7 @@ def test_latex_functions():
     assert latex(Order(x, x, y)) == r"O\left(x; \left( x, \  y\right)\rightarrow \left( 0, \  0\right)\right)"
     assert latex(Order(x, (x, oo), (y, oo))) == r"O\left(x; \left( x, \  y\right)\rightarrow \left( \infty, \  \infty\right)\right)"
     assert latex(lowergamma(x, y)) == r'\gamma\left(x, y\right)'
-    assert latex(lowergamma(x, y)**2) == r'\gamma^{2}\left(x, y\right)'
     assert latex(uppergamma(x, y)) == r'\Gamma\left(x, y\right)'
-    assert latex(uppergamma(x, y)**2) == r'\Gamma^{2}\left(x, y\right)'
 
     assert latex(cot(x)) == r'\cot{\left(x \right)}'
     assert latex(coth(x)) == r'\coth{\left(x \right)}'
@@ -396,7 +384,6 @@ def test_latex_functions():
 
     assert latex(Ei(x)) == r'\operatorname{Ei}{\left(x \right)}'
     assert latex(Ei(x)**2) == r'\operatorname{Ei}^{2}{\left(x \right)}'
-    assert latex(expint(x, y)) == r'\operatorname{E}_{x}\left(y\right)'
     assert latex(expint(x, y)**2) == r'\operatorname{E}_{x}^{2}\left(y\right)'
     assert latex(Shi(x)**2) == r'\operatorname{Shi}^{2}{\left(x \right)}'
     assert latex(Si(x)**2) == r'\operatorname{Si}^{2}{\left(x \right)}'
@@ -761,11 +748,6 @@ def test_latex_union():
         r"\left\{1, 2\right\} \cup \left[3, 4\right]"
 
 
-def test_latex_intersection():
-    assert latex(Intersection(Interval(0, 1), Interval(x, y))) == \
-        r"\left[0, 1\right] \cap \left[x, y\right]"
-
-
 def test_latex_symmetric_difference():
     assert latex(SymmetricDifference(Interval(2,5), Interval(4,7), \
         evaluate = False)) == r'\left[2, 5\right] \triangle \left[4, 7\right]'
@@ -946,7 +928,6 @@ def test_latex_KroneckerDelta():
     assert latex(KroneckerDelta(x, y + 1)) == r"\delta_{x, y + 1}"
     # issue 6578
     assert latex(KroneckerDelta(x + 1, y)) == r"\delta_{y, x + 1}"
-    assert latex(Pow(KroneckerDelta(x, y), 2, evaluate=False)) == r"\left(\delta_{x y}\right)^{2}"
 
 
 def test_latex_LeviCivita():
@@ -966,7 +947,6 @@ def test_mode():
         expr, mode='equation*') == '\\begin{equation*}x + y\\end{equation*}'
     assert latex(
         expr, mode='equation') == '\\begin{equation}x + y\\end{equation}'
-    raises(ValueError, lambda : latex(expr, mode='foo'))
 
 
 def test_latex_Piecewise():
@@ -984,8 +964,6 @@ def test_latex_Piecewise():
     assert latex(p) == s
     assert latex(A*p) == r"A \left(%s\right)" % s
     assert latex(p*A) == r"\left(%s\right) A" % s
-    assert latex(Piecewise((x, x < 1), (x**2, x <2))) == '\\begin{cases} x & ' \
-        '\\text{for}\\: x < 1 \\\\x^{2} & \\text{for}\\: x < 2 \\end{cases}'
 
 
 def test_latex_Matrix():
@@ -1124,12 +1102,12 @@ def test_noncommutative():
 
 
 def test_latex_order():
-    expr = x**3 + x**2*y + y**4 + 3*x*y**3
+    expr = x**3 + x**2*y + 3*x*y**3 + y**4
 
     assert latex(expr, order='lex') == "x^{3} + x^{2} y + 3 x y^{3} + y^{4}"
     assert latex(
         expr, order='rev-lex') == "y^{4} + 3 x y^{3} + x^{2} y + x^{3}"
-    assert latex(expr, order='none') == "x^{3} + y^{4} + y x^{2} + 3 x y^{3}"
+
 
 def test_latex_Lambda():
     assert latex(Lambda(x, x + 1)) == \
@@ -1458,11 +1436,6 @@ def test_ZeroMatrix():
     assert latex(ZeroMatrix(1, 1)) == r"\mathbb{0}"
 
 
-def test_Identity():
-    from sympy import Identity
-    assert latex(Identity(1)) == r"\mathbb{I}"
-
-
 def test_boolean_args_order():
     syms = symbols('a:f')
 
@@ -1691,9 +1664,6 @@ def test_Mul():
 def test_Pow():
     e = Pow(2, 2, evaluate=False)
     assert latex(e)  == r'2^{2}'
-    assert latex(x**(Rational(-1,3))) == r'\frac{1}{\sqrt[3]{x}}'
-    x2 = Symbol(r'x^2')
-    assert latex(x2**2) == r'\left(x^{2}\right)^{2}'
 
 
 def test_issue_7180():
@@ -1795,12 +1765,6 @@ def test_MatrixSymbol_printing():
     assert latex(-A*B - A*B*C - B) == r"- A B - A B C - B"
 
 
-def test_KroneckerProduct_printing():
-    A = MatrixSymbol('A', 3, 3)
-    B = MatrixSymbol('B', 2, 2)
-    assert latex(KroneckerProduct(A, B)) == r'A \otimes B'
-
-
 def test_Quaternion_latex_printing():
     q = Quaternion(x, y, z, t)
     assert latex(q) == "x + y i + z j + t k"
diff --git a/sympy/printing/tests/test_mathml.py b/sympy/printing/tests/test_mathml.py
index bf1d4cc238..74e09fb2b5 100644
--- a/sympy/printing/tests/test_mathml.py
+++ b/sympy/printing/tests/test_mathml.py
@@ -1,13 +1,13 @@
 from sympy import diff, Integral, Limit, sin, Symbol, Integer, Rational, cos, \
     tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, E, I, oo, \
     pi, GoldenRatio, EulerGamma, Sum, Eq, Ne, Ge, Lt, Float, Matrix, Basic, S, \
-    MatrixSymbol, Function, Derivative, log, true, false, Range, Min, Max, \
-    Lambda, IndexedBase, symbols
+    MatrixSymbol, Function, Derivative, log, Lambda
 from sympy.core.containers import Tuple
-from sympy.functions.combinatorial.factorials import factorial, factorial2, binomial
 from sympy.functions.elementary.complexes import re, im, Abs, conjugate
-from sympy.functions.elementary.exponential import exp
 from sympy.functions.elementary.integers import floor, ceiling
+from sympy.functions.elementary.exponential import exp
+from sympy.functions.combinatorial.factorials import factorial, factorial2, binomial
+from sympy.functions.elementary.complexes import conjugate
 from sympy.functions.special.zeta_functions import polylog, lerchphi
 from sympy.logic.boolalg import And, Or, Implies, Equivalent, Xor, Not
 from sympy.matrices.expressions.determinant import Determinant
@@ -16,6 +16,7 @@
 from sympy.sets.sets import FiniteSet, Union, Intersection, Complement, SymmetricDifference
 from sympy.stats.rv import RandomSymbol
 from sympy.sets.sets import Interval
+from sympy.stats.rv import RandomSymbol
 from sympy.utilities.pytest import raises
 
 x = Symbol('x')
@@ -1126,36 +1127,6 @@ def test_print_conjugate():
     assert mpp.doprint(conjugate(x + 1)) == '<mrow><menclose notation="top"><mi>x</mi></menclose><mo>+</mo><mn>1</mn></mrow>'
 
 
-def test_mathml_builtins():
-    assert mpp.doprint(None) == '<mi>None</mi>'
-    assert mpp.doprint(true) == '<mi>True</mi>'
-    assert mpp.doprint(false) == '<mi>False</mi>'
-
-
-def test_mathml_Range():
-    assert mpp.doprint(Range(1, 51)) == \
-        '<mfenced close="}" open="{"><mn>1</mn><mn>2</mn><mi>&#8230;</mi><mn>50</mn></mfenced>'
-    assert mpp.doprint(Range(1, 4)) == '<mfenced close="}" open="{"><mn>1</mn><mn>2</mn><mn>3</mn></mfenced>'
-    assert mpp.doprint(Range(0, 3, 1)) == '<mfenced close="}" open="{"><mn>0</mn><mn>1</mn><mn>2</mn></mfenced>'
-    assert mpp.doprint(Range(0, 30, 1)) == '<mfenced close="}" open="{"><mn>0</mn><mn>1</mn><mi>&#8230;</mi><mn>29</mn></mfenced>'
-    assert mpp.doprint(Range(30, 1, -1)) == '<mfenced close="}" open="{"><mn>30</mn><mn>29</mn><mi>&#8230;</mi><mn>2</mn></mfenced>'
-    assert mpp.doprint(Range(0, oo, 2)) == '<mfenced close="}" open="{"><mn>0</mn><mn>2</mn><mi>&#8230;</mi><mi>&#x221E;</mi></mfenced>'
-    assert mpp.doprint(Range(oo, -2, -2)) == '<mfenced close="}" open="{"><mi>&#x221E;</mi><mi>&#8230;</mi><mn>2</mn><mn>0</mn></mfenced>'
-    assert mpp.doprint(Range(-2, -oo, -1)) == '<mfenced close="}" open="{"><mn>-2</mn><mn>-3</mn><mi>&#8230;</mi><mrow><mo>-</mo><mi>&#x221E;</mi></mrow></mfenced>'
-
-
-def test_print_exp():
-    assert mpp.doprint(exp(x)) == '<msup><mi>&ExponentialE;</mi><mi>x</mi></msup>'
-    assert mpp.doprint(exp(1) + exp(2)) == '<mrow><mi>&ExponentialE;</mi><mo>+</mo><msup><mi>&ExponentialE;</mi><mn>2</mn></msup></mrow>'
-
-
-def test_print_MinMax():
-    assert mpp.doprint(Min(x, y)) == '<mrow><mo>min</mo><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
-    assert mpp.doprint(Min(x, 2, x**3)) == '<mrow><mo>min</mo><mfenced><mn>2</mn><mi>x</mi><msup><mi>x</mi><mn>3</mn></msup></mfenced></mrow>'
-    assert mpp.doprint(Max(x, y)) == '<mrow><mo>max</mo><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
-    assert mpp.doprint(Max(x, 2, x**3)) == '<mrow><mo>max</mo><mfenced><mn>2</mn><mi>x</mi><msup><mi>x</mi><mn>3</mn></msup></mfenced></mrow>'
-
-
 def test_print_matrix_symbol():
     A = MatrixSymbol('A', 1, 2)
     assert mpp.doprint(A) == '<mi>A</mi>'
@@ -1168,17 +1139,3 @@ def test_print_random_symbol():
     R = RandomSymbol(Symbol('R'))
     assert mpp.doprint(R) == '<mi>R</mi>'
     assert mp.doprint(R) == '<ci>R</ci>'
-
-
-def test_print_IndexedBase():
-    a,b,c,d,e = symbols('a b c d e')
-    assert mathml(IndexedBase(a)[b],printer='presentation') == '<msub><mi>a</mi><mi>b</mi></msub>'
-    assert mathml(IndexedBase(a)[b,c,d],printer = 'presentation') == '<msub><mi>a</mi><mfenced><mi>b</mi><mi>c</mi><mi>d</mi></mfenced></msub>'
-    assert mathml(IndexedBase(a)[b]*IndexedBase(c)[d]*IndexedBase(e),printer = 'presentation') == '<mrow><msub><mi>a</mi><mi>b</mi></msub><mo>&InvisibleTimes;</mo><msub><mi>c</mi><mi>d</mi></msub><mo>&InvisibleTimes;</mo><mi>e</mi></mrow>'
-
-
-def test_print_Indexed():
-    a,b,c = symbols('a b c')
-    assert mathml(IndexedBase(a),printer = 'presentation') == '<mi>a</mi>'
-    assert mathml(IndexedBase(a/b),printer = 'presentation') == '<mrow><mfrac><mi>a</mi><mi>b</mi></mfrac></mrow>'
-    assert mathml(IndexedBase((a,b)),printer = 'presentation') == '<mrow><mfenced><mi>a</mi><mi>b</mi></mfenced></mrow>'
diff --git a/sympy/series/tests/test_fourier.py b/sympy/series/tests/test_fourier.py
index 10bbe97953..1d8c208292 100644
--- a/sympy/series/tests/test_fourier.py
+++ b/sympy/series/tests/test_fourier.py
@@ -134,17 +134,15 @@ def test_FourierSeries__add__sub():
 
 def test_FourierSeries_finite():
 
-    assert fourier_series(sin(x)).truncate(1) == sin(x)
+    assert fourier_series(sin(x)).truncate() == sin(x)
     # assert type(fourier_series(sin(x)*log(x))).truncate() == FourierSeries
     # assert type(fourier_series(sin(x**2+6))).truncate() == FourierSeries
     assert fourier_series(sin(x)*log(y)*exp(z),(x,pi,-pi)).truncate() == sin(x)*log(y)*exp(z)
-    assert fourier_series(sin(x)**6).truncate(oo) == -15*cos(2*x)/32 + 3*cos(4*x)/16 - cos(6*x)/32 \
+    assert fourier_series(sin(x)**6).truncate() == -15*cos(2*x)/32 + 3*cos(4*x)/16 - cos(6*x)/32 \
            + Rational(5, 16)
-    assert fourier_series(sin(x) ** 6).truncate() == -15 * cos(2 * x) / 32 + 3 * cos(4 * x) / 16 \
-           + Rational(5, 16)
-    assert fourier_series(sin(4*x+3) + cos(3*x+4)).truncate(oo) ==  -sin(4)*sin(3*x) + sin(4*x)*cos(3) \
+    assert fourier_series(sin(4*x+3) + cos(3*x+4)).truncate() ==  -sin(4)*sin(3*x) + sin(4*x)*cos(3) \
            + cos(4)*cos(3*x) + sin(3)*cos(4*x)
-    assert fourier_series(sin(x)+cos(x)*tan(x)).truncate(oo) == 2*sin(x)
-    assert fourier_series(cos(pi*x), (x, -1, 1)).truncate(oo) == cos(pi*x)
-    assert fourier_series(cos(3*pi*x + 4) - sin(4*pi*x)*log(pi*y) , (x, -1, 1)).truncate(oo) == -log(pi*y)*sin(4*pi*x)\
+    assert fourier_series(sin(x)+cos(x)*tan(x)).truncate() == 2*sin(x)
+    assert fourier_series(cos(pi*x), (x, -1, 1)).truncate() == cos(pi*x)
+    assert fourier_series(cos(3*pi*x + 4) - sin(4*pi*x)*log(pi*y) , (x, -1, 1)).truncate() == -log(pi*y)*sin(4*pi*x)\
            - sin(4)*sin(3*pi*x) + cos(4)*cos(3*pi*x)