Repository: sympy/sympy

Issue:
Rademacher Distribution not added to sympy docs
Description of sympy.stats.Rademacher from https://github.com/sympy/sympy/blob/master/sympy/stats/frv_types.py#Rademacher is not added to the docs https://docs.sympy.org/dev/modules/stats

Discussion:

Patch:
diff --git a/doc/src/modules/stats.rst b/doc/src/modules/stats.rst
index 7b301a4ba5..90f1f189cd 100644
--- a/doc/src/modules/stats.rst
+++ b/doc/src/modules/stats.rst
@@ -15,11 +15,16 @@ Finite Types
 .. autofunction:: Binomial
 .. autofunction:: Hypergeometric
 .. autofunction:: FiniteRV
+.. autofunction:: Rademacher
 
 Discrete Types
 -----------------
 .. autofunction:: Geometric
 .. autofunction:: Poisson
+.. autofunction:: Logarithmic
+.. autofunction:: NegativeBinomial
+.. autofunction:: YuleSimon
+.. autofunction:: Zeta
 
 Continuous Types
 -------------------
diff --git a/sympy/ntheory/factor_.py b/sympy/ntheory/factor_.py
index 66ed5df15c..611b6fb082 100644
--- a/sympy/ntheory/factor_.py
+++ b/sympy/ntheory/factor_.py
@@ -19,9 +19,8 @@
 from .primetest import isprime
 from .generate import sieve, primerange, nextprime
 
-small_trailing = [0] * 256
-for j in range(1,8):
-    small_trailing[1<<j::1<<(j+1)] = [j] * (1<<(7-j))
+small_trailing = [i and max(int(not i % 2**j) and j for j in range(1, 8))
+    for i in range(256)]
 
 
 def smoothness(n):
diff --git a/sympy/printing/mathml.py b/sympy/printing/mathml.py
index bb6afe3b2a..821a3ca384 100644
--- a/sympy/printing/mathml.py
+++ b/sympy/printing/mathml.py
@@ -464,29 +464,6 @@ class MathMLPresentationPrinter(MathMLPrinterBase):
     """
     printmethod = "_mathml_presentation"
 
-    def __init__(self, settings=None):
-        MathMLPrinterBase.__init__(self, settings)
-
-        _default_settings = {
-            "fold_frac_powers": False,
-            "fold_func_brackets": False,
-            "fold_short_frac": None,
-            "inv_trig_style": "abbreviated",
-            "ln_notation": False,
-            "long_frac_ratio": None,
-            "mat_delim": "[",
-            "mat_symbol_style": "plain",
-            "mul_symbol": None,
-            "root_notation": True,
-            "symbol_names": {},
-            "order": None
-        }
-
-        self._settings = _default_settings
-
-        if settings is not None:
-            self._settings.update(settings)
-
     def mathml_tag(self, e):
         """Returns the MathML tag for an expression."""
         translate = {
diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index aba709209d..6e72b573f5 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -14,7 +14,6 @@
 
 from __future__ import print_function, division
 
-from sympy import divisors
 from sympy.core.compatibility import (iterable, is_sequence, ordered,
     default_sort_key, range)
 from sympy.core.sympify import sympify
@@ -23,12 +22,11 @@
 from sympy.core.exprtools import factor_terms
 from sympy.core.function import (expand_mul, expand_multinomial, expand_log,
                           Derivative, AppliedUndef, UndefinedFunction, nfloat,
-                          Function, expand_power_exp, Lambda, _mexpand, expand)
+                          Function, expand_power_exp, Lambda, _mexpand)
 from sympy.integrals.integrals import Integral
-from sympy.core.numbers import ilcm, Float, Rational
+from sympy.core.numbers import ilcm, Float
 from sympy.core.relational import Relational, Ge, _canonical
 from sympy.core.logic import fuzzy_not, fuzzy_and
-from sympy.core.power import integer_log
 from sympy.logic.boolalg import And, Or, BooleanAtom
 from sympy.core.basic import preorder_traversal
 
@@ -37,7 +35,7 @@
 from sympy.functions.elementary.trigonometric import (TrigonometricFunction,
                                                       HyperbolicFunction)
 from sympy.simplify import (simplify, collect, powsimp, posify, powdenest,
-                            nsimplify, denom, logcombine, sqrtdenest, fraction)
+                            nsimplify, denom, logcombine)
 from sympy.simplify.sqrtdenest import sqrt_depth
 from sympy.simplify.fu import TR1
 from sympy.matrices import Matrix, zeros
@@ -2653,87 +2651,24 @@ def _tsolve(eq, sym, **flags):
             if lhs.exp.is_Integer:
                 if lhs - rhs != eq:
                     return _solve(lhs - rhs, sym, **flags)
-
-            if sym not in lhs.exp.free_symbols:
+            elif sym not in lhs.exp.free_symbols:
                 return _solve(lhs.base - rhs**(1/lhs.exp), sym, **flags)
-
-            # _tsolve calls this with Dummy before passing the actual number in.
-            if any(t.is_Dummy for t in rhs.free_symbols):
-                raise NotImplementedError # _tsolve will call here again...
-
-            # a ** g(x) == 0
-            if not rhs:
+            elif not rhs and sym in lhs.exp.free_symbols:
                 # f(x)**g(x) only has solutions where f(x) == 0 and g(x) != 0 at
                 # the same place
                 sol_base = _solve(lhs.base, sym, **flags)
-                return [s for s in sol_base if lhs.exp.subs(sym, s) != 0]
-
-            # a ** g(x) == b
-            if not lhs.base.has(sym):
-                if lhs.base == 0:
-                    return _solve(lhs.exp, sym, **flags) if rhs != 0 else []
-
-                # Gets most solutions...
-                if lhs.base == rhs.as_base_exp()[0]:
-                    # handles case when bases are equal
-                    sol = _solve(lhs.exp - rhs.as_base_exp()[1], sym, **flags)
-                else:
-                    # handles cases when bases are not equal and exp
-                    # may or may not be equal
-                    sol = _solve(exp(log(lhs.base)*lhs.exp)-exp(log(rhs)), sym, **flags)
-
-                # Check for duplicate solutions
-                def equal(expr1, expr2):
-                    return expr1.equals(expr2) or nsimplify(expr1) == nsimplify(expr2)
-
-                # Guess a rational exponent
-                e_rat = nsimplify(log(abs(rhs))/log(abs(lhs.base)))
-                e_rat = simplify(posify(e_rat)[0])
-                n, d = fraction(e_rat)
-                if expand(lhs.base**n - rhs**d) == 0:
-                    sol = [s for s in sol if not equal(lhs.exp.subs(sym, s), e_rat)]
-                    sol.extend(_solve(lhs.exp - e_rat, sym, **flags))
-
-                return list(ordered(set(sol)))
-
-            # f(x) ** g(x) == c
+                if not sol_base:
+                    return sol_base  # no solutions to remove so return now
+                return list(ordered(set(sol_base) - set(
+                    _solve(lhs.exp, sym, **flags))))
+            elif (rhs is not S.Zero and
+                        lhs.base.is_positive and
+                        lhs.exp.is_real):
+                return _solve(lhs.exp*log(lhs.base) - log(rhs), sym, **flags)
+            elif lhs.base == 0 and rhs == 1:
+                return _solve(lhs.exp, sym, **flags)
             else:
-                sol = []
-                logform = lhs.exp*log(lhs.base) - log(rhs)
-                if logform != lhs - rhs:
-                    try:
-                        sol.extend(_solve(logform, sym, **flags))
-                    except NotImplementedError:
-                        pass
-
-                # Collect possible solutions and check with subtitution later.
-                check = []
-                if rhs == 1:
-                    # f(x) ** g(x) = 1 -- g(x)=0 or f(x)=+-1
-                    check.extend(_solve(lhs.exp, sym, **flags))
-                    check.extend(_solve(lhs.base - 1, sym, **flags))
-                    check.extend(_solve(lhs.base + 1, sym, **flags))
-                elif rhs.is_Rational:
-                    for d in (i for i in divisors(abs(rhs.p)) if i != 1):
-                        e, t = integer_log(rhs.p, d)
-                        if not t:
-                            continue  # rhs.p != d**b
-                        for s in divisors(abs(rhs.q)):
-                            if s**e== rhs.q:
-                                r = Rational(d, s)
-                                check.extend(_solve(lhs.base - r, sym, **flags))
-                                check.extend(_solve(lhs.base + r, sym, **flags))
-                                check.extend(_solve(lhs.exp - e, sym, **flags))
-                elif rhs.is_irrational:
-                    b_l, e_l = lhs.base.as_base_exp()
-                    n, d = e_l*lhs.exp.as_numer_denom()
-                    b, e = sqrtdenest(rhs).as_base_exp()
-                    check = [sqrtdenest(i) for i in (_solve(lhs.base - b, sym, **flags))]
-                    check.extend([sqrtdenest(i) for i in (_solve(lhs.exp - e, sym, **flags))])
-                    if (e_l*d) !=1 :
-                        check.extend(_solve(b_l**(n) - rhs**(e_l*d), sym, **flags))
-                sol.extend(s for s in check if eq.subs(sym, s).equals(0))
-                return list(ordered(set(sol)))
+                raise NotImplementedError
 
         elif lhs.is_Mul and rhs.is_positive:
             llhs = expand_log(log(lhs))
@@ -2779,12 +2714,7 @@ def equal(expr1, expr2):
             try:
                 poly = lhs.as_poly()
                 g = _filtered_gens(poly, sym)
-                sols = _solve_lambert(lhs - rhs, sym, g)
-                for n, s in enumerate(sols):
-                    ns = nsimplify(s)
-                    if ns != s and eq.subs(sym, ns).equals(0):
-                        sols[n] = ns
-                return sols
+                return _solve_lambert(lhs - rhs, sym, g)
             except NotImplementedError:
                 # maybe it's a convoluted function
                 if len(g) == 2:
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index ee7d298cad..5da01c2e62 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -2803,7 +2803,6 @@ def _handle_positive_dimensional(polys, symbols, denominators):
         new_system, symbols, result, [],
         denominators)
     return result
-
 # end of def _handle_positive_dimensional()
 
 
@@ -3008,7 +3007,6 @@ def nonlinsolve(system, *symbols):
 
     """
     from sympy.polys.polytools import is_zero_dimensional
-    from sympy.polys import RR
 
     if not system:
         return S.EmptySet
@@ -3053,11 +3051,7 @@ def nonlinsolve(system, *symbols):
                 return result
 
         # positive dimensional system
-        res = _handle_positive_dimensional(polys, symbols, denominators)
-        if isinstance(res, EmptySet) and any(not p.domain.is_Exact for p in polys):
-            raise NotImplementedError("Equation not in exact domain. Try converting to rational")
-        else:
-            return res
+        return _handle_positive_dimensional(polys, symbols, denominators)
 
     else:
         # If all the equations are not polynomial.
diff --git a/sympy/stats/frv_types.py b/sympy/stats/frv_types.py
index 703f99226f..b2ccb2b1e7 100644
--- a/sympy/stats/frv_types.py
+++ b/sympy/stats/frv_types.py
@@ -10,6 +10,7 @@
 Coin
 Binomial
 Hypergeometric
+Rademacher
 """
 
 from __future__ import print_function, division


Test patch:
diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index 623bff21a8..241b55b120 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -430,6 +430,8 @@ def test_solve_transcendental():
 
     # misc
     # make sure that the right variables is picked up in tsolve
+    raises(NotImplementedError, lambda: solve((exp(x) + 1)**x - 2))
+
     # shouldn't generate a GeneratorsNeeded error in _tsolve when the NaN is generated
     # for eq_down. Actual answers, as determined numerically are approx. +/- 0.83
     raises(NotImplementedError, lambda:
@@ -694,12 +696,9 @@ def test_checking():
 def test_issue_4671_4463_4467():
     assert solve((sqrt(x**2 - 1) - 2)) in ([sqrt(5), -sqrt(5)],
                                            [-sqrt(5), sqrt(5)])
-    # This is probably better than the form below but equivalent:
-    #assert solve((2**exp(y**2/x) + 2)/(x**2 + 15), y) == [-sqrt(x*log(1 + I*pi/log(2)))
-    #                                                    , sqrt(x*log(1 + I*pi/log(2)))]
     assert solve((2**exp(y**2/x) + 2)/(x**2 + 15), y) == [
-         sqrt(x*(-log(log(2)) + log(log(2) + I*pi))),
-        -sqrt(-x*(log(log(2)) - log(log(2) + I*pi)))]
+        -sqrt(x)*sqrt(-log(log(2)) + log(log(2) + I*pi)),
+        sqrt(x)*sqrt(-log(log(2)) + log(log(2) + I*pi))]
 
     C1, C2 = symbols('C1 C2')
     f = Function('f')
@@ -1594,12 +1593,16 @@ def test_lambert_multivariate():
     assert solve((log(x) + x).subs(x, x**2 + 1)) == [
         -I*sqrt(-LambertW(1) + 1), sqrt(-1 + LambertW(1))]
 
-    assert solve(x**3 - 3**x, x) == [3, -3*LambertW(-log(3)/3)/log(3)]
-    assert solve(x**2 - 2**x, x) == [2, 4]
-    assert solve(-x**2 + 2**x, x) == [2, 4]
-    assert solve(3**cos(x) - cos(x)**3) == [acos(3), acos(-3*LambertW(-log(3)/3)/log(3))]
+    assert solve(x**3 - 3**x, x) == [-3/log(3)*LambertW(-log(3)/3),
+                                     -3*LambertW(-log(3)/3, -1)/log(3)]
+    assert solve(x**2 - 2**x, x) == [2, -2*LambertW(-log(2)/2, -1)/log(2)]
+    assert solve(-x**2 + 2**x, x) == [2, -2*LambertW(-log(2)/2, -1)/log(2)]
+    assert solve(3**cos(x) - cos(x)**3) == [
+        acos(-3*LambertW(-log(3)/3)/log(3)),
+        acos(-3*LambertW(-log(3)/3, -1)/log(3))]
     assert set(solve(3*log(x) - x*log(3))) == set(  # 2.478... and 3
-        [3, -3*LambertW(-log(3)/3)/log(3)])
+        [-3*LambertW(-log(3)/3)/log(3),
+        -3*LambertW(-log(3)/3, -1)/log(3)])
     assert solve(LambertW(2*x) - y, x) == [y*exp(y)/2]
 
 
@@ -1994,33 +1997,3 @@ def test_issue_15415():
     assert solve(Eq(y + 3*x**2/2, y + 3*x), y) == []
     assert solve([Eq(y + 3*x**2/2, y + 3*x)], y) == []
     assert solve([Eq(y + 3*x**2/2, y + 3*x), Eq(x, 1)], y) == []
-
-def test_issue_15731():
-    # f(x)**g(x)=c
-    assert solve(Eq((x**2 - 7*x + 11)**(x**2 - 13*x + 42), 1)) == [2, 3, 4, 5, 6, 7]
-    assert solve((x)**(x + 4) - 4) == [-2]
-    assert solve((-x)**(-x + 4) - 4) == [2]
-    assert solve((x**2 - 6)**(x**2 - 2) - 4) == [-2, 2]
-    assert solve((x**2 - 2*x - 1)**(x**2 - 3) - 1/(1 - 2*sqrt(2))) == [sqrt(2)]
-    assert solve(x**(x + S.Half) - 4*sqrt(2)) == [S(2)]
-    assert solve((x**2 + 1)**x - 25) == [2]
-    assert solve(x**(2/x) - 2) == [2, 4]
-    assert solve((x/2)**(2/x) - sqrt(2)) == [4, 8]
-    assert solve(x**(x + S.Half) - S(9)/4) == [S(3)/2]
-    # a**g(x)=c
-    assert solve((-sqrt(sqrt(2)))**x - 2) == [4, log(2)/(log(2**(S(1)/4)) + I*pi)]
-    assert solve((sqrt(2))**x - sqrt(sqrt(2))) == [S(1)/2]
-    assert solve((-sqrt(2))**x + 2*(sqrt(2))) == [3,
-            (3*log(2)**2 + 4*pi**2 - 4*I*pi*log(2))/(log(2)**2 + 4*pi**2)]
-    assert solve((sqrt(2))**x - 2*(sqrt(2))) == [3]
-    assert solve(I**x + 1) == [2]
-    assert solve((1 + I)**x - 2*I) == [2]
-    assert solve((sqrt(2) + sqrt(3))**x - (2*sqrt(6) + 5)**(S(1)/3)) == [S(2)/3]
-    # bases of both sides are equal
-    b = Symbol('b')
-    assert solve(b**x - b**2, x) == [2]
-    assert solve(b**x - 1/b, x) == [-1]
-    assert solve(b**x - b, x) == [1]
-    b = Symbol('b', positive=True)
-    assert solve(b**x - b**2, x) == [2]
-    assert solve(b**x - 1/b, x) == [-1]
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index 981399bc8b..7dae3e9bdb 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -1224,7 +1224,6 @@ def test_nonlinsolve_abs():
 def test_raise_exception_nonlinsolve():
     raises(IndexError, lambda: nonlinsolve([x**2 -1], []))
     raises(ValueError, lambda: nonlinsolve([x**2 -1]))
-    raises(NotImplementedError, lambda: nonlinsolve([(x+y)**2 - 9, x**2 - y**2 -3/4], (x, y)))
 
 
 def test_trig_system():