### Email Archive: sbcl-devel (read-only)

 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Malcolm Reynolds - 2010-04-29 20:16 ```I'm not sure about the Lisp standard's view on this, but here is a variety of reasons why the correct mathematical answer is (arguably) 1, for any combination of integers or floats. I guess this doesn't answer whether it should be 1.0 or 1 but it definitely shouldn't be an error. http://www.faqs.org/faqs/sci-math-faq/specialnumbers/0to0/ Malcolm On Thu, Apr 29, 2010 at 9:01 PM, Roman Marynchak wrote: > Hello, > > I have found a tricky issue with EXPT behaviour in different > implementations. > > Namely, evaluating (expt 0.0 0) yields: > > 1.0 in SBCL > 1 in CLISP > 1.0 in Lispworks. > > (expt 0 0.0) results in: > > 1.0 in SBCL > error in CLISP > error in Lispworks > > > CLHS says that 0^0 = 1, and gives no details about float/integer > combinations of these zeros. > > So, what is the valid answer here? Is there some complex math theory behind > all this? > > > Regards, > Roman > > ------------------------------------------------------------------------------ > > _______________________________________________ > Sbcl-devel mailing list > Sbcl-devel@... > https://lists.sourceforge.net/lists/listinfo/sbcl-devel > > ```

[Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? Roman Marynchak <roman.marynchak@gm...>
 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Malcolm Reynolds - 2010-04-29 20:16 ```I'm not sure about the Lisp standard's view on this, but here is a variety of reasons why the correct mathematical answer is (arguably) 1, for any combination of integers or floats. I guess this doesn't answer whether it should be 1.0 or 1 but it definitely shouldn't be an error. http://www.faqs.org/faqs/sci-math-faq/specialnumbers/0to0/ Malcolm On Thu, Apr 29, 2010 at 9:01 PM, Roman Marynchak wrote: > Hello, > > I have found a tricky issue with EXPT behaviour in different > implementations. > > Namely, evaluating (expt 0.0 0) yields: > > 1.0 in SBCL > 1 in CLISP > 1.0 in Lispworks. > > (expt 0 0.0) results in: > > 1.0 in SBCL > error in CLISP > error in Lispworks > > > CLHS says that 0^0 = 1, and gives no details about float/integer > combinations of these zeros. > > So, what is the valid answer here? Is there some complex math theory behind > all this? > > > Regards, > Roman > > ------------------------------------------------------------------------------ > > _______________________________________________ > Sbcl-devel mailing list > Sbcl-devel@... > https://lists.sourceforge.net/lists/listinfo/sbcl-devel > > ```

 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Roman Marynchak - 2010-04-29 20:31 Attachments: Message as HTML ```The thing is that (expt 0 0) yields 1 in all three implementations, so no question here. That interesting article mostly discusses this case. And about 0.0^0.0 it says: " As a rule of thumb, one can say that 0^0 = 1 , but 0.0^(0.0) is undefined, meaning that when approaching from a different direction there is no clearly predetermined value to assign to 0.0^(0.0) ; but Kahan has argued that 0.0^(0.0) should be 1, because if f(x), g(x) --> 0 as x approaches some limit, and f(x) and g(x) are analytic functions, then f(x)^g(x) --> 1 " so it seems that error comes due to the undefined result of 0.0^0.0. Maybe there is some article devoted to this case? I have just implemented the EXPT patch for SBCL, but I do not know what should I return: 1, 1.0 or raise an error? Regards, Roman 2010/4/29 Malcolm Reynolds > I'm not sure about the Lisp standard's view on this, but here is a > variety of reasons why the correct mathematical answer is (arguably) > 1, for any combination of integers or floats. I guess this doesn't > answer whether it should be 1.0 or 1 but it definitely shouldn't be an > error. > > http://www.faqs.org/faqs/sci-math-faq/specialnumbers/0to0/ > > Malcolm > > On Thu, Apr 29, 2010 at 9:01 PM, Roman Marynchak > wrote: > > Hello, > > > > I have found a tricky issue with EXPT behaviour in different > > implementations. > > > > Namely, evaluating (expt 0.0 0) yields: > > > > 1.0 in SBCL > > 1 in CLISP > > 1.0 in Lispworks. > > > > (expt 0 0.0) results in: > > > > 1.0 in SBCL > > error in CLISP > > error in Lispworks > > > > > > CLHS says that 0^0 = 1, and gives no details about float/integer > > combinations of these zeros. > > > > So, what is the valid answer here? Is there some complex math theory > behind > > all this? > > > > > > Regards, > > Roman > > > > > ------------------------------------------------------------------------------ > > > > _______________________________________________ > > Sbcl-devel mailing list > > Sbcl-devel@... > > https://lists.sourceforge.net/lists/listinfo/sbcl-devel > > > > > ```

 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Harald Hanche-Olsen - 2010-04-29 23:59 ```It seems to me that the hyperspec is quite specific about (expt 0.0 0): When power-number is an integer 0, then the result is always the value one in the type of base-number, even if the base-number is zero (of any type). That is: (expt x 0) == (coerce 1 (type-of x)) You can't possibly get any clearer than that. And it continues: If power-number is a zero of any other type, then the result is also the value one, in the type of the arguments after the application of the contagion rules in Section 12.1.1.2 (Contagion in Numeric Operations), with one exception: the consequences are undefined if base-number is zero when power-number is zero and not of type integer. In other words, the consequences of (expt ZERO 0.0) are undefined if ZERO is a zero of any type. - Harald ```

 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Roman Marynchak - 2010-04-30 06:17 Attachments: Message as HTML ```Thanks for this explanation. Now I understand the behavior of EXPT in CLISP and Lispworks, and I will modify the patch for SBCL accordingly. Regards, Roman 2010/4/30 Harald Hanche-Olsen > It seems to me that the hyperspec is quite specific about > (expt 0.0 0): > > When power-number is an integer 0, then the result is always the > value one in the type of base-number, even if the base-number is > zero (of any type). That is: > > (expt x 0) == (coerce 1 (type-of x)) > > You can't possibly get any clearer than that. > > And it continues: > > If power-number is a zero of any other type, then the result is also > the value one, in the type of the arguments after the application of > the contagion rules in Section 12.1.1.2 (Contagion in Numeric > Operations), with one exception: the consequences are undefined if > base-number is zero when power-number is zero and not of type > integer. > > In other words, the consequences of (expt ZERO 0.0) are undefined if > ZERO is a zero of any type. > > - Harald > > > ------------------------------------------------------------------------------ > _______________________________________________ > Sbcl-devel mailing list > Sbcl-devel@... > https://lists.sourceforge.net/lists/listinfo/sbcl-devel > ```

 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Tobias C. Rittweiler - 2010-04-30 07:30 ```Roman Marynchak writes: > Thanks for this explanation. Now I understand the behavior of EXPT in CLISP > and Lispworks, and I will modify the patch for SBCL accordingly. You can signal an appropriate subtype of sb-kernel::reference-error and include '(:ansi-cl :function expt) as reference so future people bitten by it will have a pointer into the right direction. -T. ```

 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Roman Marynchak - 2010-04-30 07:51 Attachments: Message as HTML ```In the initial patch I signal SB-KERNEL::ARGUMENTS-OUT-OF-VALID-DOMAIN, this condition is derived from ARITHMETIC-ERROR. This is similar to Lispworks behavior. CLISP signals DIVIZION-BY-ZERO, which is a bit confusing. Is that possible to derive from ARITHMETIC-ERROR and REFERENCE-ERROR at the same time? Regards, Roman 2010/4/30 Tobias C. Rittweiler > Roman Marynchak writes: > > > Thanks for this explanation. Now I understand the behavior of EXPT in > CLISP > > and Lispworks, and I will modify the patch for SBCL accordingly. > > You can signal an appropriate subtype of sb-kernel::reference-error and > include '(:ansi-cl :function expt) as reference so future people bitten > by it will have a pointer into the right direction. > > -T. > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Sbcl-devel mailing list > Sbcl-devel@... > https://lists.sourceforge.net/lists/listinfo/sbcl-devel > ```

 Re: [Sbcl-devel] What is the valid return value of (expt 0.0 0) and (expt 0 0.0)? From: Tobias C. Rittweiler - 2010-04-30 08:02 ```Roman Marynchak writes: > In the initial patch I signal SB-KERNEL::ARGUMENTS-OUT-OF-VALID-DOMAIN, this > condition is derived from ARITHMETIC-ERROR. This is similar to Lispworks > behavior. CLISP signals DIVIZION-BY-ZERO, which is a bit confusing. Is that > possible to derive from ARITHMETIC-ERROR and REFERENCE-ERROR at the same > time? Conditions support multiple inheritance like classes, so: (define-condition arithmetic-reference-error (arithmetic-error reference-condition) ()) -T. ```