import { Op, Rewrite, ChainRewrites, Sym, Equation, Refl, VerifyEquation, assert, Subst, ApplyRewrite, Evaluate, OpToStr, SubstEq } from './utils/theorem'; export type Abs = { op: '->', a: x, b: o }; // \x. o export type Ap = { op: '$', a: F, b: x }; // F(x) export type Comp = { op: '.', a: F, b: G }; // F . G export type Id = Abs // \x. x export type Const = Abs> // \x. \y. x export type Inv = { op: 'inv', a: F } export namespace composition { export type Abstraction = Rewrite, v>, y>; export type Composition = Rewrite, x>, Ap>>; // Identity export type Identity = Rewrite, x>; export namespace proof { export interface Identity_Proof { type: 'rewrite'; left: Equation, x>, x>; // id(x) = x right: ChainRewrites<[ Abstraction, // x = x Refl, ], this['left']>; } export interface Identity_Composition_Proof { type: 'rewrite'; left: Equation, x>, Ap>; // (f . id)(x) = f(x) right: ChainRewrites<[ Composition, // f(id(x)) = f(x) Identity, // f(x) = f(x) Refl, ], this['left']>; } export type identity = [ assert>>, assert>>, ] } // Associativity export type Associativity = Rewrite< Comp, H>, Comp> > export namespace proof { export interface Assoc_Proof { type: 'rewrite'; left: Equation, H>, x>, Ap>, x>>; // ((f . g) . h)(x) = (f . (g . h))(x) right: ChainRewrites<[ Composition, H, x>, // (f . g)(h(x)) = (f . (g . h))(x) Composition>, // f(g(h(x))) = (f . (g . h))(x) Composition, x>, // f(g(h(x))) = f((g . h)(x)) Composition, // f(g(h(x))) = f(g(h(x))) Refl, ], this['left']>; } export type associativity = [ assert>>, ] } // Identity export type Transitivity = Rewrite, Abs>, Abs>; export namespace proof { export interface Transitivity_Proof { type: 'rewrite'; left: Equation, Abs>, x>, Ap, x>>; // ((\y -> z) . (\x -> y))(x) = (\x -> z)(x) right: ChainRewrites<[ Composition, Abs, x>, // (\y -> z) $ (\x -> y)(x) = (\x -> z)(x) Abstraction, // (\y -> z) $ y = (\x -> z)(x) Abstraction, // z = (\x -> z)(x) Abstraction, // z = z Refl, ], this['left']>; } export type transitivity = [ // OpToStr>>, assert>>, ] } // Inverse functions export type Inverse = Rewrite>, Abs>; export namespace proof { export interface Composition_Inverse_Proof { type: 'rewrite', known: { 'f': Equation>, 'g': Equation>, }, left: Equation>, Comp, Inv>>, // inv(f . g) = inv(g) . inv(f) right: ChainRewrites<[ SubstEq, SubstEq, // inv((\y -> z) . g) = inv(g) . inv(\y -> z) SubstEq, SubstEq, // inv((\y -> z) . (\x -> y)) = inv(\x -> y) . inv(\y -> z) Inverse<'x', 'y'>, Inverse<'y', 'z'>, // inv((\x -> y) . (\y -> z)) = (\z -> y) . (\y -> x) Transitivity<'x', 'y', 'z'>, // inv(\x -> z) = (\z -> y) . (\y -> x) Transitivity<'z', 'y', 'x'>, // inv(\x -> z) = \z -> x Inverse<'x', 'z'>, // \z -> x = \z -> x Refl ], this['left']>, } export type inverse = [ // OpToStr>>, assert>>, ] } }