Repository: sympy/sympy

Issue:
manualintegrate doesn't check domain of variables
Here is the program: 
```python 
>>> from sympy import * 
>>> from sympy.abc import x, y
>>> from sympy.integrals.manualintegrate import manualintegrate
>>> manualintegrate(x**y, x) 
x**(y + 1)/(y + 1)
>>> integrate(x**y, x) 
Integral(x**y, x)
Piecewise((log(x), Eq(y, -1)), (x**(y + 1)/(y + 1), True))
```


Discussion:

Patch:
diff --git a/doc/src/modules/core.rst b/doc/src/modules/core.rst
index bbfa52a6ab..b820bce4c9 100644
--- a/doc/src/modules/core.rst
+++ b/doc/src/modules/core.rst
@@ -58,11 +58,6 @@ Expr
 .. autoclass:: Expr
    :members:
 
-UnevaluatedExpr
----------------
-.. autoclass:: UnevaluatedExpr
-   :members:
-
 AtomicExpr
 ----------
 .. autoclass:: AtomicExpr
diff --git a/doc/src/tutorial/manipulation.rst b/doc/src/tutorial/manipulation.rst
index 7eeaf9b27a..62f09ab608 100644
--- a/doc/src/tutorial/manipulation.rst
+++ b/doc/src/tutorial/manipulation.rst
@@ -466,103 +466,6 @@ traversals easy.  We could have also written our algorithm as
     x
     y
 
-
-Prevent expression evaluation
-=============================
-
-There are generally two ways to prevent the evaluation, either pass an 
-``evaluate=False`` parameter while constructing the expression, or create
-an evaluation stopper by wrapping the expression with ``UnevaluatedExpr``.
-
-For example:
-
-    >>> from sympy import Add
-    >>> from sympy.abc import x, y, z
-    >>> x + x
-    2*x
-    >>> Add(x, x)
-    2*x
-    >>> Add(x, x, evaluate=False)
-    x + x
-
-If you don't remember the class corresponding to the expression you
-want to build (operator overloading usually assumes ``evaluate=True``),
-just use ``sympify`` and pass a string:
-
-    >>> from sympy import sympify
-    >>> sympify("x + x", evaluate=False)
-    x + x
-
-Note that ``evaluate=False`` won't prevent future evaluation in later
-usages of the expression:
-
-    >>> expr = Add(x, x, evaluate=False)
-    >>> expr
-    x + x
-    >>> expr + x
-    3*x
-
-That's why the class ``UnevaluatedExpr`` comes handy.
-``UnevaluatedExpr`` is a method provided by SymPy which lets the user keep
-an expression unevaluated. By *unevaluated* it is meant that the value
-inside of it will not interact with the expressions outside of it to give
-simplified outputs. For example:
-
-    >>> from sympy import UnevaluatedExpr
-    >>> expr = x + UnevaluatedExpr(x)
-    >>> expr
-    x + x
-    >>> x + expr
-    2*x + x
-
-The `x` remaining alone is the `x` wrapped by ``UnevaluatedExpr``.
-To release it:
-
-    >>> (x + expr).doit()
-    3*x
-
-Other examples:
-
-    >>> from sympy import *
-    >>> from sympy.abc import x, y, z
-    >>> uexpr = UnevaluatedExpr(S.One*5/7)*UnevaluatedExpr(S.One*3/4)
-    >>> uexpr
-    (5/7)*(3/4)
-    >>> x*UnevaluatedExpr(1/x)
-    x*1/x
-
-A point to be noted is that  ``UnevaluatedExpr`` cannot prevent the
-evaluation of an expression which is given as argument. For example:
-
-    >>> expr1 = UnevaluatedExpr(x + x)
-    >>> expr1
-    2*x
-    >>> expr2 = sympify('x + x', evaluate=False)
-    >>> expr2
-    x + x
-
-Remember that ``expr2`` will be evaluated if included into another
-expression. Combine both of the methods to prevent both inside and outside
-evaluations:
-
-    >>> UnevaluatedExpr(sympify("x + x", evaluate=False)) + y
-    y + x + x
-
-``UnevalutedExpr`` is supported by SymPy printers and can be used to print the
-result in different output forms. For example
-
-    >>> from sympy import latex
-    >>> uexpr = UnevaluatedExpr(S.One*5/7)*UnevaluatedExpr(S.One*3/4)
-    >>> print(latex(uexpr))
-    \frac{5}{7} \frac{3}{4}
-
-In order to release the expression and get the evaluated LaTeX form,
-just use ``.doit()``:
-
-    >>> print(latex(uexpr.doit()))
-    \frac{15}{28}
-
-
 .. rubric:: Footnotes
 
 .. [#symbols-fn] We have been using ``symbols`` instead of ``Symbol`` because it
diff --git a/sympy/calculus/finite_diff.py b/sympy/calculus/finite_diff.py
index 0c7fa606ef..d9cfbb1eab 100644
--- a/sympy/calculus/finite_diff.py
+++ b/sympy/calculus/finite_diff.py
@@ -38,8 +38,8 @@ def finite_diff_weights(order, x_list, x0=S.One):
         0 corresponds to interpolation.
     x_list: sequence
         Sequence of (unique) values for the independent variable.
-        It is useful (but not necessary) to order ``x_list`` from
-        nearest to furthest from ``x0``; see examples below.
+        It is usefull (but not necessary) to order ``x_list`` from
+        nearest to farest from ``x0``; see examples below.
     x0: Number or Symbol
         Root or value of the independent variable for which the finite
         difference weights should be generated. Default is ``S.One``.
diff --git a/sympy/integrals/manualintegrate.py b/sympy/integrals/manualintegrate.py
index 8eca0ca4b9..7379d97974 100644
--- a/sympy/integrals/manualintegrate.py
+++ b/sympy/integrals/manualintegrate.py
@@ -1024,7 +1024,8 @@ def eval_constanttimes(constant, other, substep, integrand, symbol):
 
 @evaluates(PowerRule)
 def eval_power(base, exp, integrand, symbol):
-    return (base ** (exp + 1)) / (exp + 1)
+    return sympy.Piecewise((sympy.log(base), sympy.Eq(exp, -1)),
+        ((base**(exp + 1))/(exp + 1), True))
 
 @evaluates(ExpRule)
 def eval_exp(base, exp, integrand, symbol):
diff --git a/sympy/ntheory/factor_.py b/sympy/ntheory/factor_.py
index 32b91c99be..67c2c18ce7 100644
--- a/sympy/ntheory/factor_.py
+++ b/sympy/ntheory/factor_.py
@@ -803,7 +803,7 @@ def done(n, d):
 
 
 def factorint(n, limit=None, use_trial=True, use_rho=True, use_pm1=True,
-              verbose=False, visual=None, multiple=False):
+              verbose=False, visual=None):
     r"""
     Given a positive integer ``n``, ``factorint(n)`` returns a dict containing
     the prime factors of ``n`` as keys and their respective multiplicities
@@ -850,14 +850,6 @@ def factorint(n, limit=None, use_trial=True, use_rho=True, use_pm1=True,
     >>> factorint(3*101**7, limit=5)
     {3: 1, 101: 7}
 
-    List of Factors:
-
-    If ``multiple`` is set to ``True`` then a list containing the
-    prime factors including multiplicities is returned.
-
-    >>> factorint(24, multiple=True)
-    [2, 2, 2, 3]
-
     Visual Factorization:
 
     If ``visual`` is set to ``True``, then it will return a visual
@@ -950,14 +942,6 @@ def factorint(n, limit=None, use_trial=True, use_rho=True, use_pm1=True,
     smoothness, smoothness_p, divisors
 
     """
-    if multiple:
-        fac = factorint(n, limit=limit, use_trial=use_trial,
-                           use_rho=use_rho, use_pm1=use_pm1,
-                           verbose=verbose, visual=False, multiple=False)
-        factorlist = sum(([p] * fac[p] if fac[p] > 0 else [S(1)/p]*(-1*fac[p])
-                               for p in sorted(fac)), [])
-        return factorlist
-
     factordict = {}
     if visual and not isinstance(n, Mul) and not isinstance(n, dict):
         factordict = factorint(n, limit=limit, use_trial=use_trial,
@@ -1188,7 +1172,7 @@ def factorint(n, limit=None, use_trial=True, use_rho=True, use_pm1=True,
 
 
 def factorrat(rat, limit=None, use_trial=True, use_rho=True, use_pm1=True,
-              verbose=False, visual=None, multiple=False):
+              verbose=False, visual=None):
     r"""
     Given a Rational ``r``, ``factorrat(r)`` returns a dict containing
     the prime factors of ``r`` as keys and their respective multiplicities
@@ -1209,21 +1193,9 @@ def factorrat(rat, limit=None, use_trial=True, use_rho=True, use_pm1=True,
         - ``use_rho``: Toggle use of Pollard's rho method
         - ``use_pm1``: Toggle use of Pollard's p-1 method
         - ``verbose``: Toggle detailed printing of progress
-        - ``multiple``: Toggle returning a list of factors or dict
         - ``visual``: Toggle product form of output
     """
     from collections import defaultdict
-    if multiple:
-        fac = factorrat(rat, limit=limit, use_trial=use_trial,
-                  use_rho=use_rho, use_pm1=use_pm1,
-                  verbose=verbose, visual=False,multiple=False)
-        factorlist = sum(([p] * fac[p] if fac[p] > 0 else [S(1)/p]*(-1*fac[p])
-                               for p, _ in sorted(fac.items(),
-                                                        key=lambda elem: elem[0]
-                                                        if elem[1] > 0
-                                                        else 1/elem[0])), [])
-        return factorlist
-
     f = factorint(rat.p, limit=limit, use_trial=use_trial,
                   use_rho=use_rho, use_pm1=use_pm1,
                   verbose=verbose).copy()
diff --git a/sympy/solvers/bivariate.py b/sympy/solvers/bivariate.py
index 8aceea236b..91e6c55d2f 100644
--- a/sympy/solvers/bivariate.py
+++ b/sympy/solvers/bivariate.py
@@ -47,9 +47,6 @@ def _mostfunc(lhs, func, X=None):
     ``func`` can be a function (exp, log, etc...) or any other SymPy object,
     like Pow.
 
-    If ``X`` is not ``None``, then the function returns the term composed with the
-    most ``func`` having the specified variable.
-
     Examples
     ========
 
@@ -59,8 +56,8 @@ def _mostfunc(lhs, func, X=None):
     >>> from sympy.abc import x, y
     >>> _mostfunc(exp(x) + exp(exp(x) + 2), exp)
     exp(exp(x) + 2)
-    >>> _mostfunc(exp(x) + exp(exp(y) + 2), exp)
-    exp(exp(y) + 2)
+    >>> _mostfunc(exp(x) + exp(exp(y) + 2), exp, x)
+    exp(x)
     >>> _mostfunc(exp(x) + exp(exp(y) + 2), exp, x)
     exp(x)
     >>> _mostfunc(x, exp, x) is None


Test patch:
diff --git a/sympy/integrals/tests/test_manual.py b/sympy/integrals/tests/test_manual.py
index 5f2ad181dd..3dc18568e7 100644
--- a/sympy/integrals/tests/test_manual.py
+++ b/sympy/integrals/tests/test_manual.py
@@ -217,6 +217,11 @@ def test_issue_6799():
     assert not integrate(integrand, limits).has(Dummy)
 
 
+def test_issue_12251():
+    assert manualintegrate(x**y, x) == Piecewise(
+        (log(x), Eq(y, -1)), (x**(y + 1)/(y + 1), True))
+
+
 def test_issue_3796():
     assert manualintegrate(diff(exp(x + x**2)), x) == exp(x + x**2)
     assert integrate(x * exp(x**4), x, risch=False) == -I*sqrt(pi)*erf(I*x**2)/4
diff --git a/sympy/ntheory/tests/test_factor_.py b/sympy/ntheory/tests/test_factor_.py
index 7b4c4fbd56..aed3766bab 100644
--- a/sympy/ntheory/tests/test_factor_.py
+++ b/sympy/ntheory/tests/test_factor_.py
@@ -154,20 +154,6 @@ def test_factorint():
     assert factorint(5951757) == {3: 1, 7: 1, 29: 2, 337: 1}
     assert factorint(64015937) == {7993: 1, 8009: 1}
     assert factorint(2**(2**6) + 1) == {274177: 1, 67280421310721: 1}
-
-    assert factorint(0, multiple=True) == [0]
-    assert factorint(1, multiple=True) == []
-    assert factorint(-1, multiple=True) == [-1]
-    assert factorint(-2, multiple=True) == [-1, 2]
-    assert factorint(-16, multiple=True) == [-1, 2, 2, 2, 2]
-    assert factorint(2, multiple=True) == [2]
-    assert factorint(24, multiple=True) == [2, 2, 2, 3]
-    assert factorint(126, multiple=True) == [2, 3, 3, 7]
-    assert factorint(123456, multiple=True) == [2, 2, 2, 2, 2, 2, 3, 643]
-    assert factorint(5951757, multiple=True) == [3, 7, 29, 29, 337]
-    assert factorint(64015937, multiple=True) == [7993, 8009]
-    assert factorint(2**(2**6) + 1, multiple=True) == [274177, 67280421310721]
-
     assert multiproduct(factorint(fac(200))) == fac(200)
     for b, e in factorint(fac(150)).items():
         assert e == fac_multiplicity(150, b)
@@ -438,13 +424,6 @@ def test_factorrat():
     assert str(factorrat(S(25)/14, visual=True)) == '5**2/(2*7)'
     assert str(factorrat(S(-25)/14/9, visual=True)) == '-5**2/(2*3**2*7)'
 
-    assert factorrat(S(12)/1, multiple=True) == [2, 2, 3]
-    assert factorrat(S(1)/1, multiple=True) == []
-    assert factorrat(S(25)/14, multiple=True) == [1/7, 1/2, 5, 5]
-    assert factorrat(S(12)/1, multiple=True) == [2, 2, 3]
-    assert factorrat(S(-25)/14/9, multiple=True) == \
-        [-1, 1/7, 1/3, 1/3, 1/2, 5, 5]
-
 
 def test_visual_io():
     sm = smoothness_p