A complete, production-ready implementation of the SAT Transformation Trace Format (STTF) v1.0 standard including:
- Core library for loading bundles and lifting models
- Replay engine for reconstructing simplified CNF
- Validation tools with CLI
- Bundle generation utilities
- 22 comprehensive tests (100% passing)
- Example bundles included
cd sttf
# Run everything (demo + tests + examples)
python3 demo.py
# Or step by step:
# 1. Run tests
python3 tests/test_sttf.py
# 2. Generate examples
python3 src/sttf_generate.py examples/test
# 3. Validate
python3 src/sttf_validate.py examples/test_simple --verbosefrom src.sttf_core import STTFBundle
# Load existing bundle
bundle = STTFBundle("examples/demo_simple")
# Inspect
print(f"Original: {bundle.manifest_data['original']['variables']} vars")
print(f"Simplified: {bundle.manifest_data['simplified']['variables']} vars")
print(f"Transform steps: {len(bundle.transform_steps)}")# Model for simplified CNF
model_simplified = {1: True, 2: False, 5: True}
# Lift to original
model_original = bundle.lift_model(model_simplified)
print(f"Lifted model: {model_original}")from src.sttf_replay import replay_bundle
# Replay transformation
formula = replay_bundle("examples/demo_simple")
# Check result
print(f"Clauses: {len(formula.clauses)}")
print(f"Variables: {formula.get_active_vars()}")from src.sttf_generate import STTFBundleGenerator
gen = STTFBundleGenerator("my_bundle")
# Set original formula
gen.set_original_cnf(
num_vars=5,
clauses=[[1, 2], [-1, 3], [4, 5]]
)
# Add transformations
gen.add_var_rename(1, 10)
gen.add_var_elim(5, "pure_literal")
gen.add_clause_remove(3, "subsumed")
# Write bundle
gen.write_bundle("my_preprocessor", "1.0")sttf/
├── src/
│ ├── sttf_core.py - Core: Expr, STTFBundle, model lifting
│ ├── sttf_replay.py - Replay engine
│ ├── sttf_validate.py - Validation CLI
│ └── sttf_generate.py - Bundle generator
├── tests/
│ └── test_sttf.py - 22 tests covering everything
├── examples/
│ ├── demo_simple/ - Simple example bundle
│ └── demo_complex/ - Complex example with substitutions
├── README.md - Full documentation
├── PROJECT_SUMMARY.md - Complete project overview
└── demo.py - Demonstration script
Every bundle has exactly 5 files:
bundle/
├── original.cnf # Original CNF (DIMACS)
├── simplified.cnf # Simplified CNF (DIMACS)
├── transform.log # Transformation steps
├── reconstruct.map # Reverse mapping
└── manifest.json # Metadata
7 Transformation Opcodes:
var_rename- Rename variablevar_elim- Eliminate variablevar_subst- Substitute with expressionclause_remove- Remove clauseclause_add- Add clauseclause_strengthen- Strengthen clauseunit_derive- Derive unit clause
4 Reverse Rules:
rev_map- Variable mappingrev_elim- Constant valuerev_elim_expr- Expression substitutionrev_clause_add- Added clause
Expression Support:
- Literals:
5,-3 - Operations:
NOT(),AND(),OR(),XOR() - Nested:
AND(OR(1, 2), NOT(3))
# Validate bundle
python3 src/sttf_validate.py bundle/
# Validate with verbose output
python3 src/sttf_validate.py bundle/ --verbose
# Validate with replay verification
python3 src/sttf_validate.py bundle/ --replay
# Generate examples
python3 src/sttf_generate.py output_dir/Use in your SAT preprocessor:
from src.sttf_generate import STTFBundleGenerator
class MyPreprocessor:
def __init__(self):
self.sttf = STTFBundleGenerator("output/bundle")
def preprocess(self, cnf):
# Set original
self.sttf.set_original_cnf(cnf.num_vars, cnf.clauses)
# Your preprocessing
for step in self.preprocessing_pipeline(cnf):
# Apply step
result = self.apply_step(step)
# Record in STTF
if isinstance(step, VarRename):
self.sttf.add_var_rename(step.old, step.new)
elif isinstance(step, VarElim):
self.sttf.add_var_elim(step.var, "pure_literal")
# ... etc
# Write STTF bundle
self.sttf.write_bundle("MyPreprocessor", "1.0")
return simplified_cnf✓ 22 tests, 100% passing
✓ All opcodes tested
✓ All reverse rules tested
✓ Expression evaluation tested
✓ Model lifting tested
✓ Replay engine tested
✓ End-to-end tested
Your bundles are STTF v1.0 compliant if:
- ✓
original.cnf + transform.logreproducessimplified.cnf - ✓ Models lift correctly from B → A
- ✓ All eliminated variables have reverse rules
- ✓ Only canonical opcodes used
- ✓ Grammar strictly followed
Verify with: python3 src/sttf_validate.py --replay
transform.log:
1 var_elim 4 pure_literal
2 clause_remove 4 pure_literal_clause
3 var_rename 3 5
reconstruct.map:
rev_elim 4 = false
rev_map 5 -> 3
- Read the docs: Check
README.mdfor complete API reference - Run the demo: Execute
python3 demo.pyfor full walkthrough - Explore examples: Look at
examples/demo_simple/andexamples/demo_complex/ - Run tests: Execute
python3 tests/test_sttf.pyto verify - Build bundles: Use
sttf_generate.pyto create your own
- Full specification: See original STTF document
- API docs:
README.md - Code examples:
demo.py - Test cases:
tests/test_sttf.py
Production Ready ✓
- All features implemented
- All tests passing
- Fully documented
- Ready to deploy
STTF v1.0 - Deterministic APIs for Hard Problems