From 999c2314c0d649646a53e7cc440ae3f4aa1a3d61 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 12 Dec 2023 18:47:06 +0530 Subject: feat: commutativity + identity for multiplication --- src/index.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index a161134..4c3f114 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ -import { Add, Multiply, Succ, _0 } from './nat'; -import { Op, Rewrite, ChainRewrites, Flip, Equation, Refl } from './util'; +import { Add, Multiply, Succ, _0, _1, _3 } from './nat'; +import { Op, Rewrite, ChainRewrites, Flip, Equation, Refl, VerifyEquation, assert } from './util'; export namespace addition { export type Identity = Rewrite, A>; @@ -53,5 +53,53 @@ export namespace addition { Refl>>>, // true ], this['left']>; }; + + export namespace spec { + export type commutativity = [ + assert>>, + assert>>, + ] + + export type associativity = [ + assert>>, + assert>>, + ] + } +} + +export namespace multiplication { + export type Identity = Rewrite, A>; + export type IdentityR = Rewrite, A>; + + export type Mul_Add = Rewrite, B>, Add>>; + export type Mul_AddR = Rewrite>, Add>>; + + export type Commutativity = Rewrite, Multiply>; + export interface Comm_Base { + type: 'rewrite', + left: Equation, Multiply>; // 1 * b = b * 1 + right: ChainRewrites<[ + IdentityR, // b = b + 0 + Identity, // b = b + Refl, // true + ], this['left']>; + }; + export interface Comm_Inductive { + type: 'rewrite', + left: Equation, B>, Multiply>>; // succ(a)*b = b*succ(a) + right: ChainRewrites<[ + Mul_Add, // a + a*b = b*succ(a) + Mul_AddR, // a + a*b = a + b*a + Commutativity, // a + a*b = a + a*b + Refl>>, // true + ], this['left']>; + }; + + export namespace spec { + export type commutativity = [ + assert>>, + assert>>, + ] + } } -- cgit v1.3.1