# owieczka/lambda-calculus-python architecture

> Architecture diagram of the GitHub repository owieczka/lambda-calculus-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/owieczka/lambda-calculus-python
- Repository: https://github.com/owieczka/lambda-calculus-python

## Overview

This project is essentially a Python library that implements various lambda calculus constructs – a domain-specific “language” embedded in Python. Its core purpose is to define and manipulate fundamental data types (booleans, natural numbers, arithmetic operations, signed numbers, lists, pairs, rationals, etc.) all expressed in lambda calculus form. It even demonstrates recursion via constructs like the Y combinator and includes examples (e.g., Fibonacci, division) as well as sample prime number experiments.

##### Main Components
- Core Lambda Calculus Library: Represented by the “lambdacalculus” directory. This component is divided into several modules:
- bool.py: Implements Boolean operations.
- natural.py: Implements natural numbers (with ZERO, ONE, TWO, SUCC, PRED, etc.).
- aritmetic.py: Contains more advanced arithmetic operations.
- combinators.py: Defines combinators that underpin recursive and higher-order functions (including the Y combinator).
- integer.py, signed.py, list.py, pair.py, rational.py: Additional modules that offer respective abstractions.
- Sample Application/Usage Scripts:
- primes_sierve.py and primes_sierve_v2.py: These scripts act as demonstrative applications that likely use the library’s functions to compute primes or perform related tasks.
- Testing Suite:
- The “tests” directory includes unit tests for each functional module, verifying the correctness of individual components.

##### Relationships and Interactions
- The Core Lambda Calculus Library (in “lambdacalculus”) is at the heart of the system. Each module in this directory plays a role in representing an aspect of lambda calculus – think of them as building blocks, where some modules (like combinators) are utilized by others (for recursion or function manipulation).
- The sample applications (primes_sierve files) are consumers of the core library. They use its functions to perform higher-level computations (e.g., generating primes).
- The tests provide coverage and validation for all these individual components and ensure that interactions (e.g., conversions between different representations or the execution of combinators) work as expected.

##### Architectural Patterns and Technologies
- Modular design: The project neatly separates each lambda calculus concept into its own module.
- Usage of Functional Programming Patterns: The project exemplifies the use of functions as first-class citizens, higher-order functions, and recursion (using the Y combinator pattern).
- Test-Driven Approach: The presence of comprehensive tests indicates an emphasis on validating each component, reinforcing the modular and reusable nature of the library.
- Example-Driven Documentation: The README provides inline examples (e.g., definitions of ZERO, ONE, SUCC, and PRED) to illustrate usage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Lambda Calculus Library"
        bool["Boolean Operations"]:::module
        natural["Natural Numbers"]:::module
        aritmetic["Arithmetic Operations"]:::module
        combinators["Combinators"]:::module
        integer["Integer Operations"]:::module
        signed["Signed Numbers"]:::module
        list_ops["List Operations"]:::module
        pair["Pair Operations"]:::module
        rational["Rational Numbers"]:::module
    end

    subgraph "Sample Applications"
        app1["Primes Example 1"]:::app
        app2["Primes Example 2"]:::app
    end

    subgraph "Testing Suite"
        tests["Testing Suite"]:::test
    end

    %% Relationships: Sample Applications calling Library Modules
    app1 -->|"calls_functions"| bool
    app1 -->|"calls_functions"| natural
    app1 -->|"calls_functions"| aritmetic
    app1 -->|"calls_functions"| combinators
    app1 -->|"calls_functions"| integer
    app1 -->|"calls_functions"| signed
    app1 -->|"calls_functions"| list_ops
    app1 -->|"calls_functions"| pair
    app1 -->|"calls_functions"| rational

    app2 -->|"calls_functions"| bool
    app2 -->|"calls_functions"| natural
    app2 -->|"calls_functions"| aritmetic
    app2 -->|"calls_functions"| combinators
    app2 -->|"calls_functions"| integer
    app2 -->|"calls_functions"| signed
    app2 -->|"calls_functions"| list_ops
    app2 -->|"calls_functions"| pair
    app2 -->|"calls_functions"| rational

    %% Relationships: Testing Suite validating Library Modules
    tests -->|"validates"| bool
    tests -->|"validates"| natural
    tests -->|"validates"| aritmetic
    tests -->|"validates"| combinators
    tests -->|"validates"| integer
    tests -->|"validates"| signed
    tests -->|"validates"| list_ops
    tests -->|"validates"| pair
    tests -->|"validates"| rational

    %% Styling for clarity
    classDef module fill:#ffdead,stroke:#8b4513,stroke-width:2px;
    classDef app fill:#98fb98,stroke:#2e8b57,stroke-width:2px;
    classDef test fill:#add8e6,stroke:#00008b,stroke-dasharray: 5 5,stroke-width:2px;

    %% Click Events for Lambda Calculus Library Modules
    click bool "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/bool.py"
    click natural "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/natural.py"
    click aritmetic "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/aritmetic.py"
    click combinators "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/combinators.py"
    click integer "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/integer.py"
    click signed "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/signed.py"
    click list_ops "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/list.py"
    click pair "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/pair.py"
    click rational "https://github.com/owieczka/lambda-calculus-python/blob/main/lambdacalculus/rational.py"

    %% Click Events for Sample Applications
    click app1 "https://github.com/owieczka/lambda-calculus-python/blob/main/primes_sierve.py"
    click app2 "https://github.com/owieczka/lambda-calculus-python/blob/main/primes_sierve_v2.py"

    %% Click Event for Testing Suite
    click tests "https://github.com/owieczka/lambda-calculus-python/tree/main/tests"
```
