Transformer architecture implemented in TypeScript with WebGPU.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
nn/src/byte.ts

34 lines
882 B

import { L, _, id } from './core';
import { iif } from './bool';
import { Num, Succ, Zero, fromNumber as _n, eq } from './num';
export type Byte = Num;
export const x00: Byte
= Zero;
export const xFF: Num
= _n(255);
export const Inc: L<(p: Byte) => Byte>
= _(p => iif(eq(xFF)(p))(x00)(Succ(p)));
export { ifz, cmp, lt, le, eq, ge, gt, even, odd, div, mod, show, toNumber } from './num';
export const inc: L<(n: Byte) => Byte>
= Inc;
export const dec: L<(n: Byte) => Byte>
= _(n => n(xFF)(id));
export const sum: L<(l: Byte) => L<(r: Byte) => Byte>>
= _(l => _(r => r(l)(sum(inc(l)))));
export const sub: L<(l: Byte) => L<(r: Byte) => Byte>>
= _(l => _(r => r(l)(sub(dec(l)))));
export const mul: L<(l: Byte) => L<(r: Byte) => Byte>>
= _(l => _(r => l(x00)(_(pl => sum(r)(mul(pl)(r))))));
export const fromNumber: (n: number) => Byte
= n => _n(n % 256);