From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e568be4d901b052d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII X-Received: by 10.224.207.66 with SMTP id fx2mr18153538qab.7.1356729965443; Fri, 28 Dec 2012 13:26:05 -0800 (PST) Received: by 10.49.34.135 with SMTP id z7mr5374341qei.1.1356729965422; Fri, 28 Dec 2012 13:26:05 -0800 (PST) Path: k2ni3151qap.0!nntp.google.com!ee4no3267478qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 28 Dec 2012 13:26:05 -0800 (PST) In-Reply-To: <9343de35-328f-4d43-9fb4-d77b05c950e8@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.229.206.178; posting-account=eLk0BgoAAAA-yA75xm1L7heSizMaESVg NNTP-Posting-Host: 71.229.206.178 References: <9343de35-328f-4d43-9fb4-d77b05c950e8@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <53f9e1fa-9fcc-45c7-8020-fbf974bb375c@googlegroups.com> Subject: Re: Dimensions in Ada From: jpwoodruff@gmail.com Injection-Date: Fri, 28 Dec 2012 21:26:05 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-12-28T13:26:05-08:00 List-Id: On Friday, December 28, 2012 12:50:32 PM UTC-7, jpwoo...@gmail.com wrote: > On Friday, December 28, 2012 8:22:43 AM UTC-7, =C1lex R. Mosteo wrote: >=20 > > I have vague remembrances of past discussions about unit systems in Ada= ; at=20 >=20 > >=20 >=20 > > least three ways of doing it, none of them totally satisfying. >=20 > >=20 >=20 >=20 >=20 > I suggest you examine the Unit and Measure types implemented by >=20 > Dmitry Kazakov (http://www.dmitry-kazakov.de/ada/units.htm) >=20 >=20 >=20 > Two types are used for dealing with units. The type Unit denotes the >=20 > dimension of a physical entity. The type Measure represents some >=20 > quantity of a physical unit. >=20 >=20 >=20 > Dmitry provides a formidable body of services on physically >=20 > dimensioned quantities, including math operations and I/O. =20 >=20 >=20 >=20 > Well tested and documented; a thoroughly professional product. >=20 >=20 >=20 > John After I thought about it a while, I recall that I made some notes 5 or 6 ye= ars ago. I don't know anything about the newest addition. =20 John --- notes from Jan 07. jpw ,---- | SI-Physical (etc) `---- SI packages propagate dimensional units through computations. =20 Values are expressed in SI units. Numerous physical units are defined and some conversions between units are available in the form of named multiplicative constants. Constants are declared for conversions, and generic fns can be instantiated for the furlongs-per-fortnight cases. The conversions are consistency checked. Overloads are provided for call-throughs to float-text-io to print only numerical values. There is no attempt to spell out the name of the unit. Representation uses the base units as: subtype Meter is Unit(1,0,0,0,0,0,0); -- m length subtype Kilogram is Unit(0,1,0,0,0,0,0); -- kg mass subtype Second is Unit(0,0,1,0,0,0,0); -- s time subtype Ampere is Unit(0,0,0,1,0,0,0); -- A current subtype Kelvin is Unit(0,0,0,0,1,0,0); -- K temperature subtype Mole is Unit(0,0,0,0,0,1,0); -- mol amount of substan= ce subtype Candela is Unit(0,0,0,0,0,0,1); -- cd luminous intensit= y There are four complete collections under the label SI- : Generic or not, and Physical vs Real. Every one of the libraries has the same set of packages. All you have to do to turn off the physical checking is to redirect the compilation context PATH and recompile. =20 In the SI-Physical package(s), physical units are represented in CODE using discriminated variant record that carries dimensions. Use this package to create code with compile- and execution-time checking of the units. SI-Physical package (that will execute EVERY units computation to assure proper physics) can be replaced by the packages in SI-Real when the equations are correct; that package will execute relatively quickly, but the computation is only numerically (not physically) correct. SI-Real package(s) recognize the same identifiers, but the implementation does no checking -- floating arithmetic only. Recall the adage of the sailor who wears his lifejacket on shore, but then goes to sea without it. SI-Generic denotes *only* the freedom to late-bind the base numeric type. The non-generic directorys are purpose-built to implement Float. They are quite a bit easier to follow, so are nicer to use. There are library-level instances of the generics; you might have to make new actual type in the SI.ADS package only. Three of the forms were provided by . JPW installed the SI-Generic-Real library using transformations to make it look just like physical, but with only numerical, not unit, computations. ,---- | Kazakov `---- Mostly like SI-Generic-Physical. There is no switchable "real" version that short-cuts dimensionality checks (as is available in SI-Real). =20 The type Unit denotes the dimensionality of a physical entity. The identifier for unit is in m-k-s. The domain of dimensionality is Current=20 Luminescence (=3D candela?) Temperature=20 Mass=20 Length Quantity (moles) Time Unitless The type Measure represents a dimensioned value that is always stored in m-k-s units. Declarations similar to the SI packages, minor syntactic differences but quite pretty. The package Units.Edit provides the function Image used to convert Unit to String. The string is invariably in base m-k-s units.=20 Measures.Edit has IO -- including get! Able to get a measure from a string which contains any of the SI or derived units (seems to be lower case only). JPW built a name_io.measure_io package. One should never combine a call to "Get_Value_As" with a call to Image because Image is always in base units. Offset units celsius and Fahrenheit (there are no others?) Accomodations are made to celsius (to shift kelvins) by broadening the definition of the type measure to allow offset. Operator "and" is overloaded for specifying offset units. ,---- | Grein `---- Grein has produced a well-argued implementation of the SI units. His type Item is a dimensioned quantity analogous to Kazakov's Measure, and he gives the largest-of-all suite of mathematical functions: trig, rational-fraction exponents, 3-space vectors and quaternions. Variant Unchecked is provided so that all computations can be made numeric only. This fills the same niche as SI-Real. Switch to Unchecked family when you take off your lifejacket to go sailing. The Constrained variant demands that every object in a compile unit be declared as regards its units and no object in the program can change its subtype. <> Is it true that the Unconstrained variant is provided to confound the physicist (!) Items that are unconstrained can change their dimensionality to suit any computation. <> Only SI units are defined. There are no conversions among related units. Temperatures are included but I'm uninformed. Each of SI and Kazakov offer extensive (but different) solutions to non-SI units, but Grein implements only a placeholder. -- trouble report I can declare a Newton*Meter but not a Joule ,---- | Feldman `---- The Feldman packages have discriminated units testing (similar to SI-Physical), but has only kinematic units (length, mass, time), not the entire SI standard. Not even momentum and KE in the original form. ,---- | Rogers `---- Pat Rogers provides a very similar package to Feldman - kinematic units with generic numeric model. This is clearly intended as a demonstration for classroom use. With only velocity (not acceleration) and "erg" for an energy this is only a toy. Won't even do the drag race acceleration issue.