GMP is out of ATS2 (was in ATS1)

I would like to point out that GMP is now out of ATS2.

You need to have ATS2-contrib in order to have access the the API for GMP
in ATS2.

The following code (taken out of a file of the name fact.dats) demonstrates
a simple way
to make light use of intinf (integers of unbounded precision):

(* ****** ****** )
(

//
// How to compile:
//
patscc -DATS_MEMALLOC_LIBC -I ${PATSHOME}/contrib -o fact fact.dats -lgmp
)
(
****** ****** )
//
#include
"share/atspre_define.hats"
#include
"share/atspre_staload.hats"
//
(
****** ****** *)

staload "{$LIBATSHWXI}/intinf/SATS/intinf_t.sats"
staload _ = "{$LIBATSHWXI}/intinf/DATS/intinf_t.dats"
staload _ = “{$LIBATSHWXI}/intinf/DATS/intinf_vt.dats”

(* ****** ****** *)

fun
fact{n:nat}
(n: int n): Intinf =
if n > 0 then n * fact(n-1) else int2intinf(1)
// end of [fact]

(* ****** ****** *)

implement
main (
argc, argv
) = let
val N = 10
val N = (
if argc >= 2 then g0string2int (argv[1]) else N
) : int // end of [val]
val N = g1ofg0_int (N)
val () = assertloc (N >= 0)
//
val res = fact (N)
val () = println! (“fact(”, N, ") = ", res)
//
in
0(normalexit)
end // end of [main]

(* ****** ****** *)

(* end of [fact.dats] *)

Here is some output:

fact(1000) =
40238726007709377354370243392300398571937486421071463254379991042993851239862902059204420848696940480047998861019719605863166687299480855
890132382966994459099742450408707375991882362772718873251977950595099527612087497546249704360141827809464649629105639388743788648733711918104582578364
784997701247663288983595573543251318532395846307555740911426241747434934755342864657661166779739666882029120737914385371958824980812686783837455973174
613608537953452422158659320192809087829730843139284440328123155861103697680135730421616874760967587134831202547858932076716913244842623613141250878020
800026168315102734182797770478463586817016436502415369139828126481021309276124489635992870511496497541990934222156683257208082133318611681155361583654
698404670897560290095053761647584772842188967964624494516076535340819890138544248798495995331910172335555660213945039973628075013783761530712776192684
903435262520001588853514733161170210396817592151090778801939317811419454525722386554146106289218796022383897147608850627686296714667469756291123408243
920816015378088989396451826324367161676217916890977991190375403127462228998800519544441428201218736174599264295658174662830295557029902432415318161721
046583203678690611726015878352075151628422554026517048330422614397428693306169089796848259012545832716822645806652676995865268227280707578139185817888
965220816434834482599326604336766017699961283186078838615027946595513115655203609398818061213855860030143569452722420634463179746059468257310379008402
443243846565724501440282188525247093519062092902313649327349756551395872055965422874977401141334696271542284586237738753823048386568897646192738381490
014076731044664025989949022222176590433990188601856652648506179970235619389701786004081188972991831102117122984590164192106888438712185564612496079872
290851929681937238864261483965738229112312502418664935314397013742853192664987533721894069428143411852015801412334482801505139969429015348307764456909
907315243327828826986460278986432113908350621709500259738986355427719674282224875758676575234422020757363056949882508796892816275384886339690995982628
095612145099487170124451646126037902930912088908694202851064018215439945715680594187274899809425474217358240106367740459574178516082923013535808184009
699637252423056085590370062427124341690900415369010593398383577793941097002775347200000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000

Here is a linear version that frees all the allocated memory at the end:

(* ****** ****** )
(

//
// How to compile:
//
patscc -DATS_MEMALLOC_LIBC -I ${PATSHOME}/contrib -o fact fact.dats -lgmp
//
// How to test:
valgrind ./fact 1000
//
)
(
****** ****** )
//
#include
“share/atspre_define.hats”
#include
“share/atspre_staload.hats”
//
(
****** ****** *)

staload “{$LIBATSHWXI}/intinf/SATS/intinf_vt.sats”
staload _ = “{$LIBATSHWXI}/intinf/DATS/intinf_t.dats”
staload _ = “{$LIBATSHWXI}/intinf/DATS/intinf_vt.dats”

(* ****** ****** *)

fun
fact{n:nat}
(
n: int (n)
) : Intinf = let
in
//
if n > 0 then let
val r1 = fact (n-1)
in
mul_int_intinf0 (n, r1)
end else
int2intinf (1)
// end of [if]
//
end // end of [fact]

(* ****** ****** *)

implement
main (
argc, argv
) = let
val N = 10
val N = (
if argc >= 2 then g0string2int (argv[1]) else N
) : int // end of [val]
val N = g1ofg0_int (N)
val () = assertloc (N >= 0)
//
val res = fact (N)
val () = println! (“fact(”, N, ") = ", res)
val () = intinf_free (res)
//
in
0(normalexit)
end // end of [main]

(* ****** ****** *)

(* end of [fact.dats] *)On Wednesday, December 25, 2013 5:14:52 PM UTC-5, gmhwxi wrote:

I would like to point out that GMP is now out of ATS2.

You need to have ATS2-contrib in order to have access the the API for GMP
in ATS2.

The following code (taken out of a file of the name fact.dats)
demonstrates a simple way
to make light use of intinf (integers of unbounded precision):

(* ****** ****** )
(

//
// How to compile:
//
patscc -DATS_MEMALLOC_LIBC -I ${PATSHOME}/contrib -o fact fact.dats -lgmp
)
(
****** ****** )
//
#include
“share/atspre_define.hats”
#include
“share/atspre_staload.hats”
//
(
****** ****** *)

staload “{$LIBATSHWXI}/intinf/SATS/intinf_t.sats”
staload _ = “{$LIBATSHWXI}/intinf/DATS/intinf_t.dats”
staload _ = “{$LIBATSHWXI}/intinf/DATS/intinf_vt.dats”

(* ****** ****** *)

fun
fact{n:nat}
(n: int n): Intinf =
if n > 0 then n * fact(n-1) else int2intinf(1)
// end of [fact]

(* ****** ****** *)

implement
main (
argc, argv
) = let
val N = 10
val N = (
if argc >= 2 then g0string2int (argv[1]) else N
) : int // end of [val]
val N = g1ofg0_int (N)
val () = assertloc (N >= 0)
//
val res = fact (N)
val () = println! (“fact(”, N, ") = ", res)
//
in
0(normalexit)
end // end of [main]

(* ****** ****** *)

(* end of [fact.dats] *)

Here is some output:

fact(1000) =
40238726007709377354370243392300398571937486421071463254379991042993851239862902059204420848696940480047998861019719605863166687299480855\

890132382966994459099742450408707375991882362772718873251977950595099527612087497546249704360141827809464649629105639388743788648733711918104582578364\

784997701247663288983595573543251318532395846307555740911426241747434934755342864657661166779739666882029120737914385371958824980812686783837455973174\

613608537953452422158659320192809087829730843139284440328123155861103697680135730421616874760967587134831202547858932076716913244842623613141250878020\

800026168315102734182797770478463586817016436502415369139828126481021309276124489635992870511496497541990934222156683257208082133318611681155361583654\

698404670897560290095053761647584772842188967964624494516076535340819890138544248798495995331910172335555660213945039973628075013783761530712776192684\

903435262520001588853514733161170210396817592151090778801939317811419454525722386554146106289218796022383897147608850627686296714667469756291123408243\

920816015378088989396451826324367161676217916890977991190375403127462228998800519544441428201218736174599264295658174662830295557029902432415318161721\

046583203678690611726015878352075151628422554026517048330422614397428693306169089796848259012545832716822645806652676995865268227280707578139185817888\

965220816434834482599326604336766017699961283186078838615027946595513115655203609398818061213855860030143569452722420634463179746059468257310379008402\

443243846565724501440282188525247093519062092902313649327349756551395872055965422874977401141334696271542284586237738753823048386568897646192738381490\

014076731044664025989949022222176590433990188601856652648506179970235619389701786004081188972991831102117122984590164192106888438712185564612496079872\

290851929681937238864261483965738229112312502418664935314397013742853192664987533721894069428143411852015801412334482801505139969429015348307764456909\

907315243327828826986460278986432113908350621709500259738986355427719674282224875758676575234422020757363056949882508796892816275384886339690995982628\

095612145099487170124451646126037902930912088908694202851064018215439945715680594187274899809425474217358240106367740459574178516082923013535808184009\

699637252423056085590370062427124341690900415369010593398383577793941097002775347200000000000000000000000000000000000000000000000000000000000000000000\

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000