comp.lang.ada
 help / color / mirror / Atom feed
* Dimensions in Ada
@ 2012-12-28 15:22 Álex R. Mosteo
  2012-12-28 19:50 ` jpwoodruff
  2013-01-03 12:27 ` AdaMagica
  0 siblings, 2 replies; 4+ messages in thread
From: Álex R. Mosteo @ 2012-12-28 15:22 UTC (permalink / raw)


I have vague remembrances of past discussions about unit systems in Ada; at 
least three ways of doing it, none of them totally satisfying.

Today I have stumbled in the following Ada Gem from AdaCore:

"This Gem outlines the new GNAT dimensionality checking system. This feature 
relies on Ada 2012 aspect specifications, and is available from version 
7.0.1 of GNAT onwards."

http://libre.adacore.com/adaanswers/gems_single/gem-136-how-tall-is-a-
kilogram

I lack the knowledge to judge it against the other options, which I don't 
even remember, but I'd like to hear opinions from interested parties. It 
uses a GNAT-specific aspect, so may be that provides (or not) the necessary 
magic to close the gap in previous approaches? That's what first comes to my 
mind...



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dimensions in Ada
  2012-12-28 15:22 Dimensions in Ada Álex R. Mosteo
@ 2012-12-28 19:50 ` jpwoodruff
  2012-12-28 21:26   ` jpwoodruff
  2013-01-03 12:27 ` AdaMagica
  1 sibling, 1 reply; 4+ messages in thread
From: jpwoodruff @ 2012-12-28 19:50 UTC (permalink / raw)


On Friday, December 28, 2012 8:22:43 AM UTC-7, Álex R. Mosteo wrote:
> I have vague remembrances of past discussions about unit systems in Ada; at 
> 
> least three ways of doing it, none of them totally satisfying.
> 

I suggest you examine the Unit and Measure types implemented by
Dmitry Kazakov (http://www.dmitry-kazakov.de/ada/units.htm)

Two types are used for dealing with units. The type Unit denotes the
dimension of a physical entity. The type Measure represents some
quantity of a physical unit.

Dmitry provides a formidable body of services on physically
dimensioned quantities, including math operations and I/O.  

Well tested and documented; a thoroughly professional product.

John



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dimensions in Ada
  2012-12-28 19:50 ` jpwoodruff
@ 2012-12-28 21:26   ` jpwoodruff
  0 siblings, 0 replies; 4+ messages in thread
From: jpwoodruff @ 2012-12-28 21:26 UTC (permalink / raw)


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, Álex R. Mosteo wrote:
> 
> > I have vague remembrances of past discussions about unit systems in Ada; at 
> 
> > 
> 
> > least three ways of doing it, none of them totally satisfying.
> 
> > 
> 
> 
> 
> I suggest you examine the Unit and Measure types implemented by
> 
> Dmitry Kazakov (http://www.dmitry-kazakov.de/ada/units.htm)
> 
> 
> 
> Two types are used for dealing with units. The type Unit denotes the
> 
> dimension of a physical entity. The type Measure represents some
> 
> quantity of a physical unit.
> 
> 
> 
> Dmitry provides a formidable body of services on physically
> 
> dimensioned quantities, including math operations and I/O.  
> 
> 
> 
> Well tested and documented; a thoroughly professional product.
> 
> 
> 
> John

After I thought about it a while, I recall that I made some notes 5 or 6 years ago.  I don't know anything about the newest addition.  
John
--- notes from Jan 07.  jpw
,----
| SI-Physical (etc)
`----

SI packages propagate dimensional units through computations.  

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 substance
  subtype Candela         is Unit(0,0,0,0,0,0,1); -- cd   luminous intensity



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.  

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 <xxx>.  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).  

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 
   Luminescence  (= candela?)
   Temperature 
   Mass 
   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. 

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.  <<This is different from Kazakov's impl where the
programmer decides on an object by object basis which will be mutable
and which not by declaring either definite or indefinite object. ??>>


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  <no re-check since 2007>



,----
| 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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dimensions in Ada
  2012-12-28 15:22 Dimensions in Ada Álex R. Mosteo
  2012-12-28 19:50 ` jpwoodruff
@ 2013-01-03 12:27 ` AdaMagica
  1 sibling, 0 replies; 4+ messages in thread
From: AdaMagica @ 2013-01-03 12:27 UTC (permalink / raw)


See https://groups.google.com/forum/#!searchin/comp.lang.ada/dimension$20checking/comp.lang.ada/YIARRmrir3E/X3JDTadrui0J for an overview of some findings with the GNAT units checking method. GNAT GPL 2012 however (which I played around with) is older than the current GNAT Professional, and at least one of my proposals has been implemented meanwhile.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-03 12:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-28 15:22 Dimensions in Ada Álex R. Mosteo
2012-12-28 19:50 ` jpwoodruff
2012-12-28 21:26   ` jpwoodruff
2013-01-03 12:27 ` AdaMagica

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox