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.
384Zig zag encoding is used to convert atoms to signed integers. Positive signed
385integers correspond to even atoms of twice their absolute value, and negative
386signed integers correspond to odd atoms of twice their absolute value minus
409Produces the absolute value of signed integer `a`.
413`a` is a signed integer.
422++ abs |=(a=@s (add (end 0 a) (rsh 0 a)))
441Produces the difference of `a` minus `b`.
445`a` is a signed integer.
447`b` is a signed integer.
457 (sum a (new !(syn b) (abs b)))
476Produces the remainder of `b` modulo `a`.
480`a` is a signed integer.
492 =+(c=(old a) ?:(-.c (mod +.c b) (sub b +.c)))
506> `@s`(dul:si -11 -61)
516Produces the quotient of `b` divided by `c`.
520`a` is a signed integer.
522`b` is a signed integer.
532 (new =(0 (mix (syn a) (syn b))) (div (abs a) (abs b)))
554Produces a signed integer from an atom `b`. The product's sign is determined
555by the value of flag `a`: `&` will result in a prepending `--`, and `|` will
556result in a prepending `-`.
572 `@s`?:(a (mul 2 b) ?:(=(0 b) 0 +((mul 2 (dec b)))))
595Sign and absolute value
597Produces a cell composed of a `%.y` or `%.n`, depending on whether `a` is
598positive or negative, and the absolute value of `a`.
602`a` is a signed integer.
606A cell composed of a `?` and an atom.
611 ++ old |=(a=@s [(syn a) (abs a)])
615++ old |=(a=@s [(syn a) (abs a)])
634Produces a signed integer by multiplying `a` and `b`.
638`a` is an unsigned integer.
640`b` is an unsigned integer.
646 (new =(0 (mix (syn a) (syn b))) (mul (abs a) (abs b)))
665Produces a signed integer that is the remainder of `a` divided by `b`.
669`a` is a signed integer.
671`b` is a signed integer.
680++ rem |=([a=@s b=@s] (dif a (pro b (fra a b))))
705Produces an atom by adding `a` and `b`.
709`a` is a signed integer.
711`b` is a signed integer.
721 =+ [c=(old a) d=(old b)]
724 (new & (add +.c +.d))
726 (new & (sub +.c +.d))
727 (new | (sub +.d +.c))
730 (new | (sub +.c +.d))
731 (new & (sub +.d +.c))
732 (new | (add +.c +.d))
751Multiplies the unsigned integer `a` by two, producing an atom.
755`a` is an unsigned integer.
764++ sun |=(a=@u (mul 2 a))
795Tests whether signed atom `a` is positive or negative. `%.y` is produced if `a`
796is positive, and `%.n` is produced if `a` is negative.
800`a` is a signed integer.
809++ syn |=(a=@s =(0 (end 0 a)))
828Compares `a` and `b` to see which is greater. If `a` is greater than `b`, `--1`
829is produced. If `b` is greater than `a`, `-1` is produced. If `a` and `b` are
830equal, `--0` is produced.
834`a` is a signed integer.
836`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