Abstract
Program of Thoughts (PoT) is an approach characterized by its executable intermediate steps, which ensure the accuracy of the logical calculations in the reasoning process. Currently, PoT primarily uses Python. However, relying solely on a single language may result in suboptimal solutions and overlook the potential benefits of other programming languages. In this paper, we conduct comprehensive experiments on the programming languages used in PoT and find that no single language consistently delivers optimal performance across all tasks and models. The effectiveness of each language varies depending on the specific scenarios. Inspired by this, we propose a task and model agnostic approach called MultiPoT, which harnesses strength and diversity from various languages. Experimental results reveal that it significantly outperforms Python Self-Consistency. Furthermore, it achieves comparable or superior performance compared to the best monolingual PoT in almost all tasks across all models. In particular, MultiPoT achieves more than 4.6% improvement on average on ChatGPT (gpt-3.5-turbo-0701).
Introduction: The Python Monopoly in Reasoning
Large Language Models (LLMs) often struggle with complex numerical and logical calculations. To address this, researchers developed Program of Thoughts (PoT), where the LLM generates a script to solve a problem, and an external interpreter executes it to obtain the final answer. To date, PoT research has been almost entirely Python-centric.
However, relying solely on Python creates a significant blind spot. Different programming languages possess unique built-in strengths. For instance, calculating a date exactly one year ago can be error-prone in Python if one simply subtracts 365 days, failing to account for leap years. In contrast, languages like R or JavaScript handle these temporal nuances more naturally through high-level abstractions.
Methodology: Introducing MultiPoT
To break the Python monopoly, we introduce MultiPoT (Multilingual Program of Thoughts). This approach leverages the unique strengths and syntactic diversity of multiple programming languages to improve reasoning accuracy.
The MultiPoT workflow consists of three main stages:
- Language-Specific Prompting: Instead of a generic prompt, we use few-shot demonstrations tailored to the idioms of five languages: Python, JavaScript, Java, C++, and R. The underlying reasoning logic remains identical, but the syntax is optimized for each language (e.g., using
structsin C++ ordata.framein R). - Synchronous Generation: The LLM generates multiple PoT scripts across these different languages for a single problem.
- Execution and Voting: Scripts are executed in their respective environments. MultiPoT aggregates the outputs and uses majority voting to select the final answer, utilizing cumulative generation probabilities to break ties.
This contrasts with standard "Self-Consistency" (SC) methods, which typically generate multiple scripts in a single language (usually Python) and vote on those.
Experimental Evaluation
We evaluated reasoning capabilities across five distinct, language-agnostic tasks:
- Math Application (Appl.): Elementary math word problems merged from GSM8K, SVAMP, and Asdiv.
- Math: Advanced mathematical problems from the MATH dataset.
- Date: Temporal reasoning (e.g., "What was the date one year ago?").
- Tabular: Structured text reasoning (e.g., "Penguins in a Table").
- Spatial: Spatial positioning and reasoning.
We tested these tasks across four prominent LLMs: ChatGPT, Starcoder, Code Llama, and Deepseek Coder.
Key Insights: Python is Not Always King
Our experiments revealed several surprising findings that challenge the assumption of Python's superiority in PoT:
- Task-Dependent Performance: R excels at Date reasoning because its libraries handle date intervals more intuitively than Python's
timedelta. Conversely, Python remains strong for Tabular data. - Model-Dependent Preferences: Code Llama shows a marked preference for Java, while Deepseek Coder performs best when reasoning in C++. For Deepseek Coder, Python was actually the worst-performing language on average.
- Coding vs. Reasoning: An LLM's ability to write Python for software engineering does not necessarily mean Python is its best medium for logical reasoning. The two capabilities do not perfectly align.
- Diversity Reduces Correlated Errors: Standard Python Self-Consistency often results in multiple scripts making the same logical error. By forcing the model to express logic in different languages, MultiPoT introduces syntactic diversity that drastically reduces the likelihood of repeating the same mistake.
Results and Conclusion
MultiPoT significantly outperformed standard Python Self-Consistency across almost all models and tasks. It achieved an average performance improvement of over 4.6% on ChatGPT and Starcoder compared to the best single-language PoT. Furthermore, MultiPoT achieved the highest "coverage rate"—the percentage of questions where at least one generated program was correct—proving that multilingual generation explores a more accurate solution space than monolingual generation.
In conclusion, the programming world is vast, and relying on a single language for LLM reasoning is suboptimal. By embracing multilingualism, MultiPoT harnesses the collective strengths of various languages to achieve more robust and accurate logical reasoning.
Summary updated