A JavaScript implementation of the HadithRank algorithm—a probabilistic method for evaluating the integrity of Hadith transmission chains based on Information Theory.
HadithRank is an algorithmic alternative to the traditional ṣaḥīḥ-ḍaʿīf grading system. It utilizes principles from Information Theory—specifically redundancy and channel capacity—to determine the "Likelihood of Integrity" (LI) of a report based on its transmission topology.
Unlike traditional binary or tertiary classifications, HadithRank produces a continuous reliability score (0-100%) by recursively analyzing the structure of witnesses (parallel channels) and transmission links (serial attenuation).
The algorithm models the isnād (transmission chain) as a signal propagation network:
- Parallel Combination (Siblings): Multiple independent transmitters reduce the probability of error using the noisy-OR rule:
1 - ∏(1 - LI_child). - Serial Attenuation (Parent-Child): Transmission from a narrator to their student acts as a bottleneck, multiplying the signal by an attenuation factor (fidelity coefficient):
LI_parent * α. - Bottleneck Property: A node's unreliability cannot be completely overcome by downstream branching; the "weakest link" strictly limits the maximum possible integrity of that branch.
Read the full methodology: > Mathematical Hadith Verification With Information Theory: The HadithRank Algorithm
This is a standalone JavaScript class. You can include it directly in your Node.js project or browser environment.
Download the IntegrityCalculator.js file from this repository and place it in your project folder.
Node.js:
const IntegrityCalculator = require('./IntegrityCalculator');ES Modules / Browser:
import IntegrityCalculator from './IntegrityCalculator.js';Calculate the integrity of a hadith with multiple transmission paths. The parser accepts strings in the format Source > Narrator A > Narrator B.
const IntegrityCalculator = require('./IntegrityCalculator');
// Initialize with a default attenuation (fidelity) of 0.6
// This represents 60% reliability per transmission hop
const calculator = new IntegrityCalculator(0.6);
const chains = [
// Branch 1: Source -> A -> B -> (Witnesses C, D)
'Source > A > B > C',
'Source > A > B > D',
// Branch 2: Source -> A -> E -> (Witness F)
'Source > A > E > F',
// Branch 3: Source -> G -> H -> I -> (Witnesses J, K, L)
'Source > G > H > I > J',
'Source > G > H > I > K',
'Source > G > H > I > L'
];
const result = calculator.calculate(chains);
console.log(`Final Likelihood of Integrity: ${(result * 100).toFixed(2)}%`);
// Output: 52.89%You can adjust the attenuation coefficient (defaultDecay) when initializing the calculator. This value represents the probability that a single narrator accurately preserves the signal across one "hop."
// Strict evaluation (0.5 reliability per narrator)
const strictCalc = new IntegrityCalculator(0.5);
// Lenient evaluation (0.8 reliability per narrator)
const lenientCalc = new IntegrityCalculator(0.8);Any string can be used instead of Source:
- Prophet Muhammad ﷺ > Companion 1 > Transmitter A > Transmitter B > Transmitter C
The parser is flexible with whitespace. All the following are valid:
Source > A > BSource>A>BSource > Narrator One > Narrator Two
This software is licensed under the MIT License.
MIT License
Copyright (c) 2025 [Ikram Hawramani]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.