[sage-support] How to do it in cython?

2010-06-12 Thread Rolandb
Hi,
I have a small (nonsense) example of a program I would like to be able
to convert to cython. But I don't know how to convert:
R.A,B,C=QQ[], .factor(), .unit() and
.factor(proof=False,limit=10^5). I could not find anything in the
documentation about for instance handling elements of R.A,B,C=QQ[],
thus
sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular.


R.A,B,C=QQ[]
def test(trio,expr=(A,B,C)):
(a,b,c)=sorted(map(lambda x: abs(x(trio)),expr))
basis=prod(expr).factor()
te_ontbinden=[abs(w[0](trio)) for w in basis]+[QQ(basis.unit())]
radl=abs(prod(uniq([p for g in te_ontbinden for p,_ in
ZZ(g).factor(proof=False,limit=10^5)])))
return radl

test((1,8,9),(A^2,C^2-A^2,C^2))
30

Any help is appreciated! Roland

-- 
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] How to do it in cython?

2010-06-12 Thread Robert Bradshaw


On Jun 11, 2010, at 11:23 PM, Rolandb wrote:


Hi,
I have a small (nonsense) example of a program I would like to be able
to convert to cython. But I don't know how to convert:
R.A,B,C=QQ[], .factor(), .unit() and
.factor(proof=False,limit=10^5). I could not find anything in the
documentation about for instance handling elements of R.A,B,C=QQ[],
thus
sage
.rings
.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular.


R.A,B,C=QQ[]
def test(trio,expr=(A,B,C)):
   (a,b,c)=sorted(map(lambda x: abs(x(trio)),expr))
   basis=prod(expr).factor()
   te_ontbinden=[abs(w[0](trio)) for w in basis]+[QQ(basis.unit())]
   radl=abs(prod(uniq([p for g in te_ontbinden for p,_ in
ZZ(g).factor(proof=False,limit=10^5)])))
   return radl

test((1,8,9),(A^2,C^2-A^2,C^2))
30

Any help is appreciated! Roland


Sage is preparsed. To see what comes out, do

sage: preparse(3.factor())
'Integer(3).factor()'

sage: print preparse(
R.A,B,C=QQ[]
def test(trio,expr=(A,B,C)):
   (a,b,c)=sorted(map(lambda x: abs(x(trio)),expr))
   basis=prod(expr).factor()
   te_ontbinden=[abs(w[0](trio)) for w in basis]+[QQ(basis.unit())]
   radl=abs(prod(uniq([p for g in te_ontbinden for p,_ in
ZZ(g).factor(proof=False,limit=10^5)])))
   return radl
)

R = QQ['A, B, C']; (A, B, C,) = R._first_ngens(3)
def test(trio,expr=(A,B,C)):
  (a,b,c)=sorted(map(lambda x: abs(x(trio)),expr))
  basis=prod(expr).factor()
  te_ontbinden=[abs(w[Integer(0)](trio)) for w in basis]+ 
[QQ(basis.unit())]

  radl=abs(prod(uniq([p for g in te_ontbinden for p,_ in
ZZ(g).factor(proof=False,limit=Integer(10)**Integer(5))])))
  return radl


- 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-support] Re: XPPAUT and Sage

2010-06-12 Thread Jan Groenewald
Hi

On Fri, Jun 11, 2010 at 10:30:04AM -0700, Rob wrote:
  I guess an XPPAUT wrapper and having xppaut included in sage is first prize.
 
 As a long-time user of XPP and python I disagree strongly. I don't
 think wrapping that software would be a smart way to proceed for
 Sage.

OK. Your experience trumps my guess.

 Regarding another poster's comment about XPP: Of all the things to
 criticise, I think the complaint that XPP looks and acts old because
 of its X11 Tk/tcl style interface is a bit bizarre!  I don't have any
 trouble working with it. Many, many students and faculty still pick it
 up and use it, especially if they don't want to get too bogged down in
 programming. But I agree that if you want to invest your time wisely
 for the future, and you are willing to learn a proper programming
 language, a python-based approach is the way to go.

Same poster :) I respectfully disagree on the sentiment

1. Interface matters. A lot. Nothing bizarre about that.

2. Many, many do. Many, many don't. Tit for tat. I work with
students and researchers new to computing. They do not have the
memory we have of when this style was advanced.

3. My advice was that XPP is worth it despite its atrocious cursor focus
and cut/copy/paste behaviour, in this day and age. I guess we're making
the same point there.

regards,
Jan

-- 
   .~. 
   /V\ Jan Groenewald
  /( )\www.aims.ac.za
  ^^-^^ 

-- 
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] loading files

2010-06-12 Thread Tobias Katz
Hi Amelia,
How did you try to load the file?
I guess you are using  the notebook.
There it is possible to load a file with
load('absolute_path').

If you are using the command line version you can also use
run absolute or relative path
or
run -i absolute or relative path
for running your script in the actual namespace.

Cheers..



On 06/12/2010 06:07 AM, ataylor wrote:
 Hi.
 
 I have a MacOS 10.5.8 and while I used sage a long time ago, I have
 students who need to use sage now and so am being reintroduced.
 
 Today we wrote a little for loop and called the file sageprogram.sage
 just to get started.  However, we cannot, for the life of us load the
 file into sage.
 
 (1) we did check the sage path and put the file into a folder that is
 definitely on the path --- namely /Applications/sage/
 
 (2) The error we get is
 
 Traceback (click to the left of this block for traceback)
 ...
 IOError: [Errno 2] No such file or directory: 'sageprogram.sage'
 
 
 Which makes sense if the file is not on the path searched by sage, but
 it appears to be so.
 
 Clearly sage is not finding the program.  However, we can't find
 anything (looked in the tutorial and the reference manual) to help us
 help sage find the file.  In the tutorial where it talks about loading
 and attaching files  it does not say anything about paths or where to
 place the files.
 
 - Amelia
 

-- 
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] Re: How to do it in cython?

2010-06-12 Thread Simon King
On 12 Jun., 08:56, Robert Bradshaw rober...@math.washington.edu
wrote:
 Sage is preparsed. ...

... and the preparser is not used on .pyx and .py files.

So, when you write 3 in a .pyx file, it becomes a python int, but if
you write 3 on the Sage command line, it is interpreted (by the
preparser) as a Sage integer.

However, if I am not mistaken, Cython code *is* preparsed if it is put
into a .spyx (not .pyx) filed.

Cheers,
Simon

-- 
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] Re: Building from source sage 4.4.3 under Debian lenny amd64: gcc and g++ versions do not match

2010-06-12 Thread David Kirkby
On 12 June 2010 06:56, Jan Groenewald j...@aims.ac.za wrote:
 Hi

 On Fri, Jun 11, 2010 at 03:30:54PM -0700, orca wrote:
  Furthermore, if I type $ sudo update-alternatives --config java I get
  a list of java systems I can choose from. I think you might get a
  similar list for gcc and g++?

 I think the correct way is CC and CXX variables.

That does not have a hope in hell's chance of working.

Too man parts in Sage have 'gcc' or 'g++' encoded in them and will
ignore CC and CXX. I find it very frustrating this myself.

 https://bugs.launchpad.net/ubuntu/+source/gcc-4.2/+bug/145486

 Possible in alternatives, but not advised:
 http://www.doitian.com/2009/06/switch-gcc-41-and-43-in-ubuntu/

 regards,
 Jan

Dave

-- 
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] Re: loading files

2010-06-12 Thread ataylor

Tobias,

We are using the notebook, but knowing how to do it command line is
also helpful.

So it is true that we did not know to use  .  However, I'm still
doing something wrong.  I entered

load /Users/ataylor/research/Students/EliseAndrew/sageprogram.sage

and I know this is closer because my error changed. The error now
says

ValueError: argument
(='/Users/ataylor/research/Students/EliseAndrew/sageprogram.sage\
') to load or attach must have extension py, sage, or pyx

But our program does have the extension sage.  So I'm not sure why it
is telling me this.

- Amelia

On Jun 12, 1:28 am, Tobias Katz tobi...@web.de wrote:
 Hi Amelia,
 How did you try to load the file?
 I guess you are using  the notebook.
 There it is possible to load a file with
 load('absolute_path').

 If you are using the command line version you can also use
 run absolute or relative path
 or
 run -i absolute or relative path
 for running your script in the actual namespace.

 Cheers..

 On 06/12/2010 06:07 AM, ataylor wrote:

  Hi.

  I have a MacOS 10.5.8 and while I used sage a long time ago, I have
  students who need to use sage now and so am being reintroduced.

  Today we wrote a little for loop and called the file sageprogram.sage
  just to get started.  However, we cannot, for the life of us load the
  file into sage.

  (1) we did check the sage path and put the file into a folder that is
  definitely on the path --- namely /Applications/sage/

  (2) The error we get is

  Traceback (click to the left of this block for traceback)
  ...
  IOError: [Errno 2] No such file or directory: 'sageprogram.sage'

  Which makes sense if the file is not on the path searched by sage, but
  it appears to be so.

  Clearly sage is not finding the program.  However, we can't find
  anything (looked in the tutorial and the reference manual) to help us
  help sage find the file.  In the tutorial where it talks about loading
  and attaching files  it does not say anything about paths or where to
  place the files.

  - Amelia

-- 
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] Re: loading files

2010-06-12 Thread Tobias Katz
Hi,
x has been only a placeholder.

In your case you probably would have to enter
load('/Users/ataylor/research/Students/EliseAndrew/sageprogram.sage')

Good luck with it!

Tobi



On 06/12/2010 04:06 PM, ataylor wrote:
 
 Tobias,
 
 We are using the notebook, but knowing how to do it command line is
 also helpful.
 
 So it is true that we did not know to use  .  However, I'm still
 doing something wrong.  I entered
 
 load /Users/ataylor/research/Students/EliseAndrew/sageprogram.sage
 
 and I know this is closer because my error changed. The error now
 says
 
 ValueError: argument
 (='/Users/ataylor/research/Students/EliseAndrew/sageprogram.sage\
 ') to load or attach must have extension py, sage, or pyx
 
 But our program does have the extension sage.  So I'm not sure why it
 is telling me this.
 
 - Amelia
 
 On Jun 12, 1:28 am, Tobias Katz tobi...@web.de wrote:
 Hi Amelia,
 How did you try to load the file?
 I guess you are using  the notebook.
 There it is possible to load a file with
 load('absolute_path').

 If you are using the command line version you can also use
 run absolute or relative path
 or
 run -i absolute or relative path
 for running your script in the actual namespace.

 Cheers..

 On 06/12/2010 06:07 AM, ataylor wrote:

 Hi.

 I have a MacOS 10.5.8 and while I used sage a long time ago, I have
 students who need to use sage now and so am being reintroduced.

 Today we wrote a little for loop and called the file sageprogram.sage
 just to get started.  However, we cannot, for the life of us load the
 file into sage.

 (1) we did check the sage path and put the file into a folder that is
 definitely on the path --- namely /Applications/sage/

 (2) The error we get is

 Traceback (click to the left of this block for traceback)
 ...
 IOError: [Errno 2] No such file or directory: 'sageprogram.sage'

 Which makes sense if the file is not on the path searched by sage, but
 it appears to be so.

 Clearly sage is not finding the program.  However, we can't find
 anything (looked in the tutorial and the reference manual) to help us
 help sage find the file.  In the tutorial where it talks about loading
 and attaching files  it does not say anything about paths or where to
 place the files.

 - Amelia
 

-- 
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] Re: Building from source sage 4.4.3 under Debian lenny amd64: gcc and g++ versions do not match

2010-06-12 Thread ma...@mendelu.cz
Hi, I do not understand the suggestion in this thread, but Sage
compiles fine on Debian Lenny

The compiled Sage is at 
http://user.mendelu.cz/marik/temp/sage-4.4.3-x86_64-Linux.tar.gz

My configuration:
ma...@um-bc107:/opt$ uname -a
Linux um-bc107 2.6.26-2-amd64 #1 SMP Wed May 12 18:03:14 UTC 2010
x86_64 GNU/Linux

Hope this helps
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


[sage-support] Re: loading files

2010-06-12 Thread ataylor
Got It.  Success.  Thanks!  I'm surprised at my syntax troubles with
this, but it all makes sense now.

Appreciated,
Amelia

On Jun 12, 8:21 am, Tobias Katz tobi...@web.de wrote:
 Hi,
 x has been only a placeholder.

 In your case you probably would have to enter
 load('/Users/ataylor/research/Students/EliseAndrew/sageprogram.sage')

 Good luck with it!

 Tobi

 On 06/12/2010 04:06 PM, ataylor wrote:



  Tobias,

  We are using the notebook, but knowing how to do it command line is
  also helpful.

  So it is true that we did not know to use  .  However, I'm still
  doing something wrong.  I entered

  load /Users/ataylor/research/Students/EliseAndrew/sageprogram.sage

  and I know this is closer because my error changed. The error now
  says

  ValueError: argument
  (='/Users/ataylor/research/Students/EliseAndrew/sageprogram.sage\
  ') to load or attach must have extension py, sage, or pyx

  But our program does have the extension sage.  So I'm not sure why it
  is telling me this.

  - Amelia

  On Jun 12, 1:28 am, Tobias Katz tobi...@web.de wrote:
  Hi Amelia,
  How did you try to load the file?
  I guess you are using  the notebook.
  There it is possible to load a file with
  load('absolute_path').

  If you are using the command line version you can also use
  run absolute or relative path
  or
  run -i absolute or relative path
  for running your script in the actual namespace.

  Cheers..

  On 06/12/2010 06:07 AM, ataylor wrote:

  Hi.

  I have a MacOS 10.5.8 and while I used sage a long time ago, I have
  students who need to use sage now and so am being reintroduced.

  Today we wrote a little for loop and called the file sageprogram.sage
  just to get started.  However, we cannot, for the life of us load the
  file into sage.

  (1) we did check the sage path and put the file into a folder that is
  definitely on the path --- namely /Applications/sage/

  (2) The error we get is

  Traceback (click to the left of this block for traceback)
  ...
  IOError: [Errno 2] No such file or directory: 'sageprogram.sage'

  Which makes sense if the file is not on the path searched by sage, but
  it appears to be so.

  Clearly sage is not finding the program.  However, we can't find
  anything (looked in the tutorial and the reference manual) to help us
  help sage find the file.  In the tutorial where it talks about loading
  and attaching files  it does not say anything about paths or where to
  place the files.

  - Amelia

-- 
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] Re: Building from source sage 4.4.3 under Debian lenny amd64: gcc and g++ versions do not match

2010-06-12 Thread orca
Sorry Marik and Bradshaw, but I use Debian for some five years now and
I just have a plain vanilla Debian lenny (current stable) and the
NORMAL gcc, g++ and gfortran, as I have suggested in my first post in
this thread, and as I state categorically now, sure do not all match:
the stock lenny gcc is 4.3.2, g++ is 4.2.4, and gfortran is 4.3.2. I
have now installed both versions 4.2 and 4.3 from the official Debian
lenny repositories for all three mentioned compilers. I have now tried
the following make command in order to drive the building with the
matched 4.2 versions of all these compilers:

make CC=gcc-4.2 FC=gfortran-4.2

The following error is now issued:

Found gcc 4 or later
make[2]: Entering directory `/home/orca/sage/sage-4.4.3/spkg/build/
flint-1.5.0.p4/src'
gcc-4.2 -I/home/orca/sage/sage-4.4.3/local/include/ -I/home/orca/sage/
sage-4.4.3/local/include -fPIC -funroll-loops  -O2 -DNDEBUG -o
zn_mod.o -c zn_poly/src/zn_mod.c
In file included from zn_poly/src/zn_poly_internal.h:50,
 from zn_poly/src/zn_mod.c:23:
zn_poly/src/../../mpn_extras.h: In function ‘F_mpn_negate’:
zn_poly/src/../../mpn_extras.h:75: error: ‘for’ loop initial
declaration used outside C99 mode
zn_poly/src/../../mpn_extras.h: In function ‘F_mpn_copy’:
zn_poly/src/../../mpn_extras.h:96: error: ‘for’ loop initial
declaration used outside C99 mode
zn_poly/src/../../mpn_extras.h: In function ‘F_mpn_copy_forward’:
zn_poly/src/../../mpn_extras.h:104: error: ‘for’ loop initial
declaration used outside C99 mode
zn_poly/src/../../mpn_extras.h: In function ‘F_mpn_clear’:
zn_poly/src/../../mpn_extras.h:118: error: ‘for’ loop initial
declaration used outside C99 mode
zn_poly/src/../../mpn_extras.h: In function ‘F_mpn_set’:
zn_poly/src/../../mpn_extras.h:129: error: ‘for’ loop initial
declaration used outside C99 mode
zn_poly/src/../../mpn_extras.h: In function ‘F_mpn_printx’:
zn_poly/src/../../mpn_extras.h:145: error: ‘for’ loop initial
declaration used outside C99 mode
make[2]: *** [zn_mod.o] Error 1
make[2]: Leaving directory `/home/orca/sage/sage-4.4.3/spkg/build/
flint-1.5.0.p4/src'
Error building flint shared library.

real0m0.098s
user0m0.068s
sys 0m0.024s
sage: An error occurred while installing flint-1.5.0.p4
Please email sage-devel http://groups.google.com/group/sage-devel
explaining the problem and send the relevant part of
of /home/orca/sage/sage-4.4.3/install.log.  Describe your computer,
operating system, etc.
If you want to try to fix the problem yourself, *don't* just cd to
/home/orca/sage/sage-4.4.3/spkg/build/flint-1.5.0.p4 and type 'make
check' or whatever is appropriate.
Instead, the following commands setup all environment variables
correctly and load a subshell for you to debug the error:
(cd '/home/orca/sage/sage-4.4.3/spkg/build/flint-1.5.0.p4'  '/home/
orca/sage/sage-4.4.3/sage' -sh)
When you are done debugging, you can type exit to leave the
subshell.
make[1]: *** [installed/flint-1.5.0.p4] Error 1
make[1]: Leaving directory `/home/orca/sage/sage-4.4.3/spkg'

real26m35.080s
user21m55.518s
sys 3m11.324s
Error building Sage.
./sage -docbuild all html  21 | tee -a dochtml.log
python: can't open file '/home/orca/sage/sage-4.4.3/devel/sage/doc/
common/builder.py': [Errno 2] No such file or directory


I wil take the liberty to forward this error to the sage-dev list as
well...

Any other concrete directions are warmly appreciated!


On Jun 12, 1:06 pm, Robert Bradshaw rober...@math.washington.edu
wrote:
 On Jun 12, 2010, at 7:51 AM, ma...@mendelu.cz wrote:

  Hi, I do not understand the suggestion in this thread, but Sage
  compiles fine on Debian Lenny

 Yes, it does. This thread was started due to a mismatch in the gcc and  
 g++ versions. If both versions are the same (which is the norm), it  
 should compile from source just fine.

 - 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


[sage-support] Re: Building from source sage 4.4.3 under Debian lenny amd64: gcc and g++ versions do not match

2010-06-12 Thread ma...@mendelu.cz
On 12 čvn, 23:10, orca mocal...@gmail.com wrote:
 Sorry Marik and Bradshaw, but I use Debian for some five years now and
 I just have a plain vanilla Debian lenny (current stable) and the

I have the same version of gcc and g++, see also 
http://packages.debian.org/lenny/g++
and http://packages.debian.org/lenny/g++  -- both versions are 4.3.2

You may have broken installation, installation which is not up to date
or frozen package g++ ...

Do you have 64  bit system? Does my package work on your computer?

Another my suggestion is to install new Debian Lenny in virtual
machine, compile in this virtual machine and finally move to physical
machine.

Does this help?

Robert M.

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