[sage-support] Plotting gamma function

2008-03-07 Thread Jim Clark

Hi all,

I'm a SAGE newbie, (but I have experience with python). In the sage  
reference manual is the example:

P = plot(cos, -5, 5, thickness=5, rgbcolor=(0.5,1,0.5))
P   # show it

which works just fine, but if I replace "cos" with "gamma":

P = plot(gamma, -5, 5, thickness=5, rgbcolor=(0.5,1,0.5))
P   # show it

I get:

Exception (click to the left for traceback):P   # show it
...
TypeError: 'float' object is unsubscriptable


Why can't I plot the gamma function???

Thanks for any light you shine on this,
Jim Clark

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



[sage-support] Re: clearing the denominator of a rational polynomial

2008-03-07 Thread David

Thank you Justin and Carl.  Martin Albrecht came up with a solution:

sage: Z.numerator().reduce(I2)
0

David



On Mar 6, 6:32 pm, Carl Witty <[EMAIL PROTECTED]> wrote:
> On Mar 6, 11:20 am, David <[EMAIL PROTECTED]> wrote:
>
> > I am trying to use the reduce() command on a rational pollynomial.  I
> > first clear the denominator by multiplying by the denominator but when
> > I use reduce() I get an error.  When I print out the polynomial it is
> > no longer rational but SAGE doesn't like it.  I would appriciate any
> > advice.  Below is an example script with ouput.  Thank you.
>
> The resulting polynomial does not print as rational, but Sage still
> considers it to be a rational polynomial with denominator 1.  (You can
> see this by printing parent(Z).)
>
> The general principle for this sort of situation in Sage is that you
> should be able to get the polynomial you want by treating your ring as
> a function and calling your rational polynomial; that is, I would
> expect R1(Z) to give you your polynomial.  Unfortunately, it doesn't;
> I've reported this as a bug here:http://sagetrac.org/sage_trac/ticket/2411
>
> Instead, there's a somewhat ugly workaround you can use: R1(str(Z))
> converts your polynomial to a string, then parses it again, giving you
> a polynomial in the correct ring.  And R1(str(Z)).reduce(I2) returns
> 0.
>
>
>
>
>
> > Untitled
> > system:sage
>
> > {{{id=0|
> > R1 = PolynomialRing(RationalField(),9,
> > ["x0","x1","x2","y0","y1","y2","a0","a1","a2"], "lex")
> > x0,x1,x2,y0,y1,y2,a0,a1,a2=R1.gens()
> > X=[
> > x0*y0 - x2*y1 + x1*y2,
> > a2*y0 + a1*y1 - a0*y2,
> > a1*x0 - a0*x1 - a2*x2
> > ]
> > I=R1.ideal(X)
> > I2 = I.groebner_basis()
> > print X[2].reduce(I2)
> > Y=X[2]/a1
> > Z=a1*Y
> > print Z
> > print Z.reduce(I2)
> > ///
>
> > 0
>
> > -x1*a0 + x0*a1 - x2*a2
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File "/home/notebook/sage_notebook/worksheets/admin/61/code/3.py",
> > line 17, in 
> >     exec compile(ur'print Z.reduce(I2)' + '\n', '', 'single')
> >   File "/usr/local/sage/data/extcode/sage/", line 1, in 
>
> > TypeError: reduce() takes exactly 1 argument (2 given)
>
> > }}}
>
> > {{{id=1|
>
> > }}}
>
> Carl- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: MAC PC configuration problem.

2008-03-07 Thread Jason Grout

Yi Qiang wrote:
> The problem is that the notebook is never launched to bound to a 
> specific interface. Could you please file a trac# against this?
> 
> The specific issue is that in twistedconf.tac, we start the server like so:
> 
> strports.service('tls:8000:privateKey=/Users/yqiang/.sage/notebook/private.pem:certKey=/Users/yqiang/.sage/notebook/public.pem',
>  
> factory)
> 
> It should read something like
> 
> strports.service('tls:8000:interface=127.0.0.1:privateKey=/Users/yqiang/.sage/notebook/private.pem:certKey=/Users/yqiang/.sage/notebook/public.pem',
>  
> factory)
> 
> to only listen on localhost.
> 
> Someone more familiar with the notebook should probably write the patch, 
> since the behavior of this should depend on what the user specifies when 
> launching the notebook.
> 
> Cheers,
> Yi


Yi and William,

I just posted a patch up at http://trac.sagemath.org/sage_trac/ticket/2423

Could one of you review it?  It seems to solve the problem for me and 
allows notebook(address=whatever) to work as expected as well.

Jason


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



[sage-support] Re: Set question

2008-03-07 Thread David Joyner

On Fri, Mar 7, 2008 at 10:57 AM, William Stein <[EMAIL PROTECTED]> wrote:
>
>  On Fri, Mar 7, 2008 at 7:35 AM, David Joyner <[EMAIL PROTECTED]> wrote:
>  >
>  >  Hi:
>  >  Is there a reason why Set only applies to hashable elements?
>
>  Set is implemented using the Python language's builtin set type, which
>  in turn requires that elements by hashable.

Since SAGE's uniq also required the elements to be hashable, I wonder
if anyone things that the above routine should replace it?


>
>
>  >  It is faster than
>  >  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
>  >  at removing duplicates from a list (which is what I need) but does not
>  >  apply, for example, to lists of matrices:
>
>  FYI -- If you make the matrices immutable then you can hash them.

Thanks.

>
>
>  >
>  >
>  >  sage: MS = MatrixSpace(GF(7),2,2)
>  >  sage: A = MS.identity_matrix()
>  >  sage: B = 2*A
>  >  sage: L = [A,A,B]
>  >  sage: Set(L)
>  >  
> ---
>  >   Traceback (most recent call 
> last)
>  >
>  >  /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/ in ()
>  >
>  >  
> /home/wdj/wdj/sagefiles/sage-2.10.3.rc2/local/lib/python2.5/site-packages/sage/sets/set.py
>  >  in Set(X)
>  >  78 raise TypeError, "Element has no defined underlying set"
>  >  79 elif isinstance(X, (list, tuple, set, frozenset)):
>  >  ---> 80 return Set_object_enumerated(frozenset(X))
>  >  81 try:
>  >  82 if X.is_finite():
>  >
>  >  /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_modn_dense.pyx in
>  >  sage.matrix.matrix_modn_dense.Matrix_modn_dense.__hash__()
>  >
>  >  /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_dense.pyx in
>  >  sage.matrix.matrix_dense.Matrix_dense._hash()
>  >
>  >  : mutable matrices are unhashable
>  >
>  >
>  >  - David Joyner
>  >
>  >  >
>  >
>
>
>
>  --
>  William Stein
>  Associate Professor of Mathematics
>  University of Washington
>  http://wstein.org
>
>  >
>

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



[sage-support] Re: Set question

2008-03-07 Thread William Stein

On Fri, Mar 7, 2008 at 7:35 AM, David Joyner <[EMAIL PROTECTED]> wrote:
>
>  Hi:
>  Is there a reason why Set only applies to hashable elements?

Set is implemented using the Python language's builtin set type, which
in turn requires that elements by hashable.

>  It is faster than
>  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
>  at removing duplicates from a list (which is what I need) but does not
>  apply, for example, to lists of matrices:

FYI -- If you make the matrices immutable then you can hash them.

>
>
>  sage: MS = MatrixSpace(GF(7),2,2)
>  sage: A = MS.identity_matrix()
>  sage: B = 2*A
>  sage: L = [A,A,B]
>  sage: Set(L)
>  ---
>   Traceback (most recent call last)
>
>  /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/ in ()
>
>  
> /home/wdj/wdj/sagefiles/sage-2.10.3.rc2/local/lib/python2.5/site-packages/sage/sets/set.py
>  in Set(X)
>  78 raise TypeError, "Element has no defined underlying set"
>  79 elif isinstance(X, (list, tuple, set, frozenset)):
>  ---> 80 return Set_object_enumerated(frozenset(X))
>  81 try:
>  82 if X.is_finite():
>
>  /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_modn_dense.pyx in
>  sage.matrix.matrix_modn_dense.Matrix_modn_dense.__hash__()
>
>  /mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_dense.pyx in
>  sage.matrix.matrix_dense.Matrix_dense._hash()
>
>  : mutable matrices are unhashable
>
>
>  - David Joyner
>
>  >
>



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

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



[sage-support] Set question

2008-03-07 Thread David Joyner

Hi:
Is there a reason why Set only applies to hashable elements?
It is faster than
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
at removing duplicates from a list (which is what I need) but does not
apply, for example, to lists of matrices:


sage: MS = MatrixSpace(GF(7),2,2)
sage: A = MS.identity_matrix()
sage: B = 2*A
sage: L = [A,A,B]
sage: Set(L)
---
 Traceback (most recent call last)

/mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/ in ()

/home/wdj/wdj/sagefiles/sage-2.10.3.rc2/local/lib/python2.5/site-packages/sage/sets/set.py
in Set(X)
 78 raise TypeError, "Element has no defined underlying set"
 79 elif isinstance(X, (list, tuple, set, frozenset)):
---> 80 return Set_object_enumerated(frozenset(X))
 81 try:
 82 if X.is_finite():

/mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_modn_dense.pyx in
sage.matrix.matrix_modn_dense.Matrix_modn_dense.__hash__()

/mnt/drive_hda1/sagefiles/sage-2.10.3.rc2/matrix_dense.pyx in
sage.matrix.matrix_dense.Matrix_dense._hash()

: mutable matrices are unhashable


- David Joyner

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



[sage-support] Re: Bug converting real numbers to integers?

2008-03-07 Thread Carl Witty

On Mar 7, 12:42 am, Nikos Apostolakis <[EMAIL PROTECTED]> wrote:
> Carl Witty <[EMAIL PROTECTED]> writes:
> > Didier mentioned floor(); if you actually want to round, instead of
> > taking the floor, then this works (even though it's a little verbose):
> > sage: ZZ((num*100).round())
>
> I thought that `floor' is what I was looking for: I want to get the
> integer that appears in screen as output to the command
>
> sage: RealField(12).random_element(1,9.99)*100
>
> as an element of ZZ.  However this doesn't seem to work in all
> cases!  For example:
>
> ,
> | sage: foo = RealField(16).random_element(20,99.99)*100
> | sage: foo
> | 2036.
> | sage: floor(foo)
> | 2035
> | sage: foo.round()
> | 2036.
> `

You can see the exact true value of a floating-point number with
foo.exact_rational().

For printing, the code determines a number of digits which is
(deliberately) slightly too low to represent floating-point numbers of
that precision; then it rounds to the nearest printable value.  For
example,  1.0/49*49 prints as 1.00, even though the
floating-point number you get is actually
9007199254740991/9007199254740992 or
0.99988897769753748434595763683319091796875 .

You can see the number printed with enough digits to distinguish
adjacent floating-point numbers like this:
sage: (1.0/49*49).str(truncate=False)
'0.99989'

floor gives the greatest integer which is <= the given floating-point
number:
sage: floor(1.0/49*49)
0
round gives the integer which is closest to the given floating-point
number:
sage: round(1.0/49*49)
1.00
except that it gives that integer in the form of a floating-point
number.  (IMHO, this is a bug, which I've reported here:
http://trac.sagemath.org/sage_trac/ticket/2421)

This rounding-off when printing floating-point numbers was supposed to
reduce confusion for people who don't care about floating-point
numbers, and who would be surprised (and would complain) if 1.0/49*49
did not print as 1.0.  Unfortunately, as in your case, this comes at
the cost of increasing confusion for people who do care about floating-
point numbers; I don't know how to decide if the tradeoff is worth it.

Carl

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



[sage-support] Re: Bug converting real numbers to integers?

2008-03-07 Thread Nikos Apostolakis

Carl Witty <[EMAIL PROTECTED]> writes:

> On Mar 6, 2:48 pm, Nikos Apostolakis <[EMAIL PROTECTED]> wrote:
>> > I can confirm this. I think numbers are rounded up when they are
>> > printed, which leads to confusion:
>> > {{{
>> > sage: num = RealField(12).random_element(1,9.99)*100
>> > sage: num
>> >  406.
>> > }}}
>>
>> > But num is actually ~405.725! :
>> > {{{
>> > sage: num -406
>> >  -0.375
>>
>> > }}}
>>
>> > And so ZZ(num) will fail, as it should, since num ~ 405.725.
>>
>> Hm, I see! This behavior is very confusing. Wouldn't you say it *is*
>> a bug?
>
> I'm not sure which part you're talking about: are you complaining that
> this particular number prints as an integer even though it isn't
> exactly, or that coercion to ZZ fails?
>

I guees the former.  I found it confusing that *all* numbers that
one gets by doing 

sage: RealField(12).random_element(1,9.99)*100

appear to be integers, while in fact are not.  I would expect that
if something looks like an integer then it should be able to be
coerced to be an integer.  So, I guess, I am complaining for the
latter as well :).


> For the former, I disclaim responsibility. :)  The decision to round-
> off floating-point numbers was made before I started working on Sage;
> I don't really care one way or the other.
>
> For the latter: I think that coercion to ZZ should fail.  Regardless
> of how the number prints, it really is not an integer.
>
>> Anyway to get what I expected to get I can do something like
>>
>> sage: Integer(sage_eval(str(num))*100)
>> 318
>>
>> but it seems like an ugly hack.  Is there another way?
>
> Didier mentioned floor(); if you actually want to round, instead of
> taking the floor, then this works (even though it's a little verbose):
> sage: ZZ((num*100).round())

I thought that `floor' is what I was looking for: I want to get the
integer that appears in screen as output to the command 

sage: RealField(12).random_element(1,9.99)*100  

as an element of ZZ.  However this doesn't seem to work in all
cases!  For example:

,
| sage: foo = RealField(16).random_element(20,99.99)*100
| sage: foo
| 2036.
| sage: floor(foo)
| 2035
| sage: foo.round()
| 2036.
`

I feel very confused.  Perhaps I should get some sleep :(

Nikos


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



[sage-support] Re: Error related with singular, gap and resultant

2008-03-07 Thread Simon King

Dear William,

On Mar 5, 11:51 pm, "William Stein" <[EMAIL PROTECTED]> wrote:

> Regarding whether or not your problem would be a bug,
> *anything* that's not obviously supposed to mess up the interfaces
> that does mess them up (without a big error appearing) is a bug,
> and I want to fix it.   I'm really glad if you can reliably replicate the
> problem, since that makes it vastly easier to fix.

Since there exist at least two computers on which the error can be
reproduced, i made it a ticket #2419; i thought it wouldn't hurt.
Of course i understand that it is hardly fixable if no developer is
able to reproduce it.

Yours
 Simon

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