Repository: sympy/sympy
Pull request: Adding electron_rest_mass unit in physics.units
<!-- 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
<!-- 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. -->
Fixes #24462 


#### Brief description of what is fixed or changed
The electron rest mass (symbol: me) is the mass of a stationary electron, also known as the invariant mass of the electron. It is one of the fundamental constants of physics.


#### 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.

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
  * Added electron rest mass unit 

<!-- END RELEASE NOTES -->


Problem statement:
Missing electron rest mass unit in physics.units
The electron rest mass (symbol: me) is the mass of a stationary electron, also known as the invariant mass of the electron. It is one of the fundamental constants of physics. It has a value of about 9.109×10−31 kilograms
It is not in `physics.units` should we add it.

Hints from issue discussion:

Commit message: Adding electron_rest_mass unit

Patch to review:
diff --git a/sympy/physics/units/__init__.py b/sympy/physics/units/__init__.py
index 18fee8c60119..361dbfdbcb01 100644
--- a/sympy/physics/units/__init__.py
+++ b/sympy/physics/units/__init__.py
@@ -164,6 +164,7 @@
     josephson_constant,
     von_klitzing_constant,
     Da, dalton, amu, amus, atomic_mass_unit, atomic_mass_constant,
+    me, electron_rest_mass,
     gee, gees, acceleration_due_to_gravity,
     u0, magnetic_constant, vacuum_permeability,
     e0, electric_constant, vacuum_permittivity,
@@ -398,6 +399,7 @@ def find_unit(quantity, unit_system="SI"):
     'josephson_constant',
     'von_klitzing_constant',
     'Da', 'dalton', 'amu', 'amus', 'atomic_mass_unit', 'atomic_mass_constant',
+    'me', 'electron_rest_mass',
     'gee', 'gees', 'acceleration_due_to_gravity',
     'u0', 'magnetic_constant', 'vacuum_permeability',
     'e0', 'electric_constant', 'vacuum_permittivity',
diff --git a/sympy/physics/units/definitions/__init__.py b/sympy/physics/units/definitions/__init__.py
index f60eb838bed3..ab5a0e1c2f4b 100644
--- a/sympy/physics/units/definitions/__init__.py
+++ b/sympy/physics/units/definitions/__init__.py
@@ -82,6 +82,7 @@
     josephson_constant,
     von_klitzing_constant,
     Da, dalton, amu, amus, atomic_mass_unit, atomic_mass_constant,
+    me, electron_rest_mass,
     gee, gees, acceleration_due_to_gravity,
     u0, magnetic_constant, vacuum_permeability,
     e0, electric_constant, vacuum_permittivity,
@@ -213,6 +214,7 @@
     'josephson_constant',
     'von_klitzing_constant',
     'Da', 'dalton', 'amu', 'amus', 'atomic_mass_unit', 'atomic_mass_constant',
+    'me', 'electron_rest_mass',
     'gee', 'gees', 'acceleration_due_to_gravity',
     'u0', 'magnetic_constant', 'vacuum_permeability',
     'e0', 'electric_constant', 'vacuum_permittivity',
diff --git a/sympy/physics/units/definitions/unit_definitions.py b/sympy/physics/units/definitions/unit_definitions.py
index 4939fa65acb5..cf51b51f45a5 100644
--- a/sympy/physics/units/definitions/unit_definitions.py
+++ b/sympy/physics/units/definitions/unit_definitions.py
@@ -122,6 +122,9 @@
 t = metric_ton = tonne = Quantity("tonne", abbrev="t")
 tonne.set_global_relative_scale_factor(mega, gram)
 
+# Electron rest mass
+me = electron_rest_mass = Quantity("electron_rest_mass", abbrev="me")
+
 
 # Common length units
 
diff --git a/sympy/physics/units/systems/si.py b/sympy/physics/units/systems/si.py
index 700495ad9d26..02f3e0a4b09f 100644
--- a/sympy/physics/units/systems/si.py
+++ b/sympy/physics/units/systems/si.py
@@ -25,7 +25,7 @@
     coulomb, volt, ohm, siemens, farad, henry, tesla, weber, dioptre, lux,
     katal, gray, becquerel, inch, liter, julian_year, gravitational_constant,
     speed_of_light, elementary_charge, planck, hbar, electronvolt,
-    avogadro_number, avogadro_constant, boltzmann_constant,
+    avogadro_number, avogadro_constant, boltzmann_constant, electron_rest_mass,
     stefan_boltzmann_constant, Da, atomic_mass_constant, molar_gas_constant,
     faraday_constant, josephson_constant, von_klitzing_constant,
     acceleration_due_to_gravity, magnetic_constant, vacuum_permittivity,
@@ -229,6 +229,10 @@
 SI.set_quantity_dimension(vacuum_impedance, impedance)
 SI.set_quantity_scale_factor(vacuum_impedance, u0 * c)
 
+# Electron rest mass
+SI.set_quantity_dimension(electron_rest_mass, mass)
+SI.set_quantity_scale_factor(electron_rest_mass, 9.1093837015e-31*kilogram)
+
 # Coulomb's constant:
 SI.set_quantity_dimension(coulomb_constant, force * length ** 2 / charge ** 2)
 SI.set_quantity_scale_factor(coulomb_constant, 1/(4*pi*vacuum_permittivity))
@@ -364,7 +368,7 @@
     'planck_angular_frequency', 'ohm', 'pound', 'planck_pressure', 'G', 'psi',
     'dHg0', 'von_klitzing_constant', 'planck_length', 'avogadro_number',
     'mole', 'acceleration', 'information', 'planck_energy_density',
-    'mebibyte', 's', 'acceleration_due_to_gravity',
+    'mebibyte', 's', 'acceleration_due_to_gravity', 'electron_rest_mass',
     'planck_temperature', 'units', 'mass', 'dimsys_MKSA', 'kelvin', 'kPa',
     'boltzmann', 'milli_mass_unit', 'planck_impedance', 'electric_constant',
     'derived_dims', 'kg', 'coulomb', 'siemens', 'byte', 'magnetic_flux',
diff --git a/sympy/physics/units/tests/test_quantities.py b/sympy/physics/units/tests/test_quantities.py
index 0d6784decf2d..bb0b0afb4c9e 100644
--- a/sympy/physics/units/tests/test_quantities.py
+++ b/sympy/physics/units/tests/test_quantities.py
@@ -18,7 +18,7 @@
     day, foot, grams, hour, inch, kg, km, m, meter, millimeter,
     minute, quart, s, second, speed_of_light, bit,
     byte, kibibyte, mebibyte, gibibyte, tebibyte, pebibyte, exbibyte,
-    kilogram, gravitational_constant)
+    kilogram, gravitational_constant, electron_rest_mass)
 
 from sympy.physics.units.definitions.dimension_definitions import (
     Dimension, charge, length, time, temperature, pressure,
@@ -278,6 +278,9 @@ def test_issue_quart():
     assert convert_to(4 * quart / inch ** 3, meter) == 231
     assert convert_to(4 * quart / inch ** 3, millimeter) == 231
 
+def test_electron_rest_mass():
+    assert convert_to(electron_rest_mass, kilogram) == 9.1093837015e-31*kilogram
+    assert convert_to(electron_rest_mass, grams) == 9.1093837015e-28*grams
 
 def test_issue_5565():
     assert (m < s).is_Relational
@@ -304,11 +307,11 @@ def test_find_unit():
         'deciliter', 'centiliter', 'deciliters', 'milliliter',
         'centiliters', 'milliliters', 'planck_volume']
     assert find_unit('voltage') == ['V', 'v', 'volt', 'volts', 'planck_voltage']
-    assert find_unit(grams) == ['g', 't', 'Da', 'kg', 'mg', 'ug', 'amu', 'mmu', 'amus',
-                                'gram', 'mmus', 'grams', 'pound', 'tonne', 'dalton',
-                                'pounds', 'kilogram', 'kilograms', 'microgram', 'milligram',
-                                'metric_ton', 'micrograms', 'milligrams', 'planck_mass',
-                                'milli_mass_unit', 'atomic_mass_unit', 'atomic_mass_constant']
+    assert find_unit(grams) == ['g', 't', 'Da', 'kg', 'me', 'mg', 'ug', 'amu', 'mmu', 'amus',
+                                'gram', 'mmus', 'grams', 'pound', 'tonne', 'dalton', 'pounds',
+                                'kilogram', 'kilograms','microgram', 'milligram', 'metric_ton',
+                                'micrograms', 'milligrams', 'planck_mass', 'milli_mass_unit', 'atomic_mass_unit',
+                                'electron_rest_mass', 'atomic_mass_constant']
 
 
 def test_Quantity_derivative():


Code review comments:
diff_hunk: @@ -304,11 +307,11 @@ def test_find_unit():
         'deciliter', 'centiliter', 'deciliters', 'milliliter',
         'centiliters', 'milliliters', 'planck_volume']
     assert find_unit('voltage') == ['V', 'v', 'volt', 'volts', 'planck_voltage']
-    assert find_unit(grams) == ['g', 't', 'Da', 'kg', 'mg', 'ug', 'amu', 'mmu', 'amus',
-                                'gram', 'mmus', 'grams', 'pound', 'tonne', 'dalton',
-                                'pounds', 'kilogram', 'kilograms', 'microgram', 'milligram',
-                                'metric_ton', 'micrograms', 'milligrams', 'planck_mass',
-                                'milli_mass_unit', 'atomic_mass_unit', 'atomic_mass_constant']
+    assert find_unit(grams) == ['g', 't', 'Da', 'kg', 'me', 'mg', 'ug', 'amu', 'mmu', 'amus',
+                                'gram', 'mmus', 'grams', 'pound', 'tonne', 'dalton', 'pounds',
+                                'kilogram', 'kilograms','microgram', 'milligram', 'metric_ton',
path: sympy/physics/units/tests/test_quantities.py
text: @user1:
misses a space between `kilograms` and `microgram`