Axiomatic Reasoning for LLMs

Implementation Plan on C++

1. Introduction

Deep Coding is a methodology based on four principles: structural specification, generative conformance, recursive refinement with fixed premises, and skeleton‑tissue architecture. This document provides a technical translation of these principles into concrete C++ implementations, focusing on what is possible today (C++17/20) and near future (C++26). All philosophical framing is replaced with engineering constructs.

2. Core Principle Mapping

Deep Coding Principle C++ Technical Realization
Structural specification (interface constraints) C++20 Concepts, requires clauses, pure abstract base classes
Generative conformance Template metaprogramming (specialization, recursive instantiation)
Skeleton–tissue (static) CRTP, Policy‑Based Design
Skeleton–tissue (dynamic) Non‑Virtual Interface (NVI) idiom + private virtual functions
Physical boundary for specifications C++20 Modules (.ixx / .cppm)
Fixed premises (phase checkpoints) Git tags + CMake CODEGEN target isolation
Recursive refinement Incremental builds, add_custom_command with dependency tracking

3. Structural Specification Representation

A hybrid approach is required because C++ lacks a single standard “specification as code” mechanism.

4. Code Generation Strategies

Strategy Timing Overhead Use Case
Template metaprogramming compile‑time zero Type‑level generation, static polymorphism
Clang LibTooling build‑time (pre‑compile) build time AST analysis, code transformation, spec extraction
External generators build‑time (pre‑compile) build time JSON Schema → C++ classes, OpenAPI → client/server
C++26 reflection compile‑time zero Future: standardised code splicing from specs
LLM‑assisted development time human‑in‑loop Rapid prototyping with validation gates

Recommendation: Use TMP for type‑safe, zero‑overhead generation. Use external generators for data model and API binding code. Prepare for C++26 reflection to replace most external generators.

5. Skeleton‑Tissue Architecture in C++

Pattern Skeleton Role Tissue Role Overhead ABI Stability
NVI + Template Method public non‑virtual I/F + pre/post processing private virtual implementations virtual call (minor) medium
CRTP template base class (static_cast<Derived>) derived class zero high
Pimpl + public I/F opaque pointer only hidden implementation class one indirection very high
Policy‑Based host template class independent policy classes zero high
Abstract base + virtual pure virtual interface derived class virtual call low

Guideline:

6. Build System Integration (CMake)

7. Legacy Code Migration Strategy (Strangler Fig Pattern)

Phase Focus Technical Actions
1 Assessment Run Clang‑Tidy (modernize-*), extract header dependency graph, select pilot module.
2 Pilot module Reverse‑engineer structural specification from headers (Clang LibTooling + manual validation). Generate implementation from spec. Build adapter/wrapper for legacy boundary.
3 Gradual expansion New features implemented with Deep Coding. Replace legacy modules one by one, keeping both implementations until cut‑over.
4 Full standardisation Entire codebase on Deep Coding. CMake + code generation unified. CI/CD gates (compilation, architecture tests).

Tools: clang-modules-converter, importizer, Clang‑Tidy, CodeCompass, AI‑assisted spec inference (e.g., OOPS framework).

8. Implementation Roadmap

Phase Duration Deliverable
0 – Infrastructure 1‑2 weeks CMake 3.31+, compiler with C++20 modules, Git worktree training.
1 – Structural specification 2‑3 weeks JSON Schema / OpenAPI definitions for a pilot module. Code generation pipeline (Avrotize or GTAD).
2 – Skeleton‑tissue patterns 2‑3 weeks Base classes using NVI or CRTP. Tissue generation from specification. Validation tests.
3 – Build integration 1‑2 weeks CMake CODEGEN target, module dependency management, incremental generation.
4 – Legacy migration (iterative) 2‑6 months per codebase Strangler Fig replacement, adapter generation, CI/CD gates.

9. Constraints and Risk Mitigation

Constraint / Risk Mitigation
No standard ABI guarantee Use Pimpl or extern "C" wrappers for stable boundaries.
Compile‑time explosion from TMP Limit TMP to small, hot paths. Use external generators for large data models.
LLM‑generated code may contain UB Mandatory static analysis (Clang‑Tidy, UBSan) in validation gate.
C++20 module compiler differences Test with at least GCC, Clang, MSVC. Prefer header‑based fallback for critical paths.
Team learning curve Start with pilot module, document patterns, conduct internal workshops.
Build time increase Use ccache, incremental builds, and CODEGEN target separation.

10. Conclusion

Deep Coding is implementable in C++ today using a hybrid of template metaprogramming, C++20 Modules, Concepts, NVI/CRTP/Pimpl patterns, and CMake‑integrated code generation. C++26 reflection will further reduce external tool dependencies. The methodology is particularly suited for performance‑critical systems, libraries, and large monorepos. Legacy codebases can adopt Deep Coding incrementally via the Strangler Fig pattern without a big‑bang rewrite.

This plan provides a concrete, actionable technical foundation. No philosophical axioms are required; only engineering decisions grounded in existing C++ standards and tooling.