snapkitty
agents
idris2
lean4
File size: 3,335 Bytes
1cdfc83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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);
}