Re: [sage-support] Expressions have an "abs()" (complex modulus) method, but not "arg()" (complex argument). Why ?

2015-12-21 Thread Emmanuel Charpentier
Okay. It seems that it *IS* an oversight.

Adding it *cleanly* may help (force ?) me to understand the innards of 
Sage. Nice "toy" project ... if and when I'll have time. In other words : 
I'll do it (mostly for fun), but don't hold your breath..

Thanks for the answers !

--
Emmanuel Charpentier

Le lundi 21 décembre 2015 13:28:13 UTC+1, Nathann Cohen a écrit :
>
> Why? My guess is that the method does not exist because nobody bothered 
>> to add it. 
>
> +1.
>
> Nathann 
>

-- 
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] Expressions have an "abs()" (complex modulus) method, but not "arg()" (complex argument). Why ?

2015-12-21 Thread slabbe


On Monday, December 21, 2015 at 9:10:35 PM UTC+1, Emmanuel Charpentier 
wrote:
>
> Okay. It seems that it *IS* an oversight.
>
> Adding it *cleanly* may help (force ?) me to understand the innards of 
> Sage. Nice "toy" project ... if and when I'll have time. In other words : 
> I'll do it (mostly for fun), but don't hold your breath..
>
> Thanks for the answers !
>

In Sage, (almost) nobody is paid for coding. In particular, nobody works 
for you. But Sage developers tend to work for others a lot especially when 
it is about fixing this kind fo issues. Therefore, I am sure that if you 
open a ticket for it and if you post a branch, then you will find someone 
to review it and it will be in Sage within days.
 
Sébastien


> --
> Emmanuel Charpentier
>
> Le lundi 21 décembre 2015 13:28:13 UTC+1, Nathann Cohen a écrit :
>>
>> Why? My guess is that the method does not exist because nobody bothered 
>>> to add it. 
>>
>> +1.
>>
>> Nathann 
>>
>

-- 
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] Re: Global variables called in a function

2015-12-21 Thread Vincent Delecroix

No. You can try

def f():
var('whatever')
f()
print whatever

Nothing to do with the fact that 't' was globally available before.

By design the function var:
  - creates a new symbolic variable (*not* a Python variable)
  - makes it available in the global namespace as a Python variable 
under the same name


Some more examples:

t = 5
 -> creates a Python variable named t which contains 5

t = SR.var('x')
 -> creates a Python variable named t which contains a symbolic 
variable named x


var('t')
 -> creates a Python variable named t which contains a symbolic 
variable named t.


Indeed the latter should really be thought as

t = SR.var('t')

Vincent

On 21/12/15 14:35, Carl Eberhart wrote:

Ah.  Thanks very much for that clarification.
Actually, my snippet illustrates the dilemma I was in.
t already has a value outside of f
executing f changes the value of t outside of f
that is what I would expect to happen if t were declared global in f, but I
thought t was local in f
I still love var, but now I know when to use SR.var instead
Carl

On Mon, Dec 21, 2015 at 9:49 AM, Jeroen Demeyer 
wrote:


On 2015-12-21 16:38, Carl Eberhart wrote:


I admit I don't understand what is happening in the following snippit:

def f():
  t=var('t')
  t=5
  a=2*t
  return a



Solution: never use var() in a function. If you do need a symbolic
variable in a function (note that you don't in the snippet above), you can
use SR.var() instead of plain var(). That behaves like var(), except that
it does not change any global. Example:

sage: SR.var('y')
y
sage: y
NameError: name 'y' is not defined

You can use it with explicit assignment:

sage: y = SR.var('y')
sage: y
y


--
You received this message because you are subscribed to a topic in the
Google Groups "sage-support" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/sage-support/G0vP7kulENg/unsubscribe.
To unsubscribe from this group and all its topics, 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] Re: Global variables called in a function

2015-12-21 Thread Carl Eberhart
Thanks
I guess I don't understand the difference between a python variable and a 
symbolic variable.
I know that var is part of Sage but not defined in python.  
I also know that the variables created inside a sage procedure using SR.var 
are local, but ones created by var are not.
So inside of procedures, use SR.var, not var, unless you want them to be 
available outside the procedure.
Is that correct Jeroen?




On Monday, December 21, 2015 at 5:09:05 PM UTC-6, vdelecroix wrote:
>
> No. You can try 
> Still
> def f(): 
>  var('whatever') 
> f() 
> print whatever StillThanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
>
> Nothing to do with the fact that 't' was globally available before. 
>
> By design the function var: 
>- creates a new symbolic variable (*not* a Python variable) 
>- makes it available in the global namespace as a Python variThanks.
> SR.var  does the trick for me inside of procedures.  var doesn'table 
> under the same namStille 
>
> Some more examples: 
>
> t = 5 Still
>   -> creates a Python variable named t which contains 5 
> Still
> t = SR.var('x') 
>   -> creates a Python variable named t which contains a symbolic 
> variable named x Still
>
> var('t') 
>   -> creates a Python variable named t which contains a symbolic 
> variable named t. 
>
> Indeed the latter should really be thought as 
>
> t = SR.var('t') StillThanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
>
> Vincent 
>
> On 21/12/15 14:35, Carl Eberhart wrote: Thanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
> > Ah.  Thanks very much for that clarification. 
> > Actually, my snippet illustrates the dilemma I was in. 
> > t already has a value outside of f 
> > executing f changes the value of t outside of f 
> > that is what I would expect to happen if t were declared global in f, 
> but I 
> > thought t was local in f 
> > I still love var, but now I know when to use SR.var instead 
> > Carl Thanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
> > 
> > On Mon, Dec 21, 2015 at 9:49 AM, Jeroen Demeyer  > 
> > wrote: 
> > 
> >> On 2015-12-21 16:38, Carl Eberhart wrote: 
> >> 
> >>> I admit I don't understand what is happening in the following snippit: 
> >>> 
> >>> def f(): 
> >>>   t=var('t') 
> >>>   t=5 
> >>>   a=2*t 
> >>>   return a 
> >>> 
> >> 
> >> Solution: never use var() in a function. If you do need a symbolic 
> >> variable in a function (note that you don't in the snippet above), you 
> can 
> >> use SR.var() instead of plain var(). That behaves like var(), except 
> that 
> >> it does not change any global. Example: 
> >> 
> >> sage: SR.var('y') 
> >> y 
> >> sage: y 
> >> NameError: name 'y' is not defined 
> >> 
> >> You can use it with explicit assignment: 
> >> 
> >> sage: y = SR.var('y') 
> >> sage: y 
> >> y 
> >> 
> >> 
> >> -- 
> >> You received this message because you are subscribed to a topic in the 
> >> Google Groups "sage-support" group. 
> >> To unsubscribe from this topic, visit 
> >> https://groups.google.com/d/topic/sage-support/G0vP7kulENg/unsubscribe. 
>
> >> To unsubscribe from this group and all its topics, send an email to 
> >> sage-support...@googlegroups.com . 
> >> To post to this group, send email to sage-s...@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] Re: Global variables called in a function

2015-12-21 Thread Carl Eberhart
Thanks
I guess I don't understand the difference between a python variable and a 
symbolic variable.
I know that var is part of Sage but not defined in python.  
I also know that the variables created inside a sage procedure using SR.var 
are local, but ones created by var are not.
So inside of procedures, use SR.var, not var, unless you want them to be 
available outside the procedure.
Is that correct Jeroen?




On Monday, December 21, 2015 at 5:09:05 PM UTC-6, vdelecroix wrote:
>
> No. You can try 
> Still
> def f(): 
>  var('whatever') 
> f() 
> print whatever StillThanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
>
> Nothing to do with the fact that 't' was globally available before. 
>
> By design the function var: 
>- creates a new symbolic variable (*not* a Python variable) 
>- makes it available in the global namespace as a Python variThanks.
> SR.var  does the trick for me inside of procedures.  var doesn'table 
> under the same namStille 
>
> Some more examples: 
>
> t = 5 Still
>   -> creates a Python variable named t which contains 5 
> Still
> t = SR.var('x') 
>   -> creates a Python variable named t which contains a symbolic 
> variable named x Still
>
> var('t') 
>   -> creates a Python variable named t which contains a symbolic 
> variable named t. 
>
> Indeed the latter should really be thought as 
>
> t = SR.var('t') StillThanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
>
> Vincent 
>
> On 21/12/15 14:35, Carl Eberhart wrote: Thanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
> > Ah.  Thanks very much for that clarification. 
> > Actually, my snippet illustrates the dilemma I was in. 
> > t already has a value outside of f 
> > executing f changes the value of t outside of f 
> > that is what I would expect to happen if t were declared global in f, 
> but I 
> > thought t was local in f 
> > I still love var, but now I know when to use SR.var instead 
> > Carl Thanks.
> SR.var  does the trick for me inside of procedures.  var doesn't
> > 
> > On Mon, Dec 21, 2015 at 9:49 AM, Jeroen Demeyer  > 
> > wrote: 
> > 
> >> On 2015-12-21 16:38, Carl Eberhart wrote: 
> >> 
> >>> I admit I don't understand what is happening in the following snippit: 
> >>> 
> >>> def f(): 
> >>>   t=var('t') 
> >>>   t=5 
> >>>   a=2*t 
> >>>   return a 
> >>> 
> >> 
> >> Solution: never use var() in a function. If you do need a symbolic 
> >> variable in a function (note that you don't in the snippet above), you 
> can 
> >> use SR.var() instead of plain var(). That behaves like var(), except 
> that 
> >> it does not change any global. Example: 
> >> 
> >> sage: SR.var('y') 
> >> y 
> >> sage: y 
> >> NameError: name 'y' is not defined 
> >> 
> >> You can use it with explicit assignment: 
> >> 
> >> sage: y = SR.var('y') 
> >> sage: y 
> >> y 
> >> 
> >> 
> >> -- 
> >> You received this message because you are subscribed to a topic in the 
> >> Google Groups "sage-support" group. 
> >> To unsubscribe from this topic, visit 
> >> https://groups.google.com/d/topic/sage-support/G0vP7kulENg/unsubscribe. 
>
> >> To unsubscribe from this group and all its topics, send an email to 
> >> sage-support...@googlegroups.com . 
> >> To post to this group, send email to sage-s...@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.


[sage-support] Re: Inverting integers in Sage gives different behaviour than in Python

2015-12-21 Thread Emmanuel Charpentier
Le lundi 21 décembre 2015 17:32:03 UTC+1, Mark Bell a écrit :
>
> The __invert__ methods, which controls the behaviour of the ~ operator, of 
> Integers and ints are different.
>
> In Python, for an int x, its invert ~x is defined to be its two's 
> complement and is given by -1-x 
> .
>
> On the other hand, in Sage for an Integer x 
> (from sage.rings.integer.Integer), its __invert__ is defined to be 1 / x 
> 
> .
>
> Unfortunately this difference means that ~x different results in Sage and 
> Python and so is causing some of my scripts and packages that run under 
> Python to break under Sage. Most notably, that under Sage ~0 raises a 
> "ZeroDivisionError: Rational division by zero" error rather than returning 
> -1.
>
> Looking through the git history it appears that this has been the 
> convention since at least October 2006 
> .
>  
> Is there a reason why __invert__ was chosen to act this way rather than 
> match the Python convention?
>

maybe because :
sage: var("x")
x
sage: ~x
1/x
sage: var("a,b,c,d")
(a, b, c, d)
sage: M=matrix([[a,b],[c,d]])
sage: ~M
[1/a - b*c/(a^2*(b*c/a - d))   b/(a*(b*c/a - d))]
[  c/(a*(b*c/a - d))  -1/(b*c/a - d)]
were deemed useful ? 

HTH,
--
Emmanuel Charpentier

-- 
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] Re: Global variables called in a function

2015-12-21 Thread Vincent Delecroix
To avoid confusion use "symbol" instead of "symbolic variable". A Python 
variable is a variable in the sense of programming


https://en.wikipedia.org/wiki/Variable_%28computer_science%29

A symbol represents a mathematical variable as in

https://en.wikipedia.org/wiki/Variable_%28mathematics%29

The following is some Python code that makes available a (Python) 
variable outside of a function


def f():
global a
a = 3
f()
print a

But there is *no* such thing as local variable definition in Python. The 
command "a = 5" or "t = cos(10.)" is in itself a variable declaration... 
which is a bit confusing if you start mixing with symbols and the 
terrible var function in Sage. You might have a look at other examples in


http://www.python-course.eu/python3_global_vs_local_variables.php

On 21/12/15 21:12, Carl Eberhart wrote:

Thanks
I guess I don't understand the difference between a python variable and a
symbolic variable.
I know that var is part of Sage but not defined in python.
I also know that the variables created inside a sage procedure using SR.var
are local, but ones created by var are not.
So inside of procedures, use SR.var, not var, unless you want them to be
available outside the procedure.
Is that correct Jeroen?




On Monday, December 21, 2015 at 5:09:05 PM UTC-6, vdelecroix wrote:


No. You can try
Still
def f():
  var('whatever')
f()
print whatever StillThanks.
SR.var  does the trick for me inside of procedures.  var doesn't

Nothing to do with the fact that 't' was globally available before.

By design the function var:
- creates a new symbolic variable (*not* a Python variable)
- makes it available in the global namespace as a Python variThanks.
SR.var  does the trick for me inside of procedures.  var doesn'table
under the same namStille

Some more examples:

t = 5 Still
   -> creates a Python variable named t which contains 5
Still
t = SR.var('x')
   -> creates a Python variable named t which contains a symbolic
variable named x Still

var('t')
   -> creates a Python variable named t which contains a symbolic
variable named t.

Indeed the latter should really be thought as

t = SR.var('t') StillThanks.
SR.var  does the trick for me inside of procedures.  var doesn't

Vincent

On 21/12/15 14:35, Carl Eberhart wrote: Thanks.
SR.var  does the trick for me inside of procedures.  var doesn't

Ah.  Thanks very much for that clarification.
Actually, my snippet illustrates the dilemma I was in.
t already has a value outside of f
executing f changes the value of t outside of f
that is what I would expect to happen if t were declared global in f,

but I

thought t was local in f
I still love var, but now I know when to use SR.var instead
Carl Thanks.

SR.var  does the trick for me inside of procedures.  var doesn't


On Mon, Dec 21, 2015 at 9:49 AM, Jeroen Demeyer 

wrote:


On 2015-12-21 16:38, Carl Eberhart wrote:


I admit I don't understand what is happening in the following snippit:

def f():
   t=var('t')
   t=5
   a=2*t
   return a



Solution: never use var() in a function. If you do need a symbolic
variable in a function (note that you don't in the snippet above), you

can

use SR.var() instead of plain var(). That behaves like var(), except

that

it does not change any global. Example:

sage: SR.var('y')
y
sage: y
NameError: name 'y' is not defined

You can use it with explicit assignment:

sage: y = SR.var('y')
sage: y
y


--
You received this message because you are subscribed to a topic in the
Google Groups "sage-support" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/sage-support/G0vP7kulENg/unsubscribe.



To unsubscribe from this group and all its topics, send an email to
sage-support...@googlegroups.com .
To post to this group, send email to sage-s...@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] Re: Global variables called in a function

2015-12-21 Thread Jeroen Demeyer

On 2015-12-22 01:11, Carl Eberhart wrote:

Thanks
I guess I don't understand the difference between a python variable and
a symbolic variable.


A symbolic variable is a symbol or letter in the mathematical sense. It 
is like the "x" appearing in mathematical formulas like

sin(x)^2 + cos(x)^2 == 1.

--
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: Using graphic object as a sub-figure

2015-12-21 Thread Nathann Cohen

>
> Is it possible to use a plot of some object as a subfigure in given 
> position? 
>
> Suppose for example that g is a graph. What if I want to plot g, an arrow, 
> and g with some edge deleted? There is graphic_array, but it is not quite 
> flexible. I would like to have something like 
>

If you are plotting graphs, you already have a way to do that.

sage: g = graphs.RandomGNP(10,.3)
sage: g.show(save_pos=True)
sage: g.delete_edges(g.edge_boundary([0,1,2,3]))
sage: g.show()

If you have another graph h defined on the same set of vertices, you can 
also do:

sage: h.set_pos(g.get_pos())

To use the same layout for both.

Nathann
 

-- 
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] Inverting integers in Sage gives different behaviour than in Python

2015-12-21 Thread Mark Bell
The __invert__ methods, which controls the behaviour of the ~ operator, of 
Integers and ints are different.

In Python, for an int x, its invert ~x is defined to be its two's 
complement and is given by -1-x 
.

On the other hand, in Sage for an Integer x 
(from sage.rings.integer.Integer), its __invert__ is defined to be 1 / x 

.

Unfortunately this difference means that ~x different results in Sage and 
Python and so is causing some of my scripts and packages that run under 
Python to break under Sage. Most notably, that under Sage ~0 raises a 
"ZeroDivisionError: Rational division by zero" error rather than returning 
-1.

Looking through the git history it appears that this has been the 
convention since at least October 2006 
.
 
Is there a reason why __invert__ was chosen to act this way rather than 
match the Python convention?

-- 
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] Re: Global variables called in a function

2015-12-21 Thread Jeroen Demeyer

On 2015-12-21 16:38, Carl Eberhart wrote:

I admit I don't understand what is happening in the following snippit:

def f():
 t=var('t')
 t=5
 a=2*t
 return a


Solution: never use var() in a function. If you do need a symbolic 
variable in a function (note that you don't in the snippet above), you 
can use SR.var() instead of plain var(). That behaves like var(), except 
that it does not change any global. Example:


sage: SR.var('y')
y
sage: y
NameError: name 'y' is not defined

You can use it with explicit assignment:

sage: y = SR.var('y')
sage: y
y

--
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] Re: Global variables called in a function

2015-12-21 Thread William Stein
On Monday, December 21, 2015, Carl Eberhart  wrote:

> I admit I don't understand what is happening in the following snippit:
>
> def f():
> t=var('t')
> t=5
> a=2*t
> return a
> t=3;t;f();t
> 3
> 10
> t
>
> This was executed in a sagews cell
> I think that the t which is referenced in f should be a local variable.
> However the value of t outside of f is modified by the execution of f.
> I know this happens because of the statement  t=var('t').
> Apparently, varing a variable inside a procedure vars it outside the
> procedure too.
> Is this behavior correct?
>


It is definitely as intended and documented and not a bug.See the docs of
var.   Whether or not that design decision (by me from 2007) was a good
idea is less clear.



> Thanks  Carl
> On Thursday, September 30, 2010 at 11:06:21 AM UTC-5, Robert Bradshaw
> wrote:
>>
>> On Thu, Sep 30, 2010 at 3:07 AM, Walker  wrote:
>> >> sage: x = "this is x"
>> >> sage: y = "this is y"
>> >> sage: z = "this is z"
>> >> sage: def f():
>> >> : print x
>> >> : y = "new value"
>> >> : print y
>> >> : global z
>> >> : z = "new value"
>> >> : print z
>> >> :
>> >>
>> >> sage: f()
>> >> this is x
>> >> new value
>> >> new value
>> >>
>> >> sage: x, y, z
>> >> ('this is x', 'this is y', 'new value')
>> >
>> > Yes it's true, that's the behavior I was referring to. My problem was
>> > actually that I couldn't print a global variable inside a function
>> > before I made an assignment to it; the error was something like
>> > "Cannot istantiate a local variable before assigning it." and I didn't
>> > understand why I had to assign locally a global variable which had
>> > already been assigned globally. Anyway the keyword "global" solved my
>> > problem.
>>
>> Yep, a variable is either local or global throughout the entire function.
>>
>> - Robert
>>
>>




> --
> 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.
>


-- 
Sent from my massive iPhone 6 plus.

-- 
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] Re: Global variables called in a function

2015-12-21 Thread Carl Eberhart
I admit I don't understand what is happening in the following snippit:

def f():
t=var('t')
t=5
a=2*t
return a
t=3;t;f();t
3
10
t

This was executed in a sagews cell
I think that the t which is referenced in f should be a local variable.
However the value of t outside of f is modified by the execution of f.
I know this happens because of the statement  t=var('t').
Apparently, varing a variable inside a procedure vars it outside the 
procedure too.
Is this behavior correct?
Thanks  Carl
On Thursday, September 30, 2010 at 11:06:21 AM UTC-5, Robert Bradshaw wrote:
>
> On Thu, Sep 30, 2010 at 3:07 AM, Walker  
> wrote:
> >> sage: x = "this is x"
> >> sage: y = "this is y"
> >> sage: z = "this is z"
> >> sage: def f():
> >> : print x
> >> : y = "new value"
> >> : print y
> >> : global z
> >> : z = "new value"
> >> : print z
> >> :
> >>
> >> sage: f()
> >> this is x
> >> new value
> >> new value
> >>
> >> sage: x, y, z
> >> ('this is x', 'this is y', 'new value')
> >
> > Yes it's true, that's the behavior I was referring to. My problem was
> > actually that I couldn't print a global variable inside a function
> > before I made an assignment to it; the error was something like
> > "Cannot istantiate a local variable before assigning it." and I didn't
> > understand why I had to assign locally a global variable which had
> > already been assigned globally. Anyway the keyword "global" solved my
> > problem.
>
> Yep, a variable is either local or global throughout the entire function.
>
> - Robert
>
>

-- 
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] Re: Global variables called in a function

2015-12-21 Thread Carl Eberhart
Ah.  Thanks very much for that clarification.
Actually, my snippet illustrates the dilemma I was in.
t already has a value outside of f
executing f changes the value of t outside of f
that is what I would expect to happen if t were declared global in f, but I
thought t was local in f
I still love var, but now I know when to use SR.var instead
Carl

On Mon, Dec 21, 2015 at 9:49 AM, Jeroen Demeyer 
wrote:

> On 2015-12-21 16:38, Carl Eberhart wrote:
>
>> I admit I don't understand what is happening in the following snippit:
>>
>> def f():
>>  t=var('t')
>>  t=5
>>  a=2*t
>>  return a
>>
>
> Solution: never use var() in a function. If you do need a symbolic
> variable in a function (note that you don't in the snippet above), you can
> use SR.var() instead of plain var(). That behaves like var(), except that
> it does not change any global. Example:
>
> sage: SR.var('y')
> y
> sage: y
> NameError: name 'y' is not defined
>
> You can use it with explicit assignment:
>
> sage: y = SR.var('y')
> sage: y
> y
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sage-support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sage-support/G0vP7kulENg/unsubscribe.
> To unsubscribe from this group and all its topics, 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.