aboutsummaryrefslogtreecommitdiff
path: root/comparison/Inpla/src/qsort-800000-reuse.in
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-04-28 21:47:28 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-04-28 21:47:28 +0900
commit7ea48cd96551247ecc763a5e42404ffa3464d0b0 (patch)
treefd1b63ab48d98a9243d3053522e17e31b9dc033f /comparison/Inpla/src/qsort-800000-reuse.in
parent950e2cb2184cb7ead93ba8df691a190598ed242f (diff)
parent429543c748aaf81b2a4207318eb5a05259469b21 (diff)
downloadinpla-7ea48cd96551247ecc763a5e42404ffa3464d0b0.tar.gz
inpla-7ea48cd96551247ecc763a5e42404ffa3464d0b0.zip
Merge branch 'develop'
Diffstat (limited to 'comparison/Inpla/src/qsort-800000-reuse.in')
-rw-r--r--comparison/Inpla/src/qsort-800000-reuse.in46
1 files changed, 32 insertions, 14 deletions
diff --git a/comparison/Inpla/src/qsort-800000-reuse.in b/comparison/Inpla/src/qsort-800000-reuse.in
index 810e446..7f41045 100644
--- a/comparison/Inpla/src/qsort-800000-reuse.in
+++ b/comparison/Inpla/src/qsort-800000-reuse.in
@@ -1,26 +1,44 @@
// Quick sort
-QS(ret) >< [] => ret~(*R)[];
-QS(ret) >< (int x):xs =>
- (*R)Part(x, left, right)~xs,
- (*L)QS(cntl)~left, QS(cntr)~right,
+qsort(ret) >< [] => ret~(*R)[];
+qsort(ret) >< (int x):xs =>
+ (*R)part(x, left, right)~xs,
+ (*L)qsort(cntl)~left, qsort(cntr)~right,
Append(ret, x:cntl)~cntr;
// Note: `Append' is implemented as built-in.
-Part(int x, a, b) >< [] => a~(*L)[], b~(*R)[];
-Part(int x, a, b) >< (int y):ys
-| y<x => b~(*R)(y:cnt), (*L)Part(x, a, cnt)~ys
-| _ => a~(*R)(y:cnt), (*L)Part(x, cnt, b)~ys;
+part(int x, a, b) >< [] => a~(*L)[], b~(*R)[];
+part(int x, a, b) >< (int y):ys
+| y<x => b~(*R)(y:cnt), (*L)part(x, a, cnt)~ys
+| _ => a~(*R)(y:cnt), (*L)part(x, cnt, b)~ys;
-const LIST_ELEM=800000;
-
-MkRandList(ret) >< (int n)
-| n>0 => ret~(rd:cnt), (*L)MkRandList(cnt)~(n-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~[];
-MkRandList(cnt)~(LIST_ELEM),
-QS(ret)~cnt;
+
+// validation checks
+valid(ret) >< [] => ret~False;
+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=800000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+qsort(sorted)~rndlist,
+valid(ret)~sorted;
+
ret;