Repository: sympy/sympy
Pull request: Numerical error on conversion of coulomb to statcoulomb 
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
fixes #24319 ,#24381 ,#24281
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed
fixes numerical error in the conversion of `coulomb` and `statcoulomb` 




#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

or if no release note(s) should be included use:



See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* physics.units
     *  fixed numerical error in conversion of statcoulomb and coulomb

<!-- END RELEASE NOTES -->


Problem statement:
Numerical error on conversion of coulomb to statcoulomb 
```python
In[2]: from sympy.physics.units import convert_to
In[3]: from sympy.physics.units.systems.cgs import cgs_gauss
In[4]: from sympy.physics.units.definitions.unit_definitions import statcoulomb, coulomb, second, gram, centimeter, erg
In[5]: convert_to(coulomb, statcoulomb, unit_system='cgs_gauss').n()

Out[5]:29979245.8*statcoulomb
```
`Expected Output : 1 C ≘ 2997924580 statC ≈ 3.00×109 statC`
```python 
def test_conversion_to_from_si():
         assert convert_to(statcoulomb, coulomb, cgs_gauss) == 5*coulomb/149896229
         assert convert_to(coulomb, statcoulomb, cgs_gauss) == 149896229*statcoulomb/5
```
It should be fixed as :
```python 
def test_conversion_to_from_si():
         assert convert_to(statcoulomb, coulomb, cgs_gauss) == coulomb/2997924580
         assert convert_to(coulomb, statcoulomb, cgs_gauss) ==  2997924580*statcoulomb
```

Hints from issue discussion:
Can I open the PR for that ?

Commit message: add tests

Patch to review:
diff --git a/.mailmap b/.mailmap
index be8e110a76d1..cd54bf00ef48 100644
--- a/.mailmap
+++ b/.mailmap
@@ -209,6 +209,7 @@ Abhinav Anand <abhinav.anand2807@gmail.com>
 Abhinav Chanda <abhinavchanda01@gmail.com>
 Abhishek <uchiha@pop-os.localdomain>
 Abhishek Garg <abhishekgarg119@gmail.com>
+Abhishek Patidar <1e9abhi1e10@gmail.com> Abhishek Patidar <2311abhiptdr@gmail.com>
 Abhishek Verma <iamvermaabhishek@gmail.com>
 Achal Jain <2achaljain@gmail.com>
 Adam Bloomston <adam@glitterfram.es> <mail@adambloomston>
diff --git a/sympy/physics/units/systems/cgs.py b/sympy/physics/units/systems/cgs.py
index fbf7a001bb7f..6a77dbd4a86a 100644
--- a/sympy/physics/units/systems/cgs.py
+++ b/sympy/physics/units/systems/cgs.py
@@ -56,16 +56,16 @@
 cgs_gauss.set_quantity_scale_factor(maxwell, sqrt(centimeter**3*gram)/second)
 
 # SI units expressed in CGS-gaussian units:
-cgs_gauss.set_quantity_scale_factor(coulomb, speed_of_light*statcoulomb/10)
-cgs_gauss.set_quantity_scale_factor(ampere, speed_of_light*statcoulomb/second/10)
-cgs_gauss.set_quantity_scale_factor(volt, speed_of_light*statvolt/10**6)
+cgs_gauss.set_quantity_scale_factor(coulomb, 10*speed_of_light*statcoulomb)
+cgs_gauss.set_quantity_scale_factor(ampere, 10*speed_of_light*statcoulomb/second)
+cgs_gauss.set_quantity_scale_factor(volt, 10**6/speed_of_light*statvolt)
 cgs_gauss.set_quantity_scale_factor(weber, 10**8*maxwell)
 cgs_gauss.set_quantity_scale_factor(tesla, 10**4*gauss)
 cgs_gauss.set_quantity_scale_factor(debye, One/10**18*statcoulomb*centimeter)
 cgs_gauss.set_quantity_scale_factor(oersted, sqrt(gram/centimeter)/second)
-cgs_gauss.set_quantity_scale_factor(ohm, 10**9/speed_of_light**2*second/centimeter)
-cgs_gauss.set_quantity_scale_factor(farad, One/10**9*speed_of_light**2*centimeter)
-cgs_gauss.set_quantity_scale_factor(henry, 10**9/speed_of_light**2/centimeter*second**2)
+cgs_gauss.set_quantity_scale_factor(ohm, 10**5/speed_of_light**2*second/centimeter)
+cgs_gauss.set_quantity_scale_factor(farad, One/10**5*speed_of_light**2*centimeter)
+cgs_gauss.set_quantity_scale_factor(henry, 10**5/speed_of_light**2/centimeter*second**2)
 
 # Coulomb's constant:
 cgs_gauss.set_quantity_dimension(coulomb_constant, 1)
diff --git a/sympy/physics/units/tests/test_unit_system_cgs_gauss.py b/sympy/physics/units/tests/test_unit_system_cgs_gauss.py
index 0dfb2f526279..2a1dc82d38fe 100644
--- a/sympy/physics/units/tests/test_unit_system_cgs_gauss.py
+++ b/sympy/physics/units/tests/test_unit_system_cgs_gauss.py
@@ -4,17 +4,16 @@
 from sympy.functions.elementary.miscellaneous import sqrt
 from sympy.physics.units import convert_to, coulomb_constant, elementary_charge, gravitational_constant, planck
 from sympy.physics.units.definitions.unit_definitions import statcoulomb, coulomb, second, gram, centimeter, erg, \
-    newton, joule, dyne, speed_of_light, meter
+    newton, joule, dyne, speed_of_light, meter, farad, henry, statvolt, volt, ohm
 from sympy.physics.units.systems import SI
 from sympy.physics.units.systems.cgs import cgs_gauss
 
 
 def test_conversion_to_from_si():
-
-    assert convert_to(statcoulomb, coulomb, cgs_gauss) == 5*coulomb/149896229
-    assert convert_to(coulomb, statcoulomb, cgs_gauss) == 149896229*statcoulomb/5
+    assert convert_to(statcoulomb, coulomb, cgs_gauss) == coulomb/2997924580
+    assert convert_to(coulomb, statcoulomb, cgs_gauss) == 2997924580*statcoulomb
     assert convert_to(statcoulomb, sqrt(gram*centimeter**3)/second, cgs_gauss) == centimeter**(S(3)/2)*sqrt(gram)/second
-    assert convert_to(coulomb, sqrt(gram*centimeter**3)/second, cgs_gauss) == 149896229*centimeter**(S(3)/2)*sqrt(gram)/(5*second)
+    assert convert_to(coulomb, sqrt(gram*centimeter**3)/second, cgs_gauss) == 2997924580*centimeter**(S(3)/2)*sqrt(gram)/second
 
     # SI units have an additional base unit, no conversion in case of electromagnetism:
     assert convert_to(coulomb, statcoulomb, SI) == coulomb
@@ -26,18 +25,47 @@ def test_conversion_to_from_si():
     assert convert_to(joule, erg, SI) == 10**7*erg
     assert convert_to(joule, erg, cgs_gauss) == 10**7*erg
 
+
     assert convert_to(dyne, newton, SI) == newton/10**5
     assert convert_to(dyne, newton, cgs_gauss) == newton/10**5
     assert convert_to(newton, dyne, SI) == 10**5*dyne
     assert convert_to(newton, dyne, cgs_gauss) == 10**5*dyne
 
 
+def test_ohm_cgs_gauss():
+
+    assert convert_to(ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(1*ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(2*ohm,second/centimeter,cgs_gauss) == 50000*second/(22468879468420441*centimeter)
+    assert NS(convert_to(ohm,second/centimeter,cgs_gauss)) == '1.11265005605362e-12*second/centimeter'
+    assert NS(convert_to(2*ohm,second/centimeter,cgs_gauss)) == '2.22530011210724e-12*second/centimeter'
+
+def test_henry_cgs_gauss():
+    assert convert_to(henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(1*henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(2*henry,second**2/centimeter,cgs_gauss) == 50000*second**2/(22468879468420441*centimeter)
+    assert NS(convert_to(henry,second**2/centimeter,cgs_gauss)) == '1.11265005605362e-12*second**2/centimeter'
+    assert NS(convert_to(2*henry,second**2/centimeter,cgs_gauss)) == '2.22530011210724e-12*second**2/centimeter'
+
+def test_volt_cgs_gauss():
+    assert convert_to(volt,statvolt,cgs_gauss) == 10**6*statvolt/299792458
+    assert convert_to(1*volt,statvolt,cgs_gauss) == 10**6*statvolt/299792458
+    assert convert_to(2*volt,statvolt,cgs_gauss) == 2*10**6*statvolt/299792458
+
+def test_farad_cgs_gauss():
+
+   assert convert_to(farad,centimeter,cgs_gauss) == 299792458**2*centimeter/10**5
+   assert convert_to(1*farad,centimeter,cgs_gauss) == 299792458**2*centimeter/10**5
+   assert convert_to(2*farad,centimeter,cgs_gauss) == 2*299792458**2*centimeter/10**5
+
+
+
 def test_cgs_gauss_convert_constants():
 
     assert convert_to(speed_of_light, centimeter/second, cgs_gauss) == 29979245800*centimeter/second
 
     assert convert_to(coulomb_constant, 1, cgs_gauss) == 1
-    assert convert_to(coulomb_constant, newton*meter**2/coulomb**2, cgs_gauss) == 22468879468420441*meter**2*newton/(25000000000*coulomb**2)
+    assert convert_to(coulomb_constant, newton*meter**2/coulomb**2, cgs_gauss) == 22468879468420441*meter**2*newton/(2500000*coulomb**2)
     assert convert_to(coulomb_constant, newton*meter**2/coulomb**2, SI) == 22468879468420441*meter**2*newton/(2500000*coulomb**2)
     assert convert_to(coulomb_constant, dyne*centimeter**2/statcoulomb**2, cgs_gauss) == centimeter**2*dyne/statcoulomb**2
     assert convert_to(coulomb_constant, 1, SI) == coulomb_constant


Code review comments:
diff_hunk: @@ -26,18 +25,47 @@ def test_conversion_to_from_si():
     assert convert_to(joule, erg, SI) == 10**7*erg
     assert convert_to(joule, erg, cgs_gauss) == 10**7*erg
 
+
     assert convert_to(dyne, newton, SI) == newton/10**5
     assert convert_to(dyne, newton, cgs_gauss) == newton/10**5
     assert convert_to(newton, dyne, SI) == 10**5*dyne
     assert convert_to(newton, dyne, cgs_gauss) == 10**5*dyne
 
 
+def test_ohm_cgs_gauss():
+
+    assert convert_to(ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(1*ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(2*ohm,second/centimeter,cgs_gauss) == 50000*second/(22468879468420441*centimeter)
+    assert NS(convert_to(ohm,second/centimeter,cgs_gauss)) == '1.11265005605362e-12*second/centimeter'
+    assert NS(convert_to(2*ohm,second/centimeter,cgs_gauss)) == '2.22530011210724e-12*second/centimeter'
+
+def test_henry_cgs_gauss():
+    assert convert_to(henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(1*henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(2*henry,second**2/centimeter,cgs_gauss) == 50000*second**2/(22468879468420441*centimeter)
+    assert NS(convert_to(henry,second**2/centimeter,cgs_gauss)) == '1.11265005605362e-12*second**2/centimeter'
+    assert NS(convert_to(2*henry,second**2/centimeter,cgs_gauss)) == '2.22530011210724e-12*second**2/centimeter'
+
+def test_volt_cgs_gauss():
+    assert convert_to(volt,statvolt,cgs_gauss) == 10**6*statvolt/299792458
+    assert convert_to(1*volt,statvolt,cgs_gauss) == 10**6*statvolt/299792458
+    assert convert_to(2*volt,statvolt,cgs_gauss) == 2*10**6*statvolt/299792458
path: sympy/physics/units/tests/test_unit_system_cgs_gauss.py
text: @user1:
ditto

@author:
This test is for the conversion of a `volt` to a `statvolt`
In master when we are converting `volt` to `statvolt` it gives a wrong answer.
So I fix it to `cgs_gauss.set_quantity_scale_factor(volt, 10**6/speed_of_light*statvolt)`
from `cgs_gauss.set_quantity_scale_factor(volt, speed_of_light*statvolt/10**6)`
Reference for the [conversions](https://en.wikipedia.org/wiki/Gaussian_units) of SI unit to gaussian units

diff_hunk: @@ -26,18 +25,47 @@ def test_conversion_to_from_si():
     assert convert_to(joule, erg, SI) == 10**7*erg
     assert convert_to(joule, erg, cgs_gauss) == 10**7*erg
 
+
     assert convert_to(dyne, newton, SI) == newton/10**5
     assert convert_to(dyne, newton, cgs_gauss) == newton/10**5
     assert convert_to(newton, dyne, SI) == 10**5*dyne
     assert convert_to(newton, dyne, cgs_gauss) == 10**5*dyne
 
 
+def test_ohm_cgs_gauss():
+
+    assert convert_to(ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(1*ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(2*ohm,second/centimeter,cgs_gauss) == 50000*second/(22468879468420441*centimeter)
+    assert NS(convert_to(ohm,second/centimeter,cgs_gauss)) == '1.11265005605362e-12*second/centimeter'
+    assert NS(convert_to(2*ohm,second/centimeter,cgs_gauss)) == '2.22530011210724e-12*second/centimeter'
+
+def test_henry_cgs_gauss():
+    assert convert_to(henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(1*henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(2*henry,second**2/centimeter,cgs_gauss) == 50000*second**2/(22468879468420441*centimeter)
+    assert NS(convert_to(henry,second**2/centimeter,cgs_gauss)) == '1.11265005605362e-12*second**2/centimeter'
+    assert NS(convert_to(2*henry,second**2/centimeter,cgs_gauss)) == '2.22530011210724e-12*second**2/centimeter'
path: sympy/physics/units/tests/test_unit_system_cgs_gauss.py
text: @user1:
ditto

@author:
This test is for the conversion of a `henry` to a `second**/centimeter`
In master when we are converting `henry` to `second**2/centimeter` it gives a wrong answer.
So I fix it to  `cgs_gauss.set_quantity_scale_factor(henry, 10**5/speed_of_light**2/centimeter*second**2)`
from `cgs_gauss.set_quantity_scale_factor(henry, 10**9/speed_of_light**2/centimeter*second**2)`
Reference for the [conversions](https://en.wikipedia.org/wiki/Gaussian_units) of SI unit to gaussian units

diff_hunk: @@ -26,18 +25,47 @@ def test_conversion_to_from_si():
     assert convert_to(joule, erg, SI) == 10**7*erg
     assert convert_to(joule, erg, cgs_gauss) == 10**7*erg
 
+
     assert convert_to(dyne, newton, SI) == newton/10**5
     assert convert_to(dyne, newton, cgs_gauss) == newton/10**5
     assert convert_to(newton, dyne, SI) == 10**5*dyne
     assert convert_to(newton, dyne, cgs_gauss) == 10**5*dyne
 
 
+def test_ohm_cgs_gauss():
+
+    assert convert_to(ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(1*ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(2*ohm,second/centimeter,cgs_gauss) == 50000*second/(22468879468420441*centimeter)
+    assert NS(convert_to(ohm,second/centimeter,cgs_gauss)) == '1.11265005605362e-12*second/centimeter'
+    assert NS(convert_to(2*ohm,second/centimeter,cgs_gauss)) == '2.22530011210724e-12*second/centimeter'
path: sympy/physics/units/tests/test_unit_system_cgs_gauss.py
text: @user1:
What is the purpose of these test beyond the first one?

@author:
This test is for the conversion of an ohm to a second/centimeter
In master when we are converting ohm to second/centimeter it gives a wrong answer.
So I fix it to  `cgs_gauss.set_quantity_scale_factor(ohm, 10**5/speed_of_light**2*second/centimeter)`
from `cgs_gauss.set_quantity_scale_factor(ohm, 10**9/speed_of_light**2*second/centimeter)` 
Reference for the [conversions](https://en.wikipedia.org/wiki/Gaussian_units) of SI unit to gaussian units

@user1:
The first test does that. I don't think the additional tests are adding value to the test suite.

@author:
Ok I will remove those tests.

diff_hunk: @@ -26,18 +25,47 @@ def test_conversion_to_from_si():
     assert convert_to(joule, erg, SI) == 10**7*erg
     assert convert_to(joule, erg, cgs_gauss) == 10**7*erg
 
+
     assert convert_to(dyne, newton, SI) == newton/10**5
     assert convert_to(dyne, newton, cgs_gauss) == newton/10**5
     assert convert_to(newton, dyne, SI) == 10**5*dyne
     assert convert_to(newton, dyne, cgs_gauss) == 10**5*dyne
 
 
+def test_ohm_cgs_gauss():
+
+    assert convert_to(ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(1*ohm,second/centimeter,cgs_gauss) == 25000*second/(22468879468420441*centimeter)
+    assert convert_to(2*ohm,second/centimeter,cgs_gauss) == 50000*second/(22468879468420441*centimeter)
+    assert NS(convert_to(ohm,second/centimeter,cgs_gauss)) == '1.11265005605362e-12*second/centimeter'
+    assert NS(convert_to(2*ohm,second/centimeter,cgs_gauss)) == '2.22530011210724e-12*second/centimeter'
+
+def test_henry_cgs_gauss():
+    assert convert_to(henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(1*henry,second**2/centimeter,cgs_gauss) == 25000*second**2/(22468879468420441*centimeter)
+    assert convert_to(2*henry,second**2/centimeter,cgs_gauss) == 50000*second**2/(22468879468420441*centimeter)
+    assert NS(convert_to(henry,second**2/centimeter,cgs_gauss)) == '1.11265005605362e-12*second**2/centimeter'
+    assert NS(convert_to(2*henry,second**2/centimeter,cgs_gauss)) == '2.22530011210724e-12*second**2/centimeter'
+
+def test_volt_cgs_gauss():
+    assert convert_to(volt,statvolt,cgs_gauss) == 10**6*statvolt/299792458
+    assert convert_to(1*volt,statvolt,cgs_gauss) == 10**6*statvolt/299792458
+    assert convert_to(2*volt,statvolt,cgs_gauss) == 2*10**6*statvolt/299792458
+
+def test_farad_cgs_gauss():
+
+   assert convert_to(farad,centimeter,cgs_gauss) == 299792458**2*centimeter/10**5
+   assert convert_to(1*farad,centimeter,cgs_gauss) == 299792458**2*centimeter/10**5
+   assert convert_to(2*farad,centimeter,cgs_gauss) == 2*299792458**2*centimeter/10**5
path: sympy/physics/units/tests/test_unit_system_cgs_gauss.py
text: @user1:
ditto

@author:
This test is for the conversion of a `farad` to a `centimeter`
In master when we are converting `farad` to `centimeter` it gives a wrong answer.
So I fix it to `cgs_gauss.set_quantity_scale_factor(farad, One/10**5*speed_of_light**2*centimeter)`
from `cgs_gauss.set_quantity_scale_factor(farad, One/10**9*speed_of_light**2*centimeter)`
Reference for the [conversions](https://en.wikipedia.org/wiki/Gaussian_units) of SI unit to gaussian units