fbe-SI-units.scm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #| -*-Scheme-*-
  2. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
  3. 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Massachusetts
  5. Institute of Technology
  6. This file is part of MIT/GNU Scheme.
  7. MIT/GNU Scheme is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11. MIT/GNU Scheme is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with MIT/GNU Scheme; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
  18. USA.
  19. |#
  20. ;;;; SI units
  21. (define-unit-system 'SI
  22. (list '&meter "m" "length")
  23. (list '&kilogram "kg" "mass")
  24. (list '&second "s" "time")
  25. (list '&ampere "A" "electric current")
  26. (list '&kelvin "K" "temperature")
  27. (list '&mole "mol" "amount of substance")
  28. (list '&candela "cd" "luminous intensity")
  29. #|
  30. (list '&radian "rad" "plane angle")
  31. (list '&steradian "sr" "solid angle")
  32. |#
  33. )
  34. (define &angular &unitless)
  35. (define-derived-unit SI '&radian
  36. "rad" "plane angle" &angular)
  37. (define-derived-unit SI '&steradian
  38. "rad" "solid angle" &angular)
  39. ;;; Derived SI units
  40. (define-derived-unit SI '&newton
  41. "N" "force" (g:/ (g:* &kilogram &meter) (g:square &second)))
  42. (define-derived-unit SI '&joule
  43. "J" "energy" (g:* &newton &meter))
  44. (define-derived-unit SI '&coulomb
  45. "C" "electric charge" (g:* &ampere &second))
  46. (define-derived-unit SI '&watt
  47. "W" "power" (g:/ &joule &second))
  48. (define-derived-unit SI '&volt
  49. "V" "electric potential" (g:/ &watt &ampere))
  50. ;;; FBE need to escape backslash: \Omega -> \\Omega
  51. (define-derived-unit SI '&ohm
  52. ;; "\Omega" "electric resistance" (/ &volt &ampere))
  53. "\\Omega" "electric resistance" (g:/ &volt &ampere))
  54. (define-derived-unit SI '&siemens
  55. "S" "electric conductance" (g:/ &unitless &ohm))
  56. (define-derived-unit SI '&farad
  57. "F" "capacitance" (g:/ &coulomb &volt))
  58. (define-derived-unit SI '&weber
  59. "Wb" "magnetic flux" (g:* &volt &second))
  60. (define-derived-unit SI '&henry
  61. "H" "inductance" (g:/ &weber &ampere))
  62. (define-derived-unit SI '&hertz
  63. "Hz" "frequency" (g:/ &unitless &second) :2pi)
  64. (define-derived-unit SI '&tesla
  65. "T" "magnetic flux density" (g:/ &weber (g:square &meter)))
  66. (define-derived-unit SI '&pascal
  67. "Pa" "pressure" (g:/ &newton (g:square &meter)))
  68. ;;;; SI multipliers
  69. (define-multiplier '&exa "E" 18)
  70. (define-multiplier '&peta "P" 15)
  71. (define-multiplier '&tera "T" 12)
  72. (define-multiplier '&giga "G" 9)
  73. (define-multiplier '&mega "M" 6)
  74. (define-multiplier '&kilo "k" 3)
  75. (define-multiplier '&hecto "h" 2)
  76. (define-multiplier '&deka "da" 1)
  77. (define-multiplier '&deci "d" -1)
  78. (define-multiplier '&centi "c" -2)
  79. (define-multiplier '&milli "m" -3)
  80. ;;; FBE escape backslash
  81. ;;(define-multiplier '&micro "\mu" -6)
  82. (define-multiplier '&micro "\\mu" -6)
  83. (define-multiplier '&nano "n" -9)
  84. (define-multiplier '&pico "p" -12)
  85. (define-multiplier '&femto "f" -15)
  86. (define-multiplier '&atto "a" -18)
  87. ;;; abbreviations
  88. (define-multiplier '&E "E" 18)
  89. (define-multiplier '&P "P" 15)
  90. (define-multiplier '&T "T" 12)
  91. (define-multiplier '&G "G" 9)
  92. (define-multiplier '&M "M" 6)
  93. (define-multiplier '&k "k" 3)
  94. (define-multiplier '&h "h" 2)
  95. (define-multiplier '&da "da" 1)
  96. (define-multiplier '&d "d" -1)
  97. (define-multiplier '&c "c" -2)
  98. (define-multiplier '&m "m" -3)
  99. ;;; FBE escape backslash
  100. ;;(define-multiplier '&u "\mu" -6)
  101. (define-multiplier '&u "\\mu" -6)
  102. (define-multiplier '&n "n" -9)
  103. (define-multiplier '&p "p" -12)
  104. (define-multiplier '&f "f" -15)
  105. (define-multiplier '&a "a" -18)
  106. ;;; Other units in terms of SI system
  107. (define-additional-unit SI '&lumen
  108. "lm" "luminous flux" (g:* &candela &steradian))
  109. (define-additional-unit SI '&lux
  110. "lx" "illuminance" (g:/ &lumen (g:square &meter)))
  111. (define-additional-unit SI '&katal
  112. "kat" "catalytic activity" (g:/ &mole &second))
  113. (define-additional-unit SI '&becquerel
  114. "Bq" "activity" (g:/ &unitless &second))
  115. (define-additional-unit SI '&gray
  116. "Gy" "absorbed dose" (g:/ &joule &kilogram))
  117. (define-additional-unit SI '&sievert
  118. "Sv" "dose equivalent" (g:/ &joule &kilogram))
  119. (define-additional-unit SI '&degree
  120. "$^\\circ$" "1/360 circle" &angular (g:/ :2pi 360))
  121. (define-additional-unit SI '&gram
  122. "gm" "CGS mass" &kilogram 1/1000)
  123. (define-additional-unit SI '&inch
  124. "in" "English length" &meter (* 2.54 &centi))
  125. (define-additional-unit SI '&centimeter
  126. "cm" "CGS length" &meter 1/100)
  127. (define-additional-unit SI '&pound
  128. "lb" "English force" &newton 4.4482)
  129. (define-additional-unit SI '&slug
  130. "slug" "English mass" &kilogram 14.594)
  131. (define-additional-unit SI '&foot
  132. "ft" "English length" &inch 12)
  133. (define-additional-unit SI '&mile
  134. "mi" "English length" &foot 5280)
  135. (define-additional-unit SI '&dyne
  136. "dyne" "Force" &newton 1.0e-5)
  137. (define-additional-unit SI '&calorie ;at 20 C
  138. "cal" "Heat energy" &joule 4.1819)
  139. (define-additional-unit SI '&minute
  140. "day" "Time" &second 60)
  141. (define-additional-unit SI '&hour
  142. "day" "Time" &second 3600)
  143. (define-additional-unit SI '&day
  144. "day" "Time" &second 86400)
  145. (define-additional-unit SI '&year
  146. "yr" "Tropical year 1900" &second 31556925.9747)
  147. (define-additional-unit SI '&sidereal-year
  148. "syr" "Sidereal year 1900" &second 3.1558149984e7)
  149. (define-additional-unit SI '&AU
  150. "AU" "Astronomical Unit" &meter 1.4959787066e11)
  151. (define-additional-unit SI '&arcsec
  152. "arcsec" "arc second" &radian (g:/ (g:* 2 :pi) (g:* 60 60 360)))
  153. (define parsec
  154. (g:/ (& 1 &AU) (tan (& 1 &arcsec))))
  155. (define-additional-unit SI '&pc
  156. "pc" "Parsec" &meter (u:value parsec))
  157. (define speed-of-light (& 2.99792458e8 (g:/ &meter &second)))
  158. (define-additional-unit SI '&ly
  159. "ly" "Light Year"
  160. &meter
  161. (u:value (g:* speed-of-light &year)))
  162. (define-additional-unit SI '&esu
  163. "esu" "Electrostatic Unit"
  164. &coulomb
  165. (u:value (g:/ 1 (g:* 10 speed-of-light))))
  166. (define-additional-unit SI '&ev
  167. "ev" "Electron Volt"
  168. &joule 1.602e-19)