I was implementing Catalan Numbers in numbers.py, and just wanted to see if
anyone thought this was a good idea to implement, considering Catalan
Numbers can be easily computed through binomial coefficients (though it can
come up a lot in combinatorics). I have attached a patch.


-- Srinivas

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

diff --git a/sympy/functions/combinatorial/numbers.py b/sympy/functions/combinatorial/numbers.py
index fd974b4..26d0706 100644
--- a/sympy/functions/combinatorial/numbers.py
+++ b/sympy/functions/combinatorial/numbers.py
@@ -507,3 +507,52 @@ def _eval_evalf(self, prec):
             res = mp.eulernum(m)
             mp.prec = oprec
             return Expr._from_mpmath(res, prec)
+
+
+#----------------------------------------------------------------------------#
+#                                                                            #
+#                           Catalan numbers                                  #
+#                                                                            #
+#----------------------------------------------------------------------------#
+
+class catalan(Function):
+    r"""
+    Catalan numbers
+
+    Usage
+    =====
+        catalan(n) gives the n-th Catalan number, c(n)
+
+    Examples
+    ========
+        >>> from sympy import Symbol, euler
+        >>> [catalan(n) for n in range(10)]
+        [1, 1, 2, 5, 14, 42, 132, 429, 1430]
+
+    Mathematical description
+    ========================
+        The Catalan numbers are given by
+
+                  
+                              
+                    1     / 2n \ 
+         c(n) =  -------  |    |
+                  n + 1   \  n / 
+                        
+
+    References and further reading
+    ==============================
+        * http://en.wikipedia.org/wiki/Catalan_numbers
+        * http://mathworld.wolfram.com/CatalanNumber.html
+        * http://geometer.org/mathcircles/catalan.pdf
+    """
+
+    nargs = 1
+
+    @classmethod
+    def eval(cls, n, evaluate=True):
+        if not evaluate:
+            return
+        if n.is_Integer and n.is_nonnegative:
+	       return binomial(2n,n) // (n+1)
+

Reply via email to