/usr/lib/ats2-postiats-0.2.6/libats/DATS/gflist_vt.dats is in ats2-lang 0.2.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | (***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(***********************************************************************)
(*
** ATS/Postiats - Unleashing the Potential of Types!
** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: hwxiATcsDOTbuDOTedu
// Time: October, 2010
//
(* ****** ****** *)
//
// HX: generic functional lists (fully indexed)
//
(* ****** ****** *)
//
// HX-2012-11-28: ported to ATS/Postiats from ATS/Anairiats
//
(* ****** ****** *)
staload "libats/SATS/ilist_prf.sats"
(* ****** ****** *)
staload "libats/SATS/gflist.sats"
staload "libats/SATS/gflist_vt.sats"
(* ****** ****** *)
implement
{a}(*tmp*)
gflist_vt_length (xs) = let
//
fun loop
{xs:ilist}{j:int} .<xs>. (
xs: !gflist_vt (a, xs), j: int j
) :<> [i:nat]
(LENGTH (xs, i) | int (i+j)) = let
in
//
case+ xs of
| gflist_vt_cons
(_, xs) => let
val (pf | res) = loop (xs, j+1)
in
(LENGTHcons (pf) | res)
end // end of [gflist_vt_cons]
| gflist_vt_nil () => (LENGTHnil () | j)
//
end // end of [loop]
//
in
loop (xs, 0)
end // end of [gflist_vt_length]
(* ****** ****** *)
//
implement
{a}(*tmp*)
gflist_vt_snoc
{xs}{x0}(xs, x0) = let
//
val (pfapp | res) =
gflist_vt_append<a> (xs, gflist_vt_sing(x0))
//
extern
praxi
lemma :
{xsx:ilist}
APPEND(xs, ilist_sing(x0), xsx) -> SNOC(xs, x0, xsx)
//
in
(lemma(pfapp) | res)
end // end of [gflist_vt_snoc]
(* ****** ****** *)
implement
{a}(*tmp*)
gflist_vt_append
(xs, ys) = let
//
fun loop
{xs:ilist}
{ys:ilist} .<xs>. (
xs: gflist_vt (a, xs), ys: gflist_vt (a, ys), res: &ptr? >> gflist_vt (a, zs)
) :<!wrt> #[zs:ilist] (APPEND (xs, ys, zs) | void) = let
in
//
case+ xs of
| @gflist_vt_cons
(x, xs1) => let
val () = res := xs
val xs = xs1
val (pf | ()) = loop (xs, ys, xs1)
prval () = fold@ (res)
in
(APPENDcons (pf) | ())
end // end of [gflist_vt_cons]
| ~gflist_vt_nil () => let
val () = res := ys in (APPENDnil () | ())
end // end of [gflist_vt_nil]
//
end // end of [loop]
//
var res: ptr // uninitialized
//
val (pf | ()) = loop (xs, ys, res)
//
in
(pf | res)
end // end of [gflist_vt_append]
(* ****** ****** *)
implement
{a}(*tmp*)
gflist_vt_revapp
(xs, ys) = let
in
//
case+ xs of
| @gflist_vt_cons
(x, xs1) => let
val xs1_ = xs1
val () = xs1 := ys
prval () = fold@ (xs)
val (pf | res) = gflist_vt_revapp (xs1_, xs)
in
(REVAPPcons (pf) | res)
end // end of [gflist_vt_cons]
| ~gflist_vt_nil () => (REVAPPnil () | ys)
//
end // end of [gflist_vt_append]
implement
{a}(*tmp*)
gflist_vt_reverse (xs) = gflist_vt_revapp (xs, gflist_vt_nil)
(* ****** ****** *)
local
(*
//
// HX-2012-11-28: mergesort on gflist_vt // ported from ATS/Anairiats
//
*)
fun{
a:vt0p
} split
{xs:ilist}
{n,i:nat | i <= n} .<i>. (
pflen: LENGTH (xs, n)
| xs: &gflist_vt (a, xs) >> gflist_vt (a, xs1), i: int i
) : #[xs1,xs2:ilist] (
APPEND (xs1, xs2, xs), LENGTH (xs1, i) | gflist_vt (a, xs2)
) =
if i > 0 then let
prval LENGTHcons (pflen) = pflen
val @gflist_vt_cons (_, xs1) = xs
val (pfapp, pf1len | xs2) = split (pflen | xs1, i-1)
prval () = fold@ (xs)
in
(APPENDcons (pfapp), LENGTHcons (pf1len) | xs2)
end else let
val xs2 = xs
val () = xs := gflist_vt_nil ()
prval pfapp = append_unit_left ()
in
(pfapp, LENGTHnil () | xs2)
end // end of [if]
// end of [split]
(* ****** ****** *)
absprop
UNION (
ys1: ilist, ys2: ilist, res: ilist
) (* end of [absprop] *)
(* ****** ****** *)
extern
prfun
union_commute
{ys1,ys2:ilist} {ys:ilist}
(pf: UNION (ys1, ys2, ys)): UNION (ys2, ys1, ys)
// end of [union_commute]
extern
prfun
union_nil1 {ys:ilist} (): UNION (ilist_nil, ys, ys)
extern
prfun
union_nil2 {ys:ilist} (): UNION (ys, ilist_nil, ys)
extern
prfun
union_cons1
{y:int}
{ys1,ys2:ilist}
{ys:ilist} (
pf: UNION (ys1, ys2, ys)
) : UNION (ilist_cons (y, ys1), ys2, ilist_cons (y, ys))
// end of [union_cons1]
extern
prfun
union_cons2
{y:int}
{ys1,ys2:ilist}
{ys:ilist} (
pf: UNION (ys1, ys2, ys)
) : UNION (ys1, ilist_cons (y, ys2), ilist_cons (y, ys))
// end of [union_cons2]
extern
prfun
isord_union_cons
{y1,y2:int | y1 <= y2}
{ys1,ys2:ilist} {ys:ilist} (
pf1: ISORD (ilist_cons (y1, ys1))
, pf2: ISORD (ilist_cons (y2, ys2))
, pf3: UNION (ys1, ilist_cons (y2, ys2), ys)
, pf4: ISORD (ys)
) : ISORD (ilist_cons (y1, ys))
(* ****** ****** *)
fun{
a:vt0p
} merge
{ys1,ys2:ilist}
(
pf1ord: ISORD (ys1)
, pf2ord: ISORD (ys2)
| ys1: gflist_vt (a, ys1), ys2: gflist_vt (a, ys2)
, ys: &ptr? >> gflist_vt (a, ys)
) : #[ys:ilist] (UNION (ys1, ys2, ys), ISORD (ys) | void) =
case+ ys1 of
| @gflist_vt_cons
(y1, ys1_tl) =>
(
case+ ys2 of
| @gflist_vt_cons
(y2, ys2_tl) => let
val sgn = gflist_vt_mergesort$cmp (y1, y2)
in
if sgn <= 0 then let
val () = ys := ys1; val ys1 = ys1_tl
prval () = fold@ (ys2)
prval ISORDcons (pf1ord1, _) = pf1ord
val (pfuni, pford | ()) = merge (pf1ord1, pf2ord | ys1, ys2, ys1_tl)
prval pford = isord_union_cons (pf1ord, pf2ord, pfuni, pford)
prval () = fold@ (ys)
prval pfuni = union_cons1 (pfuni)
in
(pfuni, pford | ())
end else let
prval () = fold@ (ys1)
val () = ys := ys2; val ys2 = ys2_tl
prval ISORDcons (pf2ord1, _) = pf2ord
val (pfuni, pford | ()) = merge (pf1ord, pf2ord1 | ys1, ys2, ys2_tl)
prval pfuni = union_commute (pfuni)
prval pford = isord_union_cons (pf2ord, pf1ord, pfuni, pford)
prval () = fold@ (ys)
prval pfuni = union_cons1 (pfuni)
prval pfuni = union_commute (pfuni)
in
(pfuni, pford | ())
end // end of [if]
end // end of [gflist_vt_cons]
| ~gflist_vt_nil () => let
val () = fold@ (ys1); val () = ys := ys1 in (union_nil2 (), pf1ord | ())
end // end of [gflist_vt_nil]
) (* end of [gflist_vt_cons] *)
| ~gflist_vt_nil () => let
val () = ys := ys2 in (union_nil1 (), pf2ord | ())
end // end of [gflist_vt_nil]
// end of [merge]
(* ****** ****** *)
extern
prfun sort_nilsing
{xs:ilist} {n:nat | n <= 1} (pf: LENGTH (xs, n)): SORT (xs, xs)
// end of [sort_nilsing]
(* ****** ****** *)
fun{
a:vt0p
} msort
{xs:ilist}{n:nat} .<n>.
(
pflen: LENGTH (xs, n)
| xs: gflist_vt (a, xs), n: int n
) : [ys:ilist] (
SORT (xs, ys) | gflist_vt (a, ys)
) = let
in
//
if n >= 2 then let
var xs = xs
val n2 = half(n)
val (pfapp, pf1len | xs2) = split (pflen | xs, n2)
val xs1 = xs
prval pf2len = length_istot ()
prval pflen_alt = lemma_append_length (pfapp, pf1len, pf2len)
prval () = length_isfun (pflen, pflen_alt)
val (pf1srt | ys1) = msort (pf1len | xs1, n2)
prval (pf1ord, pf1perm) = sort_elim (pf1srt)
val (pf2srt | ys2) = msort (pf2len | xs2, n-n2)
prval (pf2ord, pf2perm) = sort_elim (pf2srt)
val (pfuni, pford | ()) = merge (pf1ord, pf2ord | ys1, ys2, xs)
//
prval
pfperm =
lemma
(
pfapp, pf1perm, pf2perm, pfuni
) where
{
extern
prfun
lemma
{xs1,xs2:ilist}{xs:ilist}
{ys1,ys2:ilist}{ys:ilist}
(
APPEND (xs1, xs2, xs)
, PERMUTE (xs1, ys1), PERMUTE (xs2, ys2), UNION (ys1, ys2, ys)
) : PERMUTE (xs, ys) // end of [lemma]
} (* end of [where] *) // end of [prval]
//
prval pfsrt = sort_make (pford, pfperm)
//
in
(pfsrt | xs)
end else
(sort_nilsing (pflen) | xs)
// end of [if]
//
end // end of [msort]
in (* in of [local] *)
implement
{a}(*tmp*)
gflist_vt_mergesort (xs) = let
val (pflen | n) = gflist_vt_length<a> (xs) in msort<a> (pflen | xs, n)
end // end of [mergesort]
end // end of [local]
(* ****** ****** *)
(* end of [gflist_vt.dats] *)
|