A mathematical framework for analyzing moral judgment errors through an analogy with the Riemann Hypothesis in number theory.
This project introduces the Ethical Riemann Hypothesis (ERH). It posits that in a "healthy" moral judgment system, the cumulative error in predicting critical misjudgments grows at most like
-
Ethical Primes (
$P$ ): Critical misjudgments representing fundamental errors. -
$\Pi(x)$ : The count of ethical primes up to complexity$x$ . -
$E(x) = \Pi(x) - B(x)$ : The error term comparing the actual count vs. the baseline expectation. -
The ERH Condition:
$|E(x)| \leq C \cdot x^{1/2 + \epsilon}$ for healthy judgment systems.
| Number Theory Concept | Ethical Judgment Analogy |
|---|---|
| Prime Numbers | Ethical Primes (Critical Misjudgments) |
|
|
|
| Prime Number Theorem | Baseline Expectation$B(x)$ |
| Riemann Hypothesis | Ethical Riemann Hypothesis (Bounds on error growth) |
Below are visualizations generated by the framework, showcasing the distribution of ethical primes and the behavior of the error term.
| Zeta Function Analysis | Error Distribution |
|---|---|
![]() |
![]() |
| Prime Counting Function$\Pi(x)$ | Critical Line Analysis |
|---|---|
![]() |
![]() |
Architecture: erh_core is the Single Source of Truth for core logic. The backend (erh-security-app) installs the root package in editable mode (-e ../..) to use the latest core. simulation and erh re-export from erh_core when available. V(a) proxies: HuggingFaceEthicalOracle (toxicity→ethical score), GroundTruthProxy.load_from_csv() (empirical data), OracleDrivenJudge (CSV-first, Oracle fallback). Pipeline: run_simulation_batch --mode judge|abm, run_phase_transition_exp.py, run_full_pipeline.sh. Use FULL=1 ./scripts/run_full_pipeline.sh to include generate_all_figures. Verification: python scripts/run_verification_phase4.py [--full].
Ethic-Latex/
├── erh_core/ # Single Source of Truth (canonical core)
│ ├── core/ # Core modules (shared by simulation/ and erh/)
│ │ ├── action_space.py # Action and world generation
│ │ ├── judgement_system.py # Judge implementations
│ │ └── ethical_primes.py # Prime selection and analysis
│ └── analysis/ # Analysis tools (shared)
│ ├── erh_checks.py # ERH bound checking
│ ├── statistics.py # Statistical analysis
│ └── zeta_function.py # Ethical zeta function
├── simulation/ # Python simulation framework (research/experiments)
│ ├── models.py # Pydantic models (Action, Judgment)
│ ├── core/ # Re-exports from erh_core (backward compatibility)
│ ├── analysis/ # Re-exports from erh_core + simulation-specific
│ │ └── fairness_metrics.py # Simulation-specific fairness analysis
│ ├── quantum/ # Quantum oracle (optional qiskit; NumPy fallback)
│ │ ├── interface.py # QuantumOracle interface
│ │ ├── simulator.py # LocalQuantumJudge (local/NumPy)
│ │ └── cloud.py # CloudQuantumJudge (IBM Quantum Runtime)
│ ├── adversarial.py # AdversarialAgent for red-team testing
│ ├── visualization/ # Plotting utilities
│ │ └── plots.py # All visualization functions
│ ├── notebooks/ # Jupyter notebooks for experiments
│ │ ├── 01_basic_simulation.ipynb
│ │ ├── 02_judge_comparison.ipynb
│ │ └── ... (other analysis notebooks)
│ ├── api/ # FastAPI endpoints
│ ├── real_data/ # Real-world case studies (Adult, Exam Cheating, Sexual Abuse, COMPAS)
│ └── output/ # Generated figures and data
├── erh/ # Python SDK package (for distribution)
│ ├── core/ # Re-exports from erh_core (backward compatibility)
│ ├── analysis/ # Re-exports from erh_core
│ ├── client.py # SDK client interface
│ └── tools/ # SDK tools and adapters
├── scripts/ # Utility scripts
│ ├── fetch_real_data.sh # Fetch Adult, COMPAS, UCI Student Performance
│ ├── convert_adult_to_csv.py # Adult → data/adult.csv
│ ├── process_student_to_exam_cheating.py # UCI Student → data/exam_cheating_cases.csv
│ └── generate_synthetic_sexual_abuse.py # Fallback → data/sexual_abuse_cases.csv
├── docs/ # Documentation files
├── tests/ # Test files
├── ethical_riemann_hypothesis.tex # Main research paper (LaTeX)
└── requirements.txt # Python dependencies
- Python: 3.10 or later
- LaTeX Distribution: (Optional, for compiling the paper)
# Clone the repository
git clone <repository-url>
cd Ethic-Latex
# Recommended: use the install script (creates .venv and installs deps)
bash scripts/install_dependencies.sh
# Then: source .venv/bin/activate (or .venv\Scripts\activate on Windows)
# Or install manually (use a virtual environment)
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txtOptional: for quantum cloud backend, set IBM_QUANTUM_TOKEN in .env (see .env.example). The quantum module works without it (local/NumPy fallback).
To compile the research paper, you need a LaTeX distribution installed.
macOS (Homebrew):
# Minimal (~100MB): BasicTeX
brew install --cask basictex
# Full (~4GB): MacTeX (includes all fonts/packages)
# brew install --cask mactexAfter installing BasicTeX, open a new terminal or run eval "$(/usr/libexec/path_helper -s)" so pdflatex is on PATH.
Linux: sudo apt-get install texlive-full latexmk (Ubuntu/Debian)
Windows: Install MiKTeX.
Then compile:
# Using the provided script (checks for pdflatex, prefers latexmk)
bash scripts/compile_latex.sh
# Or manually (single main file)
pdflatex ethical_riemann_hypothesis.tex
bibtex ethical_riemann_hypothesis
pdflatex ethical_riemann_hypothesis.texfrom simulation.core import generate_world, BiasedJudge, evaluate_judgement
from simulation.core import select_ethical_primes, compute_Pi_and_error
from simulation.visualization import plot_Pi_B_E
# 1. Generate moral action space
actions = generate_world(num_actions=1000, complexity_dist='zipf')
# 2. Create and apply a judgment system
judge = BiasedJudge(bias_strength=0.2, noise_scale=0.1)
evaluate_judgement(actions, judge, tau=0.3)
# 3. Extract ethical primes (critical errors)
primes = select_ethical_primes(actions, importance_quantile=0.9)
# 4. Compute and plot error distribution
Pi_x, B_x, E_x, x_vals = compute_Pi_and_error(primes, X_max=100)
plot_Pi_B_E(x_vals, Pi_x, B_x, E_x)bash scripts/start_jupyter.shStart with simulation/notebooks/01_basic_simulation.ipynb for an introduction.
# Judge mode (default): ERH analysis with BiasedJudge, parallel instances
python scripts/run_simulation_batch.py --instances 4 --output-dir results
# ABM mode: Agent-Based Model with multiprocessing
python scripts/run_simulation_batch.py --mode abm --agents 50 --steps 100 --trials 4 --output simulation/output/batch_results.json- Judge mode: Uses
generate_world,BiasedJudge,select_ethical_primes, etc. Outputs per-instance JSON in--output-dir. - ABM mode: Uses
ABMSimulator; aggregates results to--output(default:simulation/output/batch_results.json).
from simulation.quantum import LocalQuantumJudge
from simulation.adversarial import AdversarialAgent
# Quantum oracle (local or NumPy fallback if qiskit unavailable)
quantum_judge = LocalQuantumJudge()
# Use in place of BiasedJudge for quantum-backed judgments
# Red-team agent to stress-test ERH bound
agent = AdversarialAgent(n_actions=500)
agent.run(max_steps=100)To run real-data case studies (adult_income_case_study, exam_cheating_case_study, sexual_abuse_case_study, compas_case_study), fetch and prepare datasets:
# 1. Download all datasets (Adult, COMPAS, UCI Student Performance)
bash scripts/fetch_real_data.sh
# 2. Convert and process to case-study CSV schema
python scripts/convert_adult_to_csv.py
python scripts/process_student_to_exam_cheating.py # UCI Student Performance → exam cheating proxy
python scripts/generate_synthetic_sexual_abuse.py # Fallback when no public case-level sourceExpected outputs:
data/adult.csv– Adult Income (from UCI adult.data/test)data/exam_cheating_cases.csv– Exam cheating proxy (from UCI Student Performance)data/sexual_abuse_cases.csv– Sexual abuse reporting (synthetic fallback)data/compas-scores-two-years.csv– COMPAS (from ProPublica GitHub)
Then run:
python -m simulation.real_data.adult_income_case_study
python -m simulation.real_data.exam_cheating_case_study
python -m simulation.real_data.sexual_abuse_case_study
python -m simulation.real_data.compas_case_study # or run_compas_alphaCI workflow: The build_thesis_gated.yml pipeline fetches and processes these CSV files on every run before executing case studies.
- 🚀 Streamlit Cloud (Recommended - 5 minutes): Push to GitHub, then deploy via the Streamlit website.
- 📓 Binder (For Notebooks - 2 minutes): Deploy your notebooks for live access.
- 🐳 Docker (Any Platform):
docker build -t erh-app .
docker run -p 8501:8501 erh-app streamlit run simulation/app.pySee docs/CLOUD_DEPLOYMENT.md for detailed guides.
Subject: Analysis of Structural Misjudgment in GitLab DevSecOps Pipelines
This design document outlines a Proof of Concept (PoC) applying the ERH framework to quantify how systematic and fatal security misjudgments accumulate as project complexity increases within a DevSecOps pipeline.
| Category | Description |
|---|---|
| Core Problem | Quantify the rate at which "truly fatal security misjudgments" (structural misjudgments) accumulate as the complexity of project changes grows. |
| Hypothesis | Can we use an ERH-style metric to quantify thisStructural Risk Growth? |
| Scope | GitLab Merge Request security review pipeline (using SAST/DAST results and post-merge incident data as proxies for ground truth). |
| ERH Concept | Security Context Mapping |
|---|---|
| Action ( |
Defined as asecurity decision event for a single Merge Request (MR). |
| Complexity ($c(a)$) | A composite metric of MR size and scope:$c(a) = \text{norm}(\log(1 + \text{lines_changed}) + \lambda \cdot \text{files_changed} + \dots)$ |
| True Value ($V(a)$) |
Ground Truth. |
| Judgment System ($J(a)$) |
Pipeline Judge ( |
| Error ($\Delta(a)$) |
|
| Ethical Prime ( |
ACritical Misjudgment ( |
| Column | Type | Description |
|---|---|---|
action_id |
PK (MR ID) | Unique identifier for the decision event |
lines_added |
int | Complexity factor |
files_changed |
int | Complexity factor |
services_touched |
string[] | Subsystems affected (via path mapping) |
merged_at |
timestamp | Time of merge (nullable) |
| Column | Type | Description |
|---|---|---|
action_id |
FK | Link to MR |
V |
float [-1, 1] | True Value (Post-merge security impact) |
has_post\_incident |
bool | Flag for incident discovery within observation window |
unresolved\_high |
bool | True if merged with unmitigated high/critical issues |
| Column | Type | Description |
|---|---|---|
action_id |
FK | Link to MR |
c |
float | NormalizedComplexity |
delta |
float |
|
is_prime |
bool | Flag indicating anEthical Prime |
-
Preprocessing: Ingest GitLab API data (MRs, security reports) and calculate
$c(a)$ ,$V(a)$ ,$w(a)$ ,$J(a)$ , and prime marking for all actions. - ERH-style Metrics: Compute the following for each judge:
| Metric | Formula | Description |
|---|---|---|
| Mistake Rate (MR) | Overall misjudgment frequency. | |
| Prime Count |
Count of primes where$c(a) \leq x$. | Cumulative critical error count by complexity. |
| Error Growth |
Fit$ | E(x) |
-
Interpretation: Check if
$\alpha$ satisfies the ERH-style boundary.$\alpha \approx 0.5$ implies Riemann-healthy system with controlled risk growth.$\alpha \geq 1$ implies systematic degradation.
The following table is a placeholder to be filled with simulation results.
| Judge Type | Exponent$\alpha$ | ERH Satisfied? | Growth Rate Interpretation |
|---|---|---|---|
| Biased | TBD | TBD | -- |
| Noisy | TBD | TBD | -- |
| Conservative | TBD | TBD | Low risk, potentially high friction ( |
| Radical | TBD | TBD | High risk accumulation, systematic failure ( |
- Simulation Framework: See
simulation/README.md - CI/Workflows:
build_thesis_gated.ymlruns simulation → quantum tests → thesis build;simulation.ymlfetches real data and empirical sources (HuggingFace, AITA, GitHub PR);build_thesis.ymlfetches and processes case-study CSV before running Adult/Exam Cheating/Sexual Abuse case studies. - Installation Guide: See
docs/INSTALL.md(includes venv and optional qiskit/quantum setup) - Theory: See
ethical_riemann_hypothesis.tex - Tests:
pytest tests/(includestest_quantum_entanglement.py, psychohistory integration)
The ERH framework provides:
-
Quantitative Criterion: AI systems should satisfy
$|E(x)| = O(\sqrt{x})$ . - Bias Detection: Violations of ERH indicate systematic failures.
- Fairness Analysis: Ethical primes highlight critical errors on vulnerable groups.
- Real-world case studies: Adult Income, Exam Cheating (UCI Student Performance), Sexual Abuse (synthetic fallback), COMPAS;
scripts/fetch_real_data.shfetches public sources;scripts/process_student_to_exam_cheating.pymaps UCI data to exam-cheating schema;scripts/calculate_alpha_comparison.pycompares real vs simulated α. - Quantum judgment: Optional
simulation/quantum/(local simulator or IBM Quantum); NumPy fallback when qiskit is unavailable. - Health monitor: E(x) vs Riemann bound monitoring (see
erh-security-appbackend/analysis/healthand frontend). - Adversarial agent:
simulation/adversarial.pyfor red-team testing (maximizing ethical-prime discovery).
- Apply the framework to more real-world AI systems (e.g., content moderation).
- Develop theoretical proofs for ERH boundary conditions.
- Explore connections to causal inference.
If you use this framework in your research, please cite:
@article{ethical_riemann_hypothesis,
title={The Ethical Riemann Hypothesis: A Mathematical Framework for Analyzing Moral Judgment Errors},
author={[Author Name]},
journal={[To be completed]},
year={2025}
}This project is licensed under the MIT License.
Contributions, suggestions, and discussions are welcome.
Contact: admin@dennisleehappy.org



