division seems to work

This commit is contained in:
~d6 2024-04-10 22:14:47 -04:00
parent bb92632896
commit 536992d039
1 changed files with 52 additions and 35 deletions

View File

@ -51,28 +51,28 @@
<> (normalize' (0 ?s) (1 ?t)) ((0 normalize' ?s (1 ?t))) <> (normalize' (0 ?s) (1 ?t)) ((0 normalize' ?s (1 ?t)))
-- ( to integer ) -- ( to integer )
<> ((int ?*)) (sum f (one) g reverse nilify (?*)) <> ((int ?*)) ((sum f (one) g reverse nilify (?*)))
<> (g nil) (nil) <> (g nil) (nil)
<> (g (?h ?t)) ((binary ?h g ?t)) <> (g (?h ?t)) ((binary ?h g ?t))
<> (f (?u) nil) (nil) <> (f (?u) nil) (nil)
<> (f (?u) (?h ?t)) ((mul ?h ?u f (mul ?u ten) ?t)) <> (f (?u) (?h ?t)) (((mul ?h ?u) f ((mul ?u ten)) ?t))
-- ( to string: TODO, need division for this one ) -- ( to string: TODO, need division for this one )
-- ( comparison operartions ) -- ( comparison operartions )
<> (cmp ?x ?y) (cmpc eq ?x ?y) <> ((cmp ?x ?y)) ((cmpc #eq ?x ?y))
<> (cmpc ?e nil nil) (?e) <> ((cmpc ?e nil nil)) (?e)
<> (cmpc ?e (1 ?x) nil) (gt) <> ((cmpc ?e (1 ?x) nil)) (#gt)
<> (cmpc ?e (0 ?x) nil) (cmpc ?e ?x nil) <> ((cmpc ?e (0 ?x) nil)) ((cmpc ?e ?x nil))
<> (cmpc ?e nil (1 ?y)) (lt) <> ((cmpc ?e nil (1 ?y))) (#lt)
<> (cmpc ?e nil (0 ?y)) (cmpc ?e nil ?y) <> ((cmpc ?e nil (0 ?y))) ((cmpc ?e nil ?y))
<> (cmpc ?e (0 ?x) (0 ?y)) (cmpc ?e ?x ?y) <> ((cmpc ?e (0 ?x) (0 ?y))) ((cmpc ?e ?x ?y))
<> (cmpc ?e (1 ?x) (0 ?y)) (cmpc gt ?x ?y) <> ((cmpc ?e (1 ?x) (0 ?y))) ((cmpc #gt ?x ?y))
<> (cmpc ?e (0 ?x) (1 ?y)) (cmpc lt ?x ?y) <> ((cmpc ?e (0 ?x) (1 ?y))) ((cmpc #lt ?x ?y))
<> (cmpc ?e (1 ?x) (1 ?y)) (cmpc ?e ?x ?y) <> ((cmpc ?e (1 ?x) (1 ?y))) ((cmpc ?e ?x ?y))
-- ( addition ) -- ( addition )
<> (add ?x ?y) (addc 0 ?x ?y) <> ((add ?x ?y)) (addc 0 ?x ?y)
<> (addc 0 nil nil) (nil) <> (addc 0 nil nil) (nil)
<> (addc 1 nil nil) ((1 nil)) <> (addc 1 nil nil) ((1 nil))
<> (addc ?c ?x nil) (addc ?c ?x (0 nil)) <> (addc ?c ?x nil) (addc ?c ?x (0 nil))
@ -87,18 +87,18 @@
<> (addc 1 (1 ?x) (1 ?y)) ((1 addc 1 ?x ?y)) <> (addc 1 (1 ?x) (1 ?y)) ((1 addc 1 ?x ?y))
-- ( summation ) -- ( summation )
<> (sum nil) ((0 nil)) <> ((sum nil)) ((0 nil))
<> (sum (?a nil)) (?a) <> ((sum (?a nil))) (?a)
<> (sum (?a (?b ?c))) (sum (add ?a ?b ?c)) <> ((sum (?a (?b ?c)))) ((sum ((add ?a ?b) ?c)))
-- ( multiplication ) -- ( multiplication )
<> (mul ?x ?y) (mulc nil ?x ?y) <> ((mul ?x ?y)) (mulc nil ?x ?y)
<> (mulc ?t nil ?y) (sum ?t) <> (mulc ?t nil ?y) ((sum ?t))
<> (mulc ?t (0 ?x) ?y) (mulc ?t ?x (0 ?y)) <> (mulc ?t (0 ?x) ?y) (mulc ?t ?x (0 ?y))
<> (mulc ?t (1 ?x) ?y) (mulc (?y ?t) ?x (0 ?y)) <> (mulc ?t (1 ?x) ?y) (mulc (?y ?t) ?x (0 ?y))
-- ( subtraction ) -- ( subtraction )
<> (sub ?x ?y) (normalize subc 0 ?x ?y) <> ((sub ?x ?y)) (normalize subc 0 ?x ?y)
<> (subc 0 nil nil) (nil) <> (subc 0 nil nil) (nil)
<> (subc 1 nil nil) (#err) <> (subc 1 nil nil) (#err)
<> (subc 0 ?x nil) (?x) <> (subc 0 ?x nil) (?x)
@ -119,23 +119,40 @@
<> (dec' (0 ?t)) ((1 dec' ?t)) <> (dec' (0 ?t)) ((1 dec' ?t))
<> (dec' (1 ?t)) ((0 ?t)) <> (dec' (1 ?t)) ((0 ?t))
-- ( inc )
<> ((inc nil)) ((1 nil))
<> ((inc (0 ?t))) ((1 ?t))
<> ((inc (1 ?t))) ((0 (inc ?t)))
-- ( left shift; lshift x b means x<<b ) -- ( left shift; lshift x b means x<<b )
<> (lshift ?x (0 nil)) (?x) <> ((lshift ?x (0 nil))) (?x)
<> (lshift ?x (1 nil)) ((0 ?x)) <> ((lshift ?x (1 nil))) ((0 ?x))
<> (lshift ?x (?h (?a ?b))) (lshift (0 ?x) dec (?h (?a ?b))) <> ((lshift ?x (?h (?a ?b)))) ((lshift (0 ?x) dec (?h (?a ?b))))
-- ( constants ) -- ( divmod, i.e. quotient and remainder )
<> (a) ((1 (1 nil))) <> ((divmod ?x ?y)) ((divmod1 ?x ?y (cmp ?x ?y)))
<> (b) ((0 (1 nil))) <> ((divmod1 ?x ?y #lt)) (zero)
<> (c) ((1 (1 (1 nil)))) <> ((divmod1 ?x ?y #eq)) (one)
<> (d) (int 135) <> ((divmod1 ?x ?y #gt)) ((divmod2 ?x ?y zero (0 ?y)))
<> (e) (int 1913) <> ((divmod2 ?x ?y ?s ?m)) ((divmod3 ?x ?y ?s ?m (cmp ?x ?m)))
-- ( <> (f) (int 4294967295) ) <> ((divmod3 ?x ?y ?s ?m #lt)) ((divmod4 ?x ?y ?s zero))
<> ((divmod3 ?x ?y ?s ?m #eq)) ((divmod4 ?x ?y (inc ?s) zero))
<> ((divmod3 ?x ?y ?s ?m #gt)) ((divmod2 ?x ?y (inc ?s) (0 ?m)))
<> ((divmod4 ?x ?y (0 nil) ?d)) (((add ?d one) (sub ?x ?y)))
<> ((divmod4 ?x ?y ?s ?d)) ((divmod5 (sub ?x (lshift ?y ?s)) ?y dec ?s (add ?d (lshift one ?s))))
<> ((divmod5 (0 nil) ?y ?s ?d)) ((?d (0 nil)))
<> ((divmod5 ?x ?y ?s ?d)) ((divmod6 ?x ?y ?s ?d (cmp ?x (lshift ?y ?s))))
<> ((divmod6 ?x ?y (0 nil) ?d #lt)) ((?d ?x))
<> ((divmod6 ?x ?y ?s ?d #lt)) ((divmod5 ?x ?y dec ?s ?d))
<> ((divmod6 ?x ?y ?s ?d #eq)) ((divmod4 ?x ?y ?s ?d))
<> ((divmod6 ?x ?y ?s ?d #gt)) ((divmod4 ?x ?y ?s ?d))
-- ( cmp c c ) -- ( floor divison )
-- ( add a b ) <> ((div ?x ?y)) ((div' (divmod ?x ?y)))
-- ( sum (a (b (c nil))) ) <> ((div' (?q ?r))) (?q)
-- ( mul a c )
-- ( add d e ) -- ( remainder )
-- ( lshift (int 3) (int 1) ) <> ((mod ?x ?y)) ((mod' (divmod ?x ?y)))
<> ((mod' (?q ?r))) (?r)
(mod (int 64) (int 13))