Why doesn't this get loaded into the sympy namespace along with all the other factorial frunctions? I don't understand how the __init__
file is working in this module.
git pull https://github.com/smichr/sympy subfact
Or view, comment on, or merge it at:
https://github.com/sympy/sympy/pull/1692
—
Reply to this email directly or view it on GitHub.
In sympy/functions/combinatorial/factorials.py:
> @@ -161,6 +163,64 @@ class MultiFactorial(CombinatorialFunction): > pass > > > +class subfactorial(CombinatorialFunction): > + """The subfactorial counts the derangements of n items and is > + defined for non-negative integers as:: > + > + , > + | 1 for n = 0 > + !n = | 0 for n = 1
This should be a {
or <
(and by the way, pprint(Piecewise, use_unicode=False)
looks worse than this).
You need to add it to sympy/functions/__init__.py
. I also don't understand the purpose of the sympy/functions/combinatorial/__init__.py
function.
Add the standard links to Wikipedia and/or MathWorld (or any other good reference that you know of). The Wikipedia article seems to be pretty good.
In sympy/functions/combinatorial/factorials.py:
> + @classmethod > + def eval(cls, arg): > + try: > + arg = as_int(arg) > + if arg < 0: > + raise ValueError > + return C.Integer(cls._eval(arg)) > + except ValueError: > + if sympify(arg).is_Number: > + raise ValueError("argument must be a nonnegative integer") > + > + def _sympystr(self, p): > + if self.args[0].is_Atom: > + return "!%s" % p.doprint(self.args[0]) > + else: > + return "!(%s)" % p.doprint(self.args[0])
This needs other printers too, but I wonder if you can somehow just set the function name to !
somewhere, and have all printers automatically work.
In sympy/functions/combinatorial/factorials.py:
> + @classmethod > + def eval(cls, arg): > + try: > + arg = as_int(arg) > + if arg < 0: > + raise ValueError > + return C.Integer(cls._eval(arg)) > + except ValueError: > + if sympify(arg).is_Number: > + raise ValueError("argument must be a nonnegative integer") > + > + def _sympystr(self, p): > + if self.args[0].is_Atom: > + return "!%s" % p.doprint(self.args[0]) > + else: > + return "!(%s)" % p.doprint(self.args[0])
Except it doesn't use parentheses for atom arguments. So you still have to special case it. So please add the other printers. You need pretty print (ascii and unicode, should be the same) and LaTeX (and any others that might be useful).
SymPy Bot Summary: Failed after merging smichr/subfact (afec347) into master (14452a4).
@smichr: Please fix the test failures.
Python 2.5.0-final-0: fail
Python 2.6.6-final-0: fail
Python 2.7.2-final-0: fail
Python 2.6.8-final-0: fail
Python 2.7.3-final-0: fail
PyPy 2.0.0-beta-1; 2.7.3-final-42: fail
Python 3.2.2-final-0: fail
Python 3.3.0-final-0: fail
Python 3.2.3-final-0: fail
Python 3.3.0-final-0: fail
Python 3.3.0-final-0: fail
**Sphinx 1.1.3:** pass
SymPy Bot Summary: Failed after merging smichr/subfact (797dd34) into master (501534b).
@smichr: Please fix the test failures.
Python 2.5.0-final-0: fail
Python 2.6.6-final-0: fail
Python 2.7.2-final-0: fail
Python 2.6.8-final-0: fail
Python 2.7.3-final-0: fail
PyPy 2.0.0-beta-1; 2.7.3-final-42: fail
Python 3.2.2-final-0: fail
Python 3.3.0-final-0: fail
Python 3.2.3-final-0: fail
Python 3.3.0-final-0: fail
Python 3.3.0-final-0: fail
**Sphinx 1.1.3:** pass
—
Reply to this email directly or view it on GitHub.
@asmeurer , printers and reference has been added.
In sympy/functions/combinatorial/factorials.py:
> class factorial2(CombinatorialFunction): > """The double factorial n!!, not to be confused with (n!)! > > The double factorial is defined for integers >= -1 as:: > > - , > - | n*(n - 2)*(n - 4)* ... * 1 for n odd > - n!! = -| n*(n - 2)*(n - 4)* ... * 2 for n even > - | 1 for n = 0, -1 > - ' > + { n*(n - 2)*(n - 4)* ... * 1 for n odd > + n!! = { n*(n - 2)*(n - 4)* ... * 2 for n even
That's not quite what I meant. I was thinking more
,
|
{
|
'
Really, though, none of them look very good. But we really should figure out what looks the best, and change the Piecewise ASCII pretty printer to use it.
I modified the docstring representation of the piecewise definition.
SymPy Bot Summary: Passed after merging smichr/subfact (dda5947) into master (d503614).
PyPy 2.0.0-beta-1; 2.7.3-final-42: pass
Python 2.7.2-final-0: pass
Python 3.2.1-final-0: pass
Sphinx 1.1.3: pass
Docs build command: make clean && make html-errors && make latex && cd _build/latex && xelatex sympy-*.tex
This looks fine.
Thanks for looking this over. It's in.
Merged #1692.