Re: [sage-support] Strange behavior when evaluating multivariate polynomials over integers modulo n

2021-03-08 Thread Dima Pasechnik
On Mon, Mar 8, 2021 at 12:27 PM Alex Braat  wrote:
>
> Small update:
> Replacing Integers(p^2) by QuotientRing(ZZ, p^2) seems to fix the issue.

Could you open a trac ticket on this?
It looks as if multivariate polynomial rings over Integers(p^2) are
directly using Singular,
but I don't think Singular can do such computations (over non-fields)

QuotientRing(ZZ, p^2) does something else.

>
> Op maandag 8 maart 2021 om 10:34:06 UTC+1 schreef dim...@gmail.com:
>>
>> On Mon, Mar 8, 2021 at 9:25 AM Alex Braat  wrote:
>> >
>> > Hello,
>> >
>> > I have encountered some strange behavior when I evaluate multivariate 
>> > polynomials over the integers modulo n. For instance,
>> >
>> > In:
>> > p = 3
>> > S = Integers(p^2)
>> > R. = PolynomialRing(S)
>> > f = x^2 * y^2
>> > print(f([S(p),S(1)]), f([S(1), S(p)]))
>> >
>> > Out:
>> > 1 0
>> >
>> > while both evaluations should ofcourse be equal to 0. This does not depend 
>> > on the prime p, and is consistent in both of these versions of SageMath:
>>
>> looks like a bug (also in the 9.3.beta7)
>> sage: f(S(3),S(1))
>> 1
>>
>>
>> >
>> > 'SageMath version 8.7, Release Date: 2019-03-23'
>> > 'SageMath version 9.2, Release Date: 2020-10-24'
>> >
>> > Am I doing something wrong or is this a bug?
>> >
>> > --
>> > 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...@googlegroups.com.
>> > To view this discussion on the web visit 
>> > https://groups.google.com/d/msgid/sage-support/e3b67e84-1d8b-46e4-b0dd-5558f6d4929bn%40googlegroups.com.
>
> --
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-support/c860111e-aeea-43ff-b6c5-5c392e590789n%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CAAWYfq0aFG%3Drtp%3DffKQc1T3ykWAXE0niAV0oQ2SQif9cRzU3Yg%40mail.gmail.com.


Re: [sage-support] Strange behavior when evaluating multivariate polynomials over integers modulo n

2021-03-08 Thread Alex Braat
Small update:
Replacing Integers(p^2) by QuotientRing(ZZ, p^2) seems to fix the issue.

Op maandag 8 maart 2021 om 10:34:06 UTC+1 schreef dim...@gmail.com:

> On Mon, Mar 8, 2021 at 9:25 AM Alex Braat  wrote:
> >
> > Hello,
> >
> > I have encountered some strange behavior when I evaluate multivariate 
> polynomials over the integers modulo n. For instance,
> >
> > In:
> > p = 3
> > S = Integers(p^2)
> > R. = PolynomialRing(S)
> > f = x^2 * y^2
> > print(f([S(p),S(1)]), f([S(1), S(p)]))
> >
> > Out:
> > 1 0
> >
> > while both evaluations should ofcourse be equal to 0. This does not 
> depend on the prime p, and is consistent in both of these versions of 
> SageMath:
>
> looks like a bug (also in the 9.3.beta7)
> sage: f(S(3),S(1))
> 1
>
>
> >
> > 'SageMath version 8.7, Release Date: 2019-03-23'
> > 'SageMath version 9.2, Release Date: 2020-10-24'
> >
> > Am I doing something wrong or is this a bug?
> >
> > --
> > 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...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-support/e3b67e84-1d8b-46e4-b0dd-5558f6d4929bn%40googlegroups.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/c860111e-aeea-43ff-b6c5-5c392e590789n%40googlegroups.com.


Re: [sage-support] Strange behavior when evaluating multivariate polynomials over integers modulo n

2021-03-08 Thread Dima Pasechnik
On Mon, Mar 8, 2021 at 9:25 AM Alex Braat  wrote:
>
> Hello,
>
> I have encountered some strange behavior when I evaluate multivariate 
> polynomials over the integers modulo n. For instance,
>
> In:
> p = 3
> S = Integers(p^2)
> R. = PolynomialRing(S)
> f = x^2 * y^2
> print(f([S(p),S(1)]), f([S(1), S(p)]))
>
> Out:
> 1 0
>
> while both evaluations should ofcourse be equal to 0. This does not depend on 
> the prime p, and is consistent in both of these versions of SageMath:

looks like a bug (also in the 9.3.beta7)
sage: f(S(3),S(1))
1


>
> 'SageMath version 8.7, Release Date: 2019-03-23'
> 'SageMath version 9.2, Release Date: 2020-10-24'
>
> Am I doing something wrong or is this a bug?
>
> --
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-support/e3b67e84-1d8b-46e4-b0dd-5558f6d4929bn%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CAAWYfq3W2Y47dMdY_zJSDcL_2_5aw%3DTnqqqnOrt9WGCNcwKcDQ%40mail.gmail.com.


[sage-support] Strange behavior when evaluating multivariate polynomials over integers modulo n

2021-03-08 Thread Alex Braat
Hello,

I have encountered some strange behavior when I evaluate multivariate 
polynomials over the integers modulo n. For instance,

In:
p = 3
S = Integers(p^2)
R. = PolynomialRing(S)
f = x^2 * y^2
print(f([S(p),S(1)]), f([S(1), S(p)]))

Out:
1 0

while both evaluations should ofcourse be equal to 0. This does not depend 
on the prime p, and is consistent in both of these versions of SageMath:

'SageMath version 8.7, Release Date: 2019-03-23'
'SageMath version 9.2, Release Date: 2020-10-24'

Am I doing something wrong or is this a bug?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/e3b67e84-1d8b-46e4-b0dd-5558f6d4929bn%40googlegroups.com.


[sage-support] Strange behavior in relabeling a graph in Sage 9.2

2021-01-08 Thread Nikos Apostolakis
Dear list,

Relabeling a graph in Sage 9.2 exhibits some strange behavior.  If the
argument is a dictionary constructed by dictionary comprehension Sage seems
to just ignore it.  If the dictionary is explicitly given then everything
works.  Here is an example

sage: bar = DiGraph([((2, 3), (1, 2), 2), ((3, 4), (3, 5), 3), ((3, 5), (2,
3), 3), ((5, 6), (5, 7), 5), ((5, 7), (3, 5), 5)])
sage: foo = [(5,6), (3,4), (5,7), (3,5), (2,3), (1,2)]
sage: bar.relabel({foo[i]: i for i in range(6)})
sage: bar.vertices()
[(1, 2), (2, 3), (3, 4), (3, 5), (5, 6), (5, 7)]
sage: ## However if I explicitly give the dictionary
sage: {foo[i]: i for i in range(6)}
{(5,6): 0, (3,4): 1, (5,7): 2, (3,5): 3, (2,3): 4, (1,2): 5}
sage: bar.relabel({(5,6): 0, (3,4): 1, (5,7): 2, (3,5): 3, (2,3): 4, (1,2):
5})
sage: bar.vertices()
[0, 1, 2, 3, 4, 5]
sage: sage0_version()
'SageMath version 9.2, Release Date: 2020-10-24'


This problem doesn't seem to happen in older versions of Sage. I have Sage
8.8 in another box and the problem doesn't occur:

sage: bar = DiGraph([((2, 3), (1, 2), 2), ((3, 4), (3, 5), 3), ((3, 5), (2,
3), 3), ((5, 6), (5, 7), 5), ((5, 7), (3, 5), 5)])
sage: foo = [(5,6), (3,4), (5,7), (3,5), (2,3), (1,2)]
sage: bar.relabel({foo[i]: i for i in range(6)})
sage: bar.vertices()
[0, 1, 2, 3, 4, 5]
sage: sage0_version()
'SageMath version 8.8, Release Date: 2019-06-26'

I wonder if this is caused by the transition to Python3. Some kind of lazy
evaluation?

Thanks,
Nikos Apostolakis
-- 
Οι ελαφροί ας με λέγουν ελαφρόν.
Στα σοβαρά πράγματα ήμουν πάντοτε
επιμελέστατος.

The frivolous can call me frivolous. In serious matters I've always been
most diligent.
  K. P. Kavafy

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CAO2SUmJnoUBYS88n4QP0oU_9odJVKJE053wLSH3%3Dz2ggeNDAAw%40mail.gmail.com.


Re: [sage-support] Strange behavior with RealField(n)

2016-02-21 Thread Thierry Dumont

Le 21/02/2016 20:40, John Cremona a écrit :

Try RealField(500).pi() and similar.

Yes, it works... but my small piece of code should also give correct 
results...

thanks.
t.


On 21 Feb 2016 18:10, "Thierry Dumont" > wrote:

I have students who want to compute decimals of pi...so, what can we
do with RealField(n) ?
I make the following script (pi.sage):


for p in [2..10]:
 R=RealField(10^p)
 pii=4*atan(R(1))
 print p,R,pii


Then, using sage 7.0 or 7.1.beta4:

attach("pi.sage")

This produces a lot of seemingly correct output, but, as it takes a
too long time to finish :-), I interrupt the computation (Ctrl-c).

So, lets try again; replace 10 by 5 in the for statement (I do not
leave sage). I get NaNs:


2 Real Field with 100 bits of precision NaN
3 Real Field with 1000 bits of precision NaN
4 Real Field with 1 bits of precision NaN
5 Real Field with 10 bits of precision NaN
.

Strange.

Yours
t.d.


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


--
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] Strange behavior with RealField(n)

2016-02-21 Thread John Cremona
Try RealField(500).pi() and similar.
On 21 Feb 2016 18:10, "Thierry Dumont"  wrote:

> I have students who want to compute decimals of pi...so, what can we do
> with RealField(n) ?
> I make the following script (pi.sage):
>
> 
> for p in [2..10]:
> R=RealField(10^p)
> pii=4*atan(R(1))
> print p,R,pii
> 
>
> Then, using sage 7.0 or 7.1.beta4:
>
> attach("pi.sage")
>
> This produces a lot of seemingly correct output, but, as it takes a too
> long time to finish :-), I interrupt the computation (Ctrl-c).
>
> So, lets try again; replace 10 by 5 in the for statement (I do not leave
> sage). I get NaNs:
>
>
> 2 Real Field with 100 bits of precision NaN
> 3 Real Field with 1000 bits of precision NaN
> 4 Real Field with 1 bits of precision NaN
> 5 Real Field with 10 bits of precision NaN
> .
>
> Strange.
>
> Yours
> t.d.
>
>
> --
> 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.


[sage-support] Strange behavior with RealField(n)

2016-02-21 Thread Thierry Dumont
I have students who want to compute decimals of pi...so, what can we do 
with RealField(n) ?

I make the following script (pi.sage):


for p in [2..10]:
R=RealField(10^p)
pii=4*atan(R(1))
print p,R,pii


Then, using sage 7.0 or 7.1.beta4:

attach("pi.sage")

This produces a lot of seemingly correct output, but, as it takes a too 
long time to finish :-), I interrupt the computation (Ctrl-c).


So, lets try again; replace 10 by 5 in the for statement (I do not leave 
sage). I get NaNs:



2 Real Field with 100 bits of precision NaN
3 Real Field with 1000 bits of precision NaN
4 Real Field with 1 bits of precision NaN
5 Real Field with 10 bits of precision NaN
.

Strange.

Yours
t.d.


--
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] strange behavior with sums

2014-06-23 Thread Karl Schultheisz
I'm using Sage 6.2 on Arch Linux. I have posted before about sums being 
wrong 
https://groups.google.com/d/msg/sage-support/IgC78rcdO7c/qTWzpA9f-P8J, 
and I am happy to see that the community took action. Thanks! I have been 
seeing other errors that may or may not be related to those addressed in 
the link above.

I open a new Sage session (command line). The following code ought to 
return (e^x - 1)/x.

sage: k = var('k')
sage: sum(x^k/factorial(k+1),k,0,oo)
1/4*sqrt(pi)*sqrt(x)*e^(1/2*x)

This looks similar to the sort of nonsense it was spitting out when 
misinterpreting 
Bessel functions from Maxima http://trac.sagemath.org/ticket/16224. In 
the same session, if I run the summation command again, the result is 
different.

sage: sum(x^k/factorial(k+1),k,0,oo)
sum(x^k/factorial(k + 1), k, 0, +Infinity)

And after this it will not simplify any sums, even ones it would have done 
correctly on the first try:

sage: sum(x^k/factorial(k),k,0,oo)
sum(x^k/factorial(k), k, 0, +Infinity)

Even a reset doesn't help. (As a side-note, the exit command doesn't 
survive reset.)

sage: reset()
sage: k = var('k')
sage: sum(x^k/factorial(k),k,0,oo)
sum(x^k/factorial(k), k, 0, +Infinity)
sage: exit

---
NameError Traceback (most recent call 
last)
/opt/sage/local/lib/python2.7/site-packages/sage/all_cmdline.py in 
module()
 1 exit

NameError: name 'exit' is not defined

Finite sums seem to be ok.

sage: sum(x^k,k,0,3)
x^3 + x^2 + x + 1
sage: m = var('m')
sage: sum(x^k,k,0,m)
(x^(m + 1) - 1)/(x - 1)

Any help is greatly appreciated.

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


[sage-support] strange behavior in sage 5.0

2012-05-17 Thread Kenneth A. Ribet
Any advice here?  Am I doing something wrong:

 sage: 1+1
 2
 sage: (0.8*0.15)/(0.8*0.15 + 0.2*0.85)
 
 
 Unhandled SIGILL: An illegal instruction occurred in Sage.
 This probably occurred because a *compiled* component of Sage has a bug
 in it and is not properly wrapped with sig_on(), sig_off(). You might
 want to run Sage under gdb with 'sage -gdb' to debug this.
 Sage will now terminate.
 
 /Users/kribet/Desktop/sage/spkg/bin/sage: line 312: 70167 Illegal 
 instruction: 4  sage-ipython $@ -i

Ken

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


[sage-support] strange behavior on assigning string with single quotes

2010-05-12 Thread Rajeev
Hi,

I am finding a very strange behavior in notebook. Evaluating

a = 'hello'

gives

Traceback (most recent call last):
  File stdin, line 1, in module
  File _sage_input_12.py, line 4, in module
print _support_.syseval(python, ur\u0027\u0027\u0027a = \u0027hello
\u0027\u0027\u0027\u0027, \u0027/home/rajeev/sage_notebook/
sage_notebook.sagenb/home/admin/32/cells/25\u0027)
  File , line 1
print _support_.syseval(python, ur'''a = 'hello, '/home/rajeev/
sage_notebook/sage_notebook.sagenb/home/admin/32/cells/25')
 
^
SyntaxError: EOL while scanning string literal

There is no problem when I use double quotes. I am using sage 4.2 and
I have selected python from the dropdown menu at the top.

Rajeev

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

2009-08-03 Thread VictorMiller

I was trying to find out how fast a calculation was (applying an
isogeny of degree on an elliptic curve over
a finite field).  At first I noticed that when I repeated a timeit
call with the same expression I was getting monotonically increasing
numbers, so I decided to try something more systematic. I got the
following peculiar results on sagenb.org (just now).  The average
times keep getting longer and longer.  Could this be some bug in the
way that the calls to internal timer routines are used?

 phi = E.isogeny([E(0),P,-P])
for i in xrange(20): timeit('phi(Q)')

625 loops, best of 3: 1.17 ms per loop
625 loops, best of 3: 1.75 ms per loop
125 loops, best of 3: 2.1 ms per loop
125 loops, best of 3: 2.22 ms per loop
125 loops, best of 3: 2.3 ms per loop
125 loops, best of 3: 2.4 ms per loop
125 loops, best of 3: 2.52 ms per loop
125 loops, best of 3: 2.73 ms per loop
125 loops, best of 3: 3.02 ms per loop
125 loops, best of 3: 3.32 ms per loop
125 loops, best of 3: 3.48 ms per loop
125 loops, best of 3: 3.73 ms per loop
125 loops, best of 3: 3.79 ms per loop
125 loops, best of 3: 4.21 ms per loop
125 loops, best of 3: 4.56 ms per loop
125 loops, best of 3: 5.09 ms per loop
125 loops, best of 3: 5.63 ms per loop
125 loops, best of 3: 6.23 ms per loop
125 loops, best of 3: 6.86 ms per loop
125 loops, best of 3: 7.52 ms per loop

Victor

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



[sage-support] strange behavior

2009-06-13 Thread Florian Beutler

Hay
I am a bit annoyed by sage... I just want to print a function two
times and sage gives me an error... this is the first script

#!/usr/bin/env sage -python
import sys
from sage.all import *

import functions
from functions import *

grav_const = 4.3e-06
pi = 3.14159265358979323846
sat_mass = 20.

print Ok... dann legen wir mal los!\n
print step1: definition of the density profile

r = 0.08

print rho(r),\n

print step3: definition of the integrated mass

print mass(r).n(),\n

print step3: definition of the integrated mass

print mass(r).n(),\n

the function definition is the following

import sys
from sage.all import *

def rho(r):
return  1.32419e+08/(1.+(r/0.81))**3

def mass(r):
pi = 3.14159265358979323846

x=var('x')
assume(x0)
i_term = integral(x**2*rho(x), x, 0, r)

return i_term*4.*pi;

so I just try to plot the mass two times... the error message of sage
is not very helpful (at least to me)
thanks for any help
florian



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



[sage-support] Strange behavior on sagenb

2009-03-26 Thread Jason Bandlow

Hi all,

When I start up a clean version of sage 3.4 on my local machine and
enter the following into a notebook cell:

M=load('http://www.math.upenn.edu/~jbandlow/sage_data/dic_of_kst_to_G_cob_mats.sobj')
# This object is a dictionary
key = (1, Partition([1]),Partition([2]))
print key in M.keys()
M[key]

I get the following (correct) output:

Attempting to load remote file:
http://www.math.upenn.edu/~jbandlow/sage_data/dic_of_kst_to_G_cob_mats.s\
obj
Loading: [..]
True
# A matrix that I won't reproduce here

When I enter the exact same text in a notebook cell on sagenb, I get the
following output:

Attempting to load remote file:
http://www.math.upenn.edu/~jbandlow/sage_data/dic_of_kst_to_G_cob_mats.s\
obj
Loading: [..]
True
Traceback (most recent call last):
  File stdin, line 1, in module
  File
/home/sage/sagenb/sage_notebook/worksheets/jbandlow/11/code/41.py,
line 10, in module
M[key]
  File
/home/sage/sage_install/sage-a/local/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/,
line 1, in module

KeyError: (1, [1], [2])

Why am I getting a KeyError if key in M.keys() is returning True?  And
why is the behavior on sagenb different than on my local, 3.4
built-from-source on Ubuntu 10.8 distribution?

Any ideas are very welcome!

Cheers,
Jason


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