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