comp.lang.ada
 help / color / mirror / Atom feed
* Re: Consider her way -- Re: Dimensionality Checking
@ 2001-12-13  0:09 Alexandre E. Kopilovitch
  2001-12-13 17:13 ` Mark Lundquist
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandre E. Kopilovitch @ 2001-12-13  0:09 UTC (permalink / raw)
  To: comp.lang.ada

"Mark Lundquist" <mlundquist2@attbi.com> wrote:
>>   Now let's recall the fact that the Ada is not a problem-oriented language,
>> but rather a "superassembler". It intentionally and carefully avoids all
>> paradigms that aren't closely related to the real computer architectures or
>> to the general software engineering, even if those paradigms are heavily used
>> in some significant application area. (Note that I'm speaking here about the
>> paradigms; the data representation issues are another matter, that is a natural
>> job for an assembler.)
>>   Obviously, the dimensionality paradigm is one of the kind that Ada avoids:
>> it belongs neither to a computer architecture nor to the general software
>> engineering, but to the particular application area, no matter how significant
>> it is in the real world. Therefore Ada most probably will not take any move
>> to support it directly.
>
>Well OK, but then how do you explain Ada's type system?
That facility corresponds to a major general software engineering paradigm.

>  If the language did not
>abstract types away from its own "machine model", then wouldn't we have
>C-style type-equivalence instead?
Certainly yes. 

>  Instead, in Ada we have the idea that
>"number of lines in a file" and "number of cows" can be different types.
>Isn't that pretty abstract for a "superassembler"?
Not at all. It is too abstract for an assembler (such as C, for example), but
Ada is a "superassembler", which facilitates dealing with the general software
engineering enviromnent, besides of the real computer architectures.

>>   The proper way to do the dimensional/unit analysis for the Ada programs is
>> to use the ASIS and some suitable language processor [snip...]
>
>For one thing, you would still have to code all of of your own unit conversions.
Why? Two distinct subtypes of the same type may be used together in an expression
without any conversion. Note, that I proposed to use the subtypes and not the
types for expressing of dimensionality.

>> following question: if X and X*X belong to the different types, how will you
>> treat (interpret) the usual approximations by the Taylor series?
>
>Well, I think you're almost right here... you don't have to think about
>Taylor series to see the problem.  The fundamental glitch is that
>unit-safety takes you from a numeric system that is closed under
>multiplication to one that is not.
In my opinion, the unit-safety may be based on the type system only for the
relatively simple situations, which is essentially linear. The typical example
of "apples and oranges" falls in that category.

>  Every expression in Ada has a value; if
>X is of a "dimensioned type" as we have been considering, then what is the
>type of the expression 'X * X'?  So you're right that in the "dimensioned
>type" approach there has to be some relationship between the types, but it
>would be absolutely wrong to co-opt subtyping for this.  For one, we want to
>save subtypes for what they are already used for (constraint checks);
Why "save"? You may use the subtypes for both purposes without any difficulty.
Moreover, these somtimes may be combined nicely; for example a subtype for the 
speed may have the range that corresponds to the maximal speed - either speed
of light, or (in a specific application) the speed of sound.

> but more fundamentally, it just does not make sense.  Given a subtype and a
>value, you can tell whether the value is in the subtype!
Well, but what is bad here for the dimensionality checking?

>  The subtype is not some abstract property of the object,
Even a subtype without a range? And what is it, in such a case?


Alexander Kopilovitch                      aek@vib.usr.pu.ru
Saint-Petersburg
Russia




^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: Consider her way -- Re: Dimensionality Checking
@ 2001-12-15  2:24 Alexandre E. Kopilovitch
  2001-12-17 12:49 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandre E. Kopilovitch @ 2001-12-15  2:24 UTC (permalink / raw)
  To: comp.lang.ada

"Mark Lundquist" <no.spam@getalife.com> wrote:
>you have to hand-code all needed conversions for base
>and derived units (vs. defining them for a handful of base units).  Nor are
>they reversible, i.e. for interoperability between m and km I would have to
>write the conversion going each way rather than simply defining the
>relationship between them.

So you are going to introduce the explicit relationships between the types,
and some reduction rules for the statements such as
  Variable := Expression;
- right? Hmm, that will be a great job, substantial innovation, and will produce
a visible impact on the whole Ada core language. The applications of that new
feature surely will not be restricted to the unit conversions.

>> > in this regard (unit abstraction for numeric types).
>> By the way, I still don't see an abstraction here. How will you describe the
>> notion of unit as an abstraction? For example "a type is the set of possible
>> values and the set of operations" - and what is a unit?
>
>Well, what is a "value"? :-)

No problem. Let us be slightly more formal: "a type is an ordered pair of the
sets; the elements of the first set are called the values of this type; the
elements of the second set are subroutines, and they are called the operations
of this type".

>The concept of
>unit, like that of value, is not "definable" in the language, but that is
>not necessary.  You're getting all philosophical about it and making it
>harder than it really is :-).  But I certainly do see an abstraction in units...

In such a case, perhaps you are able to describe - more or less formally -
that abstraction, which you see here?


Alexander Kopilovitch                      aek@vib.usr.pu.ru
Saint-Petersburg
Russia




^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: Consider her way -- Re: Dimensionality Checking
@ 2001-12-14 14:13 Alexandre E. Kopilovitch
  2001-12-14 16:07 ` Wes Groleau
  2001-12-14 19:49 ` Mark Lundquist
  0 siblings, 2 replies; 10+ messages in thread
From: Alexandre E. Kopilovitch @ 2001-12-14 14:13 UTC (permalink / raw)
  To: comp.lang.ada

"Mark Lundquist" <no.spam@getalife.com> wrote:
>>>Ada's type system?
>> That facility corresponds to a major general software engineering paradigm.
>
>But it has not always been so with strong typing.  I submit that it became
>"general" because it was useful in practice and feasible for implementation
>in a programming language.  I feel that unit-safety with automatic unit
>conversion is a concept that is similarly useful and feasible.
I doubt that - the latter. The scaling, that is, employment of the different
units for the same magnitude in a program is a relatively rare case. And I
beleive that the general rule is that all magnitudes in a subroutine should be
uniform, that is, a certain unit must be selected for each magnitude, and all
values of that magnitude in the subroutine must be expressed using that selected
unit. Certainly, the values of the magnitude may come from the external sources
- the parameters and input streams, and those values may be expressed using
other units; in those cases the conversions should be performed at the boundaries:
all the arguments of a call must be converted to the units required by the
subroutime called (before or inside an invocation), and the incoming numbers
must be converted immediately.

>> Ada is a "superassembler", which facilitates dealing with the general software
>> engineering enviromnent, besides of the real computer architectures.
>
>I agree.  My position is, let's make it a little more "super"
I think that such additions may lead to Ada++.

> in this regard (unit abstraction for numeric types).
By the way, I still don't see an abstraction here. How will you describe the
notion of unit as an abstraction? For example "a type is the set of possible
values and the set of operations" - and what is a unit?

>> >>   The proper way to do the dimensional/unit analysis for the Ada programs is
>> >> to use the ASIS and some suitable language processor [snip...]
>> >
>> >For one thing, you would still have to code all of of your own unit conversions.
>> Why? Two distinct subtypes of the same type may be used together in an expression
>> without any conversion.
>
>True, unfortunately for your scheme... if a quantity expressed in grams is
>used in an expression where a quantity expressed in kilograms was meant, and
>they are both the same type (because they are of the same dimensionality --
>though they may be different subtypes, I expect for the benefit of your
>checking metalanguage?), then no incompatibility is detected by the
>compiler.  Notwithstanding the detection issue, to correct the
>incompatibility you must run the value through a unit (scaling) conversion
>(which I understand would not entail a type conversion in your scheme).
>Where do these unit conversion functions come from?  They must be
>hand-coded.
Yes, surely, they must be hand-coded. But as I said above, there are only two
kinds of places where those conversions are needed - at the subroutine calls
and after input statements. I do not think that the probability of an error
there is substantially higher that the probability of a mistake within a
declaration of the "unit-aware types".

>My proposal would be to build unit-awareness
>into the type system.  That would completely change the outlook.  You would
>not think of unit-safety as being "based on" the type system -- instead,
>aspects of the semantics of the type system would be based on unit-safety!
In my opinion, the main underlying problem with units is that they are all
relative. There is no absolute unit for a distance, as well as for time,
mass, resistance etc. And the abstractions for a relativities usually appear
to be quite complex things. Therefore it is difficult to believe that such
a thing may simplify or somehow facilitate real programmimg.

  The principal difference between the dimensionality and the units is that
it is very often necessary to mix the variables of different dimensionality
in a formulae, while a mix of different units (of the same dimensionality) is
a nonsense.


Alexander Kopilovitch                      aek@vib.usr.pu.ru
Saint-Petersburg
Russia





^ permalink raw reply	[flat|nested] 10+ messages in thread
* Consider her way -- Re: Dimensionality Checking
@ 2001-12-11 19:10 Alexandre E. Kopilovitch
  2001-12-11 22:45 ` Mark Lundquist
  2001-12-13 21:08 ` Nick Roberts
  0 siblings, 2 replies; 10+ messages in thread
From: Alexandre E. Kopilovitch @ 2001-12-11 19:10 UTC (permalink / raw)
  To: comp.lang.ada

Recent discussion about the dimensions/unit analysis seems to me... well, not
directed by the spirit of the Ada language. As far as I understand, all
participants of the discussion presume that if the dimensional/unit analysis
should be done for an Ada program then it must be performed entirely with the
facilities of Ada language itself. I think that that assumption is plain wrong.

  Let us consider what the dimensional/unit analysis is, in general terms.
For every dimension/unit U we have the mapping Deg_U, which assigns the
rational numbers to the subtypes (that is, the domain of the Deg_U is the set
of all subtypes in our Ada program, and the range of the Deg_U is the set of
rational numbers). We extend this mapping to the variables and user-defined
functions, using the subtype of a variable and the subtype that a function
returns. The mapping Deg_U is "logarithmic", that is, for any variables (or 
user-defined functions) X, Y, Z:
  Z is compatible with X * Y implies Deg_U(Z) = Deg_U(X) + Deg_U(Y), and
  Z is compatible with X / Y implies Deg_U(Z) = Deg_U(X) - Deg_U(Y),
Then we require for all assignments (including an argument passing), additions
and subtractions in our program, that the values of the mapping Deg_U for the
right operand (side) must be equal to the corresponding value for the left
operand. This requirement permits us to define Deg_U over the rational
expressions. Taking into account that the "logarithmic" rule effectively
determines the values of the mapping for the square root, we conclude that 
the mapping Deg_U is defined over the algebraic expressions. The final step
is to assign zero value to all standard (predefined) transcendent functions
(such as Sin etc.). So, the mapping Deg_U is defined for all expressions,
and the condition to be verified is already formulated: for each assignment,
addition and subtraction the value of the mapping Deg_U on the right operand
must be equal to the corresponding value on the left operand.
  This is a definition of the basic "linear" dimensional analysis. One may
construct other, more sophisticated forms of the dimensional analysis for the
specific purposes.

  Now let's recall the fact that the Ada is not a problem-oriented language,
but rather a "superassembler". It intentionally and carefully avoids all
paradigms that aren't closely related to the real computer architectures or
to the general software engineering, even if those paradigms are heavily used
in some significant application area. (Note that I'm speaking here about the
paradigms; the data representation issues are another matter, that is a natural
job for an assembler.)
  Obviously, the dimensionality paradigm is one of the kind that Ada avoids:
it belongs neither to a computer architecture nor to the general software
engineering, but to the particular application area, no matter how significant
it is in the real world. Therefore Ada most probably will not take any move
to support it directly.

  The proper way to do the dimensional/unit analysis for the Ada programs is
to use the ASIS and some suitable language processor, I guess that the SML
might be the best for this purpose (because it is well-suited for the
manipulations with the algebraic type systems). So the configuration of the
whole tool chain may look like that:

       dimension/unit values for the subtypes
                       |
                       |
                      \|/
                       |
  |------|         |---------|	      |-------------|
  | ASIS | ------> | SML     | ------ | SML         |
  | tool |         | program |        | interpreter |
  |------|         |---------|        |-------------|
     |                 |
    /|\                |
     |                \|/
     |                 |
  |----------|    diagnostic output
  | Ada      |      
  | compiler |
  |----------|
     |
    /|\
     |
     |
 program to be verified
   

  Finally, I'll try to explain why the subtypes, and not the types, are the
natural carriers for the dimensionality info. Briefly, with the physical
magnitudes, all the dimensionalities are imaginary, and only the repetition
count within some underlying measurement process is real. That count is obviously
dimensionless. In fact, a dimension of physical magnitude is the abstraction
for the class of the instruments with which we can measure the magnitude.
  If you do not like such vague metaphysical arguments then consider the
following question: if X and X*X belong to the different types, how will you
treat (interpret) the usual approximations by the Taylor series?
  And as for the units, I hope everyone will agree that there is no fundamental
difference (in physics) between miles and kilometers.


Alexander Kopilovitch                      aek@vib.usr.pu.ru
Saint-Petersburg
Russia




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

end of thread, other threads:[~2001-12-17 12:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-13  0:09 Consider her way -- Re: Dimensionality Checking Alexandre E. Kopilovitch
2001-12-13 17:13 ` Mark Lundquist
  -- strict thread matches above, loose matches on Subject: below --
2001-12-15  2:24 Alexandre E. Kopilovitch
2001-12-17 12:49 ` Dmitry A. Kazakov
2001-12-14 14:13 Alexandre E. Kopilovitch
2001-12-14 16:07 ` Wes Groleau
2001-12-14 19:49 ` Mark Lundquist
2001-12-11 19:10 Alexandre E. Kopilovitch
2001-12-11 22:45 ` Mark Lundquist
2001-12-13 21:08 ` Nick Roberts

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