On Thu, Mar 19, 2009 at 1:01 AM, Minh Nguyen <nguyenmi...@gmail.com> wrote:
>
> Hi Jose,
>
> On Thu, Mar 19, 2009 at 7:49 AM, Jose Guzman <n...@neurohost.org> wrote:
>>
>> This is apparently a very easy question, but I am new to the mathematics
>> computing environment and it will take me some time to become familiar
>> with Sage. The question is the following; Are these two expressions
>> similar?
>>
>> sage: a,b,c = var('a,b,c')
>>
>> sage: var('a,b,c')
>>
>> If not, when should I use one or another?

Just another point.  Using the above two is equivalent on the command
line or in .sage scripts.  The function "var" uses a Cython "hack" to
inject a,b,c into the globals() namespace.   In some cases of Sage
library code (.py files) it is *not* equivalent in that doing
var('a,b,c') will make the symbolic variables somewhere, but a,b,c
might not be defined in the current scope.

William

>
> Both of the expressions above are more or less the same in that they
> produce the same result, i.e. declaring three symbolic variables. But
> note these points. If you do
>
> [1]
> sage: a,b,c = var("a,b,c")
>
> then it results in what you expect: namely, declaring the three
> specified symbolic variables. Now if you do
>
> [2]
> sage: var("a,b,c")
> (a, b, c)
>
> Sage does the same thing, but this time the three symbolic variables
> are printed to your terminal. The last command actually returns a
> tuple of three symbolic variables, so it makes sense to do as per [1].
> In Python, command [1] technically unpacks the tuple elements and
> store them in the variable names to the left of the equal sign. But if
> you do as in [2], then the required symbolic variables would have been
> declared even if you don't explicitly store the tuple elements: note
> this
>
> sage: var("a,b,c")
> (a, b, c)
> sage: type(a); type(b); type(c)
> <class 'sage.calculus.calculus.SymbolicVariable'>
> <class 'sage.calculus.calculus.SymbolicVariable'>
> <class 'sage.calculus.calculus.SymbolicVariable'>
>
> Also, if you like command [2] because it's less to type on the
> keyboard, then by all means do it. And if you don't want to see the
> returned tuple of symbolic variables, you can do this:
>
> sage: var("a,b,c");
>
> --
> Regards
> Minh Van Nguyen
>
> >
>



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

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

Reply via email to