From d5e26ee76dc8cbae13f4ab6a825b3f2ca4f4d308 Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Tue, 25 Sep 2012 17:52:27 -0700
Subject: [PATCH] math.extras: Faster gini. Leaving this as a separate patch
 for comparison.

---
 extra/math/extras/extras.factor | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/extra/math/extras/extras.factor b/extra/math/extras/extras.factor
index 005a924453..550484dd89 100644
--- a/extra/math/extras/extras.factor
+++ b/extra/math/extras/extras.factor
@@ -4,7 +4,7 @@
 USING: combinators.short-circuit grouping kernel locals math
 math.combinatorics math.constants math.functions math.order
 math.primes math.ranges math.statistics math.vectors memoize
-sequences sequences.extras sorting assocs ;
+sequences sequences.extras sorting assocs fry ;
 
 IN: math.extras
 
@@ -160,9 +160,11 @@ PRIVATE>
 :: (gini) ( seq -- x )
     seq natural-sort :> sorted
     seq length :> len
-    len [1,b] sorted zip 0 [ * + ] assoc-reduce :> sum0
-    2 sum0 * sorted sum len * / :> G
-    G 1 - 1 len / - ; inline
+    0 0 sorted [
+        '[ _ + ] dip dupd +
+    ] each  :> ( a b )
+    b len a * / :> B
+    1 len recip + 2 B * - ;
 
 PRIVATE>