Appendix: Algorithms and Code

Overview

All analyses described in this book were implemented in Python 3 and executed on publicly available data from the Sefaria.org API. No proprietary data, manual annotations, or non-reproducible steps were used. The complete analysis scripts are available at Zenodo (DOIs: 10.5281/zenodo.18744642, 10.5281/zenodo.18906232).

This appendix provides pseudocode descriptions of the key algorithms.

---

Algorithm 1: Foundation/Control Classification

INPUT: Hebrew consonantal text
OUTPUT: Classification of each letter as Foundation (F) or Control (C)
FOUNDATION = {ื’, ื“, ื–, ื—, ื˜, ืก, ืข, ืค, ืฆ, ืง, ืจ, ืฉ}  # 12 letters
CONTROL    = {ื, ืž, ืช, ื , ื™, ื”, ื•, ื‘, ื›, ืœ}          # 10 letters
FOR each word W in text:
FOR each letter L in W:
IF L in FOUNDATION:
classify(L) = "Foundation"
ELSE IF L in CONTROL:
classify(L) = "Control"

---

Algorithm 2: Foundation% Computation

INPUT: Text passage (verses or window)
OUTPUT: Foundation% value
foundation_count = 0
total_count = 0
FOR each word W in passage:
FOR each consonantal letter L in W:
total_count += 1
IF L in FOUNDATION:
foundation_count += 1
RETURN foundation_count / total_count * 100

---

Algorithm 3: ModeScore Computation

INPUT: Text window (set of verses)
OUTPUT: ModeScore value in range [-1, +1]
Y = count occurrences of "ื™ื”ื•ื”" in window
E = count occurrences of "ืืœื”ื™ื" or "ื”ืืœื”ื™ื" in window
IF Y + E > 0:
RETURN (Y - E) / (Y + E)
ELSE:
RETURN 0  # no divine names in window

---

Algorithm 4: Variance Scaling Analysis

INPUT: Full Torah text, list of window sizes
OUTPUT: Scaling slope (ฮฑ) and Rยฒ for each metric
FOR each window_size W in [10, 20, 50, 100, 200, 400, 800]:
values = []
FOR i = 0 TO (N - W) STEP W:
window = verses[i : i+W]
values.append(compute_metric(window))  # Foundation% or ModeScore
std_values.append(standard_deviation(values))
window_sizes.append(W)
# Log-log linear regression
log_windows = log10(window_sizes)
log_stds = log10(std_values)
slope, intercept, r_value = linear_regression(log_windows, log_stds)
RETURN slope, r_valueยฒ

---

Algorithm 5: Autocorrelation Function

INPUT: Per-verse metric values, list of lags
OUTPUT: Autocorrelation at each lag
values = array of metric values (one per verse)
mean = mean(values)
variance = variance(values)
N = length(values)
centered = values - mean
FOR each lag L in lag_list:
IF L >= N: SKIP
ac = sum(centered[0 : N-L] * centered[L : N]) / ((N - L) * variance)
autocorrelations.append(ac)
RETURN autocorrelations

---

Algorithm 6: Correlation Length Fitting

INPUT: Positive autocorrelation values and corresponding lags
OUTPUT: Correlation length ฮพ
# Exponential model: ฯ(k) = A * exp(-k/ฮพ)
# Power-law model: ฯ(k) = B * k^(-ฮฒ)
# Filter to positive AC values only
positive_lags, positive_acs = filter(ac > 0.01)
# Fit exponential
A, ฮพ = curve_fit(exponential_model, positive_lags, positive_acs)
r2_exp = compute_r_squared(positive_acs, exponential_model(positive_lags, A, ฮพ))
# Fit power-law
B, ฮฒ = curve_fit(power_law_model, positive_lags, positive_acs)
r2_pow = compute_r_squared(positive_acs, power_law_model(positive_lags, B, ฮฒ))
# Convert ฮพ from segments to verses
ฮพ_verses = ฮพ * (total_verses / num_segments)
RETURN ฮพ_verses, r2_exp, ฮฒ, r2_pow

---

Algorithm 7: Three-Channel Boundary Detection

INPUT: Full Torah text, window_size=50, step=10, threshold=1.5
OUTPUT: Count of concurrent 3-channel spikes
FOR i = 0 TO (N - window_size) STEP step:
window = verses[i : i + window_size]
# Channel 1: Foundation%
f_pct = compute_foundation_percent(window)
# Channel 2: ModeScore
mode = compute_modescore(window)
# Channel 3: Function word vector
fw_vec = compute_function_word_vector(window)
IF previous_window EXISTS:
f_change = abs(f_pct - prev_f_pct)
m_change = abs(mode - prev_mode)
fw_change = euclidean_distance(fw_vec, prev_fw_vec)
store(f_change, m_change, fw_change)
prev_f_pct, prev_mode, prev_fw_vec = f_pct, mode, fw_vec
# Normalize each channel
f_z = (f_changes - mean(f_changes)) / std(f_changes)
m_z = (m_changes - mean(m_changes)) / std(m_changes)
fw_z = (fw_changes - mean(fw_changes)) / std(fw_changes)
# Count concurrent spikes
concurrent = count(f_z > threshold AND m_z > threshold AND fw_z > threshold)
RETURN concurrent  # Expected: 0 for Torah

---

Algorithm 8: Matched-Corpus Discrimination

INPUT: List of corpora (Torah, Prophets, controls)
OUTPUT: 5D distances from Torah
FOR each corpus C:
signature[C] = [
compute_foundation_slope(C),
compute_modescore_slope(C),
compute_foundation_stability(C),
compute_spike_rate(C),
compute_mode_autocorrelation(C)
]
# Z-score normalize across all corpora
mean_vec = mean(all signatures)
std_vec = std(all signatures)
torah_z = (signature["Torah"] - mean_vec) / std_vec
FOR each corpus C != "Torah":
z = (signature[C] - mean_vec) / std_vec
distance[C] = euclidean_distance(z, torah_z)
RETURN distances  # Torah halves should be closest

---

Algorithm 9: Remove-Signal Test

INPUT: Full Torah text
OUTPUT: Base-layer metrics with and without divine names
# Original
original_slope = compute_foundation_scaling_slope(torah_text)
original_ac = compute_foundation_autocorrelation(torah_text)
# Neutralized: replace all divine names with placeholder
neutralized_text = torah_text.copy()
FOR each verse V in neutralized_text:
replace("ื™ื”ื•ื”", "ืฉื")  # neutral placeholder
replace("ืืœื”ื™ื", "ืฉื")
replace("ื”ืืœื”ื™ื", "ืฉื")
neutral_slope = compute_foundation_scaling_slope(neutralized_text)
neutral_ac = compute_foundation_autocorrelation(neutralized_text)
# Compare
slope_change = abs(original_slope - neutral_slope)
ac_correlation = pearson(original_ac, neutral_ac)
RETURN slope_change, ac_correlation
# Expected: slope_change โ‰ˆ 0, ac_correlation โ‰ˆ 1.0

---

Algorithm 10: Name Morphology Analysis

INPUT: List of personal names from Torah
OUTPUT: Foundation% and letter-type pattern for each name
FOUNDATION = {ื’, ื“, ื–, ื—, ื˜, ืก, ืข, ืค, ืฆ, ืง, ืจ, ืฉ}
AMTN = {ื, ืž, ืช, ื }
YHW = {ื™, ื”, ื•}
BKL = {ื‘, ื›, ืœ}
FOR each name N:
pattern = ""
f_count = 0
total = 0
FOR each letter L in N:
total += 1
IF L in FOUNDATION:
f_count += 1
pattern += "F"
ELSE IF L in AMTN:
pattern += "A"
ELSE IF L in YHW:
pattern += "Y"
ELSE IF L in BKL:
pattern += "B"
foundation_pct = f_count / total * 100
STORE(name=N, foundation_pct, pattern)
RETURN all name analyses

---

Data Sources

Reproducibility

All scripts are available at:

The standalone Torah Root Analyzer (torah_root_analyzer.py) can reproduce the core Foundation/Control classification and all derivative analyses from a single script.