From f724285d1d3cea85128069bcdf04e4c6af9c7a39 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 10 Dec 2023 17:33:01 +0530 Subject: adds associativity for a=0 --- src/index.ts | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index bd93300..5164412 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,41 +1,30 @@ -export type Op = string | { op: string; a: Op; b: Op }; +import { Op, Rewrite, ChainRewrites, Flip } from './util'; -export type Rewrite = { - type: 'rewrite'; - left: left; - right: right; -}; -export type RewriteKind = Rewrite; - -export type Flip = Rewrite; - -export type ApplyRewrite = - O extends R['left'] ? R['right'] - : O extends string ? O - : O extends { a: Op, b: Op, op: string } ? ( - ApplyRewrite extends O['a'] - ? Omit & { b: ApplyRewrite } - : Omit & { a: ApplyRewrite } - ) - : never; - -export type Add = { op: '+'; a: a; b: b }; +export type Add = { op: '+'; a: A; b: B }; export type Identity = Rewrite, A>; export type Commutativity = Rewrite, Add>; -// type _x = ApplyRewrite, Identity<'0'>>; - -// type Assoc = +export interface Assoc0 { + type: 'rewrite', + left: Add, B>; + right: ChainRewrites<[ + Commutativity<'0', A>, + Identity, + Flip>>, + Commutativity, '0'>, + ], this['left']>; +}; /* - Assoc: (a + b) + c = a + (b + c) For a = 0, (0 + b) + c -= b + c -= 0 + (b + c) += (b + 0) + c -- comm += b + c -- id += (b + c) + 0 -- flip id += 0 + (b + c) -- comm For a = succ(), -- cgit v1.3.1