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.


Re: [sage-support] Strange

2018-04-07 Thread Nikos Apostolakis
Graph(7) creates a graph with vertices {0 ..., 6}

HTH,
Nikos

Sent from my iPhone 

> On Apr 7, 2018, at 9:16 AM, Henri Girard  wrote:
> 
> thanks, I tried david suggestion and it's correct now :
> 
> edges = [(1,2), (1,3), (1,4),
> (2,3), (2,4), (2,5), (2, 6),
> (3,4), (3,5), (3,6), (3,7),
> (4,6), (4,7), (5,6), (6,7)]
> Gamma = Graph(edges)
> Gamma.show() 
> 
> 
> 
> Meanwhile I made it too with networkx to compare :
> 
> import networkx as nx  
> import matplotlib.pyplot as plt
> G = nx.Graph()
>
> edges = [(1,2), (1,3), (1,4), 
> (2,3), (2,4), (2,5), (2, 6), 
> (3,4), (3,5), (3,6), (3,7), 
> (4,6), (4,7), (5,6), (6,7)]
> G.add_edges_from(edges)   
>
> nx.draw_networkx(G)   
>
> limits = plt.axis('off')  
>
> plt.show(G)  
> 
> 
> 
> 
>> Le 07/04/2018 à 15:09, Jan Groenewald a écrit :
>> Hi
>> 
>>> On 7 April 2018 at 14:52, Henri Girard  wrote:
>>> I made this graph (meaning a fano's plane) but I have the zero outside the 
>>> graph ?
>>> 
>>> I don't understand why ? someone could explain ?
>>> 
>>> My adjacency_matrix is 8 but shouldn't be 7 ?
>>> 
>>> g=Graph(7)
>>> edges = [(1,2), (1,3), (1,4), 
>>> (2,3), (2,4), (2,5), (2, 6), 
>>> (3,4), (3,5), (3,6), (3,7), 
>>> (4,6), (4,7), (5,6), (6,7)]
>>> g.add_edge(1,2),g.add_edge(1,3),g.add_edge(1,4),g.add_edge(2,3),
>>> g.add_edge(2,4),g.add_edge(2,5),g.add_edge(2,6),g.add_edge(3,4),
>>> g.add_edge(3,5),g.add_edge(3,6),g.add_edge(3,7),g.add_edge(4,6),
>>> g.add_edge(4,7),g.add_edge(5,6),g.add_edge(6,7)
>>> g.show()
>>> g.adjacency_matrix(),g.incidence_matrix()
>>> 
>>> 
>>> 
>>> Best
>>> 
>> 
>> 
>> Graph? shows
>> 
>>   2. "Graph(5)" -- return an edgeless graph on the 5 vertices
>>  0,...,4.
>> 
>>   3. "Graph([list_of_vertices,list_of_edges])" -- returns a
>>  graph with given vertices/edges.
>> 
>>  To bypass auto-detection, prefer the more explicit
>>  "Graph([V,E],format='vertices_and_edges')".
>> 
>>   4. "Graph(list_of_edges)" -- return a graph with a given list
>>  of edges (see documentation of "add_edges()").
>> 
>>  To bypass auto-detection, prefer the more explicit "Graph(L,
>>  format='list_of_edges')".
>> 
>>   5. "Graph({1:[2,3,4],3:[4]})" -- return a graph by
>>  associating to each vertex the list of its neighbors.
>> 
>>  To bypass auto-detection, prefer the more explicit "Graph(D,
>>  format='dict_of_lists')".
>> 
>> so it seems correct, and there are alternatives if you prefer 1..8 instead 
>> of 0..7.
>> 
>> Regards,
>> Jan 
>>> 
>> 
>> 
>> 
>> -- 
>>   .~. 
>>   /V\ Jan Groenewald
>>  /( )\www.aims.ac.za
>>  ^^-^^ 
>> -- 
>> 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

2018-04-07 Thread Henri Girard

thanks, I tried david suggestion and it's correct now :

edges = [(1,2), (1,3), (1,4),
    (2,3), (2,4), (2,5), (2, 6),
    (3,4), (3,5), (3,6), (3,7),
    (4,6), (4,7), (5,6), (6,7)]
Gamma = Graph(edges)
Gamma.show()


Meanwhile I made it too with networkx to compare :

import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
edges = [(1,2), (1,3), (1,4),
    (2,3), (2,4), (2,5), (2, 6),
    (3,4), (3,5), (3,6), (3,7),
    (4,6), (4,7), (5,6), (6,7)]
G.add_edges_from(edges)
nx.draw_networkx(G)
limits = plt.axis('off')
plt.show(G)



Le 07/04/2018 à 15:09, Jan Groenewald a écrit :

Hi

On 7 April 2018 at 14:52, Henri Girard > wrote:


I made this graph (meaning a fano's plane) but I have the zero
outside the graph ?

I don't understand why ? someone could explain ?

My adjacency_matrix is 8 but shouldn't be 7 ?

g=Graph(7)
edges = [(1,2), (1,3), (1,4),
    (2,3), (2,4), (2,5), (2, 6),
    (3,4), (3,5), (3,6), (3,7),
    (4,6), (4,7), (5,6), (6,7)]
g.add_edge(1,2),g.add_edge(1,3),g.add_edge(1,4),g.add_edge(2,3),
g.add_edge(2,4),g.add_edge(2,5),g.add_edge(2,6),g.add_edge(3,4),
g.add_edge(3,5),g.add_edge(3,6),g.add_edge(3,7),g.add_edge(4,6),
g.add_edge(4,7),g.add_edge(5,6),g.add_edge(6,7)
g.show()
g.adjacency_matrix(),g.incidence_matrix()

Best



Graph? shows

  2. "Graph(5)" -- return an edgeless graph on the 5 vertices
 0,...,4.

  3. "Graph([list_of_vertices,list_of_edges])" -- returns a
 graph with given vertices/edges.

 To bypass auto-detection, prefer the more explicit
 "Graph([V,E],format='vertices_and_edges')".

  4. "Graph(list_of_edges)" -- return a graph with a given list
 of edges (see documentation of "add_edges()").

 To bypass auto-detection, prefer the more explicit "Graph(L,
 format='list_of_edges')".

  5. "Graph({1:[2,3,4],3:[4]})" -- return a graph by
 associating to each vertex the list of its neighbors.

 To bypass auto-detection, prefer the more explicit "Graph(D,
 format='dict_of_lists')".

so it seems correct, and there are alternatives if you prefer 1..8 
instead of 0..7.


Regards,
Jan





--
  .~.
  /V\ Jan Groenewald
 /( )\ www.aims.ac.za 
 ^^-^^
--
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

2018-04-07 Thread Jan Groenewald
Hi

On 7 April 2018 at 14:52, Henri Girard  wrote:

> I made this graph (meaning a fano's plane) but I have the zero outside the
> graph ?
>
> I don't understand why ? someone could explain ?
>
> My adjacency_matrix is 8 but shouldn't be 7 ?
>
> g=Graph(7)
> edges = [(1,2), (1,3), (1,4),
> (2,3), (2,4), (2,5), (2, 6),
> (3,4), (3,5), (3,6), (3,7),
> (4,6), (4,7), (5,6), (6,7)]
> g.add_edge(1,2),g.add_edge(1,3),g.add_edge(1,4),g.add_edge(2,3),
> g.add_edge(2,4),g.add_edge(2,5),g.add_edge(2,6),g.add_edge(3,4),
> g.add_edge(3,5),g.add_edge(3,6),g.add_edge(3,7),g.add_edge(4,6),
> g.add_edge(4,7),g.add_edge(5,6),g.add_edge(6,7)
> g.show()
> g.adjacency_matrix(),g.incidence_matrix()
>
> Best
>


Graph? shows

  2. "Graph(5)" -- return an edgeless graph on the 5 vertices
 0,...,4.

  3. "Graph([list_of_vertices,list_of_edges])" -- returns a
 graph with given vertices/edges.

 To bypass auto-detection, prefer the more explicit
 "Graph([V,E],format='vertices_and_edges')".

  4. "Graph(list_of_edges)" -- return a graph with a given list
 of edges (see documentation of "add_edges()").

 To bypass auto-detection, prefer the more explicit "Graph(L,
 format='list_of_edges')".

  5. "Graph({1:[2,3,4],3:[4]})" -- return a graph by
 associating to each vertex the list of its neighbors.

 To bypass auto-detection, prefer the more explicit "Graph(D,
 format='dict_of_lists')".

so it seems correct, and there are alternatives if you prefer 1..8 instead
of 0..7.

Regards,
Jan

>
>


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

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

2018-04-07 Thread David Joyner
On Sat, Apr 7, 2018 at 8:52 AM, Henri Girard  wrote:

> I made this graph (meaning a fano's plane) but I have the zero outside the
> graph ?
>
> I don't understand why ? someone could explain ?
>

I don't know but

sage: edges = [(1,2), (1,3), (1,4),
: (2,3), (2,4), (2,5), (2, 6),
: (3,4), (3,5), (3,6), (3,7),
: (4,6), (4,7), (5,6), (6,7)]
sage: Gamma = Graph(edges)
sage: Gamma.show()

gives the same graph but without the 0 vertex.

> My adjacency_matrix is 8 but shouldn't be 7 ?
>
> g=Graph(7)
> edges = [(1,2), (1,3), (1,4),
> (2,3), (2,4), (2,5), (2, 6),
> (3,4), (3,5), (3,6), (3,7),
> (4,6), (4,7), (5,6), (6,7)]
> g.add_edge(1,2),g.add_edge(1,3),g.add_edge(1,4),g.add_edge(2,3),
> g.add_edge(2,4),g.add_edge(2,5),g.add_edge(2,6),g.add_edge(3,4),
> g.add_edge(3,5),g.add_edge(3,6),g.add_edge(3,7),g.add_edge(4,6),
> g.add_edge(4,7),g.add_edge(5,6),g.add_edge(6,7)
> g.show()
> g.adjacency_matrix(),g.incidence_matrix()
>
> Best
>
> Henri
>
> --
> 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 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.


Re: [sage-support] Strange behaviour for two similar functions

2013-06-07 Thread John Cremona
I think you need to read a python intro to see the difference between
mutable / immutable lists and similar.  This is a python question, not
really a Sage question.

John Cremona

On 7 June 2013 09:24, B. Zhang yangtz...@gmail.com wrote:
 Hi,

 How to explain the difference between these two similar functions ?
 Thansk.

 = Test 1 
 F = [1,2,3]
 def test1(F):
 F[0] = 0
 F[1] = 0
 F[2] = 0
 print F
 test1(F); F
 [0, 0, 0]
 [0, 0, 0]

 === Test 2 ===
 F = [1,2,3]
 def test2(F):
 F = [0,0,0]
 test2(F); F
 [0, 0, 0]
 [1, 2, 3]

 --
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sage-support] Strange behaviour for two similar functions

2013-06-07 Thread Christophe BAL
+1


2013/6/7 John Cremona john.crem...@gmail.com

 I think you need to read a python intro to see the difference between
 mutable / immutable lists and similar.  This is a python question, not
 really a Sage question.

 John Cremona

 On 7 June 2013 09:24, B. Zhang yangtz...@gmail.com wrote:
  Hi,
 
  How to explain the difference between these two similar functions ?
  Thansk.
 
  = Test 1 
  F = [1,2,3]
  def test1(F):
  F[0] = 0
  F[1] = 0
  F[2] = 0
  print F
  test1(F); F
  [0, 0, 0]
  [0, 0, 0]
 
  === Test 2 ===
  F = [1,2,3]
  def test2(F):
  F = [0,0,0]
  test2(F); F
  [0, 0, 0]
  [1, 2, 3]
 
  --
  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?hl=en.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 

 --
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sage-support] Strange results with multivariate resultants

2012-09-20 Thread Julian Rüth
* Georgi Guninski gunin...@guninski.com [2012-09-19 07:34:46 +0300]:

 According to wikipedia [1]
 the multivariate resultant or Macaulay's resultant of n homogeneous 
 polynomials in n variables is a polynomial in their coefficients that 
 vanishes when they have a common non-zero solution
 My pain is $1$ can't vanish while solutions exist.
I don't think the article talks about the multivariate resultant. Imho
the line you quote is just there to mention that there are
generalizations of resultants to the multivariate case (it says
Alternatively, More generally close to that line).

 Here is homogeneous example:
 sage: K.x1,x2,x3,x4=QQ[]
 sage: p1,p2=(x2)*(x3-x4),x2*(x3-2*x4)
 sage: p1.resultant(p2,x1)
 1
Afaik this computes the resultant of p1 and p2 as polynomials in
QQ(x2,x3,x4)[x1]. As p1 and p2 are constant, they have no common root.

 On the same example pari/gp returns 0:
I don't know anything about GP, but it seems that it doesn't like to
compute resultants when the variable is not in any of the polynomials
(or do any of the variables have a special meaning?)

? p1=(x2)*(x3-x4);p2=x2*(x3-2*x4);
? polresultant(p1,p2,x1)
%2 = 0
? p1=(y)*(z-t);p2=y*(z-2*t);
? polresultant(p1,p2,x1)
%4 = 1

julian

 On Tue, Sep 18, 2012 at 05:22:59PM +0200, Julian Rüth wrote:
  Hi,
  
  I'm not sure if I understand what is counterintuitive about the results.
  
  * Georgi Guninski gunin...@guninski.com [2012-09-18 16:55:37 +0300]:
   sage: K.x1,x2,x3=PolynomialRing(QQ)
   sage: p1=(x2-1)*(x3+2)
   sage: p2=(x2-1)*(x3+3)
   sage: p1.resultant(p2)
   1
  This is the resultant of p1 and p2 w.r.t. x1 (the first variable of K).
  
   sage: K_.x2,x3=PolynomialRing(QQ)
   sage: p1_=K_(p1)
   sage: p2_=K_(p2)
   sage: p1_.resultant(p2_)
   0
  The resultant of p1 and p2 w.r.t. x2 (the first variable of K_).
  
   sage: gp.polresultant(gp(p1),gp(p2))
   0
  I'm not entirely sure what gp.polresultant() does, but it seems it
  computes the resultant w.r.t. variable()
  
  sage: gp(p1).variable()
  x2
  
  The following is strange though:
  
  sage: gp.polresultant(p1,p2,x1)
  0 # this should be 1?
  sage: gp.polresultant(p1,p2,x2)
  0
  sage: gp.polresultant(p1,p2,x3)
  x2^2 - 2*x2 + 1
  
  Am I missing something here?
  
  julian
  
  -- 
  You received this message because you are subscribed to the Google Groups 
  sage-support group.
  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.
  Visit this group at http://groups.google.com/group/sage-support?hl=en.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sage-support group.
 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.
 Visit this group at http://groups.google.com/group/sage-support?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




Re: [sage-support] Strange results with multivariate resultants

2012-09-20 Thread luisfe


On Wednesday, September 19, 2012 6:34:52 AM UTC+2, Georgi Guninski wrote:

 Hi, 

 I may be missing something, but the resultant = 1 confuses me. 
 According to wikipedia [1] 
 the multivariate resultant or Macaulay's resultant of n homogeneous 
 polynomials in n variables is a polynomial in their coefficients that 
 vanishes when they have a common non-zero solution 


Note that this means n homogeneous polynomials in n variables, in your 
example you only have two polynomials in four variables, it is not the same 
case of Macaulay's resultant.
 

 My pain is $1$ can't vanish while solutions exist. 

 Here is homogeneous example: 
 sage: K.x1,x2,x3,x4=QQ[] 
 sage: p1,p2=(x2)*(x3-x4),x2*(x3-2*x4) 
 sage: p1.resultant(p2,x1) 
 1 

 Certainly p1 and p2 have common solutions while the res. w.r.t. 
 x1 never vanishes (got this in a real world situation). 


As said, in this case the resultant is computed in the ring QQ(x2,x3)[x1] 
and the resultant will vanish if the two (univariate) polynomials have a 
common root in the algebraic closure of QQ(x2,x3). This is the standard 
resultant of multivariate polynomials with respect to one variable.

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




Re: [sage-support] Strange results with multivariate resultants

2012-09-20 Thread luisfe


On Thursday, September 20, 2012 1:05:56 PM UTC+2, Georgi Guninski wrote:

 pari disagrees with sage and maxima agrees with it. 

 which way is it? 

 maxima session: 
 (%i12) p1:(x2)*(x3-x4);p2:x2*(x3-2*x4); 
 (%i14) resultant(p1,p2,x1); 
 (%o14) 1 


In this case, there is no evaluation of x1 in the algbebraic closure of 
QQ(x2,x3,x4) that makes both polynomials zero.
 

 (%i15) resultant(p1,p2,x2); 
 (%o15) 0


In this case, there is a common root in the algebraic closure of 
QQ(x1,x3,x4), namely x2=0

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




Re: [sage-support] Strange results with multivariate resultants

2012-09-20 Thread Dima Pasechnik


On Thursday, 20 September 2012 19:05:56 UTC+8, Georgi Guninski wrote:

 pari disagrees with sage and maxima agrees with it. 

 which way is it? 

 maxima session: 
 (%i12) p1:(x2)*(x3-x4);p2:x2*(x3-2*x4); 
 (%i14) resultant(p1,p2,x1); 
 (%o14) 1 
 (%i15) resultant(p1,p2,x2); 
 (%o15) 0 

 On Wed, Sep 19, 2012 at 07:34:46AM +0300, Georgi Guninski wrote: 
  Hi, 
  
  I may be missing something, but the resultant = 1 confuses me. 


I bet the confusion comes from the fact the Sylvester matrix in this case 
is empty.
Whether an empty matrix has determinant 0, or 1, it's a deep question :–)
Note that in the ring of empty matrices, 0 equals 1, so in this sense it's 
OK...

sage: K.x1,x2,x3,x4=QQ[] 
sage: p1,p2=(x2)*(x3-x4),x2*(x3-2*x4)
sage: p1.sylvester_matrix(p2,x1)
[]
sage: p1.sylvester_matrix(p2,x1).det()
1


 

  According to wikipedia [1] 
  the multivariate resultant or Macaulay's resultant of n homogeneous 
 polynomials in n variables is a polynomial in their coefficients that 
 vanishes when they have a common non-zero solution 
  My pain is $1$ can't vanish while solutions exist. 
  
  Here is homogeneous example: 
  sage: K.x1,x2,x3,x4=QQ[] 
  sage: p1,p2=(x2)*(x3-x4),x2*(x3-2*x4) 
  sage: p1.resultant(p2,x1) 
  1 
  
  Certainly p1 and p2 have common solutions while the res. w.r.t. 
  x1 never vanishes (got this in a real world situation). 
  
  On the same example pari/gp returns 0: 
  ? p1=(x2)*(x3-x4);p2=x2*(x3-2*x4);polresultant(p1,p2,x1) 
  %5 = 0 
  
  
  [1]: 
  http://en.wikipedia.org/w/index.php?title=Resultantoldid=511538674 
  
  


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




Re: [sage-support] Strange results with multivariate resultants

2012-09-20 Thread Georgi Guninski
Thanks all for the replies.

Pari devs acknowledged their bug and fixed it in trunk here:

http://pari.math.u-bordeaux.fr/archives/pari-dev-1209/msg00034.html


On Thu, Sep 20, 2012 at 09:45:14AM -0700, Dima Pasechnik wrote:
 
 
 On Thursday, 20 September 2012 19:05:56 UTC+8, Georgi Guninski wrote:
 
  pari disagrees with sage and maxima agrees with it. 
 
  which way is it? 
 
  maxima session: 
  (%i12) p1:(x2)*(x3-x4);p2:x2*(x3-2*x4); 
  (%i14) resultant(p1,p2,x1); 
  (%o14) 1 
  (%i15) resultant(p1,p2,x2); 
  (%o15) 0 
 
  On Wed, Sep 19, 2012 at 07:34:46AM +0300, Georgi Guninski wrote: 
   Hi, 
   
   I may be missing something, but the resultant = 1 confuses me. 
 
 
 I bet the confusion comes from the fact the Sylvester matrix in this case 
 is empty.
 Whether an empty matrix has determinant 0, or 1, it's a deep question :–)
 Note that in the ring of empty matrices, 0 equals 1, so in this sense it's 
 OK...
 
 sage: K.x1,x2,x3,x4=QQ[] 
 sage: p1,p2=(x2)*(x3-x4),x2*(x3-2*x4)
 sage: p1.sylvester_matrix(p2,x1)
 []
 sage: p1.sylvester_matrix(p2,x1).det()
 1
 
 
  
 
   According to wikipedia [1] 
   the multivariate resultant or Macaulay's resultant of n homogeneous 
  polynomials in n variables is a polynomial in their coefficients that 
  vanishes when they have a common non-zero solution 
   My pain is $1$ can't vanish while solutions exist. 
   
   Here is homogeneous example: 
   sage: K.x1,x2,x3,x4=QQ[] 
   sage: p1,p2=(x2)*(x3-x4),x2*(x3-2*x4) 
   sage: p1.resultant(p2,x1) 
   1 
   
   Certainly p1 and p2 have common solutions while the res. w.r.t. 
   x1 never vanishes (got this in a real world situation). 
   
   On the same example pari/gp returns 0: 
   ? p1=(x2)*(x3-x4);p2=x2*(x3-2*x4);polresultant(p1,p2,x1) 
   %5 = 0 
   
   
   [1]: 
   http://en.wikipedia.org/w/index.php?title=Resultantoldid=511538674 
   
   
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sage-support group.
 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.
 Visit this group at http://groups.google.com/group/sage-support?hl=en.
 
 

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




Re: [sage-support] Strange results with multivariate resultants

2012-09-18 Thread Julian Rüth
Hi,

I'm not sure if I understand what is counterintuitive about the results.

* Georgi Guninski gunin...@guninski.com [2012-09-18 16:55:37 +0300]:
 sage: K.x1,x2,x3=PolynomialRing(QQ)
 sage: p1=(x2-1)*(x3+2)
 sage: p2=(x2-1)*(x3+3)
 sage: p1.resultant(p2)
 1
This is the resultant of p1 and p2 w.r.t. x1 (the first variable of K).

 sage: K_.x2,x3=PolynomialRing(QQ)
 sage: p1_=K_(p1)
 sage: p2_=K_(p2)
 sage: p1_.resultant(p2_)
 0
The resultant of p1 and p2 w.r.t. x2 (the first variable of K_).

 sage: gp.polresultant(gp(p1),gp(p2))
 0
I'm not entirely sure what gp.polresultant() does, but it seems it
computes the resultant w.r.t. variable()

sage: gp(p1).variable()
x2

The following is strange though:

sage: gp.polresultant(p1,p2,x1)
0 # this should be 1?
sage: gp.polresultant(p1,p2,x2)
0
sage: gp.polresultant(p1,p2,x3)
x2^2 - 2*x2 + 1

Am I missing something here?

julian

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




Re: [sage-support] Strange (non-)substitution of variables whose name is not equal to their representation

2010-07-07 Thread Mike Hansen
On Wed, Jul 7, 2010 at 1:49 PM, David Sanders dpsand...@gmail.com wrote:
 I now want to substitute eps=1, so I do

 a.subs(eps = 1)

 but the response is still 3*epsilon !

This is due to the way Python functions work.  Basically, doing

a.subs(eps=1)

is the same as doing

a.subs(**{'eps': 1})

When you use keyword arguments, the function gets the string 'eps'
rather than the var eps.  So, it tries to look for a variable named
'eps' which it doesn't find.  When you pass in the dictionary
explicitly:

a.subs({eps: 1})

the key is the actual variable object rather than a string so it knows
to do the right thing.

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


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


Re: [sage-support] strange n()

2010-04-11 Thread bb

Mike Hansen schrieb:

On Sat, Apr 10, 2010 at 3:37 AM, bb bblo...@arcor.de wrote:
  

sage: n(sqrt(2.), digits=40)
1.414213562373095145474621858738828450441
sage: n(sqrt(2), digits=40)
1.414213562373095048801688724209698078570
sage:



If you wanted this to be more like Maxima, the appropriate thing to do
would some something like:

sage: RealNumber = RealField(137)
sage: sqrt(2.0)
1.414213562373095048801688724209698078570
sage: sqrt(2).n(digits=40)
1.414213562373095048801688724209698078570

  

Sage is missing the errror forwarding of Mathematica.



Yes, Sage does not have a numerical type that does Mathematica's
significance arithmetic.  An interesting thread about the merits and
demerits of significance arithmetic is
http://sci.tech-archive.net/Archive/sci.math.symbolic/2008-03/msg00014.html
.

One could do a little work to get Sage's interval arithmetic to do
something similar.

--Mike

  
Tnx for helping. I did some more experimentation. I dont want to bother 
you, but if you have some time and some pation I would be thankfull for 
one more explanation. Your tip works as expected, but if I use the 
method n() I still get 53 bit of significant bits??? (see last 
expression of the snippet.)


I argue, that the parameter of n() is set elsewhere in another Variable 
than RealNumber?


sage: RealNumber = RealField(137)
sage: sqrt(2.)
1.414213562373095048801688724209698078570
sage: _.prec()
137
sage: 
sqrt(2.000)

1.414213562373095048801688724209698078570
sage: _.prec()
137
sage: 
n(sqrt(2.000), 
digits=60)

1.41421356237309504880168872420969807856967336610324780267484
sage: _.prec()
203
sage: 
n(sqrt(2.000))

1.41421356237310
sage: _.prec()
53
sage:

Regards BB

--
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 unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-11 Thread Mike Hansen
On Sun, Apr 11, 2010 at 10:01 AM, bb bblo...@arcor.de wrote:
 Tnx for helping. I did some more experimentation. I dont want to bother you,
 but if you have some time and some pation I would be thankfull for one more
 explanation. Your tip works as expected, but if I use the method n() I still
 get 53 bit of significant bits??? (see last expression of the snippet.)

 I argue, that the parameter of n() is set elsewhere in another Variable than
 RealNumber?

Yes, in the code for n, we have the following:

if prec is None:
if digits is None:
prec = 53
else:
prec = int((digits+1) * 3.32192) + 1

so it just defaults to 53 if nothing is passed in.  The RealNumber =
RealField(137) just changes the precision for floating point literals
entered on the command line.

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

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-11 Thread bb

Mike Hansen schrieb:

On Sun, Apr 11, 2010 at 10:01 AM, bb bblo...@arcor.de wrote:
  

Tnx for helping. I did some more experimentation. I dont want to bother you,
but if you have some time and some pation I would be thankfull for one more
explanation. Your tip works as expected, but if I use the method n() I still
get 53 bit of significant bits??? (see last expression of the snippet.)

I argue, that the parameter of n() is set elsewhere in another Variable than
RealNumber?



Yes, in the code for n, we have the following:

if prec is None:
if digits is None:
prec = 53
else:
prec = int((digits+1) * 3.32192) + 1

so it just defaults to 53 if nothing is passed in.  The RealNumber =
RealField(137) just changes the precision for floating point literals
entered on the command line.

--Mike

  

Tnx for clearing that n()-question!

In an earlier posting (I am always thankful for any help!) you wrote:
One could do a little work to get Sage's interval arithmetic to do
something similar. Would be an interesting experiment.

I found an internet page about that topic concerning MPFR from 2/5/2006:
http://www.ma.utexas.edu/users/kschalm/mpfr-in-sage.html
(MPFR seems to be very broadly used by different Progs under GNU Lesser 
GPL. Added is a list of related software.)


There are used some Sage-examples with a strange line-numbering with 
underscores? May be that is an outdated Sage-Version? Actual versions do 
not do any line numbering.


I did not find any evidence that MPFR or MAPM is included in Sage? I do 
not understand if MPFR is compiled with Sage in this examples on that 
page? I cannot find any evidence that MPFR is loaded?


In an extension of the floating point issue I am actually interested in: 
I found a list of libs to support floating point arithmetics that are 
not in the list of included libs to Sage. I found some examples to 
include tools with a CLI via http in the documentatin. I did not find 
hints how to include C/C++ or other language libs to Sage? (To clear 
that statement: The fact I could not find it does not mean it is not 
documented in some place!)


Again - please ignore my boring question if you feel bothered - I can 
understand that! With yor response you opened a door for floting point 
questions.


Tnx anyway - regards BB




--
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 unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-11 Thread Mike Hansen
On Sun, Apr 11, 2010 at 12:47 PM, bb bblo...@arcor.de wrote:
 In an earlier posting (I am always thankful for any help!) you wrote:
 One could do a little work to get Sage's interval arithmetic to do
 something similar. Would be an interesting experiment.

Here's a brief example

sage: RIF
Real Interval Field with 53 bits of precision
sage: R = RealIntervalField(200); R
Real Interval Field with 200 bits of precision
sage: f = RIF(pi) + 0.5; f
3.641592653589794?
sage: g = R(f); g
3.641592653589794?
sage: g.parent()
Real Interval Field with 200 bits of precision

Even when you increase the precision, it doesn't print out more digits
since it knows the upper and lower bounds.  However, this does not
currently play nice with the .n() stuff.


 I found an internet page about that topic concerning MPFR from 2/5/2006:
 http://www.ma.utexas.edu/users/kschalm/mpfr-in-sage.html
 (MPFR seems to be very broadly used by different Progs under GNU Lesser GPL.
 Added is a list of related software.)

 There are used some Sage-examples with a strange line-numbering with
 underscores? May be that is an outdated Sage-Version? Actual versions do not
 do any line numbering.

This page is indeed quite outdated.


 I did not find any evidence that MPFR or MAPM is included in Sage? I do not
 understand if MPFR is compiled with Sage in this examples on that page? I
 cannot find any evidence that MPFR is loaded?

MPFR is included in Sage by default.  Sage's RealNumber class is a
wrapper around an MPFR object.  Any high-precision floating point
arithmetic in Sage uses MPFR.

 In an extension of the floating point issue I am actually interested in: I
 found a list of libs to support floating point arithmetics that are not in
 the list of included libs to Sage. I found some examples to include tools
 with a CLI via http in the documentatin. I did not find hints how to include
 C/C++ or other language libs to Sage? (To clear that statement: The fact I
 could not find it does not mean it is not documented in some place!)

If you want to interface with other C/C++ libraries, the easiest way
to do so is using Cython [1].  There are also lots of examples in the
Sage library; for example,
$SAGE_ROOT/devel/sage/sage/rings/real_mpfr.pyx

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

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread Mike Hansen
On Sat, Apr 10, 2010 at 1:02 AM, bb bblo...@arcor.de wrote:
 Is there any explanation?

Could you be more specific in your question?  Everything there looks
normal to me.  n(pi, 20) means to compute using 20 bits of precision.

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

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread Alex Ghitza
On Sat, 10 Apr 2010 01:08:12 -0700, Mike Hansen mhan...@gmail.com wrote:
 On Sat, Apr 10, 2010 at 1:02 AM, bb bblo...@arcor.de wrote:
  Is there any explanation?
 
 Could you be more specific in your question?  Everything there looks
 normal to me.  n(pi, 20) means to compute using 20 bits of precision.

... which you can figure out from the first two lines of the docstring
for n, by typing n? at the Sage prompt :).


Best,
Alex


-- 
Alex Ghitza -- http://aghitza.org/
Lecturer in Mathematics -- The University of Melbourne -- Australia

-- 
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 unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread bb

Mike Hansen schrieb:

On Sat, Apr 10, 2010 at 1:02 AM, bb bblo...@arcor.de wrote:
  

Is there any explanation?



Could you be more specific in your question?  Everything there looks
normal to me.  n(pi, 20) means to compute using 20 bits of precision.

--Mike

  

Ok, I see - the argument defines the number of bits and not of digits!

In any other CAS (I know) that parameter describes the number of digits 
displayed. I. e .


Maxima:
(%i2) fpprec: 40;
(%o2) 40
(%i3) bfloat(sqrt(2.));
(%o3) 1.41421356237309504880168872420969807857b0
(%i4) bfloat(sqrt(2));
(%o4) 1.41421356237309504880168872420969807857b0
(%i4)

That are 40 digits (with decimal point)

Mathematica:

N[sqrt[2], 40]
1.41421356237309504880168872420969807857
delivers 40 decimal places including the decimal point.
N[sqrt[2.], 40]
1.414213562373095
(that is because Mathematica assumes a 18 bit machine precision in the 
number 2.0 and cuts off questionable digits of precision)


Sage works a bit different from the main stream with the definition of 
the number of digits. So one should not wonder about my misinterpretation!

But thanks for helping! Now I understand the difference:

sage: n(sqrt(2.), digits=40)
1.414213562373095145474621858738828450441
sage: n(sqrt(2), digits=40)
1.414213562373095048801688724209698078570
sage:

Sage is missing the errror forwarding of Mathematica.

sage: n(sqrt(2.000), digits=40)
1.414213562373095145474621858738828450441
sage: n(sqrt(2.000), digits=40)
1.414213562373095048804445654500039353252
sage: n(sqrt(2.000), digits=40)
1.414213562373095048801688724209698078570
sage: n(sqrt(2.000), digits=41)
1.4142135623730950488016887242096980785697
sage:

So one has an assortet collection and a rich choice of different 
numbers. Where I find the calculation philosophie of maxima not too bad!


Regards BB




--
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 unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread Mike Hansen
On Sat, Apr 10, 2010 at 3:37 AM, bb bblo...@arcor.de wrote:
 sage: n(sqrt(2.), digits=40)
 1.414213562373095145474621858738828450441
 sage: n(sqrt(2), digits=40)
 1.414213562373095048801688724209698078570
 sage:

If you wanted this to be more like Maxima, the appropriate thing to do
would some something like:

sage: RealNumber = RealField(137)
sage: sqrt(2.0)
1.414213562373095048801688724209698078570
sage: sqrt(2).n(digits=40)
1.414213562373095048801688724209698078570


 Sage is missing the errror forwarding of Mathematica.

Yes, Sage does not have a numerical type that does Mathematica's
significance arithmetic.  An interesting thread about the merits and
demerits of significance arithmetic is
http://sci.tech-archive.net/Archive/sci.math.symbolic/2008-03/msg00014.html
.

One could do a little work to get Sage's interval arithmetic to do
something similar.

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

To unsubscribe, reply using remove me as the subject.