aboutsummaryrefslogtreecommitdiff
path: root/comparison
diff options
context:
space:
mode:
Diffstat (limited to 'comparison')
-rw-r--r--comparison/Haskell/Makefile6
-rw-r--r--comparison/Haskell/bsort-20000.hs45
-rw-r--r--comparison/Haskell/isort-20000.hs39
-rw-r--r--comparison/Inpla/main.sh8
-rw-r--r--comparison/Inpla/src/bsort-20000-reuse.in77
-rw-r--r--comparison/Inpla/src/bsort-20000.in77
-rw-r--r--comparison/Inpla/src/bsort-efficient-20000-reuse.in40
-rw-r--r--comparison/Inpla/src/bsort-efficient-20000.in40
-rw-r--r--comparison/Inpla/src/isort-20000-reuse.in38
-rw-r--r--comparison/Inpla/src/isort-20000.in38
-rw-r--r--comparison/OCaml/Makefile6
-rw-r--r--comparison/OCaml/bsort20000.ml39
-rw-r--r--comparison/OCaml/isort20000.ml36
-rw-r--r--comparison/Python/Makefile2
-rw-r--r--comparison/Python/bsort-20000.py31
-rw-r--r--comparison/Python/isort-20000.py31
-rw-r--r--comparison/SML/Makefile2
-rw-r--r--comparison/SML/bsort-20000.sml42
-rw-r--r--comparison/SML/isort-20000.sml35
19 files changed, 620 insertions, 12 deletions
diff --git a/comparison/Haskell/Makefile b/comparison/Haskell/Makefile
index b55259f..13a1b83 100644
--- a/comparison/Haskell/Makefile
+++ b/comparison/Haskell/Makefile
@@ -1,7 +1,7 @@
CC = stack ghc
CFLAGS = -O2
BENCHMARK = bash ../tools/sptest_commands.sh
-TARGET = ack3-11 fib38 bsort-40000 isort-40000 qsort-260000 msort-260000
+TARGET = ack3-11 fib38 bsort-20000 isort-20000 qsort-260000 msort-260000
LOG = log.txt
@@ -18,10 +18,10 @@ ack3-11: ack3-11.hs
fib38: fib38.hs
$(CC) -- $(CFLAGS) $<
-bsort-40000: bsort-40000.hs
+bsort-20000: bsort-20000.hs
$(CC) -- $(CFLAGS) $<
-isort-40000: isort-40000.hs
+isort-20000: isort-20000.hs
$(CC) -- $(CFLAGS) $<
qsort-260000: qsort-260000.hs
diff --git a/comparison/Haskell/bsort-20000.hs b/comparison/Haskell/bsort-20000.hs
new file mode 100644
index 0000000..89ecfab
--- /dev/null
+++ b/comparison/Haskell/bsort-20000.hs
@@ -0,0 +1,45 @@
+{-
+https://gist.github.com/masquerade0324/68f4f3fd3ab897fbe1ad
+http://files.farka.eu/pub/AC21007/lec5.pdf
+-}
+
+import System.Random
+
+bs xs 0 = xs
+bs (x:y:ys) n =
+ if x<y then x:(bs (y:ys) (n-1))
+ else y:(bs (x:ys) (n-1))
+bs xs n = xs
+
+
+go xs 0 = xs
+go xs n = go (bs xs n) (n-1)
+
+bsort [] = []
+bsort xs = go xs (length xs -1)
+
+{-
+main = print $ bsort [3,2,8,5]
+-}
+
+
+randomList :: Int -> IO([Int])
+randomList 0 = return []
+randomList n = do
+ r <- randomRIO (1,10000)
+ rs <- randomList (n-1)
+ return (r:rs)
+
+
+validation [] = True
+validation (x:xs) = validation_cons x xs
+validation_cons x [] = True
+validation_cons x (y:ys) =
+ if x<=y then validation_cons y ys
+ else False
+
+
+main = do
+ list <- randomList 20000
+ let sorted = bsort list
+ print (validation sorted)
diff --git a/comparison/Haskell/isort-20000.hs b/comparison/Haskell/isort-20000.hs
new file mode 100644
index 0000000..a4cef88
--- /dev/null
+++ b/comparison/Haskell/isort-20000.hs
@@ -0,0 +1,39 @@
+{-
+http://www.codecodex.com/wiki/Insertion_sort#Standard_ML
+-}
+import System.Random
+
+isort [] = []
+isort (x:xs) = insert x (isort xs)
+
+insert x [] = [x]
+insert x (y:ys) =
+ if x<=y then x:y:ys
+ else y:(insert x ys)
+
+
+{-
+main = print $ isort [3,2,8,5]
+-}
+
+
+randomList :: Int -> IO([Int])
+randomList 0 = return []
+randomList n = do
+ r <- randomRIO (1,10000)
+ rs <- randomList (n-1)
+ return (r:rs)
+
+
+validation [] = True
+validation (x:xs) = validation_cons x xs
+validation_cons x [] = True
+validation_cons x (y:ys) =
+ if x<=y then validation_cons y ys
+ else False
+
+
+main = do
+ list <- randomList 20000
+ let sorted = isort list
+ print (validation sorted)
diff --git a/comparison/Inpla/main.sh b/comparison/Inpla/main.sh
index 6975046..13502b9 100644
--- a/comparison/Inpla/main.sh
+++ b/comparison/Inpla/main.sh
@@ -6,11 +6,11 @@ bash ./sptestInpla.sh src/fib-38-reuse.in
bash ./sptestInpla.sh src/ack-stream_3-11.in
bash ./sptestInpla.sh src/ack-stream_3-11-reuse.in
-bash ./sptestInpla.sh src/bsort-40000.in
-bash ./sptestInpla.sh src/bsort-40000-reuse.in
+bash ./sptestInpla.sh src/bsort-20000.in
+bash ./sptestInpla.sh src/bsort-20000-reuse.in
-bash ./sptestInpla.sh src/isort-40000.in
-bash ./sptestInpla.sh src/isort-40000-reuse.in
+bash ./sptestInpla.sh src/isort-20000.in
+bash ./sptestInpla.sh src/isort-20000-reuse.in
bash ./sptestInpla.sh src/qsort-260000.in
bash ./sptestInpla.sh src/qsort-260000-reuse.in '-Xms 17 -Xmt 0'
diff --git a/comparison/Inpla/src/bsort-20000-reuse.in b/comparison/Inpla/src/bsort-20000-reuse.in
new file mode 100644
index 0000000..c5080fe
--- /dev/null
+++ b/comparison/Inpla/src/bsort-20000-reuse.in
@@ -0,0 +1,77 @@
+// Bubble sort with the same algorithm as others
+
+/*
+// length
+length_(r,n) >< [] => r~n;
+length_(r,int n) >< (int x):xs => length_(r,n+1)~xs;
+
+length(r) >< [] => r~0;
+length(r) >< x:xs => length_(r,0) ~ x:xs;
+*/
+
+
+// stream length
+len_stream_(len, list, int ct) >< [] => len~ct, list~(*R)[];
+len_stream_(len, list, int ct) >< x:xs =>
+ list~(*R)(x:cnt),
+ len_stream_(len, cnt, ct+1) ~ xs;
+
+
+len_stream(len, list) >< [] => len~0, list~(*R)[];
+len_stream(len, list) >< x:xs =>
+ list~(x:cnt),
+ len_stream_(len, cnt, 1)~xs;
+
+
+// bubble sort
+bs(r, xs) >< (int n)
+| n == 0 => r~xs
+| _ => (*L)bs_Cons(r, n)~xs;
+
+bs_Cons(r, int n)>< x:xs => (*L)bs_ConsCons(r, n, x) ~ xs;
+bs_Cons(r, int n)>< [] => r~(*R)[];
+
+bs_ConsCons(r, int n, int x) >< (int y):ys
+| x < y => r~x:cnt, (*L)bs(cnt, y:ys) ~(n-1)
+| _ => r~y:cnt, (*L)bs(cnt, x:ys)~(n-1);
+bs_ConsCons(r, int n, int x) >< [] => r~(*R)[x];
+
+go(r,xs) >< (int n)
+| n==0 => r~xs
+| _ => bs(cnt, xs)~n, (*L)go(r, cnt)~(n-1);
+
+bsort(r) >< [] => r~[];
+bsort(r) >< x:xs =>
+ (*L)len_stream(len, alist) ~ (*R)(x:xs),
+ go(r, alist)~lengthDec1,
+ Sub(lengthDec1,len)~1;
+
+
+// Creates a random list
+make_RandList(ret) >< (int n)
+| n>0 => ret~(rd:cnt), (*L)make_RandList(cnt)~(n-1)
+ where rd=rand(10000)
+| _ => ret~[];
+
+
+// validation checks
+valid(ret) >< [] => ret~True;
+valid(ret) >< x:xs => (*L)valid_Cons(ret,x)~xs;
+
+valid_Cons(ret, int x) >< [] => ret~True;
+valid_Cons(ret, int x) >< (int y):ys
+| x<=y => (*L)valid_Cons(ret,y)~ys
+| _ => ret~False, Eraser~ys;
+
+// The `Eraser' is a built-in agent defined for any agents as follows:
+//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5;
+
+
+// Main
+const LIST_ELEM=20000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+bsort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret;
diff --git a/comparison/Inpla/src/bsort-20000.in b/comparison/Inpla/src/bsort-20000.in
new file mode 100644
index 0000000..e012bc6
--- /dev/null
+++ b/comparison/Inpla/src/bsort-20000.in
@@ -0,0 +1,77 @@
+// Bubble sort with the same algorithm as others
+
+/*
+// length
+length_(r,n) >< [] => r~n;
+length_(r,int n) >< (int x):xs => length_(r,n+1)~xs;
+
+length(r) >< [] => r~0;
+length(r) >< x:xs => length_(r,0) ~ x:xs;
+*/
+
+
+// stream length
+len_stream_(len, list, int ct) >< [] => len~ct, list~[];
+len_stream_(len, list, int ct) >< x:xs =>
+ list~x:cnt,
+ len_stream_(len, cnt, ct+1) ~xs;
+
+
+len_stream(len, list) >< [] => len~0, list~[];
+len_stream(len, list) >< x:xs =>
+ list~x:cnt,
+ len_stream_(len, cnt, 1)~xs;
+
+
+// bubble sort
+bs(r, xs) >< (int n)
+| n == 0 => r~xs
+| _ => bs_Cons(r, n)~xs;
+
+bs_Cons(r, int n)>< x:xs => bs_ConsCons(r, n, x) ~ xs;
+bs_Cons(r, int n)>< [] => r~[];
+
+bs_ConsCons(r, int n, int x) >< (int y):ys
+| x < y => r~x:cnt, bs(cnt, y:ys) ~(n-1)
+| _ => r~y:cnt, bs(cnt, x:ys)~(n-1);
+bs_ConsCons(r, int n, int x) >< [] => r~[x];
+
+go(r,xs) >< (int n)
+| n==0 => r~xs
+| _ => bs(cnt, xs)~n, go(r, cnt)~(n-1);
+
+bsort(r) >< [] => r~[];
+bsort(r) >< x:xs =>
+ len_stream(len, alist) ~ x:xs,
+ go(r, alist)~lengthDec1,
+ Sub(lengthDec1,len)~1;
+
+
+// creates a random list
+make_RandList(ret) >< (int n)
+| n>0 => ret~(rd:cnt), make_RandList(cnt)~(n-1)
+ where rd=rand(10000)
+| _ => ret~[];
+
+
+// validation checks
+valid(ret) >< [] => ret~True;
+valid(ret) >< x:xs => valid_Cons(ret,x)~xs;
+
+valid_Cons(ret, int x) >< [] => ret~True;
+valid_Cons(ret, int x) >< (int y):ys
+| x<=y => valid_Cons(ret,y)~ys
+| _ => ret~False, Eraser~ys;
+
+// The `Eraser' is a built-in agent defined for any agents as follows:
+//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5;
+
+
+// Main
+const LIST_ELEM=20000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+bsort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret; \ No newline at end of file
diff --git a/comparison/Inpla/src/bsort-efficient-20000-reuse.in b/comparison/Inpla/src/bsort-efficient-20000-reuse.in
new file mode 100644
index 0000000..e496c3e
--- /dev/null
+++ b/comparison/Inpla/src/bsort-efficient-20000-reuse.in
@@ -0,0 +1,40 @@
+// Bubble sort
+bsort(ret) >< [] => ret~[];
+bsort(ret) >< x:xs => (*L)bsort(ret)~cnt, (*R)B(cnt, x)~xs;
+bsort(ret) >< M(x) => ret~x;
+
+B(ret, int x) >< [] => ret~M([x]);
+B(ret, int x) >< M(w) => ret~M(x:w);
+B(ret, int x) >< (int y):ys
+| x<y => ret~(*R)(x:cnt), (*L)B(cnt, y)~ys
+| _ => ret~(*R)(y:cnt), (*L)B(cnt, x)~ys;
+
+
+// Creates a random list
+make_RandList(ret) >< (int n)
+| n>0 => ret~(rd:cnt), (*L)make_RandList(cnt)~(n-1)
+ where rd=rand(10000)
+| _ => ret~[];
+
+
+// validation checks
+valid(ret) >< [] => ret~True;
+valid(ret) >< x:xs => (*L)valid_Cons(ret,x)~xs;
+
+valid_Cons(ret, int x) >< [] => ret~True;
+valid_Cons(ret, int x) >< (int y):ys
+| x<=y => (*L)valid_Cons(ret,y)~ys
+| _ => ret~False, Eraser~ys;
+
+// The `Eraser' is a built-in agent defined for any agents as follows:
+//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5;
+
+
+// Main
+const LIST_ELEM=20000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+bsort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret;
diff --git a/comparison/Inpla/src/bsort-efficient-20000.in b/comparison/Inpla/src/bsort-efficient-20000.in
new file mode 100644
index 0000000..c9702fe
--- /dev/null
+++ b/comparison/Inpla/src/bsort-efficient-20000.in
@@ -0,0 +1,40 @@
+// Bubble sort
+bsort(ret) >< [] => ret~[];
+bsort(ret) >< x:xs => bsort(ret)~cnt, B(cnt, x)~xs;
+bsort(ret) >< M(x) => ret~x;
+
+B(ret, int x) >< [] => ret~M([x]);
+B(ret, int x) >< M(w) => ret~M(x:w);
+B(ret, int x) >< (int y):ys
+| x<y => ret~(x:cnt), B(cnt, y)~ys
+| _ => ret~(y:cnt), B(cnt, x)~ys;
+
+
+// creates a random list
+make_RandList(ret) >< (int n)
+| n>0 => ret~(rd:cnt), make_RandList(cnt)~(n-1)
+ where rd=rand(10000)
+| _ => ret~[];
+
+
+// validation checks
+valid(ret) >< [] => ret~True;
+valid(ret) >< x:xs => valid_Cons(ret,x)~xs;
+
+valid_Cons(ret, int x) >< [] => ret~True;
+valid_Cons(ret, int x) >< (int y):ys
+| x<=y => valid_Cons(ret,y)~ys
+| _ => ret~False, Eraser~ys;
+
+// The `Eraser' is a built-in agent defined for any agents as follows:
+//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5;
+
+
+// Main
+const LIST_ELEM=20000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+bsort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret;
diff --git a/comparison/Inpla/src/isort-20000-reuse.in b/comparison/Inpla/src/isort-20000-reuse.in
new file mode 100644
index 0000000..9d7c7ab
--- /dev/null
+++ b/comparison/Inpla/src/isort-20000-reuse.in
@@ -0,0 +1,38 @@
+// Insertion sort
+isort(ret) >< [] => ret~[];
+isort(ret) >< x:xs => (*L)I(ret, x)~cnt, (*R)isort(cnt)~xs;
+
+I(ret, int x) >< [] => ret~[x];
+I(ret, int x) >< (int y):ys
+| x<=y => ret~(*L)(x:(*R)(y:ys))
+| _ => ret~(*L)(y:cnt), (*R)I(cnt, x)~ys;
+
+
+// creates a random list
+make_RandList(ret) >< (int n)
+| n>0 => ret~(rd:cnt), (*L)make_RandList(cnt)~(n-1)
+ where rd=rand(10000)
+| _ => ret~[];
+
+
+// validation checks
+valid(ret) >< [] => ret~True;
+valid(ret) >< x:xs => (*L)valid_Cons(ret,x)~xs;
+
+valid_Cons(ret, int x) >< [] => ret~True;
+valid_Cons(ret, int x) >< (int y):ys
+| x<=y => (*L)valid_Cons(ret,y)~ys
+| _ => ret~False, Eraser~ys;
+
+// The `Eraser' is a built-in agent defined for any agents as follows:
+//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5;
+
+
+// Main
+const LIST_ELEM=20000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+isort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret;
diff --git a/comparison/Inpla/src/isort-20000.in b/comparison/Inpla/src/isort-20000.in
new file mode 100644
index 0000000..3ed10aa
--- /dev/null
+++ b/comparison/Inpla/src/isort-20000.in
@@ -0,0 +1,38 @@
+// Insertion sort
+isort(ret) >< [] => ret~[];
+isort(ret) >< x:xs => I(ret, x)~cnt, isort(cnt)~xs;
+
+I(ret, int x) >< [] => ret~[x];
+I(ret, int x) >< (int y):ys
+| x<=y => ret~(x:y:ys)
+| _ => ret~(y:cnt), I(cnt, x)~ys;
+
+
+// creates a random list
+make_RandList(ret) >< (int n)
+| n>0 => ret~(rd:cnt), make_RandList(cnt)~(n-1)
+ where rd=rand(10000)
+| _ => ret~[];
+
+
+// validation checks
+valid(ret) >< [] => ret~True;
+valid(ret) >< x:xs => valid_Cons(ret,x)~xs;
+
+valid_Cons(ret, int x) >< [] => ret~True;
+valid_Cons(ret, int x) >< (int y):ys
+| x<=y => valid_Cons(ret,y)~ys
+| _ => ret~False, Eraser~ys;
+
+// The `Eraser' is a built-in agent defined for any agents as follows:
+//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5;
+
+
+// Main
+const LIST_ELEM=20000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+isort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret;
diff --git a/comparison/OCaml/Makefile b/comparison/OCaml/Makefile
index d300b15..9db7726 100644
--- a/comparison/OCaml/Makefile
+++ b/comparison/OCaml/Makefile
@@ -1,7 +1,7 @@
CC = ocamlopt
CFLAGS =
BENCHMARK = bash ../tools/sptest_commands.sh
-TARGET = ack3_11 fib38 bsort40000 isort40000 qsort260000 msort260000
+TARGET = ack3_11 fib38 bsort20000 isort20000 qsort260000 msort260000
LOG = log.txt
@@ -18,10 +18,10 @@ ack3_11: ack3_11.ml
fib38: fib38.ml
$(CC) $(CFLAGS) $< -o $@
-bsort40000: bsort40000.ml
+bsort20000: bsort20000.ml
$(CC) $(CFLAGS) $< -o $@
-isort40000: isort40000.ml
+isort20000: isort20000.ml
$(CC) $(CFLAGS) $< -o $@
qsort260000: qsort260000.ml
diff --git a/comparison/OCaml/bsort20000.ml b/comparison/OCaml/bsort20000.ml
new file mode 100644
index 0000000..29a369c
--- /dev/null
+++ b/comparison/OCaml/bsort20000.ml
@@ -0,0 +1,39 @@
+open Format
+
+let rec bs (alist : int list) n =
+ match alist with
+ (x::y::ys) ->
+ if x<y then x::(bs (y::ys) (n-1))
+ else y::(bs (x::ys) (n-1))
+ | xs -> xs;;
+
+
+let rec go xs n =
+ match n with
+ 0 -> xs
+ | n -> go (bs xs n) (n-1);;
+
+let bsort alist =
+ match alist with
+ [] -> []
+ | xs -> go xs (List.length(xs) - 1);;
+
+
+let rec mkRandList n =
+ match n with
+ 0 -> []
+ | n -> (Random.int 10000)::(mkRandList (n-1));;
+
+
+let rec validation alist =
+ let rec validation_cons x blist =
+ match blist with
+ [] -> true
+ | y::ys -> if x<=y then (validation_cons y ys) else false
+ in
+ match alist with
+ [] -> true
+ | x::xs -> validation_cons x xs;;
+
+
+let () = print_bool (validation (bsort (mkRandList 20000)));;
diff --git a/comparison/OCaml/isort20000.ml b/comparison/OCaml/isort20000.ml
new file mode 100644
index 0000000..ddcdd2a
--- /dev/null
+++ b/comparison/OCaml/isort20000.ml
@@ -0,0 +1,36 @@
+open Format
+
+let rec insert x ylist =
+ match ylist with
+ [] -> [x]
+ | y::ys -> if x<=y
+ then x::y::ys
+ else y::(insert x ys);;
+
+
+let rec isort (alist : int list) =
+ match alist with
+ [] -> []
+ | x::xs -> insert x (isort xs);;
+
+
+
+let rec mkRandList n =
+ match n with
+ 0 -> []
+ | n -> (Random.int 10000)::(mkRandList (n-1));;
+
+
+let rec validation alist =
+ let rec validation_cons x blist =
+ match blist with
+ [] -> true
+ | y::ys -> if x<=y then (validation_cons y ys) else false
+ in
+ match alist with
+ [] -> true
+ | x::xs -> validation_cons x xs;;
+
+
+let () = print_bool (validation (isort (mkRandList 20000)));;
+
diff --git a/comparison/Python/Makefile b/comparison/Python/Makefile
index 21f4b3d..c77d677 100644
--- a/comparison/Python/Makefile
+++ b/comparison/Python/Makefile
@@ -1,5 +1,5 @@
COMMAND = python3
-TARGET = dummy.py ack3-11.py fib38.py bsort-40000.py isort-40000.py qsort-260000.py msort-260000.py
+TARGET = dummy.py ack3-11.py fib38.py bsort-20000.py isort-20000.py qsort-260000.py msort-260000.py
BENCHMARK = bash ../tools/sptest_scripts.sh
LOG = log.txt
diff --git a/comparison/Python/bsort-20000.py b/comparison/Python/bsort-20000.py
new file mode 100644
index 0000000..22cc8a7
--- /dev/null
+++ b/comparison/Python/bsort-20000.py
@@ -0,0 +1,31 @@
+# http://www.geekviewpoint.com/python/sorting/bubblesort
+import random
+
+def bubblesort(A):
+ for i in range(len(A)):
+ for k in range(len(A)-1, i, -1):
+ if (A[k] < A[k-1]):
+ tmp = A[k]
+ A[k] = A[k-1]
+ A[k-1] = tmp
+
+
+def mkRandList(n):
+ a=[]
+ for i in range(1,n+1):
+ a.insert(0, random.randint(0,10000))
+ return a
+
+
+def validation(alist):
+ for i in range(len(alist)-1):
+ if (alist[i] > alist[i+1]):
+ return False
+
+ return True
+
+
+
+a=mkRandList(20000)
+bubblesort(a)
+print(validation(a))
diff --git a/comparison/Python/isort-20000.py b/comparison/Python/isort-20000.py
new file mode 100644
index 0000000..b37fe5d
--- /dev/null
+++ b/comparison/Python/isort-20000.py
@@ -0,0 +1,31 @@
+import random
+
+def insert_sort(arr):
+ for i in range(1, len(arr)):
+ j = i - 1
+ ele = arr[i]
+ while arr[j] > ele and j >= 0:
+ arr[j + 1] = arr[j]
+ j -= 1
+ arr[j + 1] = ele
+ return arr
+
+
+def mkRandList(n):
+ a=[]
+ for i in range(1,n+1):
+ a.insert(0, random.randint(0,10000))
+ return a
+
+
+def validation(alist):
+ for i in range(len(alist)-1):
+ if (alist[i] > alist[i+1]):
+ return False
+
+ return True
+
+
+a = mkRandList(20000)
+insert_sort(a)
+print(validation(a))
diff --git a/comparison/SML/Makefile b/comparison/SML/Makefile
index 0e4e2e3..14dca02 100644
--- a/comparison/SML/Makefile
+++ b/comparison/SML/Makefile
@@ -1,5 +1,5 @@
COMMAND = sml
-TARGET = dummy.sml ack3-11.sml fib38.sml bsort-40000.sml isort-40000.sml qsort-260000.sml msort-260000.sml
+TARGET = dummy.sml ack3-11.sml fib38.sml bsort-20000.sml isort-20000.sml qsort-260000.sml msort-260000.sml
BENCHMARK = bash ../tools/sptest_scripts.sh
LOG = log.txt
diff --git a/comparison/SML/bsort-20000.sml b/comparison/SML/bsort-20000.sml
new file mode 100644
index 0000000..2129cd6
--- /dev/null
+++ b/comparison/SML/bsort-20000.sml
@@ -0,0 +1,42 @@
+(*
+https://gist.github.com/masquerade0324/68f4f3fd3ab897fbe1ad
+*)
+
+fun bs xs 0 = xs
+ | bs (x::y::ys) n =
+ if (x<y) then x::(bs (y::ys) (n-1))
+ else y::(bs (x::ys) (n-1))
+ | bs xs _ = xs;
+
+fun go xs 0 = xs
+ | go xs n = go (bs xs n) (n-1);
+
+
+fun bsort [] = []
+ | bsort xs = go xs (length(xs) - 1);
+
+
+(* Creates a random list *)
+local
+ val nextInt = Random.randRange(1,10000);
+ val r = Random.rand(1,1);
+in
+ fun mkRandList 0 = []
+ | mkRandList n = (nextInt r)::(mkRandList (n-1))
+end;
+
+
+(* Validation checks *)
+fun validation [] = true
+ | validation (x::xs) =
+ let fun validation_cons x [] = true
+ | validation_cons x (y::ys) =
+ if x<=y then validation_cons y ys
+ else false
+ in
+ validation_cons x xs
+ end;
+
+
+(* Main *)
+validation(bsort(mkRandList 20000));
diff --git a/comparison/SML/isort-20000.sml b/comparison/SML/isort-20000.sml
new file mode 100644
index 0000000..d3648cc
--- /dev/null
+++ b/comparison/SML/isort-20000.sml
@@ -0,0 +1,35 @@
+(* http://www.codecodex.com/wiki/Insertion_sort#Standard_ML *)
+fun insertsort [] = []
+ | insertsort (x::xs) =
+ let fun insert (x, []) = [x]
+ | insert (x, y::ys) =
+ if x<=y then x::y::ys
+ else y::insert(x, ys)
+ in insert(x, insertsort xs)
+ end;
+
+
+(* Creates a random list *)
+local
+ val nextInt = Random.randRange(1,10000);
+ val r = Random.rand(1,1);
+in
+ fun mkRandList 0 = []
+ | mkRandList n = (nextInt r)::(mkRandList (n-1))
+end;
+
+
+(* Validation checks *)
+fun validation [] = true
+ | validation (x::xs) =
+ let fun validation_cons x [] = true
+ | validation_cons x (y::ys) =
+ if x<=y then validation_cons y ys
+ else false
+ in
+ validation_cons x xs
+ end;
+
+
+(* Main *)
+validation(insertsort(mkRandList 20000));