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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9d03247c8459fa7b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.de!news.germany.com!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Newbie Q Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Tue, 20 Sep 2005 09:58:45 +0200 Message-ID: <7s94kvyimovp$.1jx9yjqnjmfwx$.dlg@40tude.net> NNTP-Posting-Date: 20 Sep 2005 09:58:35 MEST NNTP-Posting-Host: 8d93c329.newsread2.arcor-online.net X-Trace: DXC=MglRLNFHNn?D9BSA]l6DQ8mU0GR8mWRXZ37ga[7jn919Q4_`VjiB8=X\UUgbkd X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:4940 Date: 2005-09-20T09:58:35+02:00 List-Id: On Tue, 20 Sep 2005 01:11:13 GMT, Larry Luther wrote: > I saw the following example in "Ada Programming" Wiki book: > > if Temperature >= Degrees'(40.0) then > Put_Line ("It's extremely hot"); > elsif Temperature in Degrees'(30.0 .. 39.0) then > Put_Line ("It's hot"); > elsif Temperature in Degrees'(20.0 .. 29.0) then > Put_Line ("It's warm"); > elsif Temperature in Degrees'(10.0 .. 19.0) then > Put_Line ("It's cool"); > elsif temperature in Degrees'(0.0 .. 9.0) then > Put_Line ("It's cold"); > else > Put_Line ("It's freezing"); > end if; > > What happens at 29.5 degrees? > I'm assuming that "Temperature in Degrees'(20.0 .. 29.0)" will test > the interval Temperature >= 20.0 through Temperature <= 29.0. > So temperatures between 29.0 and 30.0 will be considered "freezing". You are right. The code above is that it tries to implement the thing known as "linguistic variables", maybe unconsciously. The terms (linguistic variables) "extremely hot", "hot", "warm" are fuzzy subsets of temperatures (not necessary intervals.) Further they can overlap, as they actually do: the same temperature might appear both cold and cool for you. The thing the code above implements is called "fuzzification." The implementation is of course wrong: 1. The result is in general case at least a subset of "extremely hot", "hot", "warm" etc. The variables may overlap. 2. The result is not crisp. It might be 1:cold, 0.5 cool, 0.3 freezing. 3. The set of variables should be complete. That is: the union of "extremely hot", "hot", "warm" should comprise all possible temperatures. This is what you have discovered with 29.5�C, which cannot be classified as any temperature! For an example of dealing with linguistic variables in Ada, see: http://www.dmitry-kazakov.de/ada/fuzzy.htm#linguistic_variable One final note. Ada does not have case-statement for real types because of 1-3. Even considering real numbers as pure numbers having no any semantics, they are intervals, which *model* margins aren't crisp (for the portability reasons.) So unlikely to discrete types, the case-statement cannot ensure: completeness and consistency. Neither any user-written program can. The attempt above perfectly illustrates this. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de