mcard-js
Version:
MCard - Content-addressable storage with cryptographic hashing, handle resolution, and vector search for Node.js and browsers
104 lines • 3.64 kB
TypeScript
/**
* Lambda Runtime - PTR Runtime for Lambda Calculus
*
* Implements α-β-η conversions as a PTR runtime, treating MCard hashes
* as Lambda terms and performing computations that produce new MCards.
*
* This runtime can be used via CLM specifications to define and verify
* Lambda Calculus reductions.
*
* @module mcard-js/ptr/lambda/LambdaRuntime
*/
import { Runtime } from '../node/RuntimeInterface';
import { CardCollection } from '../../model/CardCollection';
import { ReductionStrategy } from './BetaReduction';
import { IOEffectsConfig } from './IOEffects';
export type LambdaOperation = 'alpha' | 'beta' | 'eta-reduce' | 'eta-expand' | 'normalize' | 'step' | 'alpha-equiv' | 'eta-equiv' | 'alpha-norm' | 'eta-norm' | 'free-vars' | 'is-closed' | 'is-normal' | 'parse' | 'pretty' | 'build' | 'check-readiness' | 'num-add' | 'num-sub' | 'num-mul' | 'num-div' | 'http-request' | 'church-to-int';
export interface LambdaConfig {
operation?: LambdaOperation;
process?: LambdaOperation;
action?: LambdaOperation;
strategy?: ReductionStrategy;
maxSteps?: number;
maxTimeMs?: number;
newName?: string;
freshVar?: string;
compareWith?: string;
io_effects?: Partial<IOEffectsConfig>;
}
export interface LambdaRuntimeResult {
success: boolean;
result?: unknown;
error?: string;
termHash?: string;
prettyPrint?: string;
}
/**
* Lambda Calculus Runtime for PTR
*
* Executes Lambda Calculus operations on MCard-stored terms.
*/
export declare class LambdaRuntime implements Runtime {
private collection;
constructor(collection: CardCollection);
/**
* Execute a Lambda operation
*
* @param codeOrPath - For Lambda runtime, this is the term hash to operate on
* @param context - Additional context (varies by operation)
* @param config - Lambda configuration with operation type
* @param chapterDir - Chapter directory (used for relative paths if needed)
*/
execute(codeOrPath: string, context: unknown, config: any, chapterDir: string): Promise<LambdaRuntimeResult>;
private doAlphaRename;
private doBetaReduce;
private doEtaReduce;
private doEtaExpand;
private doNormalize;
private doStep;
private doAlphaEquiv;
private doEtaEquiv;
private doAlphaNormalize;
private doEtaNormalize;
private doFreeVars;
private doIsClosed;
private doIsNormal;
private doParse;
private doPretty;
private doBuild;
/**
* Decode a Church numeral to a regular integer.
* Church numeral n = λf.λx.f^n(x) where f is applied n times.
*
* Algorithm:
* 1. Normalize the term first
* 2. Expect form: Abs(f, Abs(x, body))
* 3. Count how many times 'f' appears in application position in body
*/
private doChurchToInt;
/**
* Count applications in a Church numeral body.
* Church numeral n has the form: λf.λx.f(f(f(...f(x)...)))
* where f appears n times.
*/
private countChurchApplications;
private doCheckReadiness;
private doNumericOp;
private doHttpRequest;
}
/**
* Parse a simple Lambda expression string into MCards
*
* Syntax:
* x, y, z - Variables
* \x.M or λx.M - Abstraction
* (M N) - Application
* M N - Application (left-associative)
*
* Examples:
* \x.x - Identity function
* \f.\x.f x - Application combinator
* (\x.x) y - Identity applied to y
*/
export declare function parseLambdaExpression(collection: CardCollection, expression: string): Promise<string>;
//# sourceMappingURL=LambdaRuntime.d.ts.map