1# 3a: signed and modular ints
2### `++fe` :: modulo bloq
20Produces the difference between two atoms in the modular basis
40 ++ dif |=([b/@ c/@] (sit (sub (add out (sit b)) (sit c))))
62------------------------------------------------------------------------
68Inverts the order of the modular field.
84 ++ inv |=(b/@ (sub (dec out) (sit b)))
102------------------------------------------------------------------------
108Revereses bytes within block.
129 (lsh c 1 $(a c, b (cut c [0 1] b)))
130 $(a c, b (cut c [1 1] b))
164 72.057.594.037.927.936
166 144.115.188.075.855.872
168 216.172.782.113.783.808
170 288.230.376.151.711.744
172 360.287.970.189.639.680
174 432.345.564.227.567.616
176 504.403.158.265.495.552
180 72.620.543.991.349.248
182------------------------------------------------------------------------
188The maximum integer value that the current block can store.
219 \/179.769.313.486.231.590.772.930.519.078.902.473.361.797.697.894.230.657.\/
220 273.430.081.157.732.675.805.500.963.132.708.477.322.407.536.021.120.113.
221 879.871.393.357.658.789.768.814.416.622.492.847.430.639.474.124.377.767.
222 893.424.865.485.276.302.219.601.246.094.119.453.082.952.085.005.768.838.
223 150.682.342.462.881.473.913.110.540.827.237.163.350.510.684.586.298.239.
224 947.245.938.479.716.304.835.356.329.624.224.137.216
227------------------------------------------------------------------------
233Roll `d` to the left by `c` `b`-sized blocks.
254 ++ rol |= [b/bloq c/@ d/@] ^- @ :: roll left
258 (sit (con (lsh b g e) (rsh b (sub f g) e)))
263 > `@ux`(~(rol fe 6) 4 3 0xabac.dedf.1213)
264 0x1213.0000.abac.dedf
265 > `@ux`(~(rol fe 6) 4 2 0xabac.dedf.1213)
266 0xdedf.1213.0000.abac
267 > `@t`(~(rol fe 5) 3 1 'dfgh')
269 > `@t`(~(rol fe 5) 3 2 'dfgh')
271 > `@t`(~(rol fe 5) 3 0 'dfgh')
274------------------------------------------------------------------------
280Roll `d` to the right by `c` `b`-sized blocks.
301 ++ ror |= {b/bloq c/@ d/@} ^- @ :: roll right
305 (sit (con (rsh b g e) (lsh b (sub f g) e)))
311 > `@ux`(~(ror fe 6) 4 1 0xabac.dedf.1213)
312 0x1213.0000.abac.dedf
313 > `@ux`(~(ror fe 6) 3 5 0xabac.dedf.1213)
314 0xacde.df12.1300.00ab
315 > `@ux`(~(ror fe 6) 3 3 0xabac.dedf.1213)
316 0xdf12.1300.00ab.acde
317 > `@t`(~(rol fe 5) 3 0 'hijk')
319 > `@t`(~(rol fe 5) 3 1 'hijk')
321 > `@t`(~(rol fe 5) 3 2 'hijk')
324------------------------------------------------------------------------
330Sum two numbers in this modular field.
349 ++ sum |=([b/@ c/@] (sit (add b c))) :: wrapping add
354 > (~(sum fe 3) 10 250)
364 > (~(sum fe 4) 10.000 256)
366 > (~(sum fe 4) 10.000 100.000)
371Atom in mod block representation
373Produce an atom in the current modular block representation.
390 ++ sit |=(b/@ (end a 1 b)) :: enforce modulo
403 > (~(sit fe 2) 10.000)
423 ++ si !: :: signed integer
426Container core for the signed integer functions.
428------------------------------------------------------------------------
434Produces the absolute value of a signed integer.
439`a` is a signed integer, `@s`.
449 ++ abs |=(a/@s (add (end 0 1 a) (rsh 0 1 a))) :: absolute value
461------------------------------------------------------------------------
467Produces the difference between two signed integers `b` and `c`.
472`a` is a signed integer, `@s`.
474`b` is a signed integer, `@s`.
485 ++ dif |= [a/@s b/@s] :: subtraction
486 (sum a (new !(syn b) (abs b)))
497 > (dif:si `@s`0 `@s`7)
500------------------------------------------------------------------------
506Produces the modulus of two signed integers.
511`a` is a signed integer, `@s`.
523 ++ dul |= [a/@s b/@] :: modulus
524 =+(c=(old a) ?:(-.c (mod +.c b) (sub b +.c)))
540------------------------------------------------------------------------
546Produces the quotient of two signed integers.
551`a` is a signed integer, `@s`.
553`b` is a signed integer, `@s`.
563 ++ fra |= [a/@s b/@s] :: divide
564 (new =(0 (mix (syn a) (syn b))) (div (abs a) (abs b)))
574------------------------------------------------------------------------
580Produces a signed integer from a loobean sign value `a` and an atom `b`.
597 ++ new |= [a/? b/@] :: [sign value] to @s
598 `@s`?:(a (mul 2 b) ?:(=(0 b) 0 +((mul 2 (dec b)))))
610------------------------------------------------------------------------
616Produces the cell `[sign value]` representations of a signed integer.
626A cell of a boolean and an atom.
631 ++ old |=(a/@s [(syn a) (abs a)]) :: [sign value]
648------------------------------------------------------------------------
654Produces the product of two signed integers.
671 ++ pro |= [a/@s b/@s] :: multiplication
672 (new =(0 (mix (syn a) (syn b))) (mul (abs a) (abs b)))
681 > (pro:si --10.000.000 -10)
683 > (pro:si -1.337 --0)
686------------------------------------------------------------------------
692Produces the remainder from a division of two signed integers.
709 ++ rem |=([a/@s b/@s] (dif a (pro b (fra a b)))) :: remainder
722 > (rem:si --0 --10.000)
725------------------------------------------------------------------------
731Sum two signed integers.
738`c` is a signed integer `@s`.
748 ++ sum |= [a/@s b/@s] :: addition
750 =+ [c=(old a) d=(old b)]
753 (new & (add +.c +.d))
755 (new & (sub +.c +.d))
756 (new | (sub +.d +.c))
759 (new | (sub +.c +.d))
760 (new & (sub +.d +.c))
761 (new | (add +.c +.d))
775------------------------------------------------------------------------
781Produces a signed integer from an unsigned integer.
783Note that the result must be manually cast to some `@s` odor to be
784inferred as an unsigned integer in the type system.
799 ++ sun |=(a/@u (mul 2 a)) :: @u to @s
812 > `@sd`(sun:si 12.345)
815------------------------------------------------------------------------
821Produce the sign of a signed integer, where `&` is posiitve, and `|` is negative.
836 ++ syn |=(a/@s =(0 (end 0 1 a))) :: sign test
848------------------------------------------------------------------------
854Compare two signed integers.
871 ++ cmp |= [a/@s b/@s] :: compare
905 ++ egcd !: :: schneier's egcd
908 =+ [c=(sun a) d=(sun b)]
909 =+ [u=[c=(sun 1) d=--0] v=[c=--0 d=(sun 1)]]
910 |- ^- {d/@ u/@s v/@s}
913 :: ?> ?& =(c (sum (pro (sun a) c.u) (pro (sun b) c.v)))
914 :: =(d (sum (pro (sun a) d.u) (pro (sun b) d.v)))
920 u [(dif d.u (pro q c.u)) c.u]
921 v [(dif d.v (pro q c.v)) c.v]
926Greatest common denominator
934 > (egcd (shaf ~ %ham) (shaf ~ %sam))
936 u=59.983.396.314.566.203.239.184.568.129.921.874.787
937 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