feat: improve reduction algorithm with LIFO-based iterator #15
Reference in New Issue
Block a user
Delete Branch "feat/lifo-improvements"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
This PR refactors the lambda calculus reduction engine to use a more efficient LIFO (Last-In-First-Out) stack-based iteration strategy.
Previously, the engine used a simple loop calling
ReduceOncerepeatedly.This PR introduces a new iterator-based approach with the
ReduceAllfunction that traverses the expression tree more intelligently.Changes include:
pkg/lifopackage implementing a generic LIFO stack data structure.pkg/lambda/iterator.gowith anIteratortype for traversing lambda expressions.pkg/lambda/reduce.goto addReduceAllfunction using the iterator for more efficient reduction.internal/engine/engine.goto useReduceAllinstead of loopingReduceOnce..txtto.testextension..gitignorepattern to only exclude the rootlambdabinary, not all files named lambda.Makefileto reference renamed test files and add silent flag to run target.Decisions
ReduceOnceandReduceAllfunctions to maintain backward compatibility and provide flexibility.Performance
Benchmark results comparing main branch vs this PR on Apple M3:
Summary: Most benchmarks show significant improvements in both speed and memory usage.
The Church benchmark shows a regression that needs investigation.
Benefits
Checklist
<type>/<description>). Always use underscores.