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-12 13:04:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!ppp-2-227.cvx5.telinco.NET!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Dimensionality Checking (Ada 20XX) Date: Wed, 12 Dec 2001 19:10:22 -0000 Message-ID: <9v8gp9$dbhjr$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> NNTP-Posting-Host: ppp-2-227.cvx5.telinco.net (212.1.153.227) X-Trace: fu-berlin.de 1008191082 14009979 212.1.153.227 (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:17863 Date: 2001-12-12T19:10:22+00:00 List-Id: In an effort to get back to Ada a bit ;-) I'll describe what I see logs and exponentiations of units meaning, and how I see them working. 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. For a certain dimensionality, a 'scaling factor' is the factor (also a real number) by which a value in the unit must be multiplied to convert it to some (actual or notional) canonical unit for that dimensionality. 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.). We could imagine a unit (and I don't know whether this corresponds to custom in physics) called, say 'Log_Foot', which is intended to represent the natural logarithm of feet. 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 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)). 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, 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. According to our example units, this package would be instantiated something like this: package Foot_Log_Functions is new Ada.Numerics.Generic_Logarithmic_Functions(Foot,Log_Foot); use Foot_Log_Functions; Now, having discussed this matter with my dad (a physicist), we still couldn't agree whether this interpretation is correct, so I'd be really grateful for any kind of (more) authoritative comment. -- Best wishes, Nick Roberts