// Application 1: Combinatorial Fault Isolation // Assign DSS weights to test factors. When a test fails, the aggregate // signal (sum of active factor weights) reveals the interaction ORDER // (2-way, 3-way, etc.) without enumerating all subsets. import { computeGreedySequence, isDSS, cardinalityFromSum, buildCardinalityTable } from './greedy.mjs'; export function runFaultIsolationDemo() { console.log('='.repeat(70)); console.log(' FAULT ISOLATION via DSS WEIGHTS'); console.log(' Erdos-Straus Greedy Sequence Application'); console.log('='.repeat(70)); console.log(); const NUM_FACTORS = 12; const weights = computeGreedySequence(NUM_FACTORS); console.log(`Test system with ${NUM_FACTORS} factors.`); console.log(`DSS weights assigned: [${weights.join(', ')}]`); console.log(`Max weight: ${weights[weights.length - 1]} (fits in ${Math.ceil(Math.log2(weights[weights.length - 1] + 1))} bits)`); console.log(); const factorNames = [ 'Auth', 'Database', 'Cache', 'Network', 'FileIO', 'Scheduler', 'Parser', 'Serializer', 'Logger', 'Config', 'Metrics', 'Queue' ]; // Simulate failing test scenarios const scenarios = [ { name: '2-way interaction', factors: [1, 4] }, // Database + Network { name: '3-way interaction', factors: [0, 2, 5] }, // Auth + Cache + Scheduler { name: '4-way interaction', factors: [3, 6, 7, 9] }, // Network + Parser + Serializer + Config { name: '1-way (single fault)', factors: [8] }, // Logger alone { name: '5-way interaction', factors: [0, 1, 3, 7, 11] }, ]; const table = buildCardinalityTable(weights); console.log('SCENARIO ANALYSIS:'); console.log('-'.repeat(70)); for (const scenario of scenarios) { const activeWeights = scenario.factors.map(i => weights[i]); const observedSum = activeWeights.reduce((a, b) => a + b, 0); const detectedCardinality = table.get(observedSum); const activeNames = scenario.factors.map(i => factorNames[i]); console.log(`\n Scenario: ${scenario.name}`); console.log(` Active factors: [${activeNames.join(', ')}]`); console.log(` Weights: [${activeWeights.join(' + ')}] = ${observedSum}`); console.log(` DSS Oracle says: "${detectedCardinality}-way interaction"`); console.log(` Correct: ${detectedCardinality === scenario.factors.length ? 'YES' : 'NO'}`); // Show the search space reduction const totalSubsets = (1 << NUM_FACTORS) - 1; const subsetsOfSameCard = comb(NUM_FACTORS, detectedCardinality); const reduction = ((1 - subsetsOfSameCard / totalSubsets) * 100).toFixed(1); console.log(` Search space: ${totalSubsets} subsets -> ${subsetsOfSameCard} (${reduction}% reduction)`); } console.log('\n' + '-'.repeat(70)); console.log('\nKEY INSIGHT: From a SINGLE aggregate number, the DSS property'); console.log('reveals the interaction order. No enumeration needed.'); console.log('Traditional fault isolation: O(2^n). With DSS oracle: O(C(n,k)).'); console.log(); return { weights, scenarios, table }; } function comb(n, k) { if (k > n) return 0; if (k === 0 || k === n) return 1; let result = 1; for (let i = 0; i < k; i++) { result = result * (n - i) / (i + 1); } return Math.round(result); }