diff --git a/ats-src/number-theory-ffi.dats b/ats-src/number-theory-ffi.dats
--- a/ats-src/number-theory-ffi.dats
+++ b/ats-src/number-theory-ffi.dats
@@ -11,8 +11,15 @@
 fun count_divisors_ats { k : nat | k >= 2 } (int(k)) : int =
   "mac#"
 
+extern
+fun totient_sum_ats { n : nat | n > 0 } : int(n) -> int =
+  "mac#"
+
 implement count_divisors_ats (n) =
   count_divisors(n)
 
 implement totient_ats (n) =
   totient(n)
+
+implement totient_sum_ats (n) =
+  totient_sum(n)
diff --git a/ats-src/number-theory.dats b/ats-src/number-theory.dats
--- a/ats-src/number-theory.dats
+++ b/ats-src/number-theory.dats
@@ -12,13 +12,11 @@
 
 typedef Odd = [ n : nat ] int(2 * n+1)
 
-extern
-praxi int_not_gt {n : nat}{ m : nat | n <= m } (i : int(n), j : int(m)) : [ n + 1 <= m ] void
-
 // m | n
 fn divides(m : int, n : int) :<> bool =
   n % m = 0
 
+// fn totient_sum(n: int) : int =
 fn count_divisors { k : nat | k >= 1 } (n : int(k)) :<> int =
   let
     fun loop {k : nat}{ m : nat | m > 0 && k >= m } .<k-m>. (n : int(k), acc : int(m)) :<> int =
@@ -33,23 +31,37 @@
     loop(n, 1)
   end
 
-fn totient { k : nat | k >= 2 } (n : int(k)) : int =
-  let
-    fnx loop { k : nat | k >= 2 }{ m : nat | m > 0 && k >= m } .<k-m>. (i : int(m), n : int(k)) : int =
-      if i > n then
-        if is_prime(n) then
-          n - 1
-        else
-          n
-      else
+// Euler's totient function.
+fn totient { k : nat | k >= 1 } (n : int(k)) : int =
+  case+ n of
+    | 1 => 1
+    | n =>> 
+      begin
         let
-          prval _ = int_not_gt(i, n)
+          fnx loop { k : nat | k >= 2 }{ m : nat | m > 0 && k >= m } .<k-m>. (i : int(m), n : int(k)) : int =
+            if i >= n then
+              if is_prime(n) then
+                n - 1
+              else
+                n
+            else
+              if n % i = 0 && is_prime(i) && i != n then
+                (loop(i + 1, n) / i) * (i - 1)
+              else
+                loop(i + 1, n)
         in
-          if n % i = 0 && is_prime(i) && i != n then
-            (loop(i + 1, n) / i) * (i - 1)
-          else
-            loop(i + 1, n)
+          loop(1, n)
         end
+      end
+
+// TODO gcd
+fun totient_sum { k : nat | k >= 1 } (n : int(k)) : int =
+  let
+    fnx loop { n : nat | n >= 1 }{ m : nat | m >= n } .<m-n>. (i : int(n), bound : int(m)) : int =
+      if i < bound then
+        totient(i) + loop(i + 1, bound)
+      else
+        totient(i)
   in
     loop(1, n)
   end
diff --git a/bench/Bench.hs b/bench/Bench.hs
--- a/bench/Bench.hs
+++ b/bench/Bench.hs
@@ -36,4 +36,8 @@
                       [ bench "tau" $ nf tau 3018
                       , bench "hsTau" $ nf hsTau 3018
                       ]
+                , bgroup "totientSum"
+                      [ bench "totientSum" $ nf totientSum 1280
+                      , bench "hsTotientSum" $ nf hsTotientSum 1280
+                      ]
                 ]
diff --git a/cbits/combinatorics.c b/cbits/combinatorics.c
--- a/cbits/combinatorics.c
+++ b/cbits/combinatorics.c
@@ -1,7 +1,7 @@
 /*
 **
 ** The C code is generated by [ATS/Postiats-0-3-8]
-** The starting compilation time is: 2018-1-1: 22h:13m
+** The starting compilation time is: 2018-1-2:  0h:11m
 **
 */
 
diff --git a/cbits/number-theory.c b/cbits/number-theory.c
--- a/cbits/number-theory.c
+++ b/cbits/number-theory.c
@@ -1,7 +1,7 @@
 /*
 **
 ** The C code is generated by [ATS/Postiats-0-3-8]
-** The starting compilation time is: 2018-1-1: 23h:18m
+** The starting compilation time is: 2018-1-2:  0h:11m
 **
 */
 
@@ -447,7 +447,7 @@
 
 ATSstatic()
 atstkind_t0ype(atstype_bool)
-ATSLIB_056_prelude__gt_g1int_int__1__2(atstkind_t0ype(atstype_int), atstkind_t0ype(atstype_int)) ;
+ATSLIB_056_prelude__gte_g1int_int__30__2(atstkind_t0ype(atstype_int), atstkind_t0ype(atstype_int)) ;
 
 ATSstatic()
 atstkind_t0ype(atstype_bool)
@@ -466,16 +466,28 @@
 ATSLIB_056_prelude__neq_g1int_int__40__1(atstkind_t0ype(atstype_int), atstkind_t0ype(atstype_int)) ;
 
 ATSstatic()
+atstkind_t0ype(atstype_int)
+totient_sum_44(atstkind_t0ype(atstype_int)) ;
+
+ATSstatic()
+atstkind_t0ype(atstype_int)
+loop_45(atstkind_t0ype(atstype_int), atstkind_t0ype(atstype_int)) ;
+
+ATSstatic()
 atstkind_t0ype(atstype_bool)
-is_even_44(atstkind_t0ype(atstype_int)) ;
+ATSLIB_056_prelude__lt_g1int_int__17__2(atstkind_t0ype(atstype_int), atstkind_t0ype(atstype_int)) ;
 
 ATSstatic()
 atstkind_t0ype(atstype_bool)
+is_even_47(atstkind_t0ype(atstype_int)) ;
+
+ATSstatic()
+atstkind_t0ype(atstype_bool)
 ATSLIB_056_prelude__eq_g0int_int__7__7(atstkind_t0ype(atstype_int), atstkind_t0ype(atstype_int)) ;
 
 ATSstatic()
 atstkind_t0ype(atstype_bool)
-is_odd_46(atstkind_t0ype(atstype_int)) ;
+is_odd_49(atstkind_t0ype(atstype_int)) ;
 
 ATSstatic()
 atstkind_t0ype(atstype_bool)
@@ -493,6 +505,12 @@
 totient_ats(atstkind_t0ype(atstype_int)) ;
 #endif // end of [QUALIFIED]
 
+#if(0)
+ATSextern()
+atstkind_t0ype(atstype_int)
+totient_sum_ats(atstkind_t0ype(atstype_int)) ;
+#endif // end of [QUALIFIED]
+
 /*
 /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/numerics.dats: 220(line=9, offs=5) -- 581(line=26, offs=10)
 */
@@ -1399,7 +1417,7 @@
 } /* end of [ATSLIB_056_prelude__eq_g0int_int__7__3] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 464(line=19, offs=4) -- 512(line=20, offs=12)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 362(line=16, offs=4) -- 410(line=17, offs=12)
 */
 /*
 local: 
@@ -1417,16 +1435,16 @@
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 464(line=19, offs=4) -- 512(line=20, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 362(line=16, offs=4) -- 410(line=17, offs=12)
 */
 ATSINSflab(__patsflab_divides_26):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 503(line=20, offs=3) -- 508(line=20, offs=8)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 401(line=17, offs=3) -- 406(line=17, offs=8)
 */
 ATSINSmove(tmp46, atspre_g0int_mod_int(arg1, arg0)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 503(line=20, offs=3) -- 512(line=20, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 401(line=17, offs=3) -- 410(line=17, offs=12)
 */
 ATSINSmove(tmpret43, ATSLIB_056_prelude__eq_g0int_int__7__4(tmp46, ATSPMVi0nt(0))) ;
 
@@ -1476,7 +1494,7 @@
 } /* end of [ATSLIB_056_prelude__eq_g0int_int__7__4] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 517(line=22, offs=4) -- 847(line=34, offs=6)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 449(line=20, offs=4) -- 779(line=32, offs=6)
 */
 /*
 local: 
@@ -1493,11 +1511,11 @@
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 517(line=22, offs=4) -- 847(line=34, offs=6)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 449(line=20, offs=4) -- 779(line=32, offs=6)
 */
 ATSINSflab(__patsflab_count_divisors_28):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 578(line=23, offs=3) -- 847(line=34, offs=6)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 510(line=21, offs=3) -- 779(line=32, offs=6)
 */
 /*
 letpush(beg)
@@ -1507,12 +1525,12 @@
 */
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 831(line=33, offs=5) -- 841(line=33, offs=15)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 763(line=31, offs=5) -- 773(line=31, offs=15)
 */
 ATSINSmove(tmpret47, loop_29(arg0, ATSPMVi0nt(1))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 578(line=23, offs=3) -- 847(line=34, offs=6)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 510(line=21, offs=3) -- 779(line=32, offs=6)
 */
 /*
 INSletpop()
@@ -1522,7 +1540,7 @@
 } /* end of [count_divisors_28] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 590(line=24, offs=9) -- 821(line=31, offs=27)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 522(line=22, offs=9) -- 753(line=29, offs=27)
 */
 /*
 local: loop_29$0(level=1)
@@ -1547,64 +1565,64 @@
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 590(line=24, offs=9) -- 821(line=31, offs=27)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 522(line=22, offs=9) -- 753(line=29, offs=27)
 */
 ATSINSflab(__patsflab_loop_29):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 688(line=25, offs=10) -- 696(line=25, offs=18)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 620(line=23, offs=10) -- 628(line=23, offs=18)
 */
 ATSINSmove(tmp49, ATSLIB_056_prelude__gte_g1int_int__30__1(arg1, arg0)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 685(line=25, offs=7) -- 821(line=31, offs=27)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 617(line=23, offs=7) -- 753(line=29, offs=27)
 */
 ATSif(
 tmp49
 ) ATSthen() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 710(line=26, offs=9) -- 711(line=26, offs=10)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 642(line=24, offs=9) -- 643(line=24, offs=10)
 */
 ATSINSmove(tmpret48, ATSPMVi0nt(1)) ;
 } ATSelse() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 734(line=28, offs=12) -- 741(line=28, offs=19)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 666(line=26, offs=12) -- 673(line=26, offs=19)
 */
 ATSINSmove(tmp57, atspre_g0int_mod_int(arg0, arg1)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 734(line=28, offs=12) -- 745(line=28, offs=23)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 666(line=26, offs=12) -- 677(line=26, offs=23)
 */
 ATSINSmove(tmp54, ATSLIB_056_prelude__eq_g0int_int__7__5(tmp57, ATSPMVi0nt(0))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 731(line=28, offs=9) -- 821(line=31, offs=27)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 663(line=26, offs=9) -- 753(line=29, offs=27)
 */
 ATSif(
 tmp54
 ) ATSthen() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 773(line=29, offs=23) -- 780(line=29, offs=30)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 705(line=27, offs=23) -- 712(line=27, offs=30)
 */
 ATSINSmove(tmp59, atspre_g1int_add_int(arg1, ATSPMVi0nt(1))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 765(line=29, offs=15) -- 781(line=29, offs=31)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 697(line=27, offs=15) -- 713(line=27, offs=31)
 */
 ATSINSmove(tmp58, loop_29(arg0, tmp59)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 761(line=29, offs=11) -- 781(line=29, offs=31)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 693(line=27, offs=11) -- 713(line=27, offs=31)
 */
 ATSINSmove(tmpret48, atspre_g0int_add_int(ATSPMVi0nt(1), tmp58)) ;
 
 } ATSelse() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 813(line=31, offs=19) -- 820(line=31, offs=26)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 745(line=29, offs=19) -- 752(line=29, offs=26)
 */
 ATSINSmove(tmp60, atspre_g1int_add_int(arg1, ATSPMVi0nt(1))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 805(line=31, offs=11) -- 821(line=31, offs=27)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 737(line=29, offs=11) -- 753(line=29, offs=27)
 */
 ATStailcal_beg()
 ATSINSmove_tlcal(apy0, arg0) ;
@@ -1746,7 +1764,7 @@
 } /* end of [ATSLIB_056_prelude__eq_g0int_int__7__5] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 852(line=36, offs=4) -- 1347(line=55, offs=6)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 813(line=35, offs=4) -- 1380(line=55, offs=10)
 */
 /*
 local: is_prime_15$0(level=0)
@@ -1763,13 +1781,56 @@
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 852(line=36, offs=4) -- 1347(line=55, offs=6)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 813(line=35, offs=4) -- 1380(line=55, offs=10)
 */
 ATSINSflab(__patsflab_totient_35):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 904(line=37, offs=3) -- 1347(line=55, offs=6)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 865(line=36, offs=3) -- 1380(line=55, offs=10)
 */
+ATScaseof_beg()
 /*
+** ibranchlst-beg
+*/
+ATSbranch_beg()
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 882(line=37, offs=7) -- 883(line=37, offs=8)
+*/
+ATSINSlab(__atstmplab6):
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 843(line=35, offs=34) -- 844(line=35, offs=35)
+*/
+ATSifnthen(ATSCKpat_int(arg0, ATSPMVint(1))) { ATSINSgoto(__atstmplab8) ; } ;
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 883(line=37, offs=8) -- 883(line=37, offs=8)
+*/
+ATSINSlab(__atstmplab7):
+/*
+emit_instr: loc0 = : 0(line=0, offs=0) -- 0(line=0, offs=0)
+*/
+/*
+ibranch-mbody:
+*/
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 887(line=37, offs=12) -- 888(line=37, offs=13)
+*/
+ATSINSmove(tmpret61, ATSPMVi0nt(1)) ;
+ATSbranch_end()
+
+ATSbranch_beg()
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 896(line=38, offs=8) -- 896(line=38, offs=8)
+*/
+ATSINSlab(__atstmplab8):
+/*
+emit_instr: loc0 = : 0(line=0, offs=0) -- 0(line=0, offs=0)
+*/
+/*
+ibranch-mbody:
+*/
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 922(line=40, offs=9) -- 1370(line=54, offs=12)
+*/
+/*
 letpush(beg)
 */
 /*
@@ -1777,22 +1838,29 @@
 */
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1331(line=54, offs=5) -- 1341(line=54, offs=15)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1348(line=53, offs=11) -- 1358(line=53, offs=21)
 */
 ATSINSmove(tmpret61, loop_36(ATSPMVi0nt(1), arg0)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 904(line=37, offs=3) -- 1347(line=55, offs=6)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 922(line=40, offs=9) -- 1370(line=54, offs=12)
 */
 /*
 INSletpop()
 */
+ATSbranch_end()
+
+/*
+** ibranchlst-end
+*/
+ATScaseof_end()
+
 ATSfunbody_end()
 ATSreturn(tmpret61) ;
 } /* end of [totient_35] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 916(line=38, offs=9) -- 1321(line=52, offs=12)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 940(line=41, offs=15) -- 1326(line=51, offs=31)
 */
 /*
 local: is_prime_15$0(level=0), loop_36$0(level=1)
@@ -1825,126 +1893,126 @@
 */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 916(line=38, offs=9) -- 1321(line=52, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 940(line=41, offs=15) -- 1326(line=51, offs=31)
 */
 ATSINSflab(__patsflab_loop_36):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1021(line=39, offs=10) -- 1026(line=39, offs=15)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1051(line=42, offs=16) -- 1057(line=42, offs=22)
 */
-ATSINSmove(tmp63, ATSLIB_056_prelude__gt_g1int_int__1__2(arg0, arg1)) ;
+ATSINSmove(tmp63, ATSLIB_056_prelude__gte_g1int_int__30__2(arg0, arg1)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1018(line=39, offs=7) -- 1321(line=52, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1048(line=42, offs=13) -- 1326(line=51, offs=31)
 */
 ATSif(
 tmp63
 ) ATSthen() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1043(line=40, offs=12) -- 1053(line=40, offs=22)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1080(line=43, offs=18) -- 1090(line=43, offs=28)
 */
 ATSINSmove(tmp66, is_prime_15(arg1)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1040(line=40, offs=9) -- 1100(line=43, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1077(line=43, offs=15) -- 1155(line=46, offs=18)
 */
 ATSif(
 tmp66
 ) ATSthen() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1070(line=41, offs=11) -- 1075(line=41, offs=16)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1113(line=44, offs=17) -- 1118(line=44, offs=22)
 */
 ATSINSmove(tmpret62, atspre_g1int_sub_int(arg1, ATSPMVi0nt(1))) ;
 
 } ATSelse() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1099(line=43, offs=11) -- 1100(line=43, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1154(line=46, offs=17) -- 1155(line=46, offs=18)
 */
 ATSINSmove(tmpret62, arg1) ;
 } /* ATSendif */
 } ATSelse() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSINSmove(tmp72, atspre_g0int_mod_int(arg1, arg0)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSINSmove(tmp69, ATSLIB_056_prelude__eq_g0int_int__7__6(tmp72, ATSPMVi0nt(0))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSif(
 tmp69
 ) ATSthen() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSINSmove(tmp68, is_prime_15(arg0)) ;
 
 } ATSelse() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSINSmove(tmp68, ATSPMVbool_false()) ;
 } /* ATSendif */
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSif(
 tmp68
 ) ATSthen() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSINSmove(tmp67, ATSLIB_056_prelude__neq_g1int_int__40__1(arg0, arg1)) ;
 
 } ATSelse() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1185(line=48, offs=14) -- 1219(line=48, offs=48)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1190(line=48, offs=18) -- 1224(line=48, offs=52)
 */
 ATSINSmove(tmp67, ATSPMVbool_false()) ;
 } /* ATSendif */
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1182(line=48, offs=11) -- 1309(line=51, offs=27)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1187(line=48, offs=15) -- 1326(line=51, offs=31)
 */
 ATSif(
 tmp67
 ) ATSthen() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1243(line=49, offs=19) -- 1248(line=49, offs=24)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1252(line=49, offs=23) -- 1257(line=49, offs=28)
 */
 ATSINSmove(tmp79, atspre_g1int_add_int(arg0, ATSPMVi0nt(1))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1238(line=49, offs=14) -- 1252(line=49, offs=28)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1247(line=49, offs=18) -- 1261(line=49, offs=32)
 */
 ATSINSmove(tmp78, loop_36(tmp79, arg1)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1238(line=49, offs=14) -- 1256(line=49, offs=32)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1247(line=49, offs=18) -- 1265(line=49, offs=36)
 */
 ATSINSmove(tmp77, atspre_g0int_div_int(tmp78, arg0)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1261(line=49, offs=37) -- 1266(line=49, offs=42)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1270(line=49, offs=41) -- 1275(line=49, offs=46)
 */
 ATSINSmove(tmp80, atspre_g1int_sub_int(arg0, ATSPMVi0nt(1))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1237(line=49, offs=13) -- 1267(line=49, offs=43)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1246(line=49, offs=17) -- 1276(line=49, offs=47)
 */
 ATSINSmove(tmpret62, atspre_g0int_mul_int(tmp77, tmp80)) ;
 
 } ATSelse() {
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1300(line=51, offs=18) -- 1305(line=51, offs=23)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1317(line=51, offs=22) -- 1322(line=51, offs=27)
 */
 ATSINSmove(tmp81, atspre_g1int_add_int(arg0, ATSPMVi0nt(1))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1295(line=51, offs=13) -- 1309(line=51, offs=27)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1312(line=51, offs=17) -- 1326(line=51, offs=31)
 */
 ATStailcal_beg()
 ATSINSmove_tlcal(apy0, tmp81) ;
@@ -1964,45 +2032,45 @@
 } /* end of [loop_36] */
 
 /*
-/usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats: 12679(line=659, offs=3) -- 12718(line=659, offs=42)
+/usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats: 12757(line=663, offs=3) -- 12797(line=663, offs=43)
 */
 /*
 local: 
-global: gt_g1int_int$1$2(level=2)
+global: gte_g1int_int$30$2(level=2)
 local: 
 global: 
 */
 ATSstatic()
 /*
-imparg = tk(4703)
-tmparg = S2Evar(tk(4703))
-tmpsub = Some(tk(4703) -> S2Eextkind(atstype_int))
+imparg = tk(4706)
+tmparg = S2Evar(tk(4706))
+tmpsub = Some(tk(4706) -> S2Eextkind(atstype_int))
 */
 atstkind_t0ype(atstype_bool)
-ATSLIB_056_prelude__gt_g1int_int__1__2(atstkind_t0ype(atstype_int) arg0, atstkind_t0ype(atstype_int) arg1)
+ATSLIB_056_prelude__gte_g1int_int__30__2(atstkind_t0ype(atstype_int) arg0, atstkind_t0ype(atstype_int) arg1)
 {
 /* tmpvardeclst(beg) */
-ATStmpdec(tmpret2__2, atstkind_t0ype(atstype_bool)) ;
-ATStmpdec(tmp3__2, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmpret50__2, atstkind_t0ype(atstype_bool)) ;
+ATStmpdec(tmp51__2, atstkind_t0ype(atstype_int)) ;
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12664(line=658, offs=1) -- 12718(line=659, offs=42)
+emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12741(line=662, offs=1) -- 12797(line=663, offs=43)
 */
-ATSINSflab(__patsflab_gt_g1int_int):
+ATSINSflab(__patsflab_gte_g1int_int):
 /*
-emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12705(line=659, offs=29) -- 12716(line=659, offs=40)
+emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12784(line=663, offs=30) -- 12795(line=663, offs=41)
 */
-ATSINSmove(tmp3__2, atspre_g1int2int_int_int(arg1)) ;
+ATSINSmove(tmp51__2, atspre_g1int2int_int_int(arg1)) ;
 
 /*
-emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12688(line=659, offs=12) -- 12718(line=659, offs=42)
+emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12766(line=663, offs=12) -- 12797(line=663, offs=43)
 */
-ATSINSmove(tmpret2__2, atspre_g1int_gt_int(arg0, tmp3__2)) ;
+ATSINSmove(tmpret50__2, atspre_g1int_gte_int(arg0, tmp51__2)) ;
 
 ATSfunbody_end()
-ATSreturn(tmpret2__2) ;
-} /* end of [ATSLIB_056_prelude__gt_g1int_int__1__2] */
+ATSreturn(tmpret50__2) ;
+} /* end of [ATSLIB_056_prelude__gte_g1int_int__30__2] */
 
 /*
 /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats: 12259(line=635, offs=3) -- 12298(line=635, offs=42)
@@ -2130,42 +2198,204 @@
 } /* end of [ATSLIB_056_prelude__neq_g1int_int__40__1] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1352(line=57, offs=4) -- 1391(line=58, offs=12)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1398(line=58, offs=5) -- 1676(line=67, offs=6)
 */
 /*
+local: totient_35$0(level=0)
+global: sqrt_int_12$0(level=0), is_prime_15$0(level=0), totient_35$0(level=0), totient_sum_44$0(level=0)
 local: 
-global: is_even_44$0(level=0)
+global: 
+*/
+ATSstatic()
+atstkind_t0ype(atstype_int)
+totient_sum_44(atstkind_t0ype(atstype_int) arg0)
+{
+/* tmpvardeclst(beg) */
+ATStmpdec(tmpret82, atstkind_t0ype(atstype_int)) ;
+/* tmpvardeclst(end) */
+ATSfunbody_beg()
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1398(line=58, offs=5) -- 1676(line=67, offs=6)
+*/
+ATSINSflab(__patsflab_totient_sum_44):
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1454(line=59, offs=3) -- 1676(line=67, offs=6)
+*/
+/*
+letpush(beg)
+*/
+/*
+letpush(end)
+*/
+
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1660(line=66, offs=5) -- 1670(line=66, offs=15)
+*/
+ATSINSmove(tmpret82, loop_45(ATSPMVi0nt(1), arg0)) ;
+
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1454(line=59, offs=3) -- 1676(line=67, offs=6)
+*/
+/*
+INSletpop()
+*/
+ATSfunbody_end()
+ATSreturn(tmpret82) ;
+} /* end of [totient_sum_44] */
+
+/*
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1466(line=60, offs=9) -- 1650(line=64, offs=19)
+*/
+/*
+local: totient_35$0(level=0), loop_45$0(level=1)
+global: totient_35$0(level=0), loop_45$0(level=1)
 local: 
 global: 
 */
 ATSstatic()
+atstkind_t0ype(atstype_int)
+loop_45(atstkind_t0ype(atstype_int) arg0, atstkind_t0ype(atstype_int) arg1)
+{
+/* tmpvardeclst(beg) */
+ATStmpdec(apy0, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(apy1, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmpret83, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmp84, atstkind_t0ype(atstype_bool)) ;
+ATStmpdec(tmp87, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmp88, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmp89, atstkind_t0ype(atstype_int)) ;
+/* tmpvardeclst(end) */
+/*
+emit_funent_fnxdeclst:
+*/
+ATSfunbody_beg()
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1466(line=60, offs=9) -- 1650(line=64, offs=19)
+*/
+ATSINSflab(__patsflab_loop_45):
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1566(line=61, offs=10) -- 1575(line=61, offs=19)
+*/
+ATSINSmove(tmp84, ATSLIB_056_prelude__lt_g1int_int__17__2(arg0, arg1)) ;
+
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1563(line=61, offs=7) -- 1650(line=64, offs=19)
+*/
+ATSif(
+tmp84
+) ATSthen() {
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1589(line=62, offs=9) -- 1598(line=62, offs=18)
+*/
+ATSINSmove(tmp87, totient_35(arg0)) ;
+
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1607(line=62, offs=27) -- 1612(line=62, offs=32)
+*/
+ATSINSmove(tmp89, atspre_g1int_add_int(arg0, ATSPMVi0nt(1))) ;
+
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1602(line=62, offs=22) -- 1620(line=62, offs=40)
+*/
+ATSINSmove(tmp88, loop_45(tmp89, arg1)) ;
+
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1589(line=62, offs=9) -- 1620(line=62, offs=40)
+*/
+ATSINSmove(tmpret83, atspre_g0int_add_int(tmp87, tmp88)) ;
+
+} ATSelse() {
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1640(line=64, offs=9) -- 1649(line=64, offs=18)
+*/
+ATSINSmove(tmpret83, totient_35(arg0)) ;
+
+} /* ATSendif */
+ATSfunbody_end()
+ATSreturn(tmpret83) ;
+/*
+emit_funent_fnxbodylst:
+*/
+} /* end of [loop_45] */
+
+/*
+/usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats: 12520(line=650, offs=3) -- 12559(line=650, offs=42)
+*/
+/*
+local: 
+global: lt_g1int_int$17$2(level=2)
+local: 
+global: 
+*/
+ATSstatic()
+/*
+imparg = tk(4697)
+tmparg = S2Evar(tk(4697))
+tmpsub = Some(tk(4697) -> S2Eextkind(atstype_int))
+*/
 atstkind_t0ype(atstype_bool)
-is_even_44(atstkind_t0ype(atstype_int) arg0)
+ATSLIB_056_prelude__lt_g1int_int__17__2(atstkind_t0ype(atstype_int) arg0, atstkind_t0ype(atstype_int) arg1)
 {
 /* tmpvardeclst(beg) */
-ATStmpdec(tmpret82, atstkind_t0ype(atstype_bool)) ;
-ATStmpdec(tmp85, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmpret24__2, atstkind_t0ype(atstype_bool)) ;
+ATStmpdec(tmp25__2, atstkind_t0ype(atstype_int)) ;
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1352(line=57, offs=4) -- 1391(line=58, offs=12)
+emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12505(line=649, offs=1) -- 12559(line=650, offs=42)
 */
-ATSINSflab(__patsflab_is_even_44):
+ATSINSflab(__patsflab_lt_g1int_int):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1382(line=58, offs=3) -- 1387(line=58, offs=8)
+emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12546(line=650, offs=29) -- 12557(line=650, offs=40)
 */
-ATSINSmove(tmp85, atspre_g0int_mod_int(arg0, ATSPMVi0nt(2))) ;
+ATSINSmove(tmp25__2, atspre_g1int2int_int_int(arg1)) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1382(line=58, offs=3) -- 1391(line=58, offs=12)
+emit_instr: loc0 = /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats({$PATSPRE}/DATS/integer.dats): 12529(line=650, offs=12) -- 12559(line=650, offs=42)
 */
-ATSINSmove(tmpret82, ATSLIB_056_prelude__eq_g0int_int__7__7(tmp85, ATSPMVi0nt(0))) ;
+ATSINSmove(tmpret24__2, atspre_g1int_lt_int(arg0, tmp25__2)) ;
 
 ATSfunbody_end()
-ATSreturn(tmpret82) ;
-} /* end of [is_even_44] */
+ATSreturn(tmpret24__2) ;
+} /* end of [ATSLIB_056_prelude__lt_g1int_int__17__2] */
 
 /*
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1681(line=69, offs=4) -- 1720(line=70, offs=12)
+*/
+/*
+local: 
+global: is_even_47$0(level=0)
+local: 
+global: 
+*/
+ATSstatic()
+atstkind_t0ype(atstype_bool)
+is_even_47(atstkind_t0ype(atstype_int) arg0)
+{
+/* tmpvardeclst(beg) */
+ATStmpdec(tmpret90, atstkind_t0ype(atstype_bool)) ;
+ATStmpdec(tmp93, atstkind_t0ype(atstype_int)) ;
+/* tmpvardeclst(end) */
+ATSfunbody_beg()
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1681(line=69, offs=4) -- 1720(line=70, offs=12)
+*/
+ATSINSflab(__patsflab_is_even_47):
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1711(line=70, offs=3) -- 1716(line=70, offs=8)
+*/
+ATSINSmove(tmp93, atspre_g0int_mod_int(arg0, ATSPMVi0nt(2))) ;
+
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1711(line=70, offs=3) -- 1720(line=70, offs=12)
+*/
+ATSINSmove(tmpret90, ATSLIB_056_prelude__eq_g0int_int__7__7(tmp93, ATSPMVi0nt(0))) ;
+
+ATSfunbody_end()
+ATSreturn(tmpret90) ;
+} /* end of [is_even_47] */
+
+/*
 /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats: 12259(line=635, offs=3) -- 12298(line=635, offs=42)
 */
 /*
@@ -2207,40 +2437,40 @@
 } /* end of [ATSLIB_056_prelude__eq_g0int_int__7__7] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1396(line=60, offs=4) -- 1434(line=61, offs=12)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1725(line=72, offs=4) -- 1763(line=73, offs=12)
 */
 /*
 local: 
-global: is_odd_46$0(level=0)
+global: is_odd_49$0(level=0)
 local: 
 global: 
 */
 ATSstatic()
 atstkind_t0ype(atstype_bool)
-is_odd_46(atstkind_t0ype(atstype_int) arg0)
+is_odd_49(atstkind_t0ype(atstype_int) arg0)
 {
 /* tmpvardeclst(beg) */
-ATStmpdec(tmpret86, atstkind_t0ype(atstype_bool)) ;
-ATStmpdec(tmp89, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmpret94, atstkind_t0ype(atstype_bool)) ;
+ATStmpdec(tmp97, atstkind_t0ype(atstype_int)) ;
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1396(line=60, offs=4) -- 1434(line=61, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1725(line=72, offs=4) -- 1763(line=73, offs=12)
 */
-ATSINSflab(__patsflab_is_odd_46):
+ATSINSflab(__patsflab_is_odd_49):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1425(line=61, offs=3) -- 1430(line=61, offs=8)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1754(line=73, offs=3) -- 1759(line=73, offs=8)
 */
-ATSINSmove(tmp89, atspre_g0int_mod_int(arg0, ATSPMVi0nt(2))) ;
+ATSINSmove(tmp97, atspre_g0int_mod_int(arg0, ATSPMVi0nt(2))) ;
 
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1425(line=61, offs=3) -- 1434(line=61, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory.dats: 1754(line=73, offs=3) -- 1763(line=73, offs=12)
 */
-ATSINSmove(tmpret86, ATSLIB_056_prelude__eq_g0int_int__7__8(tmp89, ATSPMVi0nt(1))) ;
+ATSINSmove(tmpret94, ATSLIB_056_prelude__eq_g0int_int__7__8(tmp97, ATSPMVi0nt(1))) ;
 
 ATSfunbody_end()
-ATSreturn(tmpret86) ;
-} /* end of [is_odd_46] */
+ATSreturn(tmpret94) ;
+} /* end of [is_odd_49] */
 
 /*
 /usr/local/lib/ats2-postiats-0.3.8/prelude/DATS/integer.dats: 12259(line=635, offs=3) -- 12298(line=635, offs=42)
@@ -2284,11 +2514,11 @@
 } /* end of [ATSLIB_056_prelude__eq_g0int_int__7__8] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 282(line=14, offs=30) -- 306(line=15, offs=19)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 357(line=18, offs=30) -- 381(line=19, offs=19)
 */
 /*
 local: count_divisors_28$0(level=0)
-global: count_divisors_28$0(level=0), count_divisors_ats$48$0(level=0)
+global: count_divisors_28$0(level=0), count_divisors_ats$51$0(level=0)
 local: 
 global: 
 */
@@ -2297,28 +2527,28 @@
 count_divisors_ats(atstkind_t0ype(atstype_int) arg0)
 {
 /* tmpvardeclst(beg) */
-ATStmpdec(tmpret90, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmpret98, atstkind_t0ype(atstype_int)) ;
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 263(line=14, offs=11) -- 307(line=15, offs=20)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 338(line=18, offs=11) -- 382(line=19, offs=20)
 */
 ATSINSflab(__patsflab_count_divisors_ats):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 290(line=15, offs=3) -- 306(line=15, offs=19)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 365(line=19, offs=3) -- 381(line=19, offs=19)
 */
-ATSINSmove(tmpret90, count_divisors_28(arg0)) ;
+ATSINSmove(tmpret98, count_divisors_28(arg0)) ;
 
 ATSfunbody_end()
-ATSreturn(tmpret90) ;
+ATSreturn(tmpret98) ;
 } /* end of [count_divisors_ats] */
 
 /*
-/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 331(line=17, offs=23) -- 348(line=18, offs=12)
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 406(line=21, offs=23) -- 423(line=22, offs=12)
 */
 /*
 local: totient_35$0(level=0)
-global: sqrt_int_12$0(level=0), is_prime_15$0(level=0), totient_35$0(level=0), totient_ats$49$0(level=0)
+global: sqrt_int_12$0(level=0), is_prime_15$0(level=0), totient_35$0(level=0), totient_ats$52$0(level=0)
 local: 
 global: 
 */
@@ -2327,21 +2557,51 @@
 totient_ats(atstkind_t0ype(atstype_int) arg0)
 {
 /* tmpvardeclst(beg) */
-ATStmpdec(tmpret91, atstkind_t0ype(atstype_int)) ;
+ATStmpdec(tmpret99, atstkind_t0ype(atstype_int)) ;
 /* tmpvardeclst(end) */
 ATSfunbody_beg()
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 319(line=17, offs=11) -- 349(line=18, offs=13)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 394(line=21, offs=11) -- 424(line=22, offs=13)
 */
 ATSINSflab(__patsflab_totient_ats):
 /*
-emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 339(line=18, offs=3) -- 348(line=18, offs=12)
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 414(line=22, offs=3) -- 423(line=22, offs=12)
 */
-ATSINSmove(tmpret91, totient_35(arg0)) ;
+ATSINSmove(tmpret99, totient_35(arg0)) ;
 
 ATSfunbody_end()
-ATSreturn(tmpret91) ;
+ATSreturn(tmpret99) ;
 } /* end of [totient_ats] */
+
+/*
+/home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 452(line=24, offs=27) -- 473(line=25, offs=16)
+*/
+/*
+local: totient_sum_44$0(level=0)
+global: sqrt_int_12$0(level=0), is_prime_15$0(level=0), totient_35$0(level=0), totient_sum_44$0(level=0), totient_sum_ats$53$0(level=0)
+local: 
+global: 
+*/
+ATSextern()
+atstkind_t0ype(atstype_int)
+totient_sum_ats(atstkind_t0ype(atstype_int) arg0)
+{
+/* tmpvardeclst(beg) */
+ATStmpdec(tmpret100, atstkind_t0ype(atstype_int)) ;
+/* tmpvardeclst(end) */
+ATSfunbody_beg()
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 436(line=24, offs=11) -- 474(line=25, offs=17)
+*/
+ATSINSflab(__patsflab_totient_sum_ats):
+/*
+emit_instr: loc0 = /home/vanessa/programming/haskell/current/fast-combinatorics/ats-src/number-theory-ffi.dats: 460(line=25, offs=3) -- 473(line=25, offs=16)
+*/
+ATSINSmove(tmpret100, totient_sum_44(arg0)) ;
+
+ATSfunbody_end()
+ATSreturn(tmpret100) ;
+} /* end of [totient_sum_ats] */
 
 /*
 ** for initialization(dynloading)
diff --git a/cbits/numerics.c b/cbits/numerics.c
--- a/cbits/numerics.c
+++ b/cbits/numerics.c
@@ -1,7 +1,7 @@
 /*
 **
 ** The C code is generated by [ATS/Postiats-0-3-8]
-** The starting compilation time is: 2018-1-1: 22h:13m
+** The starting compilation time is: 2018-1-2:  0h:11m
 **
 */
 
diff --git a/fast-combinatorics.cabal b/fast-combinatorics.cabal
--- a/fast-combinatorics.cabal
+++ b/fast-combinatorics.cabal
@@ -1,5 +1,5 @@
 name:                fast-combinatorics
-version:             0.1.0.8
+version:             0.1.0.9
 synopsis:            Fast combinatorics.
 description:         Fast combinatorics code with a high level of safety guaranteed by writing it in ATS.
 homepage:            https://github.com//fast-combinatorics#readme
@@ -10,9 +10,7 @@
 copyright:           Copyright: (c) 2017 Vanessa McHale
 category:            Numerics
 build-type:          Custom
-extra-source-files:  cbits/combinatorics.c
-                   , cbits/numerics.c
-                   , ATS2-Postiats-include-0.3.8/ccomp/runtime/pats_ccomp_config.h
+extra-source-files:  ATS2-Postiats-include-0.3.8/ccomp/runtime/pats_ccomp_config.h
                    , stack.yaml
                    , ats-src/*.dats
                    , cabal.project.local
diff --git a/src/Numeric/NumberTheory.hs b/src/Numeric/NumberTheory.hs
--- a/src/Numeric/NumberTheory.hs
+++ b/src/Numeric/NumberTheory.hs
@@ -7,12 +7,14 @@
 
 module Numeric.NumberTheory ( totient
                             , tau
+                            , totientSum
                             ) where
 
 import           Foreign.C
 
 foreign import ccall unsafe totient_ats :: CInt -> CInt
 foreign import ccall unsafe count_divisors_ats :: CInt -> CInt
+foreign import ccall unsafe totient_sum_ats :: CInt -> CInt
 
 conjugate :: (CInt -> CInt) -> Int -> Int
 conjugate f = fromIntegral . f . fromIntegral
@@ -24,3 +26,7 @@
 -- | Euler totient function.
 totient :: Int -> Int
 totient = conjugate totient_ats
+
+-- | @[totient k | k <- [1 .. n]]@ in Haskell
+totientSum :: Int -> Int
+totientSum = conjugate totient_sum_ats
diff --git a/src/Numeric/Pure.hs b/src/Numeric/Pure.hs
--- a/src/Numeric/Pure.hs
+++ b/src/Numeric/Pure.hs
@@ -4,10 +4,14 @@
                                   , hsChoose
                                   , hsTotient
                                   , hsTau
+                                  , hsTotientSum
                                   ) where
 
 hsTau :: Int -> Int
 hsTau n = length (filter ((== 0) . (n `mod`)) [1..n])
+
+hsTotientSum :: Int -> Int
+hsTotientSum k = sum [ hsTotient n | n <- [1..k] ]
 
 hsTotient :: Int -> Int
 hsTotient n = (n * product [ p - 1 | p <- ps ]) `div` product ps
diff --git a/test/Spec.hs b/test/Spec.hs
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -30,13 +30,16 @@
             \a k -> a < 0 || k < 0 || tooBig a k || (a == 0 && k == 0) || integerExp a k == a ^ k
     parallel $ describe "totient" $
         prop "should agree with the pure Haskell function" $
-            \m -> m < 2 || totient m == hsTotient m
+            \m -> m < 1 || totient m == hsTotient m
     parallel $ describe "totient" $
         prop "should be equal to m-1 for m prime" $
-            \m -> m < 2 || not (isPrime m) || totient m == m - 1
+            \m -> m < 1 || not (isPrime m) || totient m == m - 1
     parallel $ describe "totient" $
         prop "should satisfy Fermat's little theorem" $
-            \a m -> a < 1 || m < 2 || gcd a m /= 1 || tooBig a m || (a ^ (totient m)) `mod` m == 1
+            \a m -> a < 1 || m < 2 || gcd a m /= 1 || tooBig a m || (a ^ totient m) `mod` m == 1
     parallel $ describe "tau" $
         prop "should agree with the pure Haskell function" $
             \n -> n < 1 || tau n == hsTau n
+    parallel $ describe "totientSum" $
+        prop "should agree with the pure Haskell function" $
+            \n -> n < 1 || totientSum n == hsTotientSum n
