# foreverhaibara/triple-sos architecture

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

- Interactive diagram: https://gitdiagram.com/foreverhaibara/triple-sos
- Repository: https://github.com/foreverhaibara/triple-sos

## Overview

Triples accepts polynomial inequalities through a Python API or a GUI, parses and models the problem, then searches for a readable SOS certificate. The documented proof search applies symbolic transformations or invokes StructuralSOS, LinearSOS, or SDPSOS; numerical LP/SDP results are rationalized into exact proofs. The graph preserves these solver branches and the SDP backend layer. Some relationships are based on README descriptions and the source index; unsampled modules are represented only where documented capabilities support them.

Main entry points: [`triples/core/dispatch.py`](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/dispatch.py) (Solver dispatch), [`web_main.py`](https://github.com/foreverhaibara/triple-sos/blob/main/web_main.py) (GUI server), [`gradio.app.py`](https://github.com/foreverhaibara/triple-sos/blob/main/gradio.app.py) (Gradio app), [`triples/core/node.py`](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/node.py) (Proof tree)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interfaces"]
  node_gui["GUI server<br/>[web_main.py]"]
  node_gradio["Gradio app<br/>[gradio.app.py]"]
  node_parser["Text parser<br/>[text_process.py]"]
  node_manager["GUI manager<br/>[sos_manager.py]"]
end

subgraph group_proof["Proof search"]
  node_api["SOS API<br/>[sum_of_squares.py]"]
  node_problem["Inequality model<br/>[problem.py]"]
  node_tree["Proof tree<br/>[node.py]"]
  node_preprocess["Problem transforms"]
  node_dispatch["Solver dispatch<br/>[dispatch.py]"]
  node_solution["Proof result<br/>[solution.py]"]
end

subgraph group_solvers["SOS solvers"]
  node_structural["Structural SOS"]
  node_linear["Linear SOS<br/>[linsos.py]"]
  node_sosdp["SDP SOS<br/>[sdpsos.py]"]
end

subgraph group_sdp["SDP engine"]
  node_sdpmodel["SDP formulation<br/>[dual.py]"]
  node_backend["Solver backends<br/>[caller.py]"]
  node_rationalize["Exact rationalization<br/>[rationalize.py]"]
end

node_user(("User"))

node_user -->|"enters inequality"| node_gui
node_user -->|"enters inequality"| node_gradio
node_user -->|"submits expression"| node_api
node_gui -->|"parses input"| node_parser
node_gradio -->|"parses input"| node_parser
node_gui -->|"uses"| node_manager
node_gradio -->|"uses"| node_manager
node_manager -->|"solves problem"| node_api
node_api -->|"models input"| node_problem
node_problem -->|"creates proof search"| node_tree
node_tree -->|"transforms subgoals"| node_preprocess
node_tree -->|"selects solver"| node_dispatch
node_dispatch -->|"invokes"| node_structural
node_dispatch -->|"invokes"| node_linear
node_dispatch -->|"invokes"| node_sosdp
node_linear -->|"returns certificate"| node_solution
node_sosdp -->|"builds SDP"| node_sdpmodel
node_sdpmodel -->|"solves program"| node_backend
node_backend -->|"rationalizes result"| node_rationalize
node_sosdp -->|"returns certificate"| node_solution
node_structural -.->|"returns certificate"| node_solution

click node_gui "https://github.com/foreverhaibara/triple-sos/blob/main/web_main.py"
click node_gradio "https://github.com/foreverhaibara/triple-sos/blob/main/gradio.app.py"
click node_parser "https://github.com/foreverhaibara/triple-sos/blob/main/triples/utils/text_process.py"
click node_manager "https://github.com/foreverhaibara/triple-sos/blob/main/triples/gui/sos_manager.py"
click node_api "https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/sum_of_squares.py"
click node_problem "https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/problem.py"
click node_tree "https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/node.py"
click node_preprocess "https://github.com/foreverhaibara/triple-sos/tree/main/triples/core/preprocess"
click node_dispatch "https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/dispatch.py"
click node_structural "https://github.com/foreverhaibara/triple-sos/tree/main/triples/core/structsos"
click node_linear "https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/linsos/linsos.py"
click node_sosdp "https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/sdpsos/sdpsos.py"
click node_solution "https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/solution.py"
click node_sdpmodel "https://github.com/foreverhaibara/triple-sos/blob/main/triples/sdp/dual.py"
click node_backend "https://github.com/foreverhaibara/triple-sos/blob/main/triples/sdp/backends/caller.py"
click node_rationalize "https://github.com/foreverhaibara/triple-sos/blob/main/triples/sdp/rationalize.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_gui,node_gradio,node_parser,node_manager,node_user toneBlue
class node_api,node_problem,node_tree,node_preprocess,node_dispatch,node_solution toneAmber
class node_structural,node_linear,node_sosdp toneMint
class node_sdpmodel,node_backend,node_rationalize toneRose
```

## Components

### User interfaces

- [GUI server](https://github.com/foreverhaibara/triple-sos/blob/main/web_main.py): `web_main.py`
- [Gradio app](https://github.com/foreverhaibara/triple-sos/blob/main/gradio.app.py): `gradio.app.py`
- [Text parser](https://github.com/foreverhaibara/triple-sos/blob/main/triples/utils/text_process.py): `triples/utils/text_process.py`
- [GUI manager](https://github.com/foreverhaibara/triple-sos/blob/main/triples/gui/sos_manager.py): `triples/gui/sos_manager.py`

### Proof search

- [SOS API](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/sum_of_squares.py): `triples/core/sum_of_squares.py`
- [Inequality model](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/problem.py): `triples/core/problem.py`
- [Proof tree](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/node.py): `triples/core/node.py`
- [Problem transforms](https://github.com/foreverhaibara/triple-sos/tree/main/triples/core/preprocess): `triples/core/preprocess`
- [Solver dispatch](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/dispatch.py): `triples/core/dispatch.py`
- [Proof result](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/solution.py): `triples/core/solution.py`

### SOS solvers

- [Structural SOS](https://github.com/foreverhaibara/triple-sos/tree/main/triples/core/structsos): `triples/core/structsos`
- [Linear SOS](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/linsos/linsos.py): `triples/core/linsos/linsos.py`
- [SDP SOS](https://github.com/foreverhaibara/triple-sos/blob/main/triples/core/sdpsos/sdpsos.py): `triples/core/sdpsos/sdpsos.py`

### SDP engine

- [SDP formulation](https://github.com/foreverhaibara/triple-sos/blob/main/triples/sdp/dual.py): `triples/sdp/dual.py`
- [Solver backends](https://github.com/foreverhaibara/triple-sos/blob/main/triples/sdp/backends/caller.py): `triples/sdp/backends/caller.py`
- [Exact rationalization](https://github.com/foreverhaibara/triple-sos/blob/main/triples/sdp/rationalize.py): `triples/sdp/rationalize.py`

### Other components

- **User**

## Connections

- User → GUI server: enters inequality
- User → Gradio app: enters inequality
- User → SOS API: submits expression
- GUI server → Text parser: parses input (evidence: `web_main.py`)
- Gradio app → Text parser: parses input (evidence: `gradio.app.py`)
- GUI server → GUI manager: uses (evidence: `web_main.py`)
- Gradio app → GUI manager: uses (evidence: `gradio.app.py`)
- GUI manager → SOS API: solves problem (evidence: `triples/gui/sos_manager.py`)
- SOS API → Inequality model: models input (evidence: `triples/core/__init__.py`)
- Inequality model → Proof tree: creates proof search (evidence: `triples/core/problem.py`)
- Proof tree → Problem transforms: transforms subgoals (evidence: `triples/core/node.py`)
- Proof tree → Solver dispatch: selects solver
- Solver dispatch → Structural SOS: invokes (evidence: `triples/core/dispatch.py`)
- Solver dispatch → Linear SOS: invokes (evidence: `triples/core/dispatch.py`)
- Solver dispatch → SDP SOS: invokes (evidence: `triples/core/dispatch.py`)
- Linear SOS → Proof result: returns certificate (evidence: `triples/core/linsos/linsos.py`)
- SDP SOS → SDP formulation: builds SDP (evidence: `triples/core/sdpsos/sdpsos.py`)
- SDP formulation → Solver backends: solves program (evidence: `triples/sdp/dual.py`)
- Solver backends → Exact rationalization: rationalizes result
- SDP SOS → Proof result: returns certificate (evidence: `triples/core/sdpsos/sdpsos.py`)
- Structural SOS → Proof result: returns certificate
