From 6f31fc62f9a6ee77d71c5f5fe352e027f495ae9a Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Fri, 15 Dec 2023 22:06:30 +0530 Subject: feat: equation proofs (substitution + transitivity) --- src/util.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/util.ts') diff --git a/src/util.ts b/src/util.ts index c78c12c..da6d637 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,14 @@ -export type Op = string | { op: string; a: Op; b: Op }; +type COp = { op: string; a: Op; b: Op } +export type Op = string | COp; + +export type OpToStr = + O extends string + ? O + : O extends { op: string, a: infer a extends string, b: infer b extends string } ? `(${a} ${O['op']} ${b})` + : O extends { op: string, a: infer a extends COp, b: infer b extends string } ? `(${OpToStr} ${O['op']} ${b})` + : O extends { op: string, a: infer a extends string, b: infer b extends COp } ? `(${a} ${O['op']} ${OpToStr})` + : O extends { op: string, a: infer a extends COp, b: infer b extends COp } ? `(${OpToStr} ${O['op']} ${OpToStr})` + : never; type RwType = 'rewrite' | 'imperative'; @@ -6,6 +16,7 @@ export interface RewriteBase { type: RwType; left: Op; right: Op; + assume?: Record; } export interface Rewrite extends RewriteBase { @@ -15,6 +26,7 @@ export interface Rewrite = Rewrite; +export type Subst = Rewrite export type ApplyRewrite = R['type'] extends 'imperative' ? (R & { left: O })['right'] @@ -40,6 +52,7 @@ export type VerifyEquation = export type Evaluate = ApplyRewrite; export type assert = T; +export type assertFalse = T; export type Eq = ([a] extends [b] ? ([b] extends [a] ? true : false & { lhs: a; rhs: b }) : false & { lhs: a; rhs: b }); export type Equation = { op: '=', a: A, b: B }; -- cgit v1.3.1