Repository: sympy/sympy

Issue:
Wrong result from integrate
Reported on the mailing list:

```
Hello, I am clearly making a stupid mistake, but what?

Arc length calculation:

x = Symbol('x')
 
formula = 2 * x**2
 
d = diff(formula, x)
i = integrate(sqrt(1 + d**2), (x, 5.0, 10.0))


gives a result of 150.087

but changing the formula to this:

formula = 0.26666 * x**2

gives a result of zero. In fact any coefficient less than one gives a result of zero.
```

The problem seems to be in heurisch.

Discussion:

Patch:
diff --git a/sympy/integrals/heurisch.py b/sympy/integrals/heurisch.py
index 82ddcd6ef9..ffe74bed7c 100644
--- a/sympy/integrals/heurisch.py
+++ b/sympy/integrals/heurisch.py
@@ -559,7 +559,8 @@ def find_non_syms(expr):
         if solution is None:
             return None
         else:
-            solution = [ (k.as_expr(), v.as_expr()) for k, v in solution.items() ]
+            # If the ring is RR k.as_expr() will be 1.0*A
+            solution = [ (k.as_expr().as_coeff_Mul()[1], v.as_expr()) for k, v in solution.items() ]
             return candidate.subs(solution).subs(list(zip(coeffs, [S.Zero]*len(coeffs))))
 
     if not (F.free_symbols - set(V)):


Test patch:
diff --git a/sympy/integrals/tests/test_heurisch.py b/sympy/integrals/tests/test_heurisch.py
index c12380bbad..0a6a8b24e4 100644
--- a/sympy/integrals/tests/test_heurisch.py
+++ b/sympy/integrals/tests/test_heurisch.py
@@ -277,6 +277,12 @@ def omega(x):
 
     assert heurisch(f, x) == g
 
+def test_RR():
+    # Make sure the algorithm does the right thing if the ring is RR. See
+    # issue 8685.
+    assert heurisch(sqrt(1 + 0.25*x**2), x, hints=[]) == \
+        0.5*x*sqrt(0.25*x**2 + 1) + 1.0*asinh(0.5*x)
+
 # TODO: convert the rest of PMINT tests:
 # Airy functions
 # f = (x - AiryAi(x)*AiryAi(1, x)) / (x**2 - AiryAi(x)**2)