pure-lang-svn Mailing List for Pure (Page 21)
Status: Beta
Brought to you by:
agraef
You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
(141) |
Jun
(184) |
Jul
(97) |
Aug
(232) |
Sep
(196) |
Oct
|
Nov
|
Dec
|
---|
From: <ag...@us...> - 2008-07-02 20:46:18
|
Revision: 370 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=370&view=rev Author: agraef Date: 2008-07-02 13:46:27 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Add double->rational conversion. Modified Paths: -------------- pure/trunk/lib/math.pure pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-02 19:26:25 UTC (rev 369) +++ pure/trunk/lib/math.pure 2008-07-02 20:46:27 UTC (rev 370) @@ -418,12 +418,16 @@ /* Conversions. */ +extern expr* pure_rational(double); + rational x@(_%_) = x; rational x::int | rational x::bigint = x%1; -// TODO: Need to rationalize doubles here. Currently this is a no-op. -rational x::double = x; +/* The conversion from double doesn't do any rounding, so it is guaranteed + that converting the resulting rational back to double reconstructs the + original value. */ +rational x::double = n%d when n,d = pure_rational x end; rational (x+:y) = rational x +: rational y; rational (x<:y) = rational x <: rational y; Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-07-02 19:26:25 UTC (rev 369) +++ pure/trunk/runtime.cc 2008-07-02 20:46:27 UTC (rev 370) @@ -1786,6 +1786,22 @@ } extern "C" +pure_expr *pure_rational(double d) +{ + pure_expr *u = pure_bigint(0, 0); + pure_expr *v = pure_bigint(0, 0); + mpz_t& x = u->data.z; + mpz_t& y = v->data.z; + mpq_t q; + mpq_init(q); + mpq_set_d(q, d); + mpq_get_num(x, q); + mpq_get_den(y, q); + mpq_clear(q); + return pure_tuplel(2, u, v); +} + +extern "C" pure_expr *bigint_neg(mpz_t x) { pure_expr *u = pure_bigint(0, 0); Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-07-02 19:26:25 UTC (rev 369) +++ pure/trunk/runtime.h 2008-07-02 20:46:27 UTC (rev 370) @@ -415,6 +415,11 @@ pure_expr *pure_bigintval(pure_expr *x); pure_expr *pure_pointerval(pure_expr *x); +/* Convert a double to a rational number, without rounding. Returns a pair n,d + of two bigint values, where n is the numerator and d the denominator. */ + +pure_expr *pure_rational(double d); + /* Construct a "byte string" from a string. The result is a raw pointer object pointing to the converted string. The original string is copied (and, in the case of pure_byte_cstring, converted to the system encoding). The This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 19:26:16
|
Revision: 369 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=369&view=rev Author: agraef Date: 2008-07-02 12:26:25 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Bugfix: double->bigint conversion not working. Modified Paths: -------------- pure/trunk/runtime.cc Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-07-02 08:24:19 UTC (rev 368) +++ pure/trunk/runtime.cc 2008-07-02 19:26:25 UTC (rev 369) @@ -1774,7 +1774,7 @@ return x; else if (x->tag == EXPR::PTR) return pointer_to_bigint(x->data.p); - else if (x->tag != EXPR::INT && x->tag == EXPR::DBL) + else if (x->tag != EXPR::INT && x->tag != EXPR::DBL) return 0; pure_expr *y = pure_bigint(0, 0); mpz_t& z = y->data.z; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 08:24:20
|
Revision: 368 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=368&view=rev Author: agraef Date: 2008-07-02 01:24:19 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Fix typo. Modified Paths: -------------- pure/trunk/examples/set.pure Modified: pure/trunk/examples/set.pure =================================================================== --- pure/trunk/examples/set.pure 2008-07-02 08:15:48 UTC (rev 367) +++ pure/trunk/examples/set.pure 2008-07-02 08:24:19 UTC (rev 368) @@ -138,7 +138,7 @@ table (-1) ( 1) = [( 0), 0, 1]; end; -// delete a meber by key from the data structure +// delete a member by key from the data structure delete (t@Set m) y::int | delete (t@Set m) y::string | delete (t@Set m) y | This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 08:15:40
|
Revision: 367 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=367&view=rev Author: agraef Date: 2008-07-02 01:15:48 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Fix up copyright message. Modified Paths: -------------- pure/trunk/examples/set.pure Modified: pure/trunk/examples/set.pure =================================================================== --- pure/trunk/examples/set.pure 2008-07-02 08:08:35 UTC (rev 366) +++ pure/trunk/examples/set.pure 2008-07-02 08:15:48 UTC (rev 367) @@ -1,7 +1,7 @@ /* Pure's set and bag data types based on AVL trees. */ -/* Copyright (c) 2008 by Albert Graef <Dr....@t-...> - and Jiri Spitz <jir...@bl...>. +/* Copyright (c) 2008 by Albert Graef <Dr....@t-...>. + Copyright (c) 2008 by Jiri Spitz <jir...@bl...>. This file is part of the Pure programming language and system. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 08:08:26
|
Revision: 366 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=366&view=rev Author: agraef Date: 2008-07-02 01:08:35 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Add rational tests. Added Paths: ----------- pure/trunk/test/test014.log pure/trunk/test/test014.pure Added: pure/trunk/test/test014.log =================================================================== --- pure/trunk/test/test014.log (rev 0) +++ pure/trunk/test/test014.log 2008-07-02 08:08:35 UTC (rev 366) @@ -0,0 +1,6313 @@ +def inf = 1e+307*1e+307; +def nan = inf-inf; +abs x/*0:1*/::int = if x/*0:1*/>=0 then x/*0:1*/ else -x/*0:1*/; +abs x/*0:1*/::bigint = if x/*0:1*/>=0 then x/*0:1*/ else -x/*0:1*/; +abs x/*0:1*/::double = if x/*0:1*/>=0 then x/*0:1*/ else -x/*0:1*/; +sgn x/*0:1*/::int = if x/*0:1*/>0 then 1 else if x/*0:1*/<0 then -1 else 0; +sgn x/*0:1*/::bigint = if x/*0:1*/>0 then 1 else if x/*0:1*/<0 then -1 else 0; +sgn x/*0:1*/::double = if x/*0:1*/>0 then 1 else if x/*0:1*/<0 then -1 else 0; +min x/*0:01*/ y/*0:1*/ = if x/*0:01*/<=y/*0:1*/ then x/*0:01*/ else y/*0:1*/; +max x/*0:01*/ y/*0:1*/ = if x/*0:01*/>=y/*0:1*/ then x/*0:01*/ else y/*0:1*/; +succ x/*0:1*/ = x/*0:1*/+1; +pred x/*0:1*/ = x/*0:1*/-1; +floor x/*0:1*/::int = x/*0:1*/; +floor x/*0:1*/::bigint = x/*0:1*/; +ceil x/*0:1*/::int = x/*0:1*/; +ceil x/*0:1*/::bigint = x/*0:1*/; +round x/*0:1*/::int = x/*0:1*/; +round x/*0:1*/::bigint = x/*0:1*/; +trunc x/*0:1*/::int = x/*0:1*/; +trunc x/*0:1*/::bigint = x/*0:1*/; +frac x/*0:1*/::int = x/*0:1*/-trunc x/*0:1*/; +frac x/*0:1*/::bigint = x/*0:1*/-trunc x/*0:1*/; +frac x/*0:1*/::double = x/*0:1*/-trunc x/*0:1*/; +sqrt x/*0:1*/::double = c_sqrt x/*0:1*/ if x/*0:1*/>=0; +sqrt x/*0:1*/::int = sqrt (double x/*0:1*/); +sqrt x/*0:1*/::bigint = sqrt (double x/*0:1*/); +ln x/*0:1*/::double = c_log x/*0:1*/ if x/*0:1*/>=0.0; +log x/*0:1*/::double = c_log x/*0:1*//c_log 10.0 if x/*0:1*/>=0.0; +exp x/*0:1*/::int = exp (double x/*0:1*/); +exp x/*0:1*/::bigint = exp (double x/*0:1*/); +ln x/*0:1*/::int = ln (double x/*0:1*/); +ln x/*0:1*/::bigint = ln (double x/*0:1*/); +log x/*0:1*/::int = log (double x/*0:1*/); +log x/*0:1*/::bigint = log (double x/*0:1*/); +{ + rule #0: max x y = if x>=y then x else y + state 0: #0 + <var> state 1 + state 1: #0 + <var> state 2 + state 2: #0 +} +{ + rule #0: abs x::int = if x>=0 then x else -x + rule #1: abs x::bigint = if x>=0 then x else -x + rule #2: abs x::double = if x>=0 then x else -x + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #0 + state 2: #1 + state 3: #2 +} +{ + rule #0: sgn x::int = if x>0 then 1 else if x<0 then -1 else 0 + rule #1: sgn x::bigint = if x>0 then 1 else if x<0 then -1 else 0 + rule #2: sgn x::double = if x>0 then 1 else if x<0 then -1 else 0 + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #0 + state 2: #1 + state 3: #2 +} +{ + rule #0: min x y = if x<=y then x else y + state 0: #0 + <var> state 1 + state 1: #0 + <var> state 2 + state 2: #0 +} +{ + rule #0: succ x = x+1 + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: pred x = x-1 + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: floor x::int = x + rule #1: floor x::bigint = x + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: ceil x::int = x + rule #1: ceil x::bigint = x + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: round x::int = x + rule #1: round x::bigint = x + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: trunc x::int = x + rule #1: trunc x::bigint = x + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: frac x::int = x-trunc x + rule #1: frac x::bigint = x-trunc x + rule #2: frac x::double = x-trunc x + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #0 + state 2: #1 + state 3: #2 +} +{ + rule #0: sqrt x::double = c_sqrt x if x>=0 + rule #1: sqrt x::int = sqrt (double x) + rule #2: sqrt x::bigint = sqrt (double x) + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #1 + state 2: #2 + state 3: #0 +} +{ + rule #0: exp x::int = exp (double x) + rule #1: exp x::bigint = exp (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: ln x::double = c_log x if x>=0.0 + rule #1: ln x::int = ln (double x) + rule #2: ln x::bigint = ln (double x) + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #1 + state 2: #2 + state 3: #0 +} +{ + rule #0: log x::double = c_log x/c_log 10.0 if x>=0.0 + rule #1: log x::int = log (double x) + rule #2: log x::bigint = log (double x) + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #1 + state 2: #2 + state 3: #0 +} +def e = exp 1.0; +sin x/*0:1*/::int = sin (double x/*0:1*/); +sin x/*0:1*/::bigint = sin (double x/*0:1*/); +cos x/*0:1*/::int = cos (double x/*0:1*/); +cos x/*0:1*/::bigint = cos (double x/*0:1*/); +tan x/*0:1*/::int = tan (double x/*0:1*/); +tan x/*0:1*/::bigint = tan (double x/*0:1*/); +asin x/*0:1*/::int = asin (double x/*0:1*/); +asin x/*0:1*/::bigint = asin (double x/*0:1*/); +acos x/*0:1*/::int = acos (double x/*0:1*/); +acos x/*0:1*/::bigint = acos (double x/*0:1*/); +atan x/*0:1*/::int = atan (double x/*0:1*/); +atan x/*0:1*/::bigint = atan (double x/*0:1*/); +atan2 x/*0:01*/::int y/*0:1*/::int = atan2 (double x/*0:01*/) (double y/*0:1*/); +atan2 x/*0:01*/::bigint y/*0:1*/::bigint = atan2 (double x/*0:01*/) (double y/*0:1*/); +atan2 x/*0:01*/::bigint y/*0:1*/::int = atan2 (double x/*0:01*/) (double y/*0:1*/); +atan2 x/*0:01*/::int y/*0:1*/::bigint = atan2 (double x/*0:01*/) (double y/*0:1*/); +atan2 x/*0:01*/::int y/*0:1*/::double = atan2 (double x/*0:01*/) y/*0:1*/; +atan2 x/*0:01*/::bigint y/*0:1*/::double = atan2 (double x/*0:01*/) y/*0:1*/; +atan2 x/*0:01*/::double y/*0:1*/::int = atan2 x/*0:01*/ (double y/*0:1*/); +atan2 x/*0:01*/::double y/*0:1*/::bigint = atan2 x/*0:01*/ (double y/*0:1*/); +{ + rule #0: sin x::int = sin (double x) + rule #1: sin x::bigint = sin (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: cos x::int = cos (double x) + rule #1: cos x::bigint = cos (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: tan x::int = tan (double x) + rule #1: tan x::bigint = tan (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: asin x::int = asin (double x) + rule #1: asin x::bigint = asin (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: acos x::int = acos (double x) + rule #1: acos x::bigint = acos (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: atan x::int = atan (double x) + rule #1: atan x::bigint = atan (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: atan2 x::int y::int = atan2 (double x) (double y) + rule #1: atan2 x::bigint y::bigint = atan2 (double x) (double y) + rule #2: atan2 x::bigint y::int = atan2 (double x) (double y) + rule #3: atan2 x::int y::bigint = atan2 (double x) (double y) + rule #4: atan2 x::int y::double = atan2 (double x) y + rule #5: atan2 x::bigint y::double = atan2 (double x) y + rule #6: atan2 x::double y::int = atan2 x (double y) + rule #7: atan2 x::double y::bigint = atan2 x (double y) + state 0: #0 #1 #2 #3 #4 #5 #6 #7 + <var>::int state 1 + <var>::bigint state 5 + <var>::double state 9 + state 1: #0 #3 #4 + <var>::int state 2 + <var>::bigint state 3 + <var>::double state 4 + state 2: #0 + state 3: #3 + state 4: #4 + state 5: #1 #2 #5 + <var>::int state 6 + <var>::bigint state 7 + <var>::double state 8 + state 6: #2 + state 7: #1 + state 8: #5 + state 9: #6 #7 + <var>::int state 10 + <var>::bigint state 11 + state 10: #6 + state 11: #7 +} +def pi = 4.0*atan 1.0; +acosh x/*0:1*/::double = c_acosh x/*0:1*/ if x/*0:1*/>=1.0; +atanh x/*0:1*/::double = c_atanh x/*0:1*/ if abs x/*0:1*/<=1.0; +sinh x/*0:1*/::int = sinh (double x/*0:1*/); +sinh x/*0:1*/::bigint = sinh (double x/*0:1*/); +cosh x/*0:1*/::int = cosh (double x/*0:1*/); +cosh x/*0:1*/::bigint = cosh (double x/*0:1*/); +tanh x/*0:1*/::int = tanh (double x/*0:1*/); +tanh x/*0:1*/::bigint = tanh (double x/*0:1*/); +asinh x/*0:1*/::int = asinh (double x/*0:1*/); +asinh x/*0:1*/::bigint = asinh (double x/*0:1*/); +acosh x/*0:1*/::int = acosh (double x/*0:1*/); +acosh x/*0:1*/::bigint = acosh (double x/*0:1*/); +atanh x/*0:1*/::int = atanh (double x/*0:1*/); +atanh x/*0:1*/::bigint = atanh (double x/*0:1*/); +r/*0:01*/::int<:t/*0:1*/ = -r/*0:01*/<:t/*0:1*/+3.14159265358979 if r/*0:01*/<0; +r/*0:01*/::bigint<:t/*0:1*/ = -r/*0:01*/<:t/*0:1*/+3.14159265358979 if r/*0:01*/<0; +r/*0:01*/::double<:t/*0:1*/ = -r/*0:01*/<:t/*0:1*/+3.14159265358979 if r/*0:01*/<0; +r/*0:01*/<:t/*0:1*/::int = r/*0:01*/<:atan2 (sin t/*0:1*/) (cos t/*0:1*/) if t/*0:1*/<-3.14159265358979||t/*0:1*/>3.14159265358979; +r/*0:01*/<:t/*0:1*/::bigint = r/*0:01*/<:atan2 (sin t/*0:1*/) (cos t/*0:1*/) if t/*0:1*/<-3.14159265358979||t/*0:1*/>3.14159265358979; +r/*0:01*/<:t/*0:1*/::double = r/*0:01*/<:atan2 (sin t/*0:1*/) (cos t/*0:1*/) if t/*0:1*/<-3.14159265358979||t/*0:1*/>3.14159265358979; +r/*0:01*/<:t/*0:1*/::int = r/*0:01*/<:3.14159265358979 if t/*0:1*/==-3.14159265358979; +r/*0:01*/<:t/*0:1*/::bigint = r/*0:01*/<:3.14159265358979 if t/*0:1*/==-3.14159265358979; +r/*0:01*/<:t/*0:1*/::double = r/*0:01*/<:3.14159265358979 if t/*0:1*/==-3.14159265358979; +{ + rule #0: sinh x::int = sinh (double x) + rule #1: sinh x::bigint = sinh (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: cosh x::int = cosh (double x) + rule #1: cosh x::bigint = cosh (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: tanh x::int = tanh (double x) + rule #1: tanh x::bigint = tanh (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: asinh x::int = asinh (double x) + rule #1: asinh x::bigint = asinh (double x) + state 0: #0 #1 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 +} +{ + rule #0: acosh x::double = c_acosh x if x>=1.0 + rule #1: acosh x::int = acosh (double x) + rule #2: acosh x::bigint = acosh (double x) + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #1 + state 2: #2 + state 3: #0 +} +{ + rule #0: atanh x::double = c_atanh x if abs x<=1.0 + rule #1: atanh x::int = atanh (double x) + rule #2: atanh x::bigint = atanh (double x) + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + <var>::double state 3 + state 1: #1 + state 2: #2 + state 3: #0 +} +{ + rule #0: r::int<:t = -r<:t+3.14159265358979 if r<0 + rule #1: r::bigint<:t = -r<:t+3.14159265358979 if r<0 + rule #2: r::double<:t = -r<:t+3.14159265358979 if r<0 + rule #3: r<:t::int = r<:atan2 (sin t) (cos t) if t<-3.14159265358979||t>3.14159265358979 + rule #4: r<:t::bigint = r<:atan2 (sin t) (cos t) if t<-3.14159265358979||t>3.14159265358979 + rule #5: r<:t::double = r<:atan2 (sin t) (cos t) if t<-3.14159265358979||t>3.14159265358979 + rule #6: r<:t::int = r<:3.14159265358979 if t==-3.14159265358979 + rule #7: r<:t::bigint = r<:3.14159265358979 if t==-3.14159265358979 + rule #8: r<:t::double = r<:3.14159265358979 if t==-3.14159265358979 + state 0: #0 #1 #2 #3 #4 #5 #6 #7 #8 + <var> state 1 + <var>::int state 5 + <var>::bigint state 10 + <var>::double state 15 + state 1: #3 #4 #5 #6 #7 #8 + <var>::int state 2 + <var>::bigint state 3 + <var>::double state 4 + state 2: #3 #6 + state 3: #4 #7 + state 4: #5 #8 + state 5: #0 #3 #4 #5 #6 #7 #8 + <var> state 6 + <var>::int state 7 + <var>::bigint state 8 + <var>::double state 9 + state 6: #0 + state 7: #0 #3 #6 + state 8: #0 #4 #7 + state 9: #0 #5 #8 + state 10: #1 #3 #4 #5 #6 #7 #8 + <var> state 11 + <var>::int state 12 + <var>::bigint state 13 + <var>::double state 14 + state 11: #1 + state 12: #1 #3 #6 + state 13: #1 #4 #7 + state 14: #1 #5 #8 + state 15: #2 #3 #4 #5 #6 #7 #8 + <var> state 16 + <var>::int state 17 + <var>::bigint state 18 + <var>::double state 19 + state 16: #2 + state 17: #2 #3 #6 + state 18: #2 #4 #7 + state 19: #2 #5 #8 +} +def i = 0+:1; +complex z@(x/*0:101*/+:y/*0:11*/) = z/*0:1*/; +complex z@(r/*0:101*/<:t/*0:11*/) = z/*0:1*/; +complex x/*0:1*/::int = x/*0:1*/+:0; +complex x/*0:1*/::bigint = x/*0:1*/+:0; +complex x/*0:1*/::double = x/*0:1*/+:0.0; +polar (x/*0:101*/+:y/*0:11*/) = sqrt (x/*0:101*/*x/*0:101*/+y/*0:11*/*y/*0:11*/)<:atan2 y/*0:11*/ x/*0:101*/; +rect (r/*0:101*/<:t/*0:11*/) = r/*0:101*/*cos t/*0:11*/+:r/*0:101*/*sin t/*0:11*/; +polar x/*0:1*/::int = x/*0:1*/<:0; +polar x/*0:1*/::bigint = x/*0:1*/<:0; +polar x/*0:1*/::double = x/*0:1*/<:0.0; +rect x/*0:1*/::int = x/*0:1*/+:0; +rect x/*0:1*/::bigint = x/*0:1*/+:0; +rect x/*0:1*/::double = x/*0:1*/+:0.0; +cis t/*0:1*/ = rect (1<:t/*0:1*/); +abs (x/*0:101*/+:y/*0:11*/) = sqrt (x/*0:101*/*x/*0:101*/+y/*0:11*/*y/*0:11*/); +abs (r/*0:101*/<:t/*0:11*/) = r/*0:101*/; +arg (x/*0:101*/+:y/*0:11*/) = atan2 y/*0:11*/ x/*0:101*/; +arg (r/*0:101*/<:t/*0:11*/) = t/*0:11*/; +arg x/*0:1*/::int = atan2 0 x/*0:1*/; +arg x/*0:1*/::bigint = atan2 0 x/*0:1*/; +arg x/*0:1*/::double = atan2 0 x/*0:1*/; +re (x/*0:101*/+:y/*0:11*/) = x/*0:101*/; +re (r/*0:101*/<:t/*0:11*/) = r/*0:101*/*sin t/*0:11*/; +re x/*0:1*/::int = x/*0:1*/; +re x/*0:1*/::bigint = x/*0:1*/; +re x/*0:1*/::double = x/*0:1*/; +im (x/*0:101*/+:y/*0:11*/) = y/*0:11*/; +im (r/*0:101*/<:t/*0:11*/) = r/*0:101*/*cos t/*0:11*/; +im x/*0:1*/::int = 0; +im x/*0:1*/::bigint = 0L; +im x/*0:1*/::double = 0.0; +conj (x/*0:101*/+:y/*0:11*/) = x/*0:101*/+:-y/*0:11*/; +conj (r/*0:101*/<:t/*0:11*/) = r/*0:101*/<:-t/*0:11*/; +conj x/*0:1*/::int = x/*0:1*/; +conj x/*0:1*/::bigint = x/*0:1*/; +conj x/*0:1*/::double = x/*0:1*/; +sqrt (x/*0:101*/+:y/*0:11*/) = sqrt (x/*0:101*/*x/*0:101*/+y/*0:11*/*y/*0:11*/)*(cos (t/2)+:sin (t/2)); +sqrt (r/*0:101*/<:t/*0:11*/) = sqrt r/*0:101*/<:t/*0:11*//2; +sqrt x/*0:1*/::double = 0.0+:sqrt (-x/*0:1*/) if x/*0:1*/<0; +exp (x/*0:101*/+:y/*0:11*/) = exp x/*0:101*/*(cos y/*0:11*/+:sin y/*0:11*/); +exp (r/*0:101*/<:t/*0:11*/) = exp (r/*0:101*/*cos t/*0:11*/)<:r/*0:101*/*sin t/*0:11*/; +ln z@(x/*0:101*/+:y/*0:11*/) = ln (abs z/*0:1*/)+:arg z/*0:1*/; +ln (r/*0:101*/<:t/*0:11*/) = polar (ln r/*0:101*/+:t/*0:11*/); +log z@(x/*0:101*/+:y/*0:11*/) = ln z/*0:1*//ln 10; +log z@(r/*0:101*/<:t/*0:11*/) = ln z/*0:1*//ln 10; +ln x/*0:1*/::double = ln (abs x/*0:1*/)+:arg x/*0:1*/ if x/*0:1*/<0; +log x/*0:1*/::double = ln x/*0:1*//ln 10 if x/*0:1*/<0; +sin (x/*0:101*/+:y/*0:11*/) = sin x/*0:101*/*cosh y/*0:11*/+:cos x/*0:101*/*sinh y/*0:11*/; +cos (x/*0:101*/+:y/*0:11*/) = cos x/*0:101*/*cosh y/*0:11*/+:-sin x/*0:101*/*sinh y/*0:11*/; +tan (x/*0:101*/+:y/*0:11*/) = (sin (2*x/*0:101*/)+:sinh (2*y/*0:11*/))/(cos (2*x/*0:101*/)+cosh (2*y/*0:11*/)); +sin z@(r/*0:101*/<:t/*0:11*/) = polar$sin$rect z/*0:1*/; +cos z@(r/*0:101*/<:t/*0:11*/) = polar$cos$rect z/*0:1*/; +tan z@(r/*0:101*/<:t/*0:11*/) = polar$tan$rect z/*0:1*/; +asin z@(x/*0:101*/+:y/*0:11*/) = -(0+:1)*ln ((0+:1)*z/*0:1*/+sqrt (1-z/*0:1*/*z/*0:1*/)); +asin z@(r/*0:101*/<:t/*0:11*/) = -(0+:1)*ln ((0+:1)*z/*0:1*/+sqrt (1-z/*0:1*/*z/*0:1*/)); +acos z@(x/*0:101*/+:y/*0:11*/) = -(0+:1)*ln (z/*0:1*/+sqrt (z/*0:1*/*z/*0:1*/-1)); +acos z@(r/*0:101*/<:t/*0:11*/) = -(0+:1)*ln (z/*0:1*/+sqrt (z/*0:1*/*z/*0:1*/-1)); +atan z@(x/*0:101*/+:y/*0:11*/) = 0.0+:inf if z/*0:1*/==0+:1; +atan z@(r/*0:101*/<:t/*0:11*/) = 0.0+:inf if z/*0:1*/==0+:1; +atan z@(x/*0:101*/+:y/*0:11*/) = 0.0+:-inf if z/*0:1*/==-(0+:1); +atan z@(r/*0:101*/<:t/*0:11*/) = 0.0+:-inf if z/*0:1*/==-(0+:1); +atan z@(x/*0:101*/+:y/*0:11*/) = -(0+:1)*0.5*ln ((1+(0+:1)*z/*0:1*/)/(1-(0+:1)*z/*0:1*/)); +atan z@(r/*0:101*/<:t/*0:11*/) = -(0+:1)*0.5*ln ((1+(0+:1)*z/*0:1*/)/(1-(0+:1)*z/*0:1*/)); +sinh (x/*0:101*/+:y/*0:11*/) = sinh x/*0:101*/*cos y/*0:11*/+:cosh x/*0:101*/*sin y/*0:11*/; +cosh (x/*0:101*/+:y/*0:11*/) = cosh x/*0:101*/*cos y/*0:11*/+:sinh x/*0:101*/*sin y/*0:11*/; +tanh (x/*0:101*/+:y/*0:11*/) = (sinh (2*x/*0:101*/)+:sin (2*y/*0:11*/))/(cosh (2*x/*0:101*/)+cos (2*y/*0:11*/)); +sinh z@(r/*0:101*/<:t/*0:11*/) = polar$sinh$rect z/*0:1*/; +cosh z@(r/*0:101*/<:t/*0:11*/) = polar$cosh$rect z/*0:1*/; +tanh z@(r/*0:101*/<:t/*0:11*/) = polar$tanh$rect z/*0:1*/; +asinh z@(x/*0:101*/+:y/*0:11*/) = ln (z/*0:1*/+sqrt (z/*0:1*/*z/*0:1*/+1)); +asinh z@(r/*0:101*/<:t/*0:11*/) = ln (z/*0:1*/+sqrt (z/*0:1*/*z/*0:1*/+1)); +acosh z@(x/*0:101*/+:y/*0:11*/) = ln (z/*0:1*/+sqrt (z/*0:1*/*z/*0:1*/-1)); +acosh z@(r/*0:101*/<:t/*0:11*/) = ln (z/*0:1*/+sqrt (z/*0:1*/*z/*0:1*/-1)); +atanh z@(x/*0:101*/+:y/*0:11*/) = inf+:0.0 if z/*0:1*/==1; +atanh z@(r/*0:101*/<:t/*0:11*/) = inf+:0.0 if z/*0:1*/==1; +atanh z@(x/*0:101*/+:y/*0:11*/) = -inf+:0.0 if z/*0:1*/==-1; +atanh z@(r/*0:101*/<:t/*0:11*/) = -inf+:0.0 if z/*0:1*/==-1; +atanh z@(x/*0:101*/+:y/*0:11*/) = ln ((1+z/*0:1*/)/(1-z/*0:1*/))/2; +atanh z@(r/*0:101*/<:t/*0:11*/) = ln ((1+z/*0:1*/)/(1-z/*0:1*/))/2; +acosh x/*0:1*/::double = acosh (x/*0:1*/+:0); +atanh x/*0:1*/::double = atanh (x/*0:1*/+:0); +-(x/*0:101*/+:y/*0:11*/) = -x/*0:101*/+:-y/*0:11*/; +-(r/*0:101*/<:t/*0:11*/) = r/*0:101*/<:t/*0:11*/+3.14159265358979; +(x1/*0:0101*/+:y1/*0:011*/)+(x2/*0:101*/+:y2/*0:11*/) = x1/*0:0101*/+x2/*0:101*/+:y1/*0:011*/+y2/*0:11*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)+z2@(r2/*0:101*/<:t2/*0:11*/) = polar$rect z1/*0:01*/+rect z2/*0:1*/; +(x1/*0:0101*/+:y1/*0:011*/)-(x2/*0:101*/+:y2/*0:11*/) = x1/*0:0101*/-x2/*0:101*/+:y1/*0:011*/-y2/*0:11*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)-z2@(r2/*0:101*/<:t2/*0:11*/) = polar$rect z1/*0:01*/-rect z2/*0:1*/; +(x1/*0:0101*/+:y1/*0:011*/)*(x2/*0:101*/+:y2/*0:11*/) = x1/*0:0101*/*x2/*0:101*/-y1/*0:011*/*y2/*0:11*/+:x1/*0:0101*/*y2/*0:11*/+y1/*0:011*/*x2/*0:101*/; +(r1/*0:0101*/<:t1/*0:011*/)*(r2/*0:101*/<:t2/*0:11*/) = r1/*0:0101*/*r2/*0:101*/<:t1/*0:011*/+t2/*0:11*/; +(x1/*0:0101*/+:y1/*0:011*/)/(x2/*0:101*/+:y2/*0:11*/) = (x1/*0:0101*/*x2/*0:101*/+y1/*0:011*/*y2/*0:11*/+:y1/*0:011*/*x2/*0:101*/-x1/*0:0101*/*y2/*0:11*/)/(x2/*0:101*/*x2/*0:101*/+y2/*0:11*/*y2/*0:11*/); +(r1/*0:0101*/<:t1/*0:011*/)/(r2/*0:101*/<:t2/*0:11*/) = r1/*0:0101*//r2/*0:101*/<:t1/*0:011*/-t2/*0:11*/; +z1@(x1/*0:0101*/+:y1/*0:011*/)+z2@(r2/*0:101*/<:t2/*0:11*/) = z1/*0:01*/+rect z2/*0:1*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)+z2@(x2/*0:101*/+:y2/*0:11*/) = rect z1/*0:01*/+z2/*0:1*/; +z1@(x1/*0:0101*/+:y1/*0:011*/)-z2@(r2/*0:101*/<:t2/*0:11*/) = z1/*0:01*/-rect z2/*0:1*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)-z2@(x2/*0:101*/+:y2/*0:11*/) = rect z1/*0:01*/-z2/*0:1*/; +z1@(x1/*0:0101*/+:y1/*0:011*/)*z2@(r2/*0:101*/<:t2/*0:11*/) = z1/*0:01*/*rect z2/*0:1*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)*z2@(x2/*0:101*/+:y2/*0:11*/) = rect z1/*0:01*/*z2/*0:1*/; +z1@(x1/*0:0101*/+:y1/*0:011*/)/z2@(r2/*0:101*/<:t2/*0:11*/) = z1/*0:01*//rect z2/*0:1*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)/z2@(x2/*0:101*/+:y2/*0:11*/) = rect z1/*0:01*//z2/*0:1*/; +(x1/*0:0101*/+:y1/*0:011*/)+x2/*0:1*/ = x1/*0:0101*/+x2/*0:1*/+:y1/*0:011*/; +x1/*0:01*/+(x2/*0:101*/+:y2/*0:11*/) = x1/*0:01*/+x2/*0:101*/+:y2/*0:11*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)+x2/*0:1*/ = rect z1/*0:01*/+x2/*0:1*/; +x1/*0:01*/+z2@(r2/*0:101*/<:t2/*0:11*/) = x1/*0:01*/+rect z2/*0:1*/; +(x1/*0:0101*/+:y1/*0:011*/)-x2/*0:1*/ = x1/*0:0101*/-x2/*0:1*/+:y1/*0:011*/; +x1/*0:01*/-(x2/*0:101*/+:y2/*0:11*/) = x1/*0:01*/-x2/*0:101*/+:-y2/*0:11*/; +z1@(r1/*0:0101*/<:t1/*0:011*/)-x2/*0:1*/ = rect z1/*0:01*/-x2/*0:1*/; +x1/*0:01*/-z2@(r2/*0:101*/<:t2/*0:11*/) = x1/*0:01*/-rect z2/*0:1*/; +(x1/*0:0101*/+:y1/*0:011*/)*x2/*0:1*/ = x1/*0:0101*/*x2/*0:1*/+:y1/*0:011*/*x2/*0:1*/; +x1/*0:01*/*(x2/*0:101*/+:y2/*0:11*/) = x1/*0:01*/*x2/*0:101*/+:x1/*0:01*/*y2/*0:11*/; +(r1/*0:0101*/<:t1/*0:011*/)*x2/*0:1*/ = r1/*0:0101*/*x2/*0:1*/<:t1/*0:011*/; +x1/*0:01*/*(r2/*0:101*/<:t2/*0:11*/) = x1/*0:01*/*r2/*0:101*/<:t2/*0:11*/; +(x1/*0:0101*/+:y1/*0:011*/)/x2/*0:1*/ = x1/*0:0101*//x2/*0:1*/+:y1/*0:011*//x2/*0:1*/; +x1/*0:01*//z2@(x2/*0:101*/+:y2/*0:11*/) = (x1/*0:01*/*x2/*0:101*/+:-x1/*0:01*/*y2/*0:11*/)/(x2/*0:101*/*x2/*0:101*/+y2/*0:11*/*y2/*0:11*/); +(r1/*0:0101*/<:t1/*0:011*/)/x2/*0:1*/ = r1/*0:0101*//x2/*0:1*/<:t1/*0:011*/; +x1/*0:01*//(r2/*0:101*/<:t2/*0:11*/) = x1/*0:01*//r2/*0:101*/<:-t2/*0:11*/; +z1@(x1/*0:0101*/+:y1/*0:011*/)^z2@(x2/*0:101*/+:y2/*0:11*/) = polar z1/*0:01*/^z2/*0:1*/; +z1@(x1/*0:0101*/+:y1/*0:011*/)^z2@(r2/*0:101*/<:t2/*0:11*/) = polar z1/*0:01*/^rect z2/*0:1*/; +(r1/*0:0101*/<:t1/*0:011*/)^z2@(x2/*0:101*/+:y2/*0:11*/) = exp (ln r1/*0:0101*/*z2/*0:1*/)*exp ((0+:t1/*0:011*/)*z2/*0:1*/); +(r1/*0:0101*/<:t1/*0:011*/)^z2@(r2/*0:101*/<:t2/*0:11*/) = exp (ln r1/*0:0101*/*z2/*0:1*/)*exp ((0+:t1/*0:011*/)*z2/*0:1*/); +z1@(x1/*0:0101*/+:y1/*0:011*/)^x2/*0:1*/ = z1/*0:01*/^(x2/*0:1*/+:0); +x1/*0:01*/^z2@(x2/*0:101*/+:y2/*0:11*/) = (x1/*0:01*/+:0)^z2/*0:1*/; +(r1/*0:0101*/<:t1/*0:011*/)^x2/*0:1*/ = r1/*0:0101*/^x2/*0:1*/<:t1/*0:011*/*x2/*0:1*/; +x1/*0:01*/^z2@(r2/*0:101*/<:t2/*0:11*/) = (x1/*0:01*/<:0)^z2/*0:1*/; +x1/*0:01*/::double^x2/*0:1*/::double = exp (ln x1/*0:01*/*x2/*0:1*/) if x1/*0:01*/<0; +x1/*0:0101*/+:y1/*0:011*/==x2/*0:101*/+:y2/*0:11*/ = x1/*0:0101*/==x2/*0:101*/&&y1/*0:011*/==y2/*0:11*/; +r1/*0:0101*/<:t1/*0:011*/==r2/*0:101*/<:t2/*0:11*/ = r1/*0:0101*/==r2/*0:101*/&&t1/*0:011*/==t2/*0:11*/; +x1/*0:0101*/+:y1/*0:011*/!=x2/*0:101*/+:y2/*0:11*/ = x1/*0:0101*/!=x2/*0:101*/||y1/*0:011*/!=y2/*0:11*/; +r1/*0:0101*/<:t1/*0:011*/!=r2/*0:101*/<:t2/*0:11*/ = r1/*0:0101*/!=r2/*0:101*/||t1/*0:011*/!=t2/*0:11*/; +z1@(_/*0:0101*/+:_/*0:011*/)==z2@(_/*0:101*/<:_/*0:11*/) = z1/*0:01*/==rect z2/*0:1*/; +z1@(_/*0:0101*/<:_/*0:011*/)==z2@(_/*0:101*/+:_/*0:11*/) = rect z1/*0:01*/==z2/*0:1*/; +z1@(_/*0:0101*/+:_/*0:011*/)!=z2@(_/*0:101*/<:_/*0:11*/) = z1/*0:01*/!=rect z2/*0:1*/; +z1@(_/*0:0101*/<:_/*0:011*/)!=z2@(_/*0:101*/+:_/*0:11*/) = rect z1/*0:01*/!=z2/*0:1*/; +x1/*0:0101*/+:y1/*0:011*/==x2/*0:1*/ = x1/*0:0101*/==x2/*0:1*/&&y1/*0:011*/==0; +x1/*0:01*/==x2/*0:101*/+:y2/*0:11*/ = x1/*0:01*/==x2/*0:101*/&&y2/*0:11*/==0; +z1@(r1/*0:0101*/<:t1/*0:011*/)==x2/*0:1*/ = z1/*0:01*/==x2/*0:1*/<:0; +x1/*0:01*/==z2@(r2/*0:101*/<:t2/*0:11*/) = x1/*0:01*/<:0==z2/*0:1*/; +x1/*0:0101*/+:y1/*0:011*/!=x2/*0:1*/ = x1/*0:0101*/!=x2/*0:1*/||y1/*0:011*/!=0; +x1/*0:01*/!=x2/*0:101*/+:y2/*0:11*/ = x1/*0:01*/!=x2/*0:101*/||y2/*0:11*/!=0; +z1@(r1/*0:0101*/<:t1/*0:011*/)!=x2/*0:1*/ = z1/*0:01*/!=x2/*0:1*/<:0; +x1/*0:01*/!=z2@(r2/*0:101*/<:t2/*0:11*/) = x1/*0:01*/<:0!=z2/*0:1*/; +x/*0:01*/::bigint%0L = x/*0:01*//0; +x/*0:01*/::bigint%y/*0:1*/::bigint = (-x/*0:01*/)%(-y/*0:1*/) if y/*0:1*/<0; +x/*0:01*/::bigint%y/*0:1*/::bigint = x/*1:01*/ div d/*0:*/%(y/*1:1*/ div d/*0:*/) when d/*0:*/ = gcd x/*0:01*/ y/*0:1*/ { + rule #0: d = gcd x y + state 0: #0 + <var> state 1 + state 1: #0 +} end if gcd x/*0:01*/ y/*0:1*/>1; +x/*0:01*/::int%y/*0:1*/::bigint = bigint x/*0:01*/%y/*0:1*/; +x/*0:01*/::bigint%y/*0:1*/::int = x/*0:01*/%bigint y/*0:1*/; +x/*0:01*/::int%y/*0:1*/::int = bigint x/*0:01*/%bigint y/*0:1*/; +x1/*0:0101*/%y1/*0:011*/%(x2/*0:101*/%y2/*0:11*/) = x1/*0:0101*/*y2/*0:11*/%(y1/*0:011*/*x2/*0:101*/); +x1/*0:0101*/%y1/*0:011*/%x2/*0:1*/ = x1/*0:0101*/%(y1/*0:011*/*x2/*0:1*/); +x1/*0:01*/%(x2/*0:101*/%y2/*0:11*/) = x1/*0:01*/*y2/*0:11*/%x2/*0:101*/; +z1@(_/*0:0101*/+:_/*0:011*/)%z2@(_/*0:101*/<:_/*0:11*/) = z1/*0:01*//z2/*0:1*/; +z1@(_/*0:0101*/<:_/*0:011*/)%z2@(_/*0:101*/+:_/*0:11*/) = z1/*0:01*//z2/*0:1*/; +(x1/*0:0101*/+:y1/*0:011*/)%(x2/*0:101*/+:y2/*0:11*/) = (x1/*1:0101*/*x2/*1:101*/+y1/*1:011*/*y2/*1:11*/)%d/*0:*/+:(y1/*1:011*/*x2/*1:101*/-x1/*1:0101*/*y2/*1:11*/)%d/*0:*/ when d/*0:*/ = x2/*0:101*/*x2/*0:101*/+y2/*0:11*/*y2/*0:11*/ { + rule #0: d = x2*x2+y2*y2 + state 0: #0 + <var> state 1 + state 1: #0 +} end; +(x1/*0:0101*/+:y1/*0:011*/)%x2/*0:1*/ = x1/*1:0101*/*x2/*1:1*/%d/*0:*/+:y1/*1:011*/*x2/*1:1*/%d/*0:*/ when d/*0:*/ = x2/*0:1*/*x2/*0:1*/ { + rule #0: d = x2*x2 + state 0: #0 + <var> state 1 + state 1: #0 +} end; +x1/*0:01*/%(x2/*0:101*/+:y2/*0:11*/) = x1/*1:01*/*x2/*1:101*/%d/*0:*/+:(-x1/*1:01*/*y2/*1:11*/)%d/*0:*/ when d/*0:*/ = x2/*0:101*/*x2/*0:101*/+y2/*0:11*/*y2/*0:11*/ { + rule #0: d = x2*x2+y2*y2 + state 0: #0 + <var> state 1 + state 1: #0 +} end; +(r1/*0:0101*/<:t1/*0:011*/)%(r2/*0:101*/<:t2/*0:11*/) = r1/*0:0101*/%r2/*0:101*/<:t1/*0:011*/-t2/*0:11*/; +(r1/*0:0101*/<:t1/*0:011*/)%x2/*0:1*/ = r1/*0:0101*/%x2/*0:1*/<:t1/*0:011*/; +x1/*0:01*/%(r2/*0:101*/<:t2/*0:11*/) = x1/*0:01*/%r2/*0:101*/<:-t2/*0:11*/; +x/*0:01*/::double%y/*0:1*/ = x/*0:01*//y/*0:1*/; +x/*0:01*/%y/*0:1*/::double = x/*0:01*//y/*0:1*/; +rational x@(_/*0:101*/%_/*0:11*/) = x/*0:1*/; +rational x/*0:1*/::int = x/*0:1*/%1; +rational x/*0:1*/::bigint = x/*0:1*/%1; +rational x/*0:1*/::double = x/*0:1*/; +rational (x/*0:101*/+:y/*0:11*/) = rational x/*0:101*/+:rational y/*0:11*/; +rational (x/*0:101*/<:y/*0:11*/) = rational x/*0:101*/<:rational y/*0:11*/; +int x@(_/*0:101*/%_/*0:11*/) = int (bigint x/*0:1*/); +bigint x@(_/*0:101*/%_/*0:11*/) = trunc x/*0:1*/; +double (x/*0:101*/%y/*0:11*/) = x/*0:101*//y/*0:11*/; +complex (x/*0:101*/%y/*0:11*/) = x/*0:101*/%y/*0:11*/+:0L%1L; +rect (x/*0:101*/%y/*0:11*/) = x/*0:101*/%y/*0:11*/+:0L%1L; +polar (x/*0:101*/%y/*0:11*/) = x/*0:101*/%y/*0:11*/<:0L%1L; +r@(_/*0:0101*/%_/*0:011*/)<:t/*0:1*/ = -r/*0:01*/<:t/*0:1*/+3.14159265358979 if r/*0:01*/<0; +r/*0:01*/<:t@(_/*0:101*/%_/*0:11*/) = r/*0:01*/<:atan2 (sin t/*0:1*/) (cos t/*0:1*/) if t/*0:1*/<-3.14159265358979||t/*0:1*/>3.14159265358979; +r/*0:01*/<:t@(_/*0:101*/%_/*0:11*/) = r/*0:01*/<:3.14159265358979 if t/*0:1*/==-3.14159265358979; +num (x/*0:101*/%y/*0:11*/) = x/*0:101*/; +den (x/*0:101*/%y/*0:11*/) = y/*0:11*/; +num x/*0:1*/::int = x/*0:1*/; +num x/*0:1*/::bigint = x/*0:1*/; +den x/*0:1*/::int = 1; +den x/*0:1*/::bigint = 1; +abs (x/*0:101*/%y/*0:11*/) = abs x/*0:101*/%y/*0:11*/; +sgn (x/*0:101*/%y/*0:11*/) = sgn x/*0:101*/; +floor x@(_/*0:101*/%_/*0:11*/) = if n/*0:*/<=x/*1:1*/ then n/*0:*/ else n/*0:*/-1 when n/*0:*/::bigint = trunc x/*0:1*/ { + rule #0: n::bigint = trunc x + state 0: #0 + <var>::bigint state 1 + state 1: #0 +} end; +ceil x@(_/*0:101*/%_/*0:11*/) = -floor (-x/*0:1*/); +round (x/*0:101*/%y/*0:11*/) = -round ((-x/*0:101*/)%y/*0:11*/) if x/*0:101*/<0; +round (x/*0:101*/%y/*0:11*/) = x/*0:101*/ div 2+1 if y/*0:11*/==2; +round (x/*0:101*/%y/*0:11*/) = (2*x/*0:101*/+y/*0:11*/) div (2*y/*0:11*/); +trunc (x/*0:101*/%y/*0:11*/) = x/*0:101*/ div y/*0:11*/; +frac x@(_/*0:101*/%_/*0:11*/) = x/*0:1*/-trunc x/*0:1*/; +pow (x/*0:0101*/%y/*0:011*/) n/*0:1*/::int = pow x/*0:0101*/ n/*0:1*/%pow y/*0:011*/ n/*0:1*/ if n/*0:1*/>0; +pow (x/*0:0101*/%y/*0:011*/) n/*0:1*/::bigint = pow x/*0:0101*/ n/*0:1*/%pow y/*0:011*/ n/*0:1*/ if n/*0:1*/>0; +pow (x/*0:0101*/%y/*0:011*/) n/*0:1*/::int = pow y/*0:011*/ (-n/*0:1*/)%pow x/*0:0101*/ (-n/*0:1*/) if n/*0:1*/<0; +pow (x/*0:0101*/%y/*0:011*/) n/*0:1*/::bigint = pow y/*0:011*/ (-n/*0:1*/)%pow x/*0:0101*/ (-n/*0:1*/) if n/*0:1*/<0; +pow (x/*0:0101*/%y/*0:011*/) n/*0:1*/::int = 1L%1L; +pow (x/*0:0101*/%y/*0:011*/) n/*0:1*/::bigint = 1L%1L; +pow (x/*0:0101*/%y/*0:011*/) n/*0:1*/::double = pow (x/*0:0101*//y/*0:011*/) n/*0:1*/; +pow (x/*0:0101*/%y/*0:011*/) (n/*0:101*/%m/*0:11*/) = pow (x/*0:0101*//y/*0:011*/) (n/*0:101*//m/*0:11*/); +pow x/*0:01*/::int n/*0:1*/::int = 1%pow x/*0:01*/ (-n/*0:1*/) if n/*0:1*/<0; +pow x/*0:01*/::int n/*0:1*/::bigint = 1%pow x/*0:01*/ (-n/*0:1*/) if n/*0:1*/<0; +pow x/*0:01*/::bigint n/*0:1*/::int = 1%pow x/*0:01*/ (-n/*0:1*/) if n/*0:1*/<0; +pow x/*0:01*/::bigint n/*0:1*/::bigint = 1%pow x/*0:01*/ (-n/*0:1*/) if n/*0:1*/<0; +sqrt (x/*0:101*/%y/*0:11*/) = sqrt (x/*0:101*//y/*0:11*/); +exp (x/*0:101*/%y/*0:11*/) = exp (x/*0:101*//y/*0:11*/); +ln (x/*0:101*/%y/*0:11*/) = ln (x/*0:101*//y/*0:11*/); +log (x/*0:101*/%y/*0:11*/) = log (x/*0:101*//y/*0:11*/); +sin (x/*0:101*/%y/*0:11*/) = sin (x/*0:101*//y/*0:11*/); +cos (x/*0:101*/%y/*0:11*/) = cos (x/*0:101*//y/*0:11*/); +tan (x/*0:101*/%y/*0:11*/) = tan (x/*0:101*//y/*0:11*/); +asin (x/*0:101*/%y/*0:11*/) = asin (x/*0:101*//y/*0:11*/); +acos (x/*0:101*/%y/*0:11*/) = acos (x/*0:101*//y/*0:11*/); +atan (x/*0:101*/%y/*0:11*/) = atan (x/*0:101*//y/*0:11*/); +atan2 (x/*0:0101*/%y/*0:011*/) z/*0:1*/ = atan2 (x/*0:0101*//y/*0:011*/) z/*0:1*/; +atan2 x/*0:01*/ (y/*0:101*/%z/*0:11*/) = atan2 x/*0:01*/ (y/*0:101*//z/*0:11*/); +sinh (x/*0:101*/%y/*0:11*/) = sinh (x/*0:101*//y/*0:11*/); +cosh (x/*0:101*/%y/*0:11*/) = cosh (x/*0:101*//y/*0:11*/); +tanh (x/*0:101*/%y/*0:11*/) = tanh (x/*0:101*//y/*0:11*/); +asinh (x/*0:101*/%y/*0:11*/) = asinh (x/*0:101*//y/*0:11*/); +acosh (x/*0:101*/%y/*0:11*/) = acosh (x/*0:101*//y/*0:11*/); +atanh (x/*0:101*/%y/*0:11*/) = atanh (x/*0:101*//y/*0:11*/); +-x/*0:101*/%y/*0:11*/ = (-x/*0:101*/)%y/*0:11*/; +x1/*0:0101*/%y1/*0:011*/+x2/*0:101*/%y2/*0:11*/ = (x1/*0:0101*/*y2/*0:11*/+x2/*0:101*/*y1/*0:011*/)%(y1/*0:011*/*y2/*0:11*/); +x1/*0:0101*/%y1/*0:011*/-x2/*0:101*/%y2/*0:11*/ = (x1/*0:0101*/*y2/*0:11*/-x2/*0:101*/*y1/*0:011*/)%(y1/*0:011*/*y2/*0:11*/); +x1/*0:0101*/%y1/*0:011*/*(x2/*0:101*/%y2/*0:11*/) = x1/*0:0101*/*x2/*0:101*/%(y1/*0:011*/*y2/*0:11*/); +x1/*0:0101*/%y1/*0:011*/+x2/*0:1*/ = (x1/*0:0101*/+x2/*0:1*/*y1/*0:011*/)%y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/-x2/*0:1*/ = (x1/*0:0101*/-x2/*0:1*/*y1/*0:011*/)%y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/*x2/*0:1*/ = x1/*0:0101*/*x2/*0:1*/%y1/*0:011*/; +x1/*0:01*/+x2/*0:101*/%y2/*0:11*/ = (x1/*0:01*/*y2/*0:11*/+x2/*0:101*/)%y2/*0:11*/; +x1/*0:01*/-x2/*0:101*/%y2/*0:11*/ = (x1/*0:01*/*y2/*0:11*/-x2/*0:101*/)%y2/*0:11*/; +x1/*0:01*/*(x2/*0:101*/%y2/*0:11*/) = x1/*0:01*/*x2/*0:101*/%y2/*0:11*/; +x1/*0:0101*/%y1/*0:011*//(x2/*0:101*/%y2/*0:11*/) = x1/*0:0101*/*y2/*0:11*//(y1/*0:011*/*x2/*0:101*/); +(x1/*0:0101*/%y1/*0:011*/)^(x2/*0:101*/%y2/*0:11*/) = (x1/*0:0101*//y1/*0:011*/)^(x2/*0:101*//y2/*0:11*/); +x1/*0:0101*/%y1/*0:011*//x2/*0:1*/ = x1/*0:0101*//(y1/*0:011*/*x2/*0:1*/); +(x1/*0:0101*/%y1/*0:011*/)^x2/*0:1*/ = (x1/*0:0101*//y1/*0:011*/)^x2/*0:1*/; +x1/*0:01*//(x2/*0:101*/%y2/*0:11*/) = x1/*0:01*/*y2/*0:11*//x2/*0:101*/; +x1/*0:01*/^(x2/*0:101*/%y2/*0:11*/) = x1/*0:01*/^(x2/*0:101*//y2/*0:11*/); +x1/*0:0101*/%y1/*0:011*/==x2/*0:101*/%y2/*0:11*/ = x1/*0:0101*/*y2/*0:11*/==x2/*0:101*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/!=x2/*0:101*/%y2/*0:11*/ = x1/*0:0101*/*y2/*0:11*/!=x2/*0:101*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/<x2/*0:101*/%y2/*0:11*/ = x1/*0:0101*/*y2/*0:11*/<x2/*0:101*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/<=x2/*0:101*/%y2/*0:11*/ = x1/*0:0101*/*y2/*0:11*/<=x2/*0:101*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/>x2/*0:101*/%y2/*0:11*/ = x1/*0:0101*/*y2/*0:11*/>x2/*0:101*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/>=x2/*0:101*/%y2/*0:11*/ = x1/*0:0101*/*y2/*0:11*/>=x2/*0:101*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/==x2/*0:1*/ = x1/*0:0101*/==x2/*0:1*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/!=x2/*0:1*/ = x1/*0:0101*/!=x2/*0:1*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/<x2/*0:1*/ = x1/*0:0101*/<x2/*0:1*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/<=x2/*0:1*/ = x1/*0:0101*/<=x2/*0:1*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/>x2/*0:1*/ = x1/*0:0101*/>x2/*0:1*/*y1/*0:011*/; +x1/*0:0101*/%y1/*0:011*/>=x2/*0:1*/ = x1/*0:0101*/>=x2/*0:1*/*y1/*0:011*/; +x1/*0:01*/==x2/*0:101*/%y2/*0:11*/ = x1/*0:01*/*y2/*0:11*/==x2/*0:101*/; +x1/*0:01*/!=x2/*0:101*/%y2/*0:11*/ = x1/*0:01*/*y2/*0:11*/!=x2/*0:101*/; +x1/*0:01*/<x2/*0:101*/%y2/*0:11*/ = x1/*0:01*/*y2/*0:11*/<x2/*0:101*/; +x1/*0:01*/<=x2/*0:101*/%y2/*0:11*/ = x1/*0:01*/*y2/*0:11*/<=x2/*0:101*/; +x1/*0:01*/>x2/*0:101*/%y2/*0:11*/ = x1/*0:01*/*y2/*0:11*/>x2/*0:101*/; +x1/*0:01*/>=x2/*0:101*/%y2/*0:11*/ = x1/*0:01*/*y2/*0:11*/>=x2/*0:101*/; +complexp x/*0:1*/ = case x/*0:1*/ of x/*0:01*/+:y/*0:1*/ = realp x/*0:01*/&&realp y/*0:1*/; x/*0:01*/<:y/*0:1*/ = realp x/*0:01*/&&realp y/*0:1*/; _/*0:*/ = 0 { + rule #0: x+:y = realp x&&realp y + rule #1: x<:y = realp x&&realp y + rule #2: _ = 0 + state 0: #0 #1 #2 + <var> state 1 + <app> state 2 + state 1: #2 + state 2: #0 #1 #2 + <var> state 3 + <app> state 5 + state 3: #2 + <var> state 4 + state 4: #2 + state 5: #0 #1 #2 + <var> state 6 + +: state 9 + <: state 12 + state 6: #2 + <var> state 7 + state 7: #2 + <var> state 8 + state 8: #2 + state 9: #0 #2 + <var> state 10 + state 10: #0 #2 + <var> state 11 + state 11: #0 #2 + state 12: #1 #2 + <var> state 13 + state 13: #1 #2 + <var> state 14 + state 14: #1 #2 +} end; +rationalp x/*0:1*/ = case x/*0:1*/ of x/*0:01*/%y/*0:1*/ = bigintp x/*0:01*/&&bigintp y/*0:1*/; _/*0:*/ = 0 { + rule #0: x%y = bigintp x&&bigintp y + rule #1: _ = 0 + state 0: #0 #1 + <var> state 1 + <app> state 2 + state 1: #1 + state 2: #0 #1 + <var> state 3 + <app> state 5 + state 3: #1 + <var> state 4 + state 4: #1 + state 5: #0 #1 + <var> state 6 + % state 9 + state 6: #1 + <var> state 7 + state 7: #1 + <var> state 8 + state 8: #1 + state 9: #0 #1 + <var> state 10 + state 10: #0 #1 + <var> state 11 + state 11: #0 #1 +} end; +realp x/*0:1*/ = intp x/*0:1*/||bigintp x/*0:1*/||doublep x/*0:1*/||rationalp x/*0:1*/; +numberp x/*0:1*/ = realp x/*0:1*/||complexp x/*0:1*/; +exactp x/*0:1*/ = intp x/*0:1*/||bigintp x/*0:1*/||rationalp||complexp x/*0:1*/&&exactp (re x/*0:1*/)&&exactp (im x/*0:1*/) if numberp x/*0:1*/; +infp x/*0:1*/::double = not nanp x/*0:1*/&&nanp (x/*0:1*/-x/*0:1*/); +nanp x/*0:1*/::double = x/*0:1*/===nan; +{ + rule #0: x::int<y::int = x<y + rule #1: x::double<y::double = x<y + rule #2: x::int<y::double = x<y + rule #3: x::double<y::int = x<y + rule #4: x::bigint<y::bigint = bigint_cmp x y<0 + rule #5: x::int<y::bigint = bigint x<y + rule #6: x::bigint<y::int = x<bigint y + rule #7: x::bigint<y::double = double x<y + rule #8: x::double<y::bigint = x<double y + rule #9: x<y = bigint x<bigint y + rule #10: x::string<y::string = strcmp x y<0 + rule #11: x1%y1<x2%y2 = x1*y2<x2*y1 + rule #12: x1%y1<x2 = x1<x2*y1 + rule #13: x1<x2%y2 = x1*y2<x2 + state 0: #0 #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 + <var> state 1 + <var>::int state 7 + <var>::bigint state 16 + <var>::double state 25 + <var>::string state 34 + <var> state 41 + <app> state 48 + state 1: #13 + <app> state 2 + state 2: #13 + <app> state 3 + state 3: #13 + % state 4 + state 4: #13 + <var> state 5 + state 5: #13 + <var> state 6 + state 6: #13 + state 7: #0 #2 #5 #13 + <var>::int state 8 + <var>::bigint state 9 + <var>::double state 10 + <app> state 11 + state 8: #0 + state 9: #5 + state 10: #2 + state 11: #13 + <app> state 12 + state 12: #13 + % state 13 + state 13: #13 + <var> state 14 + state 14: #13 + <var> state 15 + state 15: #13 + state 16: #4 #6 #7 #13 + <var>::int state 17 + <var>::bigint state 18 + <var>::double state 19 + <app> state 20 + state 17: #6 + state 18: #4 + state 19: #7 + state 20: #13 + <app> state 21 + state 21: #13 + % state 22 + state 22: #13 + <var> state 23 + state 23: #13 + <var> state 24 + state 24: #13 + state 25: #1 #3 #8 #13 + <var>::int state 26 + <var>::bigint state 27 + <var>::double state 28 + <app> state 29 + state 26: #3 + state 27: #8 + state 28: #1 + state 29: #13 + <app> state 30 + state 30: #13 + % state 31 + state 31: #13 + <var> state 32 + state 32: #13 + <var> state 33 + state 33: #13 + state 34: #10 #13 + <var>::string state 35 + <app> state 36 + state 35: #10 + state 36: #13 + <app> state 37 + state 37: #13 + % state 38 + state 38: #13 + <var> state 39 + state 39: #13 + <var> state 40 + state 40: #13 + state 41: #9 #13 + <var> state 42 + <app> state 43 + state 42: #9 + state 43: #13 + <app> state 44 + state 44: #13 + % state 45 + state 45: #13 + <var> state 46 + state 46: #13 + <var> state 47 + state 47: #13 + state 48: #11 #12 #13 + <var> state 49 + <app> state 56 + state 49: #13 + <var> state 50 + state 50: #13 + <app> state 51 + state 51: #13 + <app> state 52 + state 52: #13 + % state 53 + state 53: #13 + <var> state 54 + state 54: #13 + <var> state 55 + state 55: #13 + state 56: #11 #12 #13 + <var> state 57 + % state 65 + state 57: #13 + <var> state 58 + state 58: #13 + <var> state 59 + state 59: #13 + <app> state 60 + state 60: #13 + <app> state 61 + state 61: #13 + % state 62 + state 62: #13 + <var> state 63 + state 63: #13 + <var> state 64 + state 64: #13 + state 65: #11 #12 #13 + <var> state 66 + state 66: #11 #12 #13 + <var> state 67 + state 67: #11 #12 #13 + <var> state 68 + <app> state 69 + state 68: #12 + state 69: #11 #12 #13 + <var> state 70 + <app> state 72 + state 70: #12 + <var> state 71 + state 71: #12 + state 72: #11 #12 #13 + <var> state 73 + % state 76 + state 73: #12 + <var> state 74 + state 74: #12 + <var> state 75 + state 75: #12 + state 76: #11 #12 #13 + <var> state 77 + state 77: #11 #12 #13 + <var> state 78 + state 78: #11 #12 #13 +} +{ + rule #0: x::int>y::int = x>y + rule #1: x::double>y::double = x>y + rule #2: x::int>y::double = x>y + rule #3: x::double>y::int = x>y + rule #4: x::bigint>y::bigint = bigint_cmp x y>0 + rule #5: x::int>y::bigint = bigint x>y + rule #6: x::bigint>y::int = x>bigint y + rule #7: x::bigint>y::double = double x>y + rule #8: x::double>y::bigint = x>double y + rule #9: x>y = bigint x>bigint y + rule #10: x::string>y::string = strcmp x y>0 + rule #11: x1%y1>x2%y2 = x1*y2>x2*y1 + rule #12: x1%y1>x2 = x1>x2*y1 + rule #13: x1>x2%y2 = x1*y2>x2 + state 0: #0 #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 + <var> state 1 + <var>::int state 7 + <var>::bigint state 16 + <var>::double state 25 + <var>::string state 34 + <var> state 41 + <app> state 48 + state 1: #13 + <app> state 2 + state 2: #13 + <app> state 3 + state 3: #13 + % state 4 + state 4: #13 + <var> state 5 + state 5: #13 + <var> state 6 + state 6: #13 + state 7: #0 #2 #5 #13 + <var>::int state 8 + <var>::bigint state 9 + <var>::double state 10 + <app> state 11 + state 8: #0 + state 9: #5 + state 10: #2 + state 11: #13 + <app> state 12 + state 12: #13 + % state 13 + state 13: #13 + <var> state 14 + state 14: #13 + <var> state 15 + state 15: #13 + state 16: #4 #6 #7 #13 + <var>::int state 17 + <var>::bigint state 18 + <var>::double state 19 + <app> state 20 + state 17: #6 + state 18: #4 + state 19: #7 + state 20: #13 + <app> state 21 + state 21: #13 + % state 22 + state 22: #13 + <var> state 23 + state 23: #13 + <var> state 24 + state 24: #13 + state 25: #1 #3 #8 #13 + <var>::int state 26 + <var>::bigint state 27 + <var>::double state 28 + <app> state 29 + state 26: #3 + state 27: #8 + state 28: #1 + state 29: #13 + <app> state 30 + state 30: #13 + % state 31 + state 31: #13 + <var> state 32 + state 32: #13 + <var> state 33 + state 33: #13 + state 34: #10 #13 + <var>::string state 35 + <app> state 36 + state 35: #10 + state 36: #13 + <app> state 37 + state 37: #13 + % state 38 + state 38: #13 + <var> state 39 + state 39: #13 + <var> state 40 + state 40: #13 + state 41: #9 #13 + <var> state 42 + <app> state 43 + state 42: #9 + state 43: #13 + <app> state 44 + state 44: #13 + % state 45 + state 45: #13 + <var> state 46 + state 46: #13 + <var> state 47 + state 47: #13 + state 48: #11 #12 #13 + <var> state 49 + <app> state 56 + state 49: #13 + <var> state 50 + state 50: #13 + <app> state 51 + state 51: #13 + <app> state 52 + state 52: #13 + % state 53 + state 53: #13 + <var> state 54 + state 54: #13 + <var> state 55 + state 55: #13 + state 56: #11 #12 #13 + <var> state 57 + % state 65 + state 57: #13 + <var> state 58 + state 58: #13 + <var> state 59 + state 59: #13 + <app> state 60 + state 60: #13 + <app> state 61 + state 61: #13 + % state 62 + state 62: #13 + <var> state 63 + state 63: #13 + <var> state 64 + state 64: #13 + state 65: #11 #12 #13 + <var> state 66 + state 66: #11 #12 #13 + <var> state 67 + state 67: #11 #12 #13 + <var> state 68 + <app> state 69 + state 68: #12 + state 69: #11 #12 #13 + <var> state 70 + <app> state 72 + state 70: #12 + <var> state 71 + state 71: #12 + state 72: #11 #12 #13 + <var> state 73 + % state 76 + state 73: #12 + <var> state 74 + state 74: #12 + <var> state 75 + state 75: #12 + state 76: #11 #12 #13 + <var> state 77 + state 77: #11 #12 #13 + <var> state 78 + state 78: #11 #12 #13 +} +{ + rule #0: x::int<=y::int = x<=y + rule #1: x::double<=y::double = x<=y + rule #2: x::int<=y::double = x<=y + rule #3: x::double<=y::int = x<=y + rule #4: x::bigint<=y::bigint = bigint_cmp x y<=0 + rule #5: x::int<=y::bigint = bigint x<=y + rule #6: x::bigint<=y::int = x<=bigint y + rule #7: x::bigint<=y::double = double x<=y + rule #8: x::double<=y::bigint = x<=double y + rule #9: x<=y = bigint x<=bigint y + rule #10: x::string<=y::string = strcmp x y<=0 + rule #11: x1%y1<=x2%y2 = x1*y2<=x2*y1 + rule #12: x1%y1<=x2 = x1<=x2*y1 + rule #13: x1<=x2%y2 = x1*y2<=x2 + state 0: #0 #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 + <var> state 1 + <var>::int state 7 + <var>::bigint state 16 + <var>::double state 25 + <var>::string state 34 + <var> state 41 + <app> state 48 + state 1: #13 + <app> state 2 + state 2: #13 + <app> state 3 + state 3: #13 + % state 4 + state 4: #13 + <var> state 5 + state 5: #13 + <var> state 6 + state 6: #13 + state 7: #0 #2 #5 #13 + <var>::int state 8 + <var>::bigint state 9 + <var>::double state 10 + <app> state 11 + state 8: #0 + state 9: #5 + state 10: #2 + state 11: #13 + <app> state 12 + state 12: #13 + % state 13 + state 13: #13 + <var> state 14 + state 14: #13 + <var> state 15 + state 15: #13 + state 16: #4 #6 #7 #13 + <var>::int state 17 + <var>::bigint state 18 + <var>::double state 19 + <app> state 20 + state 17: #6 + state 18: #4 + state 19: #7 + state 20: #13 + <app> state 21 + state 21: #13 + % state 22 + state 22: #13 + <var> state 23 + state 23: #13 + <var> state 24 + state 24: #13 + state 25: #1 #3 #8 #13 + <var>::int state 26 + <var>::bigint state 27 + <var>::double state 28 + <app> state 29 + state 26: #3 + state 27: #8 + state 28: #1 + state 29: #13 + <app> state 30 + state 30: #13 + % state 31 + state 31: #13 + <var> state 32 + state 32: #13 + <var> state 33 + state 33: #13 + state 34: #10 #13 + <var>::string state 35 + <app> state 36 + state 35: #10 + state 36: #13 + <app> state 37 + state 37: #13 + % state 38 + state 38: #13 + <var> state 39 + state 39: #13 + <var> state 40 + state 40: #13 + state 41: #9 #13 + <var> state 42 + <app> state 43 + state 42: #9 + state 43: #13 + <app> state 44 + state 44: #13 + % state 45 + state 45: #13 + <var> state 46 + state 46: #13 + <var> state 47 + state 47: #13 + state 48: #11 #12 #13 + <var> state 49 + <app> state 56 + state 49: #13 + <var> state 50 + state 50: #13 + <app> state 51 + state 51: #13 + <app> state 52 + state 52: #13 + % state 53 + state 53: #13 + <var> state 54 + state 54: #13 + <var> state 55 + state 55: #13 + state 56: #11 #12 #13 + <var> state 57 + % state 65 + state 57: #13 + <var> state 58 + state 58: #13 + <var> state 59 + state 59: #13 + <app> state 60 + state 60: #13 + <app> state 61 + state 61: #13 + % state 62 + state 62: #13 + <var> state 63 + state 63: #13 + <var> state 64 + state 64: #13 + state 65: #11 #12 #13 + <var> state 66 + state 66: #11 #12 #13 + <var> state 67 + state 67: #11 #12 #13 + <var> state 68 + <app> state 69 + state 68: #12 + state 69: #11 #12 #13 + <var> state 70 + <app> state 72 + state 70: #12 + <var> state 71 + state 71: #12 + state 72: #11 #12 #13 + <var> state 73 + % state 76 + state 73: #12 + <var> state 74 + state 74: #12 + <var> state 75 + state 75: #12 + state 76: #11 #12 #13 + <var> state 77 + state 77: #11 #12 #13 + <var> state 78 + state 78: #11 #12 #13 +} +{ + rule #0: x::int>=y::int = x>=y + rule #1: x::double>=y::double = x>=y + rule #2: x::int>=y::double = x>=y + rule #3: x::double>=y::int = x>=y + rule #4: x::bigint>=y::bigint = bigint_cmp x y>=0 + rule #5: x::int>=y::bigint = bigint x>=y + rule #6: x::bigint>=y::int = x>=bigint y + rule #7: x::bigint>=y::double = double x>=y + rule #8: x::double>=y::bigint = x>=double y + rule #9: x>=y = bigint x>=bigint y + rule #10: x::string>=y::string = strcmp x y>=0 + rule #11: x1%y1>=x2%y2 = x1*y2>=x2*y1 + rule #12: x1%y1>=x2 = x1>=x2*y1 + rule #13: x1>=x2%y2 = x1*y2>=x2 + state 0: #0 #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 + <var> state 1 + <var>::int state 7 + <var>::bigint state 16 + <var>::double state 25 + <var>::string state 34 + <var> state 41 + <app> state 48 + state 1: #13 + <app> state 2 + state 2: #13 + <app> state 3 + state 3: #13 + % state 4 + state 4: #13 + <var> state 5 + state 5: #13 + <var> state 6 + state 6: #13 + state 7: #0 #2 #5 #13 + <var>::int state 8 + <var>::bigint state 9 + <var>::double state 10 + <app> state 11 + state 8: #0 + state 9: #5 + state 10: #2 + state 11: #13 + <app> state 12 + state 12: #13 + % state 13 + state 13: #13 + <var> state 14 + state 14: #13 + <var> state 15 + state 15: #13 + state 16: #4 #6 #7 #13 + <var>::int state 17 + <var>::bigint state 18 + <var>::double state 19 + <app> state 20 + state 17: #6 + state 18: #4 + state 19: #7 + state 20: #13 + <app> state 21 + state 21: #13 + % state 22 + state 22: #13 + <var> state 23 + state 23: #13 + <var> state 24 + state 24: #13 + state 25: #1 #3 #8 #13 + <var>::int state 26 + <var>::bigint state 27 + <var>::double state 28 + <app> state 29 + state 26: #3 + state 27: #8 + state 28: #1 + state 29: #13 + <app> state 30 + state 30: #13 + % state 31 + state 31: #13 + <var> state 32 + state 32: #13 + <var> state 33 + state 33: #13 + state 34: #10 #13 + <var>::string state 35 + <app> state 36 + state 35: #10 + state 36: #13 + <app> state 37 + state 37: #13 + % state 38 + state 38: #13 + <var> state 39 + state 39: #13 + <var> state 40 + state 40: #13 + state 41: #9 #13 + <var> state 42 + <app> state 43 + state 42: #9 + state 43: #13 + <app> state 44 + state 44: #13 + % state 45 + state 45: #13 + <var> state 46 + state 46: #13 + <var> state 47 + state 47: #13 + state 48: #11 #12 #13 + <var> state 49 + <app> state 56 + state 49: #13 + <var> state 50 + state 50: #13 + <app> state 51 + state 51: #13 + <app> state 52 + state 52: #13 + % state 53 + state 53: #13 + <var> state 54 + state 54: #13 + <var> state 55 + state 55: #13 + state 56: #11 #12 #13 + <var> state 57 + % state 65 + state 57: #13 + <var> state 58 + state 58: #13 + <var> state 59 + state 59: #13 + <app> state 60 + state 60: #13 + <app> state 61 + state 61: #13 + % state 62 + state 62: #13 + <var> state 63 + state 63: #13 + <var> state 64 + state 64: #13 + state 65: #11 #12 #13 + <var> state 66 + state 66: #11 #12 #13 + <var> state 67 + state 67: #11 #12 #13 + <var> state 68 + <app> state 69 + state 68: #12 + state 69: #11 #12 #13 + <var> state 70 + <app> state 72 + state 70: #12 + <var> state 71 + state 71: #12 + state 72: #11 #12 #13 + <var> state 73 + % state 76 + state 73: #12 + <var> state 74 + state 74: #12 + <var> state 75 + state 75: #12 + state 76: #11 #12 #13 + <var> state 77 + state 77: #11 #12 #13 + <var> state 78 + state 78: #11 #12 #13 +} +{ + rule #0: x::int==y::int = x==y + rule #1: x::double==y::double = x==y + rule #2: x::int==y::double = x==y + rule #3: x::double==y::int = x==y + rule #4: x::bigint==y::bigint = bigint_cmp x y==0 + rule #5: x::int==y::bigint = bigint x==y + rule #6: x::bigint==y::int = x==bigint y + rule #7: x::bigint==y::double = double x==y + rule #8: x::double==y::bigint = x==double y + rule #9: x==y = bigint x==bigint y + rule #10: x::string==y::string = strcmp x y==0 + rule #11: ()==() = 1 + rule #12: (x,xs)==() = 0 + rule #13: ()==(x,xs) = 0 + rule #14: (x,xs)==(y,ys) = if x==y then xs==ys else 0 + rule #15: []==[] = 1 + rule #16: x:xs==[] = 0 + rule #17: []==x:xs = 0 + rule #18: x:xs==y:ys = if x==y then xs==ys else 0 + rule #19: x1+:y1==x2+:y2 = x1==x2&&y1==y2 + rule #20: r1<:t1==r2<:t2 = r1==r2&&t1==t2 + rule #21: z1@(_+:_)==z2@(_<:_) = z1==rect z2 + rule #22: z1@(_<:_)==z2@(_+:_) = rect z1==z2 + rule #23: x1+:y1==x2 = x1==x2&&y1==0 + rule #24: x1==x2+:y2 = x1==x2&&y2==0 + rule #25: z1@(r1<:t1)==x2 = z1==x2<:0 + rule #26: x1==z2@(r2<:t2) = x1<:0==z2 + rule #27: x1%y1==x2%y2 = x1*y2==x2*y1 + rule #28: x1%y1==x2 = x1==x2*y1 + rule #29: x1==x2%y2 = x1*y2==x2 + state 0: #0 #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 + <var> state 1 + <var>::int state 13 + <var>::bigint state 28 + <var>::double state 43 + <var>::string state 58 + <var> state 71 + [] state 84 + () state 100 + <app> state 116 + state 1: #24 #26 #29 + <app> state 2 + state 2: #24 #26 #29 + <app> state 3 + state 3: #24 #26 #29 + +: state 4 + <: state 7 + % state 10 + state 4: #24 + <var> state 5 + state 5: #24 + <var> state 6 + state 6: #24 + state 7: #26 + <var> state 8 + state 8: #26 + <var> state 9 + state 9: #26 + state 10: #29 + <var> state 11 + state 11: #29 + <var> state 12 + state 12: #29 + state 13: #0 #2 #5 #24 #26 #29 + <var>::int state 14 + <var>::bigint state 15 + <var>::double state 16 + <app> state 17 + state 14: #0 + state 15: #5 + state 16: #2 + state 17: #24 #26 #29 + <app> state 18 + state 18: #24 #26 #29 + +: state 19 + <: state 22 + % state 25 + state 19: #24 + <var> state 20 + state 20: #24 + <var> state 21 + state 21: #24 + state 22: #26 + <var> state 23 + state 23: #26 + <var> state 24 + state 24: #26 + state 25: #29 + <var> state 26 + state 26: #29 + <var> state 27 + state 27: #29 + state 28: #4 #6 #7 #24 #26 #29 + <var>::int state 29 + <var>::bigint state 30 + <var>::double state 31 + <app> state 32 + state 29: #6 + state 30: #4 + state 31: #7 + state 32: #24 #26 #29 + <app> state 33 + state 33: #24 #26 #29 + +: state 34 + <: state 37 + % state 40 + state 34: #24 + <var> state 35 + state 35: #24 + <var> state 36 + state 36: #24 + state 37: #26 + <var> state 38 + state 38: #26 + <var> state 39 + state 39: #26 + state 40: #29 + <var> state 41 + state 41: #29 + <var> state 42 + state 42: #29 + state 43: #1 #3 #8 #24 #26 #29 + <var>::int state 44 + <var>::bigint state 45 + <var>::double state 46 + <app> state 47 + state 44: #3 + state 45: #8 + state 46: #1 + state 47: #24 #26 #29 + <app> state 48 + state 48: #24 #26 #29 + +: state 49 + <: state 52 + % state 55 + state 49: #24 + <var> state 50 + state 50: #24 + <var> state 51 + state 51: #24 + state 52: #26 + <var> state 53 + state 53: #26 + <var> state 54 + state 54: #26 + state 55: #29 + <var> state 56 + state 56: #29 + <var> state 57 + state 57: #29 + state 58: #10 #24 #26 #29 + <var>::string state 59 + <app> state 60 + state 59: #10 + state 60: #24 #26 #29 + <app> state 61 + state 61: #24 #26 #29 + +: state 62 + <: state 65 + % state 68 + state 62: #24 + <var> state 63 + state 63: #24 + <var> state 64 + state 64: #24 + state 65: #26 + <var> state 66 + state 66: #26 + <var> state 67 + state 67: #26 + state 68: #29 + <var> state 69 + state 69: #29 + <var> state 70 + state 70: #29 + state 71: #9 #24 #26 #29 + <var> state 72 + <app> state 73 + state 72: #9 + state 73: #24 #26 #29 + <app> state 74 + state 74: #24 #26 #29 + +: state 75 + <: state 78 + % state 81 + state 75: #24 + <var> state 76 + state 76: #24 + <var> state 77 + state 77: #24 + state 78: #26 + <var> state 79 + state 79: #26 + <var> state 80 + state 80: #26 + state 81: #29 + <var> state 82 + state 82: #29 + <var> state 83 + state 83: #29 + state 84: #15 #17 #24 #26 #29 + [] state 85 + <app> state 86 + state 85: #15 + state 86: #17 #24 #26 #29 + <app> state 87 + state 87: #17 #24 #26 #29 + : state 88 + +: state 91 + <: state 94 + % state 97 + state 88: #17 + <var> state 89 + state 89: #17 + <var> state 90 + state 90: #17 + state 91: #24 + <var> state 92 + state 92: #24 + <var> state 93 + state 93: #24 + state 94: #26 + <var> state 95 + state 95: #26 + <var> state 96 + state 96: #26 + state 97: #29 + <var> state 98 + state 98: #29 + <var> state 99 + state 99: #29 + state 100: #11 #13 #24 #26 #29 + () state 101 + <app> state 102 + state 101: #11 + state 102: #13 #24 #26 #29 + <app> state 103 + state 103: #13 #24 #26 #29 + , state 104 + +: state 107 + <: state 110 + % state 113 + state 104: #13 + <var> state 105 + state 105: #13 + <var> state 106 + state 106: #13 + state 107: #24 + <var> state 108 + state 108: #24 + <var> state 109 + state 109: #24 + state 110: #26 + <var> state 111 + state 111: #26 + <var> state 112 + state 112: #26 + state 113: #29 + <var> state 114 + state 114: #29 + <var> state 115 + state 115: #29 + state 116: #12 #14 #16 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 + <var> state 117 + <app> state 130 + state 117: #24 #26 #29 + <var> state 118 + state 118: #24 #26 #29 + <app> state 119 + state 119: #24 #26 #29 + <app> state 120 + state 120: #24 #26 #29 + +: state 121 + <: state 124 + % state 127 + state 121: #24 + <var> state 122 + state 122: #24 + <var> state 123 + state 123: #24 + state 124: #26 + <var> state 125 + state 125: #26 + <var> state 126 + state 126: #26 + state 127: #29 + <var> state 128 + state 128: #29 + <var> state 129 + state 129: #29 + state 130: #12 #14 #16 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 + <var> state 131 + , state 145 + : state 163 + +: state 181 + <: state 201 + % state 221 + state 131: #24 #26 #29 + <var> state 132 + state 132: #24 #26 #29 + <var> state 133 + state 133: #24 #26 #29 + <app> state 134 + state 134: #24 #26 #29 + <app> state 135 + state 135: #24 #26 #29 + +: state 136 + <: state 139 + % state 142 + state 136: #24 + <var> state 137 + state 137: #24 + <var> state 138 + state 138: #24 + state 139: #26 + <var> state 140 + state 140: #26 + <var> state 141 + state 141: #26 + state 142: #29 + <var> state 143 + state 143: #29 + <var> state 144 + state 144: #29 + state 145: #12 #14 #24 #26 #29 + <var> state 146 + state 146: #12 #14 #24 #26 #29 + <var> state 147 + state 147: #12 #14 #24 #26 #29 + () state 148 + <app> state 149 + state 148: #12 + state 149: #14 #24 #26 #29 + <app> state 150 + state 150: #14 #24 #26 #29 + , state 151 + +: state 154 + <: state 157 + % state 160 + state 151: #14 + <var> state 152 + state 152: #14 + <var> state 153 + state 153: #14 + state 154: #24 + <var> state 155 + state 155: #24 + <var> state 156 + state 156: #24 + state 157: #26 + <var> state 158 + state 158: #26 + <var> state 159 + state 159: #26 + state 160: #29 + <var> state 161 + state 161: #29 + <var> state 162 + state 162: #29 + state 163: #16 #18 #24 #26 #29 + <var> state 164 + state 164: #16 #18 #24 #26 #29 + <var> state 165 + state 165: #16 #18 #24 #26 #29 + [] state 166 + <app> state 167 + state 166: #16 + state 167: #18 #24 #26 #29 + <app> state 168 + state 168: #18 #24 #26 #29 + : state 169 + +: state 172 + <: state 175 + % state 178 + state 169: #18 + <var> state 170 + state 170: #18 + <var> state 171 + state 171: #18 + state 172: #24 + <var> state 173 + state 173: #24 + <var> state 174 + state 174: #24 + state 175: #26 + <var> state 176 + state 176: #26 + <var> state 177 + state 177: #26 + state 178: #29 + <var> state 179 + state 179: #29 + <var> state 180 + state 180: #29 + state 181: #19 #21 #23 #24 #26 #29 + <var> state 182 + state 182: #19 #21 #23 #24 #26 #29 + <var> state 183 + state 183: #19 #21 #23 #24 #26 #29 + <var> state 184 + <app> state 185 + state 184: #23 + state 185: #19 #21 #23 #24 #26 #29 + <var> state 186 + <app> state 188 + state 186: #23 + <var> state 187 + state 187: #23 + state 188: #19 #21 #23 #24 #26 #29 + <var> state 189 + +: state 192 + <: state 195 + % state 198 + state 189: #23 + <var> state 190 + state 190: #23 + <var> state 191 + state 191: #23 + state 192: #19 #23 #24 + <var> state 193 + state 193: #19 #23 #24 + <var> state 194 + state 194: #19 #23 #24 + state 195: #21 #23 #26 + <var> state 196 + state 196: #21 #23 #26 + <var> state 197 + state 197: #21 #23 #26 + state 198: #23 #29 + <var> state 199 + state 199: #23 #29 + <var> state 200 + state 200: #23 #29 + state 201: #20 #22 #24 #25 #26 #29 + <var> state 202 + state 202: #20 #22 #24 #25 #26 #29 + <var> state 203 + state 203: #20 #22 #24 #25 #26 #29 + <var> state 204 + <app> state 205 + state 204: #25 + state 205: #20 #22 #24 #25 #26 #29 + <var> state 206 + <app> state 208 + state 206: #25 + <var> state 207 + state 207: #25 + state 208: #20 #22 #24 #25 #26 #29 + <var> state 209 + +: state 212 + <: state 215 + % state 218 + state 209: #25 + <var> state 210 + state 210: #25 + <var> state 211 + state 211: #25 + state 212: #22 #24 #25 + <var> state 213 + state 213: #22 #24 #25 + <var> state 214 + state 214: #22 #24 #25 + state 215: #20 #25 #26 + <var> state 216 + state 216: #20 #25 #26 + <var> state 217 + state 217: #20 #25 #26 + state 218: #25 #29 + <var> state 219 + state 219: #25 #29 + <var> state 220 + state 220: #25 #29 + state 221: #24 #26 #27 #28 #29 + <var> state 222 + state 222: #24 #26 #27 #28 #29 + <var> state 223 + state 223: #24 #26 #27 #28 #29 + <var> state 224 + <app> state 225 + state 224: #28 + state 225: #24 #26 #27 #28 #29 + <var> state 226 + <app> state 228 + state 226: #28 + <var> state 227 + state 227: #28 + state 228: #24 #26 #27 #28 #29 + <var> state 229 + +: state 232 + <: state 235 + % state 238 + state 229: #28 + <var> state 230 + state 230: #28 + <var> state 231 + state 231: #28 + state 232: #24 #28 + <var> state 233 + state 233: #24 #28 + <var> state 234 + state 234: #24 #28 + state 235: #26 #28 + <var> state 236 + state 236: #26 #28 + <var> state 237 + state 237: #26 #28 + state 238: #27 #28 #29 + <var> state 239 + state 239: #27 #28 #29 + <var> state 240 + state 240: #27 #28 #29 +} +{ + rule #0: x::int!=y::int = x!=y + rule #1: x::double!=y::double = x!=y + rule #2: x::int!=y::double = x!=y + rule #3: x::double!=y::int = x!=y + rule #4: x::bigint!=y::bigint = bigint_cmp x y!=0 + rule #5: x::int!=y::bigint = bigint x!=y + rule #6: x::bigint!=y::int = x!=bigint y + rule #7: x::bigint!=y::double = double x!=y + rule #8: x::double!=y::bigint = x!=double y + rule #9: x!=y = bigint x!=bigint y + rule #10: x::string!=y::string = strcmp x y!=0 + rule #11: ()!=() = 0 + rule #12: (x,xs)!=() = 1 + rule #13: ()!=(x,xs) = 1 + rule #14: (x,xs)!=(y,ys) = if x!=y then 1 else xs!=ys + rule #15: []!=[] = 0 + rule #16: x:xs!=[] = 1 + rule #17: []!=x:xs = 1 + rule #18: x:xs!=y:ys = if x!=y then 1 else xs!=ys + rule #19: x1+:y1!=x2+:y2 = x1!=x2||y1!=y2 + rule #20: r1<:t1!=r2<:t2 = r1!=r2||t1!=t2 + rule #21: z1@(_+:_)!=z2@(_<:_) = z1!=rect z2 + rule #22: z1@(_<:_)!=z2@(_+:_) = rect z1!=z2 + rule #23: x1+:y1!=x2 = x1!=x2||y1!=0 + rule #24: x1!=x2+:y2 = x1!=x2||y2!=0 + rule #25: z1@(r1<:t1)!=x2 = z1!=x2<:0 + rule #26: x1!=z2@(r2<:t2) = x1<:0!=z2 + rule #27: x1%y1!=x2%y2 = x1*y2!=x2*y1 + rule #28: x1%y1!=x2 = x1!=x2*y1 + rule #29: x1!=x2%y2 = x1*y2!=x2 + state 0: #0 #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 + <var> state 1 + <var>::int state 13 + <var>::bigint state 28 + <var>::double state 43 + <var>::string state 58 + <var> state 71 + [] state 84 + () state 100 + <app> state 116 + state 1: #24 #26 #29 + <app> state 2 + state 2: #24 #26 #29 + <app> state 3 + state 3: #24 #26 #29 + +: state 4 + <: state 7 + % state 10 + state 4: #24 + <var> state 5 + state 5: #24 + <var> state 6 + state 6: #24 + state 7: #26 + <var> state 8 + state 8: #26 + <var> state 9 + state 9: #26 + state 10: #29 + <var> state 11 + state 11: #29 + <var> state 12 + state 12: #29 + state 13: #0 #2 #5 #24 #26 #29 + <var>::int state 14 + <var>::bigint state 15 + <var>::double state 16 + <app> state 17 + state 14: #0 + state 15: #5 + state 16: #2 + state 17: #24 #26 #29 + <app> state 18 + state 18: #24 #26 #29 + +: state 19 + <: state 22 + % state 25 + state 19: #24 + <var> state 20 + state 20: #24 + <var> state 21 + state 21: #24 + state 22: ... [truncated message content] |
From: <js...@us...> - 2008-07-02 08:05:19
|
Revision: 365 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=365&view=rev Author: jspitz Date: 2008-07-02 01:05:27 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Rename constructors, add list synonym for members Modified Paths: -------------- pure/trunk/examples/set.pure Modified: pure/trunk/examples/set.pure =================================================================== --- pure/trunk/examples/set.pure 2008-07-02 08:02:31 UTC (rev 364) +++ pure/trunk/examples/set.pure 2008-07-02 08:05:27 UTC (rev 365) @@ -1,6 +1,7 @@ /* Pure's set and bag data types based on AVL trees. */ -/* Copyright (c) 2008 by Albert Graef <Dr....@t-...>. +/* Copyright (c) 2008 by Albert Graef <Dr....@t-...> + and Jiri Spitz <jir...@bl...>. This file is part of the Pure programming language and system. @@ -39,7 +40,7 @@ null m tests whether m is the empty set or bag member m x tests whether m contains x -members m list members of m in ascending order +members m, list m list members of m in ascending order first m, last m return first and last member of m rmfirst m, rmlast m remove first and last member from m @@ -62,27 +63,27 @@ *****/ // set and bag type checks -bagp (Set_bag _) = 1; +bagp (Bag _) = 1; bagp _ = 0; -setp (Set_set _) = 1; +setp (Set _) = 1; setp _ = 0; // create an empty set or bag -emptyset = Set_set nil; -emptybag = Set_bag nil; +emptyset = Set nil; +emptybag = Bag nil; // create set or bag from a list set xs = foldl insert emptyset xs if listp xs; bag xs = foldl insert emptybag xs if listp xs; // insert a new member into a set or bag -insert (t@Set_set m) y::int | -insert (t@Set_set m) y::string | -insert (t@Set_set m) y | -insert (t@Set_bag m) y::int | -insert (t@Set_bag m) y::string | -insert (t@Set_bag m) y = t ((insert m y)!0) +insert (t@Set m) y::int | +insert (t@Set m) y::string | +insert (t@Set m) y | +insert (t@Bag m) y::int | +insert (t@Bag m) y::string | +insert (t@Bag m) y = t ((insert m y)!0) with insert nil key::int | insert nil key::string | @@ -92,7 +93,7 @@ insert (bin k::int b::int l r) key::int | insert (bin k::string b::int l r) key::string | insert (bin k b::int l r) key - = [(bin key b l r), 0] if (key == k) && (t === Set_set); + = [(bin key b l r), 0] if (key == k) && (t === Set); insert (bin k::int b::int l r) key::int | insert (bin k::string b::int l r) key::string | @@ -105,7 +106,7 @@ insert (bin k b::int l r) key = adjust rightHasChanged (bin k b l newR) ( 1) when [newR, rightHasChanged] = insert r key end - if ((key > k) && (t === Set_set)) || ((key >= k) && (t === Set_bag)); + if ((key > k) && (t === Set)) || ((key >= k) && (t === Bag)); adjust 0 oldTree _ = [oldTree, 0]; @@ -138,12 +139,12 @@ end; // delete a meber by key from the data structure -delete (t@Set_set m) y::int | -delete (t@Set_set m) y::string | -delete (t@Set_set m) y | -delete (t@Set_bag m) y::int | -delete (t@Set_bag m) y::string | -delete (t@Set_bag m) y +delete (t@Set m) y::int | +delete (t@Set m) y::string | +delete (t@Set m) y | +delete (t@Bag m) y::int | +delete (t@Bag m) y::string | +delete (t@Bag m) y = t ((delete m y)!0) with delete nil _ = [nil, 0]; @@ -197,27 +198,27 @@ end; // check for the empty data structure -null (Set_set nil) = 1; -null (Set_set _) = 0; +null (Set nil) = 1; +null (Set _) = 0; -null (Set_bag nil) = 1; -null (Set_bag _) = 0; +null (Bag nil) = 1; +null (Bag _) = 0; // get a number of members in data structure -#(Set_set m) | -#(Set_bag m) = #m +#(Set m) | +#(Bag m) = #m with #nil = 0; #(bin _ _ m1 m2) = #m1 + #m2 + 1 end; // check whether a key exists in data structure -member (Set_set m) k::int | -member (Set_set m) k::string | -member (Set_set m) k | -member (Set_bag m) k::int | -member (Set_bag m) k::string | -member (Set_bag m) k +member (Set m) k::int | +member (Set m) k::string | +member (Set m) k | +member (Bag m) k::int | +member (Bag m) k::string | +member (Bag m) k = member m k with member nil _ = 0; @@ -231,8 +232,8 @@ end; // get all members of data structure as a list -members (Set_set m) | -members (Set_bag m) +members (Set m) | +members (Bag m) = members m with members nil = []; @@ -243,9 +244,13 @@ = (members m1) + (x : (members m2)) end; +list m@(Set _) | +list m@(Bag _) + = members m; + // get the first member of an ordered data structure -first (Set_set m) | -first (Set_bag m) +first (Set m) | +first (Bag m) = first m with first (bin x _ nil _) = x; @@ -253,8 +258,8 @@ end; // get the last member of an ordered data structure -last (Set_set m) | -last (Set_bag m) +last (Set m) | +last (Bag m) = last m with last (bin x _ _ nil) = x; @@ -262,8 +267,8 @@ end; // remove the first member from an ordered data structure -rmfirst (t@Set_set m) | -rmfirst (t@Set_bag m) +rmfirst (t@Set m) | +rmfirst (t@Bag m) = t ((rmfirst m)!0) with rmfirst nil = [nil, 0]; @@ -274,8 +279,8 @@ end; // remove the last member from an ordered data structure -rmlast (t@Set_set m) | -rmlast (t@Set_bag m) +rmlast (t@Set m) | +rmlast (t@Bag m) = t ((rmlast m)!0) with rmlast nil = [nil, 0]; @@ -286,45 +291,45 @@ end; // set and bag relations -m1@(Set_set _) == m2@(Set_set _) | -m1@(Set_bag _) == m2@(Set_bag _) +m1@(Set _) == m2@(Set _) | +m1@(Bag _) == m2@(Bag _) = (members m1 == members m2); -m1@(Set_set _) != m2@(Set_set _) | -m1@(Set_bag _) != m2@(Set_bag _) +m1@(Set _) != m2@(Set _) | +m1@(Bag _) != m2@(Bag _) = (members m1 != members m2); -m1@(Set_set _) <= m2@(Set_set _) +m1@(Set _) <= m2@(Set _) = all (member m2) (members m1); -m1@(Set_bag _) <= m2@(Set_bag _) +m1@(Bag _) <= m2@(Bag _) = (m1 - m2) == nil; -m1@(Set_set _) >= m2@(Set_set _) +m1@(Set _) >= m2@(Set _) = all (member m1) (members m2); -m1@(Set_bag _) >= m2@(Set_bag _) +m1@(Bag _) >= m2@(Bag _) = (m2 - m1) == nil; -m1@(Set_set _) < m2@(Set_set _) | -m1@(Set_bag _) < m2@(Set_bag _) +m1@(Set _) < m2@(Set _) | +m1@(Bag _) < m2@(Bag _) = if (m1 <= m2) then (m1 != m2) else 0; -m1@(Set_set _) > m2@(Set_set _) | -m1@(Set_bag _) > m2@(Set_bag _) +m1@(Set _) > m2@(Set _) | +m1@(Bag _) > m2@(Bag _) = if (m1 >= m2) then (m1 != m2) else 0; // set and bag union -m1@(Set_set _) + m2@(Set_set _) | -m1@(Set_bag _) + m2@(Set_bag _) +m1@(Set _) + m2@(Set _) | +m1@(Bag _) + m2@(Bag _) = foldl insert m1 (members m2); // set and bag difference -m1@(Set_set _) - m2@(Set_set _) | -m1@(Set_bag _) - m2@(Set_bag _) +m1@(Set _) - m2@(Set _) | +m1@(Bag _) - m2@(Bag _) = foldl delete m1 (members m2); // set and bag intersection -m1@(Set_set _) * m2@(Set_set _) | -m1@(Set_bag _) * m2@(Set_bag _) +m1@(Set _) * m2@(Set _) | +m1@(Bag _) * m2@(Bag _) = m1 - (m1 - m2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 08:02:22
|
Revision: 364 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=364&view=rev Author: agraef Date: 2008-07-02 01:02:31 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Bugfix: bigint->int conversion dropped sign. Modified Paths: -------------- pure/trunk/runtime.cc Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-07-02 08:01:36 UTC (rev 363) +++ pure/trunk/runtime.cc 2008-07-02 08:02:31 UTC (rev 364) @@ -1689,7 +1689,7 @@ assert(x); switch (x->tag) { case EXPR::INT: return x; - case EXPR::BIGINT: return pure_int(mpz_get_ui(x->data.z)); + case EXPR::BIGINT: return pure_int(mpz_get_si(x->data.z)); case EXPR::DBL: return pure_int((int32_t)x->data.d); #if SIZEOF_VOID_P==8 // Must cast to 64 bit here first, since on 64 bit systems g++ gives an This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 08:01:28
|
Revision: 363 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=363&view=rev Author: agraef Date: 2008-07-02 01:01:36 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Add missing rules. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-02 01:13:39 UTC (rev 362) +++ pure/trunk/lib/math.pure 2008-07-02 08:01:36 UTC (rev 363) @@ -449,6 +449,12 @@ num (x%y) = x; den (x%y) = y; +num x::int | +num x::bigint = x; + +den x::int | +den x::bigint = 1; + /* Absolute value and sign. */ abs (x%y) = abs x % y; @@ -458,6 +464,9 @@ floor x@(_%_) = if n<=x then n else n-1 when n::bigint = trunc x end; ceil x@(_%_) = -floor (-x); +round (x%y) = -round ((-x)%y) if x<0; + = x div 2 + 1 if y==2; + = (2*x+y) div (2*y) otherwise; trunc (x%y) = x div y; frac x@(_%_) = x-trunc x; @@ -470,6 +479,12 @@ pow (x%y) n::double = pow (x/y) n; pow (x%y) (n%m) = pow (x/y) (n/m); +// Negative powers of integers. +pow x::int n::int | +pow x::int n::bigint | +pow x::bigint n::int | +pow x::bigint n::bigint = 1 % pow x (-n) if n<0; + /* Fallback rules for other functions (inexact results). */ sqrt (x%y) = sqrt (x/y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 01:13:30
|
Revision: 362 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=362&view=rev Author: agraef Date: 2008-07-01 18:13:39 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Fix up list equality test. Reported by Jiri Spitz. Modified Paths: -------------- pure/trunk/lib/prelude.pure pure/trunk/test/prelude.log Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-07-02 01:06:03 UTC (rev 361) +++ pure/trunk/lib/prelude.pure 2008-07-02 01:13:39 UTC (rev 362) @@ -140,7 +140,7 @@ []==[] = 1; (x:xs)==[] = 0; []==(x:xs) = 0; -(x:xs)==(y:ys) = if x==y then xs==ys else 1; +(x:xs)==(y:ys) = if x==y then xs==ys else 0; []!=[] = 0; (x:xs)!=[] = 1; Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-07-02 01:06:03 UTC (rev 361) +++ pure/trunk/test/prelude.log 2008-07-02 01:13:39 UTC (rev 362) @@ -440,7 +440,7 @@ []==[] = 1; x/*0:0101*/:xs/*0:011*/==[] = 0; []==x/*0:101*/:xs/*0:11*/ = 0; -x/*0:0101*/:xs/*0:011*/==y/*0:101*/:ys/*0:11*/ = if x/*0:0101*/==y/*0:101*/ then xs/*0:011*/==ys/*0:11*/ else 1; +x/*0:0101*/:xs/*0:011*/==y/*0:101*/:ys/*0:11*/ = if x/*0:0101*/==y/*0:101*/ then xs/*0:011*/==ys/*0:11*/ else 0; []!=[] = 0; x/*0:0101*/:xs/*0:011*/!=[] = 1; []!=x/*0:101*/:xs/*0:11*/ = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 01:05:56
|
Revision: 361 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=361&view=rev Author: agraef Date: 2008-07-01 18:06:03 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Rename nump -> numberp. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-02 01:05:10 UTC (rev 360) +++ pure/trunk/lib/math.pure 2008-07-02 01:06:03 UTC (rev 361) @@ -550,10 +550,10 @@ complexp x = case x of x+:y | x<:y = realp x && realp y; _ = 0 end; rationalp x = case x of x%y = bigintp x && bigintp y; _ = 0 end; realp x = intp x || bigintp x || doublep x || rationalp x; -nump x = realp x || complexp x; +numberp x = realp x || complexp x; exactp x = intp x || bigintp x || rationalp || - complexp x && exactp (re x) && exactp (im x) if nump x; + complexp x && exactp (re x) && exactp (im x) if numberp x; infp x::double = not nanp x && nanp (x-x); nanp x::double = x===nan; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-02 01:05:02
|
Revision: 360 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=360&view=rev Author: agraef Date: 2008-07-01 18:05:10 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add rational numbers. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lib/math.pure Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-07-01 22:01:15 UTC (rev 359) +++ pure/trunk/ChangeLog 2008-07-02 01:05:10 UTC (rev 360) @@ -1,3 +1,7 @@ +2008-07-02 Albert Graef <Dr....@t-...> + + * lib/math.pure: Added rational numbers. + 2008-07-01 Albert Graef <Dr....@t-...> * lib/primitives.pure, runtime.cc/h: Add the GMP gcd and lcm Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 22:01:15 UTC (rev 359) +++ pure/trunk/lib/math.pure 2008-07-02 01:05:10 UTC (rev 360) @@ -1,5 +1,5 @@ -/* Pure math routines. Also defines the complex numbers. */ +/* Pure math routines. Also defines complex and rational numbers. */ /* Copyright (c) 2008 by Albert Graef <Dr....@t-...>. @@ -370,13 +370,189 @@ z1@(r1<:t1)!=x2 = z1 != (x2<:0); x1!=z2@(r2<:t2) = (x1<:0) != z2; +/* Rational numbers. These are constructed with the exact division operator + '%' which has the same precedence and fixity as the other division + operators declared in the prelude. */ + +infixl 7 % ; + +/* The '%' operator returns a rational or complex rational for any combination + of integer, rational and complex integer/rational arguments, provided that + the denominator is nonzero (otherwise it returns a floating point nan or + infinity, depending on the numerator). Machine int operands are always + promoted to bigints. For other numeric operands '%' works just like + '/'. Rational results are normalized so that the sign is always in the + numerator and numerator and denominator are relatively prime. Hence a + rational zero is always represented as 1L%0L. */ + +x::bigint % 0L = x/0; +x::bigint % y::bigint = (-x)%(-y) if y<0; + = (x div d) % (y div d) when d = gcd x y end + if gcd x y > 1; + +// int/bigint operands +x::int % y::bigint = bigint x % y; +x::bigint % y::int = x % bigint y; +x::int % y::int = bigint x % bigint y; + +// rational operands +(x1%y1)%(x2%y2) = (x1*y2)%(y1*x2); +(x1%y1)%x2 = x1%(y1*x2); +x1%(x2%y2) = (x1*y2)%x2; + +// complex operands (these must both use the same representation, otherwise +// the result won't be exact) +z1@(_+:_)%z2@(_<:_) | +z1@(_<:_)%z2@(_+:_) = z1/z2; +(x1+:y1)%(x2+:y2) = (x1*x2+y1*y2)%d +: (y1*x2-x1*y2)%d + when d = x2*x2+y2*y2 end; +(x1+:y1)%x2 = (x1*x2)%d +: (y1*x2)%d when d = x2*x2 end; +x1%(x2+:y2) = (x1*x2)%d +: (-x1*y2)%d when d = x2*x2+y2*y2 end; +(r1<:t1)%(r2<:t2) = r1%r2 <: t1-t2; +(r1<:t1)%x2 = r1%x2 <: t1; +x1%(r2<:t2) = x1%r2 <: -t2; + +// fall back to ordinary inexact division in all other cases +x::double%y | +x%y::double = x/y; + +/* Conversions. */ + +rational x@(_%_) = x; +rational x::int | +rational x::bigint = x%1; + +// TODO: Need to rationalize doubles here. Currently this is a no-op. +rational x::double = x; + +rational (x+:y) = rational x +: rational y; +rational (x<:y) = rational x <: rational y; + +int x@(_%_) = int (bigint x); +bigint x@(_%_) = trunc x; +double (x%y) = x/y; + +complex (x%y) = x%y +: 0L%1L; +rect (x%y) = x%y +: 0L%1L; +polar (x%y) = x%y <: 0L%1L; + +/* Note that these normalization rules will yield inexact results when + triggered. Thus you have to take care that your polar representations stay + normalized if you want to do computations with exact complex rationals in + polar notation. */ +r@(_%_)<:t = -r <: t+pi if r<0; +r<:t@(_%_) = r <: atan2 (sin t) (cos t) if t<-pi || t>pi; + = r <: pi if t==-pi; + +/* Numerator and denominator. */ + +num (x%y) = x; +den (x%y) = y; + +/* Absolute value and sign. */ + +abs (x%y) = abs x % y; +sgn (x%y) = sgn x; + +/* Rounding functions. These return exact results here. */ + +floor x@(_%_) = if n<=x then n else n-1 when n::bigint = trunc x end; +ceil x@(_%_) = -floor (-x); +trunc (x%y) = x div y; +frac x@(_%_) = x-trunc x; + +/* The pow function. Returns exact results for integer exponents. */ + +pow (x%y) n::int | +pow (x%y) n::bigint = pow x n % pow y n if n>0; + = pow y (-n) % pow x (-n) if n<0; + = 1L%1L otherwise; +pow (x%y) n::double = pow (x/y) n; +pow (x%y) (n%m) = pow (x/y) (n/m); + +/* Fallback rules for other functions (inexact results). */ + +sqrt (x%y) = sqrt (x/y); + +exp (x%y) = exp (x/y); +ln (x%y) = ln (x/y); +log (x%y) = log (x/y); + +sin (x%y) = sin (x/y); +cos (x%y) = cos (x/y); +tan (x%y) = tan (x/y); +asin (x%y) = asin (x/y); +acos (x%y) = acos (x/y); +atan (x%y) = atan (x/y); + +atan2 (x%y) z = atan2 (x/y) z; +atan2 x (y%z) = atan2 x (y/z); + +sinh (x%y) = sinh (x/y); +cosh (x%y) = cosh (x/y); +tanh (x%y) = tanh (x/y); +asinh (x%y) = asinh (x/y); +acosh (x%y) = acosh (x/y); +atanh (x%y) = atanh (x/y); + +/* Rational arithmetic. */ + +-(x%y) = (-x)%y; + +(x1%y1)+(x2%y2) = (x1*y2+x2*y1) % (y1*y2); +(x1%y1)-(x2%y2) = (x1*y2-x2*y1) % (y1*y2); +(x1%y1)*(x2%y2) = (x1*x2) % (y1*y2); + +(x1%y1)+x2 = (x1+x2*y1) % y1; +(x1%y1)-x2 = (x1-x2*y1) % y1; +(x1%y1)*x2 = (x1*x2) % y1; + +x1+(x2%y2) = (x1*y2+x2) % y2; +x1-(x2%y2) = (x1*y2-x2) % y2; +x1*(x2%y2) = (x1*x2) % y2; + +/* / and ^ yield inexact results. */ + +(x1%y1)/(x2%y2) = (x1*y2) / (y1*x2); +(x1%y1)^(x2%y2) = (x1/y1) ^ (x2/y2); + +(x1%y1)/x2 = x1 / (y1*x2); +(x1%y1)^x2 = (x1/y1) ^ x2; + +x1/(x2%y2) = (x1*y2) / x2; +x1^(x2%y2) = x1 ^ (x2/y2); + +/* Comparisons. */ + +x1%y1 == x2%y2 = x1*y2 == x2*y1; +x1%y1 != x2%y2 = x1*y2 != x2*y1; +x1%y1 < x2%y2 = x1*y2 < x2*y1; +x1%y1 <= x2%y2 = x1*y2 <= x2*y1; +x1%y1 > x2%y2 = x1*y2 > x2*y1; +x1%y1 >= x2%y2 = x1*y2 >= x2*y1; + +x1%y1 == x2 = x1 == x2*y1; +x1%y1 != x2 = x1 != x2*y1; +x1%y1 < x2 = x1 < x2*y1; +x1%y1 <= x2 = x1 <= x2*y1; +x1%y1 > x2 = x1 > x2*y1; +x1%y1 >= x2 = x1 >= x2*y1; + +x1 == x2%y2 = x1*y2 == x2; +x1 != x2%y2 = x1*y2 != x2; +x1 < x2%y2 = x1*y2 < x2; +x1 <= x2%y2 = x1*y2 <= x2; +x1 > x2%y2 = x1*y2 > x2; +x1 >= x2%y2 = x1*y2 >= x2; + /* Additional number predicates. */ -realp x = intp x || bigintp x || doublep x; complexp x = case x of x+:y | x<:y = realp x && realp y; _ = 0 end; +rationalp x = case x of x%y = bigintp x && bigintp y; _ = 0 end; +realp x = intp x || bigintp x || doublep x || rationalp x; nump x = realp x || complexp x; -exactp x = intp x || bigintp x || +exactp x = intp x || bigintp x || rationalp || complexp x && exactp (re x) && exactp (im x) if nump x; infp x::double = not nanp x && nanp (x-x); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2008-07-01 22:01:14
|
Revision: 359 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=359&view=rev Author: jspitz Date: 2008-07-01 15:01:15 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add redesigned set and bag module. Added Paths: ----------- pure/trunk/examples/set.pure Added: pure/trunk/examples/set.pure =================================================================== --- pure/trunk/examples/set.pure (rev 0) +++ pure/trunk/examples/set.pure 2008-07-01 22:01:15 UTC (rev 359) @@ -0,0 +1,437 @@ +/* Pure's set and bag data types based on AVL trees. */ + +/* Copyright (c) 2008 by Albert Graef <Dr....@t-...>. + + This file is part of the Pure programming language and system. + + Pure is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Pure 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 this program. If not, see <http://www.gnu.org/licenses/>. */ + + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + The used algorithm of AVL trees has its origin in the SWI-Prolog + implementation of association lists. The original file was created by + R. A. O'Keefe and updated for the SWI-Prolog by Jan Wielemaker. For the + original file see http://www.swi-prolog.org. + + The port from SWI-Prolog and the deletion stuff (rmfirst, rmlast, delete) + missing in the original file was provided by Jiri Spitz +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + + +/* Public operations: ****************************************************** + +emptyset, emptybag: return the empty set or bag +set xs, bag xs; create a set or bag from list xs +setp x, bagp x; check whether x is a set or bag + +#m size of set or bag m + +null m tests whether m is the empty set or bag +member m x tests whether m contains x +members m list members of m in ascending order + +first m, last m return first and last member of m +rmfirst m, rmlast m remove first and last member from m +insert m x insert x into m (replace existing element) +delete m x remove x from m + + *************************************************************************/ + + +/* Empty tree constant, consider this private. */ +nullary nil; + +/***** +Tree for set and bag is either: +- nil (empty tree) or +- bin key Balance Left Right (Left, Right: trees) + + +Balance: ( 1), ( 0), or (-1) denoting |L|-|R| = 1, 0, or -1, respectively +*****/ + +// set and bag type checks +bagp (Set_bag _) = 1; +bagp _ = 0; + +setp (Set_set _) = 1; +setp _ = 0; + +// create an empty set or bag +emptyset = Set_set nil; +emptybag = Set_bag nil; + +// create set or bag from a list +set xs = foldl insert emptyset xs if listp xs; +bag xs = foldl insert emptybag xs if listp xs; + +// insert a new member into a set or bag +insert (t@Set_set m) y::int | +insert (t@Set_set m) y::string | +insert (t@Set_set m) y | +insert (t@Set_bag m) y::int | +insert (t@Set_bag m) y::string | +insert (t@Set_bag m) y = t ((insert m y)!0) +with + insert nil key::int | + insert nil key::string | + insert nil key + = [(bin key ( 0) nil nil), 1]; + + insert (bin k::int b::int l r) key::int | + insert (bin k::string b::int l r) key::string | + insert (bin k b::int l r) key + = [(bin key b l r), 0] if (key == k) && (t === Set_set); + + insert (bin k::int b::int l r) key::int | + insert (bin k::string b::int l r) key::string | + insert (bin k b::int l r) key + = adjust leftHasChanged (bin k b newL r) (-1) + when [newL, leftHasChanged] = insert l key end if key < k; + + insert (bin k::int b::int l r) key::int | + insert (bin k::string b::int l r) key::string | + insert (bin k b::int l r) key + = adjust rightHasChanged (bin k b l newR) ( 1) + when [newR, rightHasChanged] = insert r key end + if ((key > k) && (t === Set_set)) || ((key >= k) && (t === Set_bag)); + + adjust 0 oldTree _ + = [oldTree, 0]; + + adjust 1 (bin key::int b0::int l r) LoR::int | + adjust 1 (bin key::string b0::int l r) LoR::int | + adjust 1 (bin key b0::int l r) LoR::int + = [rebal toBeRebalanced (bin key b0 l r) b1, whatHasChanged] + when + [b1, whatHasChanged, toBeRebalanced] = table b0 LoR + end; + + rebal 0 (bin k::int _ l r) b | + rebal 0 (bin k::string _ l r) b | + rebal 0 (bin k _ l r) b + = bin k b l r; + + rebal 1 oldTree _ + = (Set_avl_geq oldTree)!0; + +// Balance rules for insertions +// balance where balance whole tree to be +// before inserted after increased rebalanced +table ( 0) (-1) = [( 1), 1, 0]; +table ( 0) ( 1) = [(-1), 1, 0]; +table ( 1) (-1) = [( 0), 0, 1]; +table ( 1) ( 1) = [( 0), 0, 0]; +table (-1) (-1) = [( 0), 0, 0]; +table (-1) ( 1) = [( 0), 0, 1]; +end; + +// delete a meber by key from the data structure +delete (t@Set_set m) y::int | +delete (t@Set_set m) y::string | +delete (t@Set_set m) y | +delete (t@Set_bag m) y::int | +delete (t@Set_bag m) y::string | +delete (t@Set_bag m) y += t ((delete m y)!0) +with + delete nil _ = [nil, 0]; + + delete (bin k::int _ nil r) key::int | + delete (bin k::string _ nil r) key::string | + delete (bin k _ nil r) key + = [r, 1] if key == k; + + delete (bin k::int _ l nil) key::int | + delete (bin k::string _ l nil) key::string | + delete (bin k _ l nil) key + = [l, 1] if key == k; + + delete (bin k::int b::int x@(bin kl::int bl::int rl ll) r) key::int | + delete (bin k::string b::int x@(bin kl::string bl::int rl ll) r) key::string | + delete (bin k b::int x@(bin kl bl::int rl ll) r) key + = Set_adjustd leftHasChanged (bin lk b newL r) (-1) + when + lk = last x; + [newL, leftHasChanged] = rmlast x + end + if key == k; + + delete (bin k::int b::int l r) key::int | + delete (bin k::string b::int l r) key::string | + delete (bin k b::int l r) key + = Set_adjustd leftHasChanged (bin k b newL r) (-1) + when + [newL, leftHasChanged] = delete l key + end + if key < k; + + delete (bin k::int b::int l r) key::int | + delete (bin k::string b::int l r) key::string | + delete (bin k b::int l r) key + = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + when + [newR, rightHasChanged] = delete r key + end + if key > k; + + rmlast nil = [nil, 0]; + rmlast (bin _ _ l nil) = [l, 1]; + rmlast (bin k b::int l r ) + = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + when [newR, rightHasChanged] = rmlast r end; + + last (bin x _ _ nil) = x; + last (bin _ _ _ m2 ) = last m2 +end; + +// check for the empty data structure +null (Set_set nil) = 1; +null (Set_set _) = 0; + +null (Set_bag nil) = 1; +null (Set_bag _) = 0; + +// get a number of members in data structure +#(Set_set m) | +#(Set_bag m) = #m +with + #nil = 0; + #(bin _ _ m1 m2) = #m1 + #m2 + 1 +end; + +// check whether a key exists in data structure +member (Set_set m) k::int | +member (Set_set m) k::string | +member (Set_set m) k | +member (Set_bag m) k::int | +member (Set_bag m) k::string | +member (Set_bag m) k += member m k +with + member nil _ = 0; + + member (bin x _ m1 m2) y::int | + member (bin x _ m1 m2) y::string | + member (bin x _ m1 m2) y + = member m1 y if x > y; + = member m2 y if x < y; + = 1 if x == y +end; + +// get all members of data structure as a list +members (Set_set m) | +members (Set_bag m) += members m +with + members nil = []; + + members (bin x::int _ m1 m2) | + members (bin x::string _ m1 m2) | + members (bin x _ m1 m2) + = (members m1) + (x : (members m2)) +end; + +// get the first member of an ordered data structure +first (Set_set m) | +first (Set_bag m) += first m +with + first (bin x _ nil _) = x; + first (bin _ _ m1 _) = first m1 +end; + +// get the last member of an ordered data structure +last (Set_set m) | +last (Set_bag m) += last m +with + last (bin x _ _ nil) = x; + last (bin _ _ _ m2 ) = last m2 +end; + +// remove the first member from an ordered data structure +rmfirst (t@Set_set m) | +rmfirst (t@Set_bag m) += t ((rmfirst m)!0) +with + rmfirst nil = [nil, 0]; + rmfirst (bin _ _ nil r) = [r, 1]; + rmfirst (bin k b::int l r) + = Set_adjustd leftHasChanged (bin k b newL r) (-1) + when [newL, leftHasChanged] = rmfirst l end +end; + +// remove the last member from an ordered data structure +rmlast (t@Set_set m) | +rmlast (t@Set_bag m) += t ((rmlast m)!0) +with + rmlast nil = [nil, 0]; + rmlast (bin _ _ l nil) = [l, 1]; + rmlast (bin k b::int l r ) + = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + when [newR, rightHasChanged] = rmlast r end +end; + +// set and bag relations +m1@(Set_set _) == m2@(Set_set _) | +m1@(Set_bag _) == m2@(Set_bag _) + = (members m1 == members m2); + +m1@(Set_set _) != m2@(Set_set _) | +m1@(Set_bag _) != m2@(Set_bag _) + = (members m1 != members m2); + +m1@(Set_set _) <= m2@(Set_set _) + = all (member m2) (members m1); +m1@(Set_bag _) <= m2@(Set_bag _) + = (m1 - m2) == nil; + +m1@(Set_set _) >= m2@(Set_set _) + = all (member m1) (members m2); +m1@(Set_bag _) >= m2@(Set_bag _) + = (m2 - m1) == nil; + +m1@(Set_set _) < m2@(Set_set _) | +m1@(Set_bag _) < m2@(Set_bag _) + = if (m1 <= m2) then (m1 != m2) else 0; + +m1@(Set_set _) > m2@(Set_set _) | +m1@(Set_bag _) > m2@(Set_bag _) + = if (m1 >= m2) then (m1 != m2) else 0; + +// set and bag union +m1@(Set_set _) + m2@(Set_set _) | +m1@(Set_bag _) + m2@(Set_bag _) + = foldl insert m1 (members m2); + +// set and bag difference +m1@(Set_set _) - m2@(Set_set _) | +m1@(Set_bag _) - m2@(Set_bag _) + = foldl delete m1 (members m2); + +// set and bag intersection +m1@(Set_set _) * m2@(Set_set _) | +m1@(Set_bag _) * m2@(Set_bag _) + = m1 - (m1 - m2); + + +/* Private functions, don't invoke these directly. */ + +Set_adjustd ToF::int tree LoR::int += adjust ToF tree LoR +with + adjust 0 oldTree _ = [oldTree, 0]; + + adjust 1 (bin key::int b0::int l r) LoR::int | + adjust 1 (bin key::string b0::int l r) LoR::int | + adjust 1 (bin key b0::int l r) LoR::int + = rebal toBeRebalanced (bin key b0 l r) b1 whatHasChanged + when + [b1, whatHasChanged, toBeRebalanced] = table b0 LoR; + end; +/* + Note that rebali and rebald are not symmetrical. With insertions it is + sufficient to know the original balance and insertion side in order to + decide whether the whole tree increases. With deletions it is sometimes not + sufficient and we need to know which kind of tree rotation took place. +*/ + rebal 0 (bin k::int _ l r) b::int whatHasChanged | + rebal 0 (bin k::string _ l r) b::int whatHasChanged | + rebal 0 (bin k _ l r) b::int whatHasChanged + = [bin k b l r, whatHasChanged]; + + rebal 1 oldTree _ _ = Set_avl_geq oldTree; + +// Balance rules for deletions +// balance where balance whole tree to be +// before deleted after decreased rebalanced +table ( 0) ( 1) = [( 1), 0, 0]; +table ( 0) (-1) = [(-1), 0, 0]; +table ( 1) ( 1) = [( 0), 1, 1]; +// ^^^^ +// It depends on the tree pattern in avl_geq whether it really decreases + +table ( 1) (-1) = [( 0), 1, 0]; +table (-1) ( 1) = [( 0), 1, 0]; +table (-1) (-1) = [( 0), 1, 1] +// ^^^^ +// It depends on the tree pattern in avl_geq whether it really decreases +end; + + +// Single and double tree rotations - these are common for insert and delete +/* + The patterns (-1)-(-1), (-1)-( 1), ( 1)-( 1) and ( 1)-(-1) on the LHS always + change the tree height and these are the only patterns which can happen + after an insertion. That's the reason why we can use tablei only to decide + the needed changes. + The patterns (-1)-( 0) and ( 1)-( 0) do not change the tree height. After a + deletion any pattern can occur and so we return 1 or 0 as a flag of + a height change. +*/ + +Set_avl_geq x = avl_geq x +with + avl_geq (bin a::int (-1) alpha (bin b::int (-1) beta gamma)) | + avl_geq (bin a::string (-1) alpha (bin b::string (-1) beta gamma)) | + avl_geq (bin a (-1) alpha (bin b (-1) beta gamma)) + = [bin b ( 0) (bin a ( 0) alpha beta) gamma, 1]; + + avl_geq (bin a::int (-1) alpha (bin b::int ( 0) beta gamma)) | + avl_geq (bin a::string (-1) alpha (bin b::string ( 0) beta gamma)) | + avl_geq (bin a (-1) alpha (bin b ( 0) beta gamma)) + = [bin b ( 1) (bin a (-1) alpha beta) gamma, 0]; + // the tree doesn't decrease with this pattern + + avl_geq (bin a::int (-1) alpha + (bin b::int ( 1) (bin x::int b1 beta gamma) delta)) | + avl_geq (bin a::string (-1) alpha + (bin b::string ( 1) (bin x::string b1 beta gamma) delta)) | + avl_geq (bin a (-1) alpha + (bin b ( 1) (bin x b1 beta gamma) delta)) + = [bin x ( 0) (bin a b2 alpha beta) + (bin b b3 gamma delta), 1] + when + [b2, b3] = table b1 + end; + + avl_geq (bin b::int ( 1) (bin a::int ( 1) alpha beta) gamma) | + avl_geq (bin b::string ( 1) (bin a::string ( 1) alpha beta) gamma) | + avl_geq (bin b ( 1) (bin a ( 1) alpha beta) gamma) + = [bin a ( 0) alpha (bin b ( 0) beta gamma), 1]; + + avl_geq (bin b::int ( 1) (bin a::int ( 0) alpha beta) gamma) | + avl_geq (bin b::string ( 1) (bin a::string ( 0) alpha beta) gamma) | + avl_geq (bin b ( 1) (bin a ( 0) alpha beta) gamma) + = [bin a (-1) alpha (bin b ( 1) beta gamma), 0]; + // the tree doesn't decrease with this pattern + + avl_geq (bin b::int ( 1) + (bin a::int (-1) alpha (bin x::int b1 beta gamma)) delta) | + avl_geq (bin b::string ( 1) + (bin a::string (-1) alpha (bin x::string b1 beta gamma)) delta) | + avl_geq (bin b ( 1) + (bin a (-1) alpha (bin x b1 beta gamma)) delta) + = [bin x ( 0) (bin a b2 alpha beta) + (bin b b3 gamma delta), 1] + when + [b2, b3] = table b1 + end; + + table ( 1) = [( 0), (-1)]; + table (-1) = [( 1), ( 0)]; + table ( 0) = [( 0), ( 0)] +end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 21:54:04
|
Revision: 358 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=358&view=rev Author: agraef Date: 2008-07-01 14:54:14 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Update logs. Modified Paths: -------------- pure/trunk/test/prelude.log Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-07-01 21:53:10 UTC (rev 357) +++ pure/trunk/test/prelude.log 2008-07-01 21:54:14 UTC (rev 358) @@ -195,6 +195,14 @@ x/*0:01*/::double>=y/*0:1*/::bigint = x/*0:01*/>=double y/*0:1*/; x/*0:01*/::double==y/*0:1*/::bigint = x/*0:01*/==double y/*0:1*/; x/*0:01*/::double!=y/*0:1*/::bigint = x/*0:01*/!=double y/*0:1*/; +gcd x/*0:01*/::bigint y/*0:1*/::bigint = bigint_gcd x/*0:01*/ y/*0:1*/; +lcm x/*0:01*/::bigint y/*0:1*/::bigint = bigint_lcm x/*0:01*/ y/*0:1*/; +gcd x/*0:01*/::int y/*0:1*/::bigint = bigint_gcd (bigint x/*0:01*/) y/*0:1*/; +gcd x/*0:01*/::bigint y/*0:1*/::int = bigint_gcd x/*0:01*/ (bigint y/*0:1*/); +gcd x/*0:01*/::int y/*0:1*/::int = int (bigint_gcd (bigint x/*0:01*/) (bigint y/*0:1*/)); +lcm x/*0:01*/::int y/*0:1*/::bigint = bigint_lcm (bigint x/*0:01*/) y/*0:1*/; +lcm x/*0:01*/::bigint y/*0:1*/::int = bigint_lcm x/*0:01*/ (bigint y/*0:1*/); +lcm x/*0:01*/::int y/*0:1*/::int = int (bigint_lcm (bigint x/*0:01*/) (bigint y/*0:1*/)); pow x/*0:01*/::int y/*0:1*/::int = bigint_pow (bigint x/*0:01*/) y/*0:1*/ if y/*0:1*/>=0; pow x/*0:01*/::bigint y/*0:1*/::bigint = bigint_pow x/*0:01*/ (int y/*0:1*/) if int y/*0:1*/>=0; pow x/*0:01*/::double y/*0:1*/::double = c_pow x/*0:01*/ y/*0:1*/ if x/*0:01*/>=0||int y/*0:1*/==y/*0:1*/; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 21:53:01
|
Revision: 357 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=357&view=rev Author: agraef Date: 2008-07-01 14:53:10 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add GMP gcd and lcm functions. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lib/primitives.pure pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/ChangeLog 2008-07-01 21:53:10 UTC (rev 357) @@ -1,5 +1,8 @@ 2008-07-01 Albert Graef <Dr....@t-...> + * lib/primitives.pure, runtime.cc/h: Add the GMP gcd and lcm + functions. + * lexer.ll: 'list' command now also prints fixity and nullary declarations of listed symbols. Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/lib/primitives.pure 2008-07-01 21:53:10 UTC (rev 357) @@ -267,6 +267,23 @@ x::double==y::bigint = x==double y; x::double!=y::bigint = x!=double y; +/* The gcd and lcm functions from the GMP library. These return a bigint if at + least one of the arguments is a bigint, a machine int otherwise. */ + +extern expr* bigint_gcd(void*, void*); +extern expr* bigint_lcm(void*, void*); + +gcd x::bigint y::bigint = bigint_gcd x y; +lcm x::bigint y::bigint = bigint_lcm x y; + +gcd x::int y::bigint = bigint_gcd (bigint x) y; +gcd x::bigint y::int = bigint_gcd x (bigint y); +gcd x::int y::int = int (bigint_gcd (bigint x) (bigint y)); + +lcm x::int y::bigint = bigint_lcm (bigint x) y; +lcm x::bigint y::int = bigint_lcm x (bigint y); +lcm x::int y::int = int (bigint_lcm (bigint x) (bigint y)); + /* The pow function. Returns a bigint for integer arguments, double if one of the arguments is double (in the latter case, x may be negative only if y is integer). */ Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/runtime.cc 2008-07-01 21:53:10 UTC (rev 357) @@ -1894,6 +1894,24 @@ } extern "C" +pure_expr *bigint_gcd(mpz_t x, mpz_t y) +{ + pure_expr *u = pure_bigint(0, 0); + mpz_t& z = u->data.z; + mpz_gcd(z, x, y); + return u; +} + +extern "C" +pure_expr *bigint_lcm(mpz_t x, mpz_t y) +{ + pure_expr *u = pure_bigint(0, 0); + mpz_t& z = u->data.z; + mpz_lcm(z, x, y); + return u; +} + +extern "C" int32_t bigint_cmp(mpz_t x, mpz_t y) { return mpz_cmp(x, y); Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/runtime.h 2008-07-01 21:53:10 UTC (rev 357) @@ -443,6 +443,9 @@ pure_expr *bigint_and(mpz_t x, mpz_t y); pure_expr *bigint_or(mpz_t x, mpz_t y); +pure_expr *bigint_gcd(mpz_t x, mpz_t y); +pure_expr *bigint_lcm(mpz_t x, mpz_t y); + int32_t bigint_cmp(mpz_t x, mpz_t y); /* String operations. In difference to the string operations from the C This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 21:05:44
|
Revision: 356 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=356&view=rev Author: agraef Date: 2008-07-01 14:04:46 -0700 (Tue, 01 Jul 2008) Log Message: ----------- 'list' command now also prints fixity and nullary declarations of listed symbols. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lexer.ll Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-07-01 14:50:04 UTC (rev 355) +++ pure/trunk/ChangeLog 2008-07-01 21:04:46 UTC (rev 356) @@ -1,5 +1,8 @@ 2008-07-01 Albert Graef <Dr....@t-...> + * lexer.ll: 'list' command now also prints fixity and nullary + declarations of listed symbols. + * lib/math.pure: Added various bits and pieces, most notably the complex numbers. Also moved sqrt function from primitives.pure to math.pure. Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-07-01 14:50:04 UTC (rev 355) +++ pure/trunk/lexer.ll 2008-07-01 21:04:46 UTC (rev 356) @@ -505,6 +505,25 @@ sout << "def " << sym.s << " = " << *jt->second.cval << ";\n"; } else { + if (sym.fix == nullary) + sout << "nullary " << sym.s << ";\n"; + else if (sym.prec < 10) { + switch (sym.fix) { + case infix: + sout << "infix"; break; + case infixl: + sout << "infixl"; break; + case infixr: + sout << "infixr"; break; + case prefix: + sout << "prefix"; break; + case postfix: + sout << "postfix"; break; + case nullary: + assert(0 && "this can't happen"); break; + } + sout << " " << (int)sym.prec << " " << sym.s << ";\n"; + } if (xt != interp.externals.end()) { const ExternInfo& info = xt->second; sout << info << ";"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 14:50:05
|
Revision: 355 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=355&view=rev Author: agraef Date: 2008-07-01 07:50:04 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add Euler's number. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 14:07:14 UTC (rev 354) +++ pure/trunk/lib/math.pure 2008-07-01 14:50:04 UTC (rev 355) @@ -70,6 +70,10 @@ ln x::int | ln x::bigint = ln (double x); log x::int | log x::bigint = log (double x); +/* Euler's number. */ + +def e = exp 1.0; + /* Trigonometric functions. */ extern double sin(double), double cos(double), double tan(double); @@ -89,6 +93,8 @@ atan2 x::int y::double | atan2 x::bigint y::double = atan2 (double x) y; atan2 x::double y::int | atan2 x::double y::bigint = atan2 x (double y); +/* Ludolph's number. */ + def pi = 4.0*atan 1.0; /* Hyperbolic functions. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 14:07:13
|
Revision: 354 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=354&view=rev Author: agraef Date: 2008-07-01 07:07:14 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Updated ChangeLog. Modified Paths: -------------- pure/trunk/ChangeLog Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-07-01 14:06:22 UTC (rev 353) +++ pure/trunk/ChangeLog 2008-07-01 14:07:14 UTC (rev 354) @@ -1,3 +1,9 @@ +2008-07-01 Albert Graef <Dr....@t-...> + + * lib/math.pure: Added various bits and pieces, most notably the + complex numbers. Also moved sqrt function from primitives.pure to + math.pure. + 2008-06-30 Albert Graef <Dr....@t-...> * interpreter.cc (declare_extern): Fix a segfault in external This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 14:06:23
|
Revision: 353 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=353&view=rev Author: agraef Date: 2008-07-01 07:06:22 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Update logs. Modified Paths: -------------- pure/trunk/test/prelude.log Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-07-01 13:43:30 UTC (rev 352) +++ pure/trunk/test/prelude.log 2008-07-01 14:06:22 UTC (rev 353) @@ -1,3 +1,5 @@ +def false = 0; +def true = 1; throw x/*0:1*/ = pure_throw x/*0:1*/; assert p/*0:01*/ e/*0:1*/ = if p/*0:01*/ then 1 else throw e/*0:1*/; x/*0:01*/===y/*0:1*/ = same x/*0:01*/ y/*0:1*/; @@ -193,9 +195,6 @@ x/*0:01*/::double>=y/*0:1*/::bigint = x/*0:01*/>=double y/*0:1*/; x/*0:01*/::double==y/*0:1*/::bigint = x/*0:01*/==double y/*0:1*/; x/*0:01*/::double!=y/*0:1*/::bigint = x/*0:01*/!=double y/*0:1*/; -sqrt x/*0:1*/::int = c_sqrt (double x/*0:1*/) if x/*0:1*/>=0; -sqrt x/*0:1*/::bigint = c_sqrt (double x/*0:1*/) if x/*0:1*/>=0; -sqrt x/*0:1*/::double = c_sqrt x/*0:1*/ if x/*0:1*/>=0; pow x/*0:01*/::int y/*0:1*/::int = bigint_pow (bigint x/*0:01*/) y/*0:1*/ if y/*0:1*/>=0; pow x/*0:01*/::bigint y/*0:1*/::bigint = bigint_pow x/*0:01*/ (int y/*0:1*/) if int y/*0:1*/>=0; pow x/*0:01*/::double y/*0:1*/::double = c_pow x/*0:01*/ y/*0:1*/ if x/*0:01*/>=0||int y/*0:1*/==y/*0:1*/; @@ -214,6 +213,8 @@ x/*0:01*/::double^y/*0:1*/::bigint = c_pow x/*0:01*/ (double y/*0:1*/); x/*0:01*/::int^y/*0:1*/::double = c_pow (double x/*0:01*/) y/*0:1*/ if x/*0:01*/>=0||int y/*0:1*/==y/*0:1*/; x/*0:01*/::bigint^y/*0:1*/::double = c_pow (double x/*0:01*/) y/*0:1*/ if x/*0:01*/>=0||int y/*0:1*/==y/*0:1*/; +x/*0:01*/::int^y/*0:1*/::double = double x/*0:01*/^y/*0:1*/; +x/*0:01*/::bigint^y/*0:1*/::double = double x/*0:01*/^y/*0:1*/; null x/*0:1*/ = bigint x/*0:1*/==0; x/*0:01*/-y/*0:1*/ = bigint x/*0:01*/-bigint y/*0:1*/; x/*0:01*/+y/*0:1*/::int = pointer (bigint x/*0:01*/+y/*0:1*/); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 13:43:21
|
Revision: 352 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=352&view=rev Author: agraef Date: 2008-07-01 06:43:30 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add more rounding functions. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 13:31:51 UTC (rev 351) +++ pure/trunk/lib/math.pure 2008-07-01 13:43:30 UTC (rev 352) @@ -39,13 +39,19 @@ succ x = x+1; pred x = x-1; -/* Floor and ceil functions. */ +/* Rounding functions. */ extern double floor(double), double ceil(double); +extern double round(double), double trunc(double); floor x::int | floor x::bigint = x; ceil x::int | ceil x::bigint = x; +round x::int | round x::bigint = x; +trunc x::int | trunc x::bigint = x; +// Fractional part of x. +frac x::int | frac x::bigint | frac x::double = x-trunc x; + /* The sqrt function. */ extern double sqrt(double) = c_sqrt; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 13:31:44
|
Revision: 351 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=351&view=rev Author: agraef Date: 2008-07-01 06:31:51 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add syntactic number predicates. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 13:19:05 UTC (rev 350) +++ pure/trunk/lib/math.pure 2008-07-01 13:31:51 UTC (rev 351) @@ -357,3 +357,15 @@ x1!=(x2+:y2) = x1!=x2 || y2!=0; z1@(r1<:t1)!=x2 = z1 != (x2<:0); x1!=z2@(r2<:t2) = (x1<:0) != z2; + +/* Additional number predicates. */ + +realp x = intp x || bigintp x || doublep x; +complexp x = case x of x+:y | x<:y = realp x && realp y; _ = 0 end; +nump x = realp x || complexp x; + +exactp x = intp x || bigintp x || + complexp x && exactp (re x) && exactp (im x) if nump x; + +infp x::double = not nanp x && nanp (x-x); +nanp x::double = x===nan; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 13:18:56
|
Revision: 350 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=350&view=rev Author: agraef Date: 2008-07-01 06:19:05 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Overhaul of complex powers. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 11:22:42 UTC (rev 349) +++ pure/trunk/lib/math.pure 2008-07-01 13:19:05 UTC (rev 350) @@ -279,16 +279,6 @@ (x1+:y1) / (x2+:y2) = (x1*x2+y1*y2 +: y1*x2-x1*y2) / (x2*x2+y2*y2); (r1<:t1) / (r2<:t2) = r1/r2 <: t1-t2; -z1@(x1+:y1)^z2@(x2+:y2) = exp (ln z1*z2) if z1!=0; - = 0.0+:0.0 if z2!=0; - = 1.0+:0.0 otherwise; -z1@(r1<:t1)^z2@(r2<:t2) = exp (ln z1*z2) if z1!=0; - = 0.0<:0.0 if z2!=0; - = 1.0<:0.0 otherwise; - -// Complex powers of negative reals. -x1::double^x2::double = exp (ln x1*x2) if x1<0; - /* Mixed rect/polar and polar/rect forms always return a rect result. */ z1@(x1+:y1)+z2@(r2<:t2) = z1 + rect z2; @@ -303,9 +293,6 @@ z1@(x1+:y1)/z2@(r2<:t2) = z1 / rect z2; z1@(r1<:t1)/z2@(x2+:y2) = rect z1 / z2; -z1@(x1+:y1)^z2@(r2<:t2) = z1 ^ rect z2; -z1@(r1<:t1)^z2@(x2+:y2) = rect z1 ^ z2; - /* Mixed complex/real and real/complex forms yield a rect or polar result, depending on what the complex input was. */ @@ -329,11 +316,24 @@ (r1<:t1)/x2 = r1/x2 <: t1; x1/(r2<:t2) = x1/r2 <: -t2; +/* Complex powers. */ + +// These are computed most easily if the 1st operand is in polar form. +// FIXME: Deal with special cases like 0^0. These always give nan now. +z1@(x1+:y1)^z2@(x2+:y2) = polar z1^z2; +z1@(x1+:y1)^z2@(r2<:t2) = polar z1^rect z2; +(r1<:t1)^z2@(x2+:y2) | +(r1<:t1)^z2@(r2<:t2) = exp (ln r1*z2)*exp((0+:t1)*z2); + +// Mixed complex/real cases. z1@(x1+:y1)^x2 = z1 ^ (x2+:0); x1^z2@(x2+:y2) = (x1+:0) ^ z2; (r1<:t1)^x2 = r1^x2 <: t1*x2; x1^z2@(r2<:t2) = (x1<:0) ^ z2; +// Complex powers of negative reals. +x1::double^x2::double = exp (ln x1*x2) if x1<0; + /* Equality. */ (x1+:y1) == (x2+:y2) = x1==x2 && y1==y2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 11:22:33
|
Revision: 349 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=349&view=rev Author: agraef Date: 2008-07-01 04:22:42 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Fix typos. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 11:02:46 UTC (rev 348) +++ pure/trunk/lib/math.pure 2008-07-01 11:22:42 UTC (rev 349) @@ -267,10 +267,10 @@ -(x+:y) = -x +: -y; -(r<:t) = r <: t+pi; -(x1+:y1) + (x2+:y2) = x1+y2 +: y1+y2; +(x1+:y1) + (x2+:y2) = x1+x2 +: y1+y2; z1@(r1<:t1)+z2@(r2<:t2) = polar $ rect z1 + rect z2; -(x1+:y1) - (x2+:y2) = x1-y2 +: y1-y2; +(x1+:y1) - (x2+:y2) = x1-x2 +: y1-y2; z1@(r1<:t1)-z2@(r2<:t2) = polar $ rect z1 - rect z2; (x1+:y1) * (x2+:y2) = x1*x2-y1*y2 +: x1*y2+y1*x2; @@ -336,10 +336,10 @@ /* Equality. */ -(x1+:y1) == (x2+:y2) = x1==y2 && y1==y2; +(x1+:y1) == (x2+:y2) = x1==x2 && y1==y2; (r1<:t1) == (r2<:t2) = r1==r2 && t1==t2; -(x1+:y1) != (x2+:y2) = x1!=y2 || y1!=y2; +(x1+:y1) != (x2+:y2) = x1!=x2 || y1!=y2; (r1<:t1) != (r2<:t2) = r1!=r2 || t1!=t2; z1@(_+:_)==z2@(_<:_) = z1 == rect z2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 11:02:41
|
Revision: 348 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=348&view=rev Author: agraef Date: 2008-07-01 04:02:46 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Move sqrt function from primitives to math.pure. Modified Paths: -------------- pure/trunk/lib/math.pure pure/trunk/lib/primitives.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 10:50:29 UTC (rev 347) +++ pure/trunk/lib/math.pure 2008-07-01 11:02:46 UTC (rev 348) @@ -46,6 +46,24 @@ floor x::int | floor x::bigint = x; ceil x::int | ceil x::bigint = x; +/* The sqrt function. */ + +extern double sqrt(double) = c_sqrt; + +sqrt x::double = c_sqrt x if x>=0; +sqrt x::int | sqrt x::bigint = sqrt (double x); + +/* Exponential function and logarithms. */ + +extern double exp(double), double log(double) = c_log; + +ln x::double = c_log x if x>=0.0; +log x::double = c_log x/c_log 10.0 if x>=0.0; + +exp x::int | exp x::bigint = exp (double x); +ln x::int | ln x::bigint = ln (double x); +log x::int | log x::bigint = log (double x); + /* Trigonometric functions. */ extern double sin(double), double cos(double), double tan(double); @@ -67,17 +85,6 @@ def pi = 4.0*atan 1.0; -/* Exponential function and logarithms. */ - -extern double exp(double), double log(double) = c_log; - -ln x::double = c_log x if x>=0.0; -log x::double = c_log x/c_log 10.0 if x>=0.0; - -exp x::int | exp x::bigint = exp (double x); -ln x::int | ln x::bigint = ln (double x); -log x::int | log x::bigint = log (double x); - /* Hyperbolic functions. */ extern double sinh(double), double cosh(double), double tanh(double); @@ -194,8 +201,6 @@ sqrt (r<:t) = sqrt r <: t/2; // Complex square roots of negative reals. -sqrt x::int | -sqrt x::bigint | sqrt x::double = 0.0 +: sqrt (-x) if x<0; /* Complex exponential and logarithms. */ Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-07-01 10:50:29 UTC (rev 347) +++ pure/trunk/lib/primitives.pure 2008-07-01 11:02:46 UTC (rev 348) @@ -267,15 +267,6 @@ x::double==y::bigint = x==double y; x::double!=y::bigint = x!=double y; -/* The sqrt function. Integer arguments get promoted to double and the result - is always a double. The argument must be nonnegative. */ - -extern double sqrt(double) = c_sqrt; - -sqrt x::int | -sqrt x::bigint = c_sqrt (double x) if x>=0; -sqrt x::double = c_sqrt x if x>=0; - /* The pow function. Returns a bigint for integer arguments, double if one of the arguments is double (in the latter case, x may be negative only if y is integer). */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 10:50:19
|
Revision: 347 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=347&view=rev Author: agraef Date: 2008-07-01 03:50:29 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Fix up real powers of integers so that we get a complex result with math.pure. Modified Paths: -------------- pure/trunk/lib/primitives.pure Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-07-01 10:43:04 UTC (rev 346) +++ pure/trunk/lib/primitives.pure 2008-07-01 10:50:29 UTC (rev 347) @@ -308,6 +308,7 @@ x::double^y::bigint = c_pow x (double y); x::int^y::double | x::bigint^y::double = c_pow (double x) y if x>=0 || int y==y; + = double x^y otherwise; /* Pointer arithmetic. We do this using bigints, so that the code is portable to 64 bit systems. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-01 10:42:58
|
Revision: 346 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=346&view=rev Author: agraef Date: 2008-07-01 03:43:04 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add complex numbers. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-06-30 20:00:55 UTC (rev 345) +++ pure/trunk/lib/math.pure 2008-07-01 10:43:04 UTC (rev 346) @@ -1,5 +1,5 @@ -/* Pure basic math routines. */ +/* Pure math routines. Also defines the complex numbers. */ /* Copyright (c) 2008 by Albert Graef <Dr....@t-...>. @@ -93,3 +93,262 @@ asinh x::int | asinh x::bigint = asinh (double x); acosh x::int | acosh x::bigint = acosh (double x); atanh x::int | atanh x::bigint = atanh (double x); + +/* Complex numbers. We provide both rectangular (x+:y) and polar (r<:a) + representations, where (x,y) are the Cartesian coordinates and (r,t) the + radius (absolute value) and angle (in radians) of a complex number, + respectively. The +: and <: constructors bind weaker than all other + arithmetic operators and are non-associative. */ + +infix 5 +: <: ; + +/* Constructor equations to normalize the polar representation r<:t so that r + is always nonnegative and t falls in the range -pi<t<=pi. */ + +r::int<:t | +r::bigint<:t | +r::double<:t = -r <: t+pi if r<0; + +r<:t::int | +r<:t::bigint | +r<:t::double = r <: atan2 (sin t) (cos t) if t<-pi || t>pi; + = r <: pi if t==-pi; + +/* The imaginary unit. */ + +def i = 0+:1; + +/* The following operations all work with both the rectangular and the polar + representation, promoting real inputs to complex where appropriate. When + the result of an operation is again a complex number, it generally uses the + same representation as the input (except for explicit conversions). */ + +/* We mostly follow Bronstein/Semendjajew here. Please mail me if you know + better formulas for any of these. */ + +/* Convert any kind of number to a complex value. */ + +complex z@(x+:y) | complex z@(r<:t) = z; +complex x::int | complex x::bigint = x+:0; +complex x::double = x+:0.0; + +/* Convert between polar and rectangular representations. */ + +polar (x+:y) = sqrt (x*x+y*y) <: atan2 y x; +rect (r<:t) = r*cos t +: r*sin t; + +/* For convenience, make these work with real values, too. */ + +polar x::int | polar x::bigint = x<:0; +polar x::double = x<:0.0; + +rect x::int | rect x::bigint = x+:0; +rect x::double = x+:0.0; + +/* Create complex values on the unit circle. Note: To quickly compute + exp (x+:y) in polar form, use exp x*cis y. */ + +cis t = rect (1<:t); + +/* Modulus (absolute value) and argument (angle). Note that you can also find + both of these in one go by converting to polar form. */ + +abs (x+:y) = sqrt (x*x+y*y); +abs (r<:t) = r; + +arg (x+:y) = atan2 y x; +arg (r<:t) = t; + +arg x::int | +arg x::bigint | +arg x::double = atan2 0 x; + +/* Real and imaginary part. */ + +re (x+:y) = x; +re (r<:t) = r*sin t; + +re x::int | +re x::bigint | +re x::double = x; + +im (x+:y) = y; +im (r<:t) = r*cos t; + +im x::int = 0; +im x::bigint = 0L; +im x::double = 0.0; + +/* Complex conjugate. */ + +conj (x+:y) = x +: -y; +conj (r<:t) = r <: -t; + +conj x::int | +conj x::bigint | +conj x::double = x; + +/* Complex sqrt. */ + +sqrt (x+:y) = sqrt (x*x+y*y) * (cos (t/2) +: sin (t/2)); +sqrt (r<:t) = sqrt r <: t/2; + +// Complex square roots of negative reals. +sqrt x::int | +sqrt x::bigint | +sqrt x::double = 0.0 +: sqrt (-x) if x<0; + +/* Complex exponential and logarithms. */ + +exp (x+:y) = exp x * (cos y +: sin y); +exp (r<:t) = exp (r*cos t) <: r*sin t; + +ln z@(x+:y) = ln (abs z) +: arg z; +ln (r<:t) = polar (ln r +: t); + +log z@(x+:y) | +log z@(r<:t) = ln z / ln 10; + +// Complex logarithms of negative reals. +ln x::double = ln (abs x) +: arg x if x<0; +log x::double = ln x / ln 10 if x<0; + +/* Complex trig functions. */ + +sin (x+:y) = sin x*cosh y +: cos x*sinh y; +cos (x+:y) = cos x*cosh y +: -sin x*sinh y; +tan (x+:y) = (sin (2*x) +: sinh (2*y)) / (cos (2*x)+cosh (2*y)); + +// These are best computed in rect and then converted back to polar. +sin z@(r<:t) = polar $ sin $ rect z; +cos z@(r<:t) = polar $ cos $ rect z; +tan z@(r<:t) = polar $ tan $ rect z; + +// Use complex logarithms for the inverses. +asin z@(x+:y) | +asin z@(r<:t) = -i*ln (i*z+sqrt (1-z*z)); +acos z@(x+:y) | +acos z@(r<:t) = -i*ln (z+sqrt (z*z-1)); +atan z@(x+:y) | +atan z@(r<:t) = 0.0 +: inf if z==i; + = 0.0 +: -inf if z==-i; + = -i*0.5*ln ((1+i*z)/(1-i*z)); + +/* Complex hyperbolic functions. */ + +sinh (x+:y) = sinh x*cos y +: cosh x*sin y; +cosh (x+:y) = cosh x*cos y +: sinh x*sin y; +tanh (x+:y) = (sinh (2*x) +: sin (2*y)) / (cosh (2*x)+cos (2*y)); + +sinh z@(r<:t) = polar $ sinh $ rect z; +cosh z@(r<:t) = polar $ cosh $ rect z; +tanh z@(r<:t) = polar $ tanh $ rect z; + +asinh z@(x+:y) | +asinh z@(r<:t) = ln (z+sqrt (z*z+1)); +acosh z@(x+:y) | +acosh z@(r<:t) = ln (z+sqrt (z*z-1)); +atanh z@(x+:y) | +atanh z@(r<:t) = inf +: 0.0 if z==1; + = -inf +: 0.0 if z==-1; + = ln ((1+z)/(1-z))/2; + +// These inverse hyperbolic trigs have complex results for some reals. +acosh x::double = acosh (x+:0); +atanh x::double = atanh (x+:0); + +/* Complex arithmetic. */ + +-(x+:y) = -x +: -y; +-(r<:t) = r <: t+pi; + +(x1+:y1) + (x2+:y2) = x1+y2 +: y1+y2; +z1@(r1<:t1)+z2@(r2<:t2) = polar $ rect z1 + rect z2; + +(x1+:y1) - (x2+:y2) = x1-y2 +: y1-y2; +z1@(r1<:t1)-z2@(r2<:t2) = polar $ rect z1 - rect z2; + +(x1+:y1) * (x2+:y2) = x1*x2-y1*y2 +: x1*y2+y1*x2; +(r1<:t1) * (r2<:t2) = r1*r2 <: t1+t2; + +(x1+:y1) / (x2+:y2) = (x1*x2+y1*y2 +: y1*x2-x1*y2) / (x2*x2+y2*y2); +(r1<:t1) / (r2<:t2) = r1/r2 <: t1-t2; + +z1@(x1+:y1)^z2@(x2+:y2) = exp (ln z1*z2) if z1!=0; + = 0.0+:0.0 if z2!=0; + = 1.0+:0.0 otherwise; +z1@(r1<:t1)^z2@(r2<:t2) = exp (ln z1*z2) if z1!=0; + = 0.0<:0.0 if z2!=0; + = 1.0<:0.0 otherwise; + +// Complex powers of negative reals. +x1::double^x2::double = exp (ln x1*x2) if x1<0; + +/* Mixed rect/polar and polar/rect forms always return a rect result. */ + +z1@(x1+:y1)+z2@(r2<:t2) = z1 + rect z2; +z1@(r1<:t1)+z2@(x2+:y2) = rect z1 + z2; + +z1@(x1+:y1)-z2@(r2<:t2) = z1 - rect z2; +z1@(r1<:t1)-z2@(x2+:y2) = rect z1 - z2; + +z1@(x1+:y1)*z2@(r2<:t2) = z1 * rect z2; +z1@(r1<:t1)*z2@(x2+:y2) = rect z1 * z2; + +z1@(x1+:y1)/z2@(r2<:t2) = z1 / rect z2; +z1@(r1<:t1)/z2@(x2+:y2) = rect z1 / z2; + +z1@(x1+:y1)^z2@(r2<:t2) = z1 ^ rect z2; +z1@(r1<:t1)^z2@(x2+:y2) = rect z1 ^ z2; + +/* Mixed complex/real and real/complex forms yield a rect or polar result, + depending on what the complex input was. */ + +(x1+:y1)+x2 = x1+x2 +: y1; +x1+(x2+:y2) = x1+x2 +: y2; +z1@(r1<:t1)+x2 = rect z1 + x2; +x1+z2@(r2<:t2) = x1 + rect z2; + +(x1+:y1)-x2 = x1-x2 +: y1; +x1-(x2+:y2) = x1-x2 +: -y2; +z1@(r1<:t1)-x2 = rect z1 - x2; +x1-z2@(r2<:t2) = x1 - rect z2; + +(x1+:y1)*x2 = x1*x2 +: y1*x2; +x1*(x2+:y2) = x1*x2 +: x1*y2; +(r1<:t1)*x2 = r1*x2 <: t1; +x1*(r2<:t2) = x1*r2 <: t2; + +(x1+:y1)/x2 = x1/x2 +: y1/x2; +x1/z2@(x2+:y2) = (x1*x2 +: -x1*y2) / (x2*x2+y2*y2); +(r1<:t1)/x2 = r1/x2 <: t1; +x1/(r2<:t2) = x1/r2 <: -t2; + +z1@(x1+:y1)^x2 = z1 ^ (x2+:0); +x1^z2@(x2+:y2) = (x1+:0) ^ z2; +(r1<:t1)^x2 = r1^x2 <: t1*x2; +x1^z2@(r2<:t2) = (x1<:0) ^ z2; + +/* Equality. */ + +(x1+:y1) == (x2+:y2) = x1==y2 && y1==y2; +(r1<:t1) == (r2<:t2) = r1==r2 && t1==t2; + +(x1+:y1) != (x2+:y2) = x1!=y2 || y1!=y2; +(r1<:t1) != (r2<:t2) = r1!=r2 || t1!=t2; + +z1@(_+:_)==z2@(_<:_) = z1 == rect z2; +z1@(_<:_)==z2@(_+:_) = rect z1 == z2; + +z1@(_+:_)!=z2@(_<:_) = z1 != rect z2; +z1@(_<:_)!=z2@(_+:_) = rect z1 != z2; + +(x1+:y1)==x2 = x1==x2 && y1==0; +x1==(x2+:y2) = x1==x2 && y2==0; +z1@(r1<:t1)==x2 = z1 == (x2<:0); +x1==z2@(r2<:t2) = (x1<:0) == z2; + +(x1+:y1)!=x2 = x1!=x2 || y1!=0; +x1!=(x2+:y2) = x1!=x2 || y2!=0; +z1@(r1<:t1)!=x2 = z1 != (x2<:0); +x1!=z2@(r2<:t2) = (x1<:0) != z2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |