From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cc4f25d878383cc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-13 15:05:46 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!ppp-1-74.cvx2.telinco.NET!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Dimensionality Checking (Ada 20XX) Date: Thu, 13 Dec 2001 22:56:49 -0000 Message-ID: <9vbc87$eb6li$1@ID-25716.news.dfncis.de> References: <9v37ru$cdmva$2@ID-25716.news.dfncis.de> <9v4fkq$2bl$1@mvmap66.ciw.uni-karlsruhe.de> <9v5gjl$d9cth$1@ID-25716.news.dfncis.de> <9v5pmr$ftq$1@mvmap66.ciw.uni-karlsruhe.de> <2ZxR7.35081$ER5.394136@rwcrnsc52> <9v8gp9$dbhjr$1@ID-25716.news.dfncis.de> NNTP-Posting-Host: ppp-1-74.cvx2.telinco.net (212.1.140.74) X-Trace: fu-berlin.de 1008284745 15047346 212.1.140.74 (16 [25716]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Xref: archiver1.google.com comp.lang.ada:17895 Date: 2001-12-13T22:56:49+00:00 List-Id: "Stephen Leake" wrote in message news:u4rmv6ix4.fsf@gsfc.nasa.gov... > "Nick Roberts" writes: > > > In my view of the proposed scheme, a 'unit' has two essential > > attributes: a dimensionality; a scaling factor. > > > > A 'dimensionality' is a factor (a real number) for each of a set of > > dimensions. > > Hmm. In physics, dimensionality is an integer. Yes indeed. As you were, gentlemen. > > Supposing our set of dimensions is {Mass, Length, Time}. The unit > > 'Meter' would have the dimensionality (0, 1, 0), and let us choose > > for it the scaling factor 1. The unit 'Foot' would then have the > > same dimensionality, and a scaling factor of 0.3048 (approx.). A > > certain measurement, let us call it 'NJRH' (my height), might be > > 5.95 foot. I intend that the Ada conversion Meter(NJRH) would be > > predefined, and have the value 1.813 (approx.), as well as the > > conversion Foot(Meter'(1.813)), having the value 5.95 (approx.). > > Ok, but I'm not clear how to declare these in your new Ada. Something like this: type Basic_Dimension is (Mass, Length, Time); package Basic_Units is new Ada.Units(Basic_Dimension); Meter: constant Basic_Units.Unit_Type := (Dim => (0, 1, 0), Scaling => 1.0); Foot: constant Basic_Units.Unit_Type := (Dim => (0, 1, 0), Scaling => 0.3048); type Arm_Length is digits 5 range 0.0 .. 20.0 unit Meter; type Person_Height is delta 1.0/12 range 3.0 .. 9.0 unit Foot; NJRH: Person_Height := 5.95; Then we can use normal type conversion to automatically convert between feet and meters: Just_Long_Enough_to_Clip_Round_Ear: Arm_Length := Arm_Length( NJRH/2 ); > > It would have the dimensionality (0, 1/e, 0) and a scaling factor of > > our choosing, let us choose 1. The value of NJRH in log feet would > > be 1.783 (approx.). > > I'm not clear why a "dimensionality" of 1/e corresponds to the log of > feet, but then I don't know what log of feet means, so I guess you get > to define it. It doesn't. This was a deliberate mistake to see who was still alert. ;-) > > I do not intend that the Ada conversion Log_Foot(NJRH) would be > > permitted, nor Foot(Log_Foot'(1.783)). To achieve these conversions, > > it would be necessary to use Log and Exp functions explicitly. Thus, > > instead of Log_Foot(NJRH) we write Log(NJRH), and instead of > > Foot(Log_Foot'(1.783)) we write Exp(Log_Foot'(1.783)). > > But, how does the poor compiler know which conversions to allow, and > which to (pre)define? Conversions between units of the same dimensionality (of the same dimension set) are predefined. No other conversions are predefined. Some other conversions may be provided by predefined library units (generic ones). > > Assuming (and this may be an assumption that has to be dropped) > > units are built into Ada by means of -- having added an extra 'unit' > > attribute (in the notional sense as well as actually adding the > > attribute 'Unit) to all scalar types -- permitting the unit to be > > specified for fixed point types, > > Why are we still stuck on fixed point types? Oh shut up. :-) We're no longer stuck on fixed point types, okay? > > it would be necessary to provide a package such as this: > > > > > > generic > > type Proportional_Type is delta <>; > > type Logarithmic_Type is delta <>; > > Base: constant some_real_type := e; > > > > package Ada.Numerics.Generic_Logarithmic_Functions is > > > > function Log (X: in Proportional_Type) return Logarithmic_Type; > > function Exp (X: in Logarithmic_Type) return Proportional_Type; > > > > end; > > > > > > This package would check, upon instantiation, that the dimensionalities of > > Proportional_Type and Logarithmic_Type -- (Mp,Lp,Tp) and (Ml,Ll,Tl) > > respectively, let's say -- are related in the correct way: Mp=Ml/e; Lp=Ll/e; > > Tp=Tl/e. Typically, it should be possible for this check to be done at > > compile time. > > Ok, sounds like you could make it consistent. The above package would NOT do the check mentioned, it would do the following simple check: squeal if the dimension sets of the units of the two types are the same (i.e. ensure they are different). In the above package, I suspect both types should be floating point, rather than fixed point. > I still maintain that, in physics, > log (meters) is _meaningless_, and _never_ occurs in a real-world > problem. So attempting to define its meaning in Ada is simply not > useful. You can define something that is self-consistent, but it won't > match physics. > > I don't think you'll find a physics text that actually states "log > (meters) is meaningless and forbidden", because it seems obvious, but > I'll look in mine tonight. Maybe a high school text, where they > introduce the notion of measurement, would discuss this (I only have > my college text). You may be quite right. This is an area where I happily concede a disgusting ignorance. > -- > -- Stephe -- Best wishes, Nick Roberts