comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Surprise in array concatenation
Date: Fri, 2 Sep 2005 21:48:13 +0200
Date: 2005-09-02T21:47:42+02:00	[thread overview]
Message-ID: <11p5i525v2q5d$.17ayuwvqhazo1.dlg@40tude.net> (raw)
In-Reply-To: 43187a50$0$24162$9b4e6d93@newsread4.arcor-online.net

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



  reply	other threads:[~2005-09-02 19:48 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-01  3:16 Surprise in array concatenation Gene
2005-09-01  7:55 ` Dmitry A. Kazakov
2005-09-01  8:02   ` Florian Weimer
2005-09-01 11:48     ` Georg Bauhaus
2005-09-01 12:02       ` Lutz Donnerhacke
2005-09-01 13:01         ` Georg Bauhaus
2005-09-01 15:54       ` Florian Weimer
2005-09-01 16:09     ` Robert A Duff
2005-09-05  8:38       ` Jean-Pierre Rosen
2005-09-05 23:52         ` Robert A Duff
2005-09-06  9:03           ` Jean-Pierre Rosen
2005-09-07 17:57         ` adaworks
2005-09-07 20:01           ` Robert A Duff
2005-09-08  8:08             ` Jacob Sparre Andersen
2005-09-07 22:46           ` Jeffrey Carter
2005-09-08  4:43             ` Simon Wright
2005-09-08 10:36               ` Georg Bauhaus
2005-09-08 13:47                 ` Ed Falis
2005-09-08 17:03                   ` Pascal Obry
2005-09-08 16:45               ` Jeffrey Carter
2005-09-08 19:37                 ` Simon Wright
2005-09-08  6:32             ` adaworks
2005-09-08  9:09               ` Jean-Pierre Rosen
2005-09-08 16:56               ` Jeffrey Carter
2005-09-09 14:04                 ` Bob Spooner
2005-09-09 16:17                 ` adaworks
2005-09-23 23:04               ` Randy Brukardt
2005-09-14  8:57           ` Ole-Hjalmar Kristensen
2005-09-23 23:09           ` Randy Brukardt
2005-09-24 10:49             ` Larry Kilgallen
2005-09-24 20:27             ` Lurker
2005-09-25  0:20             ` Robert A Duff
2005-09-25 17:05             ` adaworks
2005-09-01 11:42   ` Georg Bauhaus
2005-09-01 13:59     ` Dmitry A. Kazakov
2005-09-01 15:36       ` Georg Bauhaus
2005-09-01 18:34         ` Dmitry A. Kazakov
2005-09-02 10:43           ` Georg Bauhaus
2005-09-02 13:11             ` Dmitry A. Kazakov
2005-09-02 14:23               ` Georg Bauhaus
2005-09-02 19:48                 ` Dmitry A. Kazakov
2005-09-02 17:21           ` Björn Persson
2005-09-01 16:04   ` Robert A Duff
2005-09-01 18:06     ` Dmitry A. Kazakov
2005-09-02 10:42       ` Georg Bauhaus
2005-09-02 13:20         ` Dmitry A. Kazakov
2005-09-02 14:14           ` Georg Bauhaus
2005-09-02 19:48             ` Dmitry A. Kazakov [this message]
2005-09-03 20:01               ` Georg Bauhaus
2005-09-04 10:13                 ` Dmitry A. Kazakov
2005-09-05 13:22                   ` Georg Bauhaus
2005-09-05 15:50                     ` Dmitry A. Kazakov
2005-09-05 18:20                       ` Georg Bauhaus
2005-09-05 18:31                         ` Georg Bauhaus
2005-09-06  8:20                         ` Dmitry A. Kazakov
2005-09-06 11:52                           ` Georg Bauhaus
2005-09-06 13:46                             ` Dmitry A. Kazakov
2005-09-06 15:51                               ` Georg Bauhaus
2005-09-06 21:32                                 ` Robert A Duff
2005-09-07  9:08                                 ` Dmitry A. Kazakov
2005-09-07 18:20                                   ` Georg Bauhaus
2005-09-07 19:07                                     ` Georg Bauhaus
2005-09-07 21:23                                     ` Dmitry A. Kazakov
2005-09-08 10:27                                       ` Georg Bauhaus
2005-09-08 11:39                                         ` Georg Bauhaus
2005-09-08 13:44                                         ` Dmitry A. Kazakov
2005-09-08 18:18                                           ` Georg Bauhaus
2005-09-09 10:06                                             ` Dmitry A. Kazakov
2005-09-09 12:26                                               ` Georg Bauhaus
2005-09-09 12:29                                               ` Georg Bauhaus
2005-09-01  8:48 ` Jean-Pierre Rosen
2005-09-01 15:57 ` Robert A Duff
2005-09-01 21:42   ` Gene
2005-09-01 22:56     ` tmoran
2005-09-05 15:53       ` Gene
2005-09-05 17:47         ` jimmaureenrogers
2005-09-05 22:13           ` Robert A Duff
2005-09-06  8:24             ` Dmitry A. Kazakov
2005-09-05 19:22         ` Jeffrey R. Carter
2005-09-05 21:54           ` Robert A Duff
2005-09-05 22:50             ` Larry Kilgallen
2005-09-05 23:46               ` Robert A Duff
2005-09-12  3:59                 ` Dave Thompson
2005-09-06 16:02             ` Jeffrey Carter
2005-09-06 21:00               ` Robert A Duff
2005-09-06  5:38         ` Pascal Obry
2005-09-05 21:48       ` Robert A Duff
2005-09-06  5:25         ` tmoran
2005-09-06 14:58           ` Robert A Duff
2005-09-06  9:26         ` Georg Bauhaus
2005-09-06 15:00           ` Robert A Duff
2005-09-07 11:02             ` Thierry Pirot
2005-09-07 20:09               ` Robert A Duff
2005-09-06 13:22         ` Bob Spooner
2005-09-06 15:30           ` Robert A Duff
2005-09-06 16:12             ` Jeffrey Carter
2005-09-06 21:21               ` Robert A Duff
2005-09-02 20:19     ` Jeffrey R. Carter
2005-09-03 12:51     ` Dr. Adrian Wrigley
2005-09-03 14:08       ` Jacob Sparre Andersen
2005-09-05  8:34         ` Jean-Pierre Rosen
2005-09-05  9:32           ` Arrays indexed by fixed point types (Was: Surprise in array concatenation) Jacob Sparre Andersen
2005-09-05 11:07             ` Jean-Pierre Rosen
2005-09-05 15:12               ` Dr. Adrian Wrigley
2005-09-05 12:14             ` Dmitry A. Kazakov
2005-09-05 13:07               ` Jacob Sparre Andersen
2005-09-05 15:10                 ` Dmitry A. Kazakov
2005-09-05 11:29           ` Surprise in array concatenation Dr. Adrian Wrigley
replies disabled

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