Associativity and parallel programming

def recursivePara(list : List[Int]) : Int = 
if(list.length < threshold ){
list.reduce(_+_)
}else{
val middle = list.length/2
parallel(recursivePara(list.slice(0, middle)), recursivePara(list.slice(middle, list.length)))
}

Definition of associativity :

list.reduce(_-_) 

Prove associativity :

def minus(a : Int, b : Int) 
def f(a,b) = if (a<b) minus(b,a) else minus(a,b)
def minus[A](a : A, b : A) 
def f[A](a: A, b : A) if (less(a,b)) minus(a,b) else minus(b,a=

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store