Repository: sympy/sympy
Pull request: Fix bug when multiplying Prefix and Quantity.
#### References to other Issues or PRs
Fixes #24832 

#### Brief description of what is fixed or changed
Previously, when multiplying a prefix and a quantity, the code would return 1 if the product of their scale factors was equal to 1. This resulted in incorrect output in some cases, such as when multiplying "milli" and "W", which would evaluate to 1 instead of W/1000. 
To fix this issue, the code has been updated to only return 1 when a prefix is multiplied by another prefix. When a prefix is multiplied by a quantity, the product of their scale factors is no longer checked for equality to 1.

#### 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:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

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
  * Corrected the bug in multiplication between prefix and quantity, e.g. milli * W = 1 which should be W/1000.
<!-- END RELEASE NOTES -->


Problem statement:
Bug with milli prefix
What happened:
```
In [1]: from sympy.physics.units import milli, W
In [2]: milli*W == 1
Out[2]: True
In [3]: W*milli
Out[3]: watt*Prefix(milli, m, -3, 10)
```
What I expected to happen: milli*W should evaluate to milli watts / mW

`milli*W` or more generally `milli` times some unit evaluates to the number 1. I have tried this with Watts and Volts, I'm not sure what other cases this happens. I'm using sympy version 1.11.1-1 on Arch Linux with Python 3.10.9. If you cannot reproduce I would be happy to be of any assitance.

Hints from issue discussion:
I get a 1 for all of the following (and some are redundant like "V" and "volt"):
```python
W, joule, ohm, newton, volt, V, v, volts, henrys, pa, kilogram, ohms, kilograms, Pa, weber, tesla, Wb, H, wb, newtons, kilometers, webers, pascals, kilometer, watt, T, km, kg, joules, pascal, watts, J, henry, kilo, teslas
```
Plus it's only milli.
```
In [65]: for p in PREFIXES:
    ...:     print(p, PREFIXES[p]*W)
    ...:
Y 1000000000000000000000000*watt
Z 1000000000000000000000*watt
E 1000000000000000000*watt
P 1000000000000000*watt
T 1000000000000*watt
G 1000000000*watt
M 1000000*watt
k 1000*watt
h 100*watt
da 10*watt
d watt/10
c watt/100
m 1
mu watt/1000000
n watt/1000000000
p watt/1000000000000
f watt/1000000000000000
a watt/1000000000000000000
z watt/1000000000000000000000
y watt/1000000000000000000000000
```
Dear team,

I am excited to contribute to this project and offer my skills. Please let me support the team's efforts and collaborate effectively. Looking forward to working with you all.
@Sourabh5768  Thanks for showing interest, you don't need to ask for a contribution If you know how to fix an issue, you can just make a pull request to fix it.
I looked at the code and change it a little bit to fix this issue. If anyone has time, please take a look at the pull request.

Commit message: fix code quality of the previous commit

Patch to review:
diff --git a/.mailmap b/.mailmap
index 7f81e5547e2b..05415c6a450c 100644
--- a/.mailmap
+++ b/.mailmap
@@ -821,6 +821,7 @@ Langston Barrett <langston.barrett@gmail.com>
 Lars Buitinck <larsmans@gmail.com>
 Laura Domine <temigo@gmx.com>
 Lauren Glattly <laurenglattly@gmail.com>
+Le Cong Minh Hieu <hieu.lecongminh@gmail.com>
 Lee Johnston <lee.johnston.100@gmail.com>
 Lejla Metohajrova <l.metohajrova@gmail.com>
 Lennart Fricke <lennart@die-frickes.eu>
diff --git a/sympy/physics/units/prefixes.py b/sympy/physics/units/prefixes.py
index ca6a642156bf..56a3de188119 100644
--- a/sympy/physics/units/prefixes.py
+++ b/sympy/physics/units/prefixes.py
@@ -6,7 +6,7 @@
 """
 from sympy.core.expr import Expr
 from sympy.core.sympify import sympify
-
+from sympy.core.singleton import S
 
 class Prefix(Expr):
     """
@@ -85,9 +85,9 @@ def __mul__(self, other):
 
         fact = self.scale_factor * other.scale_factor
 
-        if fact == 1:
-            return 1
-        elif isinstance(other, Prefix):
+        if isinstance(other, Prefix):
+            if fact == 1:
+                return S.One
             # simplify prefix
             for p in PREFIXES:
                 if PREFIXES[p].scale_factor == fact:
@@ -103,7 +103,7 @@ def __truediv__(self, other):
         fact = self.scale_factor / other.scale_factor
 
         if fact == 1:
-            return 1
+            return S.One
         elif isinstance(other, Prefix):
             for p in PREFIXES:
                 if PREFIXES[p].scale_factor == fact:
diff --git a/sympy/physics/units/tests/test_prefixes.py b/sympy/physics/units/tests/test_prefixes.py
index 8a7ae3a2c497..8c70c31fc668 100644
--- a/sympy/physics/units/tests/test_prefixes.py
+++ b/sympy/physics/units/tests/test_prefixes.py
@@ -2,7 +2,7 @@
 from sympy.core.numbers import Rational
 from sympy.core.singleton import S
 from sympy.core.symbol import (Symbol, symbols)
-from sympy.physics.units import Quantity, length, meter
+from sympy.physics.units import Quantity, length, meter, W
 from sympy.physics.units.prefixes import PREFIXES, Prefix, prefix_unit, kilo, \
     kibi
 from sympy.physics.units.systems import SI
@@ -17,7 +17,8 @@ def test_prefix_operations():
 
     dodeca = Prefix('dodeca', 'dd', 1, base=12)
 
-    assert m * k == 1
+    assert m * k == S.One
+    assert m * W == W / 1000
     assert k * k == M
     assert 1 / m == k
     assert k / m == M
@@ -25,7 +26,7 @@ def test_prefix_operations():
     assert dodeca * dodeca == 144
     assert 1 / dodeca == S.One / 12
     assert k / dodeca == S(1000) / 12
-    assert dodeca / dodeca == 1
+    assert dodeca / dodeca == S.One
 
     m = Quantity("fake_meter")
     SI.set_quantity_dimension(m, S.One)


Code review comments:
diff_hunk: @@ -17,15 +17,16 @@ def test_prefix_operations():
 
     dodeca = Prefix('dodeca', 'dd', 1, base=12)
 
-    assert m * k == 1
+    assert m * k == S.One
path: sympy/physics/units/tests/test_prefixes.py
text: @user1:
since 1==S.One, this would need to be tested using `is` instead `==`.

@author:
I changed accordingly. Thank you.