This paper introduces Al-Ghasali, a neuro-symbolic framework designed to bring the rigor of formal logic to the complex world of Islamic jurisprudence (Fiqh). By combining the deterministic nature of Finite State Automata (FSA) with the linguistic power of Large Language Models (LLMs), the author proposes a system that can provide instant legal verdicts while generating human-readable explanations that are mathematically guaranteed to be free of "hallucinations."
TL;DR
Al-Ghasali converts Islamic jurisprudential rules into deterministic Finite State Automata (FSA), enabling constant-time ($O(1)$) legal verdicts. It then uses an LLM to explain these results, employing a "FSA-supremacy" architecture and grammar-guided decoding to mathematically eliminate AI hallucinations and semantic errors.
What Problem Does This Paper Address?
Islamic jurisprudence, or Fiqh, is a highly structured field governed by specific logical methodologies. While recent research has successfully extracted minimal operational rules from these texts using set-theoretic formalizations, two major hurdles remain for practical application:
- Computational Overhead: Running a full logical inference engine in a real-time, user-facing application is computationally expensive and difficult to manage as state complexity grows.
- The LLM Hallucination Problem: While LLMs are great at explaining complex topics, they are notoriously unreliable for legal or religious rulings. They often "hallucinate" facts, invent non-existent legal causes, or even perform "semantic inversion"—where the AI correctly identifies a fact but uses a connector like "however" to flip the meaning of the verdict.
Al-Ghasali seeks to bridge the gap between theoretical logic and practical, safe deployment.
Methods
The framework relies on a multi-layered approach:
- Finite-State Collapse: The author proves that "closed" chapters of Fiqh (such as ritual worship, where the vocabulary is divinely fixed and unchanging) can be modeled as Finite State Automata (FSA). This reduces complex logical reasoning to a simple state-table lookup, achieving $O(1)$ complexity.
- Temporal Flattening: To handle Tartib (juristic order)—where the sequence of actions matters (e.g., washing the right arm before the left)—the system "flattens" these sequences into static ontological states within the FSA, preserving its memoryless property.
- FSA-LLM Supremacy: In this architecture, the FSA is the "boss." It calculates the verdict deterministically. The LLM acts only as a "linguistic transformer," translating the FSA's execution history into natural language.
- Grammar-Guided Constrained Decoding: The system dynamically generates a Right-Linear Grammar based on the FSA's path. During text generation, the LLM is physically restricted to only picking tokens that match this grammar.
- Valence Locking: To prevent the LLM from accidentally contradicting the verdict, the system uses a Bounded Neutral Lexicon. This restricts the AI to semantically neutral connectors (like "because of" or "and"), strictly forbidding negating or adversative connectors (like "however" or "but").
Datasets
The paper does not utilize a standard machine learning dataset for training. Instead, it uses:
- Hierarchical JSON Rule Sets: These are generated a priori using the al-sabr wa al-Taqsim (Examination and Division) algorithm to represent juristic truth tables.
- LLM Testing: The integration was tested using an OpenAI-compatible API endpoint (specifically mentioning BlueSminds GLM-4.6).
Key Insights and Ideas
- The "Closed Chapter Assumption": A major insight is that because ritual worship (Ibadat) is Tawqifi (divinely bounded), its legal ontology is constant. This allows for a "theoretical collapse" of the law into a deterministic machine.
- Hallucination as an Engineering Constraint: Rather than trying to "train" the hallucination out of an LLM, the author treats the LLM as a probabilistic engine that must be caged by a symbolic "scaffolding."
- Decidability via Hierarchy: The paper proves that nesting sub-chapter FSAs (e.g., a "Purification" modal inside a "Prayer" chapter) does not break the $O(1)$ performance guarantee or the decidability of the system.
Key Results
- Mathematical Proof of Safety: The author provides a formal proof that this architecture guarantees the absolute absence of Decisional Hallucination (wrong verdict) and Juristic Factual Hallucination (inventing legal causes).
- Performance: By pre-compiling rules into FSAs, the system achieves constant-time verdict extraction, making it suitable for low-power devices or high-traffic web applications.
- Semantic Integrity: Through "Valence Locking," the system ensures that the LLM cannot syntactically surround a "Valid" verdict with context that makes it sound "Invalid."
Limitations and Future Work
- Propositional Limits: The current framework is restricted to propositional Horn clauses. It cannot currently handle recursive relations without losing the $O(1)$ performance guarantee.
- Datalog Expansion: The author notes that moving to Datalog-style recursion (necessary for complex kinship and inheritance laws) would shift the complexity from constant time to polynomial time.
- Scope: The "Closed Chapter Assumption" applies best to ritual worship. Applying this to more dynamic areas of law (like finance or modern ethics) would require a different approach to ontological expansion.
- Deployment: Future work includes wrapping the framework into standalone desktop environments and expanding the rule sets to cover more complex genealogical relationships.
Summary updated