From: Dmitry A. Kazakov on
On Fri, 02 Sep 2005 16:23:23 +0200, Georg Bauhaus wrote:

> Dmitry A. Kazakov wrote:
>> On Fri, 02 Sep 2005 12:43:24 +0200, Georg Bauhaus wrote:
>>
>>>Dmitry A. Kazakov wrote:
>>>
>>>>>>The problem with the current (Ada 83) design is that it tries to abstract
>>>>>>away trivial mathematical facts:
>>>>>
>>>>>As does a computer :-)
>>>>
>>>>It does what you tell it. Computers do not have free will! (:-))
>>>
>>>So why do you want to tell it about non-computer mathematics?
>>
>> Huh, there is only mathematics and non-mathematics!
>
> Not at all. Mathematics is not even a well defined term in a formal
> sense of the word "definition". (Notice the recursion :-)
>
> Thus computer-mathematics (as in theory of real, operating hardware)
> if used in a PL context has to start from some description
> of the real computer to be used with a PL program.

So you add another adjective to get: "ill-defined computer mathematics."
(:-))

> Real computers executing (non-empty) programs translated from Ada text
> cannot but transorm a finite number (> 0) of finite (non-empty) sets
> of discrete "fantasies" of electro-magnetic values, somehow coping
> with the effects of one or more "times".
>
> That excludes infinity and no-bits from real-computer mathematics,
> for a start. Likewise, forget about non-discrete numbers.

This is plain wrong. You can deal with all sorts of infinity in a finite
program. Because there is no limitation on how the set of computation
states (finite) have to be mapped onto the application domain set
(potentially infinite). There is no any problem to associate one state with
Pi, another with an empty set and third with aleph-twenty.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Dmitry A. Kazakov on
On Fri, 02 Sep 2005 16:14:55 +0200, Georg Bauhaus wrote:

> Dmitry A. Kazakov wrote:
>> On Fri, 02 Sep 2005 12:42:06 +0200, Georg Bauhaus wrote:
>>
>>>Dmitry A. Kazakov wrote:
>>>
>>>>On 01 Sep 2005 12:04:17 -0400, Robert A Duff wrote:
>>>
>>>>>Heh? You want this:
>>>>>
>>>>> procedure Put(S: String) is
>>>>> begin
>>>>> for I in S'First..S'Last loop -- equivalent to S'Range
>>>>> Put_Char(S(I));
>>>>>
>>>>>to crash when S = ""?
>>>>
>>>>Yes.
>>>
>>>What is your approach to subranges then?
>>>
>>> function h(s: String) return Unsigned_32 is
>>> prefix: String renames
>>> s(s'first .. s'first + Integer'min(3, s'length - 1));
>>> result: Unsigned_32 := 0;
>>> begin
>>> for k in prefix'range loop
>>> result := result or Shift_Left(Character'pos(prefix(k)),
>>> (k - prefix'first) * 8);
>>> end loop;
>>> return result;
>>> end h;
>>>
>>>(If you could assume for the moment that there is no
>>>Unchecked_Conversion and not a different/better algorithm etc.)
>>
>> I don't see any problem, so far. Subrange of an empty range is empty.
>
> But earlier you said that s'first .. ... should crash when
> s = "".

Yes, because the code above is incorrect in my view. You should explicitly
test for s'length = 0.

>> As
>> for the checksum of an empty string it is to be extra defined.
>>
>> You cannot in general case reverse any possible sequence S1, S2, S3, ... to
>> deduce S0.
>
> This requirement being generated by arbitrarily applying
> the mathematical habit of starting things, deducing thing,
> extending things to become some general case (not well defined
> for real computers), etc.

Empty range is such a generalization!

> Basic mathematical facts
> are basic relative to some starting point from which you perform
> mathematical reasoning.

What about secondary school as a starting point? (:-))

>> IF the sequence is a series bound by some operation *:
>> SN = x1 * x2 * ...* xN
>>
>> AND * is a group operation
>>
>> THEN you can take the unit element of the group for S0.
>
> And what does mathematical group theory offer when the computer
> executes fine without it? Why don't you start your basic
> mathematical theory from things that work, and explain them
> first?

It perfectly predicts where things like above work and where they fail.
Just try to rewrite your program to make it working for any array type.

Note there is nothing particularly difficult in writing some program in
C++. But *programming* in C++ is an immense problem. See any parallel?

> If a sphere of negative radius opens many interesting insights
> into unforeseen extensions of geometry, will this have an
> influence on a pot maker's occupation?

What about zero radius? If you want to play a Luddite, then start with
prohibiting empty strings. Do a writer need empty texts?

> I'm not asking these questions because I believe that mathematics
> is the wrong science for approaching real computers. It's not.
>
> However, every once in a while I'm having to defend
> that running computers and performing mathematics are two
> sets of operations. They have a fair amount of overlap.
[..]

What is the point? Do computers something which cannot be described using
mathematics? That is not what you are saying. Then what?

A trivial analysis shows inconsistency of A'First..A'First-1. There is
nothing new in that. It is well known. A pragmatic school calmly admits it,
but points out that to fix would probably mean too much work, and that it's
much too late anyway, especially, because programs are infested with
constructs like A'First..A'Last, Index..A'Last etc.

But you seem to be seeking for rather philosophic arguments to keep it
inconsistent. (:-))

>> Now, take something else: let * be max, what would be the maximum of an
>> empty array?
>
> A problem of math-think. Like this
>
> ... talking to son:
>
> "See this little wood over there? I have counted the trees,
> there are 139."
>
> ... a little later:
>
> "Remember I told you about this wood having 139 trees, 14
> years ago? Now there are only 23 left."
>
> ... talking to granddaughter visiting:
>
> "See this little wood over there?" -- "No."
> -- "It has 0 trees". -- "Ha, ha."
>
> If there is nothing about which to say anything,
> then mathematicians decide to say something about
> it: truth. Useful, but in a material setting, you have
> to consider whether it makes sense.

Absolutely. Mathematics is applied to solve problems. To be able to do it
the mathematical models you use have to be adequate. But even before that
they have to be *consistent*. For good or bad, but no inconsistent thing
can be adequate.

> Using your Max example,
> I could ask those mathematicians about the maximum of a
> subset of the natural numbers (possibly empty!). I'd venture
> a guess that the answer will likely be, "It depends.".
>
> For example, you have given "extra defined". ;-)

Exactly as with A'First. It depends! You choose A'First to exist for any
array. But I prefer a more usable in my view:

A(A'First) does exit

or

Index'Pos(A'First) <= Index'Pos(A'Last)

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Jeffrey R. Carter on
Gene wrote:

> I completely agree with the marginal utility of other-than-1 least
> array indices.

Then you need a lot more experience. There is great utility to arrays with lower
bounds other than 1, and to arrays with non-numeric bounds.

30 years ago, when I became a coder, I worked in dendroclimatology, attempting
to determine the climate of the past from tree-ring information. We had code
with big arrays of tree-ring data, all indexed from 1, of course, since this was
in FORTRAN 66, and other arrays of climate data. The tree-ring data started with
values from some year in the past, such as 1600, and the climate data in 1895 or
so. The code was liberally sprinkled with calculations to convert between the
logical indices (years) and the actual indices (1 .. # of years). Different
calculations had to be used for the 2 data sets, I didn't capture the algorithms
in functions because I didn't know any better, and sometimes I managed to use
the wrong calculation. Ah, those were the days!

How much easier it would have been if I could simply have indexed these things
from 1600 .. 1965 and 1895 .. 1965. (Having record types would have helped, too.)

This helps explain the popularity of C and its descendants: It gives a real
feeling of accomplishment to do this kind of thing successfully, even though it
contributes nothing to the solution of the real problem being addressed.

The problem in the example is that the code defines an array type with "Integer
range <>", allowing any lower bound in Integer, and proceeds to assume that all
values of the type have lower bound of 1. That's a simple implementation error.
Had the implementor recognized that values of the type may have any lower bound
in Integer, and used 'First rather than an incorrect magic number, the problem
would not have appeared.

If there is a requirement that the values have a lower bound of 1, there's an
Ada mechanism for that:

type A is array (Positive range <>) of Whatever;

type Lower_Bound_Always_1 (Length : Natural) is record
Value : A (1 .. Length);
end record;

Even then, one should still use 'First.

--
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail
05
From: Dr. Adrian Wrigley on
On Thu, 01 Sep 2005 14:42:22 -0700, Gene wrote:

....
> I completely agree with the marginal utility of other-than-1 least
> array indices.

Like others, I'm surprised to find this is controvertial.

People have given some examples already. My favourite
examples are:

Compatibility with languages that have 0-based arrays.
it would be really annoying if indices couldn't be shared
between C and Ada arrays, for example.
(most C/C++ users see litle utility in other-than-0 least indices!)

Ability for subprograms to receive slices of arrays as
parameters. C code often has to pass start and stop
indices as separate function parameters, in addition to
the pointer to the first element. Three parameters instead
of one adds clutter. Particularly common in recursive calls.

Arrays indexed by modular types. (I know these have been criticised
elsewhere). Modular indices are really handy for circular
buffers, as well as hash tables and things (pre Ada 200Y!).

Arrays indexed by characters (eg a letter frequency table,
'a' .. 'z').

I also use symmetric array indices (eg -10 .. 10) quite a
lot for tables indexed by differences.

Sometimes negative indices are useful too, (with 0 at the top, usually)
(eg -100 .. 0). This is useful for analysing events through
relative time. Negative indices are preconditions, positive
indices would be postconditions or responses. (
(If you only have positive indices, you find some arrays in
your program run forwards through time, and some run backwards.
Tracking which is which, and getting the '-' in the right
place is particularly error prone)

And of course, plenty of contrived examples can be made up,
some of which so actually occur in real problems.
It's just another area of coding where Ada matches the
problem domain, and other languages match the solution domain.
Like so many things in Ada, you may not use them every day
in some applications, but they're there when you need them!

By the way... why aren't fixed point types discrete?
The values are integral multiples of small, which can be
supplied by the user. So I'd expect to be able to use
fixed point types as array indices etc. You cant :(
Wouldn't fixed point be *much* more useful if it was discrete?
--
Adrian
From: Jacob Sparre Andersen on
"Dr. Adrian Wrigley" <amtw(a)linuxchip.demon.co.uk.uk.uk> writes:

> By the way... why aren't fixed point types discrete?

I don't know. Is it be a leftover from some limitations in Ada83?

> The values are integral multiples of small, which can be supplied by
> the user. So I'd expect to be able to use fixed point types as
> array indices etc. You cant :( Wouldn't fixed point be *much* more
> useful if it was discrete?

Yes.

Jacob
--
ýWhen in Rome; burn itý -- Diziet Sma