comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: Re: Dimensionality Checking (Ada 20XX)
Date: Mon, 17 Dec 2001 11:10:04 GMT
Date: 2001-12-17T11:10:04+00:00	[thread overview]
Message-ID: <3c1db0d2.2038828@News.CIS.DFN.DE> (raw)
In-Reply-To: 9vdsrj$emno3$1@ID-25716.news.dfncis.de

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4239 bytes --]

On Fri, 14 Dec 2001 22:01:23 -0000, "Nick Roberts"
<nickroberts@adaos.worldonline.co.uk> wrote:

>So, the expression Exp(X) is dimensionless, and X must be (checked to be)
>dimensionless. Ditto for Log(X).
>
>The same is also true for the trigonometric functions. I recall someone
>posting in this thread suggesting, in effect, that the same is also true for
>square root; I'd like this confirmed.

The equation X <unitX>*X <unitX> = Y <unitY> has a solution when Y is
not negative and <unitY> has even powers of all base units. Thus we
could define sqrt.

>Secondly, I suppose the standard package
>Ada.Numerics.Generic_Elementary_Functions could and should check (upon
>instantiation) that the generic parameter type Float_Type is either
>dimensionless or not unit-specific. Am I correct in assuming that the Cycle
>parameter must always be dimensionless?
>
>I have accepted the idea of units being applicable to floating point types,
>as well as fixed point types, with the concern that unit-specific floating
>point types are (more) liable to abuse. Am I right that
>Ada.Numerics.Float_Random.Uniformly_Distributed should not be unit-specific?

>As a slightly separate issue, is there any merit in the idea of adding
>standard packages that provide Log, Exp, sin, Cos, Tan, etc. for fixed point
>types?

Let's look at this from slightly other point of view. I believe that
there is a lot of confusion between units and scales. Your wish to
have "logarithmic" units is rightful and IMO there is an answer. It
sounds "logarithmic scale". A scale determines the representation of a
value, but not its dimension. With scales there would be also no fixed
vs. floating point dilemma. Both are *just* different scales of the
same thing *real number*. Same is with units. There is no log(m), but
there can be logarithmically graduated scales of meters. If I dare to
misuse Ada (:-)) it could be something like:

type meters is ...
type log_meters is ...

if x is of meters then

log_meters (x) = log_meters'Val (log (meters'Pos(x)))

From this point of view Celsius degree is of course Kelvin scaled by
s(x)=x+273.15. Foot is a proportionally scaled Meter etc. Happily
there is no need in Cycle parameter for sin/cos, because rad and
degree are of different scales [but of same unit 1 SI]. 

So dimensioned types of values should be characterized by two
attributes, discriminants, tag whatsoever: unit and scale.

[ I played with this idea for a while. It is easy to make unit
discriminant a modular number. Unfortunately an attempt to use access
type discriminants to represent scales is doomed to fail, because then
the type shall be limited. Damn, but there are good reasons why the
type with a discriminant of an access type shall be limited (sigh) ]

Differently scaled values cannot be mixed but can be explicitly
converted. Values of same scale can be added and subtracted [when unit
is same], multiplied and divided.

Now problems (:-():

1. There are different ways to define operations on scaled values. For
instance: s(X+Y) vs. s(X)+s(Y). With �C we are using the first way
[2�C+2�C=4�C], with floating point numbers the second. [for scales
s(x)=ax and additive/multiplicative operations they are equivalent].

2. Multiplicative operations may produce new scales.

3. Scales and units should be matched rather "by-structure" than
by-name.

Last note. If we want to do it consistently then of course there
should be a possibility to assign units to any type. Consider complex
numbers, matrices etc.

a) Let I want to implement fuzzy readings. Then I should have an
ability to write "type Fuzzy_Number is private;" and give some public
specification that it has a dimension.

b) A biz application could treat currency as a unit and different
currencies as fixed point numbers of different scales with no loss of
precision as long all calculations are made in one currency.

c) Let I write a matrix package. I would like to define matrices of
different sizes as ones having different units. For instance NxN and
Nx1 should be two different units, so I cannot add matrices of this
sizes. Yet I can multiple one of NxN to Nx1 and have Nx1 matrix
(vector). Then I leave all checks to the compiler (:-))

Regards,
Dmitry Kazakov



  reply	other threads:[~2001-12-17 11:10 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
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 [this message]
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