[sage-support] Inconsistency between Sage and Python

2014-10-06 Thread João Alberto
I am plotting some graphs, but the plot becomes cluttered because of
the long labels. The labels are result of a conversion from a Real
number to a string. The problem here is that Sage is not consistent
with Python, as shown in the example below.

Python:
 multiplier = [1.0e0, 1.0e1, 1.0e2]
 multiplier
[1.0, 10.0, 100.0]
 str(multiplier[-1])
'100.0'


Sage:
sage: multiplier = [1.0e0, 1.0e1, 1.0e2]
sage: multiplier
[1.00, 10.0, 100.]
sage: str(multiplier[-1])
'100.'

Is this a correct behavior of Sage? at least for me, the excess of
trailing zeros is causing some trouble.

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Inconsistency between Sage and Python

2014-10-06 Thread Vincent Delecroix
Hi João,

If you want precise control on the output, you might use the python
formatting (see
https://docs.python.org/2/library/string.html#formatstrings)

sage: x = RR(pi)
sage: print x
3.14159265358979
sage: print {:.3}.format(x)
3.1
sage: print {:.5}.format(x)
3.141

But perhaps it is not an answer to your question, is it?

Vincent

2014-10-06 18:03 UTC+02:00, João Alberto joa...@gmail.com:
 I am plotting some graphs, but the plot becomes cluttered because of
 the long labels. The labels are result of a conversion from a Real
 number to a string. The problem here is that Sage is not consistent
 with Python, as shown in the example below.

 Python:
 multiplier = [1.0e0, 1.0e1, 1.0e2]
 multiplier
 [1.0, 10.0, 100.0]
 str(multiplier[-1])
 '100.0'


 Sage:
 sage: multiplier = [1.0e0, 1.0e1, 1.0e2]
 sage: multiplier
 [1.00, 10.0, 100.]
 sage: str(multiplier[-1])
 '100.'

 Is this a correct behavior of Sage? at least for me, the excess of
 trailing zeros is causing some trouble.

 --
 You received this message because you are subscribed to the Google Groups
 sage-support group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sage-support+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-support@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-support.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Inconsistency between Sage and Python

2014-10-06 Thread slelievre

João Alberto Ferreira wrote:

 I am plotting some graphs, but the plot becomes cluttered because of 
 the long labels. The labels are result of a conversion from a Real 
 number to a string. The problem here is that Sage is not consistent 
 with Python, as shown in the example below. 

 Python: 
  multiplier = [1.0e0, 1.0e1, 1.0e2] 
  multiplier 
 [1.0, 10.0, 100.0] 
  str(multiplier[-1]) 
 '100.0' 


 Sage: 
 sage: multiplier = [1.0e0, 1.0e1, 1.0e2] 
 sage: multiplier 
 [1.00, 10.0, 100.] 
 sage: str(multiplier[-1]) 
 '100.' 

 Is this a correct behavior of Sage? at least for me, the excess of 
 trailing zeros is causing some trouble. 


One option is to work with RDF:

sage: multiplier = [1.0e0, 1.0e1, 1.0e2]
sage: multiplier = [RDF(x) for x in multiplier]
sage: multiplier
[1.0, 10.0, 100.0]
sage: str(multiplier[-1])
'100.0'
 

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Inconsistency between Sage and Python

2014-10-06 Thread Jeroen Demeyer

On 2014-10-06 18:03, João Alberto wrote:

Is this a correct behavior of Sage?
It's a feature, not a bug. The reason is that the number of digits gives 
an idea about the precision of the number. Compare


sage: RealField(20)(1)
1.
sage: RealField(100)(1)
1.

If both these would be printed as 1.0, you would lose this information 
about the precision.


Python has a fixed precision of 53 bits and prints a minimal number of 
digits.


--
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Unsafe directory at startup

2014-10-06 Thread robert
Installed pre-compiled Sage-6.3.app on Mac OS X 10.9.5

At startup of Terminal Session, there is this
~$ /Applications/Sage-6.3.app/Contents/Resources/sage/sage; exit
sys:1: RuntimeWarning: not adding directory '' to sys.path since everybody 
can write to it.
Untrusted users could put files in this directory which might then be 
imported by your Python code. As a general precaution from similar 
exploits, you should not execute Python code from this directory

any ideas how to fix this?

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Unsafe directory at startup

2014-10-06 Thread Vincent Delecroix
Hello,

What do you mean by fix? This is not a bug. I see at least two possibilities:

- how to manage the rights on your computer: this is done with the
chmod command. See for example http://en.wikipedia.org/wiki/Chmod

- force ipython to add the current directory to sys.path: you can do
that inside the console with

sage: import sys
sage: import os
sage: sys.path.append(os.getcwd())

If it is something else, please be precise in your question.

Vincent

2014-10-06 20:34 UTC+02:00, robert berne...@sbcglobal.net:
 Installed pre-compiled Sage-6.3.app on Mac OS X 10.9.5

 At startup of Terminal Session, there is this
 ~$ /Applications/Sage-6.3.app/Contents/Resources/sage/sage; exit
 sys:1: RuntimeWarning: not adding directory '' to sys.path since everybody
 can write to it.
 Untrusted users could put files in this directory which might then be
 imported by your Python code. As a general precaution from similar
 exploits, you should not execute Python code from this directory
 any ideas how to fix this?

 --
 You received this message because you are subscribed to the Google Groups
 sage-support group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sage-support+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-support@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-support.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Inconsistency between Sage and Python

2014-10-06 Thread João Alberto Ferreira
Thank you, Samuel. The conversion to RDF worked because it coerces the 
other types to RDF (I think). If I convert the multiplier values to RR, RLF 
or float, the conversion does not help anymore.

On Monday, October 6, 2014 1:30:03 PM UTC-3, slelievre wrote:


 João Alberto Ferreira wrote:

 I am plotting some graphs, but the plot becomes cluttered because of 
 the long labels. The labels are result of a conversion from a Real 
 number to a string. The problem here is that Sage is not consistent 
 with Python, as shown in the example below. 

 Python: 
  multiplier = [1.0e0, 1.0e1, 1.0e2] 
  multiplier 
 [1.0, 10.0, 100.0] 
  str(multiplier[-1]) 
 '100.0' 


 Sage: 
 sage: multiplier = [1.0e0, 1.0e1, 1.0e2] 
 sage: multiplier 
 [1.00, 10.0, 100.] 
 sage: str(multiplier[-1]) 
 '100.' 

 Is this a correct behavior of Sage? at least for me, the excess of 
 trailing zeros is causing some trouble. 


 One option is to work with RDF:

 sage: multiplier = [1.0e0, 1.0e1, 1.0e2]
 sage: multiplier = [RDF(x) for x in multiplier]
 sage: multiplier
 [1.0, 10.0, 100.0]
 sage: str(multiplier[-1])
 '100.0'
  


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Inconsistency between Sage and Python

2014-10-06 Thread João Alberto Ferreira
Yes, I know Vincent, thank you, but this would complicate my code 
unnecessarily.

I used Samuel idea. But I still think that the extra trailing zeros have no 
reason to exist.

On Monday, October 6, 2014 1:08:23 PM UTC-3, vdelecroix wrote:

 Hi João, 

 If you want precise control on the output, you might use the python 
 formatting (see 
 https://docs.python.org/2/library/string.html#formatstrings) 

 sage: x = RR(pi) 
 sage: print x 
 3.14159265358979 
 sage: print {:.3}.format(x) 
 3.1 
 sage: print {:.5}.format(x) 
 3.141 

 But perhaps it is not an answer to your question, is it? 

 Vincent 

 2014-10-06 18:03 UTC+02:00, João Alberto joa...@gmail.com javascript:: 

  I am plotting some graphs, but the plot becomes cluttered because of 
  the long labels. The labels are result of a conversion from a Real 
  number to a string. The problem here is that Sage is not consistent 
  with Python, as shown in the example below. 
  
  Python: 
  multiplier = [1.0e0, 1.0e1, 1.0e2] 
  multiplier 
  [1.0, 10.0, 100.0] 
  str(multiplier[-1]) 
  '100.0' 
  
  
  Sage: 
  sage: multiplier = [1.0e0, 1.0e1, 1.0e2] 
  sage: multiplier 
  [1.00, 10.0, 100.] 
  sage: str(multiplier[-1]) 
  '100.' 
  
  Is this a correct behavior of Sage? at least for me, the excess of 
  trailing zeros is causing some trouble. 
  
  -- 
  You received this message because you are subscribed to the Google 
 Groups 
  sage-support group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an 
  email to sage-support...@googlegroups.com javascript:. 
  To post to this group, send email to sage-s...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/sage-support. 
  For more options, visit https://groups.google.com/d/optout. 
  


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Typo in provided documentation

2014-10-06 Thread NahsiN
Yes Vincent, that sounds much better,
Cheers,
Nishan

On Saturday, 4 October 2014 05:21:15 UTC-4, vdelecroix wrote:

 Hello, 

 Is it better worded as follows? 

 The issue: plot(h(x), 0, 4) plots the line y=x−2, not the multi-line 
 function defined by h. The reason? In the command plot(h(x), 0, 4), 
 first h(x) is evaluated: this means plugging the symbolic variable x 
 into the function h. The inequality x  2 evaluates to ``False`` and 
 hence ``h(x)`` evaluates to ``x - 2`` as it can be seen with 
 {{{ 
 sage: bool(x  2) 
 False 
 sage: h(x) 
 x - 2 
 }}} 

 I also find misleading to have a Python argument (the x in def 
 h(x):)  and a symbolic variable (here x) having the same name. At 
 least it should be mentioned. 

 Vincent 

 2014-10-02 20:32 UTC+02:00, NahsiN nishan.s...@gmail.com javascript:: 
  @slelievre I was just pointing out what I think is a typo. 
  @slelievre You are right, the clause after the statement clarifies the 
  situation. When a symbolic equation is evaluated, as in the definition 
 of 
  h, 
  if it is not obviously true, then it returns False. Thus h(x) evaluates 
 to 
  x-2, and this is the function that gets plotted But I still feel the 
 whole 
  
  thing can be worded slightly better and more concisely. The if clause is 
  evaluated anyway when one calls h(x) so there is no point in saying x2 
 is 
  evaluated. 
  On Thursday, 2 October 2014 13:42:25 UTC-4, slelievre wrote: 
  
  
  
  Le mercredi 1 octobre 2014 22:06:50 UTC+2, NahsiN a écrit : 
  
  Hello, I don't know where to post this so redirect me as needed. I 
  believe I have found a typo in the sage tutorial. Under Sage Tutorial 
  v6.3 
   A Guided Tour  Some Common Issues with Functions we have the 
 lines 
  def h(x): 
if x2: 
   return 0 
else: 
return x-2 
  
  The issue: plot(h(x), 0, 4) plots the line y=x−2, not the multi-line 
  function defined by h. The reason? In the command plot(h(x),0, 4), 
 first 
  
  h(x) is evaluated: this means plugging x into the function h, *which 
  means that **x2** is evaluated*. 
  
  I think the else clause is evaluated and not the if x2 clause. 
  Thanks, 
  Nishan 
  
  
  You can work around this as follows: 
  
  plot(lambda x: h(x), 0, 4) 
  
  
  
  -- 
  You received this message because you are subscribed to the Google 
 Groups 
  sage-support group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an 
  email to sage-support...@googlegroups.com javascript:. 
  To post to this group, send email to sage-s...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/sage-support. 
  For more options, visit https://groups.google.com/d/optout. 
  


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Inconsistency between Sage and Python

2014-10-06 Thread João Alberto Ferreira
Ok, I had to make a huge effort to accept this, but it's more clear now.

One last question: Why RDF does not incorporate this feature? because it 
comes from the GSL library, that is an independent project? or because its 
precision is known a priori, like the float type in Python?


On Monday, October 6, 2014 3:39:32 PM UTC-3, Jeroen Demeyer wrote:

 On 2014-10-06 18:03, João Alberto wrote: 
  Is this a correct behavior of Sage? 
 It's a feature, not a bug. The reason is that the number of digits gives 
 an idea about the precision of the number. Compare 

 sage: RealField(20)(1) 
 1. 
 sage: RealField(100)(1) 
 1. 

 If both these would be printed as 1.0, you would lose this information 
 about the precision. 

 Python has a fixed precision of 53 bits and prints a minimal number of 
 digits. 


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Typo in provided documentation

2014-10-06 Thread Vincent Delecroix
Dear Nishan,

I created a ticket for that, you can have a look at:
http://trac.sagemath.org/ticket/17107

Hopefully, this will be corrected in the next release of Sage.

Thanks for the report!
Vincent

2014-10-06 20:53 UTC+02:00, NahsiN nishan.singh.m...@gmail.com:
 Yes Vincent, that sounds much better,
 Cheers,
 Nishan

 On Saturday, 4 October 2014 05:21:15 UTC-4, vdelecroix wrote:

 Hello,

 Is it better worded as follows?

 The issue: plot(h(x), 0, 4) plots the line y=x−2, not the multi-line
 function defined by h. The reason? In the command plot(h(x), 0, 4),
 first h(x) is evaluated: this means plugging the symbolic variable x
 into the function h. The inequality x  2 evaluates to ``False`` and
 hence ``h(x)`` evaluates to ``x - 2`` as it can be seen with
 {{{
 sage: bool(x  2)
 False
 sage: h(x)
 x - 2
 }}}

 I also find misleading to have a Python argument (the x in def
 h(x):)  and a symbolic variable (here x) having the same name. At
 least it should be mentioned.

 Vincent

 2014-10-02 20:32 UTC+02:00, NahsiN nishan.s...@gmail.com javascript::

  @slelievre I was just pointing out what I think is a typo.
  @slelievre You are right, the clause after the statement clarifies the
  situation. When a symbolic equation is evaluated, as in the definition
 
 of
  h,
  if it is not obviously true, then it returns False. Thus h(x) evaluates
 
 to
  x-2, and this is the function that gets plotted But I still feel the
 whole
 
  thing can be worded slightly better and more concisely. The if clause is
 
  evaluated anyway when one calls h(x) so there is no point in saying x2
 
 is
  evaluated.
  On Thursday, 2 October 2014 13:42:25 UTC-4, slelievre wrote:
 
 
 
  Le mercredi 1 octobre 2014 22:06:50 UTC+2, NahsiN a écrit :
 
  Hello, I don't know where to post this so redirect me as needed. I
  believe I have found a typo in the sage tutorial. Under Sage Tutorial
 
  v6.3
   A Guided Tour  Some Common Issues with Functions we have the
 lines
  def h(x):
if x2:
   return 0
else:
return x-2
 
  The issue: plot(h(x), 0, 4) plots the line y=x−2, not the multi-line
  function defined by h. The reason? In the command plot(h(x),0, 4),
 first
 
  h(x) is evaluated: this means plugging x into the function h, *which
  means that **x2** is evaluated*.
 
  I think the else clause is evaluated and not the if x2 clause.
  Thanks,
  Nishan
 
 
  You can work around this as follows:
 
  plot(lambda x: h(x), 0, 4)
 
 
 
  --
  You received this message because you are subscribed to the Google
 Groups
  sage-support group.
  To unsubscribe from this group and stop receiving emails from it, send
 an
  email to sage-support...@googlegroups.com javascript:.
  To post to this group, send email to sage-s...@googlegroups.com
 javascript:.
  Visit this group at http://groups.google.com/group/sage-support.
  For more options, visit https://groups.google.com/d/optout.
 


 --
 You received this message because you are subscribed to the Google Groups
 sage-support group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sage-support+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-support@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-support.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.