code: def fold_finite(ctx, f, intervals):
      if not intervals:
          return f
      indices = [v[0] for v in intervals]
      points = [v[1] for v in intervals]
      ranges = [xrange(a, b + 1) for (a, b) in points]
  
      def g(*args):
          args = list(args)
          s = ctx.zero
          for xs in cartesian_product(ranges):
              for dim, x in zip(indices, xs):
                  args[dim] = ctx.mpf(x)
              s += f(*args)
          return s
  
      # print "Folded finite", indices
      return g
  
imports: from ..libmp.backend import xrange
  from .calculus import defun
label_desc: Use image node_id 12 for calling a global function with example usage: fold_finite(ctx, f, intervals) and returns: g, f, s