unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* (real? (* +i +i)) -> #f
@ 2012-08-03 10:02 JihemD
  2012-08-03 10:33 ` Ian Price
  2012-08-07 19:04 ` Mark H Weaver
  0 siblings, 2 replies; 4+ messages in thread
From: JihemD @ 2012-08-03 10:02 UTC (permalink / raw)
  To: Guile-user


Hi
I am playing around with Guile 2.05 on Kubuntu 12.04, 
why :
scheme@(guile-user)> (real? (* +i +i))
$13 = #f
but :
scheme@(guile-user)> (zero? (imag-part (* +i +i)))
$14 = #t

thxs
-- 
View this message in context: http://old.nabble.com/%28real--%28*-%2Bi-%2Bi%29%29--%3E--f-tp34250234p34250234.html
Sent from the Gnu - Guile - User mailing list archive at Nabble.com.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (real? (* +i +i)) -> #f
  2012-08-03 10:02 (real? (* +i +i)) -> #f JihemD
@ 2012-08-03 10:33 ` Ian Price
  2012-08-03 11:04   ` JihemD
  2012-08-07 19:04 ` Mark H Weaver
  1 sibling, 1 reply; 4+ messages in thread
From: Ian Price @ 2012-08-03 10:33 UTC (permalink / raw)
  To: JihemD; +Cc: Guile-user

JihemD <jihem01@online.fr> writes:

> Hi
> I am playing around with Guile 2.05 on Kubuntu 12.04, 
> why :
> scheme@(guile-user)> (real? (* +i +i))
> $13 = #f
> but :
> scheme@(guile-user)> (zero? (imag-part (* +i +i)))
> $14 = #t
>
> thxs

I believe guile only considers numbers with an _exact_ 0 imaginary part
to be real. However, since all guile complex numbers are inexact, this
means that (* +i +i) is not considered real.

scheme@(guile−user)> (* +i +i)
$19 = −1.0+0.0i
scheme@(guile−user)> (exact? (imag-part $19))
$20 = #f

While I don't know if this was a specific concern when writing, this is
in line with the interpretation in section 11.7.4  Numerical operations
of the r6rs document.

http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.7.4.1

If x is a real number object, then (rational? x) is true if and only if
there exist exact integer objects k1 and k2 such that (= x (/ k1 k2))
and (= (numerator x) k1) and (= (denominator x) k2) are all true. Thus
infinities and NaNs are not rational number objects.

(real? -2.5+0.0i)                              ⇒  #f
(real? -2.5+0i)                                ⇒  #t

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (real? (* +i +i)) -> #f
  2012-08-03 10:33 ` Ian Price
@ 2012-08-03 11:04   ` JihemD
  0 siblings, 0 replies; 4+ messages in thread
From: JihemD @ 2012-08-03 11:04 UTC (permalink / raw)
  To: Guile-user



Ian Price wrote:
> 
> I believe guile only considers numbers with an _exact_ 0 imaginary part
> to be real. However, since all guile complex numbers are inexact, this
> means that (* +i +i) is not considered real.
> 
> scheme@(guile−user)> (* +i +i)
> $19 = −1.0+0.0i
> scheme@(guile−user)> (exact? (imag-part $19))
> $20 = #f
> 
> While I don't know if this was a specific concern when writing, this is
> in line with the interpretation in section 11.7.4  Numerical operations
> of the r6rs document.
> 
> http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.7.4.1
> 
> If x is a real number object, then (rational? x) is true if and only if
> there exist exact integer objects k1 and k2 such that (= x (/ k1 k2))
> and (= (numerator x) k1) and (= (denominator x) k2) are all true. Thus
> infinities and NaNs are not rational number objects.
> 
> (real? -2.5+0.0i)                              ⇒  #f
> (real? -2.5+0i)                                ⇒  #t
> 
> -- 
> Ian Price
> 

Thx Ian, the concept of exactness is new for me :
scheme@(guile-user)> (real? +0i)
$1 = #t
scheme@(guile-user)> (inexact->exact 1.0)
$2 = 1
scheme@(guile-user)> (inexact->exact (* +i +i))
$3 = -1
scheme@(guile-user)> (* +i +i)
$4 = -1.0+0.0i
scheme@(guile-user)> (real? (* +i +i))
$5 = #f
scheme@(guile-user)> (real? (inexact->exact (* +i +i)))
$6 = #t

-- 
View this message in context: http://old.nabble.com/%28real--%28*-%2Bi-%2Bi%29%29--%3E--f-tp34250234p34250430.html
Sent from the Gnu - Guile - User mailing list archive at Nabble.com.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (real? (* +i +i)) -> #f
  2012-08-03 10:02 (real? (* +i +i)) -> #f JihemD
  2012-08-03 10:33 ` Ian Price
@ 2012-08-07 19:04 ` Mark H Weaver
  1 sibling, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2012-08-07 19:04 UTC (permalink / raw)
  To: JihemD; +Cc: Guile-user

On 08/03/2012 06:02 AM, JihemD wrote:
> I am playing around with Guile 2.05 on Kubuntu 12.04,
> why :
> scheme@(guile-user)>  (real? (* +i +i))
> $13 = #f
> but :
> scheme@(guile-user)>  (zero? (imag-part (* +i +i)))
> $14 = #t

In recent Scheme standards (both R6RS and draft R7RS), a number is 
considered real if and only if the imaginary part is an _exact_ zero. 
See the definitions of 'real?' in R6RS section 11.7.4 and R7RS section 
6.2.6.  The R6RS Rationale document provides some discussion in the 
"Flow analysis" portion of section 11.6.6.

The R6RS provides a 'real-valued?' predicate that might be closer to 
what you expect.  You can get it in Guile by importing (rnrs base).

As Ian noted, Guile does not currently support exact non-real complex 
numbers, so +i cannot be represented exactly, and thus the imaginary 
part of +i^2 is not known to be exactly zero.  If we add support for 
exact non-real complex numbers some day, then (real? (* +i +i)) will 
become #t.

> Thx Ian, the concept of exactness is new for me

The concept of exact numbers is described in R6RS section 3.2.

      Mark



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-08-07 19:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-03 10:02 (real? (* +i +i)) -> #f JihemD
2012-08-03 10:33 ` Ian Price
2012-08-03 11:04   ` JihemD
2012-08-07 19:04 ` Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).