basic N tags; seems to work
This commit is contained in:
parent
dad487fde3
commit
f1d0ad5b1c
158
demo.modal
158
demo.modal
|
@ -37,24 +37,24 @@
|
||||||
<> (reverse1 ?a (?h ?t)) (reverse1 (?h ?a) ?t)
|
<> (reverse1 ?a (?h ?t)) (reverse1 (?h ?a) ?t)
|
||||||
|
|
||||||
-- ( to integer )
|
-- ( to integer )
|
||||||
<> ((int ?*)) ((sum f (one) g reverse (?*)))
|
<> ((int ?*)) ((sum f (N one) g reverse (?*)))
|
||||||
<> (g ()) (())
|
<> (g ()) (())
|
||||||
<> (g (?h ?t)) (((binary ?h) g ?t))
|
<> (g (?h ?t)) (((binary ?h) g ?t))
|
||||||
<> (f (?u) ()) (())
|
<> (f (N ?u) ()) (())
|
||||||
<> (f (?u) (?h ?t)) (((mul ?h ?u) f ((mul ?u ten)) ?t))
|
<> (f (N ?u) (?h ?t)) (((mul (N ?h) (N ?u)) f (mul (N ?u) (N ten)) ?t))
|
||||||
|
|
||||||
-- ( to binary str )
|
-- ( to binary str )
|
||||||
-- ( <> ((bstr ?x)) (emit force (0 (b ?x))) )
|
-- ( <> ((bstr ?x)) (emit force (0 (b ?x))) )
|
||||||
-- ( <> ((bstr ?x)) ((bstr1 () ?x)) )
|
-- ( <> ((bstr ?x)) ((bstr1 () ?x)) )
|
||||||
<> ((bstr ?x)) ((bstr1 force ?x ()))
|
<> ((bstr (N ?x))) ((bstr1 force ?x ()))
|
||||||
<> ((bstr1 force/r () ?a)) (emit force/r (0 (b ?a)))
|
<> ((bstr1 force/r () ?a)) (emit force/r (0 (b ?a)))
|
||||||
<> ((bstr1 force/r (?h ?t) ?a)) ((bstr1 force/r ?t (?h ?a)))
|
<> ((bstr1 force/r (?h ?t) ?a)) ((bstr1 force/r ?t (?h ?a)))
|
||||||
|
|
||||||
-- ( to string: TODO, need division for this one )
|
-- ( to string: TODO, need division for this one )
|
||||||
<> ((str ?x)) ((str1 ?x ()))
|
<> ((str (N ?x))) ((str1 (N ?x) ()))
|
||||||
<> ((str1 (0 ()) ?a)) (emit force ?a)
|
<> ((str1 (N (0 ())) ?a)) (emit force ?a)
|
||||||
<> ((str1 (?h ?t) ?a)) ((str2 (divmod (?h ?t) ten) ?a))
|
<> ((str1 (N (?h ?t)) ?a)) ((str2 (divmod (N (?h ?t)) (N ten)) ?a))
|
||||||
<> ((str2 (?q ?r) ?a)) ((str1 ?q ((decimal ?r) ?a)))
|
<> ((str2 ((N ?q) (N ?r)) ?a)) ((str1 (N ?q) ((decimal ?r) ?a)))
|
||||||
|
|
||||||
-- ( force a list to evaluate to digits/letters )
|
-- ( force a list to evaluate to digits/letters )
|
||||||
<> ((?h force/r ?t)) (force/r (?h ?t))
|
<> ((?h force/r ?t)) (force/r (?h ?t))
|
||||||
|
@ -93,11 +93,9 @@
|
||||||
<> ((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 (N ?x) (N ?y))) (add/e force (addc 0 ?x ?y))
|
||||||
<> ((addc 0 () ())) (())
|
<> ((addc 0 () ())) (())
|
||||||
<> ((addc 1 () ())) ((1 ()))
|
<> ((addc 1 () ())) ((1 ()))
|
||||||
-- ( <> ((addc ?c ?x ())) ((addc ?c ?x (0 ()))) )
|
|
||||||
-- ( <> ((addc ?c () ?y)) ((addc ?c (0 ()) ?y)) )
|
|
||||||
<> ((addc 0 ?x ())) (?x)
|
<> ((addc 0 ?x ())) (?x)
|
||||||
<> ((addc 0 () ?y)) (?y)
|
<> ((addc 0 () ?y)) (?y)
|
||||||
<> ((addc 1 ?x ())) ((addc 1 ?x (0 ())))
|
<> ((addc 1 ?x ())) ((addc 1 ?x (0 ())))
|
||||||
|
@ -110,56 +108,66 @@
|
||||||
<> ((addc 1 (0 ?x) (1 ?y))) ((0 (addc 1 ?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) (0 ?y))) ((0 (addc 1 ?x ?y)))
|
||||||
<> ((addc 1 (1 ?x) (1 ?y))) ((1 (addc 1 ?x ?y)))
|
<> ((addc 1 (1 ?x) (1 ?y))) ((1 (addc 1 ?x ?y)))
|
||||||
|
<> (add/e force/r ?x) ((N ?x))
|
||||||
|
|
||||||
-- ( summation )
|
-- ( summation )
|
||||||
<> ((sum ())) ((0 ()))
|
<> ((sum ())) ((N (0 ())))
|
||||||
<> ((sum (?a ()))) (?a)
|
<> ((sum (?a ()))) (?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 () ?x ?y))
|
<> ((mul (N ?x) (N ?y))) (mul/e (mulc () ?x ?y))
|
||||||
<> ((mulc ?t () ?y)) ((sum ?t))
|
<> ((mulc ?t () ?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 ((N ?y) ?t) ?x (0 ?y)))
|
||||||
|
<> (mul/e (N ?x)) ((N ?x))
|
||||||
|
|
||||||
-- ( subtraction )
|
-- ( subtraction )
|
||||||
<> ((sub ?x ?y)) (sub1 0 ?x ?y ())
|
<> ((sub (N ?x) (N ?y))) (sub/e force (sub1 0 ?x ?y ()))
|
||||||
<> (sub1 0 () () ?s) (())
|
<> ((sub1 0 () () ?s)) (())
|
||||||
<> (sub1 1 () () ?s) (#err)
|
<> ((sub1 1 () () ?s)) (#err)
|
||||||
<> (sub1 ?c ?x () ?s) (sub1 ?c ?x (0 ()) ?s)
|
<> ((sub1 ?c ?x () ?s)) ((sub1 ?c ?x (0 ()) ?s))
|
||||||
<> (sub1 ?c () ?y ?s) (sub1 ?c (0 ()) ?y ?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) (0 ?y) ?s)) ((sub1 0 ?x ?y (0 ?s)))
|
||||||
<> (sub1 0 (0 ?x) (1 ?y) ?s) (sub2 1 ?x ?y ?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) (0 ?y) ?s)) ((sub2 0 ?x ?y ?s))
|
||||||
<> (sub1 0 (1 ?x) (1 ?y) ?s) (sub1 0 ?x ?y (0 ?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) (0 ?y) ?s)) ((sub2 1 ?x ?y ?s))
|
||||||
<> (sub1 1 (0 ?x) (1 ?y) ?s) (sub1 1 ?x ?y (0 ?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) (0 ?y) ?s)) ((sub1 0 ?x ?y (0 ?s)))
|
||||||
<> (sub1 1 (1 ?x) (1 ?y) ?s) (sub2 1 ?x ?y ?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 ())) ((1 (sub1 ?c ?x ?y ())))
|
||||||
<> (sub2 ?c ?x ?y (?h ?t)) ((0 sub2 ?c ?x ?y ?t))
|
<> ((sub2 ?c ?x ?y (?h ?t))) ((0 (sub2 ?c ?x ?y ?t)))
|
||||||
|
<> (sub/e force/r ?x) ((N ?x))
|
||||||
|
|
||||||
<> (dec (0 ())) (#err)
|
<> ((dec (N (0 ())))) (#err)
|
||||||
<> (dec (1 ())) ((0 ()))
|
<> ((dec (N (1 ())))) ((N (0 ())))
|
||||||
<> (dec (1 ?t)) ((0 ?t))
|
<> ((dec (N (1 ?t)))) ((N (0 ?t)))
|
||||||
<> (dec (0 ?t)) (dec1 (0 ?t))
|
<> ((dec (N (0 ?t)))) (dec/e (dec1 (0 ?t)))
|
||||||
<> (dec1 (1 ())) (())
|
|
||||||
<> (dec1 (1 ?t)) ((0 ?t))
|
<> ((dec1 (0 ?t))) ((1 (dec1 ?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))
|
||||||
|
|
||||||
-- ( inc )
|
-- ( inc )
|
||||||
<> ((inc ())) ((1 ()))
|
<> ((inc (N ?x))) (inc/e force (inc1 ?x))
|
||||||
<> ((inc (0 ?t))) ((1 ?t))
|
<> ((inc1 ())) ((1 ()))
|
||||||
<> ((inc (1 ?t))) ((0 (inc ?t)))
|
<> ((inc1 (0 ?t))) ((1 ?t))
|
||||||
|
<> ((inc1 (1 ?t))) ((0 (inc1 ?t)))
|
||||||
|
<> (inc/e force/r ?x) ((N ?x))
|
||||||
|
|
||||||
-- ( left shift; lshift x b means x<<b )
|
-- ( left shift; lshift x b means x<<b )
|
||||||
<> ((lshift ?x (0 ()))) (?x)
|
<> ((lshift (N ?x) (N ?k))) (lshift/e force/r (lshift1 ?x (N ?k)))
|
||||||
<> ((lshift ?x (1 ()))) ((0 ?x))
|
<> ((lshift1 ?x (N (0 ())))) (?x)
|
||||||
<> ((lshift ?x (0 (?a ?b)))) ((lshift (0 ?x) dec (0 (?a ?b))))
|
<> ((lshift1 ?x (N (1 ())))) ((0 ?x))
|
||||||
<> ((lshift ?x (1 (?a ?b)))) ((lshift (0 ?x) (0 (?a ?b))))
|
<> ((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))
|
||||||
|
|
||||||
<> ((rshift1 (?a ()))) ((0 ()))
|
<> ((rshift1 (N (?a ())))) ((N (0 ())))
|
||||||
<> ((rshift1 (?a (?b ?c)))) ((?b ?c))
|
<> ((rshift1 (N (?a (?b ?c))))) ((N (?b ?c)))
|
||||||
|
|
||||||
-- ( divmod, i.e. quotient and remainder )
|
-- ( divmod, i.e. quotient and remainder )
|
||||||
-- ( x is the dividend, or what's left of it )
|
-- ( x is the dividend, or what's left of it )
|
||||||
|
@ -168,41 +176,44 @@
|
||||||
-- ( o is the next valuet o add to the quotient )
|
-- ( o is the next valuet o add to the quotient )
|
||||||
-- ( m is the next multiple of y to work with )
|
-- ( m is the next multiple of y to work with )
|
||||||
-- ( d is the quotient, so far )
|
-- ( d is the quotient, so far )
|
||||||
<> ((divmod ?x ?y)) ((divmod1 ?x ?y (cmp ?x ?y)))
|
<> ((divmod (N ?x) (N ?y))) (divmod/p (divmod1 ?x ?y (cmp ?x ?y)))
|
||||||
<> ((divmod1 ?x ?y #lt)) ((zero ?x))
|
<> ((divmod1 ?x ?y #lt)) (((N zero) (N ?x)))
|
||||||
<> ((divmod1 ?x ?y #eq)) ((one zero))
|
<> ((divmod1 ?x ?y #eq)) (((N one) (N zero)))
|
||||||
<> ((divmod1 ?x ?y #gt)) ((divmod2 ?x ?y zero ?y))
|
<> ((divmod1 ?x ?y #gt)) ((divmod2 (N ?x) (N ?y) (N zero) (N ?y)))
|
||||||
|
|
||||||
<> ((divmod2 ?x ?y ?s ?m)) ((divmod3 ?x ?y ?s ?m (cmp ?x (0 ?m))))
|
<> ((divmod2 (N ?x) (N ?y) (N ?s) (N ?m))) ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) (cmp ?x (0 ?m))))
|
||||||
<> ((divmod3 ?x ?y ?s ?m #gt)) ((divmod2 ?x ?y (inc ?s) (0 ?m)))
|
<> ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) #gt)) ((divmod2 (N ?x) (N ?y) (inc (N ?s)) (N (0 ?m))))
|
||||||
<> ((divmod3 ?x ?y ?s ?m #eq)) ((divmod4 ?x ?y (inc ?s) (0 ?m) zero))
|
<> ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) #eq)) ((divmod4 (N ?x) (N ?y) (inc (N ?s)) (N (0 ?m)) (N zero)))
|
||||||
<> ((divmod3 ?x ?y ?s ?m #lt)) ((divmod4 ?x ?y ?s ?m zero))
|
<> ((divmod3 (N ?x) (N ?y) (N ?s) (N ?m) #lt)) ((divmod4 (N ?x) (N ?y) (N ?s) (N ?m) (N zero)))
|
||||||
|
|
||||||
<> ((divmod4 ?x ?y (0 ()) ?m ?d)) (((add ?d one) (sub ?x ?y)))
|
<> ((divmod4 (N ?x) (N ?y) (N (0 ())) (N ?m) (N ?d))) (((add (N ?d) (N one)) (sub (N ?x) (N ?y))))
|
||||||
<> ((divmod4 ?x ?y ?s ?m ?d)) ((divmod5 (sub ?x ?m) ?y dec ?s (rshift1 ?m) (add ?d (lshift one ?s))))
|
<> ((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)))))
|
||||||
|
|
||||||
<> ((divmod5 (0 ()) ?y ?s ?m ?d)) ((?d (0 ())))
|
<> ((divmod5 (N (0 ())) (N ?y) (N ?s) (N ?m) (N ?d))) (((N ?d) (N (0 ()))))
|
||||||
<> ((divmod5 ?x ?y ?s ?m ?d)) ((divmod6 ?x ?y ?s ?m ?d (cmp ?x ?m)))
|
<> ((divmod5 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d))) ((divmod6 (N ?x) (N ?y) (N ?s) (N ?m) (N ?d) (cmp ?x ?m)))
|
||||||
|
|
||||||
<> ((divmod6 ?x ?y (0 ()) ?m ?d #lt)) ((?d ?x))
|
<> ((divmod6 (N ?x) (N ?y) (N (0 ())) (N ?m) (N ?d) #lt)) (((N ?d) (N ?x)))
|
||||||
<> ((divmod6 ?x ?y ?s ?m ?d #lt)) ((divmod5 ?x ?y dec ?s (rshift1 ?m) ?d))
|
<> ((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 ?x ?y ?s ?m ?d #eq)) ((divmod4 ?x ?y ?s ?m ?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 ?x ?y ?s ?m ?d #gt)) ((divmod4 ?x ?y ?s ?m ?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)))
|
||||||
|
|
||||||
-- ( floor divison )
|
-- ( floor divison )
|
||||||
<> ((div ?x ?y)) ((div1 (divmod ?x ?y)))
|
<> ((div (N ?x) (N ?y))) ((div1 (divmod (N ?x) (N ?y))))
|
||||||
<> ((div1 (?q ?r))) (?q)
|
<> ((div1 (?q ?r))) (?q)
|
||||||
|
|
||||||
-- ( remainder )
|
-- ( remainder )
|
||||||
<> ((mod ?x ?y)) ((mod1 (divmod ?x ?y)))
|
<> ((mod (N ?x) (N ?y))) ((mod1 (divmod (N ?x) (N ?y))))
|
||||||
<> ((mod1 (?q ?r))) (?r)
|
<> ((mod1 (?q ?r))) (?r)
|
||||||
|
|
||||||
-- ( expontentiation )
|
-- ( expontentiation )
|
||||||
<> ((pow ?x ())) ((1 ()))
|
<> ((pow (N ?x) ())) ((N (1 ())))
|
||||||
<> ((pow ?x (0 ()))) ((1 ()))
|
<> ((pow (N ?x) (N (0 ())))) ((N (1 ())))
|
||||||
<> ((pow ?x (1 ()))) (?x)
|
<> ((pow (N ?x) (N (1 ())))) ((N ?x))
|
||||||
<> ((pow ?x (0 ?k))) ((pow (mul ?x ?x) ?k))
|
<> ((pow (N ?x) (N (0 ?k)))) ((pow (mul (N ?x) (N ?x)) (N ?k)))
|
||||||
<> ((pow ?x (1 ?k))) ((mul ?x (pow (mul ?x ?x) ?k)))
|
<> ((pow (N ?x) (N (1 ?k)))) ((mul (N ?x) (pow (mul (N ?x) (N ?x)) (N ?k))))
|
||||||
|
|
||||||
-- ( greatest common denominator )
|
-- ( greatest common denominator )
|
||||||
<> ((gcd ?a ?b)) ((gcd1 ?a ?b (cmp ?b (0 ()))))
|
<> ((gcd ?a ?b)) ((gcd1 ?a ?b (cmp ?b (0 ()))))
|
||||||
|
@ -213,4 +224,13 @@
|
||||||
-- ( least common multiple )
|
-- ( least common multiple )
|
||||||
<> ((lcm ?a ?b)) ((mul ?a (div ?b (gcd ?a ?b))))
|
<> ((lcm ?a ?b)) ((mul ?a (div ?b (gcd ?a ?b))))
|
||||||
|
|
||||||
(str (lcm (int 1000) (int 777)))
|
-- (str (pow (int 17) (int 17)))
|
||||||
|
|
||||||
|
<> (a) ((N (1 (1 (1 ())))))
|
||||||
|
<> (b) ((N (0 (1 (1 ())))))
|
||||||
|
<> (c) ((N (0 (1 ()))))
|
||||||
|
|
||||||
|
-- (add a b)
|
||||||
|
-- (sum (a (b (c ()))))
|
||||||
|
-- (str (div (mul a b) c))
|
||||||
|
(bstr (pow (int 20) (int 20)))
|
||||||
|
|
Loading…
Reference in New Issue