diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-30 20:36:53 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-30 20:36:53 +0900 |
| commit | e9db0870164cfec10aa219cc0898c30f6a888f53 (patch) | |
| tree | 262150d7ad6abc6759f41a7adbb6dec4a7c90cb5 /comparison/Inpla/src/bsort-20000-reuse.in | |
| parent | bd540962efa674bb70dc9ada49393db54616dcbf (diff) | |
| parent | e18b27f43ac23689822d4aaaaa3e8d550e41017a (diff) | |
| download | inpla-e9db0870164cfec10aa219cc0898c30f6a888f53.tar.gz inpla-e9db0870164cfec10aa219cc0898c30f6a888f53.zip | |
Merge branch 'develop'
Diffstat (limited to 'comparison/Inpla/src/bsort-20000-reuse.in')
| -rw-r--r-- | comparison/Inpla/src/bsort-20000-reuse.in | 77 |
1 files changed, 77 insertions, 0 deletions
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; |
