comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@adaos.worldonline.co.uk>
Subject: Re: Dimensionality Checking (Ada 20XX)
Date: Thu, 13 Dec 2001 22:56:49 -0000
Date: 2001-12-13T22:56:49+00:00	[thread overview]
Message-ID: <9vbc87$eb6li$1@ID-25716.news.dfncis.de> (raw)
In-Reply-To: u4rmv6ix4.fsf@gsfc.nasa.gov

"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:u4rmv6ix4.fsf@gsfc.nasa.gov...
> "Nick Roberts" <nickroberts@adaos.worldonline.co.uk> writes:
>
> > In my view of the proposed scheme, a 'unit' has two essential
> > attributes: a dimensionality; a scaling factor.
> >
> > A 'dimensionality' is a factor (a real number) for each of a set of
> > dimensions.
>
> Hmm. In physics, dimensionality is an integer.

Yes indeed. As you were, gentlemen.

> > Supposing our set of dimensions is {Mass, Length, Time}. The unit
> > 'Meter' would have the dimensionality (0, 1, 0), and let us choose
> > for it the scaling factor 1. The unit 'Foot' would then have the
> > same dimensionality, and a scaling factor of 0.3048 (approx.). A
> > certain measurement, let us call it 'NJRH' (my height), might be
> > 5.95 foot. I intend that the Ada conversion Meter(NJRH) would be
> > predefined, and have the value 1.813 (approx.), as well as the
> > conversion Foot(Meter'(1.813)), having the value 5.95 (approx.).
>
> Ok, but I'm not clear how to declare these in your new Ada.

Something like this:


   type Basic_Dimension is (Mass, Length, Time);

   package Basic_Units is new Ada.Units(Basic_Dimension);

   Meter: constant Basic_Units.Unit_Type := (Dim     => (0, 1, 0),
                                             Scaling => 1.0);

   Foot: constant Basic_Units.Unit_Type := (Dim     => (0, 1, 0),
                                            Scaling => 0.3048);

   type Arm_Length is digits 5 range 0.0 .. 20.0 unit Meter;

   type Person_Height is delta 1.0/12 range 3.0 .. 9.0 unit Foot;

   NJRH: Person_Height := 5.95;


Then we can use normal type conversion to automatically convert between feet
and meters:


   Just_Long_Enough_to_Clip_Round_Ear: Arm_Length := Arm_Length( NJRH/2 );


> > It would have the dimensionality (0, 1/e, 0) and a scaling factor of
> > our choosing, let us choose 1. The value of NJRH in log feet would
> > be 1.783 (approx.).
>
> I'm not clear why a "dimensionality" of 1/e corresponds to the log of
> feet, but then I don't know what log of feet means, so I guess you get
> to define it.

It doesn't. This was a deliberate mistake to see who was still alert.

;-)

> > I do not intend that the Ada conversion Log_Foot(NJRH) would be
> > permitted, nor Foot(Log_Foot'(1.783)). To achieve these conversions,
> > it would be necessary to use Log and Exp functions explicitly. Thus,
> > instead of Log_Foot(NJRH) we write Log(NJRH), and instead of
> > Foot(Log_Foot'(1.783)) we write Exp(Log_Foot'(1.783)).
>
> But, how does the poor compiler know which conversions to allow, and
> which to (pre)define?

Conversions between units of the same dimensionality (of the same dimension
set) are predefined. No other conversions are predefined. Some other
conversions may be provided by predefined library units (generic ones).

> > Assuming (and this may be an assumption that has to be dropped)
> > units are built into Ada by means of -- having added an extra 'unit'
> > attribute (in the notional sense as well as actually adding the
> > attribute 'Unit) to all scalar types -- permitting the unit to be
> > specified for fixed point types,
>
> Why are we still stuck on fixed point types?

Oh shut up. :-) We're no longer stuck on fixed point types, okay?

> > it would be necessary to provide a package such as this:
> >
> >
> >    generic
> >       type Proportional_Type is delta <>;
> >       type Logarithmic_Type is delta <>;
> >       Base: constant some_real_type := e;
> >
> >    package Ada.Numerics.Generic_Logarithmic_Functions is
> >
> >       function Log (X: in Proportional_Type) return Logarithmic_Type;
> >       function Exp (X: in Logarithmic_Type) return Proportional_Type;
> >
> >    end;
> >
> >
> > This package would check, upon instantiation, that the dimensionalities
of
> > Proportional_Type and Logarithmic_Type -- (Mp,Lp,Tp) and (Ml,Ll,Tl)
> > respectively, let's say -- are related in the correct way: Mp=Ml/e;
Lp=Ll/e;
> > Tp=Tl/e. Typically, it should be possible for this check to be done at
> > compile time.
>
> Ok, sounds like you could make it consistent.

The above package would NOT do the check mentioned, it would do the
following simple check: squeal if the dimension sets of the units of the two
types are the same (i.e. ensure they are different).

In the above package, I suspect both types should be floating point, rather
than fixed point.

> I still maintain that, in physics,
> log (meters) is _meaningless_, and _never_ occurs in a real-world
> problem. So attempting to define its meaning in Ada is simply not
> useful. You can define something that is self-consistent, but it won't
> match physics.
>
> I don't think you'll find a physics text that actually states "log
> (meters) is meaningless and forbidden", because it seems obvious, but
> I'll look in mine tonight. Maybe a high school text, where they
> introduce the notion of measurement, would discuss this (I only have
> my college text).

You may be quite right. This is an area where I happily concede a disgusting
ignorance.

> --
> -- Stephe

--
Best wishes,
Nick Roberts






  reply	other threads:[~2001-12-13 22:56 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-07  0:09 Dimensionality Checking (Ada 20XX) Snodgrass, Britt (NM75)
2001-12-07 16:15 ` Ian
2001-12-09 17:58   ` Nick Roberts
2001-12-09 22:58     ` Nick Roberts
2001-12-10  0:17     ` Mark Lundquist
2001-12-10  1:51       ` James Rogers
2001-12-10  3:33         ` Nick Roberts
2001-12-10 19:09           ` Nick Roberts
2001-12-11  8:20             ` Thomas Koenig
2001-12-11 15:37               ` Nick Roberts
2001-12-11 20:18                 ` Thomas Koenig
2001-12-12  0:58                   ` Mark Lundquist
2001-12-12  8:19                     ` Wilhelm Spickermann
2001-12-12 14:21                     ` Stephen Leake
2001-12-12 19:10                       ` Nick Roberts
2001-12-13 19:04                         ` Stephen Leake
2001-12-13 22:56                           ` Nick Roberts [this message]
2001-12-14  0:11                             ` Nick Roberts
2001-12-14 22:14                       ` Mark Lundquist
2001-12-15  1:30                         ` Nick Roberts
2001-12-10 20:22         ` Thomas Koenig
2001-12-10 17:21       ` Wes Groleau
2001-12-10 19:51         ` Mark Lundquist
2001-12-10 19:56           ` Wes Groleau
2001-12-10 20:37             ` Mark Lundquist
2001-12-10 18:56       ` Nick Roberts
2001-12-11 15:05         ` Wes Groleau
2001-12-11 16:39         ` Stephen Leake
2001-12-11 19:05           ` Nick Roberts
2001-12-11 22:50             ` Mark Johnson
2001-12-12  1:59               ` Nick Roberts
2001-12-11 23:01             ` Stephen Leake
2001-12-12  2:21               ` Nick Roberts
2001-12-12 14:16                 ` Stephen Leake
2001-12-13 19:52                   ` Nick Roberts
2001-12-13 22:22                     ` Nick Roberts
2001-12-14  6:40                       ` Robert C. Leif, Ph.D.
2001-12-14 17:30                       ` Stephen Leake
2001-12-14 17:38                     ` Stephen Leake
2001-12-11 22:45           ` Mark Lundquist
2001-12-12  1:42             ` Nick Roberts
2001-12-12 15:17               ` Mark Lundquist
2001-12-12 14:03             ` Stephen Leake
2001-12-12  9:35           ` Dmitry A. Kazakov
2001-12-12 14:26             ` Stephen Leake
2001-12-13 17:02               ` daniele andreatta
2001-12-13 19:06                 ` Stephen Leake
2001-12-14 10:16                 ` Dmitry A. Kazakov
2001-12-14 22:01                   ` Nick Roberts
2001-12-17 11:10                     ` Dmitry A. Kazakov
2001-12-17 12:16                       ` Thomas Koenig
2001-12-17 14:30                         ` Dmitry A. Kazakov
2001-12-27 17:18                         ` Steven Deller
2001-12-15  7:07                   ` Steven Deller
2001-12-17 12:31                     ` Dmitry A. Kazakov
2001-12-17 13:46                       ` Thomas Koenig
2001-12-17 15:00                         ` Dmitry A. Kazakov
2001-12-17 16:38                         ` Thomas Koenig
2001-12-17 21:07                       ` Britt Snodgrass
2001-12-20 13:44                         ` Dmitry A. Kazakov
2001-12-13 19:33         ` Mark Lundquist
2001-12-13 22:15           ` Nick Roberts
2001-12-14 20:20             ` Mark Lundquist
2001-12-10 23:31       ` Mark Lundquist
2001-12-10 13:57     ` Ian
2001-12-10 17:24       ` Wes Groleau
2001-12-10 20:38       ` Britt Snodgrass
  -- strict thread matches above, loose matches on Subject: below --
2001-12-11 13:11 Mike Brenner
2001-12-11 17:03 ` Mark Lundquist
2001-12-02 16:01 Another Idea for Ada 20XX James Rogers
2001-12-03 14:56 ` Mark Lundquist
2001-12-03 15:12   ` Lutz Donnerhacke
2001-12-03 21:13     ` Dimensionality Checking (Ada 20XX) Nick Roberts
2001-12-04 14:00       ` Dmitry A. Kazakov
2001-12-06 19:52         ` Britt Snodgrass
2001-12-06 20:55           ` Mark Lundquist
2001-12-06 22:38           ` Wes Groleau
2001-12-06 23:12             ` Mark Lundquist
2001-12-07 14:36               ` Wes Groleau
2001-12-07  9:37           ` Dmitry A. Kazakov
2001-12-07 22:51           ` Mark Lundquist
replies disabled

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