ChatLogic: Integrating Logic Programming with Large Language Models for Multi-Step Reasoning

Zhongsheng Wang, Jiamou Liu, Qiming Bao, Hongfei Rong, Jingfeng Zhang · DOI

Abstract

While Large Language Models (LLMs) demonstrate remarkable capabilities in natural language generation and creative tasks, they frequently struggle with formal deductive reasoning. This paper introduces ChatLogic, a novel framework designed to bridge the gap between neural-based linguistic creativity and symbolic logical rigor. By utilizing the LLM as a high-level controller that translates natural language into formal logic programs for execution by a symbolic engine, ChatLogic mitigates common issues such as hallucination and error propagation in multi-step reasoning tasks.

1. Introduction

Large Language Models like GPT-4 and Llama 2 have revolutionized human-computer interaction through their ability to mimic complex styles and summarize vast amounts of information. However, their underlying architecture—primarily based on next-token prediction—lacks a native mechanism for formal logic. In tasks requiring multi-step deductive reasoning (e.g., "If A implies B, and B implies C, then A implies C"), LLMs often fall victim to logical inconsistencies or lose the reasoning thread as the context grows. ChatLogic addresses these limitations by offloading logical computation to a precise symbolic solver, pyDatalog, while leveraging the LLM's strength in semantic translation.

2. The Problem: Reasoning Fragility in LLMs

In multi-step reasoning, errors are cumulative; a single hallucinated fact in an early step renders the final conclusion invalid. Furthermore, LLMs are constrained by finite context windows. As reasoning chains lengthen, models often suffer from the "lost in the middle" phenomenon, where earlier premises are forgotten or ignored. The researchers identified a specific difficulty: LLMs struggle to maintain a consistent explanation path when presented with propositions in a non-linear or random order. To solve this, a system is required that can convert fluid natural language into a rigid, executable symbolic format.

3. The ChatLogic Framework

The ChatLogic framework operates through a structured four-phase pipeline designed to ensure both the semantic accuracy and the syntactic validity of the generated logic.

3.1 Input Processing

The system receives facts and rules expressed in natural language. These serve as the raw material for the symbolic translation.

3.2 Semantic Correction (SE)

The LLM translates the input into pyDatalog code. To ensure fidelity, the framework employs a "reverse transformation" loop: the LLM translates the generated code back into natural language and compares it against the original intent. If discrepancies are found, the model iterates until the logic is aligned.

3.3 Syntax Correction (SYN)

Once semantically sound, the code is tested within a Python environment. If the pyDatalog interpreter returns an error, the error message is fed back into the LLM. This allows the model to "self-debug" and correct syntax errors before final execution.

3.4 Local Execution

The validated code is executed by a local pyDatalog engine, providing a definitive TRUE/FALSE answer based on the provided premises.

4. Mix-shot Chain of Thought

A core innovation of this framework is the Mix-shot Chain of Thought (CoT). While standard CoT encourages "step-by-step" thinking (zero-shot) and one-shot learning provides a single fixed example, Mix-shot combines these approaches. It provides a high-quality demonstration template to guide the structure of the output while allowing the model the generative freedom to navigate the specific nuances of the current logical problem.

5. Experimental Evaluation

The researchers evaluated ChatLogic using three primary benchmarks: PARARULE-Plus (400k samples involving "People" and "Animal" contexts with reasoning depths of 2–5) and CONCEPTRULES V1 & V2 (multi-step reasoning up to depth 3).

5.1 Key Results

ChatLogic consistently outperformed base models and standard Zero-shot CoT methods:

  • GPT-3.5 on PARARULE-Plus: At reasoning Depth 5, accuracy improved from 0.30 (Base) to 0.41 (ChatLogic).
  • Llama 2-7B: Demonstrated significant gains, rising from a baseline accuracy of 0.0475 to 0.1825.
  • Code Executability: The dual-correction loop (SE+SYN) proved vital. For GPT-3.5, code executability rose from 0.26 to 0.62 after applying both correction modules.

6. Discussion and Insights

  • LLM as Translator: The framework reinforces the philosophy that LLMs should function as translators of intent, while symbolic engines handle the heavy lifting of computation.
  • Symbolic Memory: By converting facts into a logic program, ChatLogic creates a "symbolic memory" that is immune to the token-limit issues and context degradation typical of standard LLM interactions.
  • The Performance Ceiling: Interestingly, GPT-4 showed less dramatic improvement compared to smaller models, suggesting that the model may be approaching a performance ceiling defined by the datasets themselves.
  • Closed-World Assumption: ChatLogic explicitly implements the "closed-world assumption" (if a fact is not stated, it is false), a logical constraint that LLMs natively struggle to maintain.

7. Limitations and Future Work

Despite its success, ChatLogic currently relies on synthetic datasets with structured language. Real-world natural language is often ambiguous and messy, posing a greater challenge for translation into rigid pyDatalog syntax. Additionally, the framework is currently optimized for specific datasets via prompt templates. Future research will focus on developing universal optimization components and expanding the framework to handle "open-world" scenarios where external knowledge must be inferred.

Summary updated

BibTeX
@inproceedings{wang2024chatlogic,
  author = {Zhongsheng Wang and Jiamou Liu and Qiming Bao and Hongfei Rong and Jingfeng Zhang},
  title = {{ChatLogic: Integrating Logic Programming with Large Language Models for Multi-Step Reasoning}},
  booktitle = {IJCNN},
  year = {2024},
  url = {https://openreview.net/forum?id=ndgXwiuqe2},
}
Figure