Repository: sympy/sympy

Issue:
sympy.physics.wigner.gaunt does not return rational number
example:
In [1]: import sympy.physics.wigner

In [2]: sympy.physics.wigner.gaunt(1,1,0,-1,1,0)
Out[2]: -0.5/sqrt(pi)
which does not return rational number

However, its equivalent return the rational
In [3]: sympy.physics.wigner.gaunt(0,1,1,0,-1,1)
Out[3]: -1/(2*sqrt(pi))

I use sympy 1.0

Discussion:
gxyd: Thanks for your contribution. Can you please add test cases for the made changes?
See this https://github.com/sympy/sympy/wiki/Writing-test-cases-in-SymPy for guidelines on how to write test cases.
NikhilPappu: @gxyd  Can assert tell the difference between -0.5*(sqrt(pi)) and -1/(2*sqrt(pi))? It did not seem to work that way when i tested it.
gxyd: Can you please paste the code, for what you expect and what you get (write in comments for what you expected and what you got)? That will help.
NikhilPappu: Without the fix, `print(gaunt(1, 1, 0, -1, 1, 0))` outputs `-0.5*(sqrt(pi))` but `assert gaunt(1, 1, 0, -1, 1, 0) == -1/(2*sqrt(pi))` returns True so I don't see how the test would help. With the fix the output is `-1/(2*sqrt(pi))`.
NikhilPappu: @gxyd Do you know of a way to write a test that checks the exact form of the expression?
gxyd: See:
```python
In [1]: a = -1/(2*sqrt(pi))

In [2]: b = -0.5*(sqrt(pi))

In [3]: a is S(-1)/(2*sqrt(pi))
Out[3]: True

In [4]: b is S(-1)/(2*sqrt(pi))
Out[4]: False
```

I'm not saying that 'is' is the way to add a test here, I haven't given thought as to the best way of writing test for this. But there definitely are ways to write tests for this.
NikhilPappu: @gxyd Thanks for that! I'll add the test.
NikhilPappu: @gxyd 'is' doesn't seem to work. This is the kind of behaviour. Also how do I past code like that?
```
In [1]: a = -1/(2*sqrt(pi))

In [2]: b = gaunt(1, 1, 0, -1, 1, 0)

In [3]: a is S(-1)/(2*sqrt(pi))
Out[3]: True

In [4]: b is S(-1)/(2*sqrt(pi))
Out[4]: False

In [5]: b
Out[5]: -1/(2*sqrt(pi))
```
jksuom: You can use `srepr` to see the structure:
```
>>> a = -1/(2*sqrt(pi))
>>> srepr(a)
'Mul(Integer(-1), Rational(1, 2), Pow(pi, Rational(-1, 2)))'
>>> b = gaunt(1, 1, 0, -1, 1, 0)
>>> srepr(b)
"Mul(Integer(-1), Float('0.5', precision=53), Pow(pi, Rational(-1, 2)))"
```

Patch:
diff --git a/sympy/physics/wigner.py b/sympy/physics/wigner.py
index 036a690961..71bb6e5ad1 100644
--- a/sympy/physics/wigner.py
+++ b/sympy/physics/wigner.py
@@ -696,7 +696,7 @@ def gaunt(l_1, l_2, l_3, m_1, m_2, m_3, prec=None):
             _Factlist[ii + l_3 - l_2 + m_1] * _Factlist[l_1 + l_2 - l_3 - ii]
         sumres = sumres + Integer((-1) ** ii) / den
 
-    res = ressqrt * prefac * sumres * (-1) ** (bigL + l_3 + m_1 - m_2)
+    res = ressqrt * prefac * sumres * Integer((-1) ** (bigL + l_3 + m_1 - m_2))
     if prec is not None:
         res = res.n(prec)
     return res


Test patch:
diff --git a/sympy/physics/tests/test_clebsch_gordan.py b/sympy/physics/tests/test_clebsch_gordan.py
index 22d7f1c2ea..48f835ecf8 100644
--- a/sympy/physics/tests/test_clebsch_gordan.py
+++ b/sympy/physics/tests/test_clebsch_gordan.py
@@ -259,6 +259,9 @@ def test_gaunt():
     def tn(a, b):
         return (a - b).n(64) < S('1e-64')
     assert gaunt(1, 0, 1, 1, 0, -1) == -1/(2*sqrt(pi))
+    assert isinstance(gaunt(1, 1, 0, -1, 1, 0).args[0], Rational)
+    assert isinstance(gaunt(0, 1, 1, 0, -1, 1).args[0], Rational)
+
     assert tn(gaunt(
         10, 10, 12, 9, 3, -12, prec=64), (-S(98)/62031) * sqrt(6279)/sqrt(pi))
     def gaunt_ref(l1, l2, l3, m1, m2, m3):