# ahmedmhedhbii/tree-evaluation architecture

> Architecture diagram of the GitHub repository ahmedmhedhbii/tree-evaluation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmedmhedhbii/tree-evaluation
- Repository: https://github.com/ahmedmhedhbii/tree-evaluation
- Video tour (about a minute): https://gitdiagram.com/ahmedmhedhbii/tree-evaluation/video

## Overview

This repository implements a space-efficient evaluation algorithm for complete binary trees, with both C++ and Python versions. In the C++ command-line workflow, a user supplies the tree height, alphabet, function table, and leaf values; initialization builds the finite field and register state, the clean computation evaluates the root, and a naive evaluator checks the result before it is printed. The recursive algorithm uses forward and inverse register computations and polynomial terms. The Python implementation is a standalone alternative. The graph reflects the shown C++ calls and documented Python capability; it does not infer links between the two implementations.

Main entry points: [`src/main.cpp`](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/main.cpp) (CLI Entry), [`src/algorithm.cpp`](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp) (Forward Recursion), [`proto/tree.py`](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/proto/tree.py) (Python Implementation), [`src/galois_field.cpp`](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/galois_field.cpp) (Field Arithmetic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["C++ Command Line"]
  node_main["CLI Entry<br/>[main.cpp]"]
  node_result["Printed Result<br/>[main.cpp]"]
end

subgraph group_algorithm["Tree Evaluation"]
  node_input["Parameter Input<br/>[algorithm.cpp]"]
  node_field_init["Field Setup<br/>[algorithm.cpp]"]
  node_clean["Clean Computation<br/>[algorithm.cpp]"]
  node_forward["Forward Recursion<br/>[algorithm.cpp]"]
  node_inverse["Inverse Recursion<br/>[algorithm.cpp]"]
  node_polynomial["Polynomial Terms<br/>[algorithm.cpp]"]
  node_naive["Naive Evaluation<br/>[algorithm.cpp]"]
end

subgraph group_field["Finite Field"]
  node_field_ops["Field Arithmetic<br/>[galois_field.cpp]"]
  node_field_types["Field Representation<br/>[galois_field.hpp]"]
end

subgraph group_python["Python Alternative"]
  node_python_impl["Python Implementation<br/>[tree.py]"]
end

node_user(("User"))

node_user -->|"starts"| node_main
node_main -->|"initializes parameters"| node_input
node_input -->|"creates field"| node_field_init
node_field_init -->|"constructs"| node_field_types
node_input -->|"creates field elements"| node_field_ops
node_main -->|"runs"| node_clean
node_clean -->|"invokes"| node_forward
node_forward -->|"invokes"| node_inverse
node_inverse -->|"invokes"| node_forward
node_forward -->|"computes terms"| node_polynomial
node_inverse -->|"computes terms"| node_polynomial
node_main -->|"checks result"| node_naive
node_main -->|"prints"| node_result
node_python_impl -.->|"offers standalone workflow"| node_python_impl

click node_main "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/main.cpp"
click node_input "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp"
click node_field_init "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp"
click node_clean "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp"
click node_forward "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp"
click node_inverse "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp"
click node_polynomial "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp"
click node_naive "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp"
click node_field_ops "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/galois_field.cpp"
click node_field_types "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/include/galois_field.hpp"
click node_result "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/main.cpp"
click node_python_impl "https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/proto/tree.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_result,node_user toneBlue
class node_input,node_field_init,node_clean,node_forward,node_inverse,node_polynomial,node_naive toneAmber
class node_field_ops,node_field_types toneMint
class node_python_impl toneRose
```

## Components

### C++ Command Line

- [CLI Entry](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/main.cpp): `src/main.cpp`
- [Printed Result](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/main.cpp): `src/main.cpp`

### Tree Evaluation

- [Parameter Input](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp): `src/algorithm.cpp`
- [Field Setup](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp): `src/algorithm.cpp`
- [Clean Computation](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp): `src/algorithm.cpp`
- [Forward Recursion](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp): `src/algorithm.cpp`
- [Inverse Recursion](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp): `src/algorithm.cpp`
- [Polynomial Terms](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp): `src/algorithm.cpp`
- [Naive Evaluation](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/algorithm.cpp): `src/algorithm.cpp`

### Finite Field

- [Field Arithmetic](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/src/galois_field.cpp): `src/galois_field.cpp`
- [Field Representation](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/include/galois_field.hpp): `include/galois_field.hpp`

### Python Alternative

- [Python Implementation](https://github.com/ahmedmhedhbii/tree-evaluation/blob/main/proto/tree.py): `proto/tree.py`

### Other components

- **User**

## Connections

- User → CLI Entry: starts (evidence: `README.md`)
- CLI Entry → Parameter Input: initializes parameters (evidence: `src/main.cpp`)
- Parameter Input → Field Setup: creates field (evidence: `src/algorithm.cpp`)
- Field Setup → Field Representation: constructs (evidence: `src/algorithm.cpp`)
- Parameter Input → Field Arithmetic: creates field elements (evidence: `src/algorithm.cpp`)
- CLI Entry → Clean Computation: runs (evidence: `src/main.cpp`)
- Clean Computation → Forward Recursion: invokes (evidence: `src/algorithm.cpp`)
- Forward Recursion → Inverse Recursion: invokes (evidence: `src/algorithm.cpp`)
- Inverse Recursion → Forward Recursion: invokes (evidence: `src/algorithm.cpp`)
- Forward Recursion → Polynomial Terms: computes terms (evidence: `src/algorithm.cpp`)
- Inverse Recursion → Polynomial Terms: computes terms (evidence: `src/algorithm.cpp`)
- CLI Entry → Naive Evaluation: checks result (evidence: `src/main.cpp`)
- CLI Entry → Printed Result: prints (evidence: `src/main.cpp`)
- Python Implementation → Python Implementation: offers standalone workflow (evidence: `README.md`)
