comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Surprise in array concatenation
Date: Thu, 8 Sep 2005 15:44:52 +0200
Date: 2005-09-08T15:44:53+02:00	[thread overview]
Message-ID: <36f5y9ptjia3$.1onymsey119zw.dlg@40tude.net> (raw)
In-Reply-To: 432011f0$0$24147$9b4e6d93@newsread4.arcor-online.net

On Thu, 08 Sep 2005 12:27:50 +0200, Georg Bauhaus wrote:

> Dmitry A. Kazakov wrote:
> 
>> How else you could check if 1 really refers to the physical 1!
> 
> Which physical 1? There is a written agreement on what represents
> 1 inside a computer, per computer.

Note that A=1 from the problem state is not a bit pattern. It is a set of
computational states for which A is considered be 1. So when you make a
memory dump and discover a bit pattern 000000001 at the address FF07712CA0
that tells absolutely nothing.

> As I said, math declares the swamp
> away into which it is built. Computer descriptions do soemthing similar.
> I do not usually try to write programs using funny interpretations of
> bits, and assume you don't either.

I don't care about representations as long as they aren't the part of the
problem space (like in communication protocols.)

>>>Can there be an index type in Ada that isn't ordered?
>> 
>> Sure:
>> 
>>    type Unordered_Index is (A, B, C, D);
>>    function "<" (Left, Right : Unordered_Index)
>>       return Boolean is abstract;
> 
> I was thinking of index types that are not ordered in Ada. See
> below.

if A < B then -- Compile error! What else you need?

>> 1. This is plain wrong. If L=U then (L+U)/2=L.
> 
> As you say, "+" isn't predefined for enumeration types.
> 
> As for M and (L+U)/2 I should have said, in Ada (and other PLs)
> if 0 <= A'Length <= 1, then (L+U)/2 can be 0 = M, and A'Length/2 = 0, always.

You cannot work with Length, it is another type! A'Length is universal
integer see ARM 3.6.2.

Mathematical equivalent of A'Length is distance between points
A'First/A'Last. If you want to work with A'Length, then you have to switch
from indices to the positions of, i.e. to I'Pos:

Array : Index -> Element
Index'Pos : Index -> Universal_Integer

Note that working with positions breaks the abstraction, because the order
of Index might be different from one of the position! If some day Ada will
have abstract arrays, then "for I in A loop" should iterate it in the order
of the Index, and not in the arbitrary one of Index'Pos.

>> (For generalizations on unordered cases see "convex hull")
> I'm trying to see arrays, and possible improvements. If a convex hull
> offers something useful

Believe me, convex sets (whether (1-t)a + tb belongs to the same set forall
0<=t<=1) are extremely important for countless numeric methods,
computational geometry etc.

>> 2. M could not be computed just because "+", "/", 2 aren't defined. Then of
>> course there could be no order;
> 
> But in fact, Ada's enumeration types are ordered.

See above.

> Try to make this pass Ada compilation,
> 
> type Unordered_Index is (A, B, C, D);
> for Unordered_Index use (A => 1, B => 3, C => 2, D => 4);

This has little to do with the order of Unordered_Index. The representation
clause defines representation. You should never mix:

1. The user-defined order and other operations (like +, -) and literals
from the problem space;
2. The positions of discrete values;
3. The representations of discrete values.

These all are different things. I hope it is clear that algorithms should
be written in terms of (1)?

>> 3. Note that (1) is wrong for modular types.
> 
> And?

and you could not write a generic array algorithm both relying on (1) and
usable for modular types.

>> Not surprisingly, they aren't
>> numbers,
> 
> That's news. There are numbers congruent modulo some number.
> But you think these numbers aren't numbers?

Yes. Modular 1 is an infinite set of numbers = { x | x = 1 (mod 16) }. You
can try to abstract this fact by choosing some definite element from each
of these sets. But you cannot do it completely. Because the structure is
different from one of Z. Some important results valid for Z will not hold.
What else would be the reason to have modular numbers?

>> but classes of equivalence (sets of numbers, infinite sets, BTW,
>> yet representable in the computer, how strange (:-)).
> 
> One equivalence class is not the same as the set of numbers mapped
> to members of the equivalence class. "type X is mod 10;" implies a
> finite set of values. Try "a: X; a := 42;" In other words, 42 cannot
> belong to the set of values expressed by X.

You again mixing sets and elements of. 42 is a literal. In the case of
equivalence classes it denotes not a number (Z) but a class of. There is no
class X'(42) for mod 10. Yet 42, now as an element of Z, is one of X'(2)
because 42=2(mod 10).

> Belonging and congruence are not the same thing.

They are exactly same. It is how the set is defined.

> For example, we cannot count an absolute
> number of items when there are at least as many items as the modulus.

This is the same logic error as above with A'Length. The type of the
cardinal numbers in Ada is defined as Universal_Integer. It is not the type
of the elements in a set!

(Taking too much C++ might be dangerous for your health! (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2005-09-08 13:44 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
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 [this message]
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