enver's picture
Publish Rootformer-Code v25 vs Qwen4-35B-A3B live interactive HTML5/SVG Showcase Space
84b4733 verified
Raw History Blame Contribute Delete
28.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rootformer-Code v25 vs Qwen4-35B-A3B — Live Interactive Demo Studio</title>
<style>
:root {
--bg: #070b14;
--panel: #0e1628;
--panel2: #121d34;
--border: rgba(148, 163, 184, 0.18);
--text: #e2e8f0;
--muted: #94a3b8;
--accent: #38bdf8;
--accent2: #818cf8;
--green: #34d399;
--amber: #fbbf24;
--rose: #fb7185;
}
* { box-sizing: border-box; }
body {
margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
background: radial-gradient(circle at 15% 0%, #102042 0%, var(--bg) 45%);
color: var(--text); min-height: 100vh;
}
.wrap { max-width: 1520px; margin: 0 auto; padding: 20px 20px 44px; }
header {
display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
padding: 18px 22px; background: rgba(14, 22, 40, 0.85); border: 1px solid var(--border);
border-radius: 16px; backdrop-filter: blur(12px); margin-bottom: 18px;
}
h1 { margin: 0 0 6px; font-size: 1.38rem; letter-spacing: -0.02em; }
.sub { color: var(--muted); font-size: 0.9rem; margin: 0; }
.links { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 10px;
font-size: 0.85rem; font-weight: 600; text-decoration: none; cursor: pointer; border: 1px solid var(--border);
background: var(--panel2); color: var(--text); transition: 0.15s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, #2563eb, #4f46e5); border-color: transparent; color: #fff; }
.kpis {
display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px;
}
.kpi {
background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
}
.kpi .lbl { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.kpi .val { font-size: 1.45rem; font-weight: 700; margin: 4px 0 2px; color: #fff; }
.kpi .note { font-size: 0.8rem; color: var(--green); }
.tabs {
display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; justify-content: space-between;
}
.tab-group { display: flex; flex-wrap: wrap; gap: 8px; }
.tab {
padding: 10px 15px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border);
color: var(--muted); font-weight: 600; font-size: 0.88rem; cursor: pointer; transition: 0.15s ease;
}
.tab:hover { color: #fff; border-color: rgba(56,189,248,0.45); }
.tab.active {
background: linear-gradient(135deg, rgba(56,189,248,0.2), rgba(129,140,248,0.22));
border-color: var(--accent); color: #fff;
}
.pane { display: none; }
.pane.active { display: block; }
.desc-bar {
display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
padding: 12px 16px; margin-bottom: 14px; font-size: 0.88rem; color: var(--muted);
}
.desc-bar strong { color: #fff; }
.split {
display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px;
}
@media (max-width: 1024px) { .split { grid-template-columns: 1fr; } }
.card {
background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
display: flex; flex-direction: column;
}
.card-head {
display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
padding: 11px 14px; background: var(--panel2); border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 8px; }
.pill {
font-size: 0.74rem; padding: 3px 8px; border-radius: 999px; font-weight: 700;
}
.pill-ours { background: rgba(52,211,153,0.16); color: var(--green); border: 1px solid rgba(52,211,153,0.35); }
.pill-q4 { background: rgba(129,140,248,0.16); color: #a5b4fc; border: 1px solid rgba(129,140,248,0.35); }
.pill-win { background: rgba(251,191,36,0.16); color: var(--amber); border: 1px solid rgba(251,191,36,0.35); }
.card-actions { display: flex; gap: 8px; align-items: center; }
.mini-link {
font-size: 0.78rem; color: var(--accent); text-decoration: none; font-weight: 600;
padding: 4px 8px; border-radius: 7px; background: rgba(56,189,248,0.1);
}
.mini-link:hover { background: rgba(56,189,248,0.22); }
iframe {
width: 100%; height: 640px; border: 0; background: #050811; display: block;
}
.table-wrap {
background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow-x: auto; margin-bottom: 18px;
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: var(--panel2); color: #cbd5e1; font-weight: 700; }
.b-pass { background: rgba(52,211,153,0.16); color: var(--green); padding: 3px 8px; border-radius: 6px; font-weight: 700; font-size: 0.78rem; }
.b-fail { background: rgba(251,113,133,0.14); color: var(--rose); padding: 3px 8px; border-radius: 6px; font-weight: 700; font-size: 0.78rem; }
pre {
margin: 0; padding: 14px; overflow: auto; max-height: 460px; font-size: 0.8rem; line-height: 1.48;
background: #060a13; color: #e2e8f0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
</style>
</head>
<body>
<div class="wrap">
<header>
<div>
<h1>⚡ Rootformer-Code v25 (Stage 25.2 + KhalilSWE v3.6) vs. Qwen4-35B-A3B</h1>
<p class="sub">100% Live Browser HTML5 / Canvas / SVG Outputs &amp; Unseen SWE-bench Shootout — Same Hardware (A100-80GB), Same Prompts</p>
</div>
<div class="links">
<a class="btn btn-primary" href="https://huggingface.co/enver/rootformer-code-v25-khalilswe-27b" target="_blank" rel="noopener">🤗 Model Weights (27B BF16)</a>
<a class="btn" href="https://huggingface.co/datasets/enver/KhalilAlgoWorks" target="_blank" rel="noopener">📚 KhalilAlgoWorks Dataset</a>
</div>
</header>
<section class="kpis">
<div class="kpi">
<div class="lbl">SWE-bench Verified 100</div>
<div class="val">62.0% <span style="font-size:0.9rem;color:#94a3b8">(62/100)</span></div>
<div class="note">63.2% Unseen · 6.2× vs Vanilla Qwen3.8-27B (10%)</div>
</div>
<div class="kpi">
<div class="lbl">Unseen SWE-HO6 vs Qwen4</div>
<div class="val">4/6 vs 3/6</div>
<div class="note">Ours 66.7% beats Qwen4-35B-A3B ReAct (50.0%)</div>
</div>
<div class="kpi">
<div class="lbl">Qwen4 + Our KhalilSWE v3.6</div>
<div class="val">5/6 <span style="font-size:0.9rem;color:#94a3b8">(83.3%)</span></div>
<div class="note">+33.3 pts lift &amp; 100% patch rate on Qwen4 itself!</div>
</div>
<div class="kpi">
<div class="lbl">Dev-615 + Turāth-40 Arabic</div>
<div class="val">81.63% / 75.0%</div>
<div class="note">502/615 OOF (ECE 0.0413) · +7.5 pts Arabic Fast</div>
</div>
</section>
<div class="tabs">
<div class="tab-group">
<button class="tab active" data-tab="hex">1. Spinning Neon Hexagon Physics (LIVE)</button>
<button class="tab" data-tab="glass">2. Glassmorphism Telemetry UI (LIVE · Full)</button>
<button class="tab" data-tab="pelican">3. Moving Pelican on a Bicycle (LIVE Animation)</button>
<button class="tab" data-tab="bench">4. SWE-HO6 &amp; Audited Code Outputs</button>
</div>
<button class="btn" id="reloadBtn" type="button">↻ Reload Active Live Demos</button>
</div>
<!-- TAB 1: SPINNING HEXAGON -->
<div class="pane active" id="pane-hex">
<div class="desc-bar">
<div><strong>Prompt:</strong> Single-file HTML5 Canvas simulation of 18 glowing physics balls with gravity, elasticity, trails, and HUD inside a rotating neon hexagon.</div>
<div><strong>Result:</strong> Ours achieved <strong>33.0 FPS</strong> with a crisp zero-overlap HUD vs Qwen4's <strong>21.5 FPS</strong>, overlapping energy text, and smeared outline.</div>
</div>
<div class="split">
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-ours">OURS</span> Rootformer Stage 25.2 (Qaṭʿ · 39.5s) <span class="pill pill-win">33.0 FPS · WIN</span></div>
<div class="card-actions">
<a class="mini-link" href="./spinning_hexagon_html_ours.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./spinning_hexagon_html_ours.html" src="./spinning_hexagon_html_ours.html" title="Ours Spinning Hexagon"></iframe>
</div>
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-q4">QWEN4</span> Qwen4-35B-A3B (35.6s · 21.5 FPS)</div>
<div class="card-actions">
<a class="mini-link" href="./spinning_hexagon_html_qwen4.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./spinning_hexagon_html_qwen4.html" src="./spinning_hexagon_html_qwen4.html" title="Qwen4 Spinning Hexagon"></iframe>
</div>
</div>
</div>
<!-- TAB 2: GLASSMORPHISM UI -->
<div class="pane" id="pane-glass">
<div class="desc-bar">
<div><strong>Prompt:</strong> Single-file dark glassmorphism Autonomous Software Engineering Agent Telemetry Card (equal <strong>10,240-token</strong> output cap for both models).</div>
<div><strong>Result:</strong> Both finished 100% cleanly (<code>finish=stop</code>, 0 JS errors) — Ours (<strong>Forge-7</strong>, <strong>7,088 tok</strong>) rendered all 4 sparkline KPI cards, dual-series bar+trendline chart, and PR pills in fewer tokens than Qwen4 (<strong>Aurora-7</strong>, <strong>7,800 eval tok</strong>).</div>
</div>
<div class="split">
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-ours">OURS</span> Rootformer Stage 25.2 (7,088 tok · Clean Finish) <span class="pill pill-win">100% COMPLETE</span></div>
<div class="card-actions">
<a class="mini-link" href="./glassmorphism_ui_html_ours.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./glassmorphism_ui_html_ours.html" src="./glassmorphism_ui_html_ours.html" title="Ours Glassmorphism UI"></iframe>
</div>
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-q4">QWEN4</span> Qwen4-35B-A3B (7,800 eval tok · Clean Finish)</div>
<div class="card-actions">
<a class="mini-link" href="./glassmorphism_ui_html_qwen4.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./glassmorphism_ui_html_qwen4.html" src="./glassmorphism_ui_html_qwen4.html" title="Qwen4 Glassmorphism UI"></iframe>
</div>
</div>
</div>
<!-- TAB 3: MOVING PELICAN ANIMATION -->
<div class="pane" id="pane-pelican">
<div class="desc-bar">
<div><strong>Prompt:</strong> Single-file HTML5 animated scene of a pelican actively pedaling a bicycle along a parallax coastal boardwalk at sunset with Speed slider, Pause toggle, and live FPS readout (equal <strong>10,240-token</strong> answer cap).</div>
<div><strong>Result:</strong> Both animate smoothly with 0 JS errors — Ours runs at <strong>40 FPS</strong> using <strong>2.1× fewer tokens</strong> (<strong>6,567</strong> vs <strong>13,805</strong> eval tok); Qwen4 runs at <strong>46 FPS</strong> with a larger pelican throat pouch.</div>
</div>
<div class="split">
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-ours">OURS</span> Rootformer Stage 25.2 (40 FPS · 6,567 tok) <span class="pill pill-win">2.1× LEANER</span></div>
<div class="card-actions">
<a class="mini-link" href="./moving_pelican_html_ours.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./moving_pelican_html_ours.html" src="./moving_pelican_html_ours.html" title="Ours Moving Pelican Animation"></iframe>
</div>
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-q4">QWEN4</span> Qwen4-35B-A3B (46 FPS · 13,805 eval tok)</div>
<div class="card-actions">
<a class="mini-link" href="./moving_pelican_html_qwen4.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./moving_pelican_html_qwen4.html" src="./moving_pelican_html_qwen4.html" title="Qwen4 Moving Pelican Animation"></iframe>
</div>
</div>
</div>
<!-- TAB 4: SWE-HO6 & CODE -->
<div class="pane" id="pane-bench">
<div class="desc-bar">
<div><strong>Unseen SWE-HO6 (3 Django + 3 SymPy from <code>heldout10</code>):</strong> Graded zero-Docker against official hidden <code>FAIL_TO_PASS + PASS_TO_PASS</code> suites under an identical 16-turn cap.</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Unseen GitHub Issue</th>
<th>Qwen3.8-27B + ReAct</th>
<th>Qwen4-35B-A3B + ReAct</th>
<th>Ours (27B + KhalilSWE v3.6)</th>
<th>Bonus: Qwen4-35B-A3B + Our KhalilSWE v3.6</th>
</tr>
</thead>
<tbody>
<tr><td><code>django__django-14725</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td></tr>
<tr><td><code>django__django-14771</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>django__django-14787</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>sympy__sympy-22456</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>sympy__sympy-22914</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>sympy__sympy-23262</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr style="background:rgba(56,189,248,0.08);font-weight:700;">
<td>Total Resolved</td>
<td>0 / 6 (0.0%)</td>
<td>3 / 6 (50.0%)</td>
<td style="color:var(--green)">4 / 6 (66.7%)</td>
<td style="color:var(--amber)">5 / 6 (83.3%)</td>
</tr>
</tbody>
</table>
</div>
<div class="desc-bar">
<div><strong>1. Unseen Multi-Library <code>BigCodeBench-Hard</code> (RandomForest / pandas / matplotlib):</strong> Both passed <strong>5/5 official unittests</strong>; Ours is <strong>3× leaner</strong> (1,040 chars vs 3,113 chars).</div>
</div>
<div class="split" style="margin-bottom:18px;">
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-ours">OURS · 5/5 PASS</span> Stage 25.2 (1,040 chars)</div></div>
<pre>import pandas as pd
from sklearn.ensemble import RandomForestClassifier
import seaborn as sns
import matplotlib.pyplot as plt
def task_func(df, target_column):
# Separate features and target
X = df.drop(columns=[target_column])
y = df[target_column]
# Train Random Forest Classifier
clf = RandomForestClassifier()
clf.fit(X, y)
# Get feature importances
feature_importances = clf.feature_importances_
# Create a dataframe for sorting
importance_df = pd.DataFrame({
&#x27;Feature&#x27;: X.columns,
&#x27;Importance&#x27;: feature_importances
})
# Sort in descending order
importance_df = importance_df.sort_values(by=&#x27;Importance&#x27;, ascending=False).reset_index(drop=True)
# Plot horizontal bar plot
fig, ax = plt.subplots()
sns.barplot(x=&#x27;Importance&#x27;, y=&#x27;Feature&#x27;, data=importance_df, ax=ax)
ax.set_xlabel(&#x27;Feature Importance Score&#x27;)
ax.set_ylabel(&#x27;Features&#x27;)
ax.set_title(&#x27;Visualizing Important Features&#x27;)
return clf, ax</pre>
</div>
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-q4">QWEN4 · 5/5 PASS</span> Qwen4-35B-A3B (3,113 chars)</div></div>
<pre>import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestClassifier
import seaborn as sns
import matplotlib.pyplot as plt
def task_func(df, target_column):
&quot;&quot;&quot;
Train a Random Forest classifier on a dataframe (using `target_column` as the
label) and plot the feature importances as a horizontal bar plot.
Parameters
----------
df : pandas.DataFrame
The dataframe containing the features and the column of interest.
target_column : str
The name of the column used as the classification target.
Returns
-------
(sklearn.ensemble.RandomForestClassifier, matplotlib.axes.Axes)
The trained random forest classifier and the Axes object of the
plotted bar chart.
&quot;&quot;&quot;
# ------------------------------------------------------------------
# 1. Split the data into features (X) and target (y)
# ------------------------------------------------------------------
X = df.drop(columns=[target_column])
y = df[target_column]
# ------------------------------------------------------------------
# 2. Encode any non numeric (categorical / boolean) feature columns so
# that the random forest can consume them.
# ------------------------------------------------------------------
non_numeric = X.select_dtypes(include=[&quot;object&quot;, &quot;category&quot;, &quot;bool&quot;, &quot;string&quot;]).columns
if len(non_numeric) &gt; 0:
X = pd.get_dummies(X, columns=list(non_numeric))
# ------------------------------------------------------------------
# 3. Train the random forest classifier
# ------------------------------------------------------------------
clf = RandomForestClassifier()
clf.fit(X, y)
# ------------------------------------------------------------------
# 4. Collect and sort the feature importances in descending order
# ------------------------------------------------------------------
importances = clf.feature_importances_
feature_names = np.asarray(X.columns)
sorted_idx = np.argsort(importances)[::-1] # descending order
sorted_importances = np.asarray(importances)[sorted_idx]
sorted_features = feature_names[sorted_idx]
# ------------------------------------------------------------------
# 5. Plot: importances on the x-axis, feature names on the y-axis
# ------------------------------------------------------------------
fig, ax = plt.subplots(figsize=(10, 6))
ax.barh(sorted_features, sorted_importances, color=&quot;skyblue&quot;, edgecolor=&quot;black&quot;)
ax.set_xlabel(&quot;Feature Importance Score&quot;)
ax.set_ylabel(&quot;Features&quot;)
ax.set_title(&quot;Visualizing Important Features&quot;)
fig.tight_layout()
return clf, ax
if __name__ == &quot;__main__&quot;:
# Simple demo
data = pd.DataFrame({
&quot;feature1&quot;: np.random.rand(100),
&quot;feature2&quot;: np.random.rand(100),
&quot;feature3&quot;: np.random.rand(100),
&quot;category&quot;: np.random.choice([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;], 100),
&quot;target&quot;: np.random.choice([0, 1], 100),
})
model, axis = task_func(data, &quot;target&quot;)
plt.show()</pre>
</div>
</div>
<div class="desc-bar">
<div><strong>2. Classical Arabic <code>Turāth</code> DAG &amp; Lexicographical Kahn Validator:</strong> Both passed <strong>10/10 hidden asserts</strong>; Ours is <strong>40% leaner</strong> with zero stray debug prints (2,096 chars vs 3,456 chars).</div>
</div>
<div class="split">
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-ours">OURS · 10/10 PASS</span> Stage 25.2 (2,096 chars)</div></div>
<pre>def analyze_isnad_dag(chains: list[list[str]], unreliable: set[str]) -&gt; dict:
from heapq import heappush, heappop
nodes = set()
edges = set()
for chain in chains:
for n in chain:
nodes.add(n)
for i in range(len(chain) - 1):
edges.add((chain[i], chain[i + 1]))
# Check for self-loops (direct cycle)
for u, v in edges:
if u == v:
return {&quot;valid_dag&quot;: False, &quot;topological_order&quot;: [], &quot;authentic_chains&quot;: 0, &quot;longest_clean_path&quot;: 0}
# Build adjacency and in-degree
adj = {n: [] for n in nodes}
in_degree = {n: 0 for n in nodes}
for u, v in edges:
adj[u].append(v)
in_degree[v] += 1
# Kahn&#x27;s algorithm with lexicographic tie-breaking
heap = [n for n in nodes if in_degree[n] == 0]
heap.sort()
topo = []
while heap:
u = heappop(heap)
topo.append(u)
for v in adj[u]:
in_degree[v] -= 1
if in_degree[v] == 0:
heappush(heap, v)
if len(topo) != len(nodes):
return {&quot;valid_dag&quot;: False, &quot;topological_order&quot;: [], &quot;authentic_chains&quot;: 0, &quot;longest_clean_path&quot;: 0}
# Authentic chains: non-empty and no narrator in unreliable
authentic_chains = 0
for chain in chains:
if len(chain) &gt; 0 and not any(n in unreliable for n in chain):
authentic_chains += 1
# Longest clean path (number of nodes) in subgraph of reliable nodes
clean_nodes = {n for n in nodes if n not in unreliable}
if not clean_nodes:
longest_clean_path = 0
else:
dp = {n: 1 for n in clean_nodes}
for u in topo:
if u not in clean_nodes:
continue
for v in adj[u]:
if v in clean_nodes:
if dp[u] + 1 &gt; dp[v]:
dp[v] = dp[u] + 1
longest_clean_path = max(dp.values())
return {
&quot;valid_dag&quot;: True,
&quot;topological_order&quot;: topo,
&quot;authentic_chains&quot;: authentic_chains,
&quot;longest_clean_path&quot;: longest_clean_path
}</pre>
</div>
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-q4">QWEN4 · 10/10 PASS</span> Qwen4-35B-A3B (3,456 chars)</div></div>
<pre>import heapq
def analyze_isnad_dag(chains: list[list[str]], unreliable: set[str]) -&gt; dict:
&quot;&quot;&quot;
تحليل رسم الإسناد الموجّه المُجمَّع من كل سلاسل الإسناد.
يعيد:
{
&quot;valid_dag&quot;: bool,
&quot;topological_order&quot;: list[str], # كسني أبجدي عند التساوي
&quot;authentic_chains&quot;: int,
&quot;longest_clean_path&quot;: int
}
&quot;&quot;&quot;
invalid = {
&quot;valid_dag&quot;: False,
&quot;topological_order&quot;: [],
&quot;authentic_chains&quot;: 0,
&quot;longest_clean_path&quot;: 0,
}
if unreliable is None:
unreliable = set()
nodes: set[str] = set()
adj: dict[str, set] = {}
indeg: dict[str, int] = {}
edge_set: set[tuple[str, str]] = set()
# ---- بناء الرسم البياني المُجمَّع (عقد + حواف فريدة) ----
for chain in chains:
if chain is None:
continue
chain = list(chain)
if not chain:
continue
for name in chain:
nodes.add(name)
if name not in adj:
adj[name] = set()
indeg[name] = 0
for a, b in zip(chain, chain[1:]):
if a == b:
# حلقة ذاتية =&gt; دورة موجهة حتماً
adj.setdefault(a, set())
indeg.setdefault(a, 0)
if (a, b) not in edge_set:
edge_set.add((a, b))
adj[a].add(b)
indeg[b] += 1
continue
if (a, b) not in edge_set:
edge_set.add((a, b))
adj[a].add(b)
indeg[b] += 1
if not nodes:
return {
&quot;valid_dag&quot;: True,
&quot;topological_order&quot;: [],
&quot;authentic_chains&quot;: 0,
&quot;longest_clean_path&quot;: 0,
}
# ---- خوارزمية كان مع أولوية صغرى (كسني أبجدي) ----
heap = [n for n in nodes if indeg[n] == 0]
heapq.heapify(heap)
order: list[str] = []
while heap:
u = heapq.heappop(heap)
order.append(u)
for v in sorted(adj[u]):
indeg[v] -= 1
if indeg[v] == 0:
heapq.heappush(heap, v)
if len(order) != len(nodes):
# توجد دورة موجهة (أو حلقة ذاتية)
return invalid
# ---- عدد السلاسل الصحيحة (خالية من الرواة غير الموثوقين) ----
authentic_chains = 0
for chain in chains:
if chain is None:
continue
if not chain:
continue
ok = True
for name in chain:
if name in unreliable:
ok = False
break
if ok:
authentic_chains += 1
# ---- أطول مسار موجّه يمر فقط برواة موثوقين (DP على الترتيب الطوبولوجي) ----
dp: dict[str, int] = {}
for u in order:
if u in unreliable:
continue
if u not in dp:
dp[u] = 1
base = dp[u]
for v in adj[u]:
if v in unreliable:
continue
if dp.get(v, 0) &lt; base + 1:
dp[v] = base + 1
longest_clean_path = max(dp.values()) if dp else 0
return {
&quot;valid_dag&quot;: True,
&quot;topological_order&quot;: order,
&quot;authentic_chains&quot;: authentic_chains,
&quot;longest_clean_path&quot;: longest_clean_path,
}
if __name__ == &quot;__main__&quot;:
print(analyze_isnad_dag([[&quot;مالك&quot;, &quot;نافع&quot;, &quot;ابن عمر&quot;]], {&quot;ابن عمر&quot;}))
print(analyze_isnad_dag([[&quot;أ&quot;, &quot;ب&quot;], [&quot;ب&quot;, &quot;أ&quot;]], set()))
print(analyze_isnad_dag([], set()))</pre>
</div>
</div>
</div>
</div>
<script>
(function() {
const tabs = document.querySelectorAll('.tab');
const panes = document.querySelectorAll('.pane');
tabs.forEach(t => {
t.addEventListener('click', () => {
tabs.forEach(x => x.classList.remove('active'));
panes.forEach(p => p.classList.remove('active'));
t.classList.add('active');
document.getElementById('pane-' + t.dataset.tab).classList.add('active');
});
});
document.getElementById('reloadBtn').addEventListener('click', () => {
const active = document.querySelector('.pane.active');
if (!active) return;
active.querySelectorAll('iframe').forEach(f => {
const base = f.getAttribute('data-src') || f.src;
f.src = base.split('?')[0] + '?t=' + Date.now();
});
});
})();
</script>
</body>
</html>