15.3.5 Auxilary Arithmetic Functions

We need to auxilariy functions to compute weighted sums and products for a given range of integers.

  \mbox{sum}(m,n,f) = \sum_{i=m}^{n}  f(i) 
\qquad \mbox{and} \qquad
  \mbox{prod}(m,n,f) = \prod_{i=m}^{n}  f(i)

These functions can be easily defined by recursive procedures (or alternatively by looping relative to a global cells containing an integer):

<int.oz>=
%% defines weighted sums and products
functor 
import 
export 
   Sum
   Prod
define 
   fun{Sum N M F}   
      if M==N-then 0 else {F N}+{Sum N+1 M F} end  
   end  
   fun{Prod N M F}
      if M==N-then 1 else {F N}*{Prod N+1 M F} end  
   end 
end


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)