Re: Mathematica 3.0 Palette for Physics SI Fundamental Constants
- To: mathgroup@smc.vnet.net
- Subject: [mg12419] Re: [mg12311] Mathematica 3.0 Palette for Physics SI Fundamental Constants
- From: Bob Hanlon <BobHanlon@aol.com>
- Date: Thu, 14 May 1998 11:15:28 -0400
A user-defined constant should behave similarly to a built-in constant such as Pi, that is, it should act like a symbol unless its numeric properties are explicitly or implicitly invoked. For example, {Pi, 2*Pi, 2*Pi/3, (1 + I)*Pi, Pi/3, Pi^2, Pi/3., Pi^2., N[Pi], 1.*Pi, (1. + I)*Pi, (1 + 1.*I)*Pi, D[Pi, x], Dt[Pi, x], NumericQ[Pi]} {Pi, 2*Pi, (2*Pi)/3, (1 + I)*Pi, Pi/3, Pi^2, 1.047197551196597, 9.869604401089357, 3.141592653589793, 3.141592653589793, 3.141592653589793 + 3.141592653589793*I, 3.141592653589793 + 3.141592653589793*I, 0, 0, True} This behavior can be implemented along the following lines (that is, I haven't checked this out thoroughly enough to be sure that I have covered all the various situations required to cause a user-defined constant to behave exactly like a built-in constant): RealQ[(x_)?NumberQ] := !(Head[x] === Complex || Head[x] === Integer || Head[x] === Rational); Real2Q[x_] := RealQ[x] || Head[x] === Complex && (RealQ[Re[x]] || RealQ[Im[x]]); defineConstant[s_Symbol, (value_)?NumberQ] := Module[{}, Unprotect[s]; Clear[s]; s/: NumericQ[s] = True; s/: N[s] := value; s/: (a_)?Real2Q*s := a*N[s]; s/: s^(a_)?Real2Q := N[s]^a; SetAttributes[s, {Constant, Protected}] ] defineConstant[c, 2.99792458*^8 Meter/Second]; {c, 2*c, 2*c/3, (1 + I)*c, c/3, c^2, c/3., c^2., N[c], 1.*c, (1. + I)*c, (1 + 1.*I)*c, D[c, x], Dt[c, x], NumericQ[c]} {c, 2*c, (2*c)/3, (1 + I)*c, c/3, c^2, (9.993081933333332*^7*Meter)/Second, 8.987551787368172*^16*(Meter/Second)^2., (2.997924579999999*^8*Meter)/Second, (2.997924579999999*^8*Meter)/Second, ((2.997924579999999*^8 + 2.997924579999999*^8*I)*Meter)/ Second, ((2.997924579999999*^8 + 2.997924579999999*^8*I)*Meter)/Second, 0, 0, True} f[\[Lambda]_] := c/\[Lambda] {f[\[Lambda]], N[f[\[Lambda]]], f[3*Meter], f[3.*Meter]} {c/\[Lambda], (2.997924579999999*^8*Meter)/ (Second*\[Lambda]), c/(3*Meter), 9.993081933333332*^7/Second} Bob Hanlon In a message dated 5/8/98 2:25:53 AM, silver1@inreach.com wrote: >I have been constructing a custom palette which has about 100 >fundamental constants for physics. What I thought would be a 2 or 3 >hour task has turned out to be a much larger project. I wanted to set >up the symbols for the constants to be as close to actual >mathematical/physics expression as possible. The purpose of the >palette is to allow you to enter c for instance for the speed of light >with appropriate units. >