From a38e25ac8202829a48ba4d9e899c4297ee51d0b7 Mon Sep 17 00:00:00 2001
From: "Vladimir V. Kisil" <V.Kisilv@leeds.ac.uk>
Date: Tue, 7 Feb 2023 22:34:55 +0000
Subject: [PATCH 2/2] Extend applicability of binomial evaluation.

When binomial(n,k) has both n<0 and k<0 but n-k>=0 we can use
the symmetry relation binomial(n,k) = binomial(n, n-k).
Suggested by Marko Riedel <riedelmo@mathematik.uni-stuttgart.de>.

Signed-off-by: Vladimir V. Kisil <V.Kisilv@leeds.ac.uk>
---
 ginac/numeric.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp
index c643d041..98524c51 100644
--- a/ginac/numeric.cpp
+++ b/ginac/numeric.cpp
@@ -2149,7 +2149,10 @@ const numeric binomial(const numeric &n, const numeric &k)
 			else
 				return *_num0_p;
 		} else {
-			return _num_1_p->power(k)*binomial(k-n-(*_num1_p),k);
+			numeric k1 = k;
+			if ( (not k.is_nonneg_integer()) && (n-k).is_nonneg_integer())
+				k1 = n-k;
+			return _num_1_p->power(k1)*binomial(k1-n-(*_num1_p),k1);
 		}
 	}
 	
-- 
2.39.1

