passagemath-symbolics 10.6.37__cp314-cp314t-macosx_13_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. passagemath_symbolics/.dylibs/libgmp.10.dylib +0 -0
  2. passagemath_symbolics/__init__.py +3 -0
  3. passagemath_symbolics-10.6.37.dist-info/METADATA +187 -0
  4. passagemath_symbolics-10.6.37.dist-info/RECORD +172 -0
  5. passagemath_symbolics-10.6.37.dist-info/WHEEL +6 -0
  6. passagemath_symbolics-10.6.37.dist-info/top_level.txt +3 -0
  7. sage/all__sagemath_symbolics.py +17 -0
  8. sage/calculus/all.py +14 -0
  9. sage/calculus/calculus.py +2826 -0
  10. sage/calculus/desolvers.py +1866 -0
  11. sage/calculus/predefined.py +51 -0
  12. sage/calculus/tests.py +225 -0
  13. sage/calculus/var.cpython-314t-darwin.so +0 -0
  14. sage/calculus/var.pyx +401 -0
  15. sage/dynamics/all__sagemath_symbolics.py +6 -0
  16. sage/dynamics/complex_dynamics/all.py +5 -0
  17. sage/dynamics/complex_dynamics/mandel_julia.py +765 -0
  18. sage/dynamics/complex_dynamics/mandel_julia_helper.cpython-314t-darwin.so +0 -0
  19. sage/dynamics/complex_dynamics/mandel_julia_helper.pyx +1035 -0
  20. sage/ext/all__sagemath_symbolics.py +1 -0
  21. sage/ext_data/kenzo/CP2.txt +45 -0
  22. sage/ext_data/kenzo/CP3.txt +349 -0
  23. sage/ext_data/kenzo/CP4.txt +4774 -0
  24. sage/ext_data/kenzo/README.txt +49 -0
  25. sage/ext_data/kenzo/S4.txt +20 -0
  26. sage/ext_data/magma/latex/latex.m +1021 -0
  27. sage/ext_data/magma/latex/latex.spec +1 -0
  28. sage/ext_data/magma/sage/basic.m +356 -0
  29. sage/ext_data/magma/sage/sage.spec +1 -0
  30. sage/ext_data/magma/spec +9 -0
  31. sage/geometry/all__sagemath_symbolics.py +8 -0
  32. sage/geometry/hyperbolic_space/all.py +5 -0
  33. sage/geometry/hyperbolic_space/hyperbolic_coercion.py +743 -0
  34. sage/geometry/hyperbolic_space/hyperbolic_constants.py +5 -0
  35. sage/geometry/hyperbolic_space/hyperbolic_geodesic.py +2409 -0
  36. sage/geometry/hyperbolic_space/hyperbolic_interface.py +206 -0
  37. sage/geometry/hyperbolic_space/hyperbolic_isometry.py +1082 -0
  38. sage/geometry/hyperbolic_space/hyperbolic_model.py +1502 -0
  39. sage/geometry/hyperbolic_space/hyperbolic_point.py +621 -0
  40. sage/geometry/riemannian_manifolds/all.py +7 -0
  41. sage/geometry/riemannian_manifolds/parametrized_surface3d.py +1632 -0
  42. sage/geometry/riemannian_manifolds/surface3d_generators.py +461 -0
  43. sage/interfaces/all__sagemath_symbolics.py +1 -0
  44. sage/interfaces/magma.py +3017 -0
  45. sage/interfaces/magma_free.py +92 -0
  46. sage/interfaces/maple.py +1397 -0
  47. sage/interfaces/mathematica.py +1345 -0
  48. sage/interfaces/mathics.py +1312 -0
  49. sage/interfaces/sympy.py +1398 -0
  50. sage/interfaces/sympy_wrapper.py +197 -0
  51. sage/interfaces/tides.py +938 -0
  52. sage/libs/all__sagemath_symbolics.py +6 -0
  53. sage/manifolds/all.py +7 -0
  54. sage/manifolds/calculus_method.py +555 -0
  55. sage/manifolds/catalog.py +437 -0
  56. sage/manifolds/chart.py +4019 -0
  57. sage/manifolds/chart_func.py +3419 -0
  58. sage/manifolds/continuous_map.py +2183 -0
  59. sage/manifolds/continuous_map_image.py +155 -0
  60. sage/manifolds/differentiable/affine_connection.py +2475 -0
  61. sage/manifolds/differentiable/all.py +1 -0
  62. sage/manifolds/differentiable/automorphismfield.py +1383 -0
  63. sage/manifolds/differentiable/automorphismfield_group.py +604 -0
  64. sage/manifolds/differentiable/bundle_connection.py +1445 -0
  65. sage/manifolds/differentiable/characteristic_cohomology_class.py +1840 -0
  66. sage/manifolds/differentiable/chart.py +1241 -0
  67. sage/manifolds/differentiable/curve.py +1028 -0
  68. sage/manifolds/differentiable/de_rham_cohomology.py +541 -0
  69. sage/manifolds/differentiable/degenerate.py +559 -0
  70. sage/manifolds/differentiable/degenerate_submanifold.py +1671 -0
  71. sage/manifolds/differentiable/diff_form.py +1658 -0
  72. sage/manifolds/differentiable/diff_form_module.py +1062 -0
  73. sage/manifolds/differentiable/diff_map.py +1315 -0
  74. sage/manifolds/differentiable/differentiable_submanifold.py +291 -0
  75. sage/manifolds/differentiable/examples/all.py +1 -0
  76. sage/manifolds/differentiable/examples/euclidean.py +2517 -0
  77. sage/manifolds/differentiable/examples/real_line.py +897 -0
  78. sage/manifolds/differentiable/examples/sphere.py +1186 -0
  79. sage/manifolds/differentiable/examples/symplectic_space.py +187 -0
  80. sage/manifolds/differentiable/examples/symplectic_space_test.py +40 -0
  81. sage/manifolds/differentiable/integrated_curve.py +4035 -0
  82. sage/manifolds/differentiable/levi_civita_connection.py +841 -0
  83. sage/manifolds/differentiable/manifold.py +4254 -0
  84. sage/manifolds/differentiable/manifold_homset.py +1826 -0
  85. sage/manifolds/differentiable/metric.py +3032 -0
  86. sage/manifolds/differentiable/mixed_form.py +1507 -0
  87. sage/manifolds/differentiable/mixed_form_algebra.py +559 -0
  88. sage/manifolds/differentiable/multivector_module.py +800 -0
  89. sage/manifolds/differentiable/multivectorfield.py +1520 -0
  90. sage/manifolds/differentiable/poisson_tensor.py +268 -0
  91. sage/manifolds/differentiable/pseudo_riemannian.py +755 -0
  92. sage/manifolds/differentiable/pseudo_riemannian_submanifold.py +1839 -0
  93. sage/manifolds/differentiable/scalarfield.py +1343 -0
  94. sage/manifolds/differentiable/scalarfield_algebra.py +472 -0
  95. sage/manifolds/differentiable/symplectic_form.py +910 -0
  96. sage/manifolds/differentiable/symplectic_form_test.py +220 -0
  97. sage/manifolds/differentiable/tangent_space.py +412 -0
  98. sage/manifolds/differentiable/tangent_vector.py +616 -0
  99. sage/manifolds/differentiable/tensorfield.py +4665 -0
  100. sage/manifolds/differentiable/tensorfield_module.py +963 -0
  101. sage/manifolds/differentiable/tensorfield_paral.py +2450 -0
  102. sage/manifolds/differentiable/tensorfield_paral_test.py +16 -0
  103. sage/manifolds/differentiable/vector_bundle.py +1728 -0
  104. sage/manifolds/differentiable/vectorfield.py +1717 -0
  105. sage/manifolds/differentiable/vectorfield_module.py +2445 -0
  106. sage/manifolds/differentiable/vectorframe.py +1832 -0
  107. sage/manifolds/family.py +270 -0
  108. sage/manifolds/local_frame.py +1490 -0
  109. sage/manifolds/manifold.py +3090 -0
  110. sage/manifolds/manifold_homset.py +452 -0
  111. sage/manifolds/operators.py +359 -0
  112. sage/manifolds/point.py +994 -0
  113. sage/manifolds/scalarfield.py +3718 -0
  114. sage/manifolds/scalarfield_algebra.py +629 -0
  115. sage/manifolds/section.py +3111 -0
  116. sage/manifolds/section_module.py +831 -0
  117. sage/manifolds/structure.py +229 -0
  118. sage/manifolds/subset.py +2764 -0
  119. sage/manifolds/subsets/all.py +1 -0
  120. sage/manifolds/subsets/closure.py +131 -0
  121. sage/manifolds/subsets/pullback.py +885 -0
  122. sage/manifolds/topological_submanifold.py +891 -0
  123. sage/manifolds/trivialization.py +733 -0
  124. sage/manifolds/utilities.py +1348 -0
  125. sage/manifolds/vector_bundle.py +1342 -0
  126. sage/manifolds/vector_bundle_fiber.py +332 -0
  127. sage/manifolds/vector_bundle_fiber_element.py +111 -0
  128. sage/matrix/all__sagemath_symbolics.py +1 -0
  129. sage/matrix/matrix_symbolic_dense.cpython-314t-darwin.so +0 -0
  130. sage/matrix/matrix_symbolic_dense.pxd +6 -0
  131. sage/matrix/matrix_symbolic_dense.pyx +1022 -0
  132. sage/matrix/matrix_symbolic_sparse.cpython-314t-darwin.so +0 -0
  133. sage/matrix/matrix_symbolic_sparse.pxd +6 -0
  134. sage/matrix/matrix_symbolic_sparse.pyx +1029 -0
  135. sage/modules/all__sagemath_symbolics.py +1 -0
  136. sage/modules/vector_callable_symbolic_dense.py +105 -0
  137. sage/modules/vector_symbolic_dense.py +116 -0
  138. sage/modules/vector_symbolic_sparse.py +118 -0
  139. sage/rings/all__sagemath_symbolics.py +4 -0
  140. sage/rings/asymptotic/all.py +6 -0
  141. sage/rings/asymptotic/asymptotic_expansion_generators.py +1485 -0
  142. sage/rings/asymptotic/asymptotic_ring.py +4858 -0
  143. sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +4153 -0
  144. sage/rings/asymptotic/growth_group.py +5373 -0
  145. sage/rings/asymptotic/growth_group_cartesian.py +1400 -0
  146. sage/rings/asymptotic/term_monoid.py +5237 -0
  147. sage/rings/function_field/all__sagemath_symbolics.py +2 -0
  148. sage/rings/polynomial/all__sagemath_symbolics.py +1 -0
  149. sage/symbolic/all.py +15 -0
  150. sage/symbolic/assumptions.py +985 -0
  151. sage/symbolic/benchmark.py +93 -0
  152. sage/symbolic/callable.py +459 -0
  153. sage/symbolic/complexity_measures.py +35 -0
  154. sage/symbolic/constants.py +1287 -0
  155. sage/symbolic/expression_conversion_algebraic.py +310 -0
  156. sage/symbolic/expression_conversion_sympy.py +317 -0
  157. sage/symbolic/expression_conversions.py +1713 -0
  158. sage/symbolic/function_factory.py +355 -0
  159. sage/symbolic/integration/all.py +1 -0
  160. sage/symbolic/integration/external.py +270 -0
  161. sage/symbolic/integration/integral.py +1115 -0
  162. sage/symbolic/maxima_wrapper.py +162 -0
  163. sage/symbolic/operators.py +267 -0
  164. sage/symbolic/random_tests.py +462 -0
  165. sage/symbolic/relation.py +1907 -0
  166. sage/symbolic/ring.cpython-314t-darwin.so +0 -0
  167. sage/symbolic/ring.pxd +5 -0
  168. sage/symbolic/ring.pyx +1396 -0
  169. sage/symbolic/subring.py +1025 -0
  170. sage/symbolic/symengine.py +19 -0
  171. sage/symbolic/tests.py +40 -0
  172. sage/symbolic/units.py +1470 -0
sage/symbolic/units.py ADDED
@@ -0,0 +1,1470 @@
1
+ # sage_setup: distribution = sagemath-symbolics
2
+ """
3
+ Units of measurement
4
+
5
+ This is the units package. It contains information about many units
6
+ and conversions between them.
7
+
8
+ TUTORIAL:
9
+
10
+ To return a unit::
11
+
12
+ sage: units.length.meter
13
+ meter
14
+
15
+ This unit acts exactly like a symbolic variable::
16
+
17
+ sage: s = units.length.meter
18
+ sage: s^2
19
+ meter^2
20
+ sage: s + var('x')
21
+ meter + x
22
+
23
+ Units have additional information in their docstring::
24
+
25
+ sage: # You would type: units.force.dyne?
26
+ sage: print(units.force.dyne.__doc__)
27
+ CGS unit for force defined to be gram*centimeter/second^2.
28
+ Equal to 10^-5 newtons.
29
+
30
+
31
+ You may call the convert function with units::
32
+
33
+ sage: t = units.mass.gram*units.length.centimeter/units.time.second^2
34
+ sage: t.convert(units.mass.pound*units.length.foot/units.time.hour^2)
35
+ 5400000000000/5760623099*(foot*pound/hour^2)
36
+ sage: t.convert(units.force.newton)
37
+ 1/100000*newton
38
+
39
+ Calling the convert function with no target returns base SI units::
40
+
41
+ sage: t.convert()
42
+ 1/100000*kilogram*meter/second^2
43
+
44
+ Giving improper units to convert to raises a :exc:`ValueError`::
45
+
46
+ sage: t.convert(units.charge.coulomb)
47
+ Traceback (most recent call last):
48
+ ...
49
+ ValueError: Incompatible units
50
+
51
+ Converting temperatures works as well::
52
+
53
+ sage: s = 68*units.temperature.fahrenheit
54
+ sage: s.convert(units.temperature.celsius)
55
+ 20*celsius
56
+ sage: s.convert()
57
+ 293.150000000000*kelvin
58
+
59
+ Trying to multiply temperatures by another unit then converting raises a :exc:`ValueError`::
60
+
61
+ sage: wrong = 50*units.temperature.celsius*units.length.foot
62
+ sage: wrong.convert()
63
+ Traceback (most recent call last):
64
+ ...
65
+ ValueError: cannot convert
66
+
67
+ TESTS:
68
+
69
+ Check that :issue:`12373` is fixed::
70
+
71
+ sage: b = units.amount_of_substance.mole
72
+ sage: b.convert(units.amount_of_substance.elementary_entity)
73
+ 6.02214129000000e23*elementary_entity
74
+
75
+ AUTHORS:
76
+
77
+ - David Ackerman
78
+ - William Stein
79
+ """
80
+
81
+ ###############################################################################
82
+ # Sage: Open Source Mathematical Software
83
+ # Copyright (C) 2009 David Ackerman <davidnackerman@gmail.com>
84
+ # William Stein <wstein@gmail.com>
85
+ # Distributed under the terms of the GNU General Public License (GPL),
86
+ # version 2 or any later version. The full text of the GPL is available at:
87
+ # https://www.gnu.org/licenses/
88
+ ###############################################################################
89
+
90
+ # standard Python libraries
91
+ import re
92
+
93
+ # Sage library
94
+ from .ring import SR
95
+ from .expression import Expression
96
+ from sage.interfaces.tab_completion import ExtraTabCompletion
97
+ from sage.misc.instancedoc import instancedoc
98
+ from sage.rings.rational_field import QQ
99
+
100
+ ###############################################################################
101
+ # Unit conversions dictionary.
102
+ ###############################################################################
103
+ one = QQ.one()
104
+
105
+
106
+ unitdict = {
107
+ 'acceleration':
108
+ {'gal': one / 100,
109
+ 'galileo': one / 100,
110
+ 'gravity': '9.80665000000000'},
111
+
112
+ 'amount_of_substance':
113
+ {'elementary_entity': '1/6.02214129000000e23',
114
+ 'mole': 1},
115
+
116
+ 'angles':
117
+ {'arc_minute': '1/10800*pi',
118
+ 'arc_second': '1/648000*pi',
119
+ 'degree': '1/180*pi',
120
+ 'grade': '1/200*pi',
121
+ 'quadrant': '1/2*pi',
122
+ 'radian': 1,
123
+ 'right_angle': '1/2*pi'},
124
+
125
+ 'area':
126
+ {'acre': QQ(316160658) / 78125,
127
+ 'are': 100,
128
+ 'barn': one / 10000000000000000000000000000,
129
+ 'hectare': 10000,
130
+ 'rood': QQ(158080329) / 156250,
131
+ 'section': QQ(40468564224) / 15625,
132
+ 'square_chain': QQ(158080329) / 390625,
133
+ 'square_meter': 1,
134
+ 'township': QQ(1456868312064) / 15625},
135
+
136
+ 'capacitance':
137
+ {'abfarad': 1000000000,
138
+ 'farad': 1,
139
+ 'statfarad': QQ(25000) / 22468879468420441},
140
+
141
+ 'charge':
142
+ {'abcoulomb': 10,
143
+ 'coulomb': 1,
144
+ 'elementary_charge': '1.60217646200000e-19',
145
+ 'faraday': '96485.3399000000',
146
+ 'franklin': one / 2997924580,
147
+ 'statcoulomb': one / 2997924580},
148
+
149
+ 'conductance':
150
+ {'abmho': 1000000000,
151
+ 'mho': 1,
152
+ 'siemens': 1},
153
+
154
+ 'current':
155
+ {'abampere': 10,
156
+ 'amp': 1,
157
+ 'ampere': 1,
158
+ 'biot': 10,
159
+ 'statampere': one / 2997924580},
160
+
161
+ 'electric_potential':
162
+ {'abvolt': one / 100000000,
163
+ 'statvolt': QQ(149896229) / 500000,
164
+ 'volt': 1},
165
+
166
+ 'energy':
167
+ {'british_thermal_unit': QQ(52752792631) / 50000000,
168
+ 'btu': QQ(52752792631) / 50000000,
169
+ 'calorie': QQ(10467) / 2500,
170
+ 'electron_volt': '1.60217733000000e-19',
171
+ 'erg': one / 10000000,
172
+ 'ev': '1.60217733000000e-19',
173
+ 'joule': 1,
174
+ 'rydberg': '2.17987200000000e-18',
175
+ 'therm': QQ(52752792631) / 500},
176
+
177
+ 'fiber_linear_mass_density':
178
+ {'denier': one / 9000000,
179
+ 'tex': one / 1000000},
180
+
181
+ 'force':
182
+ {'dyne': one / 100000,
183
+ 'gram_weight': QQ(196133) / 20000000,
184
+ 'kilogram_force': QQ(196133) / 20000,
185
+ 'kilogram_weight': QQ(196133) / 20000,
186
+ 'newton': 1,
187
+ 'pound_force': QQ(8896443230521) / 2000000000000,
188
+ 'pound_weight': QQ(8896443230521) / 2000000000000,
189
+ 'poundal': QQ(17281869297) / 125000000000,
190
+ 'ton_force': QQ(8896443230521) / 1000000000},
191
+
192
+ 'frequency':
193
+ {'1/second': 1,
194
+ 'hertz': 1},
195
+
196
+ 'illuminance':
197
+ {'foot_candle': QQ(1562500) / 145161,
198
+ 'lux': 1,
199
+ 'phot': 10000},
200
+
201
+ 'inductance':
202
+ {'abhenry': one / 1000000000,
203
+ 'henry': 1,
204
+ 'stathenry': QQ(22468879468420441) / 25000},
205
+
206
+ 'information':
207
+ {'bit': 1,
208
+ 'byte': 8,
209
+ 'nibble': 4},
210
+
211
+ 'information_rate':
212
+ {'baud': 1},
213
+
214
+ 'inverse_length':
215
+ {'diopter': 1,
216
+ 'kayser': 100},
217
+
218
+ 'length':
219
+ {'angstrom': one / 10000000000,
220
+ 'astronomical_unit': 149597870691,
221
+ 'bolt': QQ(4572) / 125,
222
+ 'cable_international': QQ(926) / 5,
223
+ 'cable_us': QQ(27432) / 125,
224
+ 'caliber': QQ(127) / 500000,
225
+ 'centimeter': one / 100,
226
+ 'chain': QQ(12573) / 625,
227
+ 'cicero': QQ(125) / 27706,
228
+ 'cubit': QQ(1143) / 2500,
229
+ 'didot': QQ(125) / 332472,
230
+ 'dtp_point': QQ(127) / 360000,
231
+ 'ell': QQ(1143) / 1000,
232
+ 'fathom': QQ(1143) / 625,
233
+ 'feet': QQ(381) / 1250,
234
+ 'fermi': one / 1000000000000000,
235
+ 'foot': QQ(381) / 1250,
236
+ 'furlong': QQ(25146) / 125,
237
+ 'hand': QQ(127) / 1250,
238
+ 'inch': QQ(127) / 5000,
239
+ 'kilometer': 1000,
240
+ 'league': QQ(603504) / 125,
241
+ 'light_year': 9460730472580800,
242
+ 'link': QQ(12573) / 62500,
243
+ 'meter': 1,
244
+ 'micron': one / 1000000,
245
+ 'mil': QQ(127) / 5000000,
246
+ 'millimeter': one / 1000,
247
+ 'mile': QQ(201168) / 125,
248
+ 'nautical_mile': 1852,
249
+ 'parsec': '3.08570000000000e16',
250
+ 'perch': QQ(12573) / 2500,
251
+ 'pica': QQ(127) / 30000,
252
+ 'pole': QQ(12573) / 2500,
253
+ 'rod': QQ(12573) / 2500,
254
+ 'rope': QQ(762) / 125,
255
+ 'skein': QQ(13716) / 125,
256
+ 'stadion': QQ(118491) / 625,
257
+ 'stadium': QQ(115443) / 625,
258
+ 'statute_mile': QQ(201168) / 125,
259
+ 'survey_foot': QQ(1200) / 3937,
260
+ 'survey_mile': QQ(6336000) / 3937,
261
+ 'x_unit': '1.00210000000000e-13',
262
+ 'yard': QQ(1143) / 1250},
263
+
264
+ 'luminance':
265
+ {'apostilb': '1/pi',
266
+ 'lambert': '10000/pi',
267
+ 'nit': 1,
268
+ 'stilb': 10000},
269
+
270
+ 'luminous_energy':
271
+ {'lumerg': 1,
272
+ 'talbot': 1},
273
+
274
+ 'luminous_flux':
275
+ {'lumen': 1},
276
+
277
+ 'luminous_intensity':
278
+ {'candela': 1,
279
+ 'candle': 1,
280
+ 'hefnerkerze': QQ(1019) / 1128},
281
+
282
+ 'magnetic_field':
283
+ {'gauss': one / 10000,
284
+ 'tesla': 1},
285
+
286
+ 'magnetic_flux':
287
+ {'maxwell': one / 100000000,
288
+ 'weber': 1},
289
+
290
+ 'magnetic_intensity':
291
+ {'oersted': '250/pi'},
292
+
293
+ 'magnetic_moment':
294
+ {'bohr_magneton': '9.27400915000000e-24',
295
+ 'nuclear_magneton': '5.05078324000000e-27'},
296
+
297
+ 'magnetomotive_force':
298
+ {'ampere_turn': 1,
299
+ 'gilbert': '5/2/pi'},
300
+
301
+ 'mass':
302
+ {'amu': '1.66053878200000e-27',
303
+ 'assay_ton': QQ(7) / 240,
304
+ 'atomic_mass_unit': '1.66053878200000e-27',
305
+ 'avoirdupois_ounce': QQ(45359237) / 1600000000,
306
+ 'avoirdupois_pound': QQ(45359237) / 100000000,
307
+ 'bale': QQ(45359237) / 200000,
308
+ 'carat': one / 5000,
309
+ 'cental': QQ(45359237) / 1000000,
310
+ 'dalton': '1.66053878200000e-27',
311
+ 'drachma': "(0.00429234000000000, {'greek':1})",
312
+ 'geepound': QQ(14593903) / 1000000,
313
+ 'grain': QQ(6479891) / 100000000000,
314
+ 'gram': one / 1000,
315
+ 'gross_hundredweight': QQ(317514659) / 6250000,
316
+ 'hundredweight': QQ(317514659) / 6250000,
317
+ 'kilogram': 1,
318
+ 'libra': '0.325971000000000',
319
+ 'long_ton': QQ(317514659) / 312500,
320
+ 'metric_ton': '1000',
321
+ 'mina': "(0.429234000000000, {'greek':100})",
322
+ 'net_hundredweight': QQ(45359237) / 1000000,
323
+ 'obol': "(0.000715380000000000,{'greek':1/6})",
324
+ 'ounce': QQ(45359237) / 1600000000,
325
+ 'ounce_troy': QQ(19439673) / 625000000,
326
+ 'pennyweight': QQ(19439673) / 12500000000,
327
+ 'pondus': '0.325969000000000',
328
+ 'pound': QQ(45359237) / 100000000,
329
+ 'pound_troy': QQ(58319019) / 156250000,
330
+ 'quintal': 100,
331
+ 'shekel': '0.0141000000000000',
332
+ 'short_hundredweight': QQ(45359237) / 1000000,
333
+ 'short_ton': QQ(45359237) / 50000,
334
+ 'slug': QQ(14593903) / 1000000,
335
+ 'solar_mass': '1.98892000000000e30',
336
+ 'stone': QQ(317514659) / 50000000,
337
+ 'talent': "(25.7540400000000, {'greek':6000})",
338
+ 'ton': QQ(45359237) / 50000,
339
+ 'tonne': 1000,
340
+ 'wey': QQ(2857631931) / 25000000},
341
+
342
+ 'power':
343
+ {'cheval_vapeur': QQ(588399) / 800,
344
+ 'horsepower': QQ(37284993579113511) / 50000000000000,
345
+ 'watt': 1},
346
+
347
+ 'pressure':
348
+ {'atmosphere': 101325,
349
+ 'bar': 100000,
350
+ 'barye': QQ((1, 10)),
351
+ 'inch_mercury': '3386.38900000000',
352
+ 'millimeter_mercury': '133.322400000000',
353
+ 'mmhg': '133.322400000000',
354
+ 'pa': 1,
355
+ 'pascal': 1,
356
+ 'pounds_per_square_inch': QQ(8896443230521) / 1290320000,
357
+ 'psi': QQ(8896443230521) / 1290320000,
358
+ 'torr': QQ(20265) / 152},
359
+
360
+ 'radiation':
361
+ {'becquerel': 1,
362
+ 'curie': 37000000000,
363
+ 'rutherford': 1000000},
364
+
365
+ 'radiation_absorbed':
366
+ {'gray': 1,
367
+ 'rad': one / 100},
368
+
369
+ 'radiation_ionizing':
370
+ {'roentgen': '0.000258000000000000',
371
+ 'rontgen': '0.000258000000000000'},
372
+
373
+ 'resistance':
374
+ {'abohm': one / 1000000000,
375
+ 'ohm': 1,
376
+ 'statohm': QQ(22468879468420441) / 25000},
377
+
378
+ 'si_prefixes':
379
+ {'atto': one / 1000000000000000000,
380
+ 'centi': one / 100,
381
+ 'deca': 10,
382
+ 'deci': QQ((1, 10)),
383
+ 'exa': 1000000000000000000,
384
+ 'femto': one / 1000000000000000,
385
+ 'giga': 1000000000,
386
+ 'hecto': 100,
387
+ 'kilo': 1000,
388
+ 'mega': 1000000,
389
+ 'micro': one / 1000000,
390
+ 'milli': one / 1000,
391
+ 'nano': one / 1000000000,
392
+ 'peta': 1000000000000000,
393
+ 'pico': one / 1000000000000,
394
+ 'tera': 1000000000000,
395
+ 'yocto': one / 1000000000000000000000000,
396
+ 'yotta': 1000000000000000000000000,
397
+ 'zepto': one / 1000000000000000000000,
398
+ 'zetta': 1000000000000000000000},
399
+
400
+ 'solid_angle':
401
+ {'steradian': 1},
402
+
403
+ 'temperature':
404
+ {'celsius': '(x + 273.15), (x), (x*9/5 + 32), ((x+273.15)*9/5)',
405
+ 'centigrade': '(x + 273.15), (x), (x*9/5 + 32), ((x+273.15)*9/5)',
406
+ 'fahrenheit': '(5/9*(x + 459.67)), ((x - 32)*5/9), (x), (x+459.67)',
407
+ 'kelvin': '(x), (x - 273.15), (x*9/5 - 459.67), (x*9/5)',
408
+ 'rankine': '(5/9*x), ((x-491.67)*5/9), (x-459.67), (x)'},
409
+
410
+ 'time':
411
+ {'century': 3153600000,
412
+ 'day': 86400,
413
+ 'decade': 315360000,
414
+ 'fortnight': 1209600,
415
+ 'hour': 3600,
416
+ 'millenium': 31536000000,
417
+ 'minute': 60,
418
+ 'month': 2628000,
419
+ 'second': 1,
420
+ 'sidereal_day': "(86164.0905308330, {'sidereal':86400})",
421
+ 'sidereal_second': "(0.997269566329086, {'sidereal':1})",
422
+ 'sidereal_year': '3.15581497632000e7',
423
+ 'tropical_year': '3.15569251779840e7',
424
+ 'week': 604800,
425
+ 'year': 31536000},
426
+
427
+ 'unit_multipliers':
428
+ {'bakers_dozen': 13,
429
+ 'dozen': 12,
430
+ 'gross': 144,
431
+ 'percent': one / 100},
432
+
433
+ 'velocity':
434
+ {'knot': '463/900'},
435
+
436
+ 'viscosity_absolute':
437
+ {'poise': one / 10,
438
+ 'reyn': QQ(8896443230521) / 1290320000},
439
+
440
+ 'viscosity_kinematic':
441
+ {'stokes': one / 10000},
442
+
443
+ 'viscosity_other':
444
+ {'rhes': 10},
445
+
446
+ 'volume':
447
+ {'bag': QQ(660732565629) / 6250000000000,
448
+ 'barrel': QQ(9936705933) / 62500000000,
449
+ 'board_foot': QQ(18435447) / 7812500000,
450
+ 'bucket': QQ(473176473) / 31250000000,
451
+ 'bushel': QQ(220244188543) / 6250000000000,
452
+ 'butt': QQ(29810117799) / 62500000000,
453
+ 'cord': QQ(884901456) / 244140625,
454
+ 'cubic_meter': 1,
455
+ 'cup': QQ(473176473) / 2000000000000,
456
+ 'ephah': QQ(1982197696887) / 50000000000000,
457
+ 'fifth': QQ(473176473) / 625000000000,
458
+ 'firkin': QQ(4091481) / 100000000,
459
+ 'fluid_dram': QQ(473176473) / 128000000000000,
460
+ 'fluid_ounce': QQ(473176473) / 16000000000000,
461
+ 'gallon': QQ(473176473) / 125000000000,
462
+ 'gill': QQ(473176473) / 4000000000000,
463
+ 'hogshead': QQ(29810117799) / 125000000000,
464
+ 'imperial_gallon': QQ(454609) / 100000000,
465
+ 'imperial_pint': QQ(454609) / 800000000,
466
+ 'jeroboam': QQ(473176473) / 156250000000,
467
+ 'jigger': QQ(1419529419) / 32000000000000,
468
+ 'liter': one / 1000,
469
+ 'magnum': QQ(473176473) / 250000000000,
470
+ 'minim': QQ(157725491) / 2560000000000000,
471
+ 'noggin': QQ(473176473) / 4000000000000,
472
+ 'omer': QQ(1982197696887) / 500000000000000,
473
+ 'peck': QQ(220244188543) / 25000000000000,
474
+ 'pint': QQ(473176473) / 1000000000000,
475
+ 'pony': QQ(1419529419) / 64000000000000,
476
+ 'puncheon': QQ(9936705933) / 31250000000,
477
+ 'quart': QQ(473176473) / 500000000000,
478
+ 'register_ton': QQ(55306341) / 19531250,
479
+ 'seam': QQ(220244188543) / 781250000000,
480
+ 'shot': QQ(473176473) / 16000000000000,
481
+ 'stere': 1,
482
+ 'tablespoon': QQ(473176473) / 32000000000000,
483
+ 'teaspoon': QQ(157725491) / 32000000000000,
484
+ 'tun': QQ(29810117799) / 31250000000,
485
+ 'uk_gallon': QQ(454609) / 100000000,
486
+ 'uk_pint': QQ(454609) / 800000000,
487
+ 'wine_bottle': QQ(3) / 4000}
488
+ }
489
+
490
+ unit_to_type = {}
491
+ value_to_unit = {}
492
+
493
+
494
+ def evalunitdict():
495
+ """
496
+ Replace all the string values of the unitdict variable by their
497
+ evaluated forms, and builds some other tables for ease of use.
498
+ This function is mainly used internally, for efficiency (and
499
+ flexibility) purposes, making it easier to describe the units.
500
+
501
+ EXAMPLES::
502
+
503
+ sage: sage.symbolic.units.evalunitdict()
504
+ """
505
+ from sage.misc.sage_eval import sage_eval
506
+ for key, value in unitdict.items():
507
+ unitdict[key] = {a: (sage_eval(repr(b)) if isinstance(b, str) else b)
508
+ for a, b in value.items()}
509
+
510
+ # FEATURE IDEA: create a function that would allow users to add
511
+ # new entries to the table without having to know anything about
512
+ # how the table is stored internally.
513
+
514
+ #
515
+ # Format the table for easier use.
516
+ #
517
+ for k, v in unitdict.items():
518
+ for a in v:
519
+ unit_to_type[a] = k
520
+
521
+ for w in unitdict:
522
+ for j in unitdict[w]:
523
+ if isinstance(unitdict[w][j], tuple):
524
+ unitdict[w][j] = unitdict[w][j][0]
525
+ value_to_unit[w] = {b: a for a, b in unitdict[w].items()}
526
+
527
+
528
+ ###############################################################################
529
+ # Documentation for individual units.
530
+ # Appears in unit's docstring.
531
+ ###############################################################################
532
+
533
+ unit_docs = {
534
+ 'acceleration_docs':
535
+ {'gal': 'Abbreviation for galileo.\nDefined to be 1/100 meter/second^2.',
536
+ 'galileo': 'Defined to be 1/100 meter/second^2.',
537
+ 'gravity': 'Also called standard gravity.\nPhysical constant defined to be 9.80665 meter/second^2.'},
538
+
539
+ 'amount_of_substance_docs':
540
+ {'elementary_entity': 'Defined to be one elementary unit of choice, usually atoms or other elementary particles.\nApproximately equal to 1.6605e-24 moles.',
541
+ 'mole': 'SI base unit of quantity.\nDefined to be the amount of substance that has an equal number of elementary entities as there are atoms in 12 grams of carbon-12.\nEquivalent to Avogadros constant elementary entities or approximately equal to 6.022*10^23 elementary entities.'},
542
+
543
+ 'angles_docs':
544
+ {'arc_minute': 'Defined to be 1/60 of a degree or pi/10800 radians.',
545
+ 'arc_second': 'Defined to be 1/3600 of a degree or pi/648000 radians.',
546
+ 'degree': 'Defined to be pi/180 radians.',
547
+ 'grade': 'Defined to be pi/200 radians.',
548
+ 'quadrant': 'Equivalent to a right angle.\nDefined to be pi/2 radians.',
549
+ 'radian': 'SI derived unit of angle.\nDefined to be the angle subtended at the center of a circle by an arc that is equal in length to the radius of the circle.',
550
+ 'right_angle': 'Equivalent to a quadrant.\nDefined to be pi/2 radians.'},
551
+
552
+ 'area_docs':
553
+ {'acre': 'Defined to be 10 square chains or 4840 square yards.\nApproximately equal to 4046.856 square meters.',
554
+ 'are': 'Defined to be 100 square meters.',
555
+ 'barn': 'Defined to be 100 square femtometers or 10^-28 square meters.',
556
+ 'hectare': 'Defined to be 10000 square meters.',
557
+ 'rood': 'Defined to be 1/4 of an acre.\nApproximately equal to 1011.714 square meters.',
558
+ 'section': 'Equivalent to a square mile.\nApproximately equal to 2.59*10^6 square meters.',
559
+ 'square_chain': 'Defined to be 4356 square feet.\nApproximately equal to 404.9856 square meters.',
560
+ 'square_meter': 'SI derived unit of area.\nDefined to be meter^2.',
561
+ 'township': 'Defined to be 36 square miles.\nApproximately equal to 9.324*10^7 square meters.'},
562
+
563
+ 'capacitance_docs':
564
+ {'abfarad': 'Defined to be 10^9 farads.',
565
+ 'farad': 'SI derived unit of capacitance.\nDefined to be the charge in coulombs a capacitor will accept for the potential across it to change one volt.\nEquivalent to coulomb/volt.',
566
+ 'statfarad': 'CGS unit defined to be statcoulomb/statvolt.\nApproximately equal to 1.11265*10^-12 farads.'},
567
+
568
+ 'charge_docs':
569
+ {'abcoulomb': 'CGS unit defined to be 10 coulombs.',
570
+ 'coulomb': 'SI derived unit of charge.\nDefined to be the amount of electric charge transported by 1 ampere in 1 second.',
571
+ 'elementary_charge': 'Defined to be the amount of electric charge carried by a single proton or negative charge carried by a single electron.\nApproximately equal to 1.602176462*10^-19 coulombs.',
572
+ 'faraday': 'Defined to be the magnitude of electric charge in one mole of electrons.\nApproximately equal to 96485.3399 coulombs.',
573
+ 'franklin': 'CGS unit defined to be the amount of electric charge necessary such that if two stationary objects placed one centimeter apart had one franklin of charge each they would repel each other with a force of one dyne.\nApproximately equal to 3.3356*10^-10 coulombs.',
574
+ 'statcoulomb': 'Equivalent to franklin.\nApproximately equal to 3.3356*10^-10 coulombs.'},
575
+
576
+ 'conductance_docs':
577
+ {'abmho': 'Defined to be 10^9 siemens.',
578
+ 'mho': 'Equivalent to siemens.',
579
+ 'siemens': 'SI derived unit of conductance.\nDefined to be an ampere per volt or 1/ohm.'},
580
+
581
+ 'current_docs':
582
+ {'abampere': 'CGS unit defined to be 10 amperes.',
583
+ 'amp': 'Abbreviation for ampere.',
584
+ 'ampere': 'SI base unit of current.\nDefined to be the constant current which will produce an attractive force of 2*10^-7 newtons per meter between two straight, parallel conductors of infinite length and negligible circular cross section placed one meter apart in free space.',
585
+ 'biot': 'Equivalent to abampere.\nEqual to 10 amperes.',
586
+ 'statampere': 'CGS unit defined to be statcoulomb/second.\nApproximately equal to 3.335641*10^-10 amperes.'},
587
+
588
+ 'electric_potential_docs':
589
+ {'abvolt': 'Defined to be 10^-8 volts.',
590
+ 'statvolt': 'CGS unit defined to be the speed of light in a vacuum/10^6 volts or approximately 299.792 volts.',
591
+ 'volt': 'SI derived unit of electric potential.\nDefined to be the value of voltage across a conductor when a current of one ampere dissipates one watt of power.'},
592
+
593
+ 'energy_docs':
594
+ {'british_thermal_unit': 'Defined to be the amount of energy required to raise the temperature of one pound of liquid water from 60 degrees Fahrenheit to 61 degrees Fahrenheit at a constant pressure of one atmosphere.\nApproximately equal to 1055.05585 joules.',
595
+ 'btu': 'Abbreviation for British thermal unit.\nApproximately equal to 1055.05585 joules.',
596
+ 'calorie': 'Defined to be the amount of energy required to raise the temperature of one gram of liquid water one degree Celsius.\nEqual to 4.1868 joules.',
597
+ 'electron_volt': 'Defined to be the amount of kinetic energy gained by a single unbound electron when it accelerates through an electrostatic potential difference of 1 volt.\nApproximately equal to 1.602*10^-19 joules.',
598
+ 'erg': 'CGS unit for energy defined to be gram*centimeter^2/second^2.\nEqual to 10^-7 joules.',
599
+ 'ev': 'Abbreviation for electron volt.\nApproximately equal to 1.602*10^-19 joules.',
600
+ 'joule': 'SI derived unit of energy.\nDefined to be kilogram*meter^2/second^2.',
601
+ 'rydberg': 'Defined to be the absolute value of the binding energy of the electron in the ground state hydrogen atom.\nApproximately equal to 2.17987*10^-18 joules.',
602
+ 'therm': 'Defined to be 100,000 British thermal units.\nApproximately equal to 1.05505585*10^8 joules.'},
603
+
604
+ 'fiber_linear_mass_density_docs':
605
+ {'denier': 'Defined to be 1 gram per 9000 meters.\nEqual to 1/9000000 of a kilogram/meter.',
606
+ 'tex': 'Defined to be 1 gram per 1000 meters.\nEqual to 1/1000000 of a kilogram/meter.'},
607
+
608
+ 'force_docs':
609
+ {'dyne': 'CGS unit for force defined to be gram*centimeter/second^2.\nEqual to 10^-5 newtons.',
610
+ 'gram_weight': 'Defined to be the magnitude of the force exerted on one gram of mass by a 9.80665 meter/second^2 gravitational field.\nEqual to 1/1000 of a kilogram weight.\nEqual to 0.00980665 newtons.',
611
+ 'kilogram_force': 'Equivalent to a kilogram weight.\nEqual to 9.80665 newtons.',
612
+ 'kilogram_weight': 'Defined to be the magnitude of the force exerted on one kilogram of mass by a 9.80665 meter/second^2 gravitational field.\nEqual to 9.80665 newtons.',
613
+ 'newton': 'SI derived unit of force.\nDefined to be kilogram*meter/second^2.',
614
+ 'pound_force': 'Equivalent to a pound weight.\nApproximately equal to 4.44822 newtons.',
615
+ 'pound_weight': 'Defined to be the magnitude of the force exerted on one pound of mass by a 9.80665 meter/second^2 gravitational field.\nApproximately equal to 4.44822 newtons.',
616
+ 'poundal': 'Defined to be pound*foot/second^2.\nApproximately equal to 0.13825 newtons.',
617
+ 'ton_force': 'Defined to be 2000 pounds of force.\nApproximately equal to 8896.4432 newtons.'},
618
+
619
+ 'frequency_docs':
620
+ {'hertz': 'SI derived unit of frequency.\nDefined to be one complete cycle per second.'},
621
+
622
+ 'illuminance_docs':
623
+ {'foot_candle': 'Defined to be lumen/foot^2.\nApproximately equal to 10.764 lux.',
624
+ 'lux': 'SI derived unit of illuminance.\nDefined to be lumen/meter^2.',
625
+ 'phot': 'CGS unit defined to be 10000 lux.'},
626
+
627
+ 'inductance_docs':
628
+ {'abhenry': 'Defined to be 10^-9 henries.',
629
+ 'henry': 'SI derived unit of inductance./nDefined to be a volt per ampere per second.',
630
+ 'stathenry': 'CGS unit defined to be one statvolt*second/statampere.\nApproximately equal to 8.98758*10^11 henries.'},
631
+
632
+ 'information_docs':
633
+ {'bit': 'Base unit of information.\nDefined to be the maximum amount of information that can be stored by a device of other physical system that can normally exist in only two distinct states.',
634
+ 'byte': 'Defined to be 8 bits.',
635
+ 'nibble': 'Defined to be 4 bits.'},
636
+
637
+ 'information_rate_docs':
638
+ {'baud': 'Defined to be 1 bit/second.'},
639
+
640
+ 'inverse_length_docs':
641
+ {'diopter': 'Defined to be 1/meter.',
642
+ 'kayser': 'Defined to be 100/meter.'},
643
+
644
+ 'length_docs':
645
+ {'angstrom': 'Defined to be 10^-10 meters.',
646
+ 'astronomical_unit': 'Originally defined as the length of the semi-major axis of the elliptical orbit of the Earth around the Sun.\nRedefined for accuracy to be the radius of an unperturbed circular Newtonian orbit about the Sun of a particle having infinitesimal mass, moving with a mean motion of 0.01720209895 radians per day.\nApproximately equal to 1.496*10^11 meters.',
647
+ 'bolt': 'Defined to be 40 yards.\nEqual to 36.576 meters.',
648
+ 'cable_international': 'Nautical unit defined to be 1/10 of a nautical mile.\nEqual to 185.2 meters.',
649
+ 'cable_us': 'Nautical unit defined to be equal to 720 feet or 120 fathoms.\nEqual to 219.456 meters.',
650
+ 'caliber': 'Equal to 1/100 of an inch.\nEqual to 0.000254 meters.',
651
+ 'centimeter': 'Equal to 1/100 of a meter.',
652
+ 'chain': 'Surveying unit defined to be 66 feet.\nApproximately equal to 20.12 meters.',
653
+ 'cicero': 'Printing unit defined to be 12 didot points.\nApproximately equal to 0.004512 meters.',
654
+ 'cubit': 'Ancient unit of length defined to be 18 inches.\nEqual to 0.4572 meters.',
655
+ 'didot': 'Printing unit equal to 1/12 of a cicero.\nApproximately equal to 0.00037597 meters.',
656
+ 'dtp_point': 'The desktop publishing point is defined to be 1/72 of an inch.\nApproximately equal to 0.0003528 meters.',
657
+ 'ell': 'Ancient unit of length defined to be 45 inches.\nEqual to 1.143 meters.',
658
+ 'fathom': 'Nautical unit defined to be 6 feet.\nEqual to 1.8288 meters.',
659
+ 'feet': 'Equal to 12 inches.\nDefined to be 0.3048 meters.',
660
+ 'fermi': 'Equivalent to a femtometer.\nEqual to 10^-15 meters.',
661
+ 'foot': 'Equal to 12 inches.\nDefined to be 0.3048 meters.',
662
+ 'furlong': 'Defined to be 660 feet, or 1/8 of a mile.\nEqual to 201.168 meters.',
663
+ 'hand': 'Defined to be 4 inches.\nEqual to 0.1016 meters.',
664
+ 'inch': 'Equal to 1/12 of a foot.\nEqual to 0.0254 meters.',
665
+ 'kilometer': 'Equal to 1000 meters.\nEqual to 3280.8399 feet.',
666
+ 'league': 'Defined to be 3 miles.\nConventionally equal to the distance a person or horse can walk in one hour.\nEqual to 4828.032 meters.',
667
+ 'light_year': 'Defined to be the distance light travels in vacuum in 365.25 days.\nApproximately equal to 9.4607*10^15 meters.',
668
+ 'link': 'Surveying unit defined to be 1/100 of a chain.\nEqual to 0.201168 meters.',
669
+ 'meter': 'SI base unit of length.\nDefined to be the distance light travels in vacuum in 1/299792458 of a second.',
670
+ 'micron': 'Defined to be 10^-6 meters.',
671
+ 'mil': 'Defined to be 1/1000 of an inch.\nEqual to 0.0000254 meters.',
672
+ 'millimeter': 'Defined to be 1/1000 of a meter.\nEqual to 0.001 meters.',
673
+ 'mile': 'Defined to be 5280 feet.\nEqual to 1609.344 meters.',
674
+ 'nautical_mile': 'Nautical unit defined to be 1852 meters.',
675
+ 'parsec': 'Defined to be the length of the adjacent side of a right triangle whose angle is 1 arcsecond and opposite side equal to 1 astronomical unit, or 1 AU/arctan(1 arcsecond).\nApproximately equal to 30.857*10^15 meters.',
676
+ 'perch': 'Equivalent to rod.\nDefined to be 16.5 feet.\nEqual to 5.0292 meters.',
677
+ 'pica': 'Printing unit defined to be 12 dtp points.\nEqual to 1/72 of a foot.\nApproximately equal to 0.004233 meters.',
678
+ 'pole': 'Equivalent to rod.\nDefined to be 16.5 feet.\nEqual to 5.0292 meters.',
679
+ 'rod': 'Defined to be 16.5 feet.\nEqual to 5.0292 meters.',
680
+ 'rope': 'Defined to be 20 feet.\nEqual to 6.096 meters.',
681
+ 'skein': 'Defined to be 360 feet.\nEqual to 109.728 meters.',
682
+ 'stadion': 'Ancient unit of length defined to be 622 feet.\nEqual to 189.5856 meters.',
683
+ 'stadium': 'Defined to be 202 yards or 606 feet.\nEqual to 184.7088 meters.',
684
+ 'statute_mile': 'Equivalent to mile.\nDefined to be 5280 feet.\nEqual to 1609.344 meters.',
685
+ 'survey_foot': 'Defined to be 1200/3937 or approximately 0.3048006 meters.',
686
+ 'survey_mile': 'Defined to be 5280 survey feet.\nApproximately equal to 1609.347 meters.',
687
+ 'x_unit': 'Unit of length used to quote wavelengths of X-rays and gamma rays.\nApproximately equal to 1.0021*10^-13 meters.',
688
+ 'yard': 'Defined to be 3 feet.\nEqual to 0.9144 meters.'},
689
+
690
+ 'luminance_docs':
691
+ {'apostilb': 'Defined to be 10^-4 lamberts.\nEqual to 1/pi*candela/meter^2.',
692
+ 'lambert': 'Defined to be 10^4/pi candela/meter^2.',
693
+ 'nit': 'Equivalent to candela/meter^2.',
694
+ 'stilb': 'CGS unit equal to 10000 candela/meter^2.'},
695
+
696
+ 'luminous_energy_docs':
697
+ {'lumerg': 'Equivalent to lumen*second',
698
+ 'talbot': 'Equivalent to lumen*second.'},
699
+
700
+ 'luminous_flux_docs':
701
+ {'lumen': 'SI derived unit of luminous flux.\nDefined to be candela*steradian.'},
702
+
703
+ 'luminous_intensity_docs':
704
+ {'candela': 'SI base unit of luminous intensity.\nDefined to be the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 540*10^12 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian.',
705
+ 'candle': 'Equivalent to candela.',
706
+ 'hefnerkerze': 'Old German unit defined to be a 8 millimeter wick burning amyl acetate with a flame height of 40 millimeters.\nApproximately equal to 0.9034 candelas.'},
707
+
708
+ 'magnetic_field_docs':
709
+ {'gauss': 'CGS unit defined to be a maxwell/centimeter^2.\nEqual to 1/10000 of a tesla.',
710
+ 'tesla': 'SI derived unit of magnetic field.\nDefined to be the magnitude of a magnetic field such that a particle with a charge of 1 coulomb passing through that field at 1 meter/second will experience a force of 1 newton.'},
711
+
712
+ 'magnetic_flux_docs':
713
+ {'maxwell': 'CGS unit defined to be a gauss*centimeter^2 or 10^-8 webers.',
714
+ 'weber': 'SI derived unit of magnetic flux.\nDefined to be a change in magnetic flux of 1 weber per second will induce an electromotive force of 1 volt.'},
715
+
716
+ 'magnetic_intensity_docs':
717
+ {'oersted': 'CGS unit defined to be 1000/(4*pi) amperes per meter of flux path.'},
718
+
719
+ 'magnetic_moment_docs':
720
+ {'bohr_magneton': 'Physical constant defined to be the magnetic moment of an electron, or elementary_charge*h_bar/2*electron_rest_mass.\nApproximately equal to 9.274*10^-24 joules/tesla.',
721
+ 'nuclear_magneton': 'Physical constant defined to be the magnetic moment of a proton, or elementary_charge*h_bar/2*proton_rest_mass.\nApproximately equal to 5.05078324*10^-27 joules/tesla.'},
722
+
723
+ 'magnetomotive_force_docs':
724
+ {'ampere_turn': 'SI derived unit of magnetomotive force.\nDefined to be a direct current of 1 ampere flowing through a single turn loop in a vacuum.',
725
+ 'gilbert': 'CGS unit defined to be 10/(4*pi) ampere turns.'},
726
+
727
+ 'mass_docs':
728
+ {'amu': 'Abbreviation for atomic mass unit.\nApproximately equal to 1.660538782*10^-27 kilograms.',
729
+ 'assay_ton': 'Defined to be milligram*short_ton/ounce_troy.\nEqual to 7/240 of a kilogram.',
730
+ 'atomic_mass_unit': 'Defined to be one twelfth of the mass of an isolated atom of carbon-12 at rest and in its ground state.\nApproximately equal to 1.660538782*10^-27 kilograms.',
731
+ 'avoirdupois_ounce': 'Equivalent to ounce.\nEqual to 1/16 of an avoirdupois pound.\nApproximately equal to 0.02835 kilograms.',
732
+ 'avoirdupois_pound': 'Equivalent to pound.\nEqual to 16 avoirdupois ounces.\nApproximately equal to 0.45359 kilograms.',
733
+ 'bale': 'Equal to 500 pounds.\nApproximately equal to 226.796 kilograms.',
734
+ 'carat': 'Defined to be equal to 200 milligrams.\nCommonly denoted ct.',
735
+ 'cental': 'Equal to 100 pounds.\nApproximately equal to 45.36 kilograms.',
736
+ 'dalton': 'Equivalent to atomic_mass_unit.\nApproximately equal to 1.660538782*10^-27 kilograms.',
737
+ 'drachma': 'Ancient Greek unit of mass.\nEqual to 6 obols.\nApproximately equal to 0.00429234 kilograms.',
738
+ 'geepound': 'Equivalent to slug.\nApproximately equal to 14.5939 kilograms.',
739
+ 'grain': 'Historically based on the average mass of a single seed of a typical cereal.\nDefined in 1958 to be 64.79891 milligrams.',
740
+ 'gram': 'Equal to 0.0001 kilograms.',
741
+ 'gross_hundredweight': 'Equivalent to hundredweight.\nEqual to 112 pounds.\nApproximately equal to 50.802 kilograms.',
742
+ 'hundredweight': 'Defined to be 112 pounds.\nApproximately equal to 50.802 kilograms.',
743
+ 'kilogram': 'SI base unit of mass.\nDefined to be equal to the mass of the International Prototype Kilogram.\nAlmost exactly equal to the amount of mass in one liter of water.',
744
+ 'libra': 'Ancient Roman unit of mass.\nApproximately equal to 0.325971 kilogram.',
745
+ 'long_ton': 'Defined to be 2240 pounds.\nApproximately equal to 1016.05 kilograms.',
746
+ 'metric_ton': 'Defined to be 1000 kilograms.',
747
+ 'mina': 'Ancient Greek unit of mass.\nEqual to 100 drachma.\nApproximately equal to 0.429234 kilograms.',
748
+ 'net_hundredweight': 'Equivalent to cental.\nEqual to 100 pounds.\nApproximately equal to 45.36 kilograms.',
749
+ 'obol': 'Ancient Greek unit of mass.\nEqual to 1/6 of drachma.\nApproximately equal to 0.00071538 kilograms.',
750
+ 'ounce': 'Equal to 1/16 of pound.\nCommonly abbreviated oz.\nApproximately equal to 0.02835 kilograms.',
751
+ 'ounce_troy': 'Equal to 1/12 of pound_troy.\nApproximately equal to 0.031103 kilograms.',
752
+ 'pennyweight': 'Equal to 1/20 of ounce_troy.\nCommonly abbreviated dwt.\nApproximately equal to 0.001555 kilograms.',
753
+ 'pondus': 'Ancient Roman unit of mass.\nApproximately equal to 0.325969 kilograms.',
754
+ 'pound': 'Equal to 16 ounces.\nDefined to be exactly 0.45359237 kilograms.',
755
+ 'pound_troy': 'Equal to 12 ounce_troy.\nApproximately equal to 0.37324 kilograms.',
756
+ 'quintal': 'Equal to 100 kilograms.',
757
+ 'shekel': 'Ancient Hebrew unit of mass.\nApproximately equal to 0.0141 kilograms.',
758
+ 'short_hundredweight': 'Equivalent to cental.\nEqual to 100 pounds.\nApproximately equal to 45.36 kilograms.',
759
+ 'short_ton': 'Equivalent to ton.\nEqual to 2000 pounds.\nApproximately equal to 907.18 kilograms.',
760
+ 'slug': 'Defined to be a mass that is accelerated 1 ft/s^2 when 1 pound_force is exerted on it.\nApproximately equal to 14.5939 kilograms.',
761
+ 'solar_mass': 'Defined to be the mass of the Sun.\nAbout 332,950 times the mass of the Earth or 1,048 times the mass of Jupiter.\nApproximately equal to 1.98892*10^30 kilograms.',
762
+ 'stone': 'Defined to be 14 pounds.\nApproximately equal to 6.35 kilograms.',
763
+ 'talent': 'Ancient Greek unit of mass.\nEqual to 6000 drachmae.\nApproximately equal to 25.754 kilograms.',
764
+ 'ton': 'Equal to 2000 pounds.\nApproximately equal to 907.18 kilograms.',
765
+ 'tonne': 'Equivalent to metric_ton.\nDefined to be 1000 kilograms.',
766
+ 'wey': 'Defined to be 252 pounds.\nApproximately equal to 114.305 kilograms.'},
767
+
768
+ 'power_docs':
769
+ {'cheval_vapeur': 'Defined to be 75 kilogram force*meter/second.\nAlso known as metric horsepower.\nEqual to 735.49875 watts.',
770
+ 'horsepower': 'Defined to be 550 feet*pound force/second.\nApproximately equal to 745.7 watts.',
771
+ 'watt': 'SI derived unit of power.\nDefined to be joule/second or, in base units, kilogram*meter^2/second^3.'},
772
+
773
+ 'pressure_docs':
774
+ {'atmosphere': 'Defined to be 101325 pascals.',
775
+ 'bar': 'Defined to be 100000 pascals.',
776
+ 'barye': 'CGS unit defined to be dyne/centimeter^2.\nEqual to 1/10 of a pascal.',
777
+ 'inch_mercury': 'Defined to be 13595.1 kilogram/meter^3*inch*gravity.\nApproximately equal to 3386.389 pascals.',
778
+ 'millimeter_mercury': 'Defined to be 13595.1 kilogram/meter^3*millimeter*gravity.\nApproximately equal to 133.3224 pascals.',
779
+ 'mmhg': 'Abbreviation for millimeter mercury.\nApproximately equal to 133.3224 pascals.',
780
+ 'pa': 'Abbreviation for pascal.',
781
+ 'pascal': 'SI derived unit of pressure.\nDefined to be newton/meter^2 or, in base units, kilogram/(meter*second^2).',
782
+ 'pounds_per_square_inch': 'Defined to be pound force/inch^2.\nApproximately equal to 6894.76 pascals.',
783
+ 'psi': 'Abbreviation for pounds per square inch.\nApproximately equal to 6894.76 pascals.',
784
+ 'torr': 'Defined to be 1/760 of an atmosphere.\nApproximately equal to 133.322 pascals.'},
785
+
786
+ 'radiation_absorbed_docs':
787
+ {'gray': 'SI derived unit of absorbed radiation.\nDefined to be the absorption of one joule of ionizing radiation by one kilogram of matter.',
788
+ 'rad': 'Defined to be 1/100 of a gray.'},
789
+
790
+ 'radiation_docs':
791
+ {'becquerel': 'SI derived unit of radiation.\nDefined to be the activity of a quantity of radioactive material in which one nucleus decays per second.',
792
+ 'curie': 'Defined to be 37*10^9 becquerels.',
793
+ 'rutherford': 'Defined to be 10^6 becquerels.'},
794
+
795
+ 'radiation_ionizing_docs':
796
+ {'roentgen': 'Defined to be .000258 coulombs/kilogram.',
797
+ 'rontgen': 'Equivalent to roentgen.\nDefined to be .000258 coulombs/kilogram.'},
798
+
799
+ 'resistance_docs':
800
+ {'abohm': 'Defined to be 10^-9 ohms.',
801
+ 'ohm': 'SI derived unit of resistance.\nDefined to be a volt per ampere.',
802
+ 'statohm': 'CGS unit defined to be statvolt/statampere.\nApproximately equal to 8.98758*10^11 ohms.'},
803
+
804
+ 'solid_angle_docs':
805
+ {'steradian': 'SI derived unit of solid angle.\nDefined to be the solid angle subtended at the center of a sphere of radius r by a portion of the surface of the sphere having an area of r^2.'},
806
+
807
+ 'temperature_docs':
808
+ {'celsius': 'Defined to be -273.15 at absolute zero and 0.01 at the triple point of Vienna Standard Mean Ocean Water.\nCelsius is related to kelvin by the equation K = 273.15 + degrees Celsius.\nA change of 1 degree Celsius is equivalent to a change of 1 degree kelvin.',
809
+ 'centigrade': 'Equivalent to celsius.',
810
+ 'fahrenheit': 'Defined to be 32 degrees at the freezing point of water and 212 degrees at the boiling point of water, both at standard pressure (1 atmosphere).\nFahrenheit is related to kelvin by the equation K = 5/9*(degrees Fahrenheit + 459.67).\nA change of 1 degree fahrenheit is equal to a change of 5/9 kelvin.',
811
+ 'kelvin': 'SI base unit of temperature.\nDefined to be exactly 0 at absolute zero and 273.16 at the triple point of Vienna Standard Mean Ocean Water.',
812
+ 'rankine': 'Defined to be 0 at absolute zero and to have the same degree increment as Fahrenheit.\nRankine is related to kelvin by the equation K = 5/9*R.'},
813
+
814
+ 'time_docs':
815
+ {'century': 'Defined to be 100 years.\nEqual to 3153600000 seconds.',
816
+ 'day': 'Defined to be 24 hours.\nEqual to 86400 seconds.',
817
+ 'decade': 'Defined to be 10 years.\nEqual to 315360000 seconds.',
818
+ 'fortnight': 'Defined to be 2 weeks or 14 days.\nEqual to 1209600 seconds.',
819
+ 'hour': 'Defined to be 60 minutes.\nEqual to 3600 seconds.',
820
+ 'millenium': 'Defined to be 1000 years.\nEqual to 31536000000 seconds.',
821
+ 'minute': 'Defined to be 60 seconds.',
822
+ 'month': 'Defined to be 30 days.\nEqual to 2628000 seconds.',
823
+ 'second': 'SI base unit of time.\nDefined to be the duration of 9,192,631,770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom.',
824
+ 'sidereal_day': 'Defined to be the time it takes for the Earth to make one complete rotation relative to the stars.\nApproximately equal to 86164.09 seconds.',
825
+ 'sidereal_second': 'Defined to be 1/86400 of a sidereal day.\nApproximately equal to 0.997269566329086 seconds.',
826
+ 'sidereal_year': 'Defined to be the time taken by the Earth to orbit the Sun once with respect to the fixed stars.\nApproximately equal to 31558149.7632 seconds.',
827
+ 'tropical_year': 'Defined to be the length of time that the Sun takes to return to the same position in the cycle of seasons, as seen from the Earth.\nApproximately equal to 31556925.1779840 seconds.',
828
+ 'week': 'Defined to be 7 days.\nEqual to 604800 seconds.',
829
+ 'year': 'Defined to be 365 days.\nEqual to 31536000 seconds.'},
830
+
831
+ 'unit_multipliers_docs':
832
+ {'bakers_dozen': 'Defined to be 13 items.',
833
+ 'dozen': 'Defined to be 12 items.',
834
+ 'gross': 'Defined to be 144 items.',
835
+ 'percent': 'Defined to be 1/100 of a quantity.'},
836
+
837
+ 'velocity_docs':
838
+ {'knot': 'Nautical unit of velocity defined to be a nautical mile per hour.\nApproximately equal to 0.5144 meter/second.'},
839
+
840
+ 'viscosity_absolute_docs':
841
+ {'poise': 'CGS unit defined to be 1/10 of pascal*second.',
842
+ 'reyn': 'Defined to be a pound_force*second/inch^2.\nApproximately equal to 6894.76 pascal*second.'},
843
+
844
+ 'viscosity_kinematic_docs':
845
+ {'stokes': 'CGS unit defined to be 1/10000 of meter^2/second.'},
846
+
847
+ 'viscosity_other_docs':
848
+ {'rhes': 'Defined to be 1/poise or 10/(pascal*second).'},
849
+
850
+ 'volume_docs':
851
+ {'bag': 'Defined to be 3 bushels.\nApproximately equal to 0.10572 cubic meters.',
852
+ 'barrel': 'Defined to be 42 gallons.\nApproximately equal to 0.15899 cubic meters.',
853
+ 'board_foot': 'Defined to be 144 cubic inches.\nApproximately equal to 0.0023597 cubic meters.',
854
+ 'bucket': 'Defined to be 4 gallons.\nApproximately equal to 0.0151416 cubic meters.',
855
+ 'bushel': 'Defined to be 2150.42 cubic inches.\nEquivalent to 4 pecks.\nApproximately equal to 0.035239 cubic meters.',
856
+ 'butt': 'Old English unit of wine casks defined to be 2 hogsheads or 126 gallons.\nApproximately equal to 0.476962 cubic meters.',
857
+ 'cord': 'Defined to be 8 feet x 8 feet x 4 feet.\nApproximately equal to 3.624556 cubic meters.',
858
+ 'cubic_meter': 'SI derived unit of volume.\nDefined to be meter^3.',
859
+ 'cup': 'Defined to be 8 fluid ounces.\nApproximately equal to 0.000236588 cubic meters.',
860
+ 'ephah': 'Ancient Hebrew unit of volume equal to 10 omers.\nApproximately equal to 0.03964 cubic meters.',
861
+ 'fifth': 'Defined to be 1/5 of a gallon.\nApproximately equal to 0.00075708 cubic meters.',
862
+ 'firkin': 'Defined to be 9 imperial gallons.\nApproximately equal to 0.04091 cubic meters.',
863
+ 'fluid_dram': 'Defined to be 1/8 of a fluid ounce.\nApproximately equal to 3.69669*10^-6 cubic meters.',
864
+ 'fluid_ounce': 'Defined to be 1/128 of a gallon.\nApproximately equal to 0.000029574 cubic meters.',
865
+ 'gallon': 'Defined to be 231 cubic inches.\nApproximately equal to 0.0037854 cubic meters.',
866
+ 'gill': 'Defined to be 4 fluid ounces.\nApproximately equal to 0.00011829 cubic meters.',
867
+ 'hogshead': 'Old English unit of wine casks defined to be 63 gallons.\nApproximately equal to 0.23848 cubic meters.',
868
+ 'imperial_gallon': 'Defined to be 4.54609 liters.\nEqual to 0.00454609 cubic meters.',
869
+ 'imperial_pint': 'Defined to be 1/8 of an imperial gallon.\nApproximately equal to 0.00056826 cubic meters.',
870
+ 'jeroboam': 'Defined to be 4/5 of a gallon.\nApproximately equal to 0.0030283 cubic meters.',
871
+ 'jigger': 'Defined to be 1 1/2 fluid ounces.\nApproximately equal to 0.00004436 cubic meters.',
872
+ 'liter': 'Defined to be 1 decimeter^3.\nEqual to 1/1000 of a cubic meter.',
873
+ 'magnum': 'Defined to be 1/2 a gallon.\nApproximately equal to 0.0018927 cubic meters.',
874
+ 'minim': 'Defined to be 1/480 of a fluid ounce.\nApproximately equal to 6.16115*10^-8 cubic meters.',
875
+ 'noggin': 'Equivalent to gill.\nDefined to be 4 fluid ounces.\nApproximately equal to 0.00011829 cubic meters.',
876
+ 'omer': 'Ancient Hebrew unit of volume equal to 9/20 of a peck.\nApproximately equal to 0.0039644 cubic meters.',
877
+ 'peck': 'Defined to be 1/4 of a bushel.\nApproximately equal to 0.0088098 cubic meters.',
878
+ 'pint': 'Defined to be 1/8 of a gallon.\nApproximately equal to 0.00047318 cubic meters.',
879
+ 'pony': 'Defined to be 3/4 of a fluid ounce.\nApproximately equal to 0.00002218 cubic meters.',
880
+ 'puncheon': 'Old English unit of wine casks defined to be 84 gallons.\nApproximately equal to 0.31797 cubic meters.',
881
+ 'quart': 'Defined to be 1/4 of a gallon.\nApproximately equal to 0.00094635 cubic meters.',
882
+ 'register_ton': 'Defined to be 100 cubic feet.\nApproximately equal to 2.83168 cubic meters.',
883
+ 'seam': 'Defined to be 8 bushels.\nApproximately equal to 0.281913 cubic meters.',
884
+ 'shot': 'Defined to be 1 fluid ounce.\nApproximately equal to 0.000029574 cubic meters.',
885
+ 'stere': 'Equivalent to cubic meter.',
886
+ 'tablespoon': 'Defined to be 1/2 of a fluid ounce.\nApproximately equal to 0.000014787 cubic meters.',
887
+ 'teaspoon': 'Defined to be 1/6 of a fluid ounce.\nEqual to 1/3 of a tablespoon.\nApproximately equal to 4.9289*10^-6 cubic meters.',
888
+ 'tun': 'Old English unit of wine casks defined to be 252 gallons.\nApproximately equal to 0.95392 cubic meters.',
889
+ 'uk_gallon': 'Equivalent to an imperial gallon.\nEqual to 0.00454609 cubic meters.',
890
+ 'uk_pint': 'Equivalent to and imperial pint.\nApproximately equal to 0.00056826 cubic meters.',
891
+ 'wine_bottle': 'Defined to be 750 milliliters.\nEqual to 0.00075 cubic meters.'}
892
+ }
893
+
894
+
895
+ ###############################################################################
896
+ # Dictionary for converting from derived units to base SI units.
897
+ ###############################################################################
898
+
899
+ unit_derivations = {'acceleration': 'length/time^2',
900
+ 'area': 'length^2',
901
+ 'capacitance': 'time^4*current^2/(length^2*mass)',
902
+ 'charge': 'current*time',
903
+ 'conductance': 'current^2*time^3/(mass*length^2)',
904
+ 'electric_potential': 'mass*length^2/(current*time^3)',
905
+ 'energy': 'mass*length^2/time^2',
906
+ 'fiber_linear_mass_density': 'mass/length',
907
+ 'force': 'mass*length/time^2',
908
+ 'frequency': '1/time',
909
+ 'illuminance': 'luminous_intensity*solid_angle/length^2',
910
+ 'inductance': 'length^2*mass/(time^2*current^2)',
911
+ 'information_rate': 'information/time',
912
+ 'inverse_length': '1/length',
913
+ 'luminance': 'luminous_intensity/length^2',
914
+ 'luminous_energy': 'luminous_intensity*solid_angle*time',
915
+ 'luminous_flux': 'luminous_intensity*solid_angle',
916
+ 'magnetic_field': 'mass/(current*time^2)',
917
+ 'magnetic_flux': 'mass*length^2/(current*time^2)',
918
+ 'magnetic_intensity': 'current/length',
919
+ 'magnetic_moment': 'current*length^2',
920
+ 'power': 'mass*length^2/time^3',
921
+ 'pressure': 'mass/(length*time^2)',
922
+ 'radiation': '1/time',
923
+ 'radiation_absorbed': 'length^2/time^2',
924
+ 'radiation_ionizing': 'current*time/mass',
925
+ 'resistance': 'mass*length^2/(current^2*time^3)',
926
+ 'velocity': 'length/time',
927
+ 'viscosity_absolute': 'mass/(length*time)',
928
+ 'viscosity_kinematic': 'length^2/time',
929
+ 'viscosity_other': 'length*time/mass',
930
+ 'volume': 'length^3'
931
+ }
932
+
933
+
934
+ def vars_in_str(s):
935
+ """
936
+ Given a string like ``'mass/(length*time)'``, return the list
937
+ ``['mass', 'length', 'time']``.
938
+
939
+ INPUT:
940
+
941
+ - ``s`` -- string
942
+
943
+ OUTPUT: list of strings (unit names)
944
+
945
+ EXAMPLES::
946
+
947
+ sage: sage.symbolic.units.vars_in_str('mass/(length*time)')
948
+ ['mass', 'length', 'time']
949
+ """
950
+ return re.findall('[a-z|_]+', s)
951
+
952
+
953
+ def unit_derivations_expr(v):
954
+ """
955
+ Given derived units name, returns the corresponding units expression.
956
+
957
+ For example, given ``'acceleration'`` output the symbolic expression
958
+ ``length/time^2``.
959
+
960
+ INPUT:
961
+
962
+ - ``v`` -- string; name of a unit type such as ``'area'``, ``'volume'``, etc.
963
+
964
+ OUTPUT: a symbolic expression
965
+
966
+ EXAMPLES::
967
+
968
+ sage: sage.symbolic.units.unit_derivations_expr('volume')
969
+ length^3
970
+ sage: sage.symbolic.units.unit_derivations_expr('electric_potential')
971
+ length^2*mass/(current*time^3)
972
+
973
+ If the unit name is unknown, a :exc:`KeyError` is raised::
974
+
975
+ sage: sage.symbolic.units.unit_derivations_expr('invalid')
976
+ Traceback (most recent call last):
977
+ ...
978
+ KeyError: 'invalid'
979
+ """
980
+ v = str(v)
981
+ Z = unit_derivations[v]
982
+ if isinstance(Z, str):
983
+ d = {x: str_to_unit(x) for x in vars_in_str(Z)}
984
+ from sage.misc.sage_eval import sage_eval
985
+ Z = sage_eval(Z, d)
986
+ unit_derivations[v] = Z
987
+ return Z
988
+
989
+
990
+ @instancedoc
991
+ class UnitExpression(Expression):
992
+ """
993
+ A symbolic unit.
994
+
995
+ EXAMPLES::
996
+
997
+ sage: acre = units.area.acre
998
+ sage: type(acre)
999
+ <class 'sage.symbolic.units.UnitExpression'>
1000
+
1001
+ TESTS::
1002
+
1003
+ sage: bool(loads(dumps(acre)) == acre)
1004
+ True
1005
+ sage: type(loads(dumps(acre)))
1006
+ <class 'sage.symbolic.units.UnitExpression'>
1007
+ """
1008
+ def _instancedoc_(self):
1009
+ """
1010
+ Return docstring for this unit.
1011
+
1012
+ EXAMPLES::
1013
+
1014
+ sage: print(units.area.acre.__doc__)
1015
+ Defined to be 10 square chains or 4840 square yards.
1016
+ Approximately equal to 4046.856 square meters.
1017
+ """
1018
+ return unitdocs(self)
1019
+
1020
+
1021
+ def str_to_unit(name):
1022
+ """
1023
+ Create the symbolic unit with given name. A symbolic unit is a
1024
+ class that derives from symbolic expression, and has a specialized
1025
+ docstring.
1026
+
1027
+ INPUT:
1028
+
1029
+ - ``name`` -- string
1030
+
1031
+ OUTPUT: a :class:`UnitExpression`
1032
+
1033
+ EXAMPLES::
1034
+
1035
+ sage: sage.symbolic.units.str_to_unit('acre')
1036
+ acre
1037
+ sage: type(sage.symbolic.units.str_to_unit('acre'))
1038
+ <class 'sage.symbolic.units.UnitExpression'>
1039
+ """
1040
+ return UnitExpression(SR, SR.var(name))
1041
+
1042
+
1043
+ class Units(ExtraTabCompletion):
1044
+ """
1045
+ A collection of units of some type.
1046
+
1047
+ EXAMPLES::
1048
+
1049
+ sage: units.power
1050
+ Collection of units of power: cheval_vapeur horsepower watt
1051
+ """
1052
+ def __init__(self, data, name=''):
1053
+ """
1054
+ EXAMPLES::
1055
+
1056
+ sage: sage.symbolic.units.Units(sage.symbolic.units.unitdict, 'all units')
1057
+ Collection of units of all units: acceleration ... volume
1058
+ """
1059
+ self.__name = name
1060
+ self.__data = data
1061
+ self.__units = {}
1062
+
1063
+ def __getstate__(self):
1064
+ """
1065
+ Used for pickling. We throw away all cached information.
1066
+
1067
+ EXAMPLES::
1068
+
1069
+ sage: type(units.__getstate__()[0])
1070
+ <... 'str'>
1071
+ sage: type(units.__getstate__()[1])
1072
+ <... 'dict'>
1073
+ sage: loads(dumps(units)) == units
1074
+ True
1075
+ sage: loads(dumps(units.area)) == units.area
1076
+ True
1077
+ sage: bool(loads(dumps(units.area.acre)) == units.area.acre)
1078
+ True
1079
+ """
1080
+ return (self.__name, self.__data)
1081
+
1082
+ def __setstate__(self, state):
1083
+ """
1084
+ Used for unpickling. See __getstate__.
1085
+
1086
+ EXAMPLES::
1087
+
1088
+ sage: state = units.__getstate__()
1089
+ sage: units.__setstate__(state)
1090
+ """
1091
+ self.__name = state[0]
1092
+ self.__data = state[1]
1093
+ self.__units = {}
1094
+
1095
+ def __eq__(self, other):
1096
+ """
1097
+ Compare two collections of units, or a collection of units
1098
+ with some other object.
1099
+
1100
+ EXAMPLES::
1101
+
1102
+ sage: units.length == 10
1103
+ False
1104
+ sage: units.length == units.length
1105
+ True
1106
+ sage: units.length == units.mass
1107
+ False
1108
+ """
1109
+ if not isinstance(other, Units):
1110
+ return False
1111
+ return (self.__name, self.__data) == (other.__name, other.__data)
1112
+
1113
+ def __ne__(self, other):
1114
+ """
1115
+ Test for unequality.
1116
+
1117
+ EXAMPLES::
1118
+
1119
+ sage: units.length != 5
1120
+ True
1121
+ sage: units.length != units.length
1122
+ False
1123
+ sage: units.length != units.mass
1124
+ True
1125
+ """
1126
+ return not (self == other)
1127
+
1128
+ def _tab_completion(self):
1129
+ """
1130
+ Return tab completions.
1131
+
1132
+ This complements the usual content of :func:`dir`, with the
1133
+ list of the names of the unit collections (resp. units) for
1134
+ :obj:`units` (resp. its subcollections), in particular for tab
1135
+ completion purposes.
1136
+
1137
+ .. SEEALSO:: :class:`ExtraTabCompletion`
1138
+
1139
+ EXAMPLES::
1140
+
1141
+ sage: units.area._tab_completion()
1142
+ ['acre', 'are', 'barn', 'hectare', 'rood', 'section', 'square_chain', 'square_meter', 'township']
1143
+ sage: units._tab_completion()
1144
+ ['acceleration', ..., 'volume']
1145
+ sage: units.force._tab_completion()
1146
+ ['dyne', ..., 'ton_force']
1147
+
1148
+ sage: dir(units)
1149
+ ['_Units__data', ..., 'acceleration', ..., 'volume']
1150
+ sage: dir(units.force)
1151
+ ['_Units__data', ..., 'dyne', ..., 'ton_force']
1152
+ """
1153
+ return sorted([x for x in self.__data if '/' not in x])
1154
+
1155
+ def __getattr__(self, name):
1156
+ """
1157
+ Return the unit with the given name.
1158
+
1159
+ EXAMPLES::
1160
+
1161
+ sage: units.area
1162
+ Collection of units of area: acre are barn hectare rood section square_chain square_meter township
1163
+ sage: units.area.barn
1164
+ barn
1165
+
1166
+ Units are cached::
1167
+
1168
+ sage: units.area.acre is units.area.acre
1169
+ True
1170
+ """
1171
+ if name in self.__units:
1172
+ return self.__units[name]
1173
+ if len(unit_to_type) == 0:
1174
+ evalunitdict()
1175
+ try:
1176
+ v = self.__data[name]
1177
+ except KeyError:
1178
+ raise AttributeError
1179
+ if isinstance(v, dict):
1180
+ U = Units(self.__data[name], name)
1181
+ else:
1182
+ U = str_to_unit(name)
1183
+ self.__units[name] = U
1184
+ return U
1185
+
1186
+ def __repr__(self):
1187
+ """
1188
+ Return string representation of this collection of units.
1189
+
1190
+ EXAMPLES::
1191
+
1192
+ sage: units.__repr__()
1193
+ 'Collection of units: acceleration ... volume'
1194
+ sage: units.area.__repr__()
1195
+ 'Collection of units of area: acre are barn hectare rood section square_chain square_meter township'
1196
+ """
1197
+ name = ' of ' + self.__name if self.__name else ''
1198
+ return "Collection of units{0}: {1}".format(name, ' '.join(sorted([str(x) for x in self.__data])))
1199
+
1200
+
1201
+ units = Units(unitdict, '')
1202
+
1203
+
1204
+ def unitdocs(unit):
1205
+ r"""
1206
+ Return docstring for the given unit.
1207
+
1208
+ INPUT:
1209
+
1210
+ - ``unit`` -- a unit
1211
+
1212
+ OUTPUT: string
1213
+
1214
+ EXAMPLES::
1215
+
1216
+ sage: sage.symbolic.units.unitdocs('meter')
1217
+ 'SI base unit of length.\nDefined to be the distance light travels in vacuum in 1/299792458 of a second.'
1218
+ sage: sage.symbolic.units.unitdocs('amu')
1219
+ 'Abbreviation for atomic mass unit.\nApproximately equal to 1.660538782*10^-27 kilograms.'
1220
+
1221
+ Units not in the list unit_docs will raise a :exc:`ValueError`::
1222
+
1223
+ sage: sage.symbolic.units.unitdocs('earth')
1224
+ Traceback (most recent call last):
1225
+ ...
1226
+ ValueError: no documentation exists for the unit earth
1227
+ """
1228
+ if is_unit(unit):
1229
+ return unit_docs[unit_to_type[str(unit)] + "_docs"][str(unit)]
1230
+ raise ValueError("no documentation exists for the unit %s" % unit)
1231
+
1232
+
1233
+ def is_unit(s) -> bool:
1234
+ """
1235
+ Return a boolean when asked whether the input is in the list of units.
1236
+
1237
+ INPUT:
1238
+
1239
+ - ``s`` -- an object
1240
+
1241
+ OUTPUT: boolean
1242
+
1243
+ EXAMPLES::
1244
+
1245
+ sage: sage.symbolic.units.is_unit(1)
1246
+ False
1247
+ sage: sage.symbolic.units.is_unit(units.length.meter)
1248
+ True
1249
+
1250
+ The square of a unit is not a unit::
1251
+
1252
+ sage: sage.symbolic.units.is_unit(units.length.meter^2)
1253
+ False
1254
+
1255
+ You can also directly create units using var, though they won't have
1256
+ a nice docstring describing the unit::
1257
+
1258
+ sage: sage.symbolic.units.is_unit(var('meter'))
1259
+ True
1260
+ """
1261
+ return str(s) in unit_to_type
1262
+
1263
+
1264
+ def convert(expr, target):
1265
+ """
1266
+ Convert units between ``expr`` and ``target``. If ``target`` is ``None``
1267
+ then converts to SI base units.
1268
+
1269
+ INPUT:
1270
+
1271
+ - ``expr`` -- the symbolic expression converting from
1272
+
1273
+ - ``target`` -- (default: ``None``) the symbolic expression converting to
1274
+
1275
+ OUTPUT: a symbolic expression
1276
+
1277
+ EXAMPLES::
1278
+
1279
+ sage: sage.symbolic.units.convert(units.length.foot, None)
1280
+ 381/1250*meter
1281
+ sage: sage.symbolic.units.convert(units.mass.kilogram, units.mass.pound)
1282
+ 100000000/45359237*pound
1283
+
1284
+ This raises :exc:`ValueError` if expr and target are not convertible::
1285
+
1286
+ sage: sage.symbolic.units.convert(units.mass.kilogram, units.length.foot)
1287
+ Traceback (most recent call last):
1288
+ ...
1289
+ ValueError: Incompatible units
1290
+ sage: sage.symbolic.units.convert(units.length.meter^2, units.length.foot)
1291
+ Traceback (most recent call last):
1292
+ ...
1293
+ ValueError: Incompatible units
1294
+
1295
+ Recognizes derived unit relationships to base units and other derived units::
1296
+
1297
+ sage: sage.symbolic.units.convert(units.length.foot/units.time.second^2, units.acceleration.galileo)
1298
+ 762/25*galileo
1299
+ sage: sage.symbolic.units.convert(units.mass.kilogram*units.length.meter/units.time.second^2, units.force.newton)
1300
+ newton
1301
+ sage: sage.symbolic.units.convert(units.length.foot^3, units.area.acre*units.length.inch)
1302
+ 1/3630*(acre*inch)
1303
+ sage: sage.symbolic.units.convert(units.charge.coulomb, units.current.ampere*units.time.second)
1304
+ (ampere*second)
1305
+ sage: sage.symbolic.units.convert(units.pressure.pascal*units.si_prefixes.kilo, units.pressure.pounds_per_square_inch)
1306
+ 1290320000000/8896443230521*pounds_per_square_inch
1307
+
1308
+ For decimal answers multiply 1.0::
1309
+
1310
+ sage: sage.symbolic.units.convert(units.pressure.pascal*units.si_prefixes.kilo, units.pressure.pounds_per_square_inch)*1.0
1311
+ 0.145037737730209*pounds_per_square_inch
1312
+
1313
+ You can also convert quantities of units::
1314
+
1315
+ sage: sage.symbolic.units.convert(cos(50) * units.angles.radian, units.angles.degree)
1316
+ degree*(180*cos(50)/pi)
1317
+ sage: sage.symbolic.units.convert(cos(30) * units.angles.radian, units.angles.degree).polynomial(RR)
1318
+ 8.83795706233228*degree
1319
+ sage: sage.symbolic.units.convert(50 * units.length.light_year / units.time.year, units.length.foot / units.time.second)
1320
+ 6249954068750/127*(foot/second)
1321
+
1322
+ Quantities may contain variables (not for temperature conversion, though)::
1323
+
1324
+ sage: sage.symbolic.units.convert(50 * x * units.area.square_meter, units.area.acre)
1325
+ acre*(1953125/158080329*x)
1326
+ """
1327
+ base_target = target
1328
+ z = {}
1329
+ tz = {}
1330
+
1331
+ for x in expr.variables():
1332
+ if is_unit(x):
1333
+ if unit_to_type[str(x)] == 'temperature':
1334
+ return convert_temperature(expr, target)
1335
+ else:
1336
+ z[x] = base_units(x)
1337
+
1338
+ expr = expr.subs(z)
1339
+
1340
+ if target is None:
1341
+ return expr
1342
+ else:
1343
+ for y in base_target.variables():
1344
+ if is_unit(y):
1345
+ tz[y] = base_units(y)
1346
+ base_target = base_target.subs(tz)
1347
+ coeff = (expr / base_target).expand()
1348
+
1349
+ for variable in coeff.variables():
1350
+ if is_unit(str(variable)):
1351
+ raise ValueError("Incompatible units")
1352
+
1353
+ return coeff.mul(target, hold=True)
1354
+
1355
+
1356
+ def base_units(unit):
1357
+ """
1358
+ Convert unit to base SI units.
1359
+
1360
+ INPUT:
1361
+
1362
+ - ``unit`` -- a unit
1363
+
1364
+ OUTPUT: a symbolic expression
1365
+
1366
+ EXAMPLES::
1367
+
1368
+ sage: sage.symbolic.units.base_units(units.length.foot)
1369
+ 381/1250*meter
1370
+
1371
+ If unit is already a base unit, it just returns that unit::
1372
+
1373
+ sage: sage.symbolic.units.base_units(units.length.meter)
1374
+ meter
1375
+
1376
+ Derived units get broken down into their base parts::
1377
+
1378
+ sage: sage.symbolic.units.base_units(units.force.newton)
1379
+ kilogram*meter/second^2
1380
+ sage: sage.symbolic.units.base_units(units.volume.liter)
1381
+ 1/1000*meter^3
1382
+
1383
+ Returns variable if ``unit`` is not a unit::
1384
+
1385
+ sage: sage.symbolic.units.base_units(var('x'))
1386
+ x
1387
+ """
1388
+ from sage.misc.sage_eval import sage_eval
1389
+ if str(unit) not in unit_to_type:
1390
+ return unit
1391
+ if unit_to_type[str(unit)] in ['si_prefixes', 'unit_multipliers']:
1392
+ number = unitdict[unit_to_type[str(unit)]][str(unit)]
1393
+ return (sage_eval(number) if isinstance(number, str) else number)
1394
+
1395
+ v = SR.var(unit_to_type[str(unit)])
1396
+ if str(v) in unit_derivations:
1397
+ base = unit_derivations_expr(v)
1398
+ for i in base.variables():
1399
+ base = base.subs({i: SR.var(value_to_unit[str(i)][1])})
1400
+ number = unitdict[str(v)][str(unit)]
1401
+ return base * (sage_eval(number) if isinstance(number, str) else number)
1402
+ else:
1403
+ base = SR.var(value_to_unit[str(v)][1])
1404
+ number = unitdict[str(v)][str(unit)]
1405
+ return base * (sage_eval(number) if isinstance(number, str) else number)
1406
+
1407
+
1408
+ def convert_temperature(expr, target):
1409
+ """
1410
+ Function for converting between temperatures.
1411
+
1412
+ INPUT:
1413
+
1414
+ - ``expr`` -- a unit of temperature
1415
+ - ``target`` -- a units of temperature
1416
+
1417
+ OUTPUT: a symbolic expression
1418
+
1419
+ EXAMPLES::
1420
+
1421
+ sage: t = 32*units.temperature.fahrenheit
1422
+ sage: t.convert(units.temperature.celsius)
1423
+ 0
1424
+ sage: t.convert(units.temperature.kelvin)
1425
+ 273.150000000000*kelvin
1426
+
1427
+ If target is ``None`` then it defaults to kelvin::
1428
+
1429
+ sage: t.convert()
1430
+ 273.150000000000*kelvin
1431
+
1432
+ This raises :exc:`ValueError` when either input is not a unit of temperature::
1433
+
1434
+ sage: t.convert(units.length.foot)
1435
+ Traceback (most recent call last):
1436
+ ...
1437
+ ValueError: cannot convert
1438
+ sage: wrong = units.length.meter*units.temperature.fahrenheit
1439
+ sage: wrong.convert()
1440
+ Traceback (most recent call last):
1441
+ ...
1442
+ ValueError: cannot convert
1443
+
1444
+ We directly call the convert_temperature function::
1445
+
1446
+ sage: sage.symbolic.units.convert_temperature(37*units.temperature.celsius, units.temperature.fahrenheit)
1447
+ 493/5*fahrenheit
1448
+ sage: 493/5.0
1449
+ 98.6000000000000
1450
+ """
1451
+ if len(expr.variables()) != 1:
1452
+ raise ValueError("cannot convert")
1453
+ elif target is None or unit_to_type[str(target)] == 'temperature':
1454
+ from sage.misc.sage_eval import sage_eval
1455
+ expr_temp = expr.variables()[0]
1456
+ coeff = expr / expr_temp
1457
+ if target is not None:
1458
+ target_temp = target.variables()[0]
1459
+ a = sage_eval(unitdict['temperature'][str(expr_temp)],
1460
+ locals={'x': coeff})
1461
+ if target is None or target_temp == units.temperature.kelvin:
1462
+ return a[0] * units.temperature.kelvin
1463
+ elif target_temp == units.temperature.celsius or target_temp == units.temperature.centigrade:
1464
+ return a[1] * target_temp
1465
+ elif target_temp == units.temperature.fahrenheit:
1466
+ return a[2] * units.temperature.fahrenheit
1467
+ elif target_temp == units.temperature.rankine:
1468
+ return a[3] * target_temp
1469
+ else:
1470
+ raise ValueError("cannot convert")