Re: [sage-support] Print statement vs function in Sage-py3

2019-04-03 Thread dsejas . mathematics


On Wednesday, April 3, 2019 at 1:56:03 PM UTC-4, John H Palmieri wrote:
>
>
>
> On Wednesday, April 3, 2019 at 10:11:19 AM UTC-7, kcrisman wrote:
>>
>>
>>
>> On Tuesday, April 2, 2019 at 6:03:23 PM UTC-4, Dima Pasechnik wrote:
>>>
>>> On Tue, Apr 2, 2019 at 10:47 PM  wrote: 
>>> > 
>>> > Hello, Sage community. 
>>> > With the upcoming migration of Sage from Python2 to Python3, I was 
>>> wondering if the "print" statement will be changed to the new "print" 
>>> function. In any case, will there be backwards compatibility with the 
>>> current behavior? 
>>>
>>> As you can see in the current sage sources, there are no print 
>>> statements left, 
>>> only print functions. 
>>>
>>> the trick with Python 2 is to do 
>>>
>>> from __future__ import print_function 
>>>
>>> to get this compatibility 
>>>
>>
>> I think the post was asking for the reverse compatibility, though. 
>>  Presumably this would be possible (but perhaps not advisable) with adding 
>> something to the preparser.  I would be okay with a preparser addition that 
>> would look for this and say something like "print blah should now be 
>> print(blah)" but raise an error.
>>
>
> Some of this has been discussed at https://trac.sagemath.org/ticket/23674 
> .
>  
> That ticket should be revived, especially if there is any consensus about 
> how to handle this. I like the idea of deprecating statements like "print 
> x" ASAP.
>
> -- 
> John
>
> +1 for John's suggestion.
I agree that the print statement should be deprecated, not just because the 
print function seems to be a more modern approach, but also because it is 
important for users to have a standard way of printing results in this two 
"sister languages", Python and Sage. Being Sage built on Python, it would 
be a philosophy clash that one uses a print function and the other a print 
statement.
However, I also believe in backwards compatibility, so I would think that 
there should be a way to indicate SageMath to execute a program using 
Python2 conventions. Maybe something like "sage -std=py2 
", or even a directive like "#! python2" at the beginning 
of the script. I would also think of a "from standards import python2", or 
a command "guess_estandard()" so that the preparser can automatically take 
care of recognizing Pyhton 2 syntax. There are many ways to deal with this 
matter.
Anyway, how can we revive ticket https://trac.sagemath.org/ticket/23674?

-- 
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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Piecewise Function Fails to Evaluate in its Domain

2019-04-03 Thread David Joyner
On Wed, Apr 3, 2019 at 2:47 PM  wrote:

> The simplest example:
>
> f = piecewise([[[-pi-1, -pi/2], 0], [(-pi/2,pi/2), 1], [[pi/2, pi+1], 0]])
> print(f(-pi))
>
>
I'm not sure why it isn't evaluating symbolic numbers like pi, but here's a
work-around:

sage: f = piecewise([((-pi-*1*, -pi/*2*), *0*), ((-pi/*2*,pi/*2*), *1*),
((pi/*2*, pi+*1*), *0*)])

sage: ff = *lambda* x: f(RR(x))

sage: ff(-pi)

0

sage: f(-*3.1415*)
0

which gives the traceback:
>
> TypeError Traceback (most recent call last)
>  in ()
> > 1 f(-pi)
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
>  in sage.symbolic.expression._eval_on_operands.new_f 
> (build/cythonized/sage/symbolic/expression.cpp:66491)()
>   12677 new_args = list(ex._unpack_operands())
>   12678 new_args.extend(args)
> > 12679 return f(ex, *new_args, **kwds)
>   12680 return new_f
>   12681
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
>  in __call__(self, parameters, variable, value, **kwds)
> 472 if value is not None:
> 473 substitution[variable] = value
> --> 474 return self.subs(substitution)
> 475
> 476 def _fast_float_(self, *args):
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
>  in sage.symbolic.expression.Expression.substitute 
> (build/cythonized/sage/symbolic/expression.cpp:30025)()
>5289 
> smap.insert(make_pair((self.coerce_in(k))._gobj,
>5290   
> (self.coerce_in(v))._gobj))
> -> 5291 res = self._gobj.subs_map(smap, 0)
>5292 return new_Expression_from_GEx(self._parent, res)
>5293
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
>  in _subs_(self, subs_map, options, parameters, x)
> 226 if hasattr(point, 'pyobject'):
> 227 # unwrap any numeric values
> --> 228 point = point.pyobject()
> 229 else:
> 230 raise ValueError('substituting the piecewise variable 
> must result in real number')
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
>  in sage.symbolic.expression.Expression.pyobject 
> (build/cythonized/sage/symbolic/expression.cpp:6083)()
> 372
> 373 cdef class Expression(CommutativeRingElement):
> --> 374 cpdef object pyobject(self):
> 375 """
> 376 Get the underlying Python object.
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
>  in sage.symbolic.expression.Expression.pyobject 
> (build/cythonized/sage/symbolic/expression.cpp:6009)()
> 428
> 429 if not is_a_numeric(self._gobj):
> --> 430 raise TypeError("self must be a numeric expression")
> 431 return py_object_from_numeric(self._gobj)
> 432
>
> TypeError: self must be a numeric expression
> sage: f(-pi)
> ---
> TypeError Traceback (most recent call last)
>  in ()
> > 1 f(-pi)
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
>  in sage.symbolic.expression._eval_on_operands.new_f 
> (build/cythonized/sage/symbolic/expression.cpp:66491)()
>   12677 new_args = list(ex._unpack_operands())
>   12678 new_args.extend(args)
> > 12679 return f(ex, *new_args, **kwds)
>   12680 return new_f
>   12681
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
>  in __call__(self, parameters, variable, value, **kwds)
> 472 if value is not None:
> 473 substitution[variable] = value
> --> 474 return self.subs(substitution)
> 475
> 476 def _fast_float_(self, *args):
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
>  in sage.symbolic.expression.Expression.substitute 
> (build/cythonized/sage/symbolic/expression.cpp:30025)()
>5289 
> smap.insert(make_pair((self.coerce_in(k))._gobj,
>5290   
> (self.coerce_in(v))._gobj))
> -> 5291 res = self._gobj.subs_map(smap, 0)
>5292 return new_Expression_from_GEx(self._parent, res)
>5293
>
> /Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
>  in _subs_(self, subs_map, options, parameters, x)
> 226 if hasattr(point, 

[sage-support] Piecewise Function Fails to Evaluate in its Domain

2019-04-03 Thread brandonhgomes
The simplest example:

f = piecewise([[[-pi-1, -pi/2], 0], [(-pi/2,pi/2), 1], [[pi/2, pi+1], 0]])
print(f(-pi))

which gives the traceback:

TypeError Traceback (most recent call last)
 in ()
> 1 f(-pi)

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
 in sage.symbolic.expression._eval_on_operands.new_f 
(build/cythonized/sage/symbolic/expression.cpp:66491)()
  12677 new_args = list(ex._unpack_operands())
  12678 new_args.extend(args)
> 12679 return f(ex, *new_args, **kwds)
  12680 return new_f
  12681

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
 in __call__(self, parameters, variable, value, **kwds)
472 if value is not None:
473 substitution[variable] = value
--> 474 return self.subs(substitution)
475
476 def _fast_float_(self, *args):

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
 in sage.symbolic.expression.Expression.substitute 
(build/cythonized/sage/symbolic/expression.cpp:30025)()
   5289 smap.insert(make_pair((self.coerce_in(k))._gobj,
   5290   
(self.coerce_in(v))._gobj))
-> 5291 res = self._gobj.subs_map(smap, 0)
   5292 return new_Expression_from_GEx(self._parent, res)
   5293

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
 in _subs_(self, subs_map, options, parameters, x)
226 if hasattr(point, 'pyobject'):
227 # unwrap any numeric values
--> 228 point = point.pyobject()
229 else:
230 raise ValueError('substituting the piecewise variable must 
result in real number')

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
 in sage.symbolic.expression.Expression.pyobject 
(build/cythonized/sage/symbolic/expression.cpp:6083)()
372
373 cdef class Expression(CommutativeRingElement):
--> 374 cpdef object pyobject(self):
375 """
376 Get the underlying Python object.

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
 in sage.symbolic.expression.Expression.pyobject 
(build/cythonized/sage/symbolic/expression.cpp:6009)()
428
429 if not is_a_numeric(self._gobj):
--> 430 raise TypeError("self must be a numeric expression")
431 return py_object_from_numeric(self._gobj)
432

TypeError: self must be a numeric expression
sage: f(-pi)
---
TypeError Traceback (most recent call last)
 in ()
> 1 f(-pi)

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
 in sage.symbolic.expression._eval_on_operands.new_f 
(build/cythonized/sage/symbolic/expression.cpp:66491)()
  12677 new_args = list(ex._unpack_operands())
  12678 new_args.extend(args)
> 12679 return f(ex, *new_args, **kwds)
  12680 return new_f
  12681

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
 in __call__(self, parameters, variable, value, **kwds)
472 if value is not None:
473 substitution[variable] = value
--> 474 return self.subs(substitution)
475
476 def _fast_float_(self, *args):

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
 in sage.symbolic.expression.Expression.substitute 
(build/cythonized/sage/symbolic/expression.cpp:30025)()
   5289 smap.insert(make_pair((self.coerce_in(k))._gobj,
   5290   
(self.coerce_in(v))._gobj))
-> 5291 res = self._gobj.subs_map(smap, 0)
   5292 return new_Expression_from_GEx(self._parent, res)
   5293

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py
 in _subs_(self, subs_map, options, parameters, x)
226 if hasattr(point, 'pyobject'):
227 # unwrap any numeric values
--> 228 point = point.pyobject()
229 else:
230 raise ValueError('substituting the piecewise variable must 
result in real number')

/Applications/SageMath-8.7.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx
 in sage.symbolic.expression.Expression.pyobject 
(build/cythonized/sage/symbolic/expression.cpp:6083)()
372
373 cdef class 

Re: [sage-support] Print statement vs function in Sage-py3

2019-04-03 Thread John Cremona
On Wed, 3 Apr 2019 at 18:56, John H Palmieri  wrote:

>
>
> On Wednesday, April 3, 2019 at 10:11:19 AM UTC-7, kcrisman wrote:
>>
>>
>>
>> On Tuesday, April 2, 2019 at 6:03:23 PM UTC-4, Dima Pasechnik wrote:
>>>
>>> On Tue, Apr 2, 2019 at 10:47 PM  wrote:
>>> >
>>> > Hello, Sage community.
>>> > With the upcoming migration of Sage from Python2 to Python3, I was
>>> wondering if the "print" statement will be changed to the new "print"
>>> function. In any case, will there be backwards compatibility with the
>>> current behavior?
>>>
>>> As you can see in the current sage sources, there are no print
>>> statements left,
>>> only print functions.
>>>
>>> the trick with Python 2 is to do
>>>
>>> from __future__ import print_function
>>>
>>> to get this compatibility
>>>
>>
>> I think the post was asking for the reverse compatibility, though.
>> Presumably this would be possible (but perhaps not advisable) with adding
>> something to the preparser.  I would be okay with a preparser addition that
>> would look for this and say something like "print blah should now be
>> print(blah)" but raise an error.
>>
>
> Some of this has been discussed at https://trac.sagemath.org/ticket/23674.
> That ticket should be revived, especially if there is any consensus about
> how to handle this. I like the idea of deprecating statements like "print
> x" ASAP.
>

+1

For what it's worth, running pyflakes on src/sage now outputs 4192 lines of
which 2438 are just "imported but unused" while pyflakes3 only only outputs
4106 lines (and the same number of "imported but unused".  That seems
somehow encouraging.


>
> --
> John
>
> --
> 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 https://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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Print statement vs function in Sage-py3

2019-04-03 Thread John H Palmieri


On Wednesday, April 3, 2019 at 10:11:19 AM UTC-7, kcrisman wrote:
>
>
>
> On Tuesday, April 2, 2019 at 6:03:23 PM UTC-4, Dima Pasechnik wrote:
>>
>> On Tue, Apr 2, 2019 at 10:47 PM > 
>> wrote: 
>> > 
>> > Hello, Sage community. 
>> > With the upcoming migration of Sage from Python2 to Python3, I was 
>> wondering if the "print" statement will be changed to the new "print" 
>> function. In any case, will there be backwards compatibility with the 
>> current behavior? 
>>
>> As you can see in the current sage sources, there are no print statements 
>> left, 
>> only print functions. 
>>
>> the trick with Python 2 is to do 
>>
>> from __future__ import print_function 
>>
>> to get this compatibility 
>>
>
> I think the post was asking for the reverse compatibility, though. 
>  Presumably this would be possible (but perhaps not advisable) with adding 
> something to the preparser.  I would be okay with a preparser addition that 
> would look for this and say something like "print blah should now be 
> print(blah)" but raise an error.
>

Some of this has been discussed at https://trac.sagemath.org/ticket/23674. 
That ticket should be revived, especially if there is any consensus about 
how to handle this. I like the idea of deprecating statements like "print 
x" ASAP.

-- 
John

-- 
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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Print statement vs function in Sage-py3

2019-04-03 Thread kcrisman


On Tuesday, April 2, 2019 at 6:03:23 PM UTC-4, Dima Pasechnik wrote:
>
> On Tue, Apr 2, 2019 at 10:47 PM  wrote: 
> > 
> > Hello, Sage community. 
> > With the upcoming migration of Sage from Python2 to Python3, I was 
> wondering if the "print" statement will be changed to the new "print" 
> function. In any case, will there be backwards compatibility with the 
> current behavior? 
>
> As you can see in the current sage sources, there are no print statements 
> left, 
> only print functions. 
>
> the trick with Python 2 is to do 
>
> from __future__ import print_function 
>
> to get this compatibility 
>

I think the post was asking for the reverse compatibility, though. 
 Presumably this would be possible (but perhaps not advisable) with adding 
something to the preparser.  I would be okay with a preparser addition that 
would look for this and say something like "print blah should now be 
print(blah)" but raise an error.

- kcrisman 

-- 
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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Pushing to trac from GitHub

2019-04-03 Thread Eric Gourgoulhon
Hi,

Le mardi 2 avril 2019 21:40:14 UTC+2, Bea Galiana a écrit :
>
> Hi,
>
> so I was wondering, is it possible to push to trac without having a trac 
> account, only logged with a GitHub account?
>
>
I think yes, see
http://doc.sagemath.org/html/en/developer/trac.html
The branch name (created automatically during the first push) must be of 
the form
u/gh-/
or
public/
where  is your GitHub name and  is any name you may choose to 
specify the branch. 

Best wishes,

Eric.

-- 
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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.