Re: m480 sage questions...

1 view
Skip to first unread message

William Stein

unread,
May 27, 2009, 12:00:31 PM5/27/09
to Daniel Shane Delamare, 480-uw09
On Tue, May 26, 2009 at 4:02 PM, Daniel Shane Delamare
<del...@u.washington.edu> wrote:
>
>
>
> Hello Prof Stein,
> Where is the actual programming code for this sloane sequence?

This is it:

def _eval(self, n):
"""
EXAMPLES::

sage: [sloane.A000142._eval(n) for n in range(10)]
[1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
"""
return arith.factorial(n)


> I only see
> the stuff that shows up when i do sloane.A000142(<tab>
> Can you make this code to print "hello world" when the sequence is called in
> sage as an example?

Put

print "hello world"

right before

return arith.factorial(n) in the code above.

> Also, I'm going to implement a sequence that uses factorials, and I remember
> that I'm supposed to load something up before I use it... what is it?

You can just use arith.factorial(n), like is done in the above
example. You can use
anything from Sage by doing

from sage.all import name_of_function

in the body of your function.

William

> Thank you,
> Daniel
>
>
>
> class A000142(SloaneSequence):
>    def __init__(self):
>        r"""
>        Factorial numbers: `n! = 1 \cdot 2 \cdot 3 \cdots n`
>
>        Order of symmetric group `S_n`, number of permutations of
>        `n` letters.
>
>        INPUT:
>
>
>        -  ``n`` - non negative integer
>
>
>        OUTPUT:
>
>
>        -  ``integer`` - function value
>
>
>        EXAMPLES::
>
>            sage: a = sloane.A000142;a
>            Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group
> S_n, $
>            sage: a(0)
>            1
>            sage: a(8)
>            40320
>            sage: a(40)
>            815915283247897734345611269596115894272000000000
>            sage: a.list(9)
>            [1, 1, 2, 6, 24, 120, 720, 5040, 40320]
>
>        AUTHORS:
>
>        - Jaap Spies (2007-01-12)
>        """
>        SloaneSequence.__init__(self, offset=0)
>
>    def _repr_(self):
>        """
>        EXAMPLES::
>
>            sage: sloane.A000142._repr_()
>            'Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group
> S_n,$
>        """
>        return "Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric
> group S$
>
>    def _eval(self, n):
>        """
>        EXAMPLES::
>            sage: a(8)
>            40320
>            sage: a(40)
>            815915283247897734345611269596115894272000000000
>            sage: a.list(9)
>            [1, 1, 2, 6, 24, 120, 720, 5040, 40320]
>
>        AUTHORS:
>
>        - Jaap Spies (2007-01-12)
>        """
>        SloaneSequence.__init__(self, offset=0)
>
>    def _repr_(self):
>        """
>        EXAMPLES::
>
>            sage: sloane.A000142._repr_()
>            'Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group
> S_n,$
>        """
>        return "Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric
> group S$
>
>    def _eval(self, n):
>        """
>        EXAMPLES::
>
>            sage: [sloane.A000142._eval(n) for n in range(10)]
>            [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
>        """
>        return arith.factorial(n)
>
>
>
>
>

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

Reply all
Reply to author
Forward
0 new messages