https://github.com/aygp-dr/fixed-point-explorer
Y combinator and fixed-point recursion exploration across Scheme dialects with formal verification
https://github.com/aygp-dr/fixed-point-explorer
functional-programming recursion scheme y-combinator
Last synced: about 2 months ago
JSON representation
Y combinator and fixed-point recursion exploration across Scheme dialects with formal verification
- Host: GitHub
- URL: https://github.com/aygp-dr/fixed-point-explorer
- Owner: aygp-dr
- License: mit
- Created: 2025-07-21T13:40:33.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-07-23T20:38:46.000Z (8 months ago)
- Last Synced: 2025-10-31T00:40:22.341Z (5 months ago)
- Topics: functional-programming, recursion, scheme, y-combinator
- Language: Shell
- Size: 324 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+TITLE: Fixed Point Explorer
#+AUTHOR: jwalsh
[[https://img.shields.io/badge/Guile-3.0+-blue.svg][https://img.shields.io/badge/Guile-3.0+-blue.svg]]
[[https://img.shields.io/badge/Chez_Scheme-9.5+-green.svg][https://img.shields.io/badge/Chez_Scheme-9.5+-green.svg]]
[[https://img.shields.io/badge/Racket-8.0+-red.svg][https://img.shields.io/badge/Racket-8.0+-red.svg]]
[[https://img.shields.io/badge/License-MIT-yellow.svg][https://img.shields.io/badge/License-MIT-yellow.svg]]
[[https://img.shields.io/badge/Lean-4.21.0-blue.svg][https://img.shields.io/badge/Lean-4.21.0-blue.svg]]
[[https://img.shields.io/badge/Lake-5.0.0-green.svg][https://img.shields.io/badge/Lake-5.0.0-green.svg]]
[[https://img.shields.io/badge/Platform-FreeBSD_|_Linux_|_macOS-lightgrey.svg][https://img.shields.io/badge/Platform-FreeBSD_|_Linux_|_macOS-lightgrey.svg]]
* Overview
Fixed Point Explorer is a multi-implementation exploration of the Y combinator and fixed-point recursion patterns in Scheme. The project demonstrates how recursive functions can be built without explicit self-reference, using the Y combinator as a foundation.
[[file:docs/images/tshirt-design.png]]
* Features
- โจ Portable Y combinator implementation working across multiple Scheme dialects
- ๐ฏ Pure functional implementations of classic recursive algorithms
- ๐ง Support for GNU Guile, Chez Scheme, and Racket
- ๐ Performance benchmarks and comparisons
- ๐งช Comprehensive test suite with edge case coverage
- ๐ Literate programming approach with Org-mode
- ๐ Formal verification capabilities (Lean 4 support)
* Quick Start
** Prerequisites
Check that you have the required dependencies:
#+BEGIN_SRC bash
gmake deps
#+END_SRC
** Running Tests
#+BEGIN_SRC bash
# Run all tests
gmake test
# Run tests for specific implementation
gmake test-guile # Primary implementation
gmake test-chez
gmake test-racket
#+END_SRC
** Interactive REPL
#+BEGIN_SRC bash
# Start Guile REPL with project loaded
gmake repl-guile
# In the REPL, try:
(load "src/portable/fibonacci.scm")
(fib 10) ;; => 55
(test-fibonacci)
#+END_SRC
* Project Structure
#+BEGIN_EXAMPLE
fixed-point-explorer/
โโโ src/
โ โโโ portable/ # Cross-implementation code
โ โ โโโ y-combinator.scm
โ โ โโโ fibonacci.scm
โ โ โโโ list-ops.scm
โ โโโ guile/ # Guile-specific extensions
โ โโโ chez/ # Chez-specific optimizations
โ โโโ racket/ # Racket-specific typed versions
โโโ test/
โ โโโ test-framework.scm
โ โโโ integration/ # Cross-implementation tests
โโโ scripts/
โ โโโ deps.sh # Dependency checking
โ โโโ setup.sh # Tool installation
โโโ lib/geiser/ # Emacs integration
โโโ docs/ # Documentation
โโโ Makefile # Build automation
#+END_EXAMPLE
* Examples
** Basic Y Combinator Usage
#+BEGIN_SRC scheme
;; Load the Y combinator
(load "src/portable/y-combinator.scm")
;; Define a recursive function using Y combinator
(define CONTINUE-fact
(lambda (f)
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1)))))))
(define factorial (Y-explicit CONTINUE-fact))
(factorial 5) ;; => 120
#+END_SRC
** Fibonacci with Memoization
#+BEGIN_SRC scheme
(load "src/portable/fibonacci.scm")
;; Basic fibonacci
(fib 20) ;; => 6765
;; Memoized version for better performance
(define memo-fib (make-memoized-fib))
(memo-fib 100) ;; Computes quickly
#+END_SRC
** List Operations
#+BEGIN_SRC scheme
(load "src/portable/list-ops.scm")
;; All list operations implemented using Y combinator
(append-y '(1 2 3) '(4 5 6)) ;; => (1 2 3 4 5 6)
(map-y (lambda (x) (* x 2)) '(1 2 3)) ;; => (2 4 6)
(filter-y even? '(1 2 3 4 5 6)) ;; => (2 4 6)
(foldr-y + 0 '(1 2 3 4 5)) ;; => 15
#+END_SRC
* Theoretical Background
The Y combinator, discovered by Haskell Curry, enables recursion in languages that don't have built-in recursion. Its type signature is:
#+BEGIN_EXAMPLE
Y : โฮฑ. ((ฮฑ โ ฮฑ) โ (ฮฑ โ ฮฑ)) โ (ฮฑ โ ฮฑ)
#+END_EXAMPLE
This project explores practical applications of this theoretical construct across different Scheme implementations.
* Implementation Details
** Guile (Primary Implementation)
GNU Guile 3.0+ is the primary development platform. All portable code is tested first on Guile.
- Uses ~string-contains~ for implementation detection
- Supports performance timing with ~(ice-9 time)~
- Compatible with Geiser for interactive development
** Cross-Implementation Compatibility
The portable code avoids implementation-specific features:
- No ~format~ in core modules (for maximum compatibility)
- Simple list-based memoization instead of hash tables
- Explicit module loading with ~load~ instead of module systems
* Performance
Run benchmarks with:
#+BEGIN_SRC bash
gmake benchmark
#+END_SRC
Example output (times vary by system):
- Guile: ~fib(30)~ in ~0.8s
- Chez: ~fib(30)~ in ~0.3s
- Racket: ~fib(30)~ in ~1.2s
* Development
** Building from Source
1. Clone the repository
2. Tangle the literate source (if using ~SETUP.org~):
#+BEGIN_SRC bash
# In Emacs: C-c C-v t on SETUP.org
#+END_SRC
3. Run tests:
#+BEGIN_SRC bash
gmake test
#+END_SRC
** Contributing
1. Ensure all tests pass: ~gmake test~
2. Follow the existing code style
3. Add tests for new functionality
4. Update documentation as needed
* Formal Verification (Optional)
For formal verification with Lean 4:
#+BEGIN_SRC bash
# Install Lean 4 (FreeBSD with Linux compatibility)
gmake setup
# Or manual installation
gmake -f Makefile.lean lean-install
#+END_SRC
* License
This project is licensed under the MIT License. See [[file:LICENSE][LICENSE]] for details.
* Acknowledgments
- Y combinator theory from Haskell Curry's work on combinatory logic
- Inspired by "The Little Schemer" and SICP
- Scheme community for maintaining excellent implementations
* Resources
- [[https://en.wikipedia.org/wiki/Fixed-point_combinator][Fixed-point combinator (Wikipedia)]]
- [[file:SETUP.org][SETUP.org]] - Literate programming source
- [[file:docs/specs/types.org][Type Specifications]] - Formal type documentation
---
[[file:docs/images/repo-barcode.png]]