mirror of
https://github.com/blackboxprogramming/universal-computer.git
synced 2026-03-17 06:57:15 -05:00
sync: update from blackroad-operator 2026-03-14
Synced from BlackRoad-OS-Inc/blackroad-operator/orgs/personal/universal-computer BlackRoad OS — Pave Tomorrow. RoadChain-SHA2048: bffc821e1a7aeac9 RoadChain-Identity: alexa@sovereign RoadChain-Full: bffc821e1a7aeac96e44719f0638a80d936a875547213672cfeb4450b79950dd23dcf26fa83cd628919360efc018e6c73f2781aa7c74790d7161abc541bb1e1a98b37973be3327ab1ac8ca53449dea903653d3ec8ad93f87765f8c9cb46d1f7b4f4ca12bb3fc50fb8946695c028dda018c92ce28711935dbbea4dad40308b53941bbace858ec8b1238751a277fdc393ef4236088d50ff7b05fa96e291ca83e747625cf0284022f16ab99954b1732dca5ffa72bf47e9921ecf629fc93950ec6df4932f66fd1298fec6fa3d9978cecbffe6f231e66192a2b4fd283cd8adeb6ef34d2fc5eb22a4901104169beed0d60e18e8aba17ac5493c4daa1bbc961f2980a80
This commit is contained in:
106
README.md
106
README.md
@@ -1,75 +1,75 @@
|
||||
> ⚗️ **Research Repository**
|
||||
>
|
||||
> This is an experimental/research repository. Code here is exploratory and not production-ready.
|
||||
> For production systems, see [BlackRoad-OS](https://github.com/BlackRoad-OS).
|
||||
|
||||
---
|
||||
|
||||
# Universal Computer
|
||||
|
||||
[](https://github.com/blackboxprogramming/universal-computer/actions/workflows/ci.yml)
|
||||
[](https://python.org)
|
||||
[](LICENSE)
|
||||
This repository contains an implementation of a **universal Turing machine** in Python. A universal Turing machine is a theoretical device capable of simulating any other Turing machine. In other words, it can compute anything that is computable. The implementation here is simple and educational; it demonstrates the principles of universality and emulation in a compact form.
|
||||
|
||||
A universal Turing machine simulator in Python. Demonstrates the foundational concept of computability: a single machine that can simulate any other Turing machine.
|
||||
## Overview
|
||||
|
||||
## How It Works
|
||||
The core of the project is a Turing machine simulator that reads a description of another machine and an input tape, then executes that machine's transition function step by step. The simulator supports tapes of unbounded length in both directions and maintains a set of states, including a halting state. The universal machine itself accepts programs encoded as tables of transitions.
|
||||
|
||||
A Turing machine has a tape (infinite in both directions), a read/write head, a set of states, and a transition function. Given a state and the symbol under the head, the machine writes a new symbol, moves left/right/stay, and transitions to a new state. It halts when it reaches the halt state.
|
||||
### Features
|
||||
|
||||
This implementation uses:
|
||||
- **Dictionary-based tape** -- positions map to symbols, missing positions are blank
|
||||
- **JSON machine descriptions** -- portable, human-readable definitions
|
||||
- **Configurable step limit** -- prevents infinite loops
|
||||
- **Tape representation:** The tape is implemented as a Python dictionary mapping integer positions to symbols. Positions not present in the dictionary are assumed to hold a blank symbol (`'_'`).
|
||||
- **Transition function:** Each transition is a mapping from `(current_state, current_symbol)` to `(next_state, write_symbol, move_direction)`, where `move_direction` is `'L'`, `'R'`, or `'S'` (stay).
|
||||
- **Machine description format:** Machine descriptions are loaded from JSON files. A description includes the set of states, the input alphabet, the blank symbol, the transition function, the start state, and the halting state.
|
||||
- **Simulation:** The simulator runs the machine until it reaches the halting state or exceeds a configurable step limit. It yields the final tape contents and the number of steps executed.
|
||||
|
||||
## Usage
|
||||
### Running the simulator
|
||||
|
||||
```bash
|
||||
# Increment binary number: 1101 (13) -> 1110 (14)
|
||||
To use the universal Turing machine, first prepare a JSON file describing the machine you want to simulate (see `machines/` for examples), then run:
|
||||
|
||||
```
|
||||
python3 utm.py machines/your_machine.json --tape "your input tape here"
|
||||
```
|
||||
|
||||
For example, to run a binary incrementer:
|
||||
|
||||
```
|
||||
python3 utm.py machines/incrementer.json --tape "1101"
|
||||
|
||||
# Check parity
|
||||
python3 utm.py machines/even_odd.json --tape "1111"
|
||||
```
|
||||
|
||||
## Included Machines
|
||||
This will increment the binary number `1101` (13) to `1110` (14).
|
||||
|
||||
| Machine | File | Description |
|
||||
|---------|------|-------------|
|
||||
| Binary Incrementer | `incrementer.json` | Adds 1 to a binary number |
|
||||
| Even/Odd | `even_odd.json` | Determines parity of a unary number |
|
||||
## Directory structure
|
||||
|
||||
## Creating Your Own Machine
|
||||
- `utm.py` – the universal Turing machine simulator.
|
||||
- `machines/` – sample machine descriptions in JSON format.
|
||||
- `README.md` – this file.
|
||||
|
||||
```json
|
||||
{
|
||||
"states": ["q0", "q1", "halt"],
|
||||
"alphabet": ["0", "1"],
|
||||
"blank": "_",
|
||||
"transitions": {
|
||||
"q0:0": ["q0", "0", "R"],
|
||||
"q0:1": ["q1", "1", "R"],
|
||||
"q0:_": ["halt", "_", "S"]
|
||||
},
|
||||
"start": "q0",
|
||||
"halt": "halt"
|
||||
}
|
||||
```
|
||||
## Sample machines
|
||||
|
||||
Each transition key is `"state:symbol"` mapping to `[next_state, write_symbol, direction]` where direction is `L` (left), `R` (right), or `S` (stay).
|
||||
The repository includes a few sample machine descriptions:
|
||||
|
||||
## Development
|
||||
- `incrementer.json` – a machine that increments a binary number.
|
||||
- `even_odd.json` – a machine that decides whether a unary number has an even or odd number of symbols.
|
||||
|
||||
```bash
|
||||
pip install pytest
|
||||
pytest tests/ -v
|
||||
```
|
||||
|
||||
## Theory
|
||||
|
||||
Alan Turing proved in 1936 that a universal Turing machine can compute anything that any Turing machine can compute. Every computer is a physical realization of this idea.
|
||||
Feel free to add more machines to the `machines/` directory to explore the power of Turing machines!
|
||||
|
||||
## License
|
||||
|
||||
Proprietary -- BlackRoad OS, Inc.
|
||||
This project is released under the MIT License. See `LICENSE` for details.
|
||||
|
||||
## Related Projects
|
||||
---
|
||||
|
||||
| Project | Description |
|
||||
|---------|-------------|
|
||||
| [RoadC](https://github.com/blackboxprogramming/roadc) | Custom programming language |
|
||||
| [Quantum Math Lab](https://github.com/blackboxprogramming/quantum-math-lab) | Mathematical computation toolkit |
|
||||
| [Simulation Theory](https://github.com/blackboxprogramming/simulation-theory) | Physics and universe simulation |
|
||||
## 📜 License & Copyright
|
||||
|
||||
**Copyright © 2026 BlackRoad OS, Inc. All Rights Reserved.**
|
||||
|
||||
**CEO:** Alexa Amundson | **PROPRIETARY AND CONFIDENTIAL**
|
||||
|
||||
This software is NOT for commercial resale. Testing purposes only.
|
||||
|
||||
### 🏢 Enterprise Scale:
|
||||
- 30,000 AI Agents
|
||||
- 30,000 Human Employees
|
||||
- CEO: Alexa Amundson
|
||||
|
||||
**Contact:** blackroad.systems@gmail.com
|
||||
|
||||
See [LICENSE](LICENSE) for complete terms.
|
||||
|
||||
Reference in New Issue
Block a user