6# 3a: signed and modular ints
7### `++fe` :: modulo bloq
25Produces the difference between two atoms in the modular basis
45 ++ dif |=([b/@ c/@] (sit (sub (add out (sit b)) (sit c))))
67------------------------------------------------------------------------
73Inverts the order of the modular field.
89 ++ inv |=(b/@ (sub (dec out) (sit b)))
107------------------------------------------------------------------------
113Revereses bytes within block.
134 (lsh c 1 $(a c, b (cut c [0 1] b)))
135 $(a c, b (cut c [1 1] b))
169 72.057.594.037.927.936
171 144.115.188.075.855.872
173 216.172.782.113.783.808
175 288.230.376.151.711.744
177 360.287.970.189.639.680
179 432.345.564.227.567.616
181 504.403.158.265.495.552
185 72.620.543.991.349.248
187------------------------------------------------------------------------
193The maximum integer value that the current block can store.
224 \/179.769.313.486.231.590.772.930.519.078.902.473.361.797.697.894.230.657.\/
225 273.430.081.157.732.675.805.500.963.132.708.477.322.407.536.021.120.113.
226 879.871.393.357.658.789.768.814.416.622.492.847.430.639.474.124.377.767.
227 893.424.865.485.276.302.219.601.246.094.119.453.082.952.085.005.768.838.
228 150.682.342.462.881.473.913.110.540.827.237.163.350.510.684.586.298.239.
229 947.245.938.479.716.304.835.356.329.624.224.137.216
232------------------------------------------------------------------------
238Roll `d` to the left by `c` `b`-sized blocks.
259 ++ rol |= [b/bloq c/@ d/@] ^- @ :: roll left
263 (sit (con (lsh b g e) (rsh b (sub f g) e)))
268 > `@ux`(~(rol fe 6) 4 3 0xabac.dedf.1213)
269 0x1213.0000.abac.dedf
270 > `@ux`(~(rol fe 6) 4 2 0xabac.dedf.1213)
271 0xdedf.1213.0000.abac
272 > `@t`(~(rol fe 5) 3 1 'dfgh')
274 > `@t`(~(rol fe 5) 3 2 'dfgh')
276 > `@t`(~(rol fe 5) 3 0 'dfgh')
279------------------------------------------------------------------------
285Roll `d` to the right by `c` `b`-sized blocks.
306 ++ ror |= {b/bloq c/@ d/@} ^- @ :: roll right
310 (sit (con (rsh b g e) (lsh b (sub f g) e)))
316 > `@ux`(~(ror fe 6) 4 1 0xabac.dedf.1213)
317 0x1213.0000.abac.dedf
318 > `@ux`(~(ror fe 6) 3 5 0xabac.dedf.1213)
319 0xacde.df12.1300.00ab
320 > `@ux`(~(ror fe 6) 3 3 0xabac.dedf.1213)
321 0xdf12.1300.00ab.acde
322 > `@t`(~(rol fe 5) 3 0 'hijk')
324 > `@t`(~(rol fe 5) 3 1 'hijk')
326 > `@t`(~(rol fe 5) 3 2 'hijk')
329------------------------------------------------------------------------
335Sum two numbers in this modular field.
354 ++ sum |=([b/@ c/@] (sit (add b c))) :: wrapping add
359 > (~(sum fe 3) 10 250)
369 > (~(sum fe 4) 10.000 256)
371 > (~(sum fe 4) 10.000 100.000)
376Atom in mod block representation
378Produce an atom in the current modular block representation.
395 ++ sit |=(b/@ (end a 1 b)) :: enforce modulo
408 > (~(sit fe 2) 10.000)
428 ++ si !: :: signed integer
431Container core for the signed integer functions.
433------------------------------------------------------------------------
439Produces the absolute value of a signed integer.
444`a` is a signed integer, `@s`.
454 ++ abs |=(a/@s (add (end 0 1 a) (rsh 0 1 a))) :: absolute value
466------------------------------------------------------------------------
472Produces the difference between two signed integers `b` and `c`.
477`a` is a signed integer, `@s`.
479`b` is a signed integer, `@s`.
490 ++ dif |= [a/@s b/@s] :: subtraction
491 (sum a (new !(syn b) (abs b)))
502 > (dif:si `@s`0 `@s`7)
505------------------------------------------------------------------------
511Produces the modulus of two signed integers.
516`a` is a signed integer, `@s`.
528 ++ dul |= [a/@s b/@] :: modulus
529 =+(c=(old a) ?:(-.c (mod +.c b) (sub b +.c)))
545------------------------------------------------------------------------
551Produces the quotient of two signed integers.
556`a` is a signed integer, `@s`.
558`b` is a signed integer, `@s`.
568 ++ fra |= [a/@s b/@s] :: divide
569 (new =(0 (mix (syn a) (syn b))) (div (abs a) (abs b)))
579------------------------------------------------------------------------
585Produces a signed integer from a loobean sign value `a` and an atom `b`.
602 ++ new |= [a/? b/@] :: [sign value] to @s
603 `@s`?:(a (mul 2 b) ?:(=(0 b) 0 +((mul 2 (dec b)))))
615------------------------------------------------------------------------
621Produces the cell `[sign value]` representations of a signed integer.
631A cell of a boolean and an atom.
636 ++ old |=(a/@s [(syn a) (abs a)]) :: [sign value]
653------------------------------------------------------------------------
659Produces the product of two signed integers.
676 ++ pro |= [a/@s b/@s] :: multiplication
677 (new =(0 (mix (syn a) (syn b))) (mul (abs a) (abs b)))
686 > (pro:si --10.000.000 -10)
688 > (pro:si -1.337 --0)
691------------------------------------------------------------------------
697Produces the remainder from a division of two signed integers.
714 ++ rem |=([a/@s b/@s] (dif a (pro b (fra a b)))) :: remainder
727 > (rem:si --0 --10.000)
730------------------------------------------------------------------------
736Sum two signed integers.
743`c` is a signed integer `@s`.
753 ++ sum |= [a/@s b/@s] :: addition
755 =+ [c=(old a) d=(old b)]
758 (new & (add +.c +.d))
760 (new & (sub +.c +.d))
761 (new | (sub +.d +.c))
764 (new | (sub +.c +.d))
765 (new & (sub +.d +.c))
766 (new | (add +.c +.d))
780------------------------------------------------------------------------
786Produces a signed integer from an unsigned integer.
788Note that the result must be manually cast to some `@s` odor to be
789inferred as an unsigned integer in the type system.
804 ++ sun |=(a/@u (mul 2 a)) :: @u to @s
817 > `@sd`(sun:si 12.345)
820------------------------------------------------------------------------
826Produce the sign of a signed integer, where `&` is posiitve, and `|` is negative.
841 ++ syn |=(a/@s =(0 (end 0 1 a))) :: sign test
853------------------------------------------------------------------------
859Compare two signed integers.
876 ++ cmp |= [a/@s b/@s] :: compare
910 ++ egcd !: :: schneier's egcd
913 =+ [c=(sun a) d=(sun b)]
914 =+ [u=[c=(sun 1) d=--0] v=[c=--0 d=(sun 1)]]
915 |- ^- {d/@ u/@s v/@s}
918 :: ?> ?& =(c (sum (pro (sun a) c.u) (pro (sun b) c.v)))
919 :: =(d (sum (pro (sun a) d.u) (pro (sun b) d.v)))
925 u [(dif d.u (pro q c.u)) c.u]
926 v [(dif d.v (pro q c.v)) c.v]
931Greatest common denominator
939 > (egcd (shaf ~ %ham) (shaf ~ %sam))
941 u=59.983.396.314.566.203.239.184.568.129.921.874.787
942 v=38.716.650.351.034.402.960.165.718.823.532.275.722
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list