comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Integers and Mathematical Correctness
Date: Mon, 29 Sep 2014 18:25:00 +0200
Date: 2014-09-29T18:25:00+02:00	[thread overview]
Message-ID: <hrq0usei9d61$.19iv7gsyzpjia$.dlg@40tude.net> (raw)
In-Reply-To: 86b50b2e-57ad-47f3-bdaf-b98abcb722be@googlegroups.com

On Mon, 29 Sep 2014 07:58:56 -0700 (PDT), Adam Beneschan wrote:

> On Sunday, September 28, 2014 12:47:18 AM UTC-7, Dmitry A. Kazakov wrote:
> 
>>> Therefore, any 
>>> operation that returns a modular type will automatically convert a
>>> negative value to the value modulo the modulus.
>> 
>> No. This is a description of some possible implementation of the operation
>> based on an integer type. This is not the only one implementation, e.g.
>> there exist machine instructions directly implementing modular operations
>> for moduli 2**16, 2**32 ...
> 
> I'm not sure we're on the same page... I'm talking about modular types in
> Ada, and my statement is taken directly from RM 3.5.4(19).

Should probably be rewritten, because it looks in contradiction with
4.5(10) that claims:

"The predefined operations on integer types either yield the mathematically
correct result or raise the exception Constraint_Error."

The mathematically correct result of any modulo K arithmetic operation is
an element of the ring {0, 1, ..., K-1}

   10 + 10 = 20  is mathematically incorrect for modulo 16

The mathematically correct one is:

   10 + 10 = 4

Though, of course

   10 + 10 ≡ 4  (mod 16)
   10 + 10 ≡ 20 (mod 16)
   10 + 10 ≡ 36 (mod 16)
   10 + 10 ≡ 52 (mod 16)
   ...

[ Elements of the ring can be considered ether numbers

   { 0, 1, ..., K-1 }

or sets of equivalence

  {{ 0, K, 2K, ... }, { 1, 1+K, 1+2K, ...}, ... , { K-1, 2K-1, 3K-1, ...}}

In ether case there is only one correct result, which cannot be "outside
the base range." ]

> (Of course, it's always possible for a clever optimizing compiler to
> generate code that skips a step.)

I bet that is the case for Unsigned_64, Unsigned_32 etc.

>> I also do not understand how all this might be related to rational numbers,
>> which are neither integer nor modular. 
> 
> There's no relation.

OK

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


  reply	other threads:[~2014-09-29 16:25 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-31 20:27 Integers and Mathematical Correctness chris.danx
2001-10-31 21:21 ` David C. Hoos
2001-10-31 22:16   ` chris.danx
2001-10-31 22:47     ` David C. Hoos
2001-10-31 22:55       ` chris.danx
2001-10-31 23:16         ` Matthew Heaney
2001-10-31 21:42 ` Mark Johnson
2001-11-01 18:57   ` Mark Johnson
2001-11-01 14:32 ` Wes Groleau
2001-11-01 16:18   ` wilhelm.spickermann
2001-11-01 16:48   ` chris.danx
2001-11-01 15:45 ` Charles Sampson
2001-11-01 16:20   ` Marin David Condic
2001-11-03 17:02     ` Richard Riehle
2001-11-05 14:47       ` Marin David Condic
2001-11-06  3:53         ` Eric G. Miller
2001-11-06  4:28           ` James Rogers
2001-11-06  6:06             ` peter
2001-11-06 14:48               ` James Rogers
2001-11-06 15:54                 ` Marin David Condic
2001-11-07  3:44             ` Eric G. Miller
2001-11-01 17:10   ` chris.danx
2001-11-01 17:52     ` Chad Robert Meiners
2001-11-01 19:02       ` chris.danx
2001-11-01 17:57     ` Wes Groleau
2001-11-03 14:57     ` Charles Sampson
2001-11-01 16:11 ` Charles Lindsey
2001-11-01 18:40   ` Wilhelm Spickermann
2001-11-01 19:18   ` chris.danx
2001-11-02  1:37     ` Steven Deller
2014-09-26  9:07       ` vincent.diemunsch
2014-09-26 16:38         ` Niklas Holsti
2014-09-26 16:58           ` AdaMagica
2014-09-26 17:51             ` Adam Beneschan
2014-09-27  9:01               ` AdaMagica
2014-09-27 10:15                 ` AdaMagica
2014-09-27 16:32                 ` Niklas Holsti
2014-09-27 16:49                   ` Jeffrey Carter
2014-09-27 18:52                     ` Niklas Holsti
2014-09-27 18:54                   ` Adam Beneschan
2014-09-27 19:07                     ` Adam Beneschan
     [not found]                 ` <3489504a-f82b-4fec-8a6c-7cb91854dd1e@googlegroups.com>
2014-09-27 19:21                   ` AdaMagica
2014-09-27 11:44           ` gautier_niouzes
2014-09-26 16:41         ` Adam Beneschan
2014-09-26 16:46         ` Adam Beneschan
2014-09-27 15:21           ` vincent.diemunsch
     [not found]             ` <34da5a39-9fa3-4e8e-a3f9-98f61a4ebcc7@googlegroups.com>
2014-09-28  7:47               ` Dmitry A. Kazakov
2014-09-29 14:58                 ` Adam Beneschan
2014-09-29 16:25                   ` Dmitry A. Kazakov [this message]
2014-10-01 19:48                   ` vincent.diemunsch
2014-10-02 11:10                     ` G.B.
2001-11-01 18:08 ` Tucker Taft
2001-11-01 18:54 ` David Starner
2001-11-01 21:44   ` Wilhelm Spickermann
2001-11-02 12:52 ` chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2001-10-31 22:42 Beard, Frank
replies disabled

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