Back to Experiments

Code Structure Convergence via Gating Mechanisms

Hypothesis

Code structure optimisation using gating mechanisms converges to a stable configuration. Multi-gate conflicts are best resolved without projection (direct selection). Deterministic gates outperform learnable gates on a per-input basis. The convergence score \(S\) reaches 0 when the structure stabilises.

Method

  1. Multi-gate conflict: Three code transformation gates (inline, unroll, vectorise) compete for the same code region. Test three conflict resolution strategies: no-projection (winner-take-all), cosine projection, and equal blend.
  2. Deterministic vs learnable: Compare fixed threshold gates (\(g = \mathbb{1}[\text{cost} < \tau]\)) against learned sigmoid gates (\(g = \sigma(w \cdot \text{features} + b)\)) on 100 code snippets.
  3. Code structure convergence: Three code decisions \(d_1, d_2, d_3 \in \{0, 1\}\) controlling inline/no-inline, unroll/no-unroll, vectorise/no-vectorise. Optimise for total execution cost. Track \(S\) and cost over 100 steps.

Results

Multi-Gate Conflict Resolution

StrategyFinal CostGate StabilityConvergence Steps
No projection (winner-take-all)11.81.00023
Cosine projection12.40.94141
Equal blend13.10.87267

No-projection (winner-take-all) is optimal for gate conflict: when transformations are mutually exclusive, blending their effects is worse than selecting the best one.

Deterministic vs Learnable Gates

Gate TypePer-Input AccuracyMean CostVariance
Deterministic (threshold)91/10012.31.41
Learnable (sigmoid)84/10012.82.17

Deterministic gates win on per-input accuracy (91% vs 84%) because the gate decision is binary and the optimal threshold is sharp. Learnable gates introduce unnecessary smoothness near the decision boundary.

Code Structure Convergence Trace

Step\(d_1\) (inline)\(d_2\) (unroll)\(d_3\) (vectorise)Cost\(S\)
011014.250.412
510013.800.318
1000113.100.241
2000112.500.142
3000112.150.067
4000112.020.018
5000112.000.000
6000112.000.000

The structure converges to \(d_1 = 0, d_2 = 0, d_3 = 1\) (vectorise only) with cost 14.25 → 12.0 and \(S \to 0\) at step 50.

Convergence Interpretation

DecisionInitialFinalReason
\(d_1\) (inline)1 (on)0 (off)Inlining increases code size, hurting cache
\(d_2\) (unroll)1 (on)0 (off)Unrolling redundant given vectorisation
\(d_3\) (vectorise)0 (off)1 (on)Vectorisation provides the largest speedup

Analysis

  • Multi-gate conflicts in code optimisation are best resolved by selection, not blending. This differs from continuous optimisation where projection helps. The discrete nature of code transformations makes winner-take-all optimal.
  • Deterministic gates outperform learnable gates per-input because the decision boundary in code optimisation is sharp (a loop either benefits from unrolling or it does not). Learned gates add unnecessary smoothness.
  • The convergence trace shows clear structure discovery: the system identifies that vectorisation alone is optimal and deactivates conflicting transformations.
  • \(S = 0\) at step 50 indicates complete structural convergence: no further changes are beneficial.

Conclusion

Theorem 8 is validated. Code structure converges to a stable configuration via gating mechanisms. The optimal conflict resolution for discrete code transformations is selection (no projection). Deterministic gates outperform learnable gates per-input. \(S \to 0\) correctly signals structural convergence.

Reproducibility

../simplex/build/sxc exp_code_gates.sx -o build/exp_code_gates.ll

OPENSSL_PREFIX=$(brew --prefix openssl)
clang -O2 build/exp_code_gates.ll \
  ../simplex/runtime/standalone_runtime.c \
  -o build/exp_code_gates \
  -lm -lssl -lcrypto -L${OPENSSL_PREFIX}/lib

./build/exp_code_gates

Related Theorems