Lambda Calculus Evaluator - Problem
Implement a lambda calculus evaluator that can parse and evaluate lambda expressions with variable binding, function application, and beta reduction.
Lambda calculus is a formal system for expressing computation based on function abstraction and application. Your evaluator should handle:
- Variables:
x,y,z, etc. - Lambda abstractions:
\x.body(function definition) - Function applications:
(f x)(applying function f to argument x) - Beta reduction:
(\x.body arg)→body[x := arg]
The input expression will be a valid lambda calculus expression as a string. Return the fully reduced expression as a string.
Input & Output
Example 1 — Simple Application
$
Input:
(\x.x y)
›
Output:
y
💡 Note:
Apply identity function \x.x to y: substitute x with y in body x, result is y
Example 2 — Nested Lambda
$
Input:
(\x.\y.x y z)
›
Output:
z
💡 Note:
Apply \x.\y.x to y and z: first substitute x with y getting \y.y, then apply to z getting z
Example 3 — No Reduction
$
Input:
\x.x
›
Output:
\x.x
💡 Note:
Identity function with no application, no beta reduction possible
Constraints
- 1 ≤ expression.length ≤ 1000
- Expression contains only valid lambda calculus syntax
- Variables are single lowercase letters
- Expressions are well-formed and parenthesized correctly
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code