aboutsummaryrefslogtreecommitdiff
path: root/comparison/Inpla/src/qsort-260000.in
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:50:21 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:50:21 +0900
commitdf4949f8b08cbe3cfd99933d5bb14a373f47f2dd (patch)
treec516c3c45d79a4843114ddd44a83b9ca87250cb7 /comparison/Inpla/src/qsort-260000.in
parent7ea48cd96551247ecc763a5e42404ffa3464d0b0 (diff)
parent779860e35f5c67c7fd48ef876784f87afcfdb321 (diff)
downloadinpla-df4949f8b08cbe3cfd99933d5bb14a373f47f2dd.tar.gz
inpla-df4949f8b08cbe3cfd99933d5bb14a373f47f2dd.zip
Merge branch 'develop'
Diffstat (limited to 'comparison/Inpla/src/qsort-260000.in')
-rw-r--r--comparison/Inpla/src/qsort-260000.in44
1 files changed, 44 insertions, 0 deletions
diff --git a/comparison/Inpla/src/qsort-260000.in b/comparison/Inpla/src/qsort-260000.in
new file mode 100644
index 0000000..2f7d63c
--- /dev/null
+++ b/comparison/Inpla/src/qsort-260000.in
@@ -0,0 +1,44 @@
+// Quick sort
+qsort(ret) >< [] => ret~[];
+qsort(ret) >< (int x):xs =>
+ part(x, left, right)~xs,
+ qsort(cntl)~left, qsort(cntr)~right,
+ Append(ret, x:cntl)~cntr;
+
+// Note: `Append' is implemented as built-in.
+
+
+part(int x, a, b) >< [] => a~[], b~[];
+part(int x, a, b) >< (int y):ys
+| y<x => b~(y:cnt), part(x, a, cnt)~ys
+| _ => a~(y:cnt), part(x, cnt, b)~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=260000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+qsort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret;