Repository: sympy/sympy

Issue:
Error in handling reciprocal square root in integral containing Fresnel functions
Transferring this from my [stackoverflow question](https://stackoverflow.com/questions/76114428/handling-reciprocals-of-negative-square-roots-in-sympy), as I was informed it is indeed a SymPy bug.

**Issue:** When performing the below integration, the result has a factor of `1/sqrt(b)` instead of `sqrt(1/b)` in the Fresnel integral arguments, which results in an additional factor of -1 when b < 0.
```
import sympy as sm
a,b,x = sm.symbols('a b x')
f = sm.integrate(sm.cos(a*x + 0.5*b*x**2),(x,0,1))

f.subs([(a,1),(b,1e-9)]).evalf()
# =0.84147
f.subs([(a,1),(b,-1e-9)]).evalf()
# =−0.84147
```

**Cause:** I am not familiar enough to know myself, but appears to be a problem with how the expression is constructed in the integration rule, or a simplification applied to it. As mentioned by SO users, these substitutions result in an expression with the expected behaviour:
```
f.subs(1/sqrt(b),sqrt(1/b))
f.subs(sqrt(1/b),1/sqrt(b))
```

(Python 3.11.2, SymPy 1.11.1)

Discussion:

Patch:
diff --git a/.mailmap b/.mailmap
index e8f54f8fa2..360035b931 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1229,6 +1229,7 @@ Sayandip Halder <sayandiph4@gmail.com> Sayandip <sayandiph4@gmail.com>
 Sean Ge <seange727@gmail.com>
 Sean P. Cornelius <spcornelius@gmail.com>
 Sean Vig <sean.v.775@gmail.com>
+Seb Tiburzio <sebtiburzio@gmail.com>
 Sebastian East <sebastianeast@ymail.com> sebastian-east <sebastianeast@ymail.com>
 Sebastian Koslowski <koslowski@kit.edu>
 Sebastian Krause <sebastian.krause@gmx.de>
diff --git a/sympy/integrals/manualintegrate.py b/sympy/integrals/manualintegrate.py
index 6bf1f36321..18dd3b6b6a 100644
--- a/sympy/integrals/manualintegrate.py
+++ b/sympy/integrals/manualintegrate.py
@@ -659,11 +659,11 @@ def eval(self) -> Expr:
         a, b, c, x = self.a, self.b, self.c, self.variable
         if a.is_extended_real:
             return Piecewise(
-                (sqrt(S.Pi/(-a))/2 * exp(c - b**2/(4*a)) *
+                (sqrt(S.Pi)/sqrt(-a)/2 * exp(c - b**2/(4*a)) *
                     erf((-2*a*x - b)/(2*sqrt(-a))), a < 0),
-                (sqrt(S.Pi/a)/2 * exp(c - b**2/(4*a)) *
+                (sqrt(S.Pi)/sqrt(a)/2 * exp(c - b**2/(4*a)) *
                     erfi((2*a*x + b)/(2*sqrt(a))), True))
-        return sqrt(S.Pi/a)/2 * exp(c - b**2/(4*a)) * \
+        return sqrt(S.Pi)/sqrt(a)/2 * exp(c - b**2/(4*a)) * \
                 erfi((2*a*x + b)/(2*sqrt(a)))
 
 
@@ -675,7 +675,7 @@ class FresnelCRule(AtomicRule):
 
     def eval(self) -> Expr:
         a, b, c, x = self.a, self.b, self.c, self.variable
-        return sqrt(S.Pi/(2*a)) * (
+        return sqrt(S.Pi)/sqrt(2*a) * (
             cos(b**2/(4*a) - c)*fresnelc((2*a*x + b)/sqrt(2*a*S.Pi)) +
             sin(b**2/(4*a) - c)*fresnels((2*a*x + b)/sqrt(2*a*S.Pi)))
 
@@ -688,7 +688,7 @@ class FresnelSRule(AtomicRule):
 
     def eval(self) -> Expr:
         a, b, c, x = self.a, self.b, self.c, self.variable
-        return sqrt(S.Pi/(2*a)) * (
+        return sqrt(S.Pi)/sqrt(2*a) * (
             cos(b**2/(4*a) - c)*fresnels((2*a*x + b)/sqrt(2*a*S.Pi)) -
             sin(b**2/(4*a) - c)*fresnelc((2*a*x + b)/sqrt(2*a*S.Pi)))
 


Test patch:
diff --git a/sympy/integrals/tests/test_integrals.py b/sympy/integrals/tests/test_integrals.py
index 0ab4731570..573cb7fb97 100644
--- a/sympy/integrals/tests/test_integrals.py
+++ b/sympy/integrals/tests/test_integrals.py
@@ -1662,8 +1662,8 @@ def test_integrate_with_complex_constants():
     x = Symbol('x', real=True)
     m = Symbol('m', real=True)
     t = Symbol('t', real=True)
-    assert integrate(exp(-I*K*x**2+m*x), x) == sqrt(I)*sqrt(pi)*exp(-I*m**2
-                    /(4*K))*erfi((-2*I*K*x + m)/(2*sqrt(K)*sqrt(-I)))/(2*sqrt(K))
+    assert integrate(exp(-I*K*x**2+m*x), x) == sqrt(pi)*exp(-I*m**2
+                    /(4*K))*erfi((-2*I*K*x + m)/(2*sqrt(K)*sqrt(-I)))/(2*sqrt(K)*sqrt(-I))
     assert integrate(1/(1 + I*x**2), x) == (-I*(sqrt(-I)*log(x - I*sqrt(-I))/2
             - sqrt(-I)*log(x + I*sqrt(-I))/2))
     assert integrate(exp(-I*x**2), x) == sqrt(pi)*erf(sqrt(I)*x)/(2*sqrt(I))
diff --git a/sympy/integrals/tests/test_manual.py b/sympy/integrals/tests/test_manual.py
index ea977b62a6..4accf09eb0 100644
--- a/sympy/integrals/tests/test_manual.py
+++ b/sympy/integrals/tests/test_manual.py
@@ -601,6 +601,20 @@ def test_issue_23566():
     assert str(i.n()) == '1.31695789692482'
 
 
+def test_issue_25093():
+    ap = Symbol('ap', positive=True)
+    an = Symbol('an', negative=True)
+    assert manualintegrate(exp(a*x**2 + b), x) == sqrt(pi)*exp(b)*erfi(sqrt(a)*x)/(2*sqrt(a))
+    assert manualintegrate(exp(ap*x**2 + b), x) == sqrt(pi)*exp(b)*erfi(sqrt(ap)*x)/(2*sqrt(ap))
+    assert manualintegrate(exp(an*x**2 + b), x) == -sqrt(pi)*exp(b)*erf(an*x/sqrt(-an))/(2*sqrt(-an))
+    assert manualintegrate(sin(a*x**2 + b), x) == (
+        sqrt(2)*sqrt(pi)*(sin(b)*fresnelc(sqrt(2)*sqrt(a)*x/sqrt(pi))
+        + cos(b)*fresnels(sqrt(2)*sqrt(a)*x/sqrt(pi)))/(2*sqrt(a)))
+    assert manualintegrate(cos(a*x**2 + b), x) == (
+        sqrt(2)*sqrt(pi)*(-sin(b)*fresnels(sqrt(2)*sqrt(a)*x/sqrt(pi))
+        + cos(b)*fresnelc(sqrt(2)*sqrt(a)*x/sqrt(pi)))/(2*sqrt(a)))
+
+
 def test_nested_pow():
     assert_is_integral_of(sqrt(x**2), x*sqrt(x**2)/2)
     assert_is_integral_of(sqrt(x**(S(5)/3)), 6*x*sqrt(x**(S(5)/3))/11)