aboutsummaryrefslogtreecommitdiff
path: root/comparison/Inpla/src/qsort-260000-reuse.in
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:49:01 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:49:01 +0900
commit8c7809d024e85d0a8acfb794a4db41b0e4bc13e6 (patch)
tree25ac81bad7be415d7cf75457275f7161d79f9f10 /comparison/Inpla/src/qsort-260000-reuse.in
parent429543c748aaf81b2a4207318eb5a05259469b21 (diff)
downloadinpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.tar.gz
inpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.zip
v0.8.2-1
Diffstat (limited to 'comparison/Inpla/src/qsort-260000-reuse.in')
-rw-r--r--comparison/Inpla/src/qsort-260000-reuse.in44
1 files changed, 44 insertions, 0 deletions
diff --git a/comparison/Inpla/src/qsort-260000-reuse.in b/comparison/Inpla/src/qsort-260000-reuse.in
new file mode 100644
index 0000000..b44e958
--- /dev/null
+++ b/comparison/Inpla/src/qsort-260000-reuse.in
@@ -0,0 +1,44 @@
+// Quick sort
+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;
+
+
+// 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=260000;
+
+make_RandList(rndlist)~(LIST_ELEM),
+qsort(sorted)~rndlist,
+valid(ret)~sorted;
+
+ret;