[sage-devel] Re: is_Integer() function semantics

2009-04-25 Thread William Stein

On Fri, Apr 24, 2009 at 8:42 PM, Robert Bradshaw
rober...@math.washington.edu wrote:

 On Apr 24, 2009, at 8:24 PM, Nick Alexander wrote:


 Another option is

 sage: 3/2 + 1/2 in ZZ
 True
 sage: 3/2 + 1/3 in ZZ
 False

 I just ran into the True in ZZ returns True thing again.  How do I
 check to see if I passed an option or True?

 You can do x is True

Also you could do

   isinstance(x, bool) and x

but I like Robert's solution better.

William

--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-25 Thread nirmal

 How could you not notice?   If I do is_Integer I get a big DeprecationWarning:
 Does your Sage not do that?

The reason I did not notice it is that is_Integer() was in the body of
a main loop and no warnings were printed.

For example,

[n for n in range(0,10) if is_Integer(n+1)]

returns

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

However

[n for n in range(0,10) if is_Integer(n)]

returns null list

[ ]

In the first case the answer was correct and in the second case the
answer was wrong. In both cases, please note no warning was printed.
My sage version is 3.4 and using it on Mac OS X.

I am using Robert's solution. It seems to work well.

Thanks,
Nirmal


--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-25 Thread nirmal

 How could you not notice?   If I do is_Integer I get a big DeprecationWarning:
 Does your Sage not do that?

The reason I did not notice it is that is_Integer() was in the body of
a main loop and no warnings were printed.

For example,

[n for n in range(0,10) if is_Integer(n+1)]

returns

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

However

[n for n in range(0,10) if is_Integer(n)]

returns null list

[ ]

In the first case the answer was correct and in the second case the
answer was wrong. In both cases, please note no warning was printed.
My sage version is 3.4 and using it on Mac OS X.

I am using Robert's solution. It seems to work well.

Thanks,
Nirmal


--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-25 Thread Nick Alexander

 [n for n in range(0,10) if is_Integer(n+1)]

snip

 [n for n in range(0,10) if is_Integer(n)]

You are doing this from the command line, yes?  The first is getting  
preparsed, so that 1 is not a python int, it is a sage Integer:

sage: preparse('[n for n in range(0,10) if is_Integer(n+1)]')
'[n for n in range(Integer(0),Integer(10)) if is_Integer(n+Integer(1))]'
sage: preparse('[n for n in range(0,10) if is_Integer(n)]')
'[n for n in range(Integer(0),Integer(10)) if is_Integer(n)]'

As for the warnings not being printed, in the loop you are maybe not  
considered to be in Python global scope?  I cannot say.

Nick

--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-25 Thread nirmal


 snip

  [n for n in range(0,10) if is_Integer(n)]

 You are doing this from the command line, yes?  

I am doing this in the notebook()

-Nirmal
--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-24 Thread nirmal

Thanks for all the helpful suggestions. I did not realize that
is_Integer() was deprecated.

On Apr 22, 2:00 am, John Cremona john.crem...@gmail.com wrote:
 This is precisely why we deprecated all the is_*() functions for end-user use:

 --
 | Sage Version 3.4.1.rc4, Release Date: 2009-04-19                   |
 | Type notebook() for the GUI, and license() for information.        |
 --

 sage: is_Integer(3/2+1/2)
 /home/masgaj/.sage/temp/host_56_150/29373/_home_masgaj__sage_init_sage_0.py:1:
 DeprecationWarning:
 Using is_Integer from the top level is deprecated since it was
 designed to be used by developers rather than end users.
 It most likely does not do what you would expect it to do.  If you
 really need to use it, import it from the module that it is defined
 in.
   # -*- coding: utf-8 -*-
 False

 sage: (3/2+1/2).is_integral()
 True

 The is_*() functions just test the type of an abject (in programming terms):

 sage: type(3/2+1/2)
 type 'sage.rings.rational.Rational'

 and the result of 3/2+1/2 is of type Rational.  Mathematically, of
 course, the same number can be an integer and a rational (and a real
 and a complex and ...).

 John

 2009/4/22 Robert Bradshaw rober...@math.washington.edu:



  On Apr 21, 2009, at 10:54 PM, Craig Citro wrote:

  In module sage.rings.integer

  is_Integer(3/2+1/2)

  returns

  False   The expected output should be True as 3/2+1/2 = 2.

  I was planning to use this function to check if the result of
  division
  is a whole number.

  You could also use the is_integral method of rational numbers:

  sage: n = 3/2 + 1/2
  sage: n.is_integral()
  True

  (This function also exists on Integers, so you could even use it in
  situations where you weren't sure if you had an honest Integer or an
  integer masquerading as a Rational.)

  Another option is

  sage: 3/2 + 1/2 in ZZ
  True
  sage: 3/2 + 1/3 in ZZ
  False

  - Robert
--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-24 Thread William Stein

On Fri, Apr 24, 2009 at 10:59 AM, nirmal nrsax...@gmail.com wrote:

 Thanks for all the helpful suggestions. I did not realize that
 is_Integer() was deprecated.

How could you not notice?   If I do is_Integer I get a big DeprecationWarning:

sage: is_Integer(3)
/Users/wstein/.sage/temp/D_69_91_158_76.dhcp4.washington.edu/15220/_Users_wstein__sage_init_sage_0.py:1:
DeprecationWarning:
Using is_Integer from the top level is deprecated since it was
designed to be used by developers rather than end users.
It most likely does not do what you would expect it to do.  If you
really need to use it, import it from the module that it is defined
in.
  # -*- coding: utf-8 -*-
True
sage:

Does your Sage not do that?

William



 On Apr 22, 2:00 am, John Cremona john.crem...@gmail.com wrote:
 This is precisely why we deprecated all the is_*() functions for end-user 
 use:

 --
 | Sage Version 3.4.1.rc4, Release Date: 2009-04-19                   |
 | Type notebook() for the GUI, and license() for information.        |
 --

 sage: is_Integer(3/2+1/2)
 /home/masgaj/.sage/temp/host_56_150/29373/_home_masgaj__sage_init_sage_0.py:1:
 DeprecationWarning:
 Using is_Integer from the top level is deprecated since it was
 designed to be used by developers rather than end users.
 It most likely does not do what you would expect it to do.  If you
 really need to use it, import it from the module that it is defined
 in.
   # -*- coding: utf-8 -*-
 False

 sage: (3/2+1/2).is_integral()
 True

 The is_*() functions just test the type of an abject (in programming terms):

 sage: type(3/2+1/2)
 type 'sage.rings.rational.Rational'

 and the result of 3/2+1/2 is of type Rational.  Mathematically, of
 course, the same number can be an integer and a rational (and a real
 and a complex and ...).

 John

 2009/4/22 Robert Bradshaw rober...@math.washington.edu:



  On Apr 21, 2009, at 10:54 PM, Craig Citro wrote:

  In module sage.rings.integer

  is_Integer(3/2+1/2)

  returns

  False   The expected output should be True as 3/2+1/2 = 2.

  I was planning to use this function to check if the result of
  division
  is a whole number.

  You could also use the is_integral method of rational numbers:

  sage: n = 3/2 + 1/2
  sage: n.is_integral()
  True

  (This function also exists on Integers, so you could even use it in
  situations where you weren't sure if you had an honest Integer or an
  integer masquerading as a Rational.)

  Another option is

  sage: 3/2 + 1/2 in ZZ
  True
  sage: 3/2 + 1/3 in ZZ
  False

  - Robert
 




-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-24 Thread Nick Alexander

 Another option is

 sage: 3/2 + 1/2 in ZZ
 True
 sage: 3/2 + 1/3 in ZZ
 False

I just ran into the True in ZZ returns True thing again.  How do I  
check to see if I passed an option or True?

Nick

--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-24 Thread Robert Bradshaw

On Apr 24, 2009, at 8:24 PM, Nick Alexander wrote:


 Another option is

 sage: 3/2 + 1/2 in ZZ
 True
 sage: 3/2 + 1/3 in ZZ
 False

 I just ran into the True in ZZ returns True thing again.  How do I
 check to see if I passed an option or True?

You can do x is True

- Robert


--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-22 Thread Robert Bradshaw

On Apr 21, 2009, at 10:54 PM, Craig Citro wrote:

 In module sage.rings.integer

 is_Integer(3/2+1/2)

 returns

 False   The expected output should be True as 3/2+1/2 = 2.

 I was planning to use this function to check if the result of  
 division
 is a whole number.


 You could also use the is_integral method of rational numbers:

 sage: n = 3/2 + 1/2
 sage: n.is_integral()
 True

 (This function also exists on Integers, so you could even use it in
 situations where you weren't sure if you had an honest Integer or an
 integer masquerading as a Rational.)

Another option is

sage: 3/2 + 1/2 in ZZ
True
sage: 3/2 + 1/3 in ZZ
False

- Robert



--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-22 Thread John Cremona

This is precisely why we deprecated all the is_*() functions for end-user use:

--
| Sage Version 3.4.1.rc4, Release Date: 2009-04-19   |
| Type notebook() for the GUI, and license() for information.|
--

sage: is_Integer(3/2+1/2)
/home/masgaj/.sage/temp/host_56_150/29373/_home_masgaj__sage_init_sage_0.py:1:
DeprecationWarning:
Using is_Integer from the top level is deprecated since it was
designed to be used by developers rather than end users.
It most likely does not do what you would expect it to do.  If you
really need to use it, import it from the module that it is defined
in.
  # -*- coding: utf-8 -*-
False

sage: (3/2+1/2).is_integral()
True

The is_*() functions just test the type of an abject (in programming terms):

sage: type(3/2+1/2)
type 'sage.rings.rational.Rational'

and the result of 3/2+1/2 is of type Rational.  Mathematically, of
course, the same number can be an integer and a rational (and a real
and a complex and ...).

John

2009/4/22 Robert Bradshaw rober...@math.washington.edu:

 On Apr 21, 2009, at 10:54 PM, Craig Citro wrote:

 In module sage.rings.integer

 is_Integer(3/2+1/2)

 returns

 False   The expected output should be True as 3/2+1/2 = 2.

 I was planning to use this function to check if the result of
 division
 is a whole number.


 You could also use the is_integral method of rational numbers:

 sage: n = 3/2 + 1/2
 sage: n.is_integral()
 True

 (This function also exists on Integers, so you could even use it in
 situations where you weren't sure if you had an honest Integer or an
 integer masquerading as a Rational.)

 Another option is

 sage: 3/2 + 1/2 in ZZ
 True
 sage: 3/2 + 1/3 in ZZ
 False

 - Robert



 


--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: is_Integer() function semantics

2009-04-21 Thread Craig Citro

 In module sage.rings.integer

 is_Integer(3/2+1/2)

 returns

 False   The expected output should be True as 3/2+1/2 = 2.

 I was planning to use this function to check if the result of division
 is a whole number.


You could also use the is_integral method of rational numbers:

sage: n = 3/2 + 1/2
sage: n.is_integral()
True

(This function also exists on Integers, so you could even use it in
situations where you weren't sure if you had an honest Integer or an
integer masquerading as a Rational.)

-cc

--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---