<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Law of Decomposition Verifier (Pro)</title>
<style>
/* Modern, clean UI */
body { font-family: 'Segoe UI', system-ui, sans-serif; background-color: #f0f2f5; color: #333; padding: 40px; }
.container { max-width: 1000px; margin: 0 auto; background: white; padding: 30px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.05); }
h1 { color: #2d3436; text-align: center; margin-bottom: 5px; }
.subtitle { text-align: center; color: #636e72; margin-bottom: 30px; font-style: italic; }
.input-group { display: flex; gap: 20px; justify-content: center; margin-bottom: 30px; background: #fafafa; padding: 20px; border-radius: 8px; border: 1px solid #eee; }
.field { display: flex; flex-direction: column; }
label { font-weight: bold; font-size: 0.9em; margin-bottom: 5px; color: #0984e3; }
input { padding: 10px; font-size: 1.1em; border: 1px solid #dfe6e9; border-radius: 4px; width: 120px; font-family: monospace; }
button { background: #0984e3; color: white; border: none; padding: 10px 30px; border-radius: 4px; font-size: 1.1em; cursor: pointer; height: 45px; align-self: flex-end; transition: 0.2s; }
button:hover { background: #0769b5; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
.card { border: 1px solid #e1e1e1; border-radius: 8px; padding: 20px; background: #fff; }
.card h3 { margin-top: 0; color: #2d3436; border-bottom: 2px solid #fdcb6e; display: inline-block; padding-bottom: 5px; }
.val { font-family: monospace; word-break: break-all; color: #444; background: #f1f2f6; padding: 5px; border-radius: 4px; }
#verdict { text-align: center; margin-top: 30px; padding: 15px; border-radius: 8px; font-weight: bold; font-size: 1.4em; display: none; }
.pass { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
</style>
</head>
<body>
<div class="container">
<h1>Power Decomposition Verifier</h1>
<p class="subtitle">Verifying the preservation of structural kernels under exponentiation</p>
<div class="input-group">
<div class="field"><label>Integer (n)</label><input type="text" id="n" value="12"></div>
<div class="field"><label>Base (b)</label><input type="text" id="b" value="6"></div>
<div class="field"><label>Exponent (k)</label><input type="text" id="k" value="3"></div>
<button onclick="runVerification()">Verify</button>
</div>
<div id="results" style="display:none;">
<div class="grid">
<div class="card">
<h3>The Kernel Law</h3>
<p>Does <strong>K(n<sup>k</sup>)</strong> equal <strong>K(n)<sup>k</sup></strong>?</p>
<p>LHS: <span class="val" id="k-lhs"></span></p>
<p>RHS: <span class="val" id="k-rhs"></span></p>
</div>
<div class="card">
<h3>The Power Law</h3>
<p>Does <strong>P(n<sup>k</sup>)</strong> equal <strong>P(n)<sup>k</sup></strong>?</p>
<p>LHS: <span class="val" id="p-lhs"></span></p>
<p>RHS: <span class="val" id="p-rhs"></span></p>
</div>
</div>
<div id="verdict"></div>
</div>
</div>
<script>
// --- OPTIMIZED MATH ENGINE ---
// 1. Better Factorization (Skips even numbers)
function getPrimeFactors(num) {
let n = BigInt(num);
const factors = new Set();
if (n < 2n) return [];
// Handle 2 separately to allow skipping evens
if (n % 2n === 0n) {
factors.add(2n);
while (n % 2n === 0n) n /= 2n;
}
// Loop odd numbers only
let d = 3n;
while (d * d <= n) {
if (n % d === 0n) {
factors.add(d);
while (n % d === 0n) n /= d;
}
d += 2n;
}
if (n > 1n) factors.add(n);
return Array.from(factors);
}
// 2. Optimized Kernel (Takes pre-calculated factors)
function getKernelWithFactors(n, factors) {
if (n === 0n) return 0n;
let kernel = n;
for (const f of factors) {
while (kernel % f === 0n) kernel /= f;
}
return kernel;
}
// 3. Optimized Power
function getPowerWithFactors(n, n_kernel) {
if (n === 0n) return 1n;
return n / n_kernel;
}
function fmt(n) {
return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
function runVerification() {
try {
const n = BigInt(document.getElementById('n').value);
const b = BigInt(document.getElementById('b').value);
const k = BigInt(document.getElementById('k').value);
if (b < 2n) throw new Error("Base b must be > 1");
// Step 1: Pre-calculate B factors ONCE
const b_factors = getPrimeFactors(b);
// Step 2: Calculate Powers
const n_k = n ** k;
// --- KERNEL LAW ---
// LHS: K(n^k)
const k_lhs = getKernelWithFactors(n_k, b_factors);
// RHS: K(n)^k
const k_n = getKernelWithFactors(n, b_factors);
const k_rhs = k_n ** k;
// --- POWER LAW ---
// LHS: P(n^k)
const p_lhs = getPowerWithFactors(n_k, k_lhs);
// RHS: P(n)^k
const p_n = getPowerWithFactors(n, k_n);
const p_rhs = p_n ** k;
// Display
document.getElementById('k-lhs').textContent = fmt(k_lhs);
document.getElementById('k-rhs').textContent = fmt(k_rhs);
document.getElementById('p-lhs').textContent = fmt(p_lhs);
document.getElementById('p-rhs').textContent = fmt(p_rhs);
const v = document.getElementById('verdict');
v.style.display = 'block';
document.getElementById('results').style.display = 'block';
if (k_lhs === k_rhs && p_lhs === p_rhs) {
v.textContent = "VERIFIED: Structural Integrity Maintained";
v.className = "pass";
} else {
v.textContent = "ERROR: Calculation Failed (Logic Error)";
v.style.background = "#ffcccc";
}
} catch (e) {
alert(e.message);
}
}
</script>
</body>
</html>