Re: [sage-support] strange behavior in matrix substitution

2010-06-13 Thread Robert Bradshaw

On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:


Please tell me if this is a bug, or, I'm missing something obvious...

sage: a = 3 # Assign a value to a variable a
sage: b = a # Create a copy of a


You're not really copying a, you're just making 'b' refer to the same  
thing that 'a' does, i.e. '3'.



sage: b = 2 # Change the value of b


Now b points to a different integer (2).


sage: b
2
sage: a # The value of a remains unchanged, as expected.
3

So far, it looks good to me. But, when I do a similar thing with
matrices, it doesn't look to be the same.

sage: v = matrix(ZZ, 3, range(9))
sage: u = v


u and v point to the same thing.


sage: u[2] = [0,0,0]


The matrix stored in the variable u has not been reassigned, it' been  
mutated.



sage: u
[0 1 2]
[3 4 5]
[0 0 0]
sage: v
[0 1 2]
[3 4 5]
[0 0 0]

Shouldn't the value of v remain the same? Why does the change in u
(or, a row of u) affect v?




On Jun 12, 2010, at 8:25 PM, Justin C. Walker wrote:



On Jun 12, 2010, at 19:07 , William Stein wrote:


On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:

[snip]

Shouldn't the value of v remain the same? Why does the change in u
(or, a row of u) affect v?

[snip]
For, e.g., integers, u=v means that the names u,v both refer to  
their own copies of the value in question.




Are you sure???  I think you statement that u is a new copy is  
wrong.   I bet


u is v

would still return true above.


Picky picky picky.  I was hoping to avoid a trip into the twisty  
maze of passages in language definition (all of which are subtly  
different :-}).  But you are correct.  u is v does return true and  
the two actually refer to the same (physical) value.  And, if one  
variable is modified, this doesn't modify the other, or the value  
that both previously referred to.


Actually, even in the case of integers, if you were to modify one, it  
would modify the other. Most object are (basically) immutable, so this  
doesn't come up. Assignment never copies, it only creates references.


- Robert

--
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
URL: http://www.sagemath.org


Re: Sage on iPhone - Re: [sage-support] strange behavior in matrix substitution

2010-06-13 Thread calcpage
I check my student's worksheets (those they share) on my iPod Touch no 
problem from sagenb.


The only problem is viewing a plot() in 3D as the jre is not supported 
on the iPod Touch's Safari.


HTH,
A. Jorge Garcia
http://calcpage.tripod.com

Teacher  Professor
Applied Mathematics, Physics  Computer Science
Baldwin Senior High School  Nassau Community College


-Original Message-
From: William Stein wst...@gmail.com
To: sage-support@googlegroups.com sage-support@googlegroups.com
Sent: Sat, Jun 12, 2010 11:55 pm
Subject: Sage on iPhone - Re: [sage-support] strange behavior in matrix 
substitution


On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


On Jun 12, 2010, at 20:30 , William Stein wrote:


On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


On Jun 12, 2010, at 19:07 , William Stein wrote:


On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:

[snip]


[snip]


I find that hard to believe.  I thought you had Sage running on all 

things digital...




Your right that I could check it on my iPhone, but I was lazy.    I'm
working on building sage *on* my ipad bit haven't finished yet


OK, that would be cool.  Would one have to jailbreak to run it?



Yes, unfortunately.  Also there's no iPhone fortran (yet), so only
parts of sage will build.
I'll show you at MSRI at sage days 22...


Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
---
Like the ski resort full of girls hunting for husbands
and husbands hunting for girls, the situation is not
as symmetrical as it might seem.
  - Alan MacKay
--

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

URL: http://www.sagemath.org



--
William Stein
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

URL: http://www.sagemath.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
URL: http://www.sagemath.org


[sage-support] strange behavior in matrix substitution

2010-06-12 Thread Byungchul Cha

Please tell me if this is a bug, or, I'm missing something obvious...

sage: a = 3 # Assign a value to a variable a
sage: b = a # Create a copy of a
sage: b = 2 # Change the value of b
sage: b
2
sage: a # The value of a remains unchanged, as expected.
3

So far, it looks good to me. But, when I do a similar thing with
matrices, it doesn't look to be the same.

sage: v = matrix(ZZ, 3, range(9))
sage: u = v
sage: u[2] = [0,0,0]
sage: u
[0 1 2]
[3 4 5]
[0 0 0]
sage: v
[0 1 2]
[3 4 5]
[0 0 0]

Shouldn't the value of v remain the same? Why does the change in u
(or, a row of u) affect v?

-- 
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
URL: http://www.sagemath.org


Re: [sage-support] strange behavior in matrix substitution

2010-06-12 Thread Justin C. Walker


On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:



Please tell me if this is a bug, or, I'm missing something obvious...

sage: a = 3 # Assign a value to a variable a
sage: b = a # Create a copy of a
sage: b = 2 # Change the value of b
sage: b
2
sage: a # The value of a remains unchanged, as expected.
3

So far, it looks good to me. But, when I do a similar thing with
matrices, it doesn't look to be the same.

sage: v = matrix(ZZ, 3, range(9))
sage: u = v
sage: u[2] = [0,0,0]
sage: u
[0 1 2]
[3 4 5]
[0 0 0]
sage: v
[0 1 2]
[3 4 5]
[0 0 0]

Shouldn't the value of v remain the same? Why does the change in u
(or, a row of u) affect v?


You might think the behavior should be the same, but that's not the  
case.  Objects with structure (matrices, for example) are copied by  
reference, while things like integers, which have little or no  
structure (from the user's perspective at any rate) are copied by  
value.


What that means is that, for matrices, u=v means that the names u,v  
now refer to the same Sage object, so when you modify one, you are  
modifying the other (since you are really modifying the underlying  
object).


For, e.g., integers, u=v means that the names u,v both refer to  
their own copies of the value in question.


This is, BTW, the way Python works, and Python is the language with  
which (most of) Sage is implemented.


In case you didn't already know that :-}

HTH.

Justin

--
Justin C. Walker, Curmudgeon at Large
Director
Institute for the Enhancement of the Director's income
---
--
They said it couldn't be done, but sometimes,
it doesn't work out that way.
  - Casey Stengel
--



--
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
URL: http://www.sagemath.org


Re: [sage-support] strange behavior in matrix substitution

2010-06-12 Thread Mike Hansen
Hello,

On Sat, Jun 12, 2010 at 5:27 PM, Byungchul Cha cha3...@gmail.com wrote:

 Please tell me if this is a bug, or, I'm missing something obvious...

 sage: a = 3 # Assign a value to a variable a
 sage: b = a # Create a copy of a

This does not create a copy of a.  When you do a = 3, this creates
new object for the integer 3 and then makes a point to that object.
When you do b = a, it makes b point to the object that you
originally created.  When you do b = 2, it makes a new object for
the integer 2 and makes b point to that.  Notice that you are never
changing (mutating) any of the objects.


 So far, it looks good to me. But, when I do a similar thing with
 matrices, it doesn't look to be the same.
 ...
 Shouldn't the value of v remain the same? Why does the change in u
 (or, a row of u) affect v?

Here, the line sage: u[2] = [0,0,0] change the object that u in
referencing.  Since u and v point to that same object (as above), you
see the changes when you look at v.  You can use copy() to actually
make a copy of v:

sage: sage: v = matrix(ZZ, 3, range(9))
sage: v = matrix(ZZ, 3, range(9))
sage: u = copy(v)
sage: u[2] = [0,0,0]
sage: u
[0 1 2]
[3 4 5]
[0 0 0]
sage: v
[0 1 2]
[3 4 5]
[6 7 8]

--Mike

-- 
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
URL: http://www.sagemath.org


Re: [sage-support] strange behavior in matrix substitution

2010-06-12 Thread William Stein
On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:

 On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:



 Please tell me if this is a bug, or, I'm missing something obvious...

 sage: a = 3 # Assign a value to a variable a
 sage: b = a # Create a copy of a
 sage: b = 2 # Change the value of b
 sage: b
 2
 sage: a # The value of a remains unchanged, as expected.
 3

 So far, it looks good to me. But, when I do a similar thing with
 matrices, it doesn't look to be the same.

 sage: v = matrix(ZZ, 3, range(9))
 sage: u = v
 sage: u[2] = [0,0,0]
 sage: u
 [0 1 2]
 [3 4 5]
 [0 0 0]
 sage: v
 [0 1 2]
 [3 4 5]
 [0 0 0]

 Shouldn't the value of v remain the same? Why does the change in u
 (or, a row of u) affect v?


 You might think the behavior should be the same, but that's not the case.  
 Objects with structure (matrices, for example) are copied by reference, 
 while things like integers, which have little or no structure (from the 
 user's perspective at any rate) are copied by value.

 What that means is that, for matrices, u=v means that the names u,v now 
 refer to the same Sage object, so when you modify one, you are modifying the 
 other (since you are really modifying the underlying object).

 For, e.g., integers, u=v means that the names u,v both refer to their own 
 copies of the value in question.


Are you sure???  I think you statement that u is a new copy is wrong.   I bet

  u is v

would still return true above.   I can't check this now, since am on iPhone



 This is, BTW, the way 
 Pythttp://www.cnn.com/2010/HEALTH/05/29/energy.boosters/hon works, and Python 
 is the language with which (most of) Sage is implemented.

 In case you didn't already know that :-}

 HTH.

 Justin

 --
 Justin C. Walker, Curmudgeon at Large
 Director
 Institute for the Enhancement of the Director's income
 ---
 --
 They said it couldn't be done, but sometimes,
 it doesn't work out that way.
   - Casey Stengel
 --



 --
 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
 URL: http://www.sagemath.org


-- 
William Stein
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
URL: http://www.sagemath.org


Re: [sage-support] strange behavior in matrix substitution

2010-06-12 Thread Justin C. Walker


On Jun 12, 2010, at 19:07 , William Stein wrote:


On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:

[snip]

Shouldn't the value of v remain the same? Why does the change in u
(or, a row of u) affect v?

[snip]
For, e.g., integers, u=v means that the names u,v both refer to  
their own copies of the value in question.




Are you sure???  I think you statement that u is a new copy is  
wrong.   I bet


 u is v

would still return true above.


Picky picky picky.  I was hoping to avoid a trip into the twisty maze  
of passages in language definition (all of which are subtly  
different :-}).  But you are correct.  u is v does return true and  
the two actually refer to the same (physical) value.  And, if one  
variable is modified, this doesn't modify the other, or the value that  
both previously referred to.



  I can't check this now, since am on iPhone


I find that hard to believe.  I thought you had Sage running on all  
things digital...


Justin

--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Enhancement of the Director's Income

When LuteFisk is outlawed,
Only outlaws will have LuteFisk




--
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
URL: http://www.sagemath.org


Re: [sage-support] strange behavior in matrix substitution

2010-06-12 Thread William Stein
On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:

 On Jun 12, 2010, at 19:07 , William Stein wrote:


 On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


 On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:

 [snip]

 Shouldn't the value of v remain the same? Why does the change in u
 (or, a row of u) affect v?

 [snip]

 For, e.g., integers, u=v means that the names u,v both refer to their own 
 copies of the value in question.



 Are you sure???  I think you statement that u is a new copy is wrong.   I bet

  u is v

 would still return true above.


 Picky picky picky.  I was hoping to avoid a trip into the twisty maze of 
 passages in language definition (all of which are subtly different :-}).  But 
 you are correct.  u is v does return true and the two actually refer to the 
 same (physical) value.  And, if one variable is modified, this doesn't modify 
 the other, or the value that both previously referred to.


   I can't check this now, since am on iPhone


 I find that hard to believe.  I thought you had Sage running on all things 
 digital...


Your right that I could check it on my iPhone, but I was lazy.I'm
working on building sage *on* my ipad bit haven't finished yet



 Justin

 --
 Justin C. Walker, Curmudgeon-At-Large
 Institute for the Enhancement of the Director's Income
 
 When LuteFisk is outlawed,
 Only outlaws will have LuteFisk
 



 --
 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
 URL: http://www.sagemath.org


-- 
William Stein
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
URL: http://www.sagemath.org


Re: [sage-support] strange behavior in matrix substitution

2010-06-12 Thread Justin C. Walker


On Jun 12, 2010, at 20:30 , William Stein wrote:


On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


On Jun 12, 2010, at 19:07 , William Stein wrote:


On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:

[snip]


[snip]


I find that hard to believe.  I thought you had Sage running on all  
things digital...




Your right that I could check it on my iPhone, but I was lazy.I'm
working on building sage *on* my ipad bit haven't finished yet


OK, that would be cool.  Would one have to jailbreak to run it?

Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
---
Like the ski resort full of girls hunting for husbands
and husbands hunting for girls, the situation is not
as symmetrical as it might seem.
  - Alan MacKay
--

--
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
URL: http://www.sagemath.org


Sage on iPhone - Re: [sage-support] strange behavior in matrix substitution

2010-06-12 Thread William Stein
On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:

 On Jun 12, 2010, at 20:30 , William Stein wrote:


 On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


 On Jun 12, 2010, at 19:07 , William Stein wrote:


 On Saturday, June 12, 2010, Justin C. Walker jus...@mac.com wrote:


 On Jun 12, 2010, at 17:27 , Byungchul Cha wrote:

 [snip]


 [snip]


 I find that hard to believe.  I thought you had Sage running on all things 
 digital...



 Your right that I could check it on my iPhone, but I was lazy.    I'm
 working on building sage *on* my ipad bit haven't finished yet


 OK, that would be cool.  Would one have to jailbreak to run it?


Yes, unfortunately.  Also there's no iPhone fortran (yet), so only
parts of sage will build.
I'll show you at MSRI at sage days 22...

 Justin

 --
 Justin C. Walker, Curmudgeon at Large
 Institute for the Absorption of Federal Funds
 ---
 Like the ski resort full of girls hunting for husbands
 and husbands hunting for girls, the situation is not
 as symmetrical as it might seem.
   - Alan MacKay
 --

 --
 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
 URL: http://www.sagemath.org


-- 
William Stein
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
URL: http://www.sagemath.org