2title = "3a: Modular and Signed Ints"
9Extended Euclidean algorithm
11Produces `d`, the [greatest common
12divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of `a` and `b`.
13Also produces `u` and `v` such that `au + bv = GCD(a, b)`.
23`d`, the greatest common divisor, is an atom.
25`u`, the coefficient of `a`, is a signed integer.
27`v`, the coefficient of `b`, is a signed integer.
35 =+ [c=(sun a) d=(sun b)]
36 =+ [u=[c=(sun 1) d=--0] v=[c=--0 d=(sun 1)]]
44 u [(dif d.u (pro q c.u)) c.u]
45 v [(dif d.v (pro q c.v)) c.v]
62Container `door` for modular arithmetic functions.
82Produces the difference between atoms `b` and `c`, with `a` as the modular base.
86`a` is an atom, and is the sample of `+fo`.
101 (sit (sub (add a b) (sit c)))
110> (~(dif fo 21) 11 45)
120Produces the power of `c` raised to the `b`, with `a` as the modular base.
124`a` is an atom, and is the sample of `+fo`.
143 ?:(=(0 (end 0 b)) e (pro c e))
155 > (~(exp fo 195) 8 2)
158 > (~(exp fo 995) 8 2)
168Produces the quotient of `b` divided by `c`, with `a` as the modular base.
172`a` is an atom, and is the sample of `+fo`.
212Produces an atom by taking the signed modulus of `a` with the coefficient `u`;
213`u` is produced by taking the [`+egcd`](#egcd) of `a` and `b`.
217`a` is an atom, and is the sample of `+fo`.
230 =+ c=(dul:si u:(egcd b a) a)
259Produces the multiplication of `b` and `c` modulo `a`.
263`a` is an atom, and is the sample of `+fo`.
297Produces the remainder of `b` modulo `a`.
301`a` is an atom, and is the sample of `+fo`.
330Produces the remainder of `(b + c) mod a`.
334`a` is an atom, and is the sample of `+fo`.
368Container core for signed integer functions.
380The signed-integer type is represented by the `@s` aura. Positive integers are
381prepended with a `--`, and negative integers are prepended with a `-`. For
382example, `--1` represents positive one, and `-1` represents negative one.
384[ZigZag encoding](https://developers.google.com/protocol-buffers/docs/encoding?hl=en#signed-ints)
385is used to convert atoms to signed integers. Positive signed
386integers correspond to even atoms of twice their absolute value, and negative
387signed integers correspond to odd atoms of twice their absolute value minus
410Produces the absolute value of signed integer `a`.
414`a` is a signed integer.
423++ abs |=(a=@s (add (end 0 a) (rsh 0 a)))
442Produces the difference of `a` minus `b`.
446`a` is a signed integer.
448`b` is a signed integer.
458 (sum a (new !(syn b) (abs b)))
477Produces the remainder of `b` modulo `a`.
481`a` is a signed integer.
493 =+(c=(old a) ?:(-.c (mod +.c b) (sub b +.c)))
507> `@s`(dul:si -11 -61)
517Produces the quotient of `b` divided by `c`.
521`a` is a signed integer.
523`b` is a signed integer.
533 (new =(0 (mix (syn a) (syn b))) (div (abs a) (abs b)))
555Produces a signed integer from an atom `b`. The product's sign is determined
556by the value of flag `a`: `&` will result in a prepending `--`, and `|` will
557result in a prepending `-`.
573 `@s`?:(a (mul 2 b) ?:(=(0 b) 0 +((mul 2 (dec b)))))
596Sign and absolute value
598Produces a cell composed of a `%.y` or `%.n`, depending on whether `a` is
599positive or negative, and the absolute value of `a`.
603`a` is a signed integer.
607A cell composed of a `?` and an atom.
612 ++ old |=(a=@s [(syn a) (abs a)])
616++ old |=(a=@s [(syn a) (abs a)])
635Produces a signed integer by multiplying `a` and `b`.
639`a` is an unsigned integer.
641`b` is an unsigned integer.
647 (new =(0 (mix (syn a) (syn b))) (mul (abs a) (abs b)))
666Produces a signed integer that is the remainder of `a` divided by `b`.
670`a` is a signed integer.
672`b` is a signed integer.
681++ rem |=([a=@s b=@s] (dif a (pro b (fra a b))))
706Produces an atom by adding `a` and `b`.
710`a` is a signed integer.
712`b` is a signed integer.
722 =+ [c=(old a) d=(old b)]
725 (new & (add +.c +.d))
727 (new & (sub +.c +.d))
728 (new | (sub +.d +.c))
731 (new | (sub +.c +.d))
732 (new & (sub +.d +.c))
733 (new | (add +.c +.d))
752Multiplies the unsigned integer `a` by two, producing an atom.
756`a` is an unsigned integer.
765++ sun |=(a=@u (mul 2 a))
796Tests whether signed atom `a` is positive or negative. `%.y` is produced if `a`
797is positive, and `%.n` is produced if `a` is negative.
801`a` is a signed integer.
810++ syn |=(a=@s =(0 (end 0 a)))
829Compares `a` and `b` to see which is greater. If `a` is greater than `b`, `--1`
830is produced. If `b` is greater than `a`, `-1` is produced. If `a` and `b` are
831equal, `--0` is produced.
835`a` is a signed integer.
837`b` is a signed integer.
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