improvements
This commit is contained in:
parent
7c8b83a67f
commit
15faffbf00
69
demo.modal
69
demo.modal
|
@ -7,16 +7,16 @@
|
|||
<> ten ((0 (1 (0 (1 ())))))
|
||||
|
||||
-- ( 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 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 to decimal digit )
|
||||
<> ((decimal (0 ()))) (0)
|
||||
|
@ -38,12 +38,16 @@
|
|||
-- ( to integer )
|
||||
<> ((int ?*)) ((sum f (one) g reverse (?*)))
|
||||
<> (g ()) (())
|
||||
<> (g (?h ?t)) ((binary ?h g ?t))
|
||||
<> (g (?h ?t)) (((binary ?h) g ?t))
|
||||
<> (f (?u) ()) (())
|
||||
<> (f (?u) (?h ?t)) (((mul ?h ?u) f ((mul ?u ten)) ?t))
|
||||
|
||||
-- ( to binary str )
|
||||
<> ((bstr ?x)) (emit force (0 (b ?x)))
|
||||
-- ( <> ((bstr ?x)) (emit force (0 (b ?x))) )
|
||||
-- ( <> ((bstr ?x)) ((bstr1 () ?x)) )
|
||||
<> ((bstr ?x)) ((bstr1 force ?x ()))
|
||||
<> ((bstr1 force/r () ?a)) (emit force/r (0 (b ?a)))
|
||||
<> ((bstr1 force/r (?h ?t) ?a)) ((bstr1 force/r ?t (?h ?a)))
|
||||
|
||||
-- ( to string: TODO, need division for this one )
|
||||
<> ((str ?x)) ((str1 ?x ()))
|
||||
|
@ -88,19 +92,23 @@
|
|||
<> ((cmpc ?e (1 ?x) (1 ?y))) ((cmpc ?e ?x ?y))
|
||||
|
||||
-- ( addition )
|
||||
<> ((add ?x ?y)) (addc 0 ?x ?y)
|
||||
<> (addc 0 () ()) (())
|
||||
<> (addc 1 () ()) ((1 ()))
|
||||
<> (addc ?c ?x ()) (addc ?c ?x (0 ()))
|
||||
<> (addc ?c () ?y) (addc ?c (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))
|
||||
<> ((add ?x ?y)) ((addc 0 ?x ?y))
|
||||
<> ((addc 0 () ())) (())
|
||||
<> ((addc 1 () ())) ((1 ()))
|
||||
-- ( <> ((addc ?c ?x ())) ((addc ?c ?x (0 ()))) )
|
||||
-- ( <> ((addc ?c () ?y)) ((addc ?c (0 ()) ?y)) )
|
||||
<> ((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)))
|
||||
|
||||
-- ( summation )
|
||||
<> ((sum ())) ((0 ()))
|
||||
|
@ -108,10 +116,10 @@
|
|||
<> ((sum (?a (?b ?c)))) ((sum ((add ?a ?b) ?c)))
|
||||
|
||||
-- ( multiplication )
|
||||
<> ((mul ?x ?y)) (mulc () ?x ?y)
|
||||
<> (mulc ?t () ?y) ((sum ?t))
|
||||
<> (mulc ?t (0 ?x) ?y) (mulc ?t ?x (0 ?y))
|
||||
<> (mulc ?t (1 ?x) ?y) (mulc (?y ?t) ?x (0 ?y))
|
||||
<> ((mul ?x ?y)) ((mulc () ?x ?y))
|
||||
<> ((mulc ?t () ?y)) ((sum ?t))
|
||||
<> ((mulc ?t (0 ?x) ?y)) ((mulc ?t ?x (0 ?y)))
|
||||
<> ((mulc ?t (1 ?x) ?y)) ((mulc (?y ?t) ?x (0 ?y)))
|
||||
|
||||
-- ( subtraction )
|
||||
<> ((sub ?x ?y)) (sub1 0 ?x ?y ())
|
||||
|
@ -188,5 +196,4 @@
|
|||
<> ((mod ?x ?y)) ((mod1 (divmod ?x ?y)))
|
||||
<> ((mod1 (?q ?r))) (?r)
|
||||
|
||||
-- (bstr (mul (int 2399) (int 3499)))
|
||||
(str (int 12345))
|
||||
(bstr (mul (int 123456789) (int 987654321)))
|
||||
|
|
Loading…
Reference in New Issue