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/bool.ts

49 lines
1.5 KiB

import { toNative as $$, L, P, _, fromNative as __ } from './core';
import { EQ, GT, LT, Ord } from './ord';
export type Bool = L<<T extends P>(t: T) => L<(f: T) => T>>;
export const True: Bool
= _(t => _(_f => t)) as Bool;
export const False: Bool
= _(_t => _(f => f));
export const iif: L<<T extends P>(b: Bool) => L<(t: T) => L<(f: T) => T>>>
= _(b => _(t => _(f => b._(t)._(f))));
export const not: L<(b: Bool) => Bool>
= _(b => b._(False)._(True));
export const cmp: L<(l: Bool) => L<(r: Bool) => Ord>>
= _(l => _(r => l._(r._(EQ)._(GT))._(r._(LT)._(EQ))));
export const lt: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(False)._(r)));
export const le: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(r)._(True)));
export const eq: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(r)._(not._(r))));
export const ge: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(True)._(not._(r))));
export const gt: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(not._(r))._(False)));
export const and: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(r)._(False)));
export const or: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(True)._(r)));
export const xor: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(not._(r))._(r)));
export const fromBoolean: (b: boolean) => Bool
= b => b ? True : False;
export const toBoolean: (b: Bool) => boolean
= b => $$(b._(__(true))._(__(false)));