2024-04-10 20:21:15 -04:00
|
|
|
<> (-- ?x) ()
|
2024-04-13 23:55:31 -04:00
|
|
|
-- ( little endian binary natural numbers and integers )
|
2024-04-10 20:21:15 -04:00
|
|
|
|
|
|
|
-- ( constants )
|
2024-04-12 12:53:40 -04:00
|
|
|
<> zero ((0 ()))
|
|
|
|
<> one ((1 ()))
|
2024-04-13 23:55:31 -04:00
|
|
|
<> two ((0 (1 ())))
|
|
|
|
<> eight ((0 (0 (0 (1 ())))))
|
2024-04-12 12:53:40 -04:00
|
|
|
<> ten ((0 (1 (0 (1 ())))))
|
2024-04-13 23:55:31 -04:00
|
|
|
<> sixteen ((0 (0 (0 (0 (1 ()))))))
|
2024-04-12 12:53:40 -04:00
|
|
|
|
|
|
|
-- reverse ()-terminated list
|
2024-04-12 13:41:39 -04:00
|
|
|
<> (reverse ?x) (reverse1 () ?x)
|
|
|
|
<> (reverse1 ?a ()) (?a)
|
|
|
|
<> (reverse1 ?a (?h ?t)) (reverse1 (?h ?a) ?t)
|
2024-04-10 20:21:15 -04:00
|
|
|
|
2024-04-13 23:55:31 -04:00
|
|
|
-- ( to natural number )
|
|
|
|
<> ((nat ?*)) ((nat1 (?*)))
|
|
|
|
<> ((nat1 ?x)) ((sum f (N one) g reverse ?x))
|
2024-04-12 12:53:40 -04:00
|
|
|
<> (g ()) (())
|
2024-04-12 14:20:35 -04:00
|
|
|
<> (g (?h ?t)) (((binary ?h) g ?t))
|
2024-04-13 00:17:13 -04:00
|
|
|
<> (f (N ?u) ()) (())
|
|
|
|
<> (f (N ?u) (?h ?t)) (((mul (N ?h) (N ?u)) f (mul (N ?u) (N ten)) ?t))
|
2024-04-10 20:21:15 -04:00
|
|
|
|
2024-04-13 23:55:31 -04:00
|
|
|
-- ( to integer )
|
|
|
|
<> ((nat-base (N ?b) ?*)) ((sum f' (N ?b) (N one) g' reverse (?*)))
|
|
|
|
<> (g' ()) (())
|
|
|
|
<> (g' (?h ?t)) (((binary ?h) g' ?t))
|
|
|
|
<> (f' (N ?b) (N ?u) ()) (())
|
|
|
|
<> (f' (N ?b) (N ?u) (?h ?t)) (((mul (N ?h) (N ?u)) f' (N ?b) (mul (N ?u) (N ?b)) ?t))
|
|
|
|
|
2024-04-11 19:03:25 -04:00
|
|
|
-- ( to binary str )
|
2024-04-12 14:20:35 -04:00
|
|
|
-- ( <> ((bstr ?x)) (emit force (0 (b ?x))) )
|
|
|
|
-- ( <> ((bstr ?x)) ((bstr1 () ?x)) )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((bstr (N ?x))) ((bstr1 force ?x ()))
|
2024-04-12 14:20:35 -04:00
|
|
|
<> ((bstr1 force/r () ?a)) (emit force/r (0 (b ?a)))
|
|
|
|
<> ((bstr1 force/r (?h ?t) ?a)) ((bstr1 force/r ?t (?h ?a)))
|
2024-04-11 19:03:25 -04:00
|
|
|
|
2024-04-13 23:55:31 -04:00
|
|
|
-- ( render as a list of characters )
|
|
|
|
<> ((tostr (N ?x))) ((tostr1 (N ?x) ()))
|
|
|
|
<> ((tostr1 (N (0 ())) ?a)) (?a)
|
|
|
|
<> ((tostr1 (N (?h ?t)) ?a)) ((tostr2 (divmod (N (?h ?t)) (N ten)) ?a))
|
|
|
|
<> ((tostr2 ((N ?q) (N ?r)) ?a)) ((tostr1 (N ?q) ((decimal ?r) ?a)))
|
|
|
|
|
|
|
|
-- ( to string )
|
|
|
|
<> ((str (Z (+ ?x)))) ((str (N ?x)))
|
|
|
|
<> ((str (Z (- ?x)))) (emit force (- (tostr (N ?x))))
|
|
|
|
<> ((str (N ?x))) (emit force (tostr (N ?x)))
|
2024-04-12 12:53:40 -04:00
|
|
|
|
|
|
|
-- ( force a list to evaluate to digits/letters )
|
|
|
|
<> ((?h force/r ?t)) (force/r (?h ?t))
|
|
|
|
<> (force ()) (force/r ())
|
2024-04-13 23:55:31 -04:00
|
|
|
<> (force (- ?t)) ((- force ?t))
|
2024-04-12 12:53:40 -04:00
|
|
|
<> (force (0 ?t)) ((0 force ?t))
|
|
|
|
<> (force (1 ?t)) ((1 force ?t))
|
|
|
|
<> (force (2 ?t)) ((2 force ?t))
|
|
|
|
<> (force (3 ?t)) ((3 force ?t))
|
|
|
|
<> (force (4 ?t)) ((4 force ?t))
|
|
|
|
<> (force (5 ?t)) ((5 force ?t))
|
|
|
|
<> (force (6 ?t)) ((6 force ?t))
|
|
|
|
<> (force (7 ?t)) ((7 force ?t))
|
|
|
|
<> (force (8 ?t)) ((8 force ?t))
|
|
|
|
<> (force (9 ?t)) ((9 force ?t))
|
|
|
|
<> (force (a ?t)) ((a force ?t))
|
|
|
|
<> (force (b ?t)) ((b force ?t))
|
|
|
|
<> (force (c ?t)) ((c force ?t))
|
|
|
|
<> (force (d ?t)) ((d force ?t))
|
|
|
|
<> (force (e ?t)) ((e force ?t))
|
|
|
|
<> (force (f ?t)) ((f force ?t))
|
|
|
|
<> (force (x ?t)) ((x force ?t))
|
|
|
|
|
|
|
|
-- ( emit )
|
|
|
|
<> (emit force/r ?*) (?*)
|
2024-04-11 18:38:49 -04:00
|
|
|
|
2024-04-10 20:21:15 -04:00
|
|
|
-- ( comparison operartions )
|
2024-04-13 23:55:31 -04:00
|
|
|
<> ((cmp (N ?x) (N ?y))) ((cmpc #eq ?x ?y))
|
2024-04-12 12:53:40 -04:00
|
|
|
<> ((cmpc ?e () ())) (?e)
|
|
|
|
<> ((cmpc ?e (1 ?x) ())) (#gt)
|
|
|
|
<> ((cmpc ?e (0 ?x) ())) ((cmpc ?e ?x ()))
|
|
|
|
<> ((cmpc ?e () (1 ?y))) (#lt)
|
|
|
|
<> ((cmpc ?e () (0 ?y))) ((cmpc ?e () ?y))
|
2024-04-10 22:14:47 -04:00
|
|
|
<> ((cmpc ?e (0 ?x) (0 ?y))) ((cmpc ?e ?x ?y))
|
|
|
|
<> ((cmpc ?e (1 ?x) (0 ?y))) ((cmpc #gt ?x ?y))
|
|
|
|
<> ((cmpc ?e (0 ?x) (1 ?y))) ((cmpc #lt ?x ?y))
|
|
|
|
<> ((cmpc ?e (1 ?x) (1 ?y))) ((cmpc ?e ?x ?y))
|
2024-04-10 20:21:15 -04:00
|
|
|
|
|
|
|
-- ( addition )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((add (N ?x) (N ?y))) (add/e force (addc 0 ?x ?y))
|
2024-04-12 14:20:35 -04:00
|
|
|
<> ((addc 0 () ())) (())
|
|
|
|
<> ((addc 1 () ())) ((1 ()))
|
|
|
|
<> ((addc 0 ?x ())) (?x)
|
|
|
|
<> ((addc 0 () ?y)) (?y)
|
|
|
|
<> ((addc 1 ?x ())) ((addc 1 ?x (0 ())))
|
|
|
|
<> ((addc 1 () ?y)) ((addc 1 (0 ()) ?y))
|
|
|
|
<> ((addc 0 (0 ?x) (0 ?y))) ((0 (addc 0 ?x ?y)))
|
|
|
|
<> ((addc 0 (0 ?x) (1 ?y))) ((1 (addc 0 ?x ?y)))
|
|
|
|
<> ((addc 0 (1 ?x) (0 ?y))) ((1 (addc 0 ?x ?y)))
|
|
|
|
<> ((addc 0 (1 ?x) (1 ?y))) ((0 (addc 1 ?x ?y)))
|
|
|
|
<> ((addc 1 (0 ?x) (0 ?y))) ((1 (addc 0 ?x ?y)))
|
|
|
|
<> ((addc 1 (0 ?x) (1 ?y))) ((0 (addc 1 ?x ?y)))
|
|
|
|
<> ((addc 1 (1 ?x) (0 ?y))) ((0 (addc 1 ?x ?y)))
|
|
|
|
<> ((addc 1 (1 ?x) (1 ?y))) ((1 (addc 1 ?x ?y)))
|
2024-04-13 00:17:13 -04:00
|
|
|
<> (add/e force/r ?x) ((N ?x))
|
2024-04-10 20:21:15 -04:00
|
|
|
|
|
|
|
-- ( summation )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((sum ())) ((N (0 ())))
|
2024-04-12 12:53:40 -04:00
|
|
|
<> ((sum (?a ()))) (?a)
|
2024-04-10 22:14:47 -04:00
|
|
|
<> ((sum (?a (?b ?c)))) ((sum ((add ?a ?b) ?c)))
|
2024-04-10 20:21:15 -04:00
|
|
|
|
|
|
|
-- ( multiplication )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((mul (N ?x) (N ?y))) (mul/e (mulc () ?x ?y))
|
2024-04-12 14:20:35 -04:00
|
|
|
<> ((mulc ?t () ?y)) ((sum ?t))
|
|
|
|
<> ((mulc ?t (0 ?x) ?y)) ((mulc ?t ?x (0 ?y)))
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((mulc ?t (1 ?x) ?y)) ((mulc ((N ?y) ?t) ?x (0 ?y)))
|
|
|
|
<> (mul/e (N ?x)) ((N ?x))
|
2024-04-10 20:21:15 -04:00
|
|
|
|
|
|
|
-- ( subtraction )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((sub (N ?x) (N ?y))) (sub/e force (sub1 0 ?x ?y ()))
|
|
|
|
<> ((sub1 0 () () ?s)) (())
|
|
|
|
<> ((sub1 1 () () ?s)) (#err)
|
|
|
|
<> ((sub1 ?c ?x () ?s)) ((sub1 ?c ?x (0 ()) ?s))
|
|
|
|
<> ((sub1 ?c () ?y ?s)) ((sub1 ?c (0 ()) ?y ?s))
|
|
|
|
<> ((sub1 0 (0 ?x) (0 ?y) ?s)) ((sub1 0 ?x ?y (0 ?s)))
|
|
|
|
<> ((sub1 0 (0 ?x) (1 ?y) ?s)) ((sub2 1 ?x ?y ?s))
|
|
|
|
<> ((sub1 0 (1 ?x) (0 ?y) ?s)) ((sub2 0 ?x ?y ?s))
|
|
|
|
<> ((sub1 0 (1 ?x) (1 ?y) ?s)) ((sub1 0 ?x ?y (0 ?s)))
|
|
|
|
<> ((sub1 1 (0 ?x) (0 ?y) ?s)) ((sub2 1 ?x ?y ?s))
|
|
|
|
<> ((sub1 1 (0 ?x) (1 ?y) ?s)) ((sub1 1 ?x ?y (0 ?s)))
|
|
|
|
<> ((sub1 1 (1 ?x) (0 ?y) ?s)) ((sub1 0 ?x ?y (0 ?s)))
|
|
|
|
<> ((sub1 1 (1 ?x) (1 ?y) ?s)) ((sub2 1 ?x ?y ?s))
|
|
|
|
<> ((sub2 ?c ?x ?y ())) ((1 (sub1 ?c ?x ?y ())))
|
|
|
|
<> ((sub2 ?c ?x ?y (?h ?t))) ((0 (sub2 ?c ?x ?y ?t)))
|
|
|
|
<> (sub/e force/r ?x) ((N ?x))
|
|
|
|
|
|
|
|
<> ((dec (N (0 ())))) (#err)
|
|
|
|
<> ((dec (N (1 ())))) ((N (0 ())))
|
|
|
|
<> ((dec (N (1 ?t)))) ((N (0 ?t)))
|
|
|
|
<> ((dec (N (0 ?t)))) (dec/e (dec1 (0 ?t)))
|
|
|
|
|
|
|
|
<> ((dec1 (0 ?t))) ((1 (dec1 ?t)))
|
|
|
|
<> ((dec1 (1 ()))) (dec/r ())
|
|
|
|
<> ((dec1 (1 ?t))) (dec/r (0 ?t))
|
|
|
|
<> ((?h dec/r ?t)) (dec/r (?h ?t))
|
|
|
|
<> (dec/e dec/r ?x) ((N ?x))
|
2024-04-10 20:21:15 -04:00
|
|
|
|
2024-04-10 22:14:47 -04:00
|
|
|
-- ( inc )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((inc (N ?x))) (inc/e force (inc1 ?x))
|
|
|
|
<> ((inc1 ())) ((1 ()))
|
|
|
|
<> ((inc1 (0 ?t))) ((1 ?t))
|
|
|
|
<> ((inc1 (1 ?t))) ((0 (inc1 ?t)))
|
|
|
|
<> (inc/e force/r ?x) ((N ?x))
|
2024-04-10 20:21:15 -04:00
|
|
|
|
2024-04-10 22:14:47 -04:00
|
|
|
-- ( left shift; lshift x b means x<<b )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((lshift (N ?x) (N ?k))) (lshift/e force/r (lshift1 ?x (N ?k)))
|
|
|
|
<> ((lshift1 ?x (N (0 ())))) (?x)
|
|
|
|
<> ((lshift1 ?x (N (1 ())))) ((0 ?x))
|
|
|
|
<> ((lshift1 ?x (N (0 (?a ?b))))) ((lshift1 (0 ?x) (dec (N (0 (?a ?b))))))
|
|
|
|
<> ((lshift1 ?x (N (1 (?a ?b))))) ((lshift1 (0 ?x) (N (0 (?a ?b)))))
|
|
|
|
<> (lshift/e force/r ?x) ((N ?x))
|
2024-04-12 12:53:40 -04:00
|
|
|
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((rshift1 (N (?a ())))) ((N (0 ())))
|
|
|
|
<> ((rshift1 (N (?a (?b ?c))))) ((N (?b ?c)))
|
2024-04-10 22:14:47 -04:00
|
|
|
|
|
|
|
-- ( divmod, i.e. quotient and remainder )
|
2024-04-12 12:53:40 -04:00
|
|
|
-- ( x is the dividend, or what's left of it )
|
|
|
|
-- ( y is the divisor )
|
|
|
|
-- ( s is the number of bits to shift, so far )
|
|
|
|
-- ( o is the next valuet o add to the quotient )
|
|
|
|
-- ( m is the next multiple of y to work with )
|
|
|
|
-- ( d is the quotient, so far )
|
2024-04-13 23:55:31 -04:00
|
|
|
<> ((divmod (N ?x) (N ?y))) (divmod/p (divmod1 ?x ?y (cmp (N ?x) (N ?y))))
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((divmod1 ?x ?y #lt)) (((N zero) (N ?x)))
|
|
|
|
<> ((divmod1 ?x ?y #eq)) (((N one) (N zero)))
|
|
|
|
<> ((divmod1 ?x ?y #gt)) ((divmod2 (N ?x) (N ?y) (N zero) (N ?y)))
|
2024-04-12 12:53:40 -04:00
|
|
|
|
2024-04-13 23:55:31 -04:00
|
|
|
<> ((divmod2 (N ?x) (N ?y) (N ?s) (N ?m))) ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) (cmp (N ?x) (N (0 ?m)))))
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) #gt)) ((divmod2 (N ?x) (N ?y) (inc (N ?s)) (N (0 ?m))))
|
|
|
|
<> ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) #eq)) ((divmod4 (N ?x) (N ?y) (inc (N ?s)) (N (0 ?m)) (N zero)))
|
|
|
|
<> ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) #lt)) ((divmod4 (N ?x) (N ?y) (N ?s) (N ?m) (N zero)))
|
2024-04-12 12:53:40 -04:00
|
|
|
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((divmod4 (N ?x) (N ?y) (N (0 ())) (N ?m) (N ?d))) (((add (N ?d) (N one)) (sub (N ?x) (N ?y))))
|
|
|
|
<> ((divmod4 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d))) ((divmod5 (sub (N ?x) (N ?m)) (N ?y) (dec (N ?s)) (rshift1 (N ?m)) (add (N ?d) (lshift (N one) (N ?s)))))
|
2024-04-12 12:53:40 -04:00
|
|
|
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((divmod5 (N (0 ())) (N ?y) (N ?s) (N ?m) (N ?d))) (((N ?d) (N (0 ()))))
|
2024-04-13 23:55:31 -04:00
|
|
|
<> ((divmod5 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d))) ((divmod6 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d) (cmp (N ?x) (N ?m))))
|
2024-04-12 12:53:40 -04:00
|
|
|
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((divmod6 (N ?x) (N ?y) (N (0 ())) (N ?m) (N ?d) #lt)) (((N ?d) (N ?x)))
|
|
|
|
<> ((divmod6 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d) #lt)) ((divmod5 (N ?x) (N ?y) (dec (N ?s)) (rshift1 (N ?m)) (N ?d)))
|
|
|
|
<> ((divmod6 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d) #eq)) ((divmod4 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d)))
|
|
|
|
<> ((divmod6 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d) #gt)) ((divmod4 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d)))
|
|
|
|
|
|
|
|
<> (divmod/p ((N ?q) (N ?r))) (divmod/e (force ?q force ?r))
|
|
|
|
<> (divmod/e (force/r ?q force/r ?r)) (((N ?q) (N ?r)))
|
2024-04-10 22:14:47 -04:00
|
|
|
|
|
|
|
-- ( floor divison )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((div (N ?x) (N ?y))) ((div1 (divmod (N ?x) (N ?y))))
|
2024-04-12 13:41:39 -04:00
|
|
|
<> ((div1 (?q ?r))) (?q)
|
2024-04-10 22:14:47 -04:00
|
|
|
|
|
|
|
-- ( remainder )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((mod (N ?x) (N ?y))) ((mod1 (divmod (N ?x) (N ?y))))
|
2024-04-12 13:41:39 -04:00
|
|
|
<> ((mod1 (?q ?r))) (?r)
|
2024-04-10 22:14:47 -04:00
|
|
|
|
2024-04-12 16:08:51 -04:00
|
|
|
-- ( expontentiation )
|
2024-04-13 00:17:13 -04:00
|
|
|
<> ((pow (N ?x) ())) ((N (1 ())))
|
|
|
|
<> ((pow (N ?x) (N (0 ())))) ((N (1 ())))
|
|
|
|
<> ((pow (N ?x) (N (1 ())))) ((N ?x))
|
|
|
|
<> ((pow (N ?x) (N (0 ?k)))) ((pow (mul (N ?x) (N ?x)) (N ?k)))
|
|
|
|
<> ((pow (N ?x) (N (1 ?k)))) ((mul (N ?x) (pow (mul (N ?x) (N ?x)) (N ?k))))
|
2024-04-12 16:08:51 -04:00
|
|
|
|
2024-04-12 18:24:54 -04:00
|
|
|
-- ( greatest common denominator )
|
2024-04-13 23:55:31 -04:00
|
|
|
<> ((gcd ?a ?b)) ((gcd1 ?a ?b (cmp ?b (N (0 ())))))
|
2024-04-12 18:24:54 -04:00
|
|
|
<> ((gcd1 ?a ?b #eq)) (?a)
|
|
|
|
<> ((gcd1 ?a ?b #gt)) ((gcd ?b (mod ?a ?b)))
|
|
|
|
<> ((gcd1 ?a ?b #lt)) ((gcd ?b (mod ?a ?b)))
|
|
|
|
|
|
|
|
-- ( least common multiple )
|
|
|
|
<> ((lcm ?a ?b)) ((mul ?a (div ?b (gcd ?a ?b))))
|
|
|
|
|
2024-04-13 23:55:31 -04:00
|
|
|
-- ( decimal digit to binary )
|
|
|
|
<> ((binary 0)) ((0 ()))
|
|
|
|
<> ((binary 1)) ((1 ()))
|
|
|
|
<> ((binary 2)) ((0 (1 ())))
|
|
|
|
<> ((binary 3)) ((1 (1 ())))
|
|
|
|
<> ((binary 4)) ((0 (0 (1 ()))))
|
|
|
|
<> ((binary 5)) ((1 (0 (1 ()))))
|
|
|
|
<> ((binary 6)) ((0 (1 (1 ()))))
|
|
|
|
<> ((binary 7)) ((1 (1 (1 ()))))
|
|
|
|
<> ((binary 8)) ((0 (0 (0 (1 ())))))
|
|
|
|
<> ((binary 9)) ((1 (0 (0 (1 ())))))
|
|
|
|
<> ((binary a)) ((0 (1 (0 (1 ())))))
|
|
|
|
<> ((binary b)) ((1 (1 (0 (1 ())))))
|
|
|
|
<> ((binary c)) ((0 (0 (1 (1 ())))))
|
|
|
|
<> ((binary d)) ((1 (0 (1 (1 ())))))
|
|
|
|
<> ((binary e)) ((0 (1 (1 (1 ())))))
|
|
|
|
<> ((binary f)) ((1 (1 (1 (1 ())))))
|
|
|
|
<> ((binary g)) ((0 (0 (0 (0 (1 ()))))))
|
|
|
|
<> ((binary h)) ((1 (0 (0 (0 (1 ()))))))
|
|
|
|
<> ((binary i)) ((0 (1 (0 (0 (1 ()))))))
|
|
|
|
<> ((binary j)) ((1 (1 (0 (0 (1 ()))))))
|
|
|
|
<> ((binary k)) ((0 (0 (1 (0 (1 ()))))))
|
|
|
|
<> ((binary l)) ((1 (0 (1 (0 (1 ()))))))
|
|
|
|
<> ((binary m)) ((0 (1 (1 (0 (1 ()))))))
|
|
|
|
<> ((binary n)) ((1 (1 (1 (0 (1 ()))))))
|
|
|
|
<> ((binary o)) ((0 (0 (0 (1 (1 ()))))))
|
|
|
|
<> ((binary p)) ((1 (0 (0 (1 (1 ()))))))
|
|
|
|
<> ((binary q)) ((0 (1 (0 (1 (1 ()))))))
|
|
|
|
<> ((binary r)) ((1 (1 (0 (1 (1 ()))))))
|
|
|
|
<> ((binary s)) ((0 (0 (1 (1 (1 ()))))))
|
|
|
|
<> ((binary t)) ((1 (0 (1 (1 (1 ()))))))
|
|
|
|
<> ((binary u)) ((0 (1 (1 (1 (1 ()))))))
|
|
|
|
<> ((binary v)) ((1 (1 (1 (1 (1 ()))))))
|
|
|
|
<> ((binary w)) ((0 (0 (0 (0 (0 (1 ())))))))
|
|
|
|
<> ((binary x)) ((1 (0 (0 (0 (0 (1 ())))))))
|
|
|
|
<> ((binary y)) ((0 (1 (0 (0 (0 (1 ())))))))
|
|
|
|
<> ((binary z)) ((1 (1 (0 (0 (0 (1 ())))))))
|
|
|
|
|
|
|
|
-- ( binary to digits )
|
|
|
|
<> ((decimal ())) (0)
|
|
|
|
<> ((decimal (0 ()))) (0)
|
|
|
|
<> ((decimal (1 ()))) (1)
|
|
|
|
<> ((decimal (0 (1 ())))) (2)
|
|
|
|
<> ((decimal (1 (1 ())))) (3)
|
|
|
|
<> ((decimal (0 (0 (1 ()))))) (4)
|
|
|
|
<> ((decimal (1 (0 (1 ()))))) (5)
|
|
|
|
<> ((decimal (0 (1 (1 ()))))) (6)
|
|
|
|
<> ((decimal (1 (1 (1 ()))))) (7)
|
|
|
|
<> ((decimal (0 (0 (0 (1 ())))))) (8)
|
|
|
|
<> ((decimal (1 (0 (0 (1 ())))))) (9)
|
|
|
|
|
|
|
|
<> ((nat>int + (N ?x))) ((Z (+ ?x)))
|
|
|
|
<> ((nat>int - (N ?x))) ((Z (- ?x)))
|
|
|
|
<> ((nat>pos (N ?x))) ((Z (+ ?x)))
|
|
|
|
<> ((nat>neg (N ?x))) ((Z (- ?x)))
|
|
|
|
|
|
|
|
<> ((negate (Z (+ ?x)))) ((Z (- ?x)))
|
|
|
|
<> ((negate (Z (+ ?x)))) ((Z (- ?x)))
|
|
|
|
|
|
|
|
<> ((cmp (Z (?s (0 ()))) (Z (?s (0 ()))))) (#eq)
|
|
|
|
<> ((cmp (Z (+ ?x)) (Z (+ ?y)))) ((cmp (N ?x) (N ?y)))
|
|
|
|
<> ((cmp (Z (+ ?x)) (Z (- ?y)))) (#gt)
|
|
|
|
<> ((cmp (Z (- ?x)) (Z (- ?y)))) ((cmp (N ?y) (N ?x)))
|
|
|
|
<> ((cmp (Z (- ?x)) (Z (?s ?y)))) (#lt)
|
|
|
|
|
|
|
|
<> ((add (Z (+ ?x)) (Z (+ ?y)))) ((nat>pos (add (N ?x) (N ?y))))
|
|
|
|
<> ((add (Z (- ?x)) (Z (- ?y)))) ((nat>neg (add (N ?x) (N ?y))))
|
|
|
|
<> ((add (Z (+ ?x)) (Z (- ?y)))) ((zadd ?x ?y (cmp (N ?x) (N ?y))))
|
|
|
|
<> ((add (Z (- ?x)) (Z (+ ?y)))) ((zadd ?y ?x (cmp (N ?y) (N ?x))))
|
|
|
|
<> ((zadd ?p ?n #gt)) ((nat>pos (sub (N ?p) (N ?n))))
|
|
|
|
<> ((zadd ?p ?n #eq)) ((Z (+ (0 ()))))
|
|
|
|
<> ((zadd ?p ?n #lt)) ((nat>neg (sub (N ?n) (N ?p))))
|
|
|
|
|
|
|
|
<> ((mul (Z (?s ?x)) (Z (?s ?y)))) ((nat>pos (mul (N ?x) (N ?y))))
|
|
|
|
<> ((mul (Z (?s ?x)) (Z (?t ?y)))) ((nat>neg (mul (N ?x) (N ?y))))
|
|
|
|
|
|
|
|
<> ((sub (Z (+ ?x)) (Z (+ ?y)))) ((add (Z (+ ?x)) (Z (- ?y))))
|
|
|
|
<> ((sub (Z (+ ?x)) (Z (- ?y)))) ((add (Z (+ ?x)) (Z (+ ?y))))
|
|
|
|
<> ((sub (Z (- ?x)) (Z (+ ?y)))) ((add (Z (- ?x)) (Z (- ?y))))
|
|
|
|
<> ((sub (Z (- ?x)) (Z (- ?y)))) ((add (Z (- ?x)) (Z (+ ?y))))
|
|
|
|
|
|
|
|
-- ( n/d = q, n%d = r )
|
|
|
|
-- ( n = d * q + r )
|
|
|
|
-- ( ---------------- )
|
|
|
|
-- ( 9 = 2 * 4 + 1 )
|
|
|
|
-- ( -9 = 2 * -4 - 1 )
|
|
|
|
-- ( 9 = -2 * -4 + 1 )
|
|
|
|
-- ( -9 = -2 * 4 - 1 )
|
|
|
|
<> ((divmod (Z (+ ?x)) (Z (+ ?y)))) ((zdm + + (divmod (N ?x) (N ?y))))
|
|
|
|
<> ((divmod (Z (- ?x)) (Z (+ ?y)))) ((zdm - - (divmod (N ?x) (N ?y))))
|
|
|
|
<> ((divmod (Z (+ ?x)) (Z (- ?y)))) ((zdm - + (divmod (N ?x) (N ?y))))
|
|
|
|
<> ((divmod (Z (- ?x)) (Z (- ?y)))) ((zdm + - (divmod (N ?x) (N ?y))))
|
|
|
|
<> ((zdm ?s ?t ((N ?q) (N ?r)))) (((Z (?s ?q)) (Z (?t ?r))))
|
|
|
|
|
|
|
|
<> ((div (Z (?s ?x)) (Z (?s ?y)))) ((nat>pos (div (N ?x) (N ?y))))
|
|
|
|
<> ((div (Z (?s ?x)) (Z (?t ?y)))) ((nat>neg (div (N ?x) (N ?y))))
|
|
|
|
|
|
|
|
<> ((mod (Z (+ ?x)) (Z (?s ?y)))) ((nat>pos (div (N ?x) (N ?y))))
|
|
|
|
<> ((mod (Z (- ?x)) (Z (?s ?y)))) ((nat>neg (div (N ?x) (N ?y))))
|
|
|
|
|
|
|
|
<> ((pow (Z (+ ?x)) (N ?k))) ((nat>pos (pow (N ?x) (N ?k))))
|
|
|
|
<> ((pow (Z (- ?x)) (N (0 ?k)))) ((nat>pos (pow (N ?x) (N (0 ?k)))))
|
|
|
|
<> ((pow (Z (- ?x)) (N (1 ?k)))) ((nat>neg (pow (N ?x) (N (1 ?k)))))
|
|
|
|
|
|
|
|
-- ( to natural number )
|
|
|
|
<> ((int ?*)) ((int1 (?*)))
|
|
|
|
<> ((int1 (- ?t))) ((int2 - (nat1 ?t)))
|
|
|
|
<> ((int1 (?h ?t))) ((int2 + (nat1 (?h ?t))))
|
|
|
|
<> ((int2 ?s (N ?x))) ((Z (?s ?x)))
|
|
|
|
|
2024-04-13 23:57:52 -04:00
|
|
|
(str (mul (int -133) (int 77)))
|