{{{id=96|
v = [plot(sin(x^(1+1/k)), (x,1,10)) for k in [1..5]]
///
}}}
{{{id=98|
A = animate(v); A
///
Animation with 5 frames
}}}
{{{id=97|
A.show(delay=50)
///
}}}
{{{id=104|
.show(viewer='canvas3d') # william cauchois
///
}}}
{{{id=103|
graph_editor(graphs.ButterflyGraph())
///
File: /sagenb/flask/sage-4.6.2/local/lib/python2.6/site-packages/sage/functions/other.py
Type: <class ‘sage.functions.other.Function_factorial’>
Definition: factorial(*args, coerce=True, hold=False, dont_call_method_on_arg=False)
Docstring:
Returns the factorial of n.
INPUT:
- n - an integer, or symbolic expression
- algorithm - string (default: ‘gmp’)
- 'gmp' - use the GMP C-library factorial function
- 'pari' - use PARI’s factorial function This option has no effect if n is a symbolic expression.
OUTPUT: an integer or symbolic expression
EXAMPLES:
sage: x = var('x') sage: factorial(0) 1 sage: factorial(4) 24 sage: factorial(10) 3628800 sage: factorial(6) == 6*5*4*3*2 True sage: f = factorial(x + factorial(x)); f factorial(x + factorial(x)) sage: f(x=3) 362880 sage: factorial(x)^2 factorial(x)^2To prevent automatic evaluation use the hold argument:
sage: factorial(5,hold=True) factorial(5)To then evaluate again, we currently must use Maxima via sage.symbolic.expression.Expression.simplify():
sage: factorial(5,hold=True).simplify() 120We can also give input other than nonnegative integers. For other nonnegative numbers, the gamma() function is used:
sage: factorial(1/2) 1/2*sqrt(pi) sage: factorial(3/4) gamma(7/4) sage: factorial(2.3) 2.68343738195577But negative input always fails:
sage: factorial(-32) Traceback (most recent call last): ... ValueError: factorial -- self = (-32) must be nonnegativeTESTS:
We verify that we can convert this function to Maxima and bring it back into Sage.:
sage: z = var('z') sage: factorial._maxima_init_() 'factorial' sage: maxima(factorial(z)) z! sage: _.sage() factorial(z) sage: k = var('k') sage: factorial(k) factorial(k) sage: factorial(3.14) 7.173269190187...Test latex typesetting:
sage: latex(factorial(x)) x! sage: latex(factorial(2*x)) \left(2 \, x\right)! sage: latex(factorial(sin(x))) \sin\left(x\right)! sage: latex(factorial(sqrt(x+1))) \left(\sqrt{x + 1}\right)! sage: latex(factorial(sqrt(x))) \sqrt{x}! sage: latex(factorial(x^(2/3))) \left(x^{\frac{2}{3}}\right)! sage: latex(factorial) { factorial}
File: /sagenb/flask/sage-4.6.2/local/lib/python2.6/site-packages/sage/functions/other.py
Source Code (starting at line 942):
class Function_factorial(GinacFunction):
def __init__(self):
r"""
Returns the factorial of `n`.
INPUT:
- ``n`` - an integer, or symbolic expression
- ``algorithm`` - string (default: 'gmp')
- ``'gmp'`` - use the GMP C-library factorial
function
- ``'pari'`` - use PARI's factorial function This
option has no effect if n is a symbolic expression.
OUTPUT: an integer or symbolic expression
EXAMPLES::
sage: x = var('x')
sage: factorial(0)
1
sage: factorial(4)
24
sage: factorial(10)
3628800
sage: factorial(6) == 6*5*4*3*2
True
sage: f = factorial(x + factorial(x)); f
factorial(x + factorial(x))
sage: f(x=3)
362880
sage: factorial(x)^2
factorial(x)^2
To prevent automatic evaluation use the ``hold`` argument::
sage: factorial(5,hold=True)
factorial(5)
To then evaluate again, we currently must use Maxima via
:meth:`sage.symbolic.expression.Expression.simplify`::
sage: factorial(5,hold=True).simplify()
120
We can also give input other than nonnegative integers. For
other nonnegative numbers, the :func:`gamma` function is used::
sage: factorial(1/2)
1/2*sqrt(pi)
sage: factorial(3/4)
gamma(7/4)
sage: factorial(2.3)
2.68343738195577
But negative input always fails::
sage: factorial(-32)
Traceback (most recent call last):
...
ValueError: factorial -- self = (-32) must be nonnegative
TESTS:
We verify that we can convert this function to Maxima and
bring it back into Sage.::
sage: z = var('z')
sage: factorial._maxima_init_()
'factorial'
sage: maxima(factorial(z))
z!
sage: _.sage()
factorial(z)
sage: k = var('k')
sage: factorial(k)
factorial(k)
sage: factorial(3.14)
7.173269190187...
Test latex typesetting::
sage: latex(factorial(x))
x!
sage: latex(factorial(2*x))
\left(2 \, x\right)!
sage: latex(factorial(sin(x)))
\sin\left(x\right)!
sage: latex(factorial(sqrt(x+1)))
\left(\sqrt{x + 1}\right)!
sage: latex(factorial(sqrt(x)))
\sqrt{x}!
sage: latex(factorial(x^(2/3)))
\left(x^{\frac{2}{3}}\right)!
sage: latex(factorial)
{\rm factorial}
"""
GinacFunction.__init__(self, "factorial", latex_name='{\rm factorial}',
conversions=dict(maxima='factorial', mathematica='Factorial'))
The next example illustrates how to use self and several "dunder" (=double underscore) methods:
{{{id=65| class Number: def __init__(derreck, x): # called when Number is instantiated derreck.x = x def __repr__(self): # defines how Number prints return "** The Number %s ** !!!"%self.x def __add__(self, right): # defines how "+" works return Number(self.x + right.x) /// }}} {{{id=108| Number ///