|
| 1 | +# Lambda Calculus Interpreter |
| 2 | + |
| 3 | +This project implements a Lambda Calculus interpreter in Rust. It supports various operations and Church encodings for numbers and boolean values. |
| 4 | + |
| 5 | +## Supported Instructions |
| 6 | + |
| 7 | +The interpreter supports the following instructions and operations: |
| 8 | + |
| 9 | +1. **Basic Lambda Calculus** |
| 10 | + - Variable: `x`, `y`, `z`, etc. |
| 11 | + - Abstraction: `λx. <expression>` |
| 12 | + - Application: `(<expression> <expression>)` |
| 13 | + |
| 14 | +2. **Church Numerals** |
| 15 | + - Encoding: Automatically handled by the interpreter |
| 16 | + - Decoding: Automatically handled by the interpreter |
| 17 | + - Addition: `add` |
| 18 | + - Subtraction: `subtract` |
| 19 | + - Multiplication: `multiply` |
| 20 | + - Predecessor: `pred` |
| 21 | + - Successor: `succ` |
| 22 | + - Is Zero: `is_zero` |
| 23 | + |
| 24 | +3. **Church Booleans** |
| 25 | + - True: `true` (encoded as `λx. λy. x`) |
| 26 | + - False: `false` (encoded as `λx. λy. y`) |
| 27 | + - And: `and` |
| 28 | + - Or: `or` |
| 29 | + - Not: `not` |
| 30 | + |
| 31 | +4. **Control Flow** |
| 32 | + - If-Then-Else: `ifelse` |
| 33 | + |
| 34 | +5. **Pairs** |
| 35 | + - Create Pair: `pair` |
| 36 | + - First Element: `fst` |
| 37 | + - Second Element: `snd` |
| 38 | + |
| 39 | +6. **Recursion** |
| 40 | + - Y Combinator: `Y` |
| 41 | + |
| 42 | +## Usage Examples |
| 43 | + |
| 44 | +Here are some examples of how to use the interpreter: |
| 45 | + |
| 46 | +1. Church Numeral Addition: |
| 47 | + ``` |
| 48 | + (add (church_encode 2) (church_encode 3)) |
| 49 | + ``` |
| 50 | + |
| 51 | +2. Boolean Operations: |
| 52 | + ``` |
| 53 | + (and true false) |
| 54 | + (or true false) |
| 55 | + (not true) |
| 56 | + ``` |
| 57 | + |
| 58 | +3. Conditional Statement: |
| 59 | + ``` |
| 60 | + (ifelse (is_zero 0) 42 58) |
| 61 | + ``` |
| 62 | + |
| 63 | +4. Factorial using Y Combinator: |
| 64 | + ``` |
| 65 | + (Y (λf. λn. (ifelse (is_zero n) 1 (multiply n (f (pred n)))))) |
| 66 | + ``` |
| 67 | + |
| 68 | +## Running Tests |
| 69 | + |
| 70 | +To run the tests and see examples of the interpreter in action, use the following command: |
| 71 | + |
| 72 | +```rust |
| 73 | +$ cargo test |
| 74 | +``` |
0 commit comments