The double factorial combinatorial function:
n!! == n * (n-2) * (n-4) * ... * ({1|2}) with 0!! == (-1)!! == 1.
INPUT:
EXAMPLES:
sage: from sage.symbolic.pynac import doublefactorial
sage: doublefactorial(-1)
1
sage: doublefactorial(0)
1
sage: doublefactorial(1)
1
sage: doublefactorial(5)
15
sage: doublefactorial(20)
3715891200
sage: prod( [20,18,..,2] )
3715891200
Return the overall size of the Pynac function registry which corresponds to the last serial value plus one.
EXAMPLE:
sage: from sage.symbolic.pynac import get_fn_serial
sage: from sage.symbolic.function import get_sfunction_from_serial
sage: get_fn_serial() > 125
True
sage: print get_sfunction_from_serial(get_fn_serial())
None
sage: get_sfunction_from_serial(get_fn_serial() - 1) is not None
True
Number of C++ level functions defined by GiNaC. (Defined mainly for testing.)
EXAMPLES:
sage: sage.symbolic.pynac.get_ginac_serial() >= 40
True
Initializes the function pointer table in Pynac. This must be called before Pynac is used; otherwise, there will be segfaults.
Initialize the numeric I object in pynac. We use the generator of QQ(i).
EXAMPLES:
sage: sage.symbolic.pynac.init_pynac_I()
sage: type(sage.symbolic.pynac.I)
<type 'sage.symbolic.expression.Expression'>
sage: type(sage.symbolic.pynac.I.pyobject())
<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'>
TESTS:
Check that trac ticket #10064 is fixed:
sage: y = I*I*x / x # so y is the expression -1
sage: y.is_positive()
False
sage: z = -x / x
sage: z.is_positive()
False
sage: bool(z == y)
True
EXAMPLES:
sage: from sage.symbolic.pynac import paramset_from_Expression
sage: f = function('f')
sage: paramset_from_Expression(f(x).diff(x))
[0L] # 32-bit
[0] # 64-bit
Wrapper function to test py_atan2.
TESTS:
sage: from sage.symbolic.pynac import py_atan2_for_doctests
sage: py_atan2_for_doctests(0., 1.)
1.57079632679490
This function is used to test py_denom().
EXAMPLES:
sage: from sage.symbolic.pynac import py_denom_for_doctests
sage: py_denom_for_doctests(2/3)
3
This function tests py_eval_infinity.
This function tests py_eval_neg_infinity.
This function tests py_eval_unsigned_infinity.
This function tests py_exp.
EXAMPLES:
sage: from sage.symbolic.pynac import py_exp_for_doctests
sage: py_exp_for_doctests(CC(2))
7.38905609893065
This function is a python wrapper around py_factorial(). This wrapper is needed when we override the eval() method for GiNaC’s factorial function in sage.functions.other.Function_factorial.
TESTS:
sage: from sage.symbolic.pynac import py_factorial_py
sage: py_factorial_py(3)
6
This function is for testing py_float.
EXAMPLES:
sage: from sage.symbolic.pynac import py_float_for_doctests
sage: py_float_for_doctests(pi, {'parent':RealField(80)})
3.1415926535897932384626
Used for doctesting py_imag.
TESTS:
sage: from sage.symbolic.pynac import py_imag_for_doctests
sage: py_imag_for_doctests(I)
1
Returns True if pynac should treat this object as an element of \(\ZZ(i)\).
TESTS:
sage: from sage.symbolic.pynac import py_is_cinteger_for_doctest
sage: py_is_cinteger_for_doctest(1)
True
sage: py_is_cinteger_for_doctest(long(-3))
True
sage: py_is_cinteger_for_doctest(I.pyobject())
True
sage: py_is_cinteger_for_doctest(I.pyobject() - 3)
True
sage: py_is_cinteger_for_doctest(I.pyobject() + 1/2)
False
Returns True if pynac should treat this object as an element of \(\QQ(i)\).
TESTS:
sage: from sage.symbolic.pynac import py_is_crational_for_doctest
sage: py_is_crational_for_doctest(1)
True
sage: py_is_crational_for_doctest(-2r)
True
sage: py_is_crational_for_doctest(1.5)
False
sage: py_is_crational_for_doctest(I.pyobject())
True
sage: py_is_crational_for_doctest(I.pyobject()+1/2)
True
Used internally for doctesting purposes.
TESTS:
sage: sage.symbolic.pynac.py_is_integer_for_doctests(1r)
True
sage: sage.symbolic.pynac.py_is_integer_for_doctests(1/3)
False
sage: sage.symbolic.pynac.py_is_integer_for_doctests(2)
True
Used internally for writing doctests for certain cdef’d functions.
EXAMPLES:
sage: from sage.symbolic.pynac import py_latex_fderivative_for_doctests as py_latex_fderivative, get_ginac_serial, get_fn_serial
sage: var('x,y,z')
(x, y, z)
sage: from sage.symbolic.function import get_sfunction_from_serial
sage: foo = function('foo', nargs=2)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_latex_fderivative(i, (0, 1, 0, 1), (x, y^z))
D[0, 1, 0, 1]\left({\rm foo}\right)\left(x, y^{z}\right)
Test latex_name:
sage: foo = function('foo', nargs=2, latex_name=r'\mathrm{bar}')
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_latex_fderivative(i, (0, 1, 0, 1), (x, y^z))
D[0, 1, 0, 1]\left(\mathrm{bar}\right)\left(x, y^{z}\right)
Test custom func:
sage: def my_print(self, *args): return "func_with_args(" + ', '.join(map(repr, args)) +')'
sage: foo = function('foo', nargs=2, print_latex_func=my_print)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_latex_fderivative(i, (0, 1, 0, 1), (x, y^z))
D[0, 1, 0, 1]func_with_args(x, y^z)
Return a string with the latex representation of the symbolic function specified by the given id applied to args.
See documentation of py_print_function_pystring for more information.
EXAMPLES:
sage: from sage.symbolic.pynac import py_latex_function_pystring, get_ginac_serial, get_fn_serial
sage: from sage.symbolic.function import get_sfunction_from_serial
sage: var('x,y,z')
(x, y, z)
sage: foo = function('foo', nargs=2)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_latex_function_pystring(i, (x,y^z))
'{\\rm foo}\\left(x, y^{z}\\right)'
sage: py_latex_function_pystring(i, (x,y^z), True)
'\\left({\\rm foo}\\right)\\left(x, y^{z}\\right)'
sage: py_latex_function_pystring(i, (int(0),x))
'{\\rm foo}\\left(0, x\\right)'
Test latex_name:
sage: foo = function('foo', nargs=2, latex_name=r'\mathrm{bar}')
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_latex_function_pystring(i, (x,y^z))
'\\mathrm{bar}\\left(x, y^{z}\\right)'
Test custom func:
sage: def my_print(self, *args): return "my args are: " + ', '.join(map(repr, args))
sage: foo = function('foo', nargs=2, print_latex_func=my_print)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_latex_function_pystring(i, (x,y^z))
'my args are: x, y^z'
Internal function used so we can doctest a certain cdef’d method.
EXAMPLES:
sage: sage.symbolic.pynac.py_latex_variable_for_doctests('x')
x
sage: sage.symbolic.pynac.py_latex_variable_for_doctests('sigma')
\sigma
This function tests py_lgamma.
EXAMPLES:
sage: from sage.symbolic.pynac import py_lgamma_for_doctests
sage: py_lgamma_for_doctests(CC(I))
-0.650923199301856 - 1.87243664726243*I
This function is a python wrapper so py_psi2 can be tested. The real tests are in the docstring for py_psi2.
EXAMPLES:
sage: from sage.symbolic.pynac import py_li2_for_doctests
sage: py_li2_for_doctests(-1.1)
-0.890838090262283
This function is a python wrapper so py_li can be tested. The real tests are in the docstring for py_li.
EXAMPLES:
sage: from sage.symbolic.pynac import py_li_for_doctests
sage: py_li_for_doctests(0,2,float)
0.000000000000000
This function tests py_log.
EXAMPLES:
sage: from sage.symbolic.pynac import py_log_for_doctests
sage: py_log_for_doctests(CC(e))
1.00000000000000
This function is a python wrapper so py_mod can be tested. The real tests are in the docstring for py_mod.
EXAMPLES:
sage: from sage.symbolic.pynac import py_mod_for_doctests
sage: py_mod_for_doctests(5, 2)
1
This function is used to test py_numer().
EXAMPLES:
sage: from sage.symbolic.pynac import py_numer_for_doctests
sage: py_numer_for_doctests(2/3)
2
Used for testing a cdef’d function.
EXAMPLES:
sage: from sage.symbolic.pynac import py_print_fderivative_for_doctests as py_print_fderivative, get_ginac_serial, get_fn_serial
sage: var('x,y,z')
(x, y, z)
sage: from sage.symbolic.function import get_sfunction_from_serial
sage: foo = function('foo', nargs=2)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_print_fderivative(i, (0, 1, 0, 1), (x, y^z))
D[0, 1, 0, 1](foo)(x, y^z)
Test custom print function:
sage: def my_print(self, *args): return "func_with_args(" + ', '.join(map(repr, args)) +')'
sage: foo = function('foo', nargs=2, print_func=my_print)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_print_fderivative(i, (0, 1, 0, 1), (x, y^z))
D[0, 1, 0, 1]func_with_args(x, y^z)
Return a string with the representation of the symbolic function specified by the given id applied to args.
INPUT:
EXAMPLES:
sage: from sage.symbolic.pynac import py_print_function_pystring, get_ginac_serial, get_fn_serial
sage: from sage.symbolic.function import get_sfunction_from_serial
sage: var('x,y,z')
(x, y, z)
sage: foo = function('foo', nargs=2)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_print_function_pystring(i, (x,y))
'foo(x, y)'
sage: py_print_function_pystring(i, (x,y), True)
'(foo)(x, y)'
sage: def my_print(self, *args): return "my args are: " + ', '.join(map(repr, args))
sage: foo = function('foo', nargs=2, print_func=my_print)
sage: for i in range(get_ginac_serial(), get_fn_serial()):
... if get_sfunction_from_serial(i) == foo: break
sage: get_sfunction_from_serial(i) == foo
True
sage: py_print_function_pystring(i, (x,y))
'my args are: x, y'
This function is a python wrapper so py_psi2 can be tested. The real tests are in the docstring for py_psi2.
EXAMPLES:
sage: from sage.symbolic.pynac import py_psi2_for_doctests
sage: py_psi2_for_doctests(1, 2)
0.644934066848226
This function is a python wrapper so py_psi can be tested. The real tests are in the docstring for py_psi.
EXAMPLES:
sage: from sage.symbolic.pynac import py_psi_for_doctests
sage: py_psi_for_doctests(2)
0.422784335098467
Used for doctesting py_real.
TESTS:
sage: from sage.symbolic.pynac import py_real_for_doctests
sage: py_real_for_doctests(I)
0
This function is for testing py_tgamma().
TESTS:
sage: from sage.symbolic.pynac import py_tgamma_for_doctests
sage: py_tgamma_for_doctests(3)
2
This function is for testing py_zeta().
EXAMPLES:
sage: from sage.symbolic.pynac import py_zeta_for_doctests
sage: py_zeta_for_doctests(CC.0)
0.00330022368532410 - 0.418155449141322*I
Add an object to the symbol table, along with how to convert it to other systems such as Maxima, Mathematica, etc. This table is used to convert from other systems back to Sage.
INPUTS:
\(obj\) – a symbolic object or function.
- \(conversions\) – a dictionary of conversions, where the keys
are the names of interfaces (e.g., ‘maxima’), and the values are the string representation of obj in that system.
EXAMPLES:
sage: sage.symbolic.pynac.register_symbol(SR(5),{'maxima':'five'})
sage: SR(maxima_calculus('five'))
5
The Binomial coefficients. It computes the binomial coefficients. For integer n and k and positive n this is the number of ways of choosing k objects from n distinct objects. If n is negative, the formula binomial(n,k) == (-1)^k*binomial(k-n-1,k) is used to compute the result.
INPUT:
OUTPUT:
integer
EXAMPLES:
sage: import sage.symbolic.pynac
sage: sage.symbolic.pynac.test_binomial(5,2)
10
sage: sage.symbolic.pynac.test_binomial(-5,3)
-35
sage: -sage.symbolic.pynac.test_binomial(3-(-5)-1, 3)
-35
EXAMPLES:
sage: from sage.symbolic.pynac import unpack_operands
sage: t = SR._force_pyobject((1, 2, x, x+1, x+2))
sage: unpack_operands(t)
(1, 2, x, x + 1, x + 2)
sage: type(unpack_operands(t))
<type 'tuple'>
sage: map(type, unpack_operands(t))
[<type 'sage.rings.integer.Integer'>, <type 'sage.rings.integer.Integer'>, <type 'sage.symbolic.expression.Expression'>, <type 'sage.symbolic.expression.Expression'>, <type 'sage.symbolic.expression.Expression'>]
sage: u = SR._force_pyobject((t, x^2))
sage: unpack_operands(u)
((1, 2, x, x + 1, x + 2), x^2)
sage: type(unpack_operands(u)[0])
<type 'tuple'>