* Newbie Q @ 2005-09-20 1:11 Larry Luther 2005-09-20 4:09 ` Jim Rogers ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Larry Luther @ 2005-09-20 1:11 UTC (permalink / raw) 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". Larry ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 1:11 Newbie Q Larry Luther @ 2005-09-20 4:09 ` Jim Rogers 2005-09-20 5:48 ` Martin Dowie 2005-09-20 11:52 ` Dr. Adrian Wrigley 2005-09-20 4:09 ` Samuel Tardieu 2005-09-20 7:58 ` Dmitry A. Kazakov 2 siblings, 2 replies; 12+ messages in thread From: Jim Rogers @ 2005-09-20 4:09 UTC (permalink / raw) "Larry Luther" <larry.luther.nospam@dolby.com> wrote in news:RkJXe.771 $OC2.358@newssvr21.news.prodigy.com: > > 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 correct. This example exhibits a similar error between 29.0 and 30.0 degrees, between 19.0 and 20.0 degrees, and between 9.0 and 10.0 degrees. The person writing this program was clearly thinking in terms of integer arithmetic when he or she was dealing with either floating point of fixed point arithmetic. The example does not indicate whether Degrees is a fixed point or floating point type. This example would work better with a fixed point type than with a floating point type because one can always know what the minimum delta between two fixed point numbers is. The same cannot be said of a floating point number. The example properly demonstrates the syntax of the if..elsif..else syntax while also creating a logical error. Jim Rogers ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 4:09 ` Jim Rogers @ 2005-09-20 5:48 ` Martin Dowie 2005-09-20 11:52 ` Dr. Adrian Wrigley 1 sibling, 0 replies; 12+ messages in thread From: Martin Dowie @ 2005-09-20 5:48 UTC (permalink / raw) Jim Rogers wrote: > > "Larry Luther" <larry.luther.nospam@dolby.com> wrote in news:RkJXe.771 > $OC2.358@newssvr21.news.prodigy.com: > > >> >>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 correct. > This example exhibits a similar error between 29.0 and 30.0 degrees, > between 19.0 and 20.0 degrees, and between 9.0 and 10.0 degrees. > > The person writing this program was clearly thinking in terms of > integer arithmetic when he or she was dealing with either floating > point of fixed point arithmetic. > > The example does not indicate whether Degrees is a fixed point or > floating point type. This example would work better with a fixed > point type than with a floating point type because one can always > know what the minimum delta between two fixed point numbers is. > The same cannot be said of a floating point number. > > The example properly demonstrates the syntax of the if..elsif..else > syntax while also creating a logical error. or... it's a very rare fixed point number, where the delta is 1.0. type Degrees is delta 1.0 range 0.0 .. 100.0; Could be a decimal type, type Degrees is delta 1.0 digits 4 range 0.0 .. 100.0; But more likely, it's a bug... Cheers -- Martin ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 4:09 ` Jim Rogers 2005-09-20 5:48 ` Martin Dowie @ 2005-09-20 11:52 ` Dr. Adrian Wrigley 2005-09-20 13:33 ` Martin Dowie 2005-09-21 17:24 ` Martin Dowie 1 sibling, 2 replies; 12+ messages in thread From: Dr. Adrian Wrigley @ 2005-09-20 11:52 UTC (permalink / raw) On Tue, 20 Sep 2005 04:09:26 +0000, Jim Rogers wrote: > The example does not indicate whether Degrees is a fixed point or > floating point type. This example would work better with a fixed > point type than with a floating point type because one can always > know what the minimum delta between two fixed point numbers is. The minimum step is known as the *small* of the type (RM 3.5.9:8). The *maximum* smallest step is given by the "delta" of the type, but implementations are free to choose smaller steps unless an attribute is applied specifying the "small". I'm sure you know this, but I had only realized this a few weeks ago when talking about wanting to address arrays by fixed point types. I had got the impression that all fixed point values were integer multiples of the delta, whereas in fact there may be additional bits of precision used by the type. This seemed counter-intuitive. (what is the rationale for delta /= small?) -- Adrian ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 11:52 ` Dr. Adrian Wrigley @ 2005-09-20 13:33 ` Martin Dowie 2005-09-21 17:24 ` Martin Dowie 1 sibling, 0 replies; 12+ messages in thread From: Martin Dowie @ 2005-09-20 13:33 UTC (permalink / raw) Dr. Adrian Wrigley wrote: [snip] > (what is the rationale for delta /= small?) 'delta' is the abstract requirement from the programmer 'small' is the compilers implementation of the abstract requirement "solution space /= implementation space" all the time... Cheers -- Martin ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 11:52 ` Dr. Adrian Wrigley 2005-09-20 13:33 ` Martin Dowie @ 2005-09-21 17:24 ` Martin Dowie 1 sibling, 0 replies; 12+ messages in thread From: Martin Dowie @ 2005-09-21 17:24 UTC (permalink / raw) Dr. Adrian Wrigley wrote: > (what is the rationale for delta /= small?) I think of it as: 'delta' is the programmers minimum requirement in the problem space 'small' is the compilers implementation of that in the solution space Cheers -- Martin ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 1:11 Newbie Q Larry Luther 2005-09-20 4:09 ` Jim Rogers @ 2005-09-20 4:09 ` Samuel Tardieu 2005-09-20 5:52 ` Simon Wright 2005-09-20 16:26 ` Martin Krischik 2005-09-20 7:58 ` Dmitry A. Kazakov 2 siblings, 2 replies; 12+ messages in thread From: Samuel Tardieu @ 2005-09-20 4:09 UTC (permalink / raw) >>>>> "Larry" == Larry Luther <larry.luther.nospam@dolby.com> writes: Larry> So temperatures between 29.0 and 30.0 will be considered Larry> "freezing". Yes, given the definition of the Degrees type found on http://en.wikibooks.org/wiki/Programming:Ada:Control I have created an account on wikibooks and edited the page. Sam -- Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 4:09 ` Samuel Tardieu @ 2005-09-20 5:52 ` Simon Wright 2005-09-20 6:28 ` Samuel Tardieu 2005-09-20 16:26 ` Martin Krischik 1 sibling, 1 reply; 12+ messages in thread From: Simon Wright @ 2005-09-20 5:52 UTC (permalink / raw) Samuel Tardieu <sam@rfc1149.net> writes: > I have created an account on wikibooks and edited the page. I found the original Degrees'(10.0 .. 19.0) a neat way of expressing the concept, but correctness wins over neatness every time! ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 5:52 ` Simon Wright @ 2005-09-20 6:28 ` Samuel Tardieu 0 siblings, 0 replies; 12+ messages in thread From: Samuel Tardieu @ 2005-09-20 6:28 UTC (permalink / raw) >>>>> "Simon" == Simon Wright <simon@pushface.org> writes: Simon> I found the original Degrees'(10.0 .. 19.0) a neat way of Simon> expressing the concept, but correctness wins over neatness Simon> every time! Sure :) (moreover, the Degrees' was useless) ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 4:09 ` Samuel Tardieu 2005-09-20 5:52 ` Simon Wright @ 2005-09-20 16:26 ` Martin Krischik 2005-09-21 7:27 ` Samuel Tardieu 1 sibling, 1 reply; 12+ messages in thread From: Martin Krischik @ 2005-09-20 16:26 UTC (permalink / raw) Samuel Tardieu wrote: >>>>>> "Larry" == Larry Luther <larry.luther.nospam@dolby.com> writes: > > Larry> So temperatures between 29.0 and 30.0 will be considered > Larry> "freezing". > > Yes, given the definition of the Degrees type found on > http://en.wikibooks.org/wiki/Programming:Ada:Control > > I have created an account on wikibooks and edited the page. Thanks. Mind you small corrections can be done without an account as well ;-) Martin -- mailto://krischik@users.sourceforge.net Ada programming at: http://ada.krischik.com ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 16:26 ` Martin Krischik @ 2005-09-21 7:27 ` Samuel Tardieu 0 siblings, 0 replies; 12+ messages in thread From: Samuel Tardieu @ 2005-09-21 7:27 UTC (permalink / raw) >>>>> "Martin" == Martin Krischik <krischik@users.sourceforge.net> writes: Martin> Thanks. Mind you small corrections can be done without an Martin> account as well ;-) I like traceability and accounting, be it to allow the original author to contact the person who made the modification to discuss it if needed. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Newbie Q 2005-09-20 1:11 Newbie Q Larry Luther 2005-09-20 4:09 ` Jim Rogers 2005-09-20 4:09 ` Samuel Tardieu @ 2005-09-20 7:58 ` Dmitry A. Kazakov 2 siblings, 0 replies; 12+ messages in thread From: Dmitry A. Kazakov @ 2005-09-20 7:58 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2005-09-21 17:24 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-09-20 1:11 Newbie Q Larry Luther 2005-09-20 4:09 ` Jim Rogers 2005-09-20 5:48 ` Martin Dowie 2005-09-20 11:52 ` Dr. Adrian Wrigley 2005-09-20 13:33 ` Martin Dowie 2005-09-21 17:24 ` Martin Dowie 2005-09-20 4:09 ` Samuel Tardieu 2005-09-20 5:52 ` Simon Wright 2005-09-20 6:28 ` Samuel Tardieu 2005-09-20 16:26 ` Martin Krischik 2005-09-21 7:27 ` Samuel Tardieu 2005-09-20 7:58 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox